| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    59 { |    59 { | 
|    60     DEFINE_STATIC_LOCAL(WTF::RefCountedLeakCounter, staticDrawingBufferCounter, 
      ("DrawingBuffer")); |    60     DEFINE_STATIC_LOCAL(WTF::RefCountedLeakCounter, staticDrawingBufferCounter, 
      ("DrawingBuffer")); | 
|    61     return staticDrawingBufferCounter; |    61     return staticDrawingBufferCounter; | 
|    62 } |    62 } | 
|    63 #endif |    63 #endif | 
|    64  |    64  | 
|    65 class ScopedTextureUnit0BindingRestorer { |    65 class ScopedTextureUnit0BindingRestorer { | 
|    66     STACK_ALLOCATED(); |    66     STACK_ALLOCATED(); | 
|    67     WTF_MAKE_NONCOPYABLE(ScopedTextureUnit0BindingRestorer); |    67     WTF_MAKE_NONCOPYABLE(ScopedTextureUnit0BindingRestorer); | 
|    68 public: |    68 public: | 
|    69     ScopedTextureUnit0BindingRestorer(WebGraphicsContext3D* context, GLenum acti
      veTextureUnit, Platform3DObject textureUnitZeroId) |    69     ScopedTextureUnit0BindingRestorer(gpu::gles2::GLES2Interface* gl, GLenum act
      iveTextureUnit, Platform3DObject textureUnitZeroId) | 
|    70         : m_context(context) |    70         : m_gl(gl) | 
|    71         , m_oldActiveTextureUnit(activeTextureUnit) |    71         , m_oldActiveTextureUnit(activeTextureUnit) | 
|    72         , m_oldTextureUnitZeroId(textureUnitZeroId) |    72         , m_oldTextureUnitZeroId(textureUnitZeroId) | 
|    73     { |    73     { | 
|    74         m_context->activeTexture(GL_TEXTURE0); |    74         m_gl->ActiveTexture(GL_TEXTURE0); | 
|    75     } |    75     } | 
|    76     ~ScopedTextureUnit0BindingRestorer() |    76     ~ScopedTextureUnit0BindingRestorer() | 
|    77     { |    77     { | 
|    78         m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); |    78         m_gl->BindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); | 
|    79         m_context->activeTexture(m_oldActiveTextureUnit); |    79         m_gl->ActiveTexture(m_oldActiveTextureUnit); | 
|    80     } |    80     } | 
|    81  |    81  | 
|    82 private: |    82 private: | 
|    83     WebGraphicsContext3D* m_context; |    83     gpu::gles2::GLES2Interface* m_gl; | 
|    84     GLenum m_oldActiveTextureUnit; |    84     GLenum m_oldActiveTextureUnit; | 
|    85     Platform3DObject m_oldTextureUnitZeroId; |    85     Platform3DObject m_oldTextureUnitZeroId; | 
|    86 }; |    86 }; | 
|    87  |    87  | 
|    88 static bool shouldFailDrawingBufferCreationForTesting = false; |    88 static bool shouldFailDrawingBufferCreationForTesting = false; | 
|    89  |    89  | 
|    90 } // namespace |    90 } // namespace | 
|    91  |    91  | 
|    92 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3D>
       context, const IntSize& size, PreserveDrawingBuffer preserve, WebGraphicsContex
      t3D::Attributes requestedAttributes) |    92 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<WebGraphicsContext3D>
       context, const IntSize& size, PreserveDrawingBuffer preserve, WebGraphicsContex
      t3D::Attributes requestedAttributes) | 
|    93 { |    93 { | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   262  |   262  | 
|   263         unsigned char* pixels = bitmap->pixels(); |   263         unsigned char* pixels = bitmap->pixels(); | 
|   264         bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
      remultipliedAlpha; |   264         bool needPremultiply = m_actualAttributes.alpha && !m_actualAttributes.p
      remultipliedAlpha; | 
|   265         WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
      n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |   265         WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
      n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 
|   266         if (pixels) |   266         if (pixels) | 
|   267             readBackFramebuffer(pixels, size().width(), size().height(), Readbac
      kSkia, op); |   267             readBackFramebuffer(pixels, size().width(), size().height(), Readbac
      kSkia, op); | 
|   268     } |   268     } | 
|   269  |   269  | 
|   270     // We must restore the texture binding since creating new textures, |   270     // We must restore the texture binding since creating new textures, | 
|   271     // consuming and producing mailboxes changes it. |   271     // consuming and producing mailboxes changes it. | 
|   272     ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
      nit, m_texture2DBinding); |   272     ScopedTextureUnit0BindingRestorer restorer(m_gl, m_activeTextureUnit, m_text
      ure2DBinding); | 
|   273  |   273  | 
|   274     // First try to recycle an old buffer. |   274     // First try to recycle an old buffer. | 
|   275     RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |   275     RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 
|   276  |   276  | 
|   277     // No buffer available to recycle, create a new one. |   277     // No buffer available to recycle, create a new one. | 
|   278     if (!frontColorBufferMailbox) { |   278     if (!frontColorBufferMailbox) { | 
|   279         TextureInfo newTexture = createTextureAndAllocateMemory(m_size); |   279         TextureInfo newTexture = createTextureAndAllocateMemory(m_size); | 
|   280         // Bad things happened, abandon ship. |   280         // Bad things happened, abandon ship. | 
|   281         if (!newTexture.textureId) |   281         if (!newTexture.textureId) | 
|   282             return false; |   282             return false; | 
|   283  |   283  | 
|   284         frontColorBufferMailbox = createNewMailbox(newTexture); |   284         frontColorBufferMailbox = createNewMailbox(newTexture); | 
|   285     } |   285     } | 
|   286  |   286  | 
|   287     if (m_preserveDrawingBuffer == Discard) { |   287     if (m_preserveDrawingBuffer == Discard) { | 
|   288         std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); |   288         std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); | 
|   289         // It appears safe to overwrite the context's framebuffer binding in the
       Discard case since there will always be a |   289         // It appears safe to overwrite the context's framebuffer binding in the
       Discard case since there will always be a | 
