Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: content/renderer/webgraphicscontext3d_command_buffer_impl.cc

Issue 7066035: Moved GPU related files in content/renderer into gpu subdirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if defined(ENABLE_GPU)
6
7 #include "content/renderer/webgraphicscontext3d_command_buffer_impl.h"
8
9 #include <GLES2/gl2.h>
10 #ifndef GL_GLEXT_PROTOTYPES
11 #define GL_GLEXT_PROTOTYPES 1
12 #endif
13 #include <GLES2/gl2ext.h>
14
15 #include <algorithm>
16
17 #include "base/string_tokenizer.h"
18 #include "base/command_line.h"
19 #include "base/debug/trace_event.h"
20 #include "base/logging.h"
21 #include "base/metrics/histogram.h"
22 #include "content/common/content_switches.h"
23 #include "content/renderer/gpu_channel_host.h"
24 #include "content/renderer/render_thread.h"
25 #include "content/renderer/render_view.h"
26 #include "gpu/command_buffer/client/gles2_implementation.h"
27 #include "gpu/command_buffer/common/constants.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
30 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h"
31
32 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
33 : context_(NULL),
34 gl_(NULL),
35 web_view_(NULL),
36 #if defined(OS_MACOSX)
37 plugin_handle_(NULL),
38 #endif // defined(OS_MACOSX)
39 context_lost_callback_(0),
40 cached_width_(0),
41 cached_height_(0),
42 bound_fbo_(0) {
43 }
44
45 WebGraphicsContext3DCommandBufferImpl::
46 ~WebGraphicsContext3DCommandBufferImpl() {
47 delete context_;
48 }
49
50 static const char* kWebGraphicsContext3DPerferredGLExtensions =
51 "GL_OES_packed_depth_stencil "
52 "GL_OES_depth24 "
53 "GL_CHROMIUM_webglsl";
54
55 bool WebGraphicsContext3DCommandBufferImpl::initialize(
56 WebGraphicsContext3D::Attributes attributes,
57 WebKit::WebView* web_view,
58 bool render_directly_to_web_view) {
59 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize");
60 webkit_glue::BindSkiaToCommandBufferGL();
61 RenderThread* render_thread = RenderThread::current();
62 if (!render_thread)
63 return false;
64 GpuChannelHost* host = render_thread->EstablishGpuChannelSync(
65 content::
66 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE);
67 if (!host)
68 return false;
69 DCHECK(host->state() == GpuChannelHost::kConnected);
70
71 // Convert WebGL context creation attributes into RendererGLContext / EGL size
72 // requests.
73 const int alpha_size = attributes.alpha ? 8 : 0;
74 const int depth_size = attributes.depth ? 24 : 0;
75 const int stencil_size = attributes.stencil ? 8 : 0;
76 const int samples = attributes.antialias ? 4 : 0;
77 const int sample_buffers = attributes.antialias ? 1 : 0;
78 const int32 attribs[] = {
79 RendererGLContext::ALPHA_SIZE, alpha_size,
80 RendererGLContext::DEPTH_SIZE, depth_size,
81 RendererGLContext::STENCIL_SIZE, stencil_size,
82 RendererGLContext::SAMPLES, samples,
83 RendererGLContext::SAMPLE_BUFFERS, sample_buffers,
84 RendererGLContext::NONE,
85 };
86
87 const GPUInfo& gpu_info = host->gpu_info();
88 UMA_HISTOGRAM_ENUMERATION(
89 "GPU.WebGraphicsContext3D_Init_CanLoseContext",
90 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context,
91 4);
92 if (attributes.canRecoverFromContextLoss == false) {
93 if (gpu_info.can_lose_context)
94 return false;
95 }
96
97 GURL active_url;
98 if (web_view && web_view->mainFrame())
99 active_url = GURL(web_view->mainFrame()->url());
100
101 if (render_directly_to_web_view) {
102 RenderView* renderview = RenderView::FromWebView(web_view);
103 if (!renderview)
104 return false;
105
106 web_view_ = web_view;
107 context_ = RendererGLContext::CreateViewContext(
108 host,
109 renderview->compositing_surface(),
110 renderview->routing_id(),
111 kWebGraphicsContext3DPerferredGLExtensions,
112 attribs,
113 active_url);
114 if (context_) {
115 context_->SetSwapBuffersCallback(
116 NewCallback(this,
117 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
118 }
119 } else {
120 bool compositing_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
121 switches::kDisableAcceleratedCompositing);
122 RendererGLContext* parent_context = NULL;
123 // If GPU compositing is enabled we need to create a GL context that shares
124 // resources with the compositor's context.
125 if (compositing_enabled) {
126 // Asking for the WebGraphicsContext3D on the WebView will force one to
127 // be created if it doesn't already exist. When the compositor is created
128 // for the view it will use the same context.
129 WebKit::WebGraphicsContext3D* view_context =
130 web_view->graphicsContext3D();
131 if (view_context) {
132 WebGraphicsContext3DCommandBufferImpl* context_impl =
133 static_cast<WebGraphicsContext3DCommandBufferImpl*>(view_context);
134 parent_context = context_impl->context_;
135 }
136 }
137 context_ = RendererGLContext::CreateOffscreenContext(
138 host,
139 parent_context,
140 gfx::Size(1, 1),
141 kWebGraphicsContext3DPerferredGLExtensions,
142 attribs,
143 active_url);
144 web_view_ = NULL;
145 }
146 if (!context_)
147 return false;
148
149 gl_ = context_->GetImplementation();
150 context_->SetContextLostCallback(
151 NewCallback(this,
152 &WebGraphicsContext3DCommandBufferImpl::OnContextLost));
153
154 // TODO(gman): Remove this.
155 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
156 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) {
157 context_->DisableShaderTranslation();
158 }
159
160 // Set attributes_ from created offscreen context.
161 {
162 attributes_ = attributes;
163 GLint alpha_bits = 0;
164 getIntegerv(GL_ALPHA_BITS, &alpha_bits);
165 attributes_.alpha = alpha_bits > 0;
166 GLint depth_bits = 0;
167 getIntegerv(GL_DEPTH_BITS, &depth_bits);
168 attributes_.depth = depth_bits > 0;
169 GLint stencil_bits = 0;
170 getIntegerv(GL_STENCIL_BITS, &stencil_bits);
171 attributes_.stencil = stencil_bits > 0;
172 GLint samples = 0;
173 getIntegerv(GL_SAMPLES, &samples);
174 attributes_.antialias = samples > 0;
175 }
176
177 return true;
178 }
179
180 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
181 return RendererGLContext::MakeCurrent(context_);
182 }
183
184 int WebGraphicsContext3DCommandBufferImpl::width() {
185 return cached_width_;
186 }
187
188 int WebGraphicsContext3DCommandBufferImpl::height() {
189 return cached_height_;
190 }
191
192 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() {
193 return true;
194 }
195
196 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() {
197 DCHECK(context_);
198 return context_->GetParentTextureId();
199 }
200
201 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
202 // Copies the contents of the off-screen render target into the texture
203 // used by the compositor.
204 context_->SwapBuffers();
205 }
206
207 void WebGraphicsContext3DCommandBufferImpl::reshape(int width, int height) {
208 cached_width_ = width;
209 cached_height_ = height;
210
211 if (web_view_) {
212 #if defined(OS_MACOSX)
213 context_->ResizeOnscreen(gfx::Size(width, height));
214 #else
215 gl_->ResizeCHROMIUM(width, height);
216 #endif
217 } else {
218 context_->ResizeOffscreen(gfx::Size(width, height));
219 // Force a SwapBuffers to get the framebuffer to resize.
220 context_->SwapBuffers();
221 }
222
223 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
224 scanline_.reset(new uint8[width * 4]);
225 #endif // FLIP_FRAMEBUFFER_VERTICALLY
226 }
227
228 WebGLId WebGraphicsContext3DCommandBufferImpl::createCompositorTexture(
229 WGC3Dsizei width, WGC3Dsizei height) {
230 return context_->CreateParentTexture(gfx::Size(width, height));
231 }
232
233 void WebGraphicsContext3DCommandBufferImpl::deleteCompositorTexture(
234 WebGLId parent_texture) {
235 context_->DeleteParentTexture(parent_texture);
236 }
237
238 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
239 void WebGraphicsContext3DCommandBufferImpl::FlipVertically(
240 uint8* framebuffer,
241 unsigned int width,
242 unsigned int height) {
243 uint8* scanline = scanline_.get();
244 if (!scanline)
245 return;
246 unsigned int row_bytes = width * 4;
247 unsigned int count = height / 2;
248 for (unsigned int i = 0; i < count; i++) {
249 uint8* row_a = framebuffer + i * row_bytes;
250 uint8* row_b = framebuffer + (height - i - 1) * row_bytes;
251 // TODO(kbr): this is where the multiplication of the alpha
252 // channel into the color buffer will need to occur if the
253 // user specifies the "premultiplyAlpha" flag in the context
254 // creation attributes.
255 memcpy(scanline, row_b, row_bytes);
256 memcpy(row_b, row_a, row_bytes);
257 memcpy(row_a, scanline, row_bytes);
258 }
259 }
260 #endif
261
262 bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
263 unsigned char* pixels,
264 size_t buffer_size) {
265 if (buffer_size != static_cast<size_t>(4 * width() * height())) {
266 return false;
267 }
268
269 // Earlier versions of this code used the GPU to flip the
270 // framebuffer vertically before reading it back for compositing
271 // via software. This code was quite complicated, used a lot of
272 // GPU memory, and didn't provide an obvious speedup. Since this
273 // vertical flip is only a temporary solution anyway until Chrome
274 // is fully GPU composited, it wasn't worth the complexity.
275
276 bool mustRestoreFBO = (bound_fbo_ != 0);
277 if (mustRestoreFBO) {
278 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0);
279 }
280 gl_->ReadPixels(0, 0, cached_width_, cached_height_,
281 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
282
283 // Swizzle red and blue channels
284 // TODO(kbr): expose GL_BGRA as extension
285 for (size_t i = 0; i < buffer_size; i += 4) {
286 std::swap(pixels[i], pixels[i + 2]);
287 }
288
289 if (mustRestoreFBO) {
290 gl_->BindFramebuffer(GL_FRAMEBUFFER, bound_fbo_);
291 }
292
293 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
294 if (pixels) {
295 FlipVertically(pixels, cached_width_, cached_height_);
296 }
297 #endif
298
299 return true;
300 }
301
302 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
303 WGC3Denum error) {
304 if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
305 synthetic_errors_.end()) {
306 synthetic_errors_.push_back(error);
307 }
308 }
309
310 void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM(
311 WGC3Denum target,
312 WGC3Dintptr offset,
313 WGC3Dsizeiptr size,
314 WGC3Denum access) {
315 return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
316 }
317
318 void WebGraphicsContext3DCommandBufferImpl::unmapBufferSubDataCHROMIUM(
319 const void* mem) {
320 return gl_->UnmapBufferSubDataCHROMIUM(mem);
321 }
322
323 void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM(
324 WGC3Denum target,
325 WGC3Dint level,
326 WGC3Dint xoffset,
327 WGC3Dint yoffset,
328 WGC3Dsizei width,
329 WGC3Dsizei height,
330 WGC3Denum format,
331 WGC3Denum type,
332 WGC3Denum access) {
333 return gl_->MapTexSubImage2DCHROMIUM(
334 target, level, xoffset, yoffset, width, height, format, type, access);
335 }
336
337 void WebGraphicsContext3DCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
338 const void* mem) {
339 gl_->UnmapTexSubImage2DCHROMIUM(mem);
340 }
341
342 void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
343 WebGLId texture, WebGLId parentTexture) {
344 copyTextureToCompositor(texture, parentTexture);
345 }
346
347 void WebGraphicsContext3DCommandBufferImpl::getParentToChildLatchCHROMIUM(
348 WGC3Duint* latch_id)
349 {
350 if (!context_->GetParentToChildLatch(latch_id)) {
351 LOG(ERROR) << "getLatch must only be called on child context";
352 synthesizeGLError(GL_INVALID_OPERATION);
353 *latch_id = gpu::kInvalidLatchId;
354 }
355 }
356
357 void WebGraphicsContext3DCommandBufferImpl::getChildToParentLatchCHROMIUM(
358 WGC3Duint* latch_id)
359 {
360 if (!context_->GetChildToParentLatch(latch_id)) {
361 LOG(ERROR) << "getLatch must only be called on child context";
362 synthesizeGLError(GL_INVALID_OPERATION);
363 *latch_id = gpu::kInvalidLatchId;
364 }
365 }
366
367 void WebGraphicsContext3DCommandBufferImpl::waitLatchCHROMIUM(
368 WGC3Duint latch_id)
369 {
370 gl_->WaitLatchCHROMIUM(latch_id);
371 }
372
373 void WebGraphicsContext3DCommandBufferImpl::setLatchCHROMIUM(
374 WGC3Duint latch_id)
375 {
376 gl_->SetLatchCHROMIUM(latch_id);
377 // required to ensure set command is sent to GPU process
378 gl_->Flush();
379 }
380
381 void WebGraphicsContext3DCommandBufferImpl::
382 rateLimitOffscreenContextCHROMIUM() {
383 gl_->RateLimitOffscreenContextCHROMIUM();
384 }
385
386 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::
387 getRequestableExtensionsCHROMIUM() {
388 return WebKit::WebString::fromUTF8(
389 gl_->GetRequestableExtensionsCHROMIUM());
390 }
391
392 void WebGraphicsContext3DCommandBufferImpl::requestExtensionCHROMIUM(
393 const char* extension) {
394 gl_->RequestExtensionCHROMIUM(extension);
395 }
396
397 void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM(
398 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
399 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
400 WGC3Dbitfield mask, WGC3Denum filter) {
401 gl_->BlitFramebufferEXT(
402 srcX0, srcY0, srcX1, srcY1,
403 dstX0, dstY0, dstX1, dstY1,
404 mask, filter);
405 }
406
407 void WebGraphicsContext3DCommandBufferImpl::
408 renderbufferStorageMultisampleCHROMIUM(
409 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
410 WGC3Dsizei width, WGC3Dsizei height) {
411 gl_->RenderbufferStorageMultisampleEXT(
412 target, samples, internalformat, width, height);
413 }
414
415 // Helper macros to reduce the amount of code.
416
417 #define DELEGATE_TO_GL(name, glname) \
418 void WebGraphicsContext3DCommandBufferImpl::name() { \
419 gl_->glname(); \
420 }
421
422 #define DELEGATE_TO_GL_1(name, glname, t1) \
423 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
424 gl_->glname(a1); \
425 }
426
427 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
428 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
429 return gl_->glname(a1); \
430 }
431
432 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
433 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
434 return gl_->glname(a1) ? true : false; \
435 }
436
437 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
438 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
439 gl_->glname(a1, a2); \
440 }
441
442 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
443 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
444 return gl_->glname(a1, a2); \
445 }
446
447 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
448 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
449 gl_->glname(a1, a2, a3); \
450 }
451
452 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
453 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
454 gl_->glname(a1, a2, a3, a4); \
455 }
456
457 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
458 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
459 t4 a4, t5 a5) { \
460 gl_->glname(a1, a2, a3, a4, a5); \
461 }
462
463 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
464 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
465 t4 a4, t5 a5, t6 a6) { \
466 gl_->glname(a1, a2, a3, a4, a5, a6); \
467 }
468
469 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
470 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
471 t4 a4, t5 a5, t6 a6, t7 a7) { \
472 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
473 }
474
475 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
476 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
477 t4 a4, t5 a5, t6 a6, \
478 t7 a7, t8 a8) { \
479 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
480 }
481
482 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
483 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
484 t4 a4, t5 a5, t6 a6, \
485 t7 a7, t8 a8, t9 a9) { \
486 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
487 }
488
489 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum)
490
491 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId)
492
493 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
494 WGC3Duint, const WGC3Dchar*)
495
496 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
497
498 void WebGraphicsContext3DCommandBufferImpl::bindFramebuffer(
499 WGC3Denum target,
500 WebGLId framebuffer) {
501 gl_->BindFramebuffer(target, framebuffer);
502 bound_fbo_ = framebuffer;
503 }
504
505 DELEGATE_TO_GL_2(bindRenderbuffer, BindRenderbuffer, WGC3Denum, WebGLId)
506
507 DELEGATE_TO_GL_2(bindTexture, BindTexture, WGC3Denum, WebGLId)
508
509 DELEGATE_TO_GL_4(blendColor, BlendColor,
510 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
511
512 DELEGATE_TO_GL_1(blendEquation, BlendEquation, WGC3Denum)
513
514 DELEGATE_TO_GL_2(blendEquationSeparate, BlendEquationSeparate,
515 WGC3Denum, WGC3Denum)
516
517 DELEGATE_TO_GL_2(blendFunc, BlendFunc, WGC3Denum, WGC3Denum)
518
519 DELEGATE_TO_GL_4(blendFuncSeparate, BlendFuncSeparate,
520 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
521
522 DELEGATE_TO_GL_4(bufferData, BufferData,
523 WGC3Denum, WGC3Dsizeiptr, const void*, WGC3Denum)
524
525 DELEGATE_TO_GL_4(bufferSubData, BufferSubData,
526 WGC3Denum, WGC3Dintptr, WGC3Dsizeiptr, const void*)
527
528 DELEGATE_TO_GL_1R(checkFramebufferStatus, CheckFramebufferStatus,
529 WGC3Denum, WGC3Denum)
530
531 DELEGATE_TO_GL_1(clear, Clear, WGC3Dbitfield)
532
533 DELEGATE_TO_GL_4(clearColor, ClearColor,
534 WGC3Dclampf, WGC3Dclampf, WGC3Dclampf, WGC3Dclampf)
535
536 DELEGATE_TO_GL_1(clearDepth, ClearDepthf, WGC3Dclampf)
537
538 DELEGATE_TO_GL_1(clearStencil, ClearStencil, WGC3Dint)
539
540 DELEGATE_TO_GL_4(colorMask, ColorMask,
541 WGC3Dboolean, WGC3Dboolean, WGC3Dboolean, WGC3Dboolean)
542
543 DELEGATE_TO_GL_1(compileShader, CompileShader, WebGLId)
544
545 DELEGATE_TO_GL_8(copyTexImage2D, CopyTexImage2D,
546 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dint, WGC3Dint,
547 WGC3Dsizei, WGC3Dsizei, WGC3Dint)
548
549 DELEGATE_TO_GL_8(copyTexSubImage2D, CopyTexSubImage2D,
550 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint,
551 WGC3Dsizei, WGC3Dsizei)
552
553 DELEGATE_TO_GL_1(cullFace, CullFace, WGC3Denum)
554
555 DELEGATE_TO_GL_1(depthFunc, DepthFunc, WGC3Denum)
556
557 DELEGATE_TO_GL_1(depthMask, DepthMask, WGC3Dboolean)
558
559 DELEGATE_TO_GL_2(depthRange, DepthRangef, WGC3Dclampf, WGC3Dclampf)
560
561 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
562
563 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
564
565 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
566 WGC3Duint)
567
568 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
569
570 void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode,
571 WGC3Dsizei count,
572 WGC3Denum type,
573 WGC3Dintptr offset) {
574 gl_->DrawElements(
575 mode, count, type,
576 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
577 }
578
579 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
580
581 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
582 WGC3Duint)
583
584 DELEGATE_TO_GL(finish, Finish)
585
586 DELEGATE_TO_GL(flush, Flush)
587
588 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
589 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
590
591 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
592 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
593
594 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
595
596 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
597
598 bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
599 WebGLId program, WGC3Duint index, ActiveInfo& info) {
600 if (!program) {
601 synthesizeGLError(GL_INVALID_VALUE);
602 return false;
603 }
604 GLint max_name_length = -1;
605 gl_->GetProgramiv(
606 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
607 if (max_name_length < 0)
608 return false;
609 scoped_array<GLchar> name(new GLchar[max_name_length]);
610 if (!name.get()) {
611 synthesizeGLError(GL_OUT_OF_MEMORY);
612 return false;
613 }
614 GLsizei length = 0;
615 GLint size = -1;
616 GLenum type = 0;
617 gl_->GetActiveAttrib(
618 program, index, max_name_length, &length, &size, &type, name.get());
619 if (size < 0) {
620 return false;
621 }
622 info.name = WebKit::WebString::fromUTF8(name.get(), length);
623 info.type = type;
624 info.size = size;
625 return true;
626 }
627
628 bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform(
629 WebGLId program, WGC3Duint index, ActiveInfo& info) {
630 GLint max_name_length = -1;
631 gl_->GetProgramiv(
632 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
633 if (max_name_length < 0)
634 return false;
635 scoped_array<GLchar> name(new GLchar[max_name_length]);
636 if (!name.get()) {
637 synthesizeGLError(GL_OUT_OF_MEMORY);
638 return false;
639 }
640 GLsizei length = 0;
641 GLint size = -1;
642 GLenum type = 0;
643 gl_->GetActiveUniform(
644 program, index, max_name_length, &length, &size, &type, name.get());
645 if (size < 0) {
646 return false;
647 }
648 info.name = WebKit::WebString::fromUTF8(name.get(), length);
649 info.type = type;
650 info.size = size;
651 return true;
652 }
653
654 DELEGATE_TO_GL_4(getAttachedShaders, GetAttachedShaders,
655 WebGLId, WGC3Dsizei, WGC3Dsizei*, WebGLId*)
656
657 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
658 WebGLId, const WGC3Dchar*, WGC3Dint)
659
660 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
661
662 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
663 WGC3Denum, WGC3Denum, WGC3Dint*)
664
665 WebKit::WebGraphicsContext3D::Attributes
666 WebGraphicsContext3DCommandBufferImpl::getContextAttributes() {
667 return attributes_;
668 }
669
670 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
671 if (!synthetic_errors_.empty()) {
672 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
673 WGC3Denum err = *iter;
674 synthetic_errors_.erase(iter);
675 return err;
676 }
677
678 return gl_->GetError();
679 }
680
681 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() {
682 return context_->IsCommandBufferContextLost();
683 }
684
685 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
686
687 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
688 GetFramebufferAttachmentParameteriv,
689 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
690
691 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
692
693 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
694
695 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog(
696 WebGLId program) {
697 GLint logLength = 0;
698 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
699 if (!logLength)
700 return WebKit::WebString();
701 scoped_array<GLchar> log(new GLchar[logLength]);
702 if (!log.get())
703 return WebKit::WebString();
704 GLsizei returnedLogLength = 0;
705 gl_->GetProgramInfoLog(
706 program, logLength, &returnedLogLength, log.get());
707 DCHECK_EQ(logLength, returnedLogLength + 1);
708 WebKit::WebString res =
709 WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
710 return res;
711 }
712
713 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
714 WGC3Denum, WGC3Denum, WGC3Dint*)
715
716 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
717
718 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
719 WebGLId shader) {
720 GLint logLength = 0;
721 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
722 if (!logLength)
723 return WebKit::WebString();
724 scoped_array<GLchar> log(new GLchar[logLength]);
725 if (!log.get())
726 return WebKit::WebString();
727 GLsizei returnedLogLength = 0;
728 gl_->GetShaderInfoLog(
729 shader, logLength, &returnedLogLength, log.get());
730 DCHECK_EQ(logLength, returnedLogLength + 1);
731 WebKit::WebString res =
732 WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
733 return res;
734 }
735
736 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
737 WebGLId shader) {
738 GLint logLength = 0;
739 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
740 if (!logLength)
741 return WebKit::WebString();
742 scoped_array<GLchar> log(new GLchar[logLength]);
743 if (!log.get())
744 return WebKit::WebString();
745 GLsizei returnedLogLength = 0;
746 gl_->GetShaderSource(
747 shader, logLength, &returnedLogLength, log.get());
748 DCHECK_EQ(logLength, returnedLogLength + 1);
749 WebKit::WebString res =
750 WebKit::WebString::fromUTF8(log.get(), returnedLogLength);
751 return res;
752 }
753
754 WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getString(
755 WGC3Denum name) {
756 return WebKit::WebString::fromUTF8(
757 reinterpret_cast<const char*>(gl_->GetString(name)));
758 }
759
760 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
761 WGC3Denum, WGC3Denum, WGC3Dfloat*)
762
763 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
764 WGC3Denum, WGC3Denum, WGC3Dint*)
765
766 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
767
768 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
769
770 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
771 WebGLId, const WGC3Dchar*, WGC3Dint)
772
773 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
774 WGC3Duint, WGC3Denum, WGC3Dfloat*)
775
776 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
777 WGC3Duint, WGC3Denum, WGC3Dint*)
778
779 WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset(
780 WGC3Duint index, WGC3Denum pname) {
781 GLvoid* value = NULL;
782 // NOTE: If pname is ever a value that returns more then 1 element
783 // this will corrupt memory.
784 gl_->GetVertexAttribPointerv(index, pname, &value);
785 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
786 }
787
788 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
789
790 DELEGATE_TO_GL_1RB(isBuffer, IsBuffer, WebGLId, WGC3Dboolean)
791
792 DELEGATE_TO_GL_1RB(isEnabled, IsEnabled, WGC3Denum, WGC3Dboolean)
793
794 DELEGATE_TO_GL_1RB(isFramebuffer, IsFramebuffer, WebGLId, WGC3Dboolean)
795
796 DELEGATE_TO_GL_1RB(isProgram, IsProgram, WebGLId, WGC3Dboolean)
797
798 DELEGATE_TO_GL_1RB(isRenderbuffer, IsRenderbuffer, WebGLId, WGC3Dboolean)
799
800 DELEGATE_TO_GL_1RB(isShader, IsShader, WebGLId, WGC3Dboolean)
801
802 DELEGATE_TO_GL_1RB(isTexture, IsTexture, WebGLId, WGC3Dboolean)
803
804 DELEGATE_TO_GL_1(lineWidth, LineWidth, WGC3Dfloat)
805
806 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
807
808 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
809
810 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
811
812 DELEGATE_TO_GL_7(readPixels, ReadPixels,
813 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
814 WGC3Denum, void*)
815
816 void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() {
817 }
818
819 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
820 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
821
822 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
823
824 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
825
826 void WebGraphicsContext3DCommandBufferImpl::shaderSource(
827 WebGLId shader, const WGC3Dchar* string) {
828 GLint length = strlen(string);
829 gl_->ShaderSource(shader, 1, &string, &length);
830 }
831
832 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
833
834 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
835 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
836
837 DELEGATE_TO_GL_1(stencilMask, StencilMask, WGC3Duint)
838
839 DELEGATE_TO_GL_2(stencilMaskSeparate, StencilMaskSeparate,
840 WGC3Denum, WGC3Duint)
841
842 DELEGATE_TO_GL_3(stencilOp, StencilOp,
843 WGC3Denum, WGC3Denum, WGC3Denum)
844
845 DELEGATE_TO_GL_4(stencilOpSeparate, StencilOpSeparate,
846 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Denum)
847
848 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
849 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
850 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
851
852 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
853 WGC3Denum, WGC3Denum, WGC3Dfloat);
854
855 static const unsigned int kTextureWrapR = 0x8072;
856
857 void WebGraphicsContext3DCommandBufferImpl::texParameteri(
858 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
859 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
860 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
861 // edge of cube maps, and, if it is, push it into the GLES2 service
862 // side code.
863 if (pname == kTextureWrapR) {
864 return;
865 }
866 gl_->TexParameteri(target, pname, param);
867 }
868
869 DELEGATE_TO_GL_9(texSubImage2D, TexSubImage2D,
870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei,
871 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
872
873 DELEGATE_TO_GL_2(uniform1f, Uniform1f, WGC3Dint, WGC3Dfloat)
874
875 DELEGATE_TO_GL_3(uniform1fv, Uniform1fv, WGC3Dint, WGC3Dsizei,
876 const WGC3Dfloat*)
877
878 DELEGATE_TO_GL_2(uniform1i, Uniform1i, WGC3Dint, WGC3Dint)
879
880 DELEGATE_TO_GL_3(uniform1iv, Uniform1iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
881
882 DELEGATE_TO_GL_3(uniform2f, Uniform2f, WGC3Dint, WGC3Dfloat, WGC3Dfloat)
883
884 DELEGATE_TO_GL_3(uniform2fv, Uniform2fv, WGC3Dint, WGC3Dsizei,
885 const WGC3Dfloat*)
886
887 DELEGATE_TO_GL_3(uniform2i, Uniform2i, WGC3Dint, WGC3Dint, WGC3Dint)
888
889 DELEGATE_TO_GL_3(uniform2iv, Uniform2iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
890
891 DELEGATE_TO_GL_4(uniform3f, Uniform3f, WGC3Dint,
892 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
893
894 DELEGATE_TO_GL_3(uniform3fv, Uniform3fv, WGC3Dint, WGC3Dsizei,
895 const WGC3Dfloat*)
896
897 DELEGATE_TO_GL_4(uniform3i, Uniform3i, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
898
899 DELEGATE_TO_GL_3(uniform3iv, Uniform3iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
900
901 DELEGATE_TO_GL_5(uniform4f, Uniform4f, WGC3Dint,
902 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
903
904 DELEGATE_TO_GL_3(uniform4fv, Uniform4fv, WGC3Dint, WGC3Dsizei,
905 const WGC3Dfloat*)
906
907 DELEGATE_TO_GL_5(uniform4i, Uniform4i, WGC3Dint,
908 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dint)
909
910 DELEGATE_TO_GL_3(uniform4iv, Uniform4iv, WGC3Dint, WGC3Dsizei, const WGC3Dint*)
911
912 DELEGATE_TO_GL_4(uniformMatrix2fv, UniformMatrix2fv,
913 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
914
915 DELEGATE_TO_GL_4(uniformMatrix3fv, UniformMatrix3fv,
916 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
917
918 DELEGATE_TO_GL_4(uniformMatrix4fv, UniformMatrix4fv,
919 WGC3Dint, WGC3Dsizei, WGC3Dboolean, const WGC3Dfloat*)
920
921 DELEGATE_TO_GL_1(useProgram, UseProgram, WebGLId)
922
923 DELEGATE_TO_GL_1(validateProgram, ValidateProgram, WebGLId)
924
925 DELEGATE_TO_GL_2(vertexAttrib1f, VertexAttrib1f, WGC3Duint, WGC3Dfloat)
926
927 DELEGATE_TO_GL_2(vertexAttrib1fv, VertexAttrib1fv, WGC3Duint,
928 const WGC3Dfloat*)
929
930 DELEGATE_TO_GL_3(vertexAttrib2f, VertexAttrib2f, WGC3Duint,
931 WGC3Dfloat, WGC3Dfloat)
932
933 DELEGATE_TO_GL_2(vertexAttrib2fv, VertexAttrib2fv, WGC3Duint,
934 const WGC3Dfloat*)
935
936 DELEGATE_TO_GL_4(vertexAttrib3f, VertexAttrib3f, WGC3Duint,
937 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
938
939 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
940 const WGC3Dfloat*)
941
942 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
943 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
944
945 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
946 const WGC3Dfloat*)
947
948 void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer(
949 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
950 WGC3Dsizei stride, WGC3Dintptr offset) {
951 gl_->VertexAttribPointer(
952 index, size, type, normalized, stride,
953 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
954 }
955
956 DELEGATE_TO_GL_4(viewport, Viewport,
957 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
958
959 WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() {
960 GLuint o;
961 gl_->GenBuffers(1, &o);
962 return o;
963 }
964
965 WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() {
966 GLuint o = 0;
967 gl_->GenFramebuffers(1, &o);
968 return o;
969 }
970
971 WebGLId WebGraphicsContext3DCommandBufferImpl::createProgram() {
972 return gl_->CreateProgram();
973 }
974
975 WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() {
976 GLuint o;
977 gl_->GenRenderbuffers(1, &o);
978 return o;
979 }
980
981 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
982
983 WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() {
984 GLuint o;
985 gl_->GenTextures(1, &o);
986 return o;
987 }
988
989 void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) {
990 gl_->DeleteBuffers(1, &buffer);
991 }
992
993 void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer(
994 WebGLId framebuffer) {
995 gl_->DeleteFramebuffers(1, &framebuffer);
996 }
997
998 void WebGraphicsContext3DCommandBufferImpl::deleteProgram(WebGLId program) {
999 gl_->DeleteProgram(program);
1000 }
1001
1002 void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer(
1003 WebGLId renderbuffer) {
1004 gl_->DeleteRenderbuffers(1, &renderbuffer);
1005 }
1006
1007 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) {
1008 gl_->DeleteShader(shader);
1009 }
1010
1011 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) {
1012 gl_->DeleteTextures(1, &texture);
1013 }
1014
1015 void WebGraphicsContext3DCommandBufferImpl::copyTextureToCompositor(
1016 WebGLId texture, WebGLId parentTexture) {
1017 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::copyTextureToCompositor");
1018 gl_->CopyTextureToParentTextureCHROMIUM(texture, parentTexture);
1019 gl_->Flush();
1020 }
1021
1022 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() {
1023 // This may be called after tear-down of the RenderView.
1024 RenderView* renderview =
1025 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
1026 if (renderview)
1027 renderview->OnViewContextSwapBuffersComplete();
1028 }
1029
1030 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback(
1031 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb)
1032 {
1033 context_lost_callback_ = cb;
1034 }
1035
1036 void WebGraphicsContext3DCommandBufferImpl::OnContextLost() {
1037 if (context_lost_callback_) {
1038 context_lost_callback_->onContextLost();
1039 }
1040
1041 RenderView* renderview =
1042 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
1043 if (renderview)
1044 renderview->OnViewContextSwapBuffersAborted();
1045 }
1046
1047 #endif // defined(ENABLE_GPU)
OLDNEW
« no previous file with comments | « content/renderer/webgraphicscontext3d_command_buffer_impl.h ('k') | content/renderer/webplugin_delegate_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698