| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 { | 194 { |
| 195 // Need to flush skia's internal queue because texture is about to be access
ed directly | 195 // Need to flush skia's internal queue because texture is about to be access
ed directly |
| 196 GrContext* grContext = m_contextProvider->grContext(); | 196 GrContext* grContext = m_contextProvider->grContext(); |
| 197 grContext->flush(); | 197 grContext->flush(); |
| 198 | 198 |
| 199 ImageInfo imageInfo = createIOSurfaceBackedTexture(); | 199 ImageInfo imageInfo = createIOSurfaceBackedTexture(); |
| 200 if (imageInfo.empty()) | 200 if (imageInfo.empty()) |
| 201 return false; | 201 return false; |
| 202 | 202 |
| 203 gpu::gles2::GLES2Interface* gl = contextGL(); | 203 gpu::gles2::GLES2Interface* gl = contextGL(); |
| 204 if (!gl) |
| 205 return false; |
| 206 |
| 204 GLuint imageTexture = skia::GrBackendObjectToGrGLTextureInfo(image->getTextu
reHandle(true))->fID; | 207 GLuint imageTexture = skia::GrBackendObjectToGrGLTextureInfo(image->getTextu
reHandle(true))->fID; |
| 205 gl->CopySubTextureCHROMIUM(imageTexture, imageInfo.m_textureId, 0, 0, 0, 0,
m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); | 208 gl->CopySubTextureCHROMIUM(imageTexture, imageInfo.m_textureId, 0, 0, 0, 0,
m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_FALSE); |
| 206 | 209 |
| 207 MailboxInfo& info = m_mailboxes.first(); | 210 MailboxInfo& info = m_mailboxes.first(); |
| 208 info.m_mailbox.textureTarget = GC3D_TEXTURE_RECTANGLE_ARB; | 211 info.m_mailbox.textureTarget = GC3D_TEXTURE_RECTANGLE_ARB; |
| 209 gl->GenMailboxCHROMIUM(info.m_mailbox.name); | 212 gl->GenMailboxCHROMIUM(info.m_mailbox.name); |
| 210 gl->ProduceTextureDirectCHROMIUM(imageInfo.m_textureId, info.m_mailbox.textu
reTarget, info.m_mailbox.name); | 213 gl->ProduceTextureDirectCHROMIUM(imageInfo.m_textureId, info.m_mailbox.textu
reTarget, info.m_mailbox.name); |
| 211 info.m_mailbox.allowOverlay = true; | 214 info.m_mailbox.allowOverlay = true; |
| 212 | 215 |
| 213 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); | 216 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 229 | 232 |
| 230 Canvas2DLayerBridge::ImageInfo Canvas2DLayerBridge::createIOSurfaceBackedTexture
() | 233 Canvas2DLayerBridge::ImageInfo Canvas2DLayerBridge::createIOSurfaceBackedTexture
() |
| 231 { | 234 { |
| 232 if (!m_imageInfoCache.isEmpty()) { | 235 if (!m_imageInfoCache.isEmpty()) { |
| 233 Canvas2DLayerBridge::ImageInfo info = m_imageInfoCache.last(); | 236 Canvas2DLayerBridge::ImageInfo info = m_imageInfoCache.last(); |
| 234 m_imageInfoCache.removeLast(); | 237 m_imageInfoCache.removeLast(); |
| 235 return info; | 238 return info; |
| 236 } | 239 } |
| 237 | 240 |
| 238 gpu::gles2::GLES2Interface* gl = contextGL(); | 241 gpu::gles2::GLES2Interface* gl = contextGL(); |
| 242 if (!gl) |
| 243 return Canvas2DLayerBridge::ImageInfo(); |
| 244 |
| 239 GLuint imageId = gl->CreateGpuMemoryBufferImageCHROMIUM(m_size.width(), m_si
ze.height(), GL_RGBA, GC3D_SCANOUT_CHROMIUM); | 245 GLuint imageId = gl->CreateGpuMemoryBufferImageCHROMIUM(m_size.width(), m_si
ze.height(), GL_RGBA, GC3D_SCANOUT_CHROMIUM); |
| 240 if (!imageId) | 246 if (!imageId) |
| 241 return Canvas2DLayerBridge::ImageInfo(); | 247 return Canvas2DLayerBridge::ImageInfo(); |
| 242 | 248 |
| 243 GLuint textureId; | 249 GLuint textureId; |
| 244 gl->GenTextures(1, &textureId); | 250 gl->GenTextures(1, &textureId); |
| 245 GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; | 251 GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; |
| 246 gl->BindTexture(target, textureId); | 252 gl->BindTexture(target, textureId); |
| 247 gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, getGLFilter()); | 253 gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, getGLFilter()); |
| 248 gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, getGLFilter()); | 254 gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, getGLFilter()); |
| 249 gl->TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 255 gl->TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 250 gl->TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 256 gl->TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 251 gl->BindTexImage2DCHROMIUM(target, imageId); | 257 gl->BindTexImage2DCHROMIUM(target, imageId); |
| 252 | 258 |
| 253 return Canvas2DLayerBridge::ImageInfo(imageId, textureId); | 259 return Canvas2DLayerBridge::ImageInfo(imageId, textureId); |
| 254 } | 260 } |
| 255 | 261 |
| 256 void Canvas2DLayerBridge::deleteCHROMIUMImage(ImageInfo info) | 262 void Canvas2DLayerBridge::deleteCHROMIUMImage(ImageInfo info) |
| 257 { | 263 { |
| 258 gpu::gles2::GLES2Interface* gl = contextGL(); | 264 gpu::gles2::GLES2Interface* gl = contextGL(); |
| 259 if (gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 265 if (!gl) |
| 260 return; | 266 return; |
| 261 | 267 |
| 262 GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; | 268 GLenum target = GC3D_TEXTURE_RECTANGLE_ARB; |
| 263 gl->BindTexture(target, info.m_textureId); | 269 gl->BindTexture(target, info.m_textureId); |
| 264 gl->ReleaseTexImage2DCHROMIUM(target, info.m_imageId); | 270 gl->ReleaseTexImage2DCHROMIUM(target, info.m_imageId); |
| 265 gl->DestroyImageCHROMIUM(info.m_imageId); | 271 gl->DestroyImageCHROMIUM(info.m_imageId); |
| 266 gl->DeleteTextures(1, &info.m_textureId); | 272 gl->DeleteTextures(1, &info.m_textureId); |
| 267 gl->BindTexture(target, 0); | 273 gl->BindTexture(target, 0); |
| 268 | 274 |
| 269 resetSkiaTextureBinding(); | 275 resetSkiaTextureBinding(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Need to flush skia's internal queue because texture is about to be access
ed directly | 321 // Need to flush skia's internal queue because texture is about to be access
ed directly |
| 316 grContext->flush(); | 322 grContext->flush(); |
| 317 | 323 |
| 318 // Because of texture sharing with the compositor, we must invalidate | 324 // Because of texture sharing with the compositor, we must invalidate |
| 319 // the state cached in skia so that the deferred copy on write | 325 // the state cached in skia so that the deferred copy on write |
| 320 // in SkSurface_Gpu does not make any false assumptions. | 326 // in SkSurface_Gpu does not make any false assumptions. |
| 321 mailboxInfo.m_image->getTexture()->textureParamsModified(); | 327 mailboxInfo.m_image->getTexture()->textureParamsModified(); |
| 322 mailboxInfo.m_mailbox.textureTarget = GL_TEXTURE_2D; | 328 mailboxInfo.m_mailbox.textureTarget = GL_TEXTURE_2D; |
| 323 | 329 |
| 324 gpu::gles2::GLES2Interface* gl = contextGL(); | 330 gpu::gles2::GLES2Interface* gl = contextGL(); |
| 331 if (!gl) |
| 332 return false; |
| 333 |
| 325 GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(mailboxInfo.m_imag
e->getTextureHandle(true))->fID; | 334 GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(mailboxInfo.m_imag
e->getTextureHandle(true))->fID; |
| 326 gl->BindTexture(GL_TEXTURE_2D, textureID); | 335 gl->BindTexture(GL_TEXTURE_2D, textureID); |
| 327 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getGLFilter()); | 336 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, getGLFilter()); |
| 328 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getGLFilter()); | 337 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, getGLFilter()); |
| 329 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 338 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 330 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 339 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 331 | 340 |
| 332 // Re-use the texture's existing mailbox, if there is one. | 341 // Re-use the texture's existing mailbox, if there is one. |
| 333 if (mailboxInfo.m_image->getTexture()->getCustomData()) { | 342 if (mailboxInfo.m_image->getTexture()->getCustomData()) { |
| 334 ASSERT(mailboxInfo.m_image->getTexture()->getCustomData()->size() == siz
eof(mailboxInfo.m_mailbox.name)); | 343 ASSERT(mailboxInfo.m_image->getTexture()->getCustomData()->size() == siz
eof(mailboxInfo.m_mailbox.name)); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 if (isAccelerated() && gl) | 696 if (isAccelerated() && gl) |
| 688 gl->Flush(); | 697 gl->Flush(); |
| 689 } | 698 } |
| 690 | 699 |
| 691 | 700 |
| 692 gpu::gles2::GLES2Interface* Canvas2DLayerBridge::contextGL() | 701 gpu::gles2::GLES2Interface* Canvas2DLayerBridge::contextGL() |
| 693 { | 702 { |
| 694 // Check on m_layer is necessary because contextGL() may be called during | 703 // Check on m_layer is necessary because contextGL() may be called during |
| 695 // the destruction of m_layer | 704 // the destruction of m_layer |
| 696 if (m_layer && !m_destructionInProgress) { | 705 if (m_layer && !m_destructionInProgress) { |
| 697 // Ensure rate limiter is disabled if context is lost. | 706 // Call checkSurfaceValid to ensure rate limiter is disabled if context
is lost. |
| 698 checkSurfaceValid(); | 707 if (!checkSurfaceValid()) |
| 708 return nullptr; |
| 699 } | 709 } |
| 700 return m_contextProvider ? m_contextProvider->contextGL() : nullptr; | 710 return m_contextProvider ? m_contextProvider->contextGL() : nullptr; |
| 701 } | 711 } |
| 702 | 712 |
| 703 bool Canvas2DLayerBridge::checkSurfaceValid() | 713 bool Canvas2DLayerBridge::checkSurfaceValid() |
| 704 { | 714 { |
| 705 ASSERT(!m_destructionInProgress); | 715 ASSERT(!m_destructionInProgress); |
| 706 if (m_destructionInProgress) | 716 if (m_destructionInProgress) |
| 707 return false; | 717 return false; |
| 708 if (isHibernating()) | 718 if (isHibernating()) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 983 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
| 974 } | 984 } |
| 975 | 985 |
| 976 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 986 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
| 977 { | 987 { |
| 978 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); | 988 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); |
| 979 hibernationHistogram.count(event); | 989 hibernationHistogram.count(event); |
| 980 } | 990 } |
| 981 | 991 |
| 982 } // namespace blink | 992 } // namespace blink |
| OLD | NEW |