|   290         // WebGLRenderingContext::clearIfComposited() call made before the next 
      draw call which restores the framebuffer binding. |   290         // WebGLRenderingContext::clearIfComposited() call made before the next 
      draw call which restores the framebuffer binding. | 
|   291         // If this stops being true at some point, we should track the current f
      ramebuffer binding in the DrawingBuffer and restore |   291         // If this stops being true at some point, we should track the current f
      ramebuffer binding in the DrawingBuffer and restore | 
|   292         // it after attaching the new back buffer here. |   292         // it after attaching the new back buffer here. | 
|   293         m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   293         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   294         attachColorBufferToCurrentFBO(); |   294         attachColorBufferToCurrentFBO(); | 
|   295  |   295  | 
|   296         if (m_discardFramebufferSupported) { |   296         if (m_discardFramebufferSupported) { | 
|   297             // Explicitly discard framebuffer to save GPU memory bandwidth for t
      ile-based GPU arch. |   297             // Explicitly discard framebuffer to save GPU memory bandwidth for t
      ile-based GPU arch. | 
|   298             const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT
      TACHMENT, GL_STENCIL_ATTACHMENT}; |   298             const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT
      TACHMENT, GL_STENCIL_ATTACHMENT}; | 
|   299             m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); |   299             m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); | 
|   300         } |   300         } | 
|   301     } else { |   301     } else { | 
|   302         m_context->copyTextureCHROMIUM(m_colorBuffer.textureId, frontColorBuffer
      Mailbox->textureInfo.textureId, frontColorBufferMailbox->textureInfo.parameters.
      internalColorFormat, GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, GL_FALSE); |   302         m_context->copyTextureCHROMIUM(m_colorBuffer.textureId, frontColorBuffer
      Mailbox->textureInfo.textureId, frontColorBufferMailbox->textureInfo.parameters.
      internalColorFormat, GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, GL_FALSE); | 
|   303     } |   303     } | 
|   304  |   304  | 
|   305     restoreFramebufferBindings(); |   305     restoreFramebufferBindings(); | 
|   306     m_contentsChanged = false; |   306     m_contentsChanged = false; | 
|   307  |   307  | 
|   308     m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo
      .textureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBu
      fferMailbox->mailbox.name); |   308     m_context->produceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo
      .textureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBu
      fferMailbox->mailbox.name); | 
|   309     const WGC3Duint64 fenceSync = m_context->insertFenceSyncCHROMIUM(); |   309     const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 
|   310     m_context->flush(); |   310     m_context->flush(); | 
|   311     frontColorBufferMailbox->mailbox.validSyncToken = m_context->genSyncTokenCHR
      OMIUM(fenceSync, frontColorBufferMailbox->mailbox.syncToken); |   311     frontColorBufferMailbox->mailbox.validSyncToken = m_context->genSyncTokenCHR
      OMIUM(fenceSync, frontColorBufferMailbox->mailbox.syncToken); | 
|   312     frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex
      tureInfo.imageId != 0; |   312     frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->tex
      tureInfo.imageId != 0; | 
|   313     frontColorBufferMailbox->mailbox.textureTarget = frontColorBufferMailbox->te
      xtureInfo.parameters.target; |   313     frontColorBufferMailbox->mailbox.textureTarget = frontColorBufferMailbox->te
      xtureInfo.parameters.target; | 
|   314     frontColorBufferMailbox->mailbox.textureSize = WebSize(m_size.width(), m_siz
      e.height()); |   314     frontColorBufferMailbox->mailbox.textureSize = WebSize(m_size.width(), m_siz
      e.height()); | 
|   315     setBufferClearNeeded(true); |   315     setBufferClearNeeded(true); | 
|   316  |   316  | 
|   317     // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
      as live mailboxes |   317     // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h
      as live mailboxes | 
|   318     ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); |   318     ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); | 
|   319     frontColorBufferMailbox->m_parentDrawingBuffer = this; |   319     frontColorBufferMailbox->m_parentDrawingBuffer = this; | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   400     RefPtr<MailboxInfo> mailboxInfo; |   400     RefPtr<MailboxInfo> mailboxInfo; | 
|   401     for (size_t i = 0; i < m_textureMailboxes.size(); i++) { |   401     for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | 
|   402         if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { |   402         if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { | 
|   403             mailboxInfo = m_textureMailboxes[i]; |   403             mailboxInfo = m_textureMailboxes[i]; | 
|   404             break; |   404             break; | 
|   405         } |   405         } | 
|   406     } |   406     } | 
|   407     ASSERT(mailboxInfo); |   407     ASSERT(mailboxInfo); | 
|   408  |   408  | 
|   409     if (mailboxInfo->mailbox.validSyncToken) { |   409     if (mailboxInfo->mailbox.validSyncToken) { | 
|   410         m_context->waitSyncTokenCHROMIUM(mailboxInfo->mailbox.syncToken); |   410         m_gl->WaitSyncTokenCHROMIUM(mailboxInfo->mailbox.syncToken); | 
|   411         mailboxInfo->mailbox.validSyncToken = false; |   411         mailboxInfo->mailbox.validSyncToken = false; | 
|   412     } |   412     } | 
|   413  |   413  | 
|   414     if (mailboxInfo->size != m_size) { |   414     if (mailboxInfo->size != m_size) { | 
|   415         resizeTextureMemory(&mailboxInfo->textureInfo, m_size); |   415         resizeTextureMemory(&mailboxInfo->textureInfo, m_size); | 
|   416         mailboxInfo->size = m_size; |   416         mailboxInfo->size = m_size; | 
|   417     } |   417     } | 
|   418  |   418  | 
|   419     return mailboxInfo.release(); |   419     return mailboxInfo.release(); | 
|   420 } |   420 } | 
|   421  |   421  | 
|   422 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(const Tex
      tureInfo& info) |   422 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(const Tex
      tureInfo& info) | 
