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 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "content/renderer/gpu/webgraphicscontext3d_guest.h" |
8 #ifndef GL_GLEXT_PROTOTYPES | 8 |
9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 |
10 #endif | 10 #define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 |
11 #include "third_party/khronos/GLES2/gl2ext.h" | |
12 | 11 |
13 #include <algorithm> | 12 #include <algorithm> |
14 #include <set> | 13 #include <set> |
15 | 14 |
16 #include "base/bind.h" | 15 #include "base/bind.h" |
17 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
18 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
19 #include "base/command_line.h" | 18 #include "base/command_line.h" |
20 #include "base/debug/trace_event.h" | 19 #include "base/debug/trace_event.h" |
21 #include "base/logging.h" | 20 #include "base/logging.h" |
22 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
23 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
24 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
25 #include "content/common/gpu/gpu_memory_allocation.h" | 24 #include "content/common/child_process.h" |
26 #include "content/common/gpu/client/command_buffer_proxy.h" | 25 #include "content/common/gpu/client/command_buffer_proxy.h" |
27 #include "content/common/gpu/client/gpu_channel_host.h" | 26 #include "content/common/gpu/client/gpu_channel_host.h" |
28 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "content/renderer/guest_to_host_channel.h" |
| 29 #include "content/renderer/render_thread_impl.h" |
| 30 #include "content/renderer/render_view_impl.h" |
| 31 #include "gpu/command_buffer/client/gles2_lib.h" |
29 #include "gpu/command_buffer/client/gles2_implementation.h" | 32 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 33 #include "gpu/command_buffer/client/transfer_buffer.h" |
30 #include "gpu/command_buffer/common/constants.h" | 34 #include "gpu/command_buffer/common/constants.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
31 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" | 38 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" |
32 | 39 |
33 static base::LazyInstance<base::Lock>::Leaky | 40 WebGraphicsContext3DGuest::WebGraphicsContext3DGuest( |
34 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; | 41 gpu::CommandBuffer* command_buffer, |
35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > | 42 GuestToHostChannel* channel, |
36 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 43 WebKit::WebView* webview) |
37 | 44 : channel_(channel), |
38 namespace { | 45 initialize_failed_(false), |
39 | 46 web_view_(webview), |
40 void ClearSharedContexts() { | 47 context_lost_callback_(0), |
41 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 48 context_lost_reason_(GL_NO_ERROR), |
42 g_all_shared_contexts.Pointer()->clear(); | 49 swapbuffers_complete_callback_(0), |
| 50 cached_width_(0), |
| 51 cached_height_(0), |
| 52 dead_(false), |
| 53 bound_fbo_(0), |
| 54 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 55 command_buffer_.reset(command_buffer); |
| 56 if (!command_buffer_->Initialize()) { |
| 57 initialize_failed_ = true; |
| 58 return; |
| 59 } |
43 } | 60 } |
44 | 61 |
45 } // namespace anonymous | 62 WebGraphicsContext3DGuest::~WebGraphicsContext3DGuest() { |
46 | |
47 | |
48 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | |
49 int surface_id, | |
50 const GURL& active_url, | |
51 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client) | |
52 : initialize_failed_(false), | |
53 context_(NULL), | |
54 gl_(NULL), | |
55 host_(NULL), | |
56 surface_id_(surface_id), | |
57 active_url_(active_url), | |
58 swap_client_(swap_client), | |
59 memory_allocation_changed_callback_(0), | |
60 context_lost_callback_(0), | |
61 context_lost_reason_(GL_NO_ERROR), | |
62 error_message_callback_(0), | |
63 swapbuffers_complete_callback_(0), | |
64 gpu_preference_(gfx::PreferIntegratedGpu), | |
65 cached_width_(0), | |
66 cached_height_(0), | |
67 bound_fbo_(0), | |
68 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
69 } | 63 } |
70 | 64 |
71 WebGraphicsContext3DCommandBufferImpl:: | 65 bool WebGraphicsContext3DGuest::MaybeInitializeGL() { |
72 ~WebGraphicsContext3DCommandBufferImpl() { | 66 if (gl_.get()) |
73 if (host_) { | 67 return true; |
74 if (host_->WillGpuSwitchOccur(false, gpu_preference_)) { | |
75 host_->ForciblyCloseChannel(); | |
76 ClearSharedContexts(); | |
77 } | |
78 } | |
79 | 68 |
80 { | |
81 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | |
82 g_all_shared_contexts.Pointer()->erase(this); | |
83 } | |
84 delete context_; | |
85 } | |
86 | |
87 bool WebGraphicsContext3DCommandBufferImpl::Initialize( | |
88 const WebGraphicsContext3D::Attributes& attributes) { | |
89 DCHECK(!context_); | |
90 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); | |
91 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); | |
92 if (!factory) | |
93 return false; | |
94 | |
95 // The noExtensions and canRecoverFromContextLoss flags are | |
96 // currently used as hints that we are creating a context on | |
97 // behalf of WebGL or accelerated 2D canvas, respectively. | |
98 if (attributes.noExtensions || !attributes.canRecoverFromContextLoss) | |
99 gpu_preference_ = gfx::PreferDiscreteGpu; | |
100 | |
101 bool retry = false; | |
102 | |
103 // Note similar code in Pepper PlatformContext3DImpl::Init. | |
104 do { | |
105 host_ = factory->EstablishGpuChannelSync( | |
106 content:: | |
107 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); | |
108 if (!host_) | |
109 return false; | |
110 DCHECK(host_->state() == GpuChannelHost::kConnected); | |
111 | |
112 if (!retry) { | |
113 // If the creation of this context requires all contexts for this | |
114 // client to be destroyed on the GPU process side, then drop the | |
115 // channel and recreate it. | |
116 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) { | |
117 host_->ForciblyCloseChannel(); | |
118 ClearSharedContexts(); | |
119 retry = true; | |
120 } | |
121 } else { | |
122 retry = false; | |
123 } | |
124 } while (retry); | |
125 | |
126 const content::GPUInfo& gpu_info = host_->gpu_info(); | |
127 UMA_HISTOGRAM_ENUMERATION( | |
128 "GPU.WebGraphicsContext3D_Init_CanLoseContext", | |
129 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, | |
130 4); | |
131 if (attributes.canRecoverFromContextLoss == false) { | |
132 if (gpu_info.can_lose_context) | |
133 return false; | |
134 } | |
135 | |
136 attributes_ = attributes; | |
137 return true; | |
138 } | |
139 | |
140 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { | |
141 if (context_) | |
142 return true; | |
143 if (initialize_failed_) | 69 if (initialize_failed_) |
144 return false; | 70 return false; |
145 | 71 |
146 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 72 // Create the GLES2 helper, which writes the command buffer protocol. |
| 73 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
| 74 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
| 75 initialize_failed_ = true; |
| 76 return false; |
| 77 } |
| 78 // Map the buffer into the renderer process's address space. |
| 79 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
147 | 80 |
148 // Convert WebGL context creation attributes into ContentGLContext / EGL size | 81 // Create the object exposing the OpenGL API. |
149 // requests. | 82 gl_.reset(new gpu::gles2::GLES2Implementation( |
150 const int alpha_size = attributes_.alpha ? 8 : 0; | 83 gles2_helper_.get(), |
151 const int depth_size = attributes_.depth ? 24 : 0; | 84 transfer_buffer_.get(), |
152 const int stencil_size = attributes_.stencil ? 8 : 0; | 85 false, |
153 const int samples = attributes_.antialias ? 4 : 0; | 86 true)); |
154 const int sample_buffers = attributes_.antialias ? 1 : 0; | |
155 const int32 attribs[] = { | |
156 ContentGLContext::ALPHA_SIZE, alpha_size, | |
157 ContentGLContext::DEPTH_SIZE, depth_size, | |
158 ContentGLContext::STENCIL_SIZE, stencil_size, | |
159 ContentGLContext::SAMPLES, samples, | |
160 ContentGLContext::SAMPLE_BUFFERS, sample_buffers, | |
161 ContentGLContext::SHARE_RESOURCES, attributes_.shareResources ? 1 : 0, | |
162 ContentGLContext::BIND_GENERATES_RESOURCES, 0, | |
163 ContentGLContext::NONE, | |
164 }; | |
165 | 87 |
166 const char* preferred_extensions = "*"; | 88 // TODO(fsamuel): Is this right? |
167 | 89 if (!gl_->Initialize( |
168 // We need to lock g_all_shared_contexts until after ContentGLContext::Create | 90 kTransferBufferSize, |
169 // to ensure that the context we picked for our share group isn't deleted. | 91 kTransferBufferSize, |
170 // (There's also a lock in our destructor.) | 92 kTransferBufferSize)) |
171 { | |
172 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | |
173 ContentGLContext* share_group = NULL; | |
174 if (attributes_.shareResources) { | |
175 share_group = g_all_shared_contexts.Pointer()->empty() ? | |
176 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_; | |
177 } | |
178 | |
179 if (surface_id_) { | |
180 context_ = ContentGLContext::CreateViewContext( | |
181 host_, | |
182 surface_id_, | |
183 share_group, | |
184 preferred_extensions, | |
185 attribs, | |
186 active_url_, | |
187 gpu_preference_); | |
188 } else { | |
189 context_ = ContentGLContext::CreateOffscreenContext( | |
190 host_, | |
191 gfx::Size(1, 1), | |
192 share_group, | |
193 preferred_extensions, | |
194 attribs, | |
195 active_url_, | |
196 gpu_preference_); | |
197 } | |
198 } | |
199 | |
200 if (!context_) | |
201 return false; | 93 return false; |
202 | 94 |
203 gl_ = context_->GetImplementation(); | 95 if (!channel_->BindGraphics()) { |
204 | 96 initialize_failed_ = true; |
205 // TODO(twiz): This code is too fragile in that it assumes that only WebGL | 97 return false; |
206 // contexts will request noExtensions. | |
207 if (gl_ && attributes_.noExtensions) | |
208 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | |
209 | |
210 context_->SetContextLostCallback( | |
211 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, | |
212 weak_ptr_factory_.GetWeakPtr())); | |
213 | |
214 context_->GetCommandBufferProxy()->SetOnConsoleMessageCallback( | |
215 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage, | |
216 weak_ptr_factory_.GetWeakPtr())); | |
217 | |
218 // TODO(gman): Remove this. | |
219 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
220 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { | |
221 context_->DisableShaderTranslation(); | |
222 } | 98 } |
223 | |
224 // Set attributes_ from created offscreen context. | 99 // Set attributes_ from created offscreen context. |
225 { | 100 { |
226 GLint alpha_bits = 0; | 101 GLint alpha_bits = 0; |
227 getIntegerv(GL_ALPHA_BITS, &alpha_bits); | 102 getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
228 attributes_.alpha = alpha_bits > 0; | 103 attributes_.alpha = alpha_bits > 0; |
229 GLint depth_bits = 0; | 104 GLint depth_bits = 0; |
230 getIntegerv(GL_DEPTH_BITS, &depth_bits); | 105 getIntegerv(GL_DEPTH_BITS, &depth_bits); |
231 attributes_.depth = depth_bits > 0; | 106 attributes_.depth = depth_bits > 0; |
232 GLint stencil_bits = 0; | 107 GLint stencil_bits = 0; |
233 getIntegerv(GL_STENCIL_BITS, &stencil_bits); | 108 getIntegerv(GL_STENCIL_BITS, &stencil_bits); |
234 attributes_.stencil = stencil_bits > 0; | 109 attributes_.stencil = stencil_bits > 0; |
235 GLint samples = 0; | 110 GLint samples = 0; |
236 getIntegerv(GL_SAMPLES, &samples); | 111 getIntegerv(GL_SAMPLES, &samples); |
237 attributes_.antialias = samples > 0; | 112 attributes_.antialias = samples > 0; |
238 } | 113 } |
239 | 114 |
240 if (attributes_.shareResources) { | |
241 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | |
242 g_all_shared_contexts.Pointer()->insert(this); | |
243 } | |
244 | |
245 context_->SetMemoryAllocationChangedCallback(base::Bind( | |
246 &WebGraphicsContext3DCommandBufferImpl::OnMemoryAllocationChanged, | |
247 weak_ptr_factory_.GetWeakPtr())); | |
248 | |
249 return true; | 115 return true; |
250 } | 116 } |
251 | 117 |
252 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { | 118 bool WebGraphicsContext3DGuest::makeContextCurrent() { |
253 if (!MaybeInitializeGL()) | 119 if (!MaybeInitializeGL()) |
254 return false; | 120 return false; |
255 return ContentGLContext::MakeCurrent(context_); | 121 gles2::SetGLContext(gl_.get()); |
| 122 |
| 123 // Don't request latest error status from service. Just use the locally |
| 124 // cached information from the last flush. |
| 125 // TODO(apatrick): I'm not sure if this should actually change the |
| 126 // current context if it fails. For now it gets changed even if it fails |
| 127 // because making GL calls with a NULL context crashes. |
| 128 if (command_buffer_->GetLastState().error != gpu::error::kNoError) |
| 129 return false; |
| 130 return true; |
256 } | 131 } |
257 | 132 |
258 int WebGraphicsContext3DCommandBufferImpl::width() { | 133 int WebGraphicsContext3DGuest::width() { |
259 return cached_width_; | 134 return cached_width_; |
260 } | 135 } |
261 | 136 |
262 int WebGraphicsContext3DCommandBufferImpl::height() { | 137 int WebGraphicsContext3DGuest::height() { |
263 return cached_height_; | 138 return cached_height_; |
264 } | 139 } |
265 | 140 |
266 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() { | 141 void WebGraphicsContext3DGuest::playDead() { |
| 142 dead_ = true; |
| 143 OnContextLost(); |
| 144 } |
| 145 |
| 146 bool WebGraphicsContext3DGuest::isGLES2Compliant() { |
267 return true; | 147 return true; |
268 } | 148 } |
269 | 149 |
270 bool WebGraphicsContext3DCommandBufferImpl::setParentContext( | 150 bool WebGraphicsContext3DGuest::setParentContext( |
271 WebGraphicsContext3D* parent_context) { | 151 WebGraphicsContext3D* parent_context) { |
272 WebGraphicsContext3DCommandBufferImpl* parent_context_impl = | 152 NOTIMPLEMENTED(); |
273 static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context); | 153 return true; |
274 return context_->SetParent( | |
275 parent_context_impl ? parent_context_impl->context() : NULL); | |
276 } | 154 } |
277 | 155 |
278 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { | 156 WebGLId WebGraphicsContext3DGuest::getPlatformTextureId() { |
279 return context_->GetParentTextureId(); | 157 NOTIMPLEMENTED(); |
| 158 return 0; |
280 } | 159 } |
281 | 160 |
282 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { | 161 void WebGraphicsContext3DGuest::prepareTexture() { |
283 // Copies the contents of the off-screen render target into the texture | 162 // Copies the contents of the off-screen render target into the texture |
284 // used by the compositor. | 163 // used by the compositor. |
285 if (ShouldUseSwapClient()) | 164 RenderViewImpl* renderview = |
286 swap_client_->OnViewContextSwapBuffersPosted(); | 165 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; |
287 context_->SwapBuffers(); | 166 if (renderview) |
288 context_->Echo(base::Bind( | 167 renderview->OnViewContextSwapBuffersPosted(); |
289 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete, | 168 |
290 weak_ptr_factory_.GetWeakPtr())); | 169 // Swap buffers |
| 170 gl_->SwapBuffers(); |
| 171 channel_->IssueSwapBuffers(); |
| 172 // TODO(fsamuel): GuestToHostChannel will call OnSwapBuffersComplete |
| 173 // when it receives a swap buffers ACK message from the host. |
291 #if defined(OS_MACOSX) | 174 #if defined(OS_MACOSX) |
292 // It appears that making the compositor's on-screen context current on | 175 // It appears that making the compositor's on-screen context current on |
293 // other platforms implies this flush. TODO(kbr): this means that the | 176 // other platforms implies this flush. TODO(kbr): this means that the |
294 // TOUCH build and, in the future, other platforms might need this. | 177 // TOUCH build and, in the future, other platforms might need this. |
295 gl_->Flush(); | 178 gl_->Flush(); |
296 #endif | 179 #endif |
297 } | 180 } |
298 | 181 |
299 void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM( | 182 void WebGraphicsContext3DGuest::postSubBufferCHROMIUM( |
300 int x, int y, int width, int height) { | 183 int x, int y, int width, int height) { |
301 // Same flow control as WebGraphicsContext3DCommandBufferImpl::prepareTexture | 184 // Same flow control as WebGraphicsContext3DGuest::prepareTexture |
302 // (see above). | 185 // (see above). |
303 if (ShouldUseSwapClient()) | 186 RenderViewImpl* renderview = |
304 swap_client_->OnViewContextSwapBuffersPosted(); | 187 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; |
| 188 if (renderview) |
| 189 renderview->OnViewContextSwapBuffersPosted(); |
305 gl_->PostSubBufferCHROMIUM(x, y, width, height); | 190 gl_->PostSubBufferCHROMIUM(x, y, width, height); |
306 context_->Echo(base::Bind( | 191 channel_->IssueSwapBuffers(); |
307 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete, | |
308 weak_ptr_factory_.GetWeakPtr())); | |
309 } | 192 } |
310 | 193 |
311 void WebGraphicsContext3DCommandBufferImpl::reshape(int width, int height) { | 194 void WebGraphicsContext3DGuest::reshape(int width, int height) { |
312 cached_width_ = width; | 195 cached_width_ = width; |
313 cached_height_ = height; | 196 cached_height_ = height; |
314 | 197 |
315 gl_->ResizeCHROMIUM(width, height); | 198 gl_->ResizeCHROMIUM(width, height); |
| 199 |
| 200 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
| 201 scanline_.reset(new uint8[width * 4]); |
| 202 #endif // FLIP_FRAMEBUFFER_VERTICALLY |
316 } | 203 } |
317 | 204 |
318 #ifdef FLIP_FRAMEBUFFER_VERTICALLY | 205 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
319 void WebGraphicsContext3DCommandBufferImpl::FlipVertically( | 206 void WebGraphicsContext3DGuest::FlipVertically( |
320 uint8* framebuffer, | 207 uint8* framebuffer, |
321 unsigned int width, | 208 unsigned int width, |
322 unsigned int height) { | 209 unsigned int height) { |
323 if (width == 0) | 210 uint8* scanline = scanline_.get(); |
| 211 if (!scanline) |
324 return; | 212 return; |
325 scanline_.resize(width * 4); | |
326 uint8* scanline = &scanline_[0]; | |
327 unsigned int row_bytes = width * 4; | 213 unsigned int row_bytes = width * 4; |
328 unsigned int count = height / 2; | 214 unsigned int count = height / 2; |
329 for (unsigned int i = 0; i < count; i++) { | 215 for (unsigned int i = 0; i < count; i++) { |
330 uint8* row_a = framebuffer + i * row_bytes; | 216 uint8* row_a = framebuffer + i * row_bytes; |
331 uint8* row_b = framebuffer + (height - i - 1) * row_bytes; | 217 uint8* row_b = framebuffer + (height - i - 1) * row_bytes; |
332 // TODO(kbr): this is where the multiplication of the alpha | 218 // TODO(kbr): this is where the multiplication of the alpha |
333 // channel into the color buffer will need to occur if the | 219 // channel into the color buffer will need to occur if the |
334 // user specifies the "premultiplyAlpha" flag in the context | 220 // user specifies the "premultiplyAlpha" flag in the context |
335 // creation attributes. | 221 // creation attributes. |
336 memcpy(scanline, row_b, row_bytes); | 222 memcpy(scanline, row_b, row_bytes); |
337 memcpy(row_b, row_a, row_bytes); | 223 memcpy(row_b, row_a, row_bytes); |
338 memcpy(row_a, scanline, row_bytes); | 224 memcpy(row_a, scanline, row_bytes); |
339 } | 225 } |
340 } | 226 } |
341 #endif | 227 #endif |
342 | 228 |
343 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer( | 229 bool WebGraphicsContext3DGuest::readBackFramebuffer( |
344 unsigned char* pixels, | 230 unsigned char* pixels, |
345 size_t buffer_size, | 231 size_t buffer_size, |
346 WebGLId buffer, | 232 WebGLId buffer, |
347 int width, | 233 int width, |
348 int height) { | 234 int height) { |
349 if (buffer_size != static_cast<size_t>(4 * width * height)) { | 235 if (buffer_size != static_cast<size_t>(4 * width * height)) { |
350 return false; | 236 return false; |
351 } | 237 } |
352 | 238 |
353 // Earlier versions of this code used the GPU to flip the | 239 // Earlier versions of this code used the GPU to flip the |
(...skipping 21 matching lines...) Expand all Loading... |
375 | 261 |
376 #ifdef FLIP_FRAMEBUFFER_VERTICALLY | 262 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
377 if (pixels) { | 263 if (pixels) { |
378 FlipVertically(pixels, width, height); | 264 FlipVertically(pixels, width, height); |
379 } | 265 } |
380 #endif | 266 #endif |
381 | 267 |
382 return true; | 268 return true; |
383 } | 269 } |
384 | 270 |
385 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer( | 271 bool WebGraphicsContext3DGuest::readBackFramebuffer( |
386 unsigned char* pixels, | 272 unsigned char* pixels, |
387 size_t buffer_size) { | 273 size_t buffer_size) { |
388 return readBackFramebuffer(pixels, buffer_size, 0, width(), height()); | 274 return readBackFramebuffer(pixels, buffer_size, 0, width(), height()); |
389 } | 275 } |
390 | 276 |
391 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError( | 277 void WebGraphicsContext3DGuest::synthesizeGLError( |
392 WGC3Denum error) { | 278 WGC3Denum error) { |
393 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == | 279 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == |
394 synthetic_errors_.end()) { | 280 synthetic_errors_.end()) { |
395 synthetic_errors_.push_back(error); | 281 synthetic_errors_.push_back(error); |
396 } | 282 } |
397 } | 283 } |
398 | 284 |
399 void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM( | 285 void* WebGraphicsContext3DGuest::mapBufferSubDataCHROMIUM( |
400 WGC3Denum target, | 286 WGC3Denum target, |
401 WGC3Dintptr offset, | 287 WGC3Dintptr offset, |
402 WGC3Dsizeiptr size, | 288 WGC3Dsizeiptr size, |
403 WGC3Denum access) { | 289 WGC3Denum access) { |
404 return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access); | 290 return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access); |
405 } | 291 } |
406 | 292 |
407 void WebGraphicsContext3DCommandBufferImpl::unmapBufferSubDataCHROMIUM( | 293 void WebGraphicsContext3DGuest::unmapBufferSubDataCHROMIUM( |
408 const void* mem) { | 294 const void* mem) { |
409 return gl_->UnmapBufferSubDataCHROMIUM(mem); | 295 return gl_->UnmapBufferSubDataCHROMIUM(mem); |
410 } | 296 } |
411 | 297 |
412 void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM( | 298 void* WebGraphicsContext3DGuest::mapTexSubImage2DCHROMIUM( |
413 WGC3Denum target, | 299 WGC3Denum target, |
414 WGC3Dint level, | 300 WGC3Dint level, |
415 WGC3Dint xoffset, | 301 WGC3Dint xoffset, |
416 WGC3Dint yoffset, | 302 WGC3Dint yoffset, |
417 WGC3Dsizei width, | 303 WGC3Dsizei width, |
418 WGC3Dsizei height, | 304 WGC3Dsizei height, |
419 WGC3Denum format, | 305 WGC3Denum format, |
420 WGC3Denum type, | 306 WGC3Denum type, |
421 WGC3Denum access) { | 307 WGC3Denum access) { |
422 return gl_->MapTexSubImage2DCHROMIUM( | 308 return gl_->MapTexSubImage2DCHROMIUM( |
423 target, level, xoffset, yoffset, width, height, format, type, access); | 309 target, level, xoffset, yoffset, width, height, format, type, access); |
424 } | 310 } |
425 | 311 |
426 void WebGraphicsContext3DCommandBufferImpl::unmapTexSubImage2DCHROMIUM( | 312 void WebGraphicsContext3DGuest::unmapTexSubImage2DCHROMIUM( |
427 const void* mem) { | 313 const void* mem) { |
428 gl_->UnmapTexSubImage2DCHROMIUM(mem); | 314 gl_->UnmapTexSubImage2DCHROMIUM(mem); |
429 } | 315 } |
430 | 316 |
431 void WebGraphicsContext3DCommandBufferImpl::setVisibilityCHROMIUM( | 317 void WebGraphicsContext3DGuest::setVisibilityCHROMIUM( |
432 bool visible) { | 318 bool visible) { |
433 gl_->Flush(); | 319 gl_->Flush(); |
434 context_->SetSurfaceVisible(visible); | 320 // TODO(fsamuel): There doesn't seem to be an equivalent ppapi |
| 321 // message. Do we care? |
| 322 //context_->SetSurfaceVisible(visible); |
435 if (!visible) | 323 if (!visible) |
436 gl_->FreeEverything(); | 324 gl_->FreeEverything(); |
437 } | 325 } |
438 | 326 |
439 void WebGraphicsContext3DCommandBufferImpl:: | 327 void WebGraphicsContext3DGuest::copyTextureToParentTextureCHROMIUM( |
440 setMemoryAllocationChangedCallbackCHROMIUM( | |
441 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) { | |
442 memory_allocation_changed_callback_ = callback; | |
443 } | |
444 | |
445 | |
446 void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM( | |
447 WebGLId texture, WebGLId parentTexture) { | 328 WebGLId texture, WebGLId parentTexture) { |
448 NOTIMPLEMENTED(); | 329 NOTIMPLEMENTED(); |
449 } | 330 } |
450 | 331 |
451 void WebGraphicsContext3DCommandBufferImpl:: | 332 void WebGraphicsContext3DGuest:: |
452 rateLimitOffscreenContextCHROMIUM() { | 333 rateLimitOffscreenContextCHROMIUM() { |
453 gl_->RateLimitOffscreenContextCHROMIUM(); | 334 gl_->RateLimitOffscreenContextCHROMIUM(); |
454 } | 335 } |
455 | 336 |
456 WebKit::WebString WebGraphicsContext3DCommandBufferImpl:: | 337 WebKit::WebString WebGraphicsContext3DGuest:: |
457 getRequestableExtensionsCHROMIUM() { | 338 getRequestableExtensionsCHROMIUM() { |
458 return WebKit::WebString::fromUTF8( | 339 return WebKit::WebString::fromUTF8( |
459 gl_->GetRequestableExtensionsCHROMIUM()); | 340 gl_->GetRequestableExtensionsCHROMIUM()); |
460 } | 341 } |
461 | 342 |
462 void WebGraphicsContext3DCommandBufferImpl::requestExtensionCHROMIUM( | 343 void WebGraphicsContext3DGuest::requestExtensionCHROMIUM( |
463 const char* extension) { | 344 const char* extension) { |
464 gl_->RequestExtensionCHROMIUM(extension); | 345 gl_->RequestExtensionCHROMIUM(extension); |
465 } | 346 } |
466 | 347 |
467 void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM( | 348 void WebGraphicsContext3DGuest::blitFramebufferCHROMIUM( |
468 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, | 349 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, |
469 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, | 350 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, |
470 WGC3Dbitfield mask, WGC3Denum filter) { | 351 WGC3Dbitfield mask, WGC3Denum filter) { |
471 gl_->BlitFramebufferEXT( | 352 gl_->BlitFramebufferEXT( |
472 srcX0, srcY0, srcX1, srcY1, | 353 srcX0, srcY0, srcX1, srcY1, |
473 dstX0, dstY0, dstX1, dstY1, | 354 dstX0, dstY0, dstX1, dstY1, |
474 mask, filter); | 355 mask, filter); |
475 } | 356 } |
476 | 357 |
477 void WebGraphicsContext3DCommandBufferImpl:: | 358 void WebGraphicsContext3DGuest:: |
478 renderbufferStorageMultisampleCHROMIUM( | 359 renderbufferStorageMultisampleCHROMIUM( |
479 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, | 360 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, |
480 WGC3Dsizei width, WGC3Dsizei height) { | 361 WGC3Dsizei width, WGC3Dsizei height) { |
481 gl_->RenderbufferStorageMultisampleEXT( | 362 gl_->RenderbufferStorageMultisampleEXT( |
482 target, samples, internalformat, width, height); | 363 target, samples, internalformat, width, height); |
483 } | 364 } |
484 | 365 |
485 // Helper macros to reduce the amount of code. | 366 // Helper macros to reduce the amount of code. |
486 | 367 |
487 #define DELEGATE_TO_GL(name, glname) \ | 368 #define DELEGATE_TO_GL(name, glname) \ |
488 void WebGraphicsContext3DCommandBufferImpl::name() { \ | 369 void WebGraphicsContext3DGuest::name() { \ |
489 gl_->glname(); \ | 370 gl_->glname(); \ |
490 } | 371 } |
491 | 372 |
492 #define DELEGATE_TO_GL_1(name, glname, t1) \ | 373 #define DELEGATE_TO_GL_1(name, glname, t1) \ |
493 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \ | 374 void WebGraphicsContext3DGuest::name(t1 a1) { \ |
494 gl_->glname(a1); \ | 375 gl_->glname(a1); \ |
495 } | 376 } |
496 | 377 |
497 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \ | 378 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \ |
498 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \ | 379 rt WebGraphicsContext3DGuest::name(t1 a1) { \ |
499 return gl_->glname(a1); \ | 380 return gl_->glname(a1); \ |
500 } | 381 } |
501 | 382 |
502 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \ | 383 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \ |
503 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \ | 384 rt WebGraphicsContext3DGuest::name(t1 a1) { \ |
504 return gl_->glname(a1) ? true : false; \ | 385 return gl_->glname(a1) ? true : false; \ |
505 } | 386 } |
506 | 387 |
507 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \ | 388 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \ |
508 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \ | 389 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2) { \ |
509 gl_->glname(a1, a2); \ | 390 gl_->glname(a1, a2); \ |
510 } | 391 } |
511 | 392 |
512 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \ | 393 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \ |
513 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \ | 394 rt WebGraphicsContext3DGuest::name(t1 a1, t2 a2) { \ |
514 return gl_->glname(a1, a2); \ | 395 return gl_->glname(a1, a2); \ |
515 } | 396 } |
516 | 397 |
517 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \ | 398 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \ |
518 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \ | 399 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3) { \ |
519 gl_->glname(a1, a2, a3); \ | 400 gl_->glname(a1, a2, a3); \ |
520 } | 401 } |
521 | 402 |
522 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ | 403 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ |
523 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \ | 404 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, t4 a4) { \ |
524 gl_->glname(a1, a2, a3, a4); \ | 405 gl_->glname(a1, a2, a3, a4); \ |
525 } | 406 } |
526 | 407 |
527 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \ | 408 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \ |
528 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \ | 409 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, \ |
529 t4 a4, t5 a5) { \ | 410 t4 a4, t5 a5) { \ |
530 gl_->glname(a1, a2, a3, a4, a5); \ | 411 gl_->glname(a1, a2, a3, a4, a5); \ |
531 } | 412 } |
532 | 413 |
533 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \ | 414 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \ |
534 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \ | 415 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, \ |
535 t4 a4, t5 a5, t6 a6) { \ | 416 t4 a4, t5 a5, t6 a6) { \ |
536 gl_->glname(a1, a2, a3, a4, a5, a6); \ | 417 gl_->glname(a1, a2, a3, a4, a5, a6); \ |
537 } | 418 } |
538 | 419 |
539 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \ | 420 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \ |
540 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \ | 421 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, \ |
541 t4 a4, t5 a5, t6 a6, t7 a7) { \ | 422 t4 a4, t5 a5, t6 a6, t7 a7) { \ |
542 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \ | 423 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \ |
543 } | 424 } |
544 | 425 |
545 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \ | 426 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \ |
546 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \ | 427 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, \ |
547 t4 a4, t5 a5, t6 a6, \ | 428 t4 a4, t5 a5, t6 a6, \ |
548 t7 a7, t8 a8) { \ | 429 t7 a7, t8 a8) { \ |
549 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \ | 430 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \ |
550 } | 431 } |
551 | 432 |
552 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ | 433 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
553 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \ | 434 void WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, \ |
554 t4 a4, t5 a5, t6 a6, \ | 435 t4 a4, t5 a5, t6 a6, \ |
555 t7 a7, t8 a8, t9 a9) { \ | 436 t7 a7, t8 a8, t9 a9) { \ |
556 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 437 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
557 } | 438 } |
558 | 439 |
559 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum) | 440 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum) |
560 | 441 |
561 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId) | 442 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId) |
562 | 443 |
563 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId, | 444 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId, |
564 WGC3Duint, const WGC3Dchar*) | 445 WGC3Duint, const WGC3Dchar*) |
565 | 446 |
566 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId) | 447 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId) |
567 | 448 |
568 void WebGraphicsContext3DCommandBufferImpl::bindFramebuffer( | 449 void WebGraphicsContext3DGuest::bindFramebuffer( |
569 WGC3Denum target, | 450 WGC3Denum target, |
570 WebGLId framebuffer) { | 451 WebGLId framebuffer) { |
571 gl_->BindFramebuffer(target, framebuffer); | 452 gl_->BindFramebuffer(target, framebuffer); |
572 bound_fbo_ = framebuffer; | 453 bound_fbo_ = framebuffer; |
573 } | 454 } |
574 | 455 |
575 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId) | 456 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId) |
576 | 457 |
577 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId) | 458 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId) |
578 | 459 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 519 |
639 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId) | 520 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId) |
640 | 521 |
641 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum) | 522 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum) |
642 | 523 |
643 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray, | 524 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray, |
644 WGC3Duint) | 525 WGC3Duint) |
645 | 526 |
646 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei) | 527 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei) |
647 | 528 |
648 void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode, | 529 void WebGraphicsContext3DGuest::drawElements(WGC3Denum mode, |
649 WGC3Dsizei count, | 530 WGC3Dsizei count, |
650 WGC3Denum type, | 531 WGC3Denum type, |
651 WGC3Dintptr offset) { | 532 WGC3Dintptr offset) { |
652 gl_->DrawElements( | 533 gl_->DrawElements( |
653 mode, count, type, | 534 mode, count, type, |
654 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); | 535 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); |
655 } | 536 } |
656 | 537 |
657 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum) | 538 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum) |
658 | 539 |
659 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray, | 540 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray, |
660 WGC3Duint) | 541 WGC3Duint) |
661 | 542 |
662 DELEGATE_TO_GL(finish, Finish) | 543 DELEGATE_TO_GL(finish, Finish) |
663 | 544 |
664 DELEGATE_TO_GL(flush, Flush) | 545 DELEGATE_TO_GL(flush, Flush) |
665 | 546 |
666 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer, | 547 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer, |
667 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId) | 548 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId) |
668 | 549 |
669 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D, | 550 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D, |
670 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint) | 551 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint) |
671 | 552 |
672 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum) | 553 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum) |
673 | 554 |
674 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum) | 555 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum) |
675 | 556 |
676 bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib( | 557 bool WebGraphicsContext3DGuest::getActiveAttrib( |
677 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 558 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
678 if (!program) { | 559 if (!program) { |
679 synthesizeGLError(GL_INVALID_VALUE); | 560 synthesizeGLError(GL_INVALID_VALUE); |
680 return false; | 561 return false; |
681 } | 562 } |
682 GLint max_name_length = -1; | 563 GLint max_name_length = -1; |
683 gl_->GetProgramiv( | 564 gl_->GetProgramiv( |
684 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); | 565 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); |
685 if (max_name_length < 0) | 566 if (max_name_length < 0) |
686 return false; | 567 return false; |
687 scoped_array<GLchar> name(new GLchar[max_name_length]); | 568 scoped_array<GLchar> name(new GLchar[max_name_length]); |
688 if (!name.get()) { | 569 if (!name.get()) { |
689 synthesizeGLError(GL_OUT_OF_MEMORY); | 570 synthesizeGLError(GL_OUT_OF_MEMORY); |
690 return false; | 571 return false; |
691 } | 572 } |
692 GLsizei length = 0; | 573 GLsizei length = 0; |
693 GLint size = -1; | 574 GLint size = -1; |
694 GLenum type = 0; | 575 GLenum type = 0; |
695 gl_->GetActiveAttrib( | 576 gl_->GetActiveAttrib( |
696 program, index, max_name_length, &length, &size, &type, name.get()); | 577 program, index, max_name_length, &length, &size, &type, name.get()); |
697 if (size < 0) { | 578 if (size < 0) { |
698 return false; | 579 return false; |
699 } | 580 } |
700 info.name = WebKit::WebString::fromUTF8(name.get(), length); | 581 info.name = WebKit::WebString::fromUTF8(name.get(), length); |
701 info.type = type; | 582 info.type = type; |
702 info.size = size; | 583 info.size = size; |
703 return true; | 584 return true; |
704 } | 585 } |
705 | 586 |
706 bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform( | 587 bool WebGraphicsContext3DGuest::getActiveUniform( |
707 WebGLId program, WGC3Duint index, ActiveInfo& info) { | 588 WebGLId program, WGC3Duint index, ActiveInfo& info) { |
708 GLint max_name_length = -1; | 589 GLint max_name_length = -1; |
709 gl_->GetProgramiv( | 590 gl_->GetProgramiv( |
710 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); | 591 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); |
711 if (max_name_length < 0) | 592 if (max_name_length < 0) |
712 return false; | 593 return false; |
713 scoped_array<GLchar> name(new GLchar[max_name_length]); | 594 scoped_array<GLchar> name(new GLchar[max_name_length]); |
714 if (!name.get()) { | 595 if (!name.get()) { |
715 synthesizeGLError(GL_OUT_OF_MEMORY); | 596 synthesizeGLError(GL_OUT_OF_MEMORY); |
716 return false; | 597 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
734 | 615 |
735 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation, | 616 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation, |
736 WebGLId, const WGC3Dchar*, WGC3Dint) | 617 WebGLId, const WGC3Dchar*, WGC3Dint) |
737 | 618 |
738 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*) | 619 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*) |
739 | 620 |
740 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv, | 621 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv, |
741 WGC3Denum, WGC3Denum, WGC3Dint*) | 622 WGC3Denum, WGC3Denum, WGC3Dint*) |
742 | 623 |
743 WebKit::WebGraphicsContext3D::Attributes | 624 WebKit::WebGraphicsContext3D::Attributes |
744 WebGraphicsContext3DCommandBufferImpl::getContextAttributes() { | 625 WebGraphicsContext3DGuest::getContextAttributes() { |
745 return attributes_; | 626 return attributes_; |
746 } | 627 } |
747 | 628 |
748 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() { | 629 WGC3Denum WebGraphicsContext3DGuest::getError() { |
749 if (!synthetic_errors_.empty()) { | 630 if (!synthetic_errors_.empty()) { |
750 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); | 631 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); |
751 WGC3Denum err = *iter; | 632 WGC3Denum err = *iter; |
752 synthetic_errors_.erase(iter); | 633 synthetic_errors_.erase(iter); |
753 return err; | 634 return err; |
754 } | 635 } |
755 | 636 |
756 return gl_->GetError(); | 637 return gl_->GetError(); |
757 } | 638 } |
758 | 639 |
759 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() { | 640 bool WebGraphicsContext3DGuest::isContextLost() { |
760 return initialize_failed_ || | 641 // TODO(fsamuel): Context is assumed to be never lost |
761 (context_ && context_->IsCommandBufferContextLost()) || | 642 // until I find a cleaner way to do this. |
762 context_lost_reason_ != GL_NO_ERROR; | 643 return dead_ || initialize_failed_; |
763 } | 644 } |
764 | 645 |
765 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*) | 646 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*) |
766 | 647 |
767 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv, | 648 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv, |
768 GetFramebufferAttachmentParameteriv, | 649 GetFramebufferAttachmentParameteriv, |
769 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*) | 650 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*) |
770 | 651 |
771 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*) | 652 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*) |
772 | 653 |
773 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*) | 654 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*) |
774 | 655 |
775 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog( | 656 WebKit::WebString WebGraphicsContext3DGuest::getProgramInfoLog( |
776 WebGLId program) { | 657 WebGLId program) { |
777 GLint logLength = 0; | 658 GLint logLength = 0; |
778 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); | 659 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); |
779 if (!logLength) | 660 if (!logLength) |
780 return WebKit::WebString(); | 661 return WebKit::WebString(); |
781 scoped_array<GLchar> log(new GLchar[logLength]); | 662 scoped_array<GLchar> log(new GLchar[logLength]); |
782 if (!log.get()) | 663 if (!log.get()) |
783 return WebKit::WebString(); | 664 return WebKit::WebString(); |
784 GLsizei returnedLogLength = 0; | 665 GLsizei returnedLogLength = 0; |
785 gl_->GetProgramInfoLog( | 666 gl_->GetProgramInfoLog( |
786 program, logLength, &returnedLogLength, log.get()); | 667 program, logLength, &returnedLogLength, log.get()); |
787 DCHECK_EQ(logLength, returnedLogLength + 1); | 668 DCHECK_EQ(logLength, returnedLogLength + 1); |
788 WebKit::WebString res = | 669 WebKit::WebString res = |
789 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); | 670 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); |
790 return res; | 671 return res; |
791 } | 672 } |
792 | 673 |
793 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv, | 674 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv, |
794 WGC3Denum, WGC3Denum, WGC3Dint*) | 675 WGC3Denum, WGC3Denum, WGC3Dint*) |
795 | 676 |
796 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*) | 677 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*) |
797 | 678 |
798 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog( | 679 WebKit::WebString WebGraphicsContext3DGuest::getShaderInfoLog( |
799 WebGLId shader) { | 680 WebGLId shader) { |
800 GLint logLength = 0; | 681 GLint logLength = 0; |
801 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); | 682 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); |
802 if (!logLength) | 683 if (!logLength) |
803 return WebKit::WebString(); | 684 return WebKit::WebString(); |
804 scoped_array<GLchar> log(new GLchar[logLength]); | 685 scoped_array<GLchar> log(new GLchar[logLength]); |
805 if (!log.get()) | 686 if (!log.get()) |
806 return WebKit::WebString(); | 687 return WebKit::WebString(); |
807 GLsizei returnedLogLength = 0; | 688 GLsizei returnedLogLength = 0; |
808 gl_->GetShaderInfoLog( | 689 gl_->GetShaderInfoLog( |
809 shader, logLength, &returnedLogLength, log.get()); | 690 shader, logLength, &returnedLogLength, log.get()); |
810 DCHECK_EQ(logLength, returnedLogLength + 1); | 691 DCHECK_EQ(logLength, returnedLogLength + 1); |
811 WebKit::WebString res = | 692 WebKit::WebString res = |
812 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); | 693 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); |
813 return res; | 694 return res; |
814 } | 695 } |
815 | 696 |
816 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource( | 697 WebKit::WebString WebGraphicsContext3DGuest::getShaderSource( |
817 WebGLId shader) { | 698 WebGLId shader) { |
818 GLint logLength = 0; | 699 GLint logLength = 0; |
819 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); | 700 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); |
820 if (!logLength) | 701 if (!logLength) |
821 return WebKit::WebString(); | 702 return WebKit::WebString(); |
822 scoped_array<GLchar> log(new GLchar[logLength]); | 703 scoped_array<GLchar> log(new GLchar[logLength]); |
823 if (!log.get()) | 704 if (!log.get()) |
824 return WebKit::WebString(); | 705 return WebKit::WebString(); |
825 GLsizei returnedLogLength = 0; | 706 GLsizei returnedLogLength = 0; |
826 gl_->GetShaderSource( | 707 gl_->GetShaderSource( |
827 shader, logLength, &returnedLogLength, log.get()); | 708 shader, logLength, &returnedLogLength, log.get()); |
828 if (!returnedLogLength) | 709 if (!returnedLogLength) |
829 return WebKit::WebString(); | 710 return WebKit::WebString(); |
830 DCHECK_EQ(logLength, returnedLogLength + 1); | 711 DCHECK_EQ(logLength, returnedLogLength + 1); |
831 WebKit::WebString res = | 712 WebKit::WebString res = |
832 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); | 713 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); |
833 return res; | 714 return res; |
834 } | 715 } |
835 | 716 |
836 WebKit::WebString WebGraphicsContext3DCommandBufferImpl:: | 717 WebKit::WebString WebGraphicsContext3DGuest:: |
837 getTranslatedShaderSourceANGLE(WebGLId shader) { | 718 getTranslatedShaderSourceANGLE(WebGLId shader) { |
838 GLint logLength = 0; | 719 GLint logLength = 0; |
839 gl_->GetShaderiv( | 720 gl_->GetShaderiv( |
840 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength); | 721 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength); |
841 if (!logLength) | 722 if (!logLength) |
842 return WebKit::WebString(); | 723 return WebKit::WebString(); |
843 scoped_array<GLchar> log(new GLchar[logLength]); | 724 scoped_array<GLchar> log(new GLchar[logLength]); |
844 if (!log.get()) | 725 if (!log.get()) |
845 return WebKit::WebString(); | 726 return WebKit::WebString(); |
846 GLsizei returnedLogLength = 0; | 727 GLsizei returnedLogLength = 0; |
847 gl_->GetTranslatedShaderSourceANGLE( | 728 gl_->GetTranslatedShaderSourceANGLE( |
848 shader, logLength, &returnedLogLength, log.get()); | 729 shader, logLength, &returnedLogLength, log.get()); |
849 if (!returnedLogLength) | 730 if (!returnedLogLength) |
850 return WebKit::WebString(); | 731 return WebKit::WebString(); |
851 DCHECK_EQ(logLength, returnedLogLength + 1); | 732 DCHECK_EQ(logLength, returnedLogLength + 1); |
852 WebKit::WebString res = | 733 WebKit::WebString res = |
853 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); | 734 WebKit::WebString::fromUTF8(log.get(), returnedLogLength); |
854 return res; | 735 return res; |
855 } | 736 } |
856 | 737 |
857 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getString( | 738 WebKit::WebString WebGraphicsContext3DGuest::getString( |
858 WGC3Denum name) { | 739 WGC3Denum name) { |
859 return WebKit::WebString::fromUTF8( | 740 return WebKit::WebString::fromUTF8( |
860 reinterpret_cast<const char*>(gl_->GetString(name))); | 741 reinterpret_cast<const char*>(gl_->GetString(name))); |
861 } | 742 } |
862 | 743 |
863 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv, | 744 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv, |
864 WGC3Denum, WGC3Denum, WGC3Dfloat*) | 745 WGC3Denum, WGC3Denum, WGC3Dfloat*) |
865 | 746 |
866 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv, | 747 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv, |
867 WGC3Denum, WGC3Denum, WGC3Dint*) | 748 WGC3Denum, WGC3Denum, WGC3Dint*) |
868 | 749 |
869 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*) | 750 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*) |
870 | 751 |
871 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*) | 752 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*) |
872 | 753 |
873 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation, | 754 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation, |
874 WebGLId, const WGC3Dchar*, WGC3Dint) | 755 WebGLId, const WGC3Dchar*, WGC3Dint) |
875 | 756 |
876 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv, | 757 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv, |
877 WGC3Duint, WGC3Denum, WGC3Dfloat*) | 758 WGC3Duint, WGC3Denum, WGC3Dfloat*) |
878 | 759 |
879 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv, | 760 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv, |
880 WGC3Duint, WGC3Denum, WGC3Dint*) | 761 WGC3Duint, WGC3Denum, WGC3Dint*) |
881 | 762 |
882 WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset( | 763 WGC3Dsizeiptr WebGraphicsContext3DGuest::getVertexAttribOffset( |
883 WGC3Duint index, WGC3Denum pname) { | 764 WGC3Duint index, WGC3Denum pname) { |
884 GLvoid* value = NULL; | 765 GLvoid* value = NULL; |
885 // NOTE: If pname is ever a value that returns more then 1 element | 766 // NOTE: If pname is ever a value that returns more then 1 element |
886 // this will corrupt memory. | 767 // this will corrupt memory. |
887 gl_->GetVertexAttribPointerv(index, pname, &value); | 768 gl_->GetVertexAttribPointerv(index, pname, &value); |
888 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value)); | 769 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value)); |
889 } | 770 } |
890 | 771 |
891 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum) | 772 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum) |
892 | 773 |
(...skipping 16 matching lines...) Expand all Loading... |
909 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId) | 790 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId) |
910 | 791 |
911 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint) | 792 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint) |
912 | 793 |
913 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat) | 794 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat) |
914 | 795 |
915 DELEGATE_TO_GL_7(readPixels, ReadPixels, | 796 DELEGATE_TO_GL_7(readPixels, ReadPixels, |
916 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum, | 797 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum, |
917 WGC3Denum, void*) | 798 WGC3Denum, void*) |
918 | 799 |
919 void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() { | 800 void WebGraphicsContext3DGuest::releaseShaderCompiler() { |
920 } | 801 } |
921 | 802 |
922 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage, | 803 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage, |
923 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei) | 804 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei) |
924 | 805 |
925 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean) | 806 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean) |
926 | 807 |
927 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) | 808 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) |
928 | 809 |
929 void WebGraphicsContext3DCommandBufferImpl::shaderSource( | 810 void WebGraphicsContext3DGuest::shaderSource( |
930 WebGLId shader, const WGC3Dchar* string) { | 811 WebGLId shader, const WGC3Dchar* string) { |
931 GLint length = strlen(string); | 812 GLint length = strlen(string); |
932 gl_->ShaderSource(shader, 1, &string, &length); | 813 gl_->ShaderSource(shader, 1, &string, &length); |
933 } | 814 } |
934 | 815 |
935 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint) | 816 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint) |
936 | 817 |
937 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate, | 818 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate, |
938 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint) | 819 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint) |
939 | 820 |
(...skipping 10 matching lines...) Expand all Loading... |
950 | 831 |
951 DELEGATE_TO_GL_9(texImage2D, TexImage2D, | 832 DELEGATE_TO_GL_9(texImage2D, TexImage2D, |
952 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, | 833 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, |
953 WGC3Dint, WGC3Denum, WGC3Denum, const void*) | 834 WGC3Dint, WGC3Denum, WGC3Denum, const void*) |
954 | 835 |
955 DELEGATE_TO_GL_3(texParameterf, TexParameterf, | 836 DELEGATE_TO_GL_3(texParameterf, TexParameterf, |
956 WGC3Denum, WGC3Denum, WGC3Dfloat); | 837 WGC3Denum, WGC3Denum, WGC3Dfloat); |
957 | 838 |
958 static const unsigned int kTextureWrapR = 0x8072; | 839 static const unsigned int kTextureWrapR = 0x8072; |
959 | 840 |
960 void WebGraphicsContext3DCommandBufferImpl::texParameteri( | 841 void WebGraphicsContext3DGuest::texParameteri( |
961 WGC3Denum target, WGC3Denum pname, WGC3Dint param) { | 842 WGC3Denum target, WGC3Denum pname, WGC3Dint param) { |
962 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in | 843 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in |
963 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the | 844 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the |
964 // edge of cube maps, and, if it is, push it into the GLES2 service | 845 // edge of cube maps, and, if it is, push it into the GLES2 service |
965 // side code. | 846 // side code. |
966 if (pname == kTextureWrapR) { | 847 if (pname == kTextureWrapR) { |
967 return; | 848 return; |
968 } | 849 } |
969 gl_->TexParameteri(target, pname, param); | 850 gl_->TexParameteri(target, pname, param); |
970 } | 851 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 | 922 |
1042 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint, | 923 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint, |
1043 const WGC3Dfloat*) | 924 const WGC3Dfloat*) |
1044 | 925 |
1045 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint, | 926 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint, |
1046 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) | 927 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) |
1047 | 928 |
1048 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint, | 929 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint, |
1049 const WGC3Dfloat*) | 930 const WGC3Dfloat*) |
1050 | 931 |
1051 void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer( | 932 void WebGraphicsContext3DGuest::vertexAttribPointer( |
1052 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized, | 933 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized, |
1053 WGC3Dsizei stride, WGC3Dintptr offset) { | 934 WGC3Dsizei stride, WGC3Dintptr offset) { |
1054 gl_->VertexAttribPointer( | 935 gl_->VertexAttribPointer( |
1055 index, size, type, normalized, stride, | 936 index, size, type, normalized, stride, |
1056 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); | 937 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); |
1057 } | 938 } |
1058 | 939 |
1059 DELEGATE_TO_GL_4(viewport, Viewport, | 940 DELEGATE_TO_GL_4(viewport, Viewport, |
1060 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) | 941 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) |
1061 | 942 |
1062 WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() { | 943 WebGLId WebGraphicsContext3DGuest::createBuffer() { |
1063 GLuint o; | 944 GLuint o; |
1064 gl_->GenBuffers(1, &o); | 945 gl_->GenBuffers(1, &o); |
1065 return o; | 946 return o; |
1066 } | 947 } |
1067 | 948 |
1068 WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() { | 949 WebGLId WebGraphicsContext3DGuest::createFramebuffer() { |
1069 GLuint o = 0; | 950 GLuint o = 0; |
1070 gl_->GenFramebuffers(1, &o); | 951 gl_->GenFramebuffers(1, &o); |
1071 return o; | 952 return o; |
1072 } | 953 } |
1073 | 954 |
1074 WebGLId WebGraphicsContext3DCommandBufferImpl::createProgram() { | 955 WebGLId WebGraphicsContext3DGuest::createProgram() { |
1075 return gl_->CreateProgram(); | 956 return gl_->CreateProgram(); |
1076 } | 957 } |
1077 | 958 |
1078 WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() { | 959 WebGLId WebGraphicsContext3DGuest::createRenderbuffer() { |
1079 GLuint o; | 960 GLuint o; |
1080 gl_->GenRenderbuffers(1, &o); | 961 gl_->GenRenderbuffers(1, &o); |
1081 return o; | 962 return o; |
1082 } | 963 } |
1083 | 964 |
1084 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId); | 965 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId); |
1085 | 966 |
1086 WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() { | 967 WebGLId WebGraphicsContext3DGuest::createTexture() { |
1087 GLuint o; | 968 GLuint o; |
1088 gl_->GenTextures(1, &o); | 969 gl_->GenTextures(1, &o); |
1089 return o; | 970 return o; |
1090 } | 971 } |
1091 | 972 |
1092 void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) { | 973 void WebGraphicsContext3DGuest::deleteBuffer(WebGLId buffer) { |
1093 gl_->DeleteBuffers(1, &buffer); | 974 gl_->DeleteBuffers(1, &buffer); |
1094 } | 975 } |
1095 | 976 |
1096 void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer( | 977 void WebGraphicsContext3DGuest::deleteFramebuffer( |
1097 WebGLId framebuffer) { | 978 WebGLId framebuffer) { |
1098 gl_->DeleteFramebuffers(1, &framebuffer); | 979 gl_->DeleteFramebuffers(1, &framebuffer); |
1099 } | 980 } |
1100 | 981 |
1101 void WebGraphicsContext3DCommandBufferImpl::deleteProgram(WebGLId program) { | 982 void WebGraphicsContext3DGuest::deleteProgram(WebGLId program) { |
1102 gl_->DeleteProgram(program); | 983 gl_->DeleteProgram(program); |
1103 } | 984 } |
1104 | 985 |
1105 void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer( | 986 void WebGraphicsContext3DGuest::deleteRenderbuffer( |
1106 WebGLId renderbuffer) { | 987 WebGLId renderbuffer) { |
1107 gl_->DeleteRenderbuffers(1, &renderbuffer); | 988 gl_->DeleteRenderbuffers(1, &renderbuffer); |
1108 } | 989 } |
1109 | 990 |
1110 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) { | 991 void WebGraphicsContext3DGuest::deleteShader(WebGLId shader) { |
1111 gl_->DeleteShader(shader); | 992 gl_->DeleteShader(shader); |
1112 } | 993 } |
1113 | 994 |
1114 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { | 995 void WebGraphicsContext3DGuest::deleteTexture(WebGLId texture) { |
1115 gl_->DeleteTextures(1, &texture); | 996 gl_->DeleteTextures(1, &texture); |
1116 } | 997 } |
1117 | 998 |
1118 bool WebGraphicsContext3DCommandBufferImpl::ShouldUseSwapClient() { | 999 void WebGraphicsContext3DGuest::OnSwapBuffersComplete() { |
1119 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); | |
1120 return factory && factory->IsMainThread() && swap_client_.get(); | |
1121 } | |
1122 | |
1123 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { | |
1124 typedef WebGraphicsContext3DSwapBuffersClient WGC3DSwapClient; | |
1125 // This may be called after tear-down of the RenderView. | 1000 // This may be called after tear-down of the RenderView. |
1126 if (ShouldUseSwapClient()) { | 1001 RenderViewImpl* renderview = |
1127 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 1002 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; |
1128 &WGC3DSwapClient::OnViewContextSwapBuffersComplete, swap_client_)); | 1003 if (renderview) { |
| 1004 MessageLoop::current()->PostTask( |
| 1005 FROM_HERE, |
| 1006 base::Bind(&RenderViewImpl::OnViewContextSwapBuffersComplete, |
| 1007 renderview)); |
1129 } | 1008 } |
1130 | 1009 |
1131 if (swapbuffers_complete_callback_) | 1010 if (swapbuffers_complete_callback_) |
1132 swapbuffers_complete_callback_->onSwapBuffersComplete(); | 1011 swapbuffers_complete_callback_->onSwapBuffersComplete(); |
1133 } | 1012 } |
1134 | 1013 |
1135 void WebGraphicsContext3DCommandBufferImpl::OnMemoryAllocationChanged( | 1014 void WebGraphicsContext3DGuest::setContextLostCallback( |
1136 const GpuMemoryAllocation& allocation) { | |
1137 if (memory_allocation_changed_callback_) | |
1138 memory_allocation_changed_callback_->onMemoryAllocationChanged( | |
1139 allocation.gpu_resource_size_in_bytes); | |
1140 } | |
1141 | |
1142 void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback( | |
1143 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) { | |
1144 error_message_callback_ = cb; | |
1145 } | |
1146 | |
1147 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback( | |
1148 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { | 1015 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { |
1149 context_lost_callback_ = cb; | 1016 context_lost_callback_ = cb; |
1150 } | 1017 } |
1151 | 1018 |
1152 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() { | 1019 WGC3Denum WebGraphicsContext3DGuest::getGraphicsResetStatusARB() { |
1153 if (context_->IsCommandBufferContextLost() && | 1020 return dead_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; |
1154 context_lost_reason_ == GL_NO_ERROR) { | |
1155 return GL_UNKNOWN_CONTEXT_RESET_ARB; | |
1156 } | |
1157 | |
1158 return context_lost_reason_; | |
1159 } | 1021 } |
1160 | 1022 |
1161 void WebGraphicsContext3DCommandBufferImpl:: | 1023 void WebGraphicsContext3DGuest:: |
1162 setSwapBuffersCompleteCallbackCHROMIUM( | 1024 setSwapBuffersCompleteCallbackCHROMIUM( |
1163 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) { | 1025 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) { |
1164 swapbuffers_complete_callback_ = cb; | 1026 swapbuffers_complete_callback_ = cb; |
1165 } | 1027 } |
1166 | 1028 |
1167 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, | 1029 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, |
1168 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) | 1030 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) |
1169 | 1031 |
1170 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, | 1032 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, |
1171 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) | 1033 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) |
1172 | 1034 |
1173 #if WEBKIT_USING_SKIA | 1035 void WebGraphicsContext3DGuest::OnContextLost() { |
1174 GrGLInterface* WebGraphicsContext3DCommandBufferImpl::onCreateGrGLInterface() { | 1036 fprintf(stderr, ">>>>%s\n", __PRETTY_FUNCTION__); |
1175 return webkit_glue::CreateCommandBufferSkiaGLBinding(); | 1037 RenderViewImpl* renderview = |
1176 } | 1038 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; |
1177 #endif | 1039 if (renderview) { |
1178 | 1040 fprintf(stderr, ">>>Found a renderview\n"); |
1179 namespace { | 1041 renderview->OnViewContextSwapBuffersAborted(); |
1180 | |
1181 WGC3Denum convertReason(ContentGLContext::ContextLostReason reason) { | |
1182 switch (reason) { | |
1183 case ContentGLContext::kGuilty: | |
1184 return GL_GUILTY_CONTEXT_RESET_ARB; | |
1185 case ContentGLContext::kInnocent: | |
1186 return GL_INNOCENT_CONTEXT_RESET_ARB; | |
1187 case ContentGLContext::kUnknown: | |
1188 return GL_UNKNOWN_CONTEXT_RESET_ARB; | |
1189 } | |
1190 | |
1191 NOTREACHED(); | |
1192 return GL_UNKNOWN_CONTEXT_RESET_ARB; | |
1193 } | |
1194 | |
1195 } // anonymous namespace | |
1196 | |
1197 void WebGraphicsContext3DCommandBufferImpl::OnContextLost( | |
1198 ContentGLContext::ContextLostReason reason) { | |
1199 context_lost_reason_ = convertReason(reason); | |
1200 if (context_lost_callback_) { | |
1201 context_lost_callback_->onContextLost(); | |
1202 } | |
1203 if (attributes_.shareResources) | |
1204 ClearSharedContexts(); | |
1205 if (ShouldUseSwapClient()) | |
1206 swap_client_->OnViewContextSwapBuffersAborted(); | |
1207 } | |
1208 | |
1209 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | |
1210 const std::string& message, int id) { | |
1211 if (error_message_callback_) { | |
1212 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | |
1213 error_message_callback_->onErrorMessage(str, id); | |
1214 } | 1042 } |
1215 } | 1043 } |
1216 | 1044 |
| 1045 #endif // defined(ENABLE_GPU) |
OLD | NEW |