| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  * Copyright (C) 2012 Google Inc. All rights reserved. |     2  * Copyright (C) 2012 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 |     5  * modification, are permitted provided that the following conditions | 
|     6  * are met: |     6  * are met: | 
|     7  * |     7  * | 
|     8  * 1.  Redistributions of source code must retain the above copyright |     8  * 1.  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  * 2.  Redistributions in binary form must reproduce the above copyright |    10  * 2.  Redistributions in binary form must reproduce the above copyright | 
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   210 bool Canvas2DLayerBridge::prepareIOSurfaceMailboxFromImage(SkImage* image, WebEx
      ternalTextureMailbox* outMailbox) |   210 bool Canvas2DLayerBridge::prepareIOSurfaceMailboxFromImage(SkImage* image, WebEx
      ternalTextureMailbox* outMailbox) | 
|   211 { |   211 { | 
|   212     // Need to flush skia's internal queue because texture is about to be access
      ed directly |   212     // Need to flush skia's internal queue because texture is about to be access
      ed directly | 
|   213     GrContext* grContext = m_contextProvider->grContext(); |   213     GrContext* grContext = m_contextProvider->grContext(); | 
|   214     grContext->flush(); |   214     grContext->flush(); | 
|   215  |   215  | 
|   216     ImageInfo imageInfo = createIOSurfaceBackedTexture(); |   216     ImageInfo imageInfo = createIOSurfaceBackedTexture(); | 
|   217     if (imageInfo.empty()) |   217     if (imageInfo.empty()) | 
|   218         return false; |   218         return false; | 
|   219  |   219  | 
 |   220     gpu::gles2::GLES2Interface* gl = contextGL(); | 
|   220     GLuint imageTexture = skia::GrBackendObjectToGrGLTextureInfo(image->getTextu
      reHandle(true))->fID; |   221     GLuint imageTexture = skia::GrBackendObjectToGrGLTextureInfo(image->getTextu
      reHandle(true))->fID; | 
|   221     context()->copySubTextureCHROMIUM(imageTexture, imageInfo.m_textureId, 0, 0,
       0, 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); |   222     context()->copySubTextureCHROMIUM(imageTexture, imageInfo.m_textureId, 0, 0,
       0, 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); | 
|   222  |   223  | 
|   223     MailboxInfo& info = m_mailboxes.first(); |   224     MailboxInfo& info = m_mailboxes.first(); | 
|   224     info.m_mailbox.textureTarget = GC3D_TEXTURE_RECTANGLE_ARB; |   225     info.m_mailbox.textureTarget = GC3D_TEXTURE_RECTANGLE_ARB; | 
|   225     context()->genMailboxCHROMIUM(info.m_mailbox.name); |   226     context()->genMailboxCHROMIUM(info.m_mailbox.name); | 
|   226     context()->produceTextureDirectCHROMIUM(imageInfo.m_textureId, info.m_mailbo
      x.textureTarget, info.m_mailbox.name); |   227     context()->produceTextureDirectCHROMIUM(imageInfo.m_textureId, info.m_mailbo
      x.textureTarget, info.m_mailbox.name); | 
|   227     info.m_mailbox.allowOverlay = true; |   228     info.m_mailbox.allowOverlay = true; | 
|   228  |   229  | 
|   229     const WGC3Duint64 fenceSync = context()->insertFenceSyncCHROMIUM(); |   230     const WGC3Duint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 
|   230     context()->flush(); |   231     context()->flush(); | 
|   231     info.m_mailbox.validSyncToken = context()->genSyncTokenCHROMIUM(fenceSync, i
      nfo.m_mailbox.syncToken); |   232     info.m_mailbox.validSyncToken = context()->genSyncTokenCHROMIUM(fenceSync, i
      nfo.m_mailbox.syncToken); | 
|   232  |   233  | 
|   233     info.m_imageInfo = imageInfo; |   234     info.m_imageInfo = imageInfo; | 
|   234     *outMailbox = info.m_mailbox; |   235     *outMailbox = info.m_mailbox; | 
|   235  |   236  | 
|   236     context()->bindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0); |   237     gl->BindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0); | 
|   237  |   238  | 
|   238     // Because we are changing the texture binding without going through skia, |   239     // Because we are changing the texture binding without going through skia, | 
|   239     // we must dirty the context. |   240     // we must dirty the context. | 
|   240     grContext->resetContext(kTextureBinding_GrGLBackendState); |   241     grContext->resetContext(kTextureBinding_GrGLBackendState); | 
|   241  |   242  | 
|   242     return true; |   243     return true; | 
|   243 } |   244 } | 
|   244  |   245  | 
|   245 Canvas2DLayerBridge::ImageInfo Canvas2DLayerBridge::createIOSurfaceBackedTexture
      () |   246 Canvas2DLayerBridge::ImageInfo Canvas2DLayerBridge::createIOSurfaceBackedTexture
      () | 