|   423 { |   423 { | 
|   424     RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |   424     RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 
|   425     m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |   425     m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 
|   426     returnMailbox->textureInfo = info; |   426     returnMailbox->textureInfo = info; | 
|   427     returnMailbox->size = m_size; |   427     returnMailbox->size = m_size; | 
|   428     m_textureMailboxes.append(returnMailbox); |   428     m_textureMailboxes.append(returnMailbox); | 
|   429     return returnMailbox.release(); |   429     return returnMailbox.release(); | 
|   430 } |   430 } | 
|   431  |   431  | 
|   432 void DrawingBuffer::deleteMailbox(const WebExternalTextureMailbox& mailbox) |   432 void DrawingBuffer::deleteMailbox(const WebExternalTextureMailbox& mailbox) | 
|   433 { |   433 { | 
|   434     for (size_t i = 0; i < m_textureMailboxes.size(); i++) { |   434     for (size_t i = 0; i < m_textureMailboxes.size(); i++) { | 
|   435         if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { |   435         if (nameEquals(m_textureMailboxes[i]->mailbox, mailbox)) { | 
|   436             if (mailbox.validSyncToken) |   436             if (mailbox.validSyncToken) | 
|   437                 m_context->waitSyncTokenCHROMIUM(mailbox.syncToken); |   437                 m_gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 
|   438  |   438  | 
|   439             deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); |   439             deleteChromiumImageForTexture(&m_textureMailboxes[i]->textureInfo); | 
|   440  |   440  | 
|   441             m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
      d); |   441             m_context->deleteTexture(m_textureMailboxes[i]->textureInfo.textureI
      d); | 
|   442             m_textureMailboxes.remove(i); |   442             m_textureMailboxes.remove(i); | 
|   443             return; |   443             return; | 
|   444         } |   444         } | 
|   445     } |   445     } | 
|   446     ASSERT_NOT_REACHED(); |   446     ASSERT_NOT_REACHED(); | 
|   447 } |   447 } | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|   463         if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
      exture")) { |   463         if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t
      exture")) { | 
|   464             m_antiAliasingMode = MSAAImplicitResolve; |   464             m_antiAliasingMode = MSAAImplicitResolve; | 
|   465         } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space
      _antialiasing")) { |   465         } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space
      _antialiasing")) { | 
|   466             m_antiAliasingMode = ScreenSpaceAntialiasing; |   466             m_antiAliasingMode = ScreenSpaceAntialiasing; | 
|   467         } |   467         } | 
|   468     } |   468     } | 
|   469     m_sampleCount = std::min(4, maxSampleCount); |   469     m_sampleCount = std::min(4, maxSampleCount); | 
|   470  |   470  | 
|   471     m_fbo = m_context->createFramebuffer(); |   471     m_fbo = m_context->createFramebuffer(); | 
|   472  |   472  | 
|   473     m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   473     m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   474     createSecondaryBuffers(); |   474     createSecondaryBuffers(); | 
|   475     // We first try to initialize everything with the requested attributes. |   475     // We first try to initialize everything with the requested attributes. | 
|   476     if (!reset(size)) |   476     if (!reset(size)) | 
|   477         return false; |   477         return false; | 
|   478     // If that succeeds, we then see what we actually got and update our actual 
      attributes to reflect that. |   478     // If that succeeds, we then see what we actually got and update our actual 
      attributes to reflect that. | 
|   479     m_actualAttributes = m_requestedAttributes; |   479     m_actualAttributes = m_requestedAttributes; | 
|   480     if (m_requestedAttributes.alpha) { |   480     if (m_requestedAttributes.alpha) { | 
|   481         WGC3Dint alphaBits = 0; |   481         WGC3Dint alphaBits = 0; | 
|   482         m_context->getIntegerv(GL_ALPHA_BITS, &alphaBits); |   482         m_context->getIntegerv(GL_ALPHA_BITS, &alphaBits); | 
|   483         m_actualAttributes.alpha = alphaBits > 0; |   483         m_actualAttributes.alpha = alphaBits > 0; | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|   495     m_actualAttributes.antialias = multisample(); |   495     m_actualAttributes.antialias = multisample(); | 
|   496  |   496  | 
|   497     if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |   497     if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { | 
|   498         // It's possible that the drawing buffer allocation provokes a context l
      oss, so check again just in case. http://crbug.com/512302 |   498         // It's possible that the drawing buffer allocation provokes a context l
      oss, so check again just in case. http://crbug.com/512302 | 
|   499         return false; |   499         return false; | 
|   500     } |   500     } | 
|   501  |   501  | 
|   502     return true; |   502     return true; | 
|   503 } |   503 } | 
|   504  |   504  | 
|   505 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platfor
      m3DObject texture, GLenum internalFormat, |   505 bool DrawingBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, gpu::gl
      es2::GLES2Interface* gl, Platform3DObject texture, GLenum internalFormat, | 
|   506     GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi
      ngBuffer sourceBuffer) |   506     GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceDrawi
      ngBuffer sourceBuffer) | 
|   507 { |   507 { | 
|   508     if (m_contentsChanged) { |   508     if (m_contentsChanged) { | 
|   509         if (m_antiAliasingMode != None) { |   509         if (m_antiAliasingMode != None) { | 
|   510             commit(); |   510             commit(); | 
|   511             restoreFramebufferBindings(); |   511             restoreFramebufferBindings(); | 
|   512         } |   512         } | 
|   513         m_context->flush(); |   513         m_context->flush(); | 
|   514     } |   514     } | 
|   515  |   515  | 
|   516     // Assume that the destination target is GL_TEXTURE_2D. |   516     // Assume that the destination target is GL_TEXTURE_2D. | 
|   517     if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
      at, destType, level)) |   517     if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
      at, destType, level)) | 
