| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_GL_GL_CONTEXT_EGL_H_ | 5 #ifndef UI_GFX_GL_GL_SURFACE_EGL_H_ |
| 6 #define UI_GFX_GL_GL_CONTEXT_EGL_H_ | 6 #define UI_GFX_GL_GL_SURFACE_EGL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "ui/gfx/gl/gl_surface.h" |
| 10 #include "ui/gfx/gl/gl_context.h" | |
| 11 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| 12 | 11 |
| 12 typedef void* EGLConfig; |
| 13 typedef void* EGLDisplay; | 13 typedef void* EGLDisplay; |
| 14 typedef void* EGLContext; | |
| 15 typedef void* EGLSurface; | 14 typedef void* EGLSurface; |
| 16 | 15 |
| 17 namespace gfx { | 16 namespace gfx { |
| 18 | 17 |
| 19 // Takes ownership of an EGL surface and reference counts it so it can be shared | 18 // Interface for EGL contexts. |
| 20 // by multiple EGL contexts and destroyed with the last. | 19 class GLSurfaceEGL : public GLSurface { |
| 21 class SharedEGLSurface : public base::RefCounted<SharedEGLSurface> { | |
| 22 public: | 20 public: |
| 23 explicit SharedEGLSurface(EGLSurface surface); | 21 GLSurfaceEGL(); |
| 24 ~SharedEGLSurface(); | 22 virtual ~GLSurfaceEGL(); |
| 25 | 23 |
| 26 EGLSurface egl_surface() const; | 24 static bool InitializeOneOff(); |
| 25 static EGLDisplay GetDisplay(); |
| 26 static EGLConfig GetConfig(); |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 EGLSurface surface_; | 29 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL); |
| 30 DISALLOW_COPY_AND_ASSIGN(SharedEGLSurface); | |
| 31 }; | 30 }; |
| 32 | 31 |
| 33 // Interface for EGL contexts. Adds an EGL specific accessor for retreiving | 32 // Encapsulates an EGL surface bound to a view. |
| 34 // the surface. | 33 class NativeViewGLSurfaceEGL : public GLSurfaceEGL { |
| 35 class BaseEGLContext : public GLContext { | |
| 36 public: | 34 public: |
| 37 BaseEGLContext() {} | 35 explicit NativeViewGLSurfaceEGL(void* window); |
| 38 virtual ~BaseEGLContext() {} | 36 virtual ~NativeViewGLSurfaceEGL(); |
| 39 | |
| 40 static bool InitializeOneOff(); | |
| 41 | |
| 42 static EGLDisplay GetDisplay(); | |
| 43 | |
| 44 // Get the associated EGL surface. | |
| 45 virtual SharedEGLSurface* GetSurface() = 0; | |
| 46 | |
| 47 // Implement GLContext. | |
| 48 virtual std::string GetExtensions(); | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(BaseEGLContext); | |
| 52 }; | |
| 53 | |
| 54 // Encapsulates an EGL OpenGL ES context that renders to a view. | |
| 55 class NativeViewEGLContext : public BaseEGLContext { | |
| 56 public: | |
| 57 explicit NativeViewEGLContext(void* window); | |
| 58 virtual ~NativeViewEGLContext(); | |
| 59 | 37 |
| 60 // Initialize an EGL context. | 38 // Initialize an EGL context. |
| 61 bool Initialize(); | 39 bool Initialize(); |
| 62 | 40 |
| 63 // Implement GLContext. | 41 // Implement GLSurface. |
| 64 virtual void Destroy(); | 42 virtual void Destroy(); |
| 65 virtual bool MakeCurrent(); | |
| 66 virtual bool IsCurrent(); | |
| 67 virtual bool IsOffscreen(); | 43 virtual bool IsOffscreen(); |
| 68 virtual bool SwapBuffers(); | 44 virtual bool SwapBuffers(); |
| 69 virtual gfx::Size GetSize(); | 45 virtual gfx::Size GetSize(); |
| 70 virtual void* GetHandle(); | 46 virtual EGLSurface GetHandle(); |
| 71 virtual void SetSwapInterval(int interval); | |
| 72 | |
| 73 // Implement BaseEGLContext. | |
| 74 virtual SharedEGLSurface* GetSurface(); | |
| 75 | 47 |
| 76 private: | 48 private: |
| 77 void* window_; | 49 void* window_; |
| 78 scoped_refptr<SharedEGLSurface> surface_; | 50 EGLSurface surface_; |
| 79 EGLContext context_; | |
| 80 | 51 |
| 81 DISALLOW_COPY_AND_ASSIGN(NativeViewEGLContext); | 52 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL); |
| 82 }; | 53 }; |
| 83 | 54 |
| 84 // Encapsulates an EGL OpenGL ES context intended for offscreen use. It is | 55 // Encapsulates a pbuffer EGL surface. |
| 85 // actually associated with a native window or a pbuffer on supporting platforms | 56 class PbufferGLSurfaceEGL : public GLSurfaceEGL { |
| 86 // and will render to it. The caller must bind an FBO to prevent this. | |
| 87 // TODO(apatrick): implement pbuffers in ANGLE and change this to | |
| 88 // PbufferEGLContext and use it on all EGL platforms. | |
| 89 class SecondaryEGLContext : public BaseEGLContext { | |
| 90 public: | 57 public: |
| 91 SecondaryEGLContext(); | 58 explicit PbufferGLSurfaceEGL(const gfx::Size& size); |
| 92 virtual ~SecondaryEGLContext(); | 59 virtual ~PbufferGLSurfaceEGL(); |
| 93 | 60 |
| 94 // Initialize an EGL context that shares a namespace with another. | 61 // Initialize an EGL context that shares a namespace with another. |
| 95 bool Initialize(GLContext* shared_context); | 62 bool Initialize(); |
| 96 | 63 |
| 97 // Implement GLContext. | 64 // Implement GLSurface. |
| 98 virtual void Destroy(); | 65 virtual void Destroy(); |
| 99 virtual bool MakeCurrent(); | |
| 100 virtual bool IsCurrent(); | |
| 101 virtual bool IsOffscreen(); | 66 virtual bool IsOffscreen(); |
| 102 virtual bool SwapBuffers(); | 67 virtual bool SwapBuffers(); |
| 103 virtual gfx::Size GetSize(); | 68 virtual gfx::Size GetSize(); |
| 104 virtual void* GetHandle(); | 69 virtual EGLSurface GetHandle(); |
| 105 virtual void SetSwapInterval(int interval); | |
| 106 | |
| 107 // Implement BaseEGLContext. | |
| 108 virtual SharedEGLSurface* GetSurface(); | |
| 109 | 70 |
| 110 private: | 71 private: |
| 111 scoped_refptr<SharedEGLSurface> surface_; | 72 gfx::Size size_; |
| 112 EGLContext context_; | 73 EGLSurface surface_; |
| 113 | 74 |
| 114 DISALLOW_COPY_AND_ASSIGN(SecondaryEGLContext); | 75 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL); |
| 115 }; | 76 }; |
| 116 | 77 |
| 117 } // namespace gfx | 78 } // namespace gfx |
| 118 | 79 |
| 119 #endif // UI_GFX_GL_GL_CONTEXT_EGL_H_ | 80 #endif // UI_GFX_GL_GL_SURFACE_EGL_H_ |
| OLD | NEW |