|   246 { |   247 { | 
|   247     if (!m_imageInfoCache.isEmpty()) { |   248     if (!m_imageInfoCache.isEmpty()) { | 
|   248         Canvas2DLayerBridge::ImageInfo info = m_imageInfoCache.last(); |   249         Canvas2DLayerBridge::ImageInfo info = m_imageInfoCache.last(); | 
|   249         m_imageInfoCache.removeLast(); |   250         m_imageInfoCache.removeLast(); | 
|   250         return info; |   251         return info; | 
|   251     } |   252     } | 
|   252  |   253  | 
|   253     WebGraphicsContext3D* webContext = context(); |   254     WebGraphicsContext3D* webContext = context(); | 
 |   255     gpu::gles2::GLES2Interface* gl = contextGL(); | 
|   254     GLuint imageId = webContext->createGpuMemoryBufferImageCHROMIUM(m_size.width
      (), m_size.height(), GL_BGRA_EXT, GC3D_SCANOUT_CHROMIUM); |   256     GLuint imageId = webContext->createGpuMemoryBufferImageCHROMIUM(m_size.width
      (), m_size.height(), GL_BGRA_EXT, GC3D_SCANOUT_CHROMIUM); | 
|   255     if (!imageId) |   257     if (!imageId) | 
|   256         return Canvas2DLayerBridge::ImageInfo(); |   258         return Canvas2DLayerBridge::ImageInfo(); | 
|   257  |   259  | 
|   258     GLuint textureId= webContext->createTexture(); |   260     GLuint textureId= webContext->createTexture(); | 
|   259     if (!textureId) { |   261     if (!textureId) { | 
|   260         webContext->destroyImageCHROMIUM(imageId); |   262         webContext->destroyImageCHROMIUM(imageId); | 
|   261         return Canvas2DLayerBridge::ImageInfo(); |   263         return Canvas2DLayerBridge::ImageInfo(); | 
|   262     } |   264     } | 
|   263  |   265  | 
|   264     GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; |   266     GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; | 
|   265     webContext->bindTexture(target, textureId); |   267     gl->BindTexture(target, textureId); | 
|   266     webContext->texParameteri(target, GL_TEXTURE_MAG_FILTER, getGLFilter()); |   268     webContext->texParameteri(target, GL_TEXTURE_MAG_FILTER, getGLFilter()); | 
|   267     webContext->texParameteri(target, GL_TEXTURE_MIN_FILTER, getGLFilter()); |   269     webContext->texParameteri(target, GL_TEXTURE_MIN_FILTER, getGLFilter()); | 
|   268     webContext->texParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |   270     webContext->texParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
|   269     webContext->texParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |   271     webContext->texParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
|   270     webContext->bindTexImage2DCHROMIUM(target, imageId); |   272     webContext->bindTexImage2DCHROMIUM(target, imageId); | 
|   271  |   273  | 
|   272     return Canvas2DLayerBridge::ImageInfo(imageId, textureId); |   274     return Canvas2DLayerBridge::ImageInfo(imageId, textureId); | 
|   273 } |   275 } | 
|   274  |   276  | 
|   275 void Canvas2DLayerBridge::deleteCHROMIUMImage(ImageInfo info) |   277 void Canvas2DLayerBridge::deleteCHROMIUMImage(ImageInfo info) | 
|   276 { |   278 { | 
|   277     if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR
      OR) |   279     WebGraphicsContext3D* webContext = context(); | 
 |   280     gpu::gles2::GLES2Interface* gl = contextGL(); | 
 |   281     if (gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 
|   278         return; |   282         return; | 
|   279  |   283  | 
|   280     GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; |   284     GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; | 
|   281     WebGraphicsContext3D* webContext = context(); |   285     gl->BindTexture(target, info.m_textureId); | 
|   282     webContext->bindTexture(target, info.m_textureId); |  | 
|   283     webContext->releaseTexImage2DCHROMIUM(target, info.m_imageId); |   286     webContext->releaseTexImage2DCHROMIUM(target, info.m_imageId); | 
|   284     webContext->destroyImageCHROMIUM(info.m_imageId); |   287     webContext->destroyImageCHROMIUM(info.m_imageId); | 
|   285     webContext->deleteTexture(info.m_textureId); |   288     webContext->deleteTexture(info.m_textureId); | 
|   286     webContext->bindTexture(target, 0); |   289     gl->BindTexture(target, 0); | 
|   287  |   290  | 
|   288     resetSkiaTextureBinding(); |   291     resetSkiaTextureBinding(); | 
|   289 } |   292 } | 
|   290  |   293  | 
|   291 void Canvas2DLayerBridge::clearCHROMIUMImageCache() |   294 void Canvas2DLayerBridge::clearCHROMIUMImageCache() | 
|   292 { |   295 { | 
|   293     for (const auto& it : m_imageInfoCache) { |   296     for (const auto& it : m_imageInfoCache) { | 
|   294         deleteCHROMIUMImage(it); |   297         deleteCHROMIUMImage(it); | 
|   295     } |   298     } | 
|   296     m_imageInfoCache.clear(); |   299     m_imageInfoCache.clear(); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   334     // Need to flush skia's internal queue because texture is about to be access
      ed directly |   337     // Need to flush skia's internal queue because texture is about to be access
      ed directly | 
|   335     grContext->flush(); |   338     grContext->flush(); | 
|   336  |   339  | 
|   337     // Because of texture sharing with the compositor, we must invalidate |   340     // Because of texture sharing with the compositor, we must invalidate | 
|   338     // the state cached in skia so that the deferred copy on write |   341     // the state cached in skia so that the deferred copy on write | 
|   339     // in SkSurface_Gpu does not make any false assumptions. |   342     // in SkSurface_Gpu does not make any false assumptions. | 
|   340     mailboxInfo.m_image->getTexture()->textureParamsModified(); |   343     mailboxInfo.m_image->getTexture()->textureParamsModified(); | 
|   341     mailboxInfo.m_mailbox.textureTarget = GL_TEXTURE_2D; |   344     mailboxInfo.m_mailbox.textureTarget = GL_TEXTURE_2D; | 
|   342  |   345  | 
|   343     WebGraphicsContext3D* webContext = context(); |   346     WebGraphicsContext3D* webContext = context(); | 
 |   347     gpu::gles2::GLES2Interface* gl = contextGL(); | 
|   344     GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(mailboxInfo.m_imag
      e->getTextureHandle(true))->fID; |   348     GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(mailboxInfo.m_imag
      e->getTextureHandle(true))->fID; | 
|   345     webContext->bindTexture(GL_TEXTURE_2D, textureID); |   349     gl->BindTexture(GL_TEXTURE_2D, textureID); | 
|   346     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getGLFilter(
      )); |   350     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getGLFilter(
      )); | 
