| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // This API is consistent with other OpenGL setup APIs like window's WGL | 5 // This API is consistent with other OpenGL setup APIs like window's WGL |
| 6 // and pepper's PGL. This API is used to manage OpenGL RendererGLContexts in the | 6 // and pepper's PGL. This API is used to manage OpenGL ContentGLContexts in the |
| 7 // Chrome renderer process in a way that is consistent with other platforms. | 7 // Chrome renderer process in a way that is consistent with other platforms. |
| 8 | 8 |
| 9 #ifndef CONTENT_RENDERER_GPU_RENDERER_GL_CONTEXT_H_ | 9 #ifndef CONTENT_COMMON_GPU_CLIENT_RENDERER_GL_CONTEXT_H_ |
| 10 #define CONTENT_RENDERER_GPU_RENDERER_GL_CONTEXT_H_ | 10 #define CONTENT_COMMON_GPU_CLIENT_RENDERER_GL_CONTEXT_H_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "ui/gfx/gl/gpu_preference.h" | 19 #include "ui/gfx/gl/gpu_preference.h" |
| 20 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 | 22 |
| 23 class GpuChannelHost; | 23 class GpuChannelHost; |
| 24 class CommandBufferProxy; | 24 class CommandBufferProxy; |
| 25 class GURL; | 25 class GURL; |
| 26 | 26 |
| 27 namespace gpu { | 27 namespace gpu { |
| 28 class TransferBuffer; | 28 class TransferBuffer; |
| 29 namespace gles2 { | 29 namespace gles2 { |
| 30 class GLES2CmdHelper; | 30 class GLES2CmdHelper; |
| 31 class GLES2Implementation; | 31 class GLES2Implementation; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext>, | 35 class ContentGLContext : public base::SupportsWeakPtr<ContentGLContext>, |
| 36 public base::NonThreadSafe { | 36 public base::NonThreadSafe { |
| 37 public: | 37 public: |
| 38 // These are the same error codes as used by EGL. | 38 // These are the same error codes as used by EGL. |
| 39 enum Error { | 39 enum Error { |
| 40 SUCCESS = 0x3000, | 40 SUCCESS = 0x3000, |
| 41 NOT_INITIALIZED = 0x3001, | |
| 42 BAD_ATTRIBUTE = 0x3004, | 41 BAD_ATTRIBUTE = 0x3004, |
| 43 BAD_RendererGLContext = 0x3006, | |
| 44 CONTEXT_LOST = 0x300E | 42 CONTEXT_LOST = 0x300E |
| 45 }; | 43 }; |
| 46 | 44 |
| 47 // RendererGLContext configuration attributes. Those in the 16-bit range are | 45 // ContentGLContext configuration attributes. Those in the 16-bit range are |
| 48 // the same as used by EGL. Those outside the 16-bit range are unique to | 46 // the same as used by EGL. Those outside the 16-bit range are unique to |
| 49 // Chromium. Attributes are matched using a closest fit algorithm. | 47 // Chromium. Attributes are matched using a closest fit algorithm. |
| 50 enum Attribute { | 48 enum Attribute { |
| 51 ALPHA_SIZE = 0x3021, | 49 ALPHA_SIZE = 0x3021, |
| 52 BLUE_SIZE = 0x3022, | 50 BLUE_SIZE = 0x3022, |
| 53 GREEN_SIZE = 0x3023, | 51 GREEN_SIZE = 0x3023, |
| 54 RED_SIZE = 0x3024, | 52 RED_SIZE = 0x3024, |
| 55 DEPTH_SIZE = 0x3025, | 53 DEPTH_SIZE = 0x3025, |
| 56 STENCIL_SIZE = 0x3026, | 54 STENCIL_SIZE = 0x3026, |
| 57 SAMPLES = 0x3031, | 55 SAMPLES = 0x3031, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 // Initialize the library. This must have completed before any other | 76 // Initialize the library. This must have completed before any other |
| 79 // functions are invoked. | 77 // functions are invoked. |
| 80 static bool Initialize(); | 78 static bool Initialize(); |
| 81 | 79 |
| 82 // Terminate the library. This must be called after any other functions | 80 // Terminate the library. This must be called after any other functions |
| 83 // have completed. | 81 // have completed. |
| 84 static bool Terminate(); | 82 static bool Terminate(); |
| 85 | 83 |
| 86 ~RendererGLContext(); | 84 ~ContentGLContext(); |
| 87 | 85 |
| 88 // Create a RendererGLContext that renders directly to a view. The view and | 86 // Create a ContentGLContext that renders directly to a view. The view and |
| 89 // the associated window must not be destroyed until the returned | 87 // the associated window must not be destroyed until the returned |
| 90 // RendererGLContext has been destroyed, otherwise the GPU process might | 88 // ContentGLContext has been destroyed, otherwise the GPU process might |
| 91 // attempt to render to an invalid window handle. | 89 // attempt to render to an invalid window handle. |
| 92 // | 90 // |
| 93 // NOTE: on Mac OS X, this entry point is only used to set up the | 91 // NOTE: on Mac OS X, this entry point is only used to set up the |
| 94 // accelerated compositor's output. On this platform, we actually pass | 92 // accelerated compositor's output. On this platform, we actually pass |
| 95 // a gfx::PluginWindowHandle in place of the gfx::NativeViewId, | 93 // a gfx::PluginWindowHandle in place of the gfx::NativeViewId, |
| 96 // because the facility to allocate a fake PluginWindowHandle is | 94 // because the facility to allocate a fake PluginWindowHandle is |
| 97 // already in place. We could add more entry points and messages to | 95 // already in place. We could add more entry points and messages to |
| 98 // allocate both fake PluginWindowHandles and NativeViewIds and map | 96 // allocate both fake PluginWindowHandles and NativeViewIds and map |
| 99 // from fake NativeViewIds to PluginWindowHandles, but this seems like | 97 // from fake NativeViewIds to PluginWindowHandles, but this seems like |
| 100 // unnecessary complexity at the moment. | 98 // unnecessary complexity at the moment. |
| 101 // | 99 // |
| 102 // The render_view_id is currently also only used on Mac OS X. | 100 // The render_view_id is currently also only used on Mac OS X. |
| 103 // TODO(kbr): clean up the arguments to this function and make them | 101 // TODO(kbr): clean up the arguments to this function and make them |
| 104 // more cross-platform. | 102 // more cross-platform. |
| 105 static RendererGLContext* CreateViewContext( | 103 static ContentGLContext* CreateViewContext( |
| 106 GpuChannelHost* channel, | 104 GpuChannelHost* channel, |
| 107 int32 surface_id, | 105 int32 surface_id, |
| 108 RendererGLContext* share_group, | 106 ContentGLContext* share_group, |
| 109 const char* allowed_extensions, | 107 const char* allowed_extensions, |
| 110 const int32* attrib_list, | 108 const int32* attrib_list, |
| 111 const GURL& active_url, | 109 const GURL& active_url, |
| 112 gfx::GpuPreference gpu_preference); | 110 gfx::GpuPreference gpu_preference); |
| 113 | 111 |
| 114 // Create a RendererGLContext that renders to an offscreen frame buffer. If | 112 // Create a ContentGLContext that renders to an offscreen frame buffer. If |
| 115 // parent is not NULL, that RendererGLContext can access a copy of the created | 113 // parent is not NULL, that ContentGLContext can access a copy of the created |
| 116 // RendererGLContext's frame buffer that is updated every time SwapBuffers is | 114 // ContentGLContext's frame buffer that is updated every time SwapBuffers is |
| 117 // called. It is not as general as shared RendererGLContexts in other | 115 // called. It is not as general as shared ContentGLContexts in other |
| 118 // implementations of OpenGL. If parent is not NULL, it must be used on the | 116 // implementations of OpenGL. If parent is not NULL, it must be used on the |
| 119 // same thread as the parent. A child RendererGLContext may not outlive its | 117 // same thread as the parent. A child ContentGLContext may not outlive its |
| 120 // parent. attrib_list must be NULL or a NONE-terminated list of | 118 // parent. attrib_list must be NULL or a NONE-terminated list of |
| 121 // attribute/value pairs. | 119 // attribute/value pairs. |
| 122 static RendererGLContext* CreateOffscreenContext( | 120 static ContentGLContext* CreateOffscreenContext( |
| 123 GpuChannelHost* channel, | 121 GpuChannelHost* channel, |
| 124 const gfx::Size& size, | 122 const gfx::Size& size, |
| 125 RendererGLContext* share_group, | 123 ContentGLContext* share_group, |
| 126 const char* allowed_extensions, | 124 const char* allowed_extensions, |
| 127 const int32* attrib_list, | 125 const int32* attrib_list, |
| 128 const GURL& active_url, | 126 const GURL& active_url, |
| 129 gfx::GpuPreference gpu_preference); | 127 gfx::GpuPreference gpu_preference); |
| 130 | 128 |
| 131 // Sets the parent context. If any parent textures have been created for | 129 // Sets the parent context. If any parent textures have been created for |
| 132 // another parent, it is important to delete them before changing the parent. | 130 // another parent, it is important to delete them before changing the parent. |
| 133 bool SetParent(RendererGLContext* parent); | 131 bool SetParent(ContentGLContext* parent); |
| 134 | 132 |
| 135 // For an offscreen frame buffer RendererGLContext, return the texture ID with | 133 // For an offscreen frame buffer ContentGLContext, return the texture ID with |
| 136 // respect to the parent RendererGLContext. Returns zero if RendererGLContext | 134 // respect to the parent ContentGLContext. Returns zero if ContentGLContext |
| 137 // does not have a parent. | 135 // does not have a parent. |
| 138 uint32 GetParentTextureId(); | 136 uint32 GetParentTextureId(); |
| 139 | 137 |
| 140 // Create a new texture in the parent's RendererGLContext. Returns zero if | 138 // Create a new texture in the parent's ContentGLContext. Returns zero if |
| 141 // RendererGLContext does not have a parent. | 139 // ContentGLContext does not have a parent. |
| 142 uint32 CreateParentTexture(const gfx::Size& size); | 140 uint32 CreateParentTexture(const gfx::Size& size); |
| 143 | 141 |
| 144 // Deletes a texture in the parent's RendererGLContext. | 142 // Deletes a texture in the parent's ContentGLContext. |
| 145 void DeleteParentTexture(uint32 texture); | 143 void DeleteParentTexture(uint32 texture); |
| 146 | 144 |
| 147 void SetContextLostCallback( | 145 void SetContextLostCallback( |
| 148 const base::Callback<void(ContextLostReason)>& callback); | 146 const base::Callback<void(ContextLostReason)>& callback); |
| 149 | 147 |
| 150 // Set the current RendererGLContext for the calling thread. | 148 // Set the current ContentGLContext for the calling thread. |
| 151 static bool MakeCurrent(RendererGLContext* context); | 149 static bool MakeCurrent(ContentGLContext* context); |
| 152 | 150 |
| 153 // For a view RendererGLContext, display everything that has been rendered | 151 // For a view ContentGLContext, display everything that has been rendered |
| 154 // since the last call. For an offscreen RendererGLContext, resolve everything | 152 // since the last call. For an offscreen ContentGLContext, resolve everything |
| 155 // that has been rendered since the last call to a copy that can be accessed | 153 // that has been rendered since the last call to a copy that can be accessed |
| 156 // by the parent RendererGLContext. | 154 // by the parent ContentGLContext. |
| 157 bool SwapBuffers(); | 155 bool SwapBuffers(); |
| 158 | 156 |
| 159 // Run the task once the channel has been flushed. Takes care of deleting the | 157 // Run the task once the channel has been flushed. Takes care of deleting the |
| 160 // task whether the echo succeeds or not. | 158 // task whether the echo succeeds or not. |
| 161 bool Echo(const base::Closure& task); | 159 bool Echo(const base::Closure& task); |
| 162 | 160 |
| 163 // Sends an IPC message with the new state of surface visibility | 161 // Sends an IPC message with the new state of surface visibility |
| 164 bool SetSurfaceVisible(bool visibility); | 162 bool SetSurfaceVisible(bool visibility); |
| 165 | 163 |
| 166 // TODO(gman): Remove this | 164 // TODO(gman): Remove this |
| 167 void DisableShaderTranslation(); | 165 void DisableShaderTranslation(); |
| 168 | 166 |
| 169 // Allows direct access to the GLES2 implementation so a RendererGLContext | 167 // Allows direct access to the GLES2 implementation so a ContentGLContext |
| 170 // can be used without making it current. | 168 // can be used without making it current. |
| 171 gpu::gles2::GLES2Implementation* GetImplementation(); | 169 gpu::gles2::GLES2Implementation* GetImplementation(); |
| 172 | 170 |
| 173 // Return the current error. | 171 // Return the current error. |
| 174 Error GetError(); | 172 Error GetError(); |
| 175 | 173 |
| 176 // Return true if GPU process reported RendererGLContext lost or there was a | 174 // Return true if GPU process reported ContentGLContext lost or there was a |
| 177 // problem communicating with the GPU process. | 175 // problem communicating with the GPU process. |
| 178 bool IsCommandBufferContextLost(); | 176 bool IsCommandBufferContextLost(); |
| 179 | 177 |
| 180 CommandBufferProxy* GetCommandBufferProxy(); | 178 CommandBufferProxy* GetCommandBufferProxy(); |
| 181 | 179 |
| 182 private: | 180 private: |
| 183 explicit RendererGLContext(GpuChannelHost* channel); | 181 explicit ContentGLContext(GpuChannelHost* channel); |
| 184 | 182 |
| 185 bool Initialize(bool onscreen, | 183 bool Initialize(bool onscreen, |
| 186 int32 surface_id, | 184 int32 surface_id, |
| 187 const gfx::Size& size, | 185 const gfx::Size& size, |
| 188 RendererGLContext* share_group, | 186 ContentGLContext* share_group, |
| 189 const char* allowed_extensions, | 187 const char* allowed_extensions, |
| 190 const int32* attrib_list, | 188 const int32* attrib_list, |
| 191 const GURL& active_url, | 189 const GURL& active_url, |
| 192 gfx::GpuPreference gpu_preference); | 190 gfx::GpuPreference gpu_preference); |
| 193 void Destroy(); | 191 void Destroy(); |
| 194 | 192 |
| 195 void OnContextLost(); | 193 void OnContextLost(); |
| 196 | 194 |
| 197 scoped_refptr<GpuChannelHost> channel_; | 195 scoped_refptr<GpuChannelHost> channel_; |
| 198 base::WeakPtr<RendererGLContext> parent_; | 196 base::WeakPtr<ContentGLContext> parent_; |
| 199 base::Callback<void(ContextLostReason)> context_lost_callback_; | 197 base::Callback<void(ContextLostReason)> context_lost_callback_; |
| 200 uint32 parent_texture_id_; | 198 uint32 parent_texture_id_; |
| 201 CommandBufferProxy* command_buffer_; | 199 CommandBufferProxy* command_buffer_; |
| 202 gpu::gles2::GLES2CmdHelper* gles2_helper_; | 200 gpu::gles2::GLES2CmdHelper* gles2_helper_; |
| 203 gpu::TransferBuffer* transfer_buffer_; | 201 gpu::TransferBuffer* transfer_buffer_; |
| 204 gpu::gles2::GLES2Implementation* gles2_implementation_; | 202 gpu::gles2::GLES2Implementation* gles2_implementation_; |
| 205 Error last_error_; | 203 Error last_error_; |
| 206 int frame_number_; | 204 int frame_number_; |
| 207 | 205 |
| 208 DISALLOW_COPY_AND_ASSIGN(RendererGLContext); | 206 DISALLOW_COPY_AND_ASSIGN(ContentGLContext); |
| 209 }; | 207 }; |
| 210 | 208 |
| 211 #endif // CONTENT_RENDERER_GPU_RENDERER_GL_CONTEXT_H_ | 209 #endif // CONTENT_COMMON_GPU_CLIENT_RENDERER_GL_CONTEXT_H_ |
| OLD | NEW |