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/gl/gl_bindings.h" 19 #include "ui/gl/gl_surface.h" 20 #include "ui/gl/vsync_provider.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 virtual bool Initialize(VSyncProvider* sync_provider); 71 72 protected: 73 virtual ~NativeViewGLSurfaceEGL(); 74 void SetHandle(EGLSurface surface); 75 76 private: 77 gfx::AcceleratedWidget window_; 78 EGLSurface surface_; 79 bool supports_post_sub_buffer_; 80 EGLConfig config_; 81 82 scoped_ptr<VSyncProvider> vsync_provider_; 83 84 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL); 85 }; 86 87 // Encapsulates a pbuffer EGL surface. 88 class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL { 89 public: 90 explicit PbufferGLSurfaceEGL(const gfx::Size& size); 91 92 // Implement GLSurface. 93 virtual EGLConfig GetConfig() OVERRIDE; 94 virtual bool Initialize() OVERRIDE; 95 virtual void Destroy() OVERRIDE; 96 virtual bool IsOffscreen() OVERRIDE; 97 virtual bool SwapBuffers() OVERRIDE; 98 virtual gfx::Size GetSize() OVERRIDE; 99 virtual bool Resize(const gfx::Size& size) OVERRIDE; 100 virtual EGLSurface GetHandle() OVERRIDE; 101 virtual void* GetShareHandle() OVERRIDE; 102 103 protected: 104 virtual ~PbufferGLSurfaceEGL(); 105 106 private: 107 gfx::Size size_; 108 EGLSurface surface_; 109 110 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL); 111 }; 112 113 } // namespace gfx 114 115 #endif // UI_GL_GL_SURFACE_EGL_H_ 116