|   347     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getGLFilter(
      )); |   351     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getGLFilter(
      )); | 
|   348     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
      ); |   352     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
      ); | 
|   349     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
      ); |   353     webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
      ); | 
|   350  |   354  | 
|   351     // Re-use the texture's existing mailbox, if there is one. |   355     // Re-use the texture's existing mailbox, if there is one. | 
|   352     if (mailboxInfo.m_image->getTexture()->getCustomData()) { |   356     if (mailboxInfo.m_image->getTexture()->getCustomData()) { | 
|   353         ASSERT(mailboxInfo.m_image->getTexture()->getCustomData()->size() == siz
      eof(mailboxInfo.m_mailbox.name)); |   357         ASSERT(mailboxInfo.m_image->getTexture()->getCustomData()->size() == siz
      eof(mailboxInfo.m_mailbox.name)); | 
|   354         memcpy(&mailboxInfo.m_mailbox.name[0], mailboxInfo.m_image->getTexture()
      ->getCustomData()->data(), sizeof(mailboxInfo.m_mailbox.name)); |   358         memcpy(&mailboxInfo.m_mailbox.name[0], mailboxInfo.m_image->getTexture()
      ->getCustomData()->data(), sizeof(mailboxInfo.m_mailbox.name)); | 
|   355     } else { |   359     } else { | 
|   356         context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name); |   360         context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name); | 
|   357         RefPtr<SkData> mailboxNameData = adoptRef(SkData::NewWithCopy(&mailboxIn
      fo.m_mailbox.name[0], sizeof(mailboxInfo.m_mailbox.name))); |   361         RefPtr<SkData> mailboxNameData = adoptRef(SkData::NewWithCopy(&mailboxIn
      fo.m_mailbox.name[0], sizeof(mailboxInfo.m_mailbox.name))); | 