|   518         return false; |   518         return false; | 
|   519  |   519  | 
|   520     // Contexts may be in a different share group. We must transfer the texture 
      through a mailbox first |   520     // Contexts may be in a different share group. We must transfer the texture 
      through a mailbox first | 
|   521     WebExternalTextureMailbox mailbox; |   521     WebExternalTextureMailbox mailbox; | 
|   522     GLint textureId = 0; |   522     GLint textureId = 0; | 
|   523     GLenum target = 0; |   523     GLenum target = 0; | 
|   524     if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { |   524     if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { | 
|   525         textureId = m_frontColorBuffer.texInfo.textureId; |   525         textureId = m_frontColorBuffer.texInfo.textureId; | 
|   526         mailbox = m_frontColorBuffer.mailbox; |   526         mailbox = m_frontColorBuffer.mailbox; | 
|   527         target = m_frontColorBuffer.texInfo.parameters.target; |   527         target = m_frontColorBuffer.texInfo.parameters.target; | 
|   528     } else { |   528     } else { | 
|   529         textureId = m_colorBuffer.textureId; |   529         textureId = m_colorBuffer.textureId; | 
|   530         target = m_colorBuffer.parameters.target; |   530         target = m_colorBuffer.parameters.target; | 
|   531         m_context->genMailboxCHROMIUM(mailbox.name); |   531         m_context->genMailboxCHROMIUM(mailbox.name); | 
|   532         m_context->produceTextureDirectCHROMIUM(textureId, target, mailbox.name)
      ; |   532         m_context->produceTextureDirectCHROMIUM(textureId, target, mailbox.name)
      ; | 
|   533         const WGC3Duint64 fenceSync = m_context->insertFenceSyncCHROMIUM(); |   533         const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 
|   534         m_context->flush(); |   534         m_context->flush(); | 
|   535         mailbox.validSyncToken = m_context->genSyncTokenCHROMIUM(fenceSync, mail
      box.syncToken); |   535         mailbox.validSyncToken = m_context->genSyncTokenCHROMIUM(fenceSync, mail
      box.syncToken); | 
|   536     } |   536     } | 
|   537  |   537  | 
|   538     if (mailbox.validSyncToken) |   538     if (mailbox.validSyncToken) | 
|   539         context->waitSyncTokenCHROMIUM(mailbox.syncToken); |   539         gl->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 
|   540     Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(ta
      rget, mailbox.name); |   540     Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(ta
      rget, mailbox.name); | 
|   541  |   541  | 
|   542     GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; |   542     GLboolean unpackPremultiplyAlphaNeeded = GL_FALSE; | 
|   543     GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; |   543     GLboolean unpackUnpremultiplyAlphaNeeded = GL_FALSE; | 
|   544     if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
      emultiplyAlpha) |   544     if (m_actualAttributes.alpha && m_actualAttributes.premultipliedAlpha && !pr
      emultiplyAlpha) | 
|   545         unpackUnpremultiplyAlphaNeeded = GL_TRUE; |   545         unpackUnpremultiplyAlphaNeeded = GL_TRUE; | 
|   546     else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha 
      && premultiplyAlpha) |   546     else if (m_actualAttributes.alpha && !m_actualAttributes.premultipliedAlpha 
      && premultiplyAlpha) | 
|   547         unpackPremultiplyAlphaNeeded = GL_TRUE; |   547         unpackPremultiplyAlphaNeeded = GL_TRUE; | 
|   548  |   548  | 
|   549     context->copyTextureCHROMIUM(sourceTexture, texture, internalFormat, destTyp
      e, flipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); |   549     context->copyTextureCHROMIUM(sourceTexture, texture, internalFormat, destTyp
      e, flipY, unpackPremultiplyAlphaNeeded, unpackUnpremultiplyAlphaNeeded); | 
|   550  |   550  | 
|   551     context->deleteTexture(sourceTexture); |   551     context->deleteTexture(sourceTexture); | 
|   552  |   552  | 
|   553     const WGC3Duint64 fenceSync = context->insertFenceSyncCHROMIUM(); |   553     const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 
|   554  |   554  | 
|   555     context->flush(); |   555     context->flush(); | 
|   556     GLbyte syncToken[24]; |   556     GLbyte syncToken[24]; | 
|   557     if (context->genSyncTokenCHROMIUM(fenceSync, syncToken)) |   557     if (context->genSyncTokenCHROMIUM(fenceSync, syncToken)) | 
|   558         m_context->waitSyncTokenCHROMIUM(syncToken); |   558         m_gl->WaitSyncTokenCHROMIUM(syncToken); | 
|   559  |   559  | 
|   560     return true; |   560     return true; | 
|   561 } |   561 } | 
|   562  |   562  | 
|   563 Platform3DObject DrawingBuffer::framebuffer() const |   563 Platform3DObject DrawingBuffer::framebuffer() const | 
|   564 { |   564 { | 
|   565     return m_fbo; |   565     return m_fbo; | 
|   566 } |   566 } | 
|   567  |   567  | 
|   568 WebLayer* DrawingBuffer::platformLayer() |   568 WebLayer* DrawingBuffer::platformLayer() | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   627     if (m_layer) |   627     if (m_layer) | 
|   628         GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |   628         GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 
|   629 } |   629 } | 
|   630  |   630  | 
|   631 WebGLId DrawingBuffer::createColorTexture(const TextureParameters& parameters) |   631 WebGLId DrawingBuffer::createColorTexture(const TextureParameters& parameters) | 
|   632 { |   632 { | 
|   633     WebGLId offscreenColorTexture = m_context->createTexture(); |   633     WebGLId offscreenColorTexture = m_context->createTexture(); | 
|   634     if (!offscreenColorTexture) |   634     if (!offscreenColorTexture) | 
|   635         return 0; |   635         return 0; | 
|   636  |   636  | 
|   637     m_context->bindTexture(parameters.target, offscreenColorTexture); |   637     m_gl->BindTexture(parameters.target, offscreenColorTexture); | 
|   638     m_context->texParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR
      ); |   638     m_context->texParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR
      ); | 
