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/native_widget_types.h"
     17 #include "ui/gfx/size.h"
     18 #include "ui/gfx/vsync_provider.h"
     19 #include "ui/gl/gl_bindings.h"
     20 #include "ui/gl/gl_surface.h"
     21 
     22 namespace gfx {
     23 
     24 // Interface for EGL surface.
     25 class GL_EXPORT GLSurfaceEGL : public GLSurface {
     26  public:
     27   GLSurfaceEGL();
     28 
     29   // Implement GLSurface.
     30   virtual EGLDisplay GetDisplay() OVERRIDE;
     31 
     32   static bool InitializeOneOff();
     33   static EGLDisplay GetHardwareDisplay();
     34   static EGLNativeDisplayType GetNativeDisplay();
     35 
     36   // These aren't particularly tied to surfaces, but since we already
     37   // have the static InitializeOneOff here, it's easiest to reuse its
     38   // initialization guards.
     39   static const char* GetEGLExtensions();
     40   static bool HasEGLExtension(const char* name);
     41   static bool IsCreateContextRobustnessSupported();
     42 
     43  protected:
     44   virtual ~GLSurfaceEGL();
     45 
     46  private:
     47   DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
     48 };
     49 
     50 // Encapsulates an EGL surface bound to a view.
     51 class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL {
     52  public:
     53   explicit NativeViewGLSurfaceEGL(gfx::AcceleratedWidget window);
     54 
     55   // Implement GLSurface.
     56   virtual EGLConfig GetConfig() OVERRIDE;
     57   virtual bool Initialize() OVERRIDE;
     58   virtual void Destroy() OVERRIDE;
     59   virtual bool Resize(const gfx::Size& size) OVERRIDE;
     60   virtual bool Recreate() OVERRIDE;
     61   virtual bool IsOffscreen() OVERRIDE;
     62   virtual bool SwapBuffers() OVERRIDE;
     63   virtual gfx::Size GetSize() OVERRIDE;
     64   virtual EGLSurface GetHandle() OVERRIDE;
     65   virtual std::string GetExtensions() OVERRIDE;
     66   virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
     67   virtual VSyncProvider* GetVSyncProvider() OVERRIDE;
     68 
     69   // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider.
     70   // Takes ownership of the VSyncProvider.
     71   virtual bool Initialize(VSyncProvider* sync_provider);
     72 
     73  protected:
     74   virtual ~NativeViewGLSurfaceEGL();
     75   void SetHandle(EGLSurface surface);
     76 
     77  private:
     78   gfx::AcceleratedWidget window_;
     79   EGLSurface surface_;
     80   bool supports_post_sub_buffer_;
     81   EGLConfig config_;
     82 
     83   scoped_ptr<VSyncProvider> vsync_provider_;
     84 
     85   DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL);
     86 };
     87 
     88 // Encapsulates a pbuffer EGL surface.
     89 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL {
     90  public:
     91   explicit PbufferGLSurfaceEGL(const gfx::Size& size);
     92 
     93   // Implement GLSurface.
     94   virtual EGLConfig GetConfig() OVERRIDE;
     95   virtual bool Initialize() OVERRIDE;
     96   virtual void Destroy() OVERRIDE;
     97   virtual bool IsOffscreen() OVERRIDE;
     98   virtual bool SwapBuffers() OVERRIDE;
     99   virtual gfx::Size GetSize() OVERRIDE;
    100   virtual bool Resize(const gfx::Size& size) OVERRIDE;
    101   virtual EGLSurface GetHandle() OVERRIDE;
    102   virtual void* GetShareHandle() OVERRIDE;
    103 
    104  protected:
    105   virtual ~PbufferGLSurfaceEGL();
    106 
    107  private:
    108   gfx::Size size_;
    109   EGLSurface surface_;
    110 
    111   DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL);
    112 };
    113 
    114 // SurfacelessEGL is used as Offscreen surface when platform supports
    115 // KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the
    116 // need to create a dummy EGLsurface in case we render to client API targets.
    117 class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL {
    118  public:
    119   explicit SurfacelessEGL(const gfx::Size& size);
    120 
    121   // Implement GLSurface.
    122   virtual EGLConfig GetConfig() OVERRIDE;
    123   virtual bool Initialize() OVERRIDE;
    124   virtual void Destroy() OVERRIDE;
    125   virtual bool IsOffscreen() OVERRIDE;
    126   virtual bool SwapBuffers() OVERRIDE;
    127   virtual gfx::Size GetSize() OVERRIDE;
    128   virtual bool Resize(const gfx::Size& size) OVERRIDE;
    129   virtual EGLSurface GetHandle() OVERRIDE;
    130   virtual void* GetShareHandle() OVERRIDE;
    131 
    132  protected:
    133   virtual ~SurfacelessEGL();
    134 
    135  private:
    136   gfx::Size size_;
    137   DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL);
    138 };
    139 
    140 }  // namespace gfx
    141 
    142 #endif  // UI_GL_GL_SURFACE_EGL_H_
    143