|   358         mailboxInfo.m_image->getTexture()->setCustomData(mailboxNameData.get()); |   362         mailboxInfo.m_image->getTexture()->setCustomData(mailboxNameData.get()); | 
|   359         webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo.m_mailbox.
      name); |   363         webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo.m_mailbox.
      name); | 
|   360     } |   364     } | 
|   361  |   365  | 
|   362     if (isHidden()) { |   366     if (isHidden()) { | 
|   363         // With hidden canvases, we release the SkImage immediately because |   367         // With hidden canvases, we release the SkImage immediately because | 
|   364         // there is no need for animations to be double buffered. |   368         // there is no need for animations to be double buffered. | 
|   365         mailboxInfo.m_image.clear(); |   369         mailboxInfo.m_image.clear(); | 
|   366     } else { |   370     } else { | 
|   367         // FIXME: We'd rather insert a syncpoint than perform a flush here, |   371         // FIXME: We'd rather insert a syncpoint than perform a flush here, | 
|   368         // but currently the canvas will flicker if we don't flush here. |   372         // but currently the canvas will flicker if we don't flush here. | 
|   369         const WGC3Duint64 fenceSync = webContext->insertFenceSyncCHROMIUM(); |   373         const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 
|   370         webContext->flush(); |   374         webContext->flush(); | 
|   371         mailboxInfo.m_mailbox.validSyncToken = webContext->genSyncTokenCHROMIUM(
      fenceSync, mailboxInfo.m_mailbox.syncToken); |   375         mailboxInfo.m_mailbox.validSyncToken = webContext->genSyncTokenCHROMIUM(
      fenceSync, mailboxInfo.m_mailbox.syncToken); | 
|   372     } |   376     } | 
|   373     webContext->bindTexture(GL_TEXTURE_2D, 0); |   377     gl->BindTexture(GL_TEXTURE_2D, 0); | 
|   374     // Because we are changing the texture binding without going through skia, |   378     // Because we are changing the texture binding without going through skia, | 
|   375     // we must dirty the context. |   379     // we must dirty the context. | 
|   376     grContext->resetContext(kTextureBinding_GrGLBackendState); |   380     grContext->resetContext(kTextureBinding_GrGLBackendState); | 
|   377  |   381  | 
|   378     *outMailbox = mailboxInfo.m_mailbox; |   382     *outMailbox = mailboxInfo.m_mailbox; | 
|   379     return true; |   383     return true; | 
|   380 } |   384 } | 
|   381  |   385  | 
|   382 void Canvas2DLayerBridge::resetSkiaTextureBinding() |   386 void Canvas2DLayerBridge::resetSkiaTextureBinding() | 
|   383 { |   387 { | 
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   711  |   715  | 
|   712 WebGraphicsContext3D* Canvas2DLayerBridge::context() |   716 WebGraphicsContext3D* Canvas2DLayerBridge::context() | 
|   713 { |   717 { | 
|   714     // Check on m_layer is necessary because context() may be called during |   718     // Check on m_layer is necessary because context() may be called during | 
|   715     // the destruction of m_layer |   719     // the destruction of m_layer | 
|   716     if (m_layer && !m_destructionInProgress) |   720     if (m_layer && !m_destructionInProgress) | 
|   717         checkSurfaceValid(); // To ensure rate limiter is disabled if context is
       lost. |   721         checkSurfaceValid(); // To ensure rate limiter is disabled if context is
       lost. | 
|   718     return m_contextProvider ? m_contextProvider->context3d() : 0; |   722     return m_contextProvider ? m_contextProvider->context3d() : 0; | 
|   719 } |   723 } | 
|   720  |   724  | 
 |   725 gpu::gles2::GLES2Interface* Canvas2DLayerBridge::contextGL() | 
 |   726 { | 
 |   727     // Check on m_layer is necessary because contextGL() may be called during | 
 |   728     // the destruction of m_layer | 
 |   729     if (m_layer && !m_destructionInProgress) { | 
 |   730         // Ensure rate limiter is disabled if context is lost. | 
 |   731         checkSurfaceValid(); | 
 |   732     } | 
 |   733     return m_contextProvider ? m_contextProvider->contextGL() : nullptr; | 
 |   734 } | 
 |   735  | 
|   721 bool Canvas2DLayerBridge::checkSurfaceValid() |   736 bool Canvas2DLayerBridge::checkSurfaceValid() | 
|   722 { |   737 { | 
|   723     ASSERT(!m_destructionInProgress); |   738     ASSERT(!m_destructionInProgress); | 
|   724     if (m_destructionInProgress) |   739     if (m_destructionInProgress) | 
|   725         return false; |   740         return false; | 
|   726     if (isHibernating()) |   741     if (isHibernating()) | 
|   727         return true; |   742         return true; | 
|   728     if (!m_layer) |   743     if (!m_layer) | 
|   729         return true; |   744         return true; | 
|   730     if (!m_surface) |   745     if (!m_surface) | 
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   837         ASSERT(releasedMailboxInfo != firstMailbox); |   852         ASSERT(releasedMailboxInfo != firstMailbox); | 
|   838     } |   853     } | 
|   839  |   854  | 
|   840     if (!contextLost) { |   855     if (!contextLost) { | 
|   841         // Invalidate texture state in case the compositor altered it since the 
      copy-on-write. |   856         // Invalidate texture state in case the compositor altered it since the 
      copy-on-write. | 
|   842         if (releasedMailboxInfo->m_image) { |   857         if (releasedMailboxInfo->m_image) { | 
|   843 #if USE_IOSURFACE_FOR_2D_CANVAS |   858 #if USE_IOSURFACE_FOR_2D_CANVAS | 
|   844             ASSERT(releasedMailboxInfo->m_imageInfo.empty()); |   859             ASSERT(releasedMailboxInfo->m_imageInfo.empty()); | 
|   845 #endif // USE_IOSURFACE_FOR_2D_CANVAS |   860 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 
|   846             if (mailbox.validSyncToken) { |   861             if (mailbox.validSyncToken) { | 
|   847                 context()->waitSyncTokenCHROMIUM(mailbox.syncToken); |   862                 contextGL()->WaitSyncTokenCHROMIUM(mailbox.syncToken); | 
|   848             } |   863             } | 
|   849             GrTexture* texture = releasedMailboxInfo->m_image->getTexture(); |   864             GrTexture* texture = releasedMailboxInfo->m_image->getTexture(); | 
|   850             if (texture) { |   865             if (texture) { | 
|   851                 if (lostResource) { |   866                 if (lostResource) { | 
|   852                     texture->abandon(); |   867                     texture->abandon(); | 
|   853                 } else { |   868                 } else { | 
|   854                     texture->textureParamsModified(); |   869                     texture->textureParamsModified(); | 
|   855                 } |   870                 } | 
|   856             } |   871             } | 
|   857         } |   872         } | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   991 #endif // USE_IOSURFACE_FOR_2D_CANVAS |  1006 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 
|   992 } |  1007 } | 
|   993  |  1008  | 
|   994 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |  1009 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 
|   995 { |  1010 { | 
|   996     DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
      ernationEvents", HibernationEventCount)); |  1011     DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
      ernationEvents", HibernationEventCount)); | 
|   997     hibernationHistogram.count(event); |  1012     hibernationHistogram.count(event); | 
|   998 } |  1013 } | 
|   999  |  1014  | 
|  1000 } // namespace blink |  1015 } // namespace blink | 
| OLD | NEW |