|   639     m_context->texParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR
      ); |   639     m_context->texParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR
      ); | 
|   640     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_E
      DGE); |   640     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_E
      DGE); | 
|   641     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_E
      DGE); |   641     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_E
      DGE); | 
|   642  |   642  | 
|   643     return offscreenColorTexture; |   643     return offscreenColorTexture; | 
|   644 } |   644 } | 
|   645  |   645  | 
|   646 void DrawingBuffer::createSecondaryBuffers() |   646 void DrawingBuffer::createSecondaryBuffers() | 
|   647 { |   647 { | 
|   648     // create a multisample FBO |   648     // create a multisample FBO | 
|   649     if (m_antiAliasingMode == MSAAExplicitResolve) { |   649     if (m_antiAliasingMode == MSAAExplicitResolve) { | 
|   650         m_multisampleFBO = m_context->createFramebuffer(); |   650         m_multisampleFBO = m_context->createFramebuffer(); | 
|   651         m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |   651         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 
|   652         m_multisampleColorBuffer = m_context->createRenderbuffer(); |   652         m_multisampleColorBuffer = m_context->createRenderbuffer(); | 
|   653     } |   653     } | 
|   654 } |   654 } | 
|   655  |   655  | 
|   656 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) |   656 bool DrawingBuffer::resizeFramebuffer(const IntSize& size) | 
|   657 { |   657 { | 
|   658     m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   658     m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   659     if (m_antiAliasingMode != MSAAExplicitResolve) |   659     if (m_antiAliasingMode != MSAAExplicitResolve) | 
|   660         resizeDepthStencil(size); |   660         resizeDepthStencil(size); | 
|   661     if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMP
      LETE) |   661     if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | 
|   662         return false; |   662         return false; | 
|   663  |   663  | 
|   664     return true; |   664     return true; | 
|   665 } |   665 } | 
|   666  |   666  | 
|   667 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) |   667 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) | 
|   668 { |   668 { | 
|   669     if (m_antiAliasingMode == MSAAExplicitResolve) { |   669     if (m_antiAliasingMode == MSAAExplicitResolve) { | 
|   670         m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |   670         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 
|   671  |   671  | 
|   672         m_context->bindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); |   672         m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer); | 
|   673         m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sam
      pleCount, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), siz
      e.height()); |   673         m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
      unt, m_colorBuffer.parameters.internalRenderbufferFormat, size.width(), size.hei
      ght()); | 
|   674  |   674  | 
|   675         if (m_context->getError() == GL_OUT_OF_MEMORY) |   675         if (m_context->getError() == GL_OUT_OF_MEMORY) | 
|   676             return false; |   676             return false; | 
|   677  |   677  | 
|   678         m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R
      ENDERBUFFER, m_multisampleColorBuffer); |   678         m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_R
      ENDERBUFFER, m_multisampleColorBuffer); | 
|   679         resizeDepthStencil(size); |   679         resizeDepthStencil(size); | 
|   680         if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_
      COMPLETE) |   680         if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPL
      ETE) | 
|   681             return false; |   681             return false; | 
|   682     } |   682     } | 
|   683  |   683  | 
|   684     return true; |   684     return true; | 
|   685 } |   685 } | 
|   686  |   686  | 
|   687 void DrawingBuffer::resizeDepthStencil(const IntSize& size) |   687 void DrawingBuffer::resizeDepthStencil(const IntSize& size) | 
|   688 { |   688 { | 
|   689     if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) |   689     if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) | 
|   690         return; |   690         return; | 
|   691  |   691  | 
|   692     if (!m_depthStencilBuffer) |   692     if (!m_depthStencilBuffer) | 
|   693         m_depthStencilBuffer = m_context->createRenderbuffer(); |   693         m_depthStencilBuffer = m_context->createRenderbuffer(); | 
|   694     m_context->bindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); |   694     m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); | 
|   695     if (m_antiAliasingMode == MSAAImplicitResolve) |   695     if (m_antiAliasingMode == MSAAImplicitResolve) | 
|   696         m_context->renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |   696         m_context->renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 
|   697     else if (m_antiAliasingMode == MSAAExplicitResolve) |   697     else if (m_antiAliasingMode == MSAAExplicitResolve) | 
|   698         m_context->renderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sam
      pleCount, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |   698         m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 
|   699     else |   699     else | 
|   700         m_context->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES,
       size.width(), size.height()); |   700         m_context->renderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES,
       size.width(), size.height()); | 
|   701     m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G
      L_RENDERBUFFER, m_depthStencilBuffer); |   701     m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G
      L_RENDERBUFFER, m_depthStencilBuffer); | 
|   702     m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); |   702     m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); | 
|   703 } |   703 } | 
|   704  |   704  | 
|   705  |   705  | 
|   706  |   706  | 
|   707 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |   707 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 
|   708 { |   708 { | 
|   709     // We will clear the multisample FBO, but we also need to clear the non-mult
      isampled buffer. |   709     // We will clear the multisample FBO, but we also need to clear the non-mult
      isampled buffer. | 
|   710     if (m_multisampleFBO) { |   710     if (m_multisampleFBO) { | 
|   711         m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   711         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   712         m_context->clear(GL_COLOR_BUFFER_BIT); |   712         m_gl->Clear(GL_COLOR_BUFFER_BIT); | 
|   713     } |   713     } | 
|   714  |   714  | 
|   715     m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
      BO : m_fbo); |   715     m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : 
      m_fbo); | 
