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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 if (m_destructionInProgress) { | 217 if (m_destructionInProgress) { |
218 // It can be hit in the following sequence. | 218 // It can be hit in the following sequence. |
219 // 1. WebGL draws something. | 219 // 1. WebGL draws something. |
220 // 2. The compositor begins the frame. | 220 // 2. The compositor begins the frame. |
221 // 3. Javascript makes a context lost using WEBGL_lose_context extension
. | 221 // 3. Javascript makes a context lost using WEBGL_lose_context extension
. |
222 // 4. Here. | 222 // 4. Here. |
223 return false; | 223 return false; |
224 } | 224 } |
225 | 225 |
226 m_context->makeContextCurrent(); | |
227 | |
228 // Resolve the multisampled buffer into m_colorBuffer texture. | 226 // Resolve the multisampled buffer into m_colorBuffer texture. |
229 if (m_multisampleMode != None) | 227 if (m_multisampleMode != None) |
230 commit(); | 228 commit(); |
231 | 229 |
232 if (bitmap) { | 230 if (bitmap) { |
233 bitmap->setSize(size()); | 231 bitmap->setSize(size()); |
234 | 232 |
235 unsigned char* pixels = bitmap->pixels(); | 233 unsigned char* pixels = bitmap->pixels(); |
236 bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
remultipliedAlpha; | 234 bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
remultipliedAlpha; |
237 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 235 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); | 308 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); |
311 return; | 309 return; |
312 } | 310 } |
313 } | 311 } |
314 ASSERT_NOT_REACHED(); | 312 ASSERT_NOT_REACHED(); |
315 } | 313 } |
316 | 314 |
317 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail
box& mailbox) | 315 void DrawingBuffer::mailboxReleasedWithoutRecycling(const WebExternalTextureMail
box& mailbox) |
318 { | 316 { |
319 ASSERT(m_textureMailboxes.size()); | 317 ASSERT(m_textureMailboxes.size()); |
320 m_context->makeContextCurrent(); | |
321 // Ensure not to call the destructor until deleteMailbox() is completed. | 318 // Ensure not to call the destructor until deleteMailbox() is completed. |
322 RefPtr<DrawingBuffer> self = this; | 319 RefPtr<DrawingBuffer> self = this; |
323 deleteMailbox(mailbox); | 320 deleteMailbox(mailbox); |
324 } | 321 } |
325 | 322 |
326 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() | 323 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
327 { | 324 { |
328 if (m_recycledMailboxQueue.isEmpty()) | 325 if (m_recycledMailboxQueue.isEmpty()) |
329 return PassRefPtr<MailboxInfo>(); | 326 return PassRefPtr<MailboxInfo>(); |
330 | 327 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); | 378 m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
d); |
382 m_textureMailboxes.remove(i); | 379 m_textureMailboxes.remove(i); |
383 return; | 380 return; |
384 } | 381 } |
385 } | 382 } |
386 ASSERT_NOT_REACHED(); | 383 ASSERT_NOT_REACHED(); |
387 } | 384 } |
388 | 385 |
389 bool DrawingBuffer::initialize(const IntSize& size) | 386 bool DrawingBuffer::initialize(const IntSize& size) |
390 { | 387 { |
391 if (!m_context->makeContextCurrent()) { | |
392 // Most likely the GPU process exited and the attempt to reconnect to it
failed. | |
393 // Need to try to restore the context again later. | |
394 return false; | |
395 } | |
396 | |
397 if (m_context->isContextLost()) { | 388 if (m_context->isContextLost()) { |
398 // Need to try to restore the context again later. | 389 // Need to try to restore the context again later. |
399 return false; | 390 return false; |
400 } | 391 } |
401 | 392 |
402 if (m_requestedAttributes.alpha) { | 393 if (m_requestedAttributes.alpha) { |
403 m_internalColorFormat = GL_RGBA; | 394 m_internalColorFormat = GL_RGBA; |
404 m_colorFormat = GL_RGBA; | 395 m_colorFormat = GL_RGBA; |
405 m_internalRenderbufferFormat = GL_RGBA8_OES; | 396 m_internalRenderbufferFormat = GL_RGBA8_OES; |
406 } else { | 397 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 WGC3Dint stencilBits = 0; | 440 WGC3Dint stencilBits = 0; |
450 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); | 441 m_context->getIntegerv(GL_STENCIL_BITS, &stencilBits); |
451 m_actualAttributes.stencil = stencilBits > 0; | 442 m_actualAttributes.stencil = stencilBits > 0; |
452 } | 443 } |
453 m_actualAttributes.antialias = multisample(); | 444 m_actualAttributes.antialias = multisample(); |
454 return true; | 445 return true; |
455 } | 446 } |
456 | 447 |
457 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre
multiplyAlpha, bool flipY, bool fromFrontBuffer) | 448 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
m3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool pre
multiplyAlpha, bool flipY, bool fromFrontBuffer) |
458 { | 449 { |
459 if (!m_context->makeContextCurrent()) | |
460 return false; | |
461 | |
462 GLint textureId = m_colorBuffer.textureId; | 450 GLint textureId = m_colorBuffer.textureId; |
463 if (fromFrontBuffer && m_frontColorBuffer.textureId) | 451 if (fromFrontBuffer && m_frontColorBuffer.textureId) |
464 textureId = m_frontColorBuffer.textureId; | 452 textureId = m_frontColorBuffer.textureId; |
465 | 453 |
466 if (m_contentsChanged) { | 454 if (m_contentsChanged) { |
467 if (m_multisampleMode != None) { | 455 if (m_multisampleMode != None) { |
468 commit(); | 456 commit(); |
469 if (!m_framebufferBinding) | 457 if (!m_framebufferBinding) |
470 bind(); | 458 bind(); |
471 else | 459 else |
472 restoreFramebufferBinding(); | 460 restoreFramebufferBinding(); |
473 } | 461 } |
474 m_context->flush(); | 462 m_context->flush(); |
475 } | 463 } |
476 | 464 |
477 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) | 465 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) |
478 return false; | 466 return false; |
479 | 467 |
480 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 468 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
481 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 469 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
482 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 470 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
483 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, bufferMail
box->mailbox.name); | 471 m_context->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, bufferMail
box->mailbox.name); |
484 m_context->flush(); | 472 m_context->flush(); |
485 | 473 |
486 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 474 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
487 | 475 |
488 if (!context->makeContextCurrent()) | |
489 return false; | |
490 | |
491 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | 476 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); |
492 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, bufferMailbox->mailbox.name); | 477 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, bufferMailbox->mailbox.name); |
493 | 478 |
494 bool unpackPremultiplyAlphaNeeded = false; | 479 bool unpackPremultiplyAlphaNeeded = false; |
495 bool unpackUnpremultiplyAlphaNeeded = false; | 480 bool unpackUnpremultiplyAlphaNeeded = false; |
496 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
emultiplyAlpha) | 481 if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
emultiplyAlpha) |
497 unpackUnpremultiplyAlphaNeeded = true; | 482 unpackUnpremultiplyAlphaNeeded = true; |
498 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha
&& premultiplyAlpha) | 483 else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha
&& premultiplyAlpha) |
499 unpackPremultiplyAlphaNeeded = true; | 484 unpackPremultiplyAlphaNeeded = true; |
500 | 485 |
(...skipping 27 matching lines...) Expand all Loading... |
528 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); | 513 m_layer->setBlendBackgroundColor(m_actualAttributes.alpha); |
529 m_layer->setPremultipliedAlpha(m_actualAttributes.premultipliedAlpha); | 514 m_layer->setPremultipliedAlpha(m_actualAttributes.premultipliedAlpha); |
530 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 515 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
531 } | 516 } |
532 | 517 |
533 return m_layer->layer(); | 518 return m_layer->layer(); |
534 } | 519 } |
535 | 520 |
536 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 521 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
537 { | 522 { |
538 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) | 523 if (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR) |
539 return; | 524 return; |
540 | 525 |
541 if (!imageBuffer) | 526 if (!imageBuffer) |
542 return; | 527 return; |
543 Platform3DObject tex = imageBuffer->getBackingTexture(); | 528 Platform3DObject tex = imageBuffer->getBackingTexture(); |
544 if (tex) { | 529 if (tex) { |
545 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 530 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
546 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 531 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
547 m_context->produceTextureDirectCHROMIUM(m_frontColorBuffer.textureId, GL
_TEXTURE_2D, bufferMailbox->mailbox.name); | 532 m_context->produceTextureDirectCHROMIUM(m_frontColorBuffer.textureId, GL
_TEXTURE_2D, bufferMailbox->mailbox.name); |
548 m_context->flush(); | 533 m_context->flush(); |
549 | 534 |
550 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); | 535 bufferMailbox->mailbox.syncPoint = m_context->insertSyncPoint(); |
551 OwnPtr<WebGraphicsContext3DProvider> provider = | 536 OwnPtr<WebGraphicsContext3DProvider> provider = |
552 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D
Provider()); | 537 adoptPtr(Platform::current()->createSharedOffscreenGraphicsContext3D
Provider()); |
553 if (!provider) | 538 if (!provider) |
554 return; | 539 return; |
555 WebGraphicsContext3D* context = provider->context3d(); | 540 WebGraphicsContext3D* context = provider->context3d(); |
556 if (!context || !context->makeContextCurrent()) | 541 if (!context) |
557 return; | 542 return; |
558 | 543 |
559 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); | 544 context->waitSyncPoint(bufferMailbox->mailbox.syncPoint); |
560 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU
M(GL_TEXTURE_2D, bufferMailbox->mailbox.name); | 545 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIU
M(GL_TEXTURE_2D, bufferMailbox->mailbox.name); |
561 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, | 546 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, |
562 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 547 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
563 context->deleteTexture(sourceTexture); | 548 context->deleteTexture(sourceTexture); |
564 context->flush(); | 549 context->flush(); |
565 m_context->waitSyncPoint(context->insertSyncPoint()); | 550 m_context->waitSyncPoint(context->insertSyncPoint()); |
566 return; | 551 return; |
(...skipping 16 matching lines...) Expand all Loading... |
583 m_layer->clearTexture(); | 568 m_layer->clearTexture(); |
584 | 569 |
585 m_context->flush(); | 570 m_context->flush(); |
586 } | 571 } |
587 | 572 |
588 void DrawingBuffer::beginDestruction() | 573 void DrawingBuffer::beginDestruction() |
589 { | 574 { |
590 ASSERT(!m_destructionInProgress); | 575 ASSERT(!m_destructionInProgress); |
591 m_destructionInProgress = true; | 576 m_destructionInProgress = true; |
592 | 577 |
593 m_context->makeContextCurrent(); | |
594 | |
595 clearPlatformLayer(); | 578 clearPlatformLayer(); |
596 | 579 |
597 while (!m_recycledMailboxQueue.isEmpty()) | 580 while (!m_recycledMailboxQueue.isEmpty()) |
598 deleteMailbox(m_recycledMailboxQueue.takeLast()); | 581 deleteMailbox(m_recycledMailboxQueue.takeLast()); |
599 | 582 |
600 if (m_multisampleFBO) | 583 if (m_multisampleFBO) |
601 m_context->deleteFramebuffer(m_multisampleFBO); | 584 m_context->deleteFramebuffer(m_multisampleFBO); |
602 | 585 |
603 if (m_fbo) | 586 if (m_fbo) |
604 m_context->deleteFramebuffer(m_fbo); | 587 m_context->deleteFramebuffer(m_fbo); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 return true; | 862 return true; |
880 } | 863 } |
881 | 864 |
882 void DrawingBuffer::commit(long x, long y, long width, long height) | 865 void DrawingBuffer::commit(long x, long y, long width, long height) |
883 { | 866 { |
884 if (width < 0) | 867 if (width < 0) |
885 width = m_size.width(); | 868 width = m_size.width(); |
886 if (height < 0) | 869 if (height < 0) |
887 height = m_size.height(); | 870 height = m_size.height(); |
888 | 871 |
889 m_context->makeContextCurrent(); | |
890 | |
891 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 872 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
892 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 873 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
893 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 874 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
894 | 875 |
895 if (m_scissorEnabled) | 876 if (m_scissorEnabled) |
896 m_context->disable(GL_SCISSOR_TEST); | 877 m_context->disable(GL_SCISSOR_TEST); |
897 | 878 |
898 // Use NEAREST, because there is no scale performed during the blit. | 879 // Use NEAREST, because there is no scale performed during the blit. |
899 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 880 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
900 | 881 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 1049 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
1069 { | 1050 { |
1070 if (info->imageId) { | 1051 if (info->imageId) { |
1071 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 1052 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
1072 m_context->destroyImageCHROMIUM(info->imageId); | 1053 m_context->destroyImageCHROMIUM(info->imageId); |
1073 info->imageId = 0; | 1054 info->imageId = 0; |
1074 } | 1055 } |
1075 } | 1056 } |
1076 | 1057 |
1077 } // namespace blink | 1058 } // namespace blink |
OLD | NEW |