| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 gfx::AcceleratedWidget window) | 120 gfx::AcceleratedWidget window) |
| 121 : is_offscreen_(is_offscreen), | 121 : is_offscreen_(is_offscreen), |
| 122 window_(window), | 122 window_(window), |
| 123 initialized_(false), | 123 initialized_(false), |
| 124 initialize_failed_(false), | 124 initialize_failed_(false), |
| 125 context_(context.Pass()), | 125 context_(context.Pass()), |
| 126 gl_(NULL), | 126 gl_(NULL), |
| 127 context_lost_callback_(NULL), | 127 context_lost_callback_(NULL), |
| 128 context_lost_reason_(GL_NO_ERROR), | 128 context_lost_reason_(GL_NO_ERROR), |
| 129 attributes_(attributes), | 129 attributes_(attributes), |
| 130 cached_width_(0), | |
| 131 cached_height_(0), | |
| 132 flush_id_(0) { | 130 flush_id_(0) { |
| 133 } | 131 } |
| 134 | 132 |
| 135 WebGraphicsContext3DInProcessCommandBufferImpl:: | 133 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 136 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 134 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
| 137 } | 135 } |
| 138 | 136 |
| 139 // static | 137 // static |
| 140 void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( | 138 void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( |
| 141 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 139 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // direct OpenGL bindings needs to call the appropriate form of | 228 // direct OpenGL bindings needs to call the appropriate form of |
| 231 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong | 229 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong |
| 232 // context. Uncommenting the line below clears the current context so that | 230 // context. Uncommenting the line below clears the current context so that |
| 233 // any code not calling eglMakeCurrent in the appropriate place should crash. | 231 // any code not calling eglMakeCurrent in the appropriate place should crash. |
| 234 // This is not a perfect test but generally code that used the direct OpenGL | 232 // This is not a perfect test but generally code that used the direct OpenGL |
| 235 // bindings should not be mixed with code that uses WebGraphicsContext3D. | 233 // bindings should not be mixed with code that uses WebGraphicsContext3D. |
| 236 // | 234 // |
| 237 // GLInProcessContext::MakeCurrent(NULL); | 235 // GLInProcessContext::MakeCurrent(NULL); |
| 238 } | 236 } |
| 239 | 237 |
| 240 int WebGraphicsContext3DInProcessCommandBufferImpl::width() { | 238 // Helper macros to reduce the amount of code. |
| 241 return cached_width_; | 239 |
| 240 #define DELEGATE_TO_GL(name, glname) \ |
| 241 void WebGraphicsContext3DInProcessCommandBufferImpl::name() { \ |
| 242 ClearContext(); \ |
| 243 gl_->glname(); \ |
| 242 } | 244 } |
| 243 | 245 |
| 244 int WebGraphicsContext3DInProcessCommandBufferImpl::height() { | 246 #define DELEGATE_TO_GL_1(name, glname, t1) \ |
| 245 return cached_height_; | 247 void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ |
| 248 ClearContext(); \ |
| 249 gl_->glname(a1); \ |
| 250 } |
| 251 |
| 252 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \ |
| 253 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ |
| 254 ClearContext(); \ |
| 255 return gl_->glname(a1); \ |
| 256 } |
| 257 |
| 258 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \ |
| 259 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ |
| 260 ClearContext(); \ |
| 261 return gl_->glname(a1) ? true : false; \ |
| 262 } |
| 263 |
| 264 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \ |
| 265 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 266 t1 a1, t2 a2) { \ |
| 267 ClearContext(); \ |
| 268 gl_->glname(a1, a2); \ |
| 269 } |
| 270 |
| 271 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \ |
| 272 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \ |
| 273 ClearContext(); \ |
| 274 return gl_->glname(a1, a2); \ |
| 275 } |
| 276 |
| 277 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \ |
| 278 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 279 t1 a1, t2 a2, t3 a3) { \ |
| 280 ClearContext(); \ |
| 281 gl_->glname(a1, a2, a3); \ |
| 282 } |
| 283 |
| 284 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \ |
| 285 rt WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 286 t1 a1, t2 a2, t3 a3) { \ |
| 287 ClearContext(); \ |
| 288 return gl_->glname(a1, a2, a3); \ |
| 289 } |
| 290 |
| 291 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ |
| 292 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 293 t1 a1, t2 a2, t3 a3, t4 a4) { \ |
| 294 ClearContext(); \ |
| 295 gl_->glname(a1, a2, a3, a4); \ |
| 296 } |
| 297 |
| 298 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \ |
| 299 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 300 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \ |
| 301 ClearContext(); \ |
| 302 gl_->glname(a1, a2, a3, a4, a5); \ |
| 303 } |
| 304 |
| 305 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \ |
| 306 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 307 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) { \ |
| 308 ClearContext(); \ |
| 309 gl_->glname(a1, a2, a3, a4, a5, a6); \ |
| 310 } |
| 311 |
| 312 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \ |
| 313 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 314 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) { \ |
| 315 ClearContext(); \ |
| 316 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \ |
| 317 } |
| 318 |
| 319 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \ |
| 320 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 321 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) { \ |
| 322 ClearContext(); \ |
| 323 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \ |
| 324 } |
| 325 |
| 326 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
| 327 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
| 328 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) { \ |
| 329 ClearContext(); \ |
| 330 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
| 246 } | 331 } |
| 247 | 332 |
| 248 void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() { | 333 void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() { |
| 249 if (!isContextLost()) { | 334 if (!isContextLost()) { |
| 250 gl_->SwapBuffers(); | 335 gl_->SwapBuffers(); |
| 251 gl_->ShallowFlushCHROMIUM(); | 336 gl_->ShallowFlushCHROMIUM(); |
| 252 } | 337 } |
| 253 } | 338 } |
| 254 | 339 |
| 255 void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM( | 340 void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM( |
| 256 int x, int y, int width, int height) { | 341 int x, int y, int width, int height) { |
| 257 gl_->PostSubBufferCHROMIUM(x, y, width, height); | 342 gl_->PostSubBufferCHROMIUM(x, y, width, height); |
| 258 } | 343 } |
| 259 | 344 |
| 260 void WebGraphicsContext3DInProcessCommandBufferImpl::reshape( | 345 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float) |
| 261 int width, int height) { | |
| 262 reshapeWithScaleFactor(width, height, 1.0f); | |
| 263 } | |
| 264 | |
| 265 void WebGraphicsContext3DInProcessCommandBufferImpl::reshapeWithScaleFactor( | |
| 266 int width, int height, float scale_factor) { | |
| 267 cached_width_ = width; | |
| 268 cached_height_ = height; | |
| 269 | |
| 270 // TODO(gmam): See if we can comment this in. | |
| 271 // ClearContext(); | |
| 272 | |
| 273 gl_->ResizeCHROMIUM(width, height, scale_factor); | |
| 274 } | |
| 275 | 346 |
| 276 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError( | 347 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError( |
| 277 WGC3Denum error) { | 348 WGC3Denum error) { |
| 278 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == | 349 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == |
| 279 synthetic_errors_.end()) { | 350 synthetic_errors_.end()) { |
| 280 synthetic_errors_.push_back(error); | 351 synthetic_errors_.push_back(error); |
| 281 } | 352 } |
| 282 } | 353 } |
| 283 | 354 |
| 284 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM( | 355 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 450 |
| 380 void WebGraphicsContext3DInProcessCommandBufferImpl:: | 451 void WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 381 renderbufferStorageMultisampleCHROMIUM( | 452 renderbufferStorageMultisampleCHROMIUM( |
| 382 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, | 453 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, |
| 383 WGC3Dsizei width, WGC3Dsizei height) { | 454 WGC3Dsizei width, WGC3Dsizei height) { |
| 384 ClearContext(); | 455 ClearContext(); |
| 385 gl_->RenderbufferStorageMultisampleEXT( | 456 gl_->RenderbufferStorageMultisampleEXT( |
| 386 target, samples, internalformat, width, height); | 457 target, samples, internalformat, width, height); |
| 387 } | 458 } |
| 388 | 459 |
| 389 // Helper macros to reduce the amount of code. | |
| 390 | |
| 391 #define DELEGATE_TO_GL(name, glname) \ | |
| 392 void WebGraphicsContext3DInProcessCommandBufferImpl::name() { \ | |
| 393 ClearContext(); \ | |
| 394 gl_->glname(); \ | |
| 395 } | |
| 396 | |
| 397 #define DELEGATE_TO_GL_1(name, glname, t1) \ | |
| 398 void WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ | |
| 399 ClearContext(); \ | |
| 400 gl_->glname(a1); \ | |
| 401 } | |
| 402 | |
| 403 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \ | |
| 404 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ | |
| 405 ClearContext(); \ | |
| 406 return gl_->glname(a1); \ | |
| 407 } | |
| 408 | |
| 409 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \ | |
| 410 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1) { \ | |
| 411 ClearContext(); \ | |
| 412 return gl_->glname(a1) ? true : false; \ | |
| 413 } | |
| 414 | |
| 415 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \ | |
| 416 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 417 t1 a1, t2 a2) { \ | |
| 418 ClearContext(); \ | |
| 419 gl_->glname(a1, a2); \ | |
| 420 } | |
| 421 | |
| 422 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \ | |
| 423 rt WebGraphicsContext3DInProcessCommandBufferImpl::name(t1 a1, t2 a2) { \ | |
| 424 ClearContext(); \ | |
| 425 return gl_->glname(a1, a2); \ | |
| 426 } | |
| 427 | |
| 428 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \ | |
| 429 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 430 t1 a1, t2 a2, t3 a3) { \ | |
| 431 ClearContext(); \ | |
| 432 gl_->glname(a1, a2, a3); \ | |
| 433 } | |
| 434 | |
| 435 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \ | |
| 436 rt WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 437 t1 a1, t2 a2, t3 a3) { \ | |
| 438 ClearContext(); \ | |
| 439 return gl_->glname(a1, a2, a3); \ | |
| 440 } | |
| 441 | |
| 442 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ | |
| 443 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 444 t1 a1, t2 a2, t3 a3, t4 a4) { \ | |
| 445 ClearContext(); \ | |
| 446 gl_->glname(a1, a2, a3, a4); \ | |
| 447 } | |
| 448 | |
| 449 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \ | |
| 450 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 451 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \ | |
| 452 ClearContext(); \ | |
| 453 gl_->glname(a1, a2, a3, a4, a5); \ | |
| 454 } | |
| 455 | |
| 456 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \ | |
| 457 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 458 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) { \ | |
| 459 ClearContext(); \ | |
| 460 gl_->glname(a1, a2, a3, a4, a5, a6); \ | |
| 461 } | |
| 462 | |
| 463 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \ | |
| 464 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 465 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) { \ | |
| 466 ClearContext(); \ | |
| 467 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \ | |
| 468 } | |
| 469 | |
| 470 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \ | |
| 471 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 472 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) { \ | |
| 473 ClearContext(); \ | |
| 474 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \ | |
| 475 } | |
| 476 | |
| 477 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ | |
| 478 void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ | |
| 479 t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) { \ | |
| 480 ClearContext(); \ | |
| 481 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | |
| 482 } | |
| 483 | |
| 484 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum) | 460 DELEGATE_TO_GL_1(activeTexture, ActiveTexture, WGC3Denum) |
| 485 | 461 |
| 486 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId) | 462 DELEGATE_TO_GL_2(attachShader, AttachShader, WebGLId, WebGLId) |
| 487 | 463 |
| 488 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId, | 464 DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId, |
| 489 WGC3Duint, const WGC3Dchar*) | 465 WGC3Duint, const WGC3Dchar*) |
| 490 | 466 |
| 491 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId) | 467 DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId) |
| 492 | 468 |
| 493 void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer( | 469 void WebGraphicsContext3DInProcessCommandBufferImpl::bindFramebuffer( |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1208 |
| 1233 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1209 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1234 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1210 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1235 WGC3Denum, WGC3Denum, const void*) | 1211 WGC3Denum, WGC3Denum, const void*) |
| 1236 | 1212 |
| 1237 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1213 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1238 WGC3Denum) | 1214 WGC3Denum) |
| 1239 | 1215 |
| 1240 } // namespace gpu | 1216 } // namespace gpu |
| 1241 } // namespace webkit | 1217 } // namespace webkit |
| OLD | NEW |