|   716     m_context->clear(clearMask); |   716     m_gl->Clear(clearMask); | 
|   717 } |   717 } | 
|   718  |   718  | 
|   719 bool DrawingBuffer::hasImplicitStencilBuffer() const |   719 bool DrawingBuffer::hasImplicitStencilBuffer() const | 
|   720 { |   720 { | 
|   721     return m_depthStencilBuffer && m_requestedAttributes.depth && !m_requestedAt
      tributes.stencil; |   721     return m_depthStencilBuffer && m_requestedAttributes.depth && !m_requestedAt
      tributes.stencil; | 
|   722 } |   722 } | 
|   723  |   723  | 
|   724 void DrawingBuffer::setSize(const IntSize& size) |   724 void DrawingBuffer::setSize(const IntSize& size) | 
|   725 { |   725 { | 
|   726     if (m_size == size) |   726     if (m_size == size) | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   751         return false; |   751         return false; | 
|   752  |   752  | 
|   753     if (adjustedSize != m_size) { |   753     if (adjustedSize != m_size) { | 
|   754         do { |   754         do { | 
|   755             if (m_colorBuffer.textureId) { |   755             if (m_colorBuffer.textureId) { | 
|   756                 resizeTextureMemory(&m_colorBuffer, adjustedSize); |   756                 resizeTextureMemory(&m_colorBuffer, adjustedSize); | 
|   757             } else { |   757             } else { | 
|   758                 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize); |   758                 m_colorBuffer = createTextureAndAllocateMemory(adjustedSize); | 
|   759             } |   759             } | 
|   760  |   760  | 
|   761             m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   761             m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   762             attachColorBufferToCurrentFBO(); |   762             attachColorBufferToCurrentFBO(); | 
|   763  |   763  | 
|   764             // resize multisample FBO |   764             // resize multisample FBO | 
|   765             if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
      r(adjustedSize)) { |   765             if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
      r(adjustedSize)) { | 
|   766                 adjustedSize.scale(s_resourceAdjustedRatio); |   766                 adjustedSize.scale(s_resourceAdjustedRatio); | 
|   767                 continue; |   767                 continue; | 
|   768             } |   768             } | 
|   769             break; |   769             break; | 
|   770         } while (!adjustedSize.isEmpty()); |   770         } while (!adjustedSize.isEmpty()); | 
|   771  |   771  | 
|   772         setSize(adjustedSize); |   772         setSize(adjustedSize); | 
|   773  |   773  | 
|   774         if (adjustedSize.isEmpty()) |   774         if (adjustedSize.isEmpty()) | 
|   775             return false; |   775             return false; | 
|   776     } |   776     } | 
|   777  |   777  | 
|   778     m_context->disable(GL_SCISSOR_TEST); |   778     m_gl->Disable(GL_SCISSOR_TEST); | 
|   779     m_context->clearColor(0, 0, 0, 0); |   779     m_gl->ClearColor(0, 0, 0, 0); | 
|   780     m_context->colorMask(true, true, true, true); |   780     m_gl->ColorMask(true, true, true, true); | 
|   781  |   781  | 
|   782     GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |   782     GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 
|   783     if (m_actualAttributes.depth) { |   783     if (m_actualAttributes.depth) { | 
|   784         m_context->clearDepth(1.0f); |   784         m_gl->ClearDepthf(1.0f); | 
|   785         clearMask |= GL_DEPTH_BUFFER_BIT; |   785         clearMask |= GL_DEPTH_BUFFER_BIT; | 
|   786         m_context->depthMask(true); |   786         m_gl->DepthMask(true); | 
|   787     } |   787     } | 
|   788     if (m_actualAttributes.stencil) { |   788     if (m_actualAttributes.stencil) { | 
|   789         m_context->clearStencil(0); |   789         m_gl->ClearStencil(0); | 
|   790         clearMask |= GL_STENCIL_BUFFER_BIT; |   790         clearMask |= GL_STENCIL_BUFFER_BIT; | 
|   791         m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |   791         m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 
|   792     } |   792     } | 
|   793  |   793  | 
|   794     clearFramebuffers(clearMask); |   794     clearFramebuffers(clearMask); | 
|   795     return true; |   795     return true; | 
|   796 } |   796 } | 
|   797  |   797  | 
|   798 void DrawingBuffer::commit() |   798 void DrawingBuffer::commit() | 
|   799 { |   799 { | 
|   800     if (m_multisampleFBO && !m_contentsChangeCommitted) { |   800     if (m_multisampleFBO && !m_contentsChangeCommitted) { | 
|   801         m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |   801         m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 
|   802         m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |   802         m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 
|   803  |   803  | 
|   804         if (m_scissorEnabled) |   804         if (m_scissorEnabled) | 
|   805             m_context->disable(GL_SCISSOR_TEST); |   805             m_gl->Disable(GL_SCISSOR_TEST); | 
|   806  |   806  | 
|   807         int width = m_size.width(); |   807         int width = m_size.width(); | 
|   808         int height = m_size.height(); |   808         int height = m_size.height(); | 
|   809         // Use NEAREST, because there is no scale performed during the blit. |   809         // Use NEAREST, because there is no scale performed during the blit. | 
|   810         m_context->blitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, hei
      ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |   810         m_context->blitFramebufferCHROMIUM(0, 0, width, height, 0, 0, width, hei
      ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 
|   811  |   811  | 
|   812         if (m_scissorEnabled) |   812         if (m_scissorEnabled) | 
|   813             m_context->enable(GL_SCISSOR_TEST); |   813             m_gl->Enable(GL_SCISSOR_TEST); | 
|   814     } |   814     } | 
|   815  |   815  | 
|   816     m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |   816     m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 
|   817     if (m_antiAliasingMode == ScreenSpaceAntialiasing) { |   817     if (m_antiAliasingMode == ScreenSpaceAntialiasing) { | 
|   818         m_context->applyScreenSpaceAntialiasingCHROMIUM(); |   818         m_gl->ApplyScreenSpaceAntialiasingCHROMIUM(); | 
|   819     } |   819     } | 
|   820     m_contentsChangeCommitted = true; |   820     m_contentsChangeCommitted = true; | 
|   821 } |   821 } | 
|   822  |   822  | 
|   823 void DrawingBuffer::restoreFramebufferBindings() |   823 void DrawingBuffer::restoreFramebufferBindings() | 
|   824 { |   824 { | 
|   825     if (m_drawFramebufferBinding && m_readFramebufferBinding) { |   825     if (m_drawFramebufferBinding && m_readFramebufferBinding) { | 
|   826         if (m_drawFramebufferBinding == m_readFramebufferBinding) { |   826         if (m_drawFramebufferBinding == m_readFramebufferBinding) { | 
|   827             m_context->bindFramebuffer(GL_FRAMEBUFFER, m_readFramebufferBinding)
      ; |   827             m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_readFramebufferBinding); | 
|   828         } else { |   828         } else { | 
|   829             m_context->bindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBin
      ding); |   829             m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBinding)
      ; | 
|   830             m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBin
      ding); |   830             m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBinding)
      ; | 
|   831         } |   831         } | 
|   832         return; |   832         return; | 
|   833     } |   833     } | 
|   834     if (!m_drawFramebufferBinding && !m_readFramebufferBinding) { |   834     if (!m_drawFramebufferBinding && !m_readFramebufferBinding) { | 
|   835         bind(GL_FRAMEBUFFER); |   835         bind(GL_FRAMEBUFFER); | 
|   836         return; |   836         return; | 
|   837     } |   837     } | 
|   838     if (!m_drawFramebufferBinding) { |   838     if (!m_drawFramebufferBinding) { | 
|   839         bind(GL_DRAW_FRAMEBUFFER); |   839         bind(GL_DRAW_FRAMEBUFFER); | 
|   840         m_context->bindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBinding
      ); |   840         m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER, m_readFramebufferBinding); | 
