| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 if (m_destructionInProgress) { | 198 if (m_destructionInProgress) { |
| 199 // It can be hit in the following sequence. | 199 // It can be hit in the following sequence. |
| 200 // 1. WebGL draws something. | 200 // 1. WebGL draws something. |
| 201 // 2. The compositor begins the frame. | 201 // 2. The compositor begins the frame. |
| 202 // 3. Javascript makes a context lost using WEBGL_lose_context extension
. | 202 // 3. Javascript makes a context lost using WEBGL_lose_context extension
. |
| 203 // 4. Here. | 203 // 4. Here. |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 | 206 |
| 207 m_context->makeContextCurrent(); | |
| 208 | |
| 209 // Resolve the multisampled buffer into m_colorBuffer texture. | 207 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 210 if (m_multisampleMode != None) | 208 if (m_multisampleMode != None) |
| 211 commit(); | 209 commit(); |
| 212 | 210 |
| 213 if (bitmap) { | 211 if (bitmap) { |
| 214 bitmap->setSize(size()); | 212 bitmap->setSize(size()); |
| 215 | 213 |
| 216 unsigned char* pixels = bitmap->pixels(); | 214 unsigned char* pixels = bitmap->pixels(); |
| 217 bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
remultipliedAlpha; | 215 bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
remultipliedAlpha; |
| 218 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 216 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); | 289 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); |
| 292 return; | 290 return; |
| 293 } | 291 } |
| 294 } | 292 } |
| 295 ASSERT_NOT_REACHED(); | 293 ASSERT_NOT_REACHED(); |
| 296 } | 294 } |
| 297 | 295 |
| 298 void DrawingBuffer::mailboxReleasedWhileDestructionInProgress(const WebExternalT
extureMailbox& mailbox) | 296 void DrawingBuffer::mailboxReleasedWhileDestructionInProgress(const WebExternalT
extureMailbox& mailbox) |
| 299 { | 297 { |
| 300 ASSERT(m_textureMailboxes.size()); | 298 ASSERT(m_textureMailboxes.size()); |
| 301 m_context->makeContextCurrent(); | |
| 302 // Ensure not to call the destructor until deleteMailbox() is completed. | 299 // Ensure not to call the destructor until deleteMailbox() is completed. |
| 303 RefPtr<DrawingBuffer> self = this; | 300 RefPtr<DrawingBuffer> self = this; |
| 304 deleteMailbox(mailbox); | 301 deleteMailbox(mailbox); |
| 305 } | 302 } |
| 306 | 303 |
| 307 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() | 304 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
| 308 { | 305 { |
| 309 if (m_recycledMailboxQueue.isEmpty()) | 306 if (m_recycledMailboxQueue.isEmpty()) |
| 310 return PassRefPtr<MailboxInfo>(); | 307 return PassRefPtr<MailboxInfo>(); |
| 311 | 308 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); | 359 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); |
| 363 m_textureMailboxes.remove(i); | 360 m_textureMailboxes.remove(i); |
| 364 return; | 361 return; |
| 365 } | 362 } |
| 366 } | 363 } |
| 367 ASSERT_NOT_REACHED(); | 364 ASSERT_NOT_REACHED(); |
| 368 } | 365 } |
| 369 | 366 |
| 370 bool DrawingBuffer::initialize(const IntSize& size) | 367 bool DrawingBuffer::initialize(const IntSize& size) |
| 371 { | 368 { |
| 372 if (!m_context->makeContextCurrent()) { | |
| 373 // Most likely the GPU process exited and the attempt to reconnect to it
failed. | |
| 374 // Need to try to restore the context again later. | |
| 375 return false; | |
| 376 } | |
| 377 | |
| 378 if (m_context->isContextLost()) { | 369 if (m_context->isContextLost()) { |
| 379 // Need to try to restore the context again later. | 370 // Need to try to restore the context again later. |
| 380 return false; | 371 return false; |
| 381 } | 372 } |
| 382 | 373 |
| 383 if (m_requestedAttributes.alpha) { | 374 if (m_requestedAttributes.alpha) { |
| 384 m_internalColorFormat = GL_RGBA; | 375 m_internalColorFormat = GL_RGBA; |
| 385 m_colorFormat = GL_RGBA; | 376 m_colorFormat = GL_RGBA; |
| 386 m_internalRenderbufferFormat = GL_RGBA8_OES; | 377 m_internalRenderbufferFormat = GL_RGBA8_OES; |
| 387 } else { | 378 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 WGC3Dint stencilBits = 0; | 421 WGC3Dint stencilBits = 0; |
| 431 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); | 422 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); |
| 432 m_actualAttributes.stencil = stencilBits > 0; | 423 m_actualAttributes.stencil = stencilBits > 0; |
| 433 } | 424 } |
| 434 m_actualAttributes.antialias = multisample(); | 425 m_actualAttributes.antialias = multisample(); |
| 435 return true; | 426 return true; |
| 436 } | 427 } |
| 437 | 428 |
| 438 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre
multiplyAlpha, bool flipY, bool fromFrontBuffer) | 429 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre
multiplyAlpha, bool flipY, bool fromFrontBuffer) |
| 439 { | 430 { |
| 440 if (!m_context->makeContextCurrent()) | |
| 441 return false; | |
| 442 | |
| 443 GLint textureId = m_colorBuffer.textureId; | 431 GLint textureId = m_colorBuffer.textureId; |
| 444 if (fromFrontBuffer && m_frontColorBuffer.textureId) | 432 if (fromFrontBuffer && m_frontColorBuffer.textureId) |
| 445 textureId = m_frontColorBuffer.textureId; | 433 textureId = m_frontColorBuffer.textureId; |
| 446 | 434 |
| 447 if (m_contentsChanged) { | 435 if (m_contentsChanged) { |
| 448 if (m_multisampleMode != None) { | 436 if (m_multisampleMode != None) { |
| 449 commit(); | 437 commit(); |
| 450 if (!m_framebufferBinding) | 438 if (!m_framebufferBinding) |
| 451 bind(); | 439 bind(); |
| 452 else | 440 else |
| 453 restoreFramebufferBinding(); | 441 restoreFramebufferBinding(); |
| 454 } | 442 } |
| 455 m_context->flush(); | 443 m_context->flush(); |
| 456 } | 444 } |
| 457 | 445 |
| 458 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) | 446 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) |
| 459 return false; | 447 return false; |
| 460 | 448 |
| 461 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 449 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
| 462 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 450 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
| 463 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 451 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
| 464 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, bufferMail
box->mailbox.name); | 452 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, bufferMail
box->mailbox.name); |
| 465 m_context->flush(); | 453 m_context->flush(); |
| 466 | 454 |
| 467 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 455 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| 468 | 456 |
| 469 if (!context->makeContextCurrent()) | |
| 470 return false; | |
| 471 | |
| 472 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | 457 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); |
| 473 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, bufferMailbox->mailbox.name); | 458 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, bufferMailbox->mailbox.name); |
| 474 | 459 |
| 475 bool unpackPremultiplyAlphaNeeded = false; | 460 bool unpackPremultiplyAlphaNeeded = false; |
| 476 bool unpackUnpremultiplyAlphaNeeded = false; | 461 bool unpackUnpremultiplyAlphaNeeded = false; |
| 477 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
emultiplyAlpha) | 462 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
emultiplyAlpha) |
| 478 unpackUnpremultiplyAlphaNeeded = true; | 463 unpackUnpremultiplyAlphaNeeded = true; |
| 479 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha
&& premultiplyAlpha) | 464 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha
&& premultiplyAlpha) |
| 480 unpackPremultiplyAlphaNeeded = true; | 465 unpackPremultiplyAlphaNeeded = true; |
| 481 | 466 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 509 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); | 494 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); |
| 510 m_layer->setPremultipliedAlpha(m_actualAttributes.premultipliedAlpha); | 495 m_layer->setPremultipliedAlpha(m_actualAttributes.premultipliedAlpha); |
| 511 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 496 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 512 } | 497 } |
| 513 | 498 |
| 514 return m_layer->layer(); | 499 return m_layer->layer(); |
| 515 } | 500 } |
| 516 | 501 |
| 517 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 502 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
| 518 { | 503 { |
| 519 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) | 504 if (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR) |
| 520 return; | 505 return; |
| 521 | 506 |
| 522 if (!imageBuffer) | 507 if (!imageBuffer) |
| 523 return; | 508 return; |
| 524 Platform3DObject tex = imageBuffer->getBackingTexture(); | 509 Platform3DObject tex = imageBuffer->getBackingTexture(); |
| 525 if (tex) { | 510 if (tex) { |
| 526 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 511 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
| 527 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 512 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
| 528 m_context->produceTextureDirectCHROMIUM(m_frontColorBuffer.textureId, GL
_TEXTURE_2D, bufferMailbox->mailbox.name); | 513 m_context->produceTextureDirectCHROMIUM(m_frontColorBuffer.textureId, GL
_TEXTURE_2D, bufferMailbox->mailbox.name); |
| 529 m_context->flush(); | 514 m_context->flush(); |
| 530 | 515 |
| 531 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 516 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
| 532 OwnPtr<WebGraphicsContext3DProvider> provider = | 517 OwnPtr<WebGraphicsContext3DProvider> provider = |
| 533 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D
Provider()); | 518 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D
Provider()); |
| 534 if (!provider) | 519 if (!provider) |
| 535 return; | 520 return; |
| 536 WebGraphicsContext3D* context = provider->context3d(); | 521 WebGraphicsContext3D* context = provider->context3d(); |
| 537 if (!context || !context->makeContextCurrent()) | 522 if (!context) |
| 538 return; | 523 return; |
| 539 | 524 |
| 540 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | 525 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); |
| 541 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU
M(GL_TEXTURE_2D, bufferMailbox->mailbox.name); | 526 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU
M(GL_TEXTURE_2D, bufferMailbox->mailbox.name); |
| 542 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, | 527 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, |
| 543 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 528 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 544 context->deleteTexture(sourceTexture); | 529 context->deleteTexture(sourceTexture); |
| 545 context->flush(); | 530 context->flush(); |
| 546 m_context->waitSyncPoint(context->insertSyncPoint()); | 531 m_context->waitSyncPoint(context->insertSyncPoint()); |
| 547 return; | 532 return; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 564 m_layer->clearTexture(); | 549 m_layer->clearTexture(); |
| 565 | 550 |
| 566 m_context->flush(); | 551 m_context->flush(); |
| 567 } | 552 } |
| 568 | 553 |
| 569 void DrawingBuffer::beginDestruction() | 554 void DrawingBuffer::beginDestruction() |
| 570 { | 555 { |
| 571 ASSERT(!m_destructionInProgress); | 556 ASSERT(!m_destructionInProgress); |
| 572 m_destructionInProgress = true; | 557 m_destructionInProgress = true; |
| 573 | 558 |
| 574 m_context->makeContextCurrent(); | |
| 575 | |
| 576 clearPlatformLayer(); | 559 clearPlatformLayer(); |
| 577 | 560 |
| 578 while (!m_recycledMailboxQueue.isEmpty()) | 561 while (!m_recycledMailboxQueue.isEmpty()) |
| 579 deleteMailbox(m_recycledMailboxQueue.takeLast()); | 562 deleteMailbox(m_recycledMailboxQueue.takeLast()); |
| 580 | 563 |
| 581 if (m_multisampleFBO) | 564 if (m_multisampleFBO) |
| 582 m_context->deleteFramebuffer(m_multisampleFBO); | 565 m_context->deleteFramebuffer(m_multisampleFBO); |
| 583 | 566 |
| 584 if (m_fbo) | 567 if (m_fbo) |
| 585 m_context->deleteFramebuffer(m_fbo); | 568 m_context->deleteFramebuffer(m_fbo); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 return true; | 843 return true; |
| 861 } | 844 } |
| 862 | 845 |
| 863 void DrawingBuffer::commit(long x, long y, long width, long height) | 846 void DrawingBuffer::commit(long x, long y, long width, long height) |
| 864 { | 847 { |
| 865 if (width < 0) | 848 if (width < 0) |
| 866 width = m_size.width(); | 849 width = m_size.width(); |
| 867 if (height < 0) | 850 if (height < 0) |
| 868 height = m_size.height(); | 851 height = m_size.height(); |
| 869 | 852 |
| 870 m_context->makeContextCurrent(); | |
| 871 | |
| 872 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 853 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
| 873 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 854 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
| 874 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 855 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
| 875 | 856 |
| 876 if (m_scissorEnabled) | 857 if (m_scissorEnabled) |
| 877 m_context->disable(GL_SCISSOR_TEST); | 858 m_context->disable(GL_SCISSOR_TEST); |
| 878 | 859 |
| 879 // Use NEAREST, because there is no scale performed during the blit. | 860 // Use NEAREST, because there is no scale performed during the blit. |
| 880 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 861 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 881 | 862 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 1030 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
| 1050 { | 1031 { |
| 1051 if (info->imageId) { | 1032 if (info->imageId) { |
| 1052 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 1033 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
| 1053 m_context->destroyImageCHROMIUM(info->imageId); | 1034 m_context->destroyImageCHROMIUM(info->imageId); |
| 1054 info->imageId = 0; | 1035 info->imageId = 0; |
| 1055 } | 1036 } |
| 1056 } | 1037 } |
| 1057 | 1038 |
| 1058 } // namespace blink | 1039 } // namespace blink |
| OLD | NEW |