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

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

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

Powered by Google App Engine
This is Rietveld 408576698