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