|   841     } else { |   841     } else { | 
|   842         bind(GL_READ_FRAMEBUFFER); |   842         bind(GL_READ_FRAMEBUFFER); | 
|   843         m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBinding
      ); |   843         m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFramebufferBinding); | 
|   844     } |   844     } | 
|   845 } |   845 } | 
|   846  |   846  | 
|   847 bool DrawingBuffer::multisample() const |   847 bool DrawingBuffer::multisample() const | 
|   848 { |   848 { | 
|   849     return m_antiAliasingMode != None; |   849     return m_antiAliasingMode != None; | 
|   850 } |   850 } | 
|   851  |   851  | 
|   852 void DrawingBuffer::bind(GLenum target) |   852 void DrawingBuffer::bind(GLenum target) | 
|   853 { |   853 { | 
|   854     if (target != GL_READ_FRAMEBUFFER) |   854     if (target != GL_READ_FRAMEBUFFER) | 
|   855         m_context->bindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO :
       m_fbo); |   855         m_gl->BindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO : m_fb
      o); | 
|   856     else |   856     else | 
|   857         m_context->bindFramebuffer(target, m_fbo); |   857         m_gl->BindFramebuffer(target, m_fbo); | 
|   858 } |   858 } | 
|   859  |   859  | 
|   860 void DrawingBuffer::setPackAlignment(GLint param) |   860 void DrawingBuffer::setPackAlignment(GLint param) | 
|   861 { |   861 { | 
|   862     m_packAlignment = param; |   862     m_packAlignment = param; | 
|   863 } |   863 } | 
|   864  |   864  | 
|   865 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
      urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) |   865 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
      urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) | 
|   866 { |   866 { | 
|   867     ASSERT(!m_actualAttributes.premultipliedAlpha); |   867     ASSERT(!m_actualAttributes.premultipliedAlpha); | 
|   868     width = size().width(); |   868     width = size().width(); | 
|   869     height = size().height(); |   869     height = size().height(); | 
|   870  |   870  | 
|   871     Checked<int, RecordOverflow> dataSize = 4; |   871     Checked<int, RecordOverflow> dataSize = 4; | 
|   872     dataSize *= width; |   872     dataSize *= width; | 
|   873     dataSize *= height; |   873     dataSize *= height; | 
|   874     if (dataSize.hasOverflowed()) |   874     if (dataSize.hasOverflowed()) | 
|   875         return false; |   875         return false; | 
|   876  |   876  | 
|   877     WTF::ArrayBufferContents pixels(width * height, 4, WTF::ArrayBufferContents:
      :NotShared, WTF::ArrayBufferContents::DontInitialize); |   877     WTF::ArrayBufferContents pixels(width * height, 4, WTF::ArrayBufferContents:
      :NotShared, WTF::ArrayBufferContents::DontInitialize); | 
|   878  |   878  | 
|   879     GLint fbo = 0; |   879     GLint fbo = 0; | 
|   880     if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { |   880     if (sourceBuffer == FrontBuffer && m_frontColorBuffer.texInfo.textureId) { | 
|   881         fbo = m_context->createFramebuffer(); |   881         fbo = m_context->createFramebuffer(); | 
|   882         m_context->bindFramebuffer(GL_FRAMEBUFFER, fbo); |   882         m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 
|   883         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_front
      ColorBuffer.texInfo.parameters.target, m_frontColorBuffer.texInfo.textureId, 0); |   883         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_front
      ColorBuffer.texInfo.parameters.target, m_frontColorBuffer.texInfo.textureId, 0); | 
|   884     } else { |   884     } else { | 
|   885         m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer()); |   885         m_gl->BindFramebuffer(GL_FRAMEBUFFER, framebuffer()); | 
|   886     } |   886     } | 
|   887  |   887  | 
|   888     readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, heigh
      t, ReadbackRGBA, WebGLImageConversion::AlphaDoNothing); |   888     readBackFramebuffer(static_cast<unsigned char*>(pixels.data()), width, heigh
      t, ReadbackRGBA, WebGLImageConversion::AlphaDoNothing); | 
