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