| 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_CONTEXT_EGL_H_ |
| 6 #define UI_GFX_GL_GL_CONTEXT_EGL_H_ | 6 #define UI_GFX_GL_GL_CONTEXT_EGL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include <string> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/gfx/gl/gl_context.h" | 12 #include "ui/gfx/gl/gl_context.h" |
| 11 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 12 | 14 |
| 13 typedef void* EGLDisplay; | |
| 14 typedef void* EGLContext; | 15 typedef void* EGLContext; |
| 15 typedef void* EGLSurface; | |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 | 18 |
| 19 // Takes ownership of an EGL surface and reference counts it so it can be shared | 19 class GLSurfaceEGL; |
| 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 | |
| 33 // Interface for EGL contexts. Adds an EGL specific accessor for retreiving | |
| 34 // the surface. | |
| 35 class BaseEGLContext : public GLContext { | |
| 36 public: | |
| 37 BaseEGLContext() {} | |
| 38 virtual ~BaseEGLContext() {} | |
| 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 | 20 |
| 54 // Encapsulates an EGL OpenGL ES context that renders to a view. | 21 // Encapsulates an EGL OpenGL ES context that renders to a view. |
| 55 class NativeViewEGLContext : public BaseEGLContext { | 22 class GLContextEGL : public GLContext { |
| 56 public: | 23 public: |
| 57 explicit NativeViewEGLContext(void* window); | 24 // Takes ownership of surface. TODO(apatrick): separate notion of surface |
| 58 virtual ~NativeViewEGLContext(); | 25 // from context. |
| 26 explicit GLContextEGL(GLSurfaceEGL* surface); |
| 27 |
| 28 virtual ~GLContextEGL(); |
| 59 | 29 |
| 60 // Initialize an EGL context. | 30 // Initialize an EGL context. |
| 61 bool Initialize(); | |
| 62 | |
| 63 // Implement GLContext. | |
| 64 virtual void Destroy(); | |
| 65 virtual bool MakeCurrent(); | |
| 66 virtual bool IsCurrent(); | |
| 67 virtual bool IsOffscreen(); | |
| 68 virtual bool SwapBuffers(); | |
| 69 virtual gfx::Size GetSize(); | |
| 70 virtual void* GetHandle(); | |
| 71 virtual void SetSwapInterval(int interval); | |
| 72 | |
| 73 // Implement BaseEGLContext. | |
| 74 virtual SharedEGLSurface* GetSurface(); | |
| 75 | |
| 76 private: | |
| 77 void* window_; | |
| 78 scoped_refptr<SharedEGLSurface> surface_; | |
| 79 EGLContext context_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(NativeViewEGLContext); | |
| 82 }; | |
| 83 | |
| 84 // Encapsulates an EGL OpenGL ES context intended for offscreen use. It is | |
| 85 // actually associated with a native window or a pbuffer on supporting platforms | |
| 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: | |
| 91 SecondaryEGLContext(); | |
| 92 virtual ~SecondaryEGLContext(); | |
| 93 | |
| 94 // Initialize an EGL context that shares a namespace with another. | |
| 95 bool Initialize(GLContext* shared_context); | 31 bool Initialize(GLContext* shared_context); |
| 96 | 32 |
| 97 // Implement GLContext. | 33 // Implement GLContext. |
| 98 virtual void Destroy(); | 34 virtual void Destroy(); |
| 99 virtual bool MakeCurrent(); | 35 virtual bool MakeCurrent(); |
| 100 virtual bool IsCurrent(); | 36 virtual bool IsCurrent(); |
| 101 virtual bool IsOffscreen(); | 37 virtual bool IsOffscreen(); |
| 102 virtual bool SwapBuffers(); | 38 virtual bool SwapBuffers(); |
| 103 virtual gfx::Size GetSize(); | 39 virtual gfx::Size GetSize(); |
| 104 virtual void* GetHandle(); | 40 virtual void* GetHandle(); |
| 105 virtual void SetSwapInterval(int interval); | 41 virtual void SetSwapInterval(int interval); |
| 106 | 42 virtual std::string GetExtensions(); |
| 107 // Implement BaseEGLContext. | |
| 108 virtual SharedEGLSurface* GetSurface(); | |
| 109 | 43 |
| 110 private: | 44 private: |
| 111 scoped_refptr<SharedEGLSurface> surface_; | 45 scoped_ptr<GLSurfaceEGL> surface_; |
| 112 EGLContext context_; | 46 EGLContext context_; |
| 113 | 47 |
| 114 DISALLOW_COPY_AND_ASSIGN(SecondaryEGLContext); | 48 DISALLOW_COPY_AND_ASSIGN(GLContextEGL); |
| 115 }; | 49 }; |
| 116 | 50 |
| 117 } // namespace gfx | 51 } // namespace gfx |
| 118 | 52 |
| 119 #endif // UI_GFX_GL_GL_CONTEXT_EGL_H_ | 53 #endif // UI_GFX_GL_GL_CONTEXT_EGL_H_ |
| OLD | NEW |