|   889     flipVertically(static_cast<uint8_t*>(pixels.data()), width, height); |   889     flipVertically(static_cast<uint8_t*>(pixels.data()), width, height); | 
|   890  |   890  | 
|   891     if (fbo) { |   891     if (fbo) { | 
|   892         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_front
      ColorBuffer.texInfo.parameters.target, 0, 0); |   892         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_front
      ColorBuffer.texInfo.parameters.target, 0, 0); | 
|   893         m_context->deleteFramebuffer(fbo); |   893         m_context->deleteFramebuffer(fbo); | 
|   894     } |   894     } | 
|   895  |   895  | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   947  |   947  | 
|   948 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
      ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
       type, GLint unpackAlignment) |   948 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
      ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
       type, GLint unpackAlignment) | 
|   949 { |   949 { | 
|   950     ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 
      || unpackAlignment == 8); |   950     ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 
      || unpackAlignment == 8); | 
|   951     m_context->texImage2D(target, level, internalformat, width, height, border, 
      format, type, 0); |   951     m_context->texImage2D(target, level, internalformat, width, height, border, 
      format, type, 0); | 
|   952 } |   952 } | 
|   953  |   953  | 
|   954 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |   954 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 
|   955 { |   955 { | 
|   956     if (info->imageId) { |   956     if (info->imageId) { | 
|   957         m_context->bindTexture(info->parameters.target, info->textureId); |   957         m_gl->BindTexture(info->parameters.target, info->textureId); | 
|   958         m_context->releaseTexImage2DCHROMIUM(info->parameters.target, info->imag
      eId); |   958         m_context->releaseTexImage2DCHROMIUM(info->parameters.target, info->imag
      eId); | 
|   959         m_context->destroyImageCHROMIUM(info->imageId); |   959         m_context->destroyImageCHROMIUM(info->imageId); | 
|   960         info->imageId = 0; |   960         info->imageId = 0; | 
|   961     } |   961     } | 
|   962 } |   962 } | 
|   963  |   963  | 
|   964 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
      ntSize& size) |   964 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
      ntSize& size) | 
|   965 { |   965 { | 
|   966     // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose |   966     // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose | 
|   967     // behavior mimics a texture with internal format GL_RGB. |   967     // behavior mimics a texture with internal format GL_RGB. | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1006     return info; |  1006     return info; | 
|  1007 } |  1007 } | 
|  1008  |  1008  | 
|  1009 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |  1009 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 
|  1010 { |  1010 { | 
|  1011     ASSERT(info->textureId); |  1011     ASSERT(info->textureId); | 
|  1012     if (info->imageId) { |  1012     if (info->imageId) { | 
|  1013         deleteChromiumImageForTexture(info); |  1013         deleteChromiumImageForTexture(info); | 
|  1014         info->imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width
      (), size.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |  1014         info->imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width
      (), size.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 
|  1015         if (info->imageId) { |  1015         if (info->imageId) { | 
|  1016             m_context->bindTexture(info->parameters.target, info->textureId); |  1016             m_gl->BindTexture(info->parameters.target, info->textureId); | 
|  1017             m_context->bindTexImage2DCHROMIUM(info->parameters.target, info->ima
      geId); |  1017             m_context->bindTexImage2DCHROMIUM(info->parameters.target, info->ima
      geId); | 
|  1018             return; |  1018             return; | 
|  1019         } |  1019         } | 
|  1020  |  1020  | 
|  1021         // If the desired texture target is different, there's no way to fall ba
      ck |  1021         // If the desired texture target is different, there's no way to fall ba
      ck | 
|  1022         // to a non CHROMIUM_image texture. |  1022         // to a non CHROMIUM_image texture. | 
|  1023         if (chromiumImageTextureParameters().target != defaultTextureParameters(
      ).target) |  1023         if (chromiumImageTextureParameters().target != defaultTextureParameters(
      ).target) | 
|  1024             return; |  1024             return; | 
|  1025     } |  1025     } | 
|  1026  |  1026  | 
|  1027     m_context->bindTexture(info->parameters.target, info->textureId); |  1027     m_gl->BindTexture(info->parameters.target, info->textureId); | 
|  1028     texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
      ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
      SIGNED_BYTE); |  1028     texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
      ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
      SIGNED_BYTE); | 
|  1029 } |  1029 } | 
|  1030  |  1030  | 
|  1031 void DrawingBuffer::attachColorBufferToCurrentFBO() |  1031 void DrawingBuffer::attachColorBufferToCurrentFBO() | 
|  1032 { |  1032 { | 
|  1033     WGC3Denum target = m_colorBuffer.parameters.target; |  1033     WGC3Denum target = m_colorBuffer.parameters.target; | 
|  1034  |  1034  | 
|  1035     m_context->bindTexture(target, m_colorBuffer.textureId); |  1035     m_gl->BindTexture(target, m_colorBuffer.textureId); | 
|  1036  |  1036  | 
|  1037     if (m_antiAliasingMode == MSAAImplicitResolve) |  1037     if (m_antiAliasingMode == MSAAImplicitResolve) | 
|  1038         m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
      TTACHMENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |  1038         m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
      TTACHMENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 
|  1039     else |  1039     else | 
|  1040         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
       m_colorBuffer.textureId, 0); |  1040         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
       m_colorBuffer.textureId, 0); | 
|  1041  |  1041  | 
|  1042     m_context->bindTexture(GL_TEXTURE_2D, m_texture2DBinding); |  1042     m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 
|  1043 } |  1043 } | 
|  1044  |  1044  | 
|  1045 } // namespace blink |  1045 } // namespace blink | 
| OLD | NEW |