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

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

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: WeakPtr, still figuring out why one layout test timed out 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "platform/tracing/TraceEvent.h" 42 #include "platform/tracing/TraceEvent.h"
43 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
44 #include "public/platform/WebCompositorSupport.h" 44 #include "public/platform/WebCompositorSupport.h"
45 #include "public/platform/WebExternalBitmap.h" 45 #include "public/platform/WebExternalBitmap.h"
46 #include "public/platform/WebExternalTextureLayer.h" 46 #include "public/platform/WebExternalTextureLayer.h"
47 #include "public/platform/WebGraphicsContext3DProvider.h" 47 #include "public/platform/WebGraphicsContext3DProvider.h"
48 #include "skia/ext/texture_handle.h" 48 #include "skia/ext/texture_handle.h"
49 #include "third_party/skia/include/gpu/GrContext.h" 49 #include "third_party/skia/include/gpu/GrContext.h"
50 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" 50 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
51 #include "wtf/CheckedNumeric.h" 51 #include "wtf/CheckedNumeric.h"
52 #include "wtf/WeakPtr.h"
52 #include "wtf/typed_arrays/ArrayBufferContents.h" 53 #include "wtf/typed_arrays/ArrayBufferContents.h"
53 #include <algorithm> 54 #include <algorithm>
54 #include <memory> 55 #include <memory>
55 56
56 namespace blink { 57 namespace blink {
57 58
58 namespace { 59 namespace {
59 60
60 const float s_resourceAdjustedRatio = 0.5; 61 const float s_resourceAdjustedRatio = 0.5;
61 62
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 m_webGLVersion(webGLVersion), 145 m_webGLVersion(webGLVersion),
145 m_contextProvider(std::move(contextProvider)), 146 m_contextProvider(std::move(contextProvider)),
146 m_gl(m_contextProvider->contextGL()), 147 m_gl(m_contextProvider->contextGL()),
147 m_extensionsUtil(std::move(extensionsUtil)), 148 m_extensionsUtil(std::move(extensionsUtil)),
148 m_discardFramebufferSupported(discardFramebufferSupported), 149 m_discardFramebufferSupported(discardFramebufferSupported),
149 m_wantAlphaChannel(wantAlphaChannel), 150 m_wantAlphaChannel(wantAlphaChannel),
150 m_premultipliedAlpha(premultipliedAlpha), 151 m_premultipliedAlpha(premultipliedAlpha),
151 m_softwareRendering(m_contextProvider->isSoftwareRendering()), 152 m_softwareRendering(m_contextProvider->isSoftwareRendering()),
152 m_wantDepth(wantDepth), 153 m_wantDepth(wantDepth),
153 m_wantStencil(wantStencil), 154 m_wantStencil(wantStencil),
154 m_chromiumImageUsage(chromiumImageUsage) { 155 m_chromiumImageUsage(chromiumImageUsage),
156 m_weakPtrFactory(this) {
155 // Used by browser tests to detect the use of a DrawingBuffer. 157 // Used by browser tests to detect the use of a DrawingBuffer.
156 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", 158 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation",
157 TRACE_EVENT_SCOPE_GLOBAL); 159 TRACE_EVENT_SCOPE_GLOBAL);
158 } 160 }
159 161
160 DrawingBuffer::~DrawingBuffer() { 162 DrawingBuffer::~DrawingBuffer() {
161 DCHECK(m_destructionInProgress); 163 DCHECK(m_destructionInProgress);
162 m_layer.reset(); 164 m_layer.reset();
163 m_contextProvider.reset(); 165 m_contextProvider.reset();
164 } 166 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // back to it. 476 // back to it.
475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use 477 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use
476 // the actual texture id and avoid needing to produce/consume a mailbox. 478 // the actual texture id and avoid needing to produce/consume a mailbox.
477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( 479 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM(
478 GL_TEXTURE_2D, textureMailbox.name()); 480 GL_TEXTURE_2D, textureMailbox.name());
479 // Return the mailbox but report that the resource is lost to prevent trying 481 // 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 482 // to use the backing for future frames. We keep it alive with our own
481 // reference to the backing via our |textureId|. 483 // reference to the backing via our |textureId|.
482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); 484 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */);
483 485
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 486 // We reuse the same mailbox name from above since our texture id was consumed
499 // from it. 487 // from it.
500 const auto& skImageMailbox = textureMailbox.mailbox(); 488 const auto& skImageMailbox = textureMailbox.mailbox();
501 // Use the sync token generated after producing the mailbox. Waiting for this 489 // 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 490 // 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 491 // 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 492 // because the texture id it generated would only be valid for the
505 // DrawingBuffer's context anyways. 493 // DrawingBuffer's context anyways.
506 const auto& skImageSyncToken = textureMailbox.sync_token(); 494 const auto& skImageSyncToken = textureMailbox.sync_token();
507 495
508 // TODO(xidachen): Create a small pool of recycled textures from 496 // TODO(xidachen): Create a small pool of recycled textures from
509 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them 497 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them
510 // in DrawingBuffer. 498 // in DrawingBuffer.
511 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( 499 return AcceleratedStaticBitmapImage::createFromWebGLContextImage(
512 std::move(skImage), skImageMailbox, skImageSyncToken); 500 skImageMailbox, skImageSyncToken, textureId,
501 m_weakPtrFactory.createWeakPtr(), m_size);
513 } 502 }
514 503
515 DrawingBuffer::ColorBufferParameters 504 DrawingBuffer::ColorBufferParameters
516 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { 505 DrawingBuffer::gpuMemoryBufferColorBufferParameters() {
517 #if OS(MACOSX) 506 #if OS(MACOSX)
518 // A CHROMIUM_image backed texture requires a specialized set of parameters 507 // A CHROMIUM_image backed texture requires a specialized set of parameters
519 // on OSX. 508 // on OSX.
520 ColorBufferParameters parameters; 509 ColorBufferParameters parameters;
521 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 510 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
522 511
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 if (m_pixelUnpackBufferBindingDirty) 1254 if (m_pixelUnpackBufferBindingDirty)
1266 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); 1255 client->DrawingBufferClientRestorePixelUnpackBufferBinding();
1267 } 1256 }
1268 1257
1269 bool DrawingBuffer::shouldUseChromiumImage() { 1258 bool DrawingBuffer::shouldUseChromiumImage() {
1270 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && 1259 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() &&
1271 m_chromiumImageUsage == AllowChromiumImage; 1260 m_chromiumImageUsage == AllowChromiumImage;
1272 } 1261 }
1273 1262
1274 } // namespace blink 1263 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698