Home | History | Annotate | Download | only in gl
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_GL_GL_SURFACE_EGL_H_
      6 #define UI_GL_GL_SURFACE_EGL_H_
      7 
      8 #if defined(OS_WIN)
      9 #include <windows.h>
     10 #endif
     11 
     12 #include <string>
     13 
     14 #include "base/compiler_specific.h"
     15 #include "base/time/time.h"
     16 #include "ui/gfx/size.h"
     17 #include "ui/gfx/vsync_provider.h"
     18 #include "ui/gl/gl_bindings.h"
     19 #include "ui/gl/gl_surface.h"
     20 
     21 namespace gfx {
     22 
     23 // Get default EGL display for GLSurfaceEGL (differs by platform).
     24 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay();
     25 
     26 // Interface for EGL surface.
     27 class GL_EXPORT GLSurfaceEGL : public GLSurface {
     28  public:
     29   GLSurfaceEGL();
     30 
     31   // Implement GLSurface.
     32   virtual EGLDisplay GetDisplay() OVERRIDE;
     33 
     34   static bool InitializeOneOff();
     35   static EGLDisplay GetHardwareDisplay();
     36   static EGLNativeDisplayType GetNativeDisplay();
     37 
     38   // These aren't particularly tied to surfaces, but since we already
     39   // have the static InitializeOneOff here, it's easiest to reuse its
     40   // initialization guards.
     41   static const char* GetEGLExtensions();
     42   static bool HasEGLExtension(const char* name);
     43   static bool IsCreateContextRobustnessSupported();
     44   static bool IsEGLSurfacelessContextSupported();
     45 
     46  protected:
     47   virtual ~GLSurfaceEGL();
     48 
     49  private:
     50 #if defined(OS_WIN)
     51   static EGLDisplay GetPlatformDisplay(EGLNativeDisplayType native_display);
     52 #endif
     53 
     54   DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
     55 };
     56 
     57 // Encapsulates an EGL surface bound to a view.
     58 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
     59  public:
     60   explicit NativeViewGLSurfaceEGL(EGLNativeWindowType window);
     61 
     62   // Implement GLSurface.
     63   virtual EGLConfig GetConfig() OVERRIDE;
     64   virtual bool Initialize() OVERRIDE;
     65   virtual void Destroy() OVERRIDE;
     66   virtual bool Resize(const gfx::Size& size) OVERRIDE;
     67   virtual bool Recreate() OVERRIDE;
     68   virtual bool IsOffscreen() OVERRIDE;
     69   virtual bool SwapBuffers() OVERRIDE;
     70   virtual gfx::Size GetSize() OVERRIDE;
     71   virtual EGLSurface GetHandle() OVERRIDE;
     72   virtual bool SupportsPostSubBuffer() OVERRIDE;
     73   virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
     74   virtual VSyncProvider* GetVSyncProvider() OVERRIDE;
     75 
     76   // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
     77   // Takes ownership of the VSyncProvider.
     78   virtual bool Initialize(scoped_ptr<VSyncProvider> sync_provider);
     79 
     80  protected:
     81   virtual ~NativeViewGLSurfaceEGL();
     82 
     83   EGLNativeWindowType window_;
     84 
     85  private:
     86   EGLSurface surface_;
     87   bool supports_post_sub_buffer_;
     88   EGLConfig config_;
     89   gfx::Size size_;
     90 
     91   scoped_ptr<VSyncProvider> vsync_provider_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
     94 };
     95 
     96 // Encapsulates a pbuffer EGL surface.
     97 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
     98  public:
     99   explicit PbufferGLSurfaceEGL(const gfx::Size& size);
    100 
    101   // Implement GLSurface.
    102   virtual EGLConfig GetConfig() OVERRIDE;
    103   virtual bool Initialize() OVERRIDE;
    104   virtual void Destroy() OVERRIDE;
    105   virtual bool IsOffscreen() OVERRIDE;
    106   virtual bool SwapBuffers() OVERRIDE;
    107   virtual gfx::Size GetSize() OVERRIDE;
    108   virtual bool Resize(const gfx::Size& size) OVERRIDE;
    109   virtual EGLSurface GetHandle() OVERRIDE;
    110   virtual void* GetShareHandle() OVERRIDE;
    111 
    112  protected:
    113   virtual ~PbufferGLSurfaceEGL();
    114 
    115  private:
    116   gfx::Size size_;
    117   EGLSurface surface_;
    118 
    119   DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
    120 };
    121 
    122 // SurfacelessEGL is used as Offscreen surface when platform supports
    123 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
    124 // need to create a dummy EGLsurface in case we render to client API targets.
    125 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
    126  public:
    127   explicit SurfacelessEGL(const gfx::Size& size);
    128 
    129   // Implement GLSurface.
    130   virtual EGLConfig GetConfig() OVERRIDE;
    131   virtual bool Initialize() OVERRIDE;
    132   virtual void Destroy() OVERRIDE;
    133   virtual bool IsOffscreen() OVERRIDE;
    134   virtual bool SwapBuffers() OVERRIDE;
    135   virtual gfx::Size GetSize() OVERRIDE;
    136   virtual bool Resize(const gfx::Size& size) OVERRIDE;
    137   virtual EGLSurface GetHandle() OVERRIDE;
    138   virtual void* GetShareHandle() OVERRIDE;
    139 
    140  protected:
    141   virtual ~SurfacelessEGL();
    142 
    143  private:
    144   gfx::Size size_;
    145   DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
    146 };
    147 
    148 }  // namespace gfx
    149 
    150 #endif  // UI_GL_GL_SURFACE_EGL_H_
    151