Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp

Issue 2643343002: DrawingBuffer: Use gfx::GpuMemoryBuffer directly and set color space (Closed)
Patch Set: Fix buffer format Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/graphics/gpu/DrawingBuffer.h" 31 #include "platform/graphics/gpu/DrawingBuffer.h"
32 32
33 #include "cc/resources/shared_bitmap.h" 33 #include "cc/resources/shared_bitmap.h"
34 #include "gpu/GLES2/gl2extchromium.h" 34 #include "gpu/GLES2/gl2extchromium.h"
35 #include "gpu/command_buffer/client/gles2_interface.h" 35 #include "gpu/command_buffer/client/gles2_interface.h"
36 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
36 #include "gpu/command_buffer/common/capabilities.h" 37 #include "gpu/command_buffer/common/capabilities.h"
38 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
37 #include "platform/RuntimeEnabledFeatures.h" 39 #include "platform/RuntimeEnabledFeatures.h"
38 #include "platform/graphics/AcceleratedStaticBitmapImage.h" 40 #include "platform/graphics/AcceleratedStaticBitmapImage.h"
39 #include "platform/graphics/GraphicsLayer.h" 41 #include "platform/graphics/GraphicsLayer.h"
40 #include "platform/graphics/ImageBuffer.h" 42 #include "platform/graphics/ImageBuffer.h"
41 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h" 43 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h"
42 #include "platform/graphics/gpu/Extensions3DUtil.h" 44 #include "platform/graphics/gpu/Extensions3DUtil.h"
43 #include "platform/instrumentation/tracing/TraceEvent.h" 45 #include "platform/instrumentation/tracing/TraceEvent.h"
44 #include "public/platform/Platform.h" 46 #include "public/platform/Platform.h"
45 #include "public/platform/WebCompositorSupport.h" 47 #include "public/platform/WebCompositorSupport.h"
46 #include "public/platform/WebExternalBitmap.h" 48 #include "public/platform/WebExternalBitmap.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 m_contextProvider(WTF::wrapUnique( 147 m_contextProvider(WTF::wrapUnique(
146 new WebGraphicsContext3DProviderWrapper(std::move(contextProvider)))), 148 new WebGraphicsContext3DProviderWrapper(std::move(contextProvider)))),
147 m_gl(this->contextProvider()->contextGL()), 149 m_gl(this->contextProvider()->contextGL()),
148 m_extensionsUtil(std::move(extensionsUtil)), 150 m_extensionsUtil(std::move(extensionsUtil)),
149 m_discardFramebufferSupported(discardFramebufferSupported), 151 m_discardFramebufferSupported(discardFramebufferSupported),
150 m_wantAlphaChannel(wantAlphaChannel), 152 m_wantAlphaChannel(wantAlphaChannel),
151 m_premultipliedAlpha(premultipliedAlpha), 153 m_premultipliedAlpha(premultipliedAlpha),
152 m_softwareRendering(this->contextProvider()->isSoftwareRendering()), 154 m_softwareRendering(this->contextProvider()->isSoftwareRendering()),
153 m_wantDepth(wantDepth), 155 m_wantDepth(wantDepth),
154 m_wantStencil(wantStencil), 156 m_wantStencil(wantStencil),
157 m_colorSpace(gfx::ColorSpace::CreateSRGB()),
155 m_chromiumImageUsage(chromiumImageUsage) { 158 m_chromiumImageUsage(chromiumImageUsage) {
156 // Used by browser tests to detect the use of a DrawingBuffer. 159 // Used by browser tests to detect the use of a DrawingBuffer.
157 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", 160 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation",
158 TRACE_EVENT_SCOPE_GLOBAL); 161 TRACE_EVENT_SCOPE_GLOBAL);
159 } 162 }
160 163
161 DrawingBuffer::~DrawingBuffer() { 164 DrawingBuffer::~DrawingBuffer() {
162 DCHECK(m_destructionInProgress); 165 DCHECK(m_destructionInProgress);
163 m_layer.reset(); 166 m_layer.reset();
164 m_contextProvider.reset(); 167 m_contextProvider.reset();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 DCHECK(pixels); 307 DCHECK(pixels);
305 bool needPremultiply = m_wantAlphaChannel && !m_premultipliedAlpha; 308 bool needPremultiply = m_wantAlphaChannel && !m_premultipliedAlpha;
306 WebGLImageConversion::AlphaOp op = 309 WebGLImageConversion::AlphaOp op =
307 needPremultiply ? WebGLImageConversion::AlphaDoPremultiply 310 needPremultiply ? WebGLImageConversion::AlphaDoPremultiply
308 : WebGLImageConversion::AlphaDoNothing; 311 : WebGLImageConversion::AlphaDoNothing;
309 readBackFramebuffer(pixels, size().width(), size().height(), ReadbackSkia, 312 readBackFramebuffer(pixels, size().width(), size().height(), ReadbackSkia,
310 op); 313 op);
311 } 314 }
312 315
313 *outMailbox = cc::TextureMailbox(bitmap.get(), m_size); 316 *outMailbox = cc::TextureMailbox(bitmap.get(), m_size);
317 outMailbox->set_color_space(m_colorSpace);
314 318
315 // This holds a ref on the DrawingBuffer that will keep it alive until the 319 // This holds a ref on the DrawingBuffer that will keep it alive until the
316 // mailbox is released (and while the release callback is running). It also 320 // mailbox is released (and while the release callback is running). It also
317 // owns the SharedBitmap. 321 // owns the SharedBitmap.
318 auto func = WTF::bind(&DrawingBuffer::mailboxReleasedSoftware, 322 auto func = WTF::bind(&DrawingBuffer::mailboxReleasedSoftware,
319 RefPtr<DrawingBuffer>(this), 323 RefPtr<DrawingBuffer>(this),
320 WTF::passed(std::move(bitmap)), m_size); 324 WTF::passed(std::move(bitmap)), m_size);
321 *outReleaseCallback = 325 *outReleaseCallback =
322 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func))); 326 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func)));
323 return true; 327 return true;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 380 }
377 381
378 // Populate the output mailbox and callback. 382 // Populate the output mailbox and callback.
379 { 383 {
380 bool isOverlayCandidate = colorBufferForMailbox->imageId != 0; 384 bool isOverlayCandidate = colorBufferForMailbox->imageId != 0;
381 bool secureOutputOnly = false; 385 bool secureOutputOnly = false;
382 *outMailbox = cc::TextureMailbox( 386 *outMailbox = cc::TextureMailbox(
383 colorBufferForMailbox->mailbox, colorBufferForMailbox->produceSyncToken, 387 colorBufferForMailbox->mailbox, colorBufferForMailbox->produceSyncToken,
384 colorBufferForMailbox->parameters.target, gfx::Size(m_size), 388 colorBufferForMailbox->parameters.target, gfx::Size(m_size),
385 isOverlayCandidate, secureOutputOnly); 389 isOverlayCandidate, secureOutputOnly);
390 outMailbox->set_color_space(m_colorSpace);
386 391
387 // This holds a ref on the DrawingBuffer that will keep it alive until the 392 // This holds a ref on the DrawingBuffer that will keep it alive until the
388 // mailbox is released (and while the release callback is running). 393 // mailbox is released (and while the release callback is running).
389 auto func = WTF::bind(&DrawingBuffer::mailboxReleasedGpu, 394 auto func = WTF::bind(&DrawingBuffer::mailboxReleasedGpu,
390 RefPtr<DrawingBuffer>(this), colorBufferForMailbox); 395 RefPtr<DrawingBuffer>(this), colorBufferForMailbox);
391 *outReleaseCallback = cc::SingleReleaseCallback::Create( 396 *outReleaseCallback = cc::SingleReleaseCallback::Create(
392 convertToBaseCallback(std::move(func))); 397 convertToBaseCallback(std::move(func)));
393 } 398 }
394 399
395 // Point |m_frontColorBuffer| to the buffer that we are now presenting. 400 // Point |m_frontColorBuffer| to the buffer that we are now presenting.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (!m_recycledColorBufferQueue.isEmpty()) { 570 if (!m_recycledColorBufferQueue.isEmpty()) {
566 RefPtr<ColorBuffer> recycled = m_recycledColorBufferQueue.takeLast(); 571 RefPtr<ColorBuffer> recycled = m_recycledColorBufferQueue.takeLast();
567 if (recycled->receiveSyncToken.HasData()) 572 if (recycled->receiveSyncToken.HasData())
568 m_gl->WaitSyncTokenCHROMIUM(recycled->receiveSyncToken.GetData()); 573 m_gl->WaitSyncTokenCHROMIUM(recycled->receiveSyncToken.GetData());
569 DCHECK(recycled->size == m_size); 574 DCHECK(recycled->size == m_size);
570 return recycled; 575 return recycled;
571 } 576 }
572 return createColorBuffer(m_size); 577 return createColorBuffer(m_size);
573 } 578 }
574 579
575 DrawingBuffer::ColorBuffer::ColorBuffer(DrawingBuffer* drawingBuffer, 580 DrawingBuffer::ColorBuffer::ColorBuffer(
576 const ColorBufferParameters& parameters, 581 DrawingBuffer* drawingBuffer,
577 const IntSize& size, 582 const ColorBufferParameters& parameters,
578 GLuint textureId, 583 const IntSize& size,
579 GLuint imageId) 584 GLuint textureId,
585 GLuint imageId,
586 std::unique_ptr<gfx::GpuMemoryBuffer> gpuMemoryBuffer)
580 : drawingBuffer(drawingBuffer), 587 : drawingBuffer(drawingBuffer),
581 parameters(parameters), 588 parameters(parameters),
582 size(size), 589 size(size),
583 textureId(textureId), 590 textureId(textureId),
584 imageId(imageId) { 591 imageId(imageId),
592 gpuMemoryBuffer(std::move(gpuMemoryBuffer)) {
585 drawingBuffer->contextGL()->GenMailboxCHROMIUM(mailbox.name); 593 drawingBuffer->contextGL()->GenMailboxCHROMIUM(mailbox.name);
586 } 594 }
587 595
588 DrawingBuffer::ColorBuffer::~ColorBuffer() { 596 DrawingBuffer::ColorBuffer::~ColorBuffer() {
589 gpu::gles2::GLES2Interface* gl = drawingBuffer->m_gl; 597 gpu::gles2::GLES2Interface* gl = drawingBuffer->m_gl;
590 if (receiveSyncToken.HasData()) 598 if (receiveSyncToken.HasData())
591 gl->WaitSyncTokenCHROMIUM(receiveSyncToken.GetConstData()); 599 gl->WaitSyncTokenCHROMIUM(receiveSyncToken.GetConstData());
592 if (imageId) { 600 if (imageId) {
593 gl->BindTexture(parameters.target, textureId); 601 gl->BindTexture(parameters.target, textureId);
594 gl->ReleaseTexImage2DCHROMIUM(parameters.target, imageId); 602 gl->ReleaseTexImage2DCHROMIUM(parameters.target, imageId);
595 gl->DestroyImageCHROMIUM(imageId); 603 gl->DestroyImageCHROMIUM(imageId);
596 switch (parameters.target) { 604 switch (parameters.target) {
597 case GL_TEXTURE_2D: 605 case GL_TEXTURE_2D:
598 // Restore the texture binding for GL_TEXTURE_2D, since the client will 606 // Restore the texture binding for GL_TEXTURE_2D, since the client will
599 // expect the previous state. 607 // expect the previous state.
600 if (drawingBuffer->m_client) 608 if (drawingBuffer->m_client)
601 drawingBuffer->m_client->DrawingBufferClientRestoreTexture2DBinding(); 609 drawingBuffer->m_client->DrawingBufferClientRestoreTexture2DBinding();
602 break; 610 break;
603 case GC3D_TEXTURE_RECTANGLE_ARB: 611 case GC3D_TEXTURE_RECTANGLE_ARB:
604 // Rectangle textures aren't exposed to WebGL, so don't bother 612 // Rectangle textures aren't exposed to WebGL, so don't bother
605 // restoring this state (there is no meaningful way to restore it). 613 // restoring this state (there is no meaningful way to restore it).
606 break; 614 break;
607 default: 615 default:
608 NOTREACHED(); 616 NOTREACHED();
609 break; 617 break;
610 } 618 }
619 gpuMemoryBuffer.reset();
611 } 620 }
612 gl->DeleteTextures(1, &textureId); 621 gl->DeleteTextures(1, &textureId);
613 } 622 }
614 623
615 bool DrawingBuffer::initialize(const IntSize& size, bool useMultisampling) { 624 bool DrawingBuffer::initialize(const IntSize& size, bool useMultisampling) {
616 ScopedStateRestorer scopedStateRestorer(this); 625 ScopedStateRestorer scopedStateRestorer(this);
617 626
618 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { 627 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) {
619 // Need to try to restore the context again later. 628 // Need to try to restore the context again later.
620 return false; 629 return false;
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 RefPtr<DrawingBuffer::ColorBuffer> DrawingBuffer::createColorBuffer( 1131 RefPtr<DrawingBuffer::ColorBuffer> DrawingBuffer::createColorBuffer(
1123 const IntSize& size) { 1132 const IntSize& size) {
1124 DCHECK(m_stateRestorer); 1133 DCHECK(m_stateRestorer);
1125 m_stateRestorer->setFramebufferBindingDirty(); 1134 m_stateRestorer->setFramebufferBindingDirty();
1126 m_stateRestorer->setTextureBindingDirty(); 1135 m_stateRestorer->setTextureBindingDirty();
1127 1136
1128 // Select the Parameters for the texture object. Allocate the backing 1137 // Select the Parameters for the texture object. Allocate the backing
1129 // GpuMemoryBuffer and GLImage, if one is going to be used. 1138 // GpuMemoryBuffer and GLImage, if one is going to be used.
1130 ColorBufferParameters parameters; 1139 ColorBufferParameters parameters;
1131 GLuint imageId = 0; 1140 GLuint imageId = 0;
1132 if (shouldUseChromiumImage()) { 1141 std::unique_ptr<gfx::GpuMemoryBuffer> gpuMemoryBuffer;
1142 gpu::GpuMemoryBufferManager* gpuMemoryBufferManager =
1143 Platform::current()->getGpuMemoryBufferManager();
1144 if (shouldUseChromiumImage() && gpuMemoryBufferManager) {
1133 parameters = gpuMemoryBufferColorBufferParameters(); 1145 parameters = gpuMemoryBufferColorBufferParameters();
1134 imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM( 1146 gfx::BufferFormat bufferFormat = gpu::DefaultBufferFormatForImageFormat(
1135 size.width(), size.height(), parameters.creationInternalColorFormat, 1147 parameters.creationInternalColorFormat);
1136 GC3D_SCANOUT_CHROMIUM); 1148 gpuMemoryBuffer = gpuMemoryBufferManager->CreateGpuMemoryBuffer(
1149 gfx::Size(size), bufferFormat, gfx::BufferUsage::SCANOUT,
1150 gpu::kNullSurfaceHandle);
1151 if (gpuMemoryBuffer) {
1152 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled())
1153 gpuMemoryBuffer->SetColorSpaceForScanout(m_colorSpace);
1154 imageId = m_gl->CreateImageCHROMIUM(
1155 gpuMemoryBuffer->AsClientBuffer(), size.width(), size.height(),
1156 parameters.creationInternalColorFormat);
1157 if (!imageId)
1158 gpuMemoryBuffer.reset();
1159 }
1137 } else { 1160 } else {
1138 parameters = textureColorBufferParameters(); 1161 parameters = textureColorBufferParameters();
1139 } 1162 }
1140 1163
1141 // Allocate the texture for this object. 1164 // Allocate the texture for this object.
1142 GLuint textureId = 0; 1165 GLuint textureId = 0;
1143 { 1166 {
1144 m_gl->GenTextures(1, &textureId); 1167 m_gl->GenTextures(1, &textureId);
1145 m_gl->BindTexture(parameters.target, textureId); 1168 m_gl->BindTexture(parameters.target, textureId);
1146 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1169 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 1207 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1185 parameters.target, textureId, 0); 1208 parameters.target, textureId, 0);
1186 m_gl->ClearColor(0, 0, 0, 1); 1209 m_gl->ClearColor(0, 0, 0, 1);
1187 m_gl->ColorMask(false, false, false, true); 1210 m_gl->ColorMask(false, false, false, true);
1188 m_gl->Clear(GL_COLOR_BUFFER_BIT); 1211 m_gl->Clear(GL_COLOR_BUFFER_BIT);
1189 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 1212 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1190 parameters.target, 0, 0); 1213 parameters.target, 0, 0);
1191 m_gl->DeleteFramebuffers(1, &fbo); 1214 m_gl->DeleteFramebuffers(1, &fbo);
1192 } 1215 }
1193 1216
1194 return adoptRef(new ColorBuffer(this, parameters, size, textureId, imageId)); 1217 return adoptRef(new ColorBuffer(this, parameters, size, textureId, imageId,
1218 std::move(gpuMemoryBuffer)));
1195 } 1219 }
1196 1220
1197 void DrawingBuffer::attachColorBufferToReadFramebuffer() { 1221 void DrawingBuffer::attachColorBufferToReadFramebuffer() {
1198 DCHECK(m_stateRestorer); 1222 DCHECK(m_stateRestorer);
1199 m_stateRestorer->setFramebufferBindingDirty(); 1223 m_stateRestorer->setFramebufferBindingDirty();
1200 m_stateRestorer->setTextureBindingDirty(); 1224 m_stateRestorer->setTextureBindingDirty();
1201 1225
1202 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 1226 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
1203 1227
1204 GLenum target = m_backColorBuffer->parameters.target; 1228 GLenum target = m_backColorBuffer->parameters.target;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 if (m_pixelUnpackBufferBindingDirty) 1290 if (m_pixelUnpackBufferBindingDirty)
1267 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); 1291 client->DrawingBufferClientRestorePixelUnpackBufferBinding();
1268 } 1292 }
1269 1293
1270 bool DrawingBuffer::shouldUseChromiumImage() { 1294 bool DrawingBuffer::shouldUseChromiumImage() {
1271 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && 1295 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() &&
1272 m_chromiumImageUsage == AllowChromiumImage; 1296 m_chromiumImageUsage == AllowChromiumImage;
1273 } 1297 }
1274 1298
1275 } // namespace blink 1299 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698