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