| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 m_webGLVersion(webGLVersion), | 144 m_webGLVersion(webGLVersion), |
| 145 m_contextProvider(std::move(contextProvider)), | 145 m_contextProvider(std::move(contextProvider)), |
| 146 m_gl(m_contextProvider->contextGL()), | 146 m_gl(m_contextProvider->contextGL()), |
| 147 m_extensionsUtil(std::move(extensionsUtil)), | 147 m_extensionsUtil(std::move(extensionsUtil)), |
| 148 m_discardFramebufferSupported(discardFramebufferSupported), | 148 m_discardFramebufferSupported(discardFramebufferSupported), |
| 149 m_wantAlphaChannel(wantAlphaChannel), | 149 m_wantAlphaChannel(wantAlphaChannel), |
| 150 m_premultipliedAlpha(premultipliedAlpha), | 150 m_premultipliedAlpha(premultipliedAlpha), |
| 151 m_softwareRendering(m_contextProvider->isSoftwareRendering()), | 151 m_softwareRendering(m_contextProvider->isSoftwareRendering()), |
| 152 m_wantDepth(wantDepth), | 152 m_wantDepth(wantDepth), |
| 153 m_wantStencil(wantStencil), | 153 m_wantStencil(wantStencil), |
| 154 m_chromiumImageUsage(chromiumImageUsage) { | 154 m_chromiumImageUsage(chromiumImageUsage), |
| 155 m_weakPtrFactory(this) { |
| 155 // Used by browser tests to detect the use of a DrawingBuffer. | 156 // Used by browser tests to detect the use of a DrawingBuffer. |
| 156 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", | 157 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", |
| 157 TRACE_EVENT_SCOPE_GLOBAL); | 158 TRACE_EVENT_SCOPE_GLOBAL); |
| 158 } | 159 } |
| 159 | 160 |
| 160 DrawingBuffer::~DrawingBuffer() { | 161 DrawingBuffer::~DrawingBuffer() { |
| 161 DCHECK(m_destructionInProgress); | 162 DCHECK(m_destructionInProgress); |
| 162 m_layer.reset(); | 163 m_layer.reset(); |
| 163 m_contextProvider.reset(); | 164 m_contextProvider.reset(); |
| 164 } | 165 } |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // back to it. | 475 // back to it. |
| 475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use | 476 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use |
| 476 // the actual texture id and avoid needing to produce/consume a mailbox. | 477 // the actual texture id and avoid needing to produce/consume a mailbox. |
| 477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( | 478 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( |
| 478 GL_TEXTURE_2D, textureMailbox.name()); | 479 GL_TEXTURE_2D, textureMailbox.name()); |
| 479 // Return the mailbox but report that the resource is lost to prevent trying | 480 // Return the mailbox but report that the resource is lost to prevent trying |
| 480 // to use the backing for future frames. We keep it alive with our own | 481 // to use the backing for future frames. We keep it alive with our own |
| 481 // reference to the backing via our |textureId|. | 482 // reference to the backing via our |textureId|. |
| 482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); | 483 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); |
| 483 | 484 |
| 484 // Store that texture id as the backing for an SkImage. | |
| 485 GrGLTextureInfo textureInfo; | |
| 486 textureInfo.fTarget = GL_TEXTURE_2D; | |
| 487 textureInfo.fID = textureId; | |
| 488 GrBackendTextureDesc backendTexture; | |
| 489 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 490 backendTexture.fWidth = m_size.width(); | |
| 491 backendTexture.fHeight = m_size.height(); | |
| 492 backendTexture.fConfig = kSkia8888_GrPixelConfig; | |
| 493 backendTexture.fTextureHandle = | |
| 494 skia::GrGLTextureInfoToGrBackendObject(textureInfo); | |
| 495 sk_sp<SkImage> skImage = | |
| 496 SkImage::MakeFromAdoptedTexture(grContext, backendTexture); | |
| 497 | |
| 498 // We reuse the same mailbox name from above since our texture id was consumed | 485 // We reuse the same mailbox name from above since our texture id was consumed |
| 499 // from it. | 486 // from it. |
| 500 const auto& skImageMailbox = textureMailbox.mailbox(); | 487 const auto& skImageMailbox = textureMailbox.mailbox(); |
| 501 // Use the sync token generated after producing the mailbox. Waiting for this | 488 // Use the sync token generated after producing the mailbox. Waiting for this |
| 502 // before trying to use the mailbox with some other context will ensure it is | 489 // before trying to use the mailbox with some other context will ensure it is |
| 503 // valid. We wouldn't need to wait for the consume done in this function | 490 // valid. We wouldn't need to wait for the consume done in this function |
| 504 // because the texture id it generated would only be valid for the | 491 // because the texture id it generated would only be valid for the |
| 505 // DrawingBuffer's context anyways. | 492 // DrawingBuffer's context anyways. |
| 506 const auto& skImageSyncToken = textureMailbox.sync_token(); | 493 const auto& skImageSyncToken = textureMailbox.sync_token(); |
| 507 | 494 |
| 508 // TODO(xidachen): Create a small pool of recycled textures from | 495 // TODO(xidachen): Create a small pool of recycled textures from |
| 509 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them | 496 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them |
| 510 // in DrawingBuffer. | 497 // in DrawingBuffer. |
| 511 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( | 498 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( |
| 512 std::move(skImage), skImageMailbox, skImageSyncToken); | 499 skImageMailbox, skImageSyncToken, textureId, |
| 500 m_weakPtrFactory.createWeakPtr(), m_size); |
| 513 } | 501 } |
| 514 | 502 |
| 515 DrawingBuffer::ColorBufferParameters | 503 DrawingBuffer::ColorBufferParameters |
| 516 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { | 504 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { |
| 517 #if OS(MACOSX) | 505 #if OS(MACOSX) |
| 518 // A CHROMIUM_image backed texture requires a specialized set of parameters | 506 // A CHROMIUM_image backed texture requires a specialized set of parameters |
| 519 // on OSX. | 507 // on OSX. |
| 520 ColorBufferParameters parameters; | 508 ColorBufferParameters parameters; |
| 521 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 509 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
| 522 | 510 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 if (m_pixelUnpackBufferBindingDirty) | 1253 if (m_pixelUnpackBufferBindingDirty) |
| 1266 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); | 1254 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); |
| 1267 } | 1255 } |
| 1268 | 1256 |
| 1269 bool DrawingBuffer::shouldUseChromiumImage() { | 1257 bool DrawingBuffer::shouldUseChromiumImage() { |
| 1270 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 1258 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && |
| 1271 m_chromiumImageUsage == AllowChromiumImage; | 1259 m_chromiumImageUsage == AllowChromiumImage; |
| 1272 } | 1260 } |
| 1273 | 1261 |
| 1274 } // namespace blink | 1262 } // namespace blink |
| OLD | NEW |