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

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

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: no crash! && address comments Created 4 years, 1 month 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 20 matching lines...) Expand all
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/common/capabilities.h" 36 #include "gpu/command_buffer/common/capabilities.h"
37 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
38 #include "platform/graphics/AcceleratedStaticBitmapImage.h" 38 #include "platform/graphics/AcceleratedStaticBitmapImage.h"
39 #include "platform/graphics/GraphicsLayer.h" 39 #include "platform/graphics/GraphicsLayer.h"
40 #include "platform/graphics/ImageBuffer.h" 40 #include "platform/graphics/ImageBuffer.h"
41 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h"
41 #include "platform/graphics/gpu/Extensions3DUtil.h" 42 #include "platform/graphics/gpu/Extensions3DUtil.h"
42 #include "platform/tracing/TraceEvent.h" 43 #include "platform/tracing/TraceEvent.h"
43 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
44 #include "public/platform/WebCompositorSupport.h" 45 #include "public/platform/WebCompositorSupport.h"
45 #include "public/platform/WebExternalBitmap.h" 46 #include "public/platform/WebExternalBitmap.h"
46 #include "public/platform/WebExternalTextureLayer.h" 47 #include "public/platform/WebExternalTextureLayer.h"
47 #include "public/platform/WebGraphicsContext3DProvider.h" 48 #include "public/platform/WebGraphicsContext3DProvider.h"
48 #include "skia/ext/texture_handle.h" 49 #include "skia/ext/texture_handle.h"
49 #include "third_party/skia/include/gpu/GrContext.h" 50 #include "third_party/skia/include/gpu/GrContext.h"
50 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" 51 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 bool wantAlphaChannel, 136 bool wantAlphaChannel,
136 bool premultipliedAlpha, 137 bool premultipliedAlpha,
137 PreserveDrawingBuffer preserve, 138 PreserveDrawingBuffer preserve,
138 WebGLVersion webGLVersion, 139 WebGLVersion webGLVersion,
139 bool wantDepth, 140 bool wantDepth,
140 bool wantStencil, 141 bool wantStencil,
141 ChromiumImageUsage chromiumImageUsage) 142 ChromiumImageUsage chromiumImageUsage)
142 : m_client(client), 143 : m_client(client),
143 m_preserveDrawingBuffer(preserve), 144 m_preserveDrawingBuffer(preserve),
144 m_webGLVersion(webGLVersion), 145 m_webGLVersion(webGLVersion),
145 m_contextProvider(std::move(contextProvider)), 146 m_contextProvider(wrapUnique(
146 m_gl(m_contextProvider->contextGL()), 147 new WebGraphicsContext3DProviderWrapper(std::move(contextProvider)))),
148 m_gl(m_contextProvider->contextProvider()->contextGL()),
147 m_extensionsUtil(std::move(extensionsUtil)), 149 m_extensionsUtil(std::move(extensionsUtil)),
148 m_discardFramebufferSupported(discardFramebufferSupported), 150 m_discardFramebufferSupported(discardFramebufferSupported),
149 m_wantAlphaChannel(wantAlphaChannel), 151 m_wantAlphaChannel(wantAlphaChannel),
150 m_premultipliedAlpha(premultipliedAlpha), 152 m_premultipliedAlpha(premultipliedAlpha),
151 m_softwareRendering(m_contextProvider->isSoftwareRendering()), 153 m_softwareRendering(
154 m_contextProvider->contextProvider()->isSoftwareRendering()),
Justin Novosad 2016/11/08 20:41:50 No need for m_contextProvider-> Just: m_softwareRe
xidachen 2016/11/08 21:01:54 Done.
152 m_wantDepth(wantDepth), 155 m_wantDepth(wantDepth),
153 m_wantStencil(wantStencil), 156 m_wantStencil(wantStencil),
154 m_chromiumImageUsage(chromiumImageUsage) { 157 m_chromiumImageUsage(chromiumImageUsage) {
155 // Used by browser tests to detect the use of a DrawingBuffer. 158 // Used by browser tests to detect the use of a DrawingBuffer.
156 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", 159 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation",
157 TRACE_EVENT_SCOPE_GLOBAL); 160 TRACE_EVENT_SCOPE_GLOBAL);
158 } 161 }
159 162
160 DrawingBuffer::~DrawingBuffer() { 163 DrawingBuffer::~DrawingBuffer() {
161 DCHECK(m_destructionInProgress); 164 DCHECK(m_destructionInProgress);
(...skipping 16 matching lines...) Expand all
178 } else { 181 } else {
179 ASSERT(!m_bufferClearNeeded); 182 ASSERT(!m_bufferClearNeeded);
180 } 183 }
181 } 184 }
182 185
183 gpu::gles2::GLES2Interface* DrawingBuffer::contextGL() { 186 gpu::gles2::GLES2Interface* DrawingBuffer::contextGL() {
184 return m_gl; 187 return m_gl;
185 } 188 }
186 189
187 WebGraphicsContext3DProvider* DrawingBuffer::contextProvider() { 190 WebGraphicsContext3DProvider* DrawingBuffer::contextProvider() {
188 return m_contextProvider.get(); 191 return m_contextProvider->contextProvider();
189 } 192 }
190 193
191 void DrawingBuffer::setIsHidden(bool hidden) { 194 void DrawingBuffer::setIsHidden(bool hidden) {
192 if (m_isHidden == hidden) 195 if (m_isHidden == hidden)
193 return; 196 return;
194 m_isHidden = hidden; 197 m_isHidden = hidden;
195 if (m_isHidden) 198 if (m_isHidden)
196 m_recycledColorBufferQueue.clear(); 199 m_recycledColorBufferQueue.clear();
197 } 200 }
198 201
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 438
436 RecycledBitmap recycled = {std::move(bitmap), m_size}; 439 RecycledBitmap recycled = {std::move(bitmap), m_size};
437 m_recycledBitmaps.append(std::move(recycled)); 440 m_recycledBitmaps.append(std::move(recycled));
438 } 441 }
439 442
440 PassRefPtr<StaticBitmapImage> DrawingBuffer::transferToStaticBitmapImage() { 443 PassRefPtr<StaticBitmapImage> DrawingBuffer::transferToStaticBitmapImage() {
441 ScopedStateRestorer scopedStateRestorer(this); 444 ScopedStateRestorer scopedStateRestorer(this);
442 445
443 // This can be null if the context is lost before the first call to 446 // This can be null if the context is lost before the first call to
444 // grContext(). 447 // grContext().
445 GrContext* grContext = m_contextProvider->grContext(); 448 GrContext* grContext = m_contextProvider->contextProvider()->grContext();
Justin Novosad 2016/11/08 20:41:50 No need for "m_contextProvider->"
xidachen 2016/11/08 21:01:54 Done.
446 449
447 cc::TextureMailbox textureMailbox; 450 cc::TextureMailbox textureMailbox;
448 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 451 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
449 bool success = false; 452 bool success = false;
450 if (grContext) { 453 if (grContext) {
451 bool forceGpuResult = true; 454 bool forceGpuResult = true;
452 success = prepareTextureMailboxInternal(&textureMailbox, &releaseCallback, 455 success = prepareTextureMailboxInternal(&textureMailbox, &releaseCallback,
453 forceGpuResult); 456 forceGpuResult);
454 } 457 }
455 if (!success) { 458 if (!success) {
(...skipping 18 matching lines...) Expand all
474 // back to it. 477 // back to it.
475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use 478 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use
476 // the actual texture id and avoid needing to produce/consume a mailbox. 479 // the actual texture id and avoid needing to produce/consume a mailbox.
477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( 480 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM(
478 GL_TEXTURE_2D, textureMailbox.name()); 481 GL_TEXTURE_2D, textureMailbox.name());
479 // Return the mailbox but report that the resource is lost to prevent trying 482 // 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 483 // to use the backing for future frames. We keep it alive with our own
481 // reference to the backing via our |textureId|. 484 // reference to the backing via our |textureId|.
482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); 485 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */);
483 486
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 487 // We reuse the same mailbox name from above since our texture id was consumed
499 // from it. 488 // from it.
500 const auto& skImageMailbox = textureMailbox.mailbox(); 489 const auto& skImageMailbox = textureMailbox.mailbox();
501 // Use the sync token generated after producing the mailbox. Waiting for this 490 // 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 491 // 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 492 // 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 493 // because the texture id it generated would only be valid for the
505 // DrawingBuffer's context anyways. 494 // DrawingBuffer's context anyways.
506 const auto& skImageSyncToken = textureMailbox.sync_token(); 495 const auto& skImageSyncToken = textureMailbox.sync_token();
507 496
508 // TODO(xidachen): Create a small pool of recycled textures from 497 // TODO(xidachen): Create a small pool of recycled textures from
509 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them 498 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them
510 // in DrawingBuffer. 499 // in DrawingBuffer.
511 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( 500 return AcceleratedStaticBitmapImage::createFromWebGLContextImage(
512 std::move(skImage), skImageMailbox, skImageSyncToken); 501 skImageMailbox, skImageSyncToken, textureId,
502 m_contextProvider->createWeakPtr(), m_size);
513 } 503 }
514 504
515 DrawingBuffer::ColorBufferParameters 505 DrawingBuffer::ColorBufferParameters
516 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { 506 DrawingBuffer::gpuMemoryBufferColorBufferParameters() {
517 #if OS(MACOSX) 507 #if OS(MACOSX)
518 // A CHROMIUM_image backed texture requires a specialized set of parameters 508 // A CHROMIUM_image backed texture requires a specialized set of parameters
519 // on OSX. 509 // on OSX.
520 ColorBufferParameters parameters; 510 ColorBufferParameters parameters;
521 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 511 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
522 512
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 if (m_pixelUnpackBufferBindingDirty) 1255 if (m_pixelUnpackBufferBindingDirty)
1266 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); 1256 client->DrawingBufferClientRestorePixelUnpackBufferBinding();
1267 } 1257 }
1268 1258
1269 bool DrawingBuffer::shouldUseChromiumImage() { 1259 bool DrawingBuffer::shouldUseChromiumImage() {
1270 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && 1260 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() &&
1271 m_chromiumImageUsage == AllowChromiumImage; 1261 m_chromiumImageUsage == AllowChromiumImage;
1272 } 1262 }
1273 1263
1274 } // namespace blink 1264 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698