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

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

Issue 2455983005: Refactor AcceleratedStaticBitmapImage (Closed)
Patch Set: fix flickering 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" 5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/quads/texture_draw_quad.h" 8 #include "cc/quads/texture_draw_quad.h"
9 #include "gpu/command_buffer/client/gles2_interface.h" 9 #include "gpu/command_buffer/client/gles2_interface.h"
10 #include "platform/Histogram.h" 10 #include "platform/Histogram.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 // Hold ref to |textureId| for the piece of GPU memory where the pixel data 129 // Hold ref to |textureId| for the piece of GPU memory where the pixel data
130 // is uploaded to, to keep it alive until the browser ReclaimResources. 130 // is uploaded to, to keep it alive until the browser ReclaimResources.
131 m_cachedTextureIds.add(m_nextResourceId, textureId); 131 m_cachedTextureIds.add(m_nextResourceId, textureId);
132 } 132 }
133 133
134 void OffscreenCanvasFrameDispatcherImpl:: 134 void OffscreenCanvasFrameDispatcherImpl::
135 setTransferableResourceToStaticBitmapImage( 135 setTransferableResourceToStaticBitmapImage(
136 cc::TransferableResource& resource, 136 cc::TransferableResource& resource,
137 RefPtr<StaticBitmapImage> image) { 137 RefPtr<StaticBitmapImage> image) {
138 image->ensureMailbox(); 138 image->ensureMailbox();
xidachen 2016/11/04 13:18:03 junov@: Then in here, we call image->ensureMailbox
139 resource.mailbox_holder = gpu::MailboxHolder( 139 resource.mailbox_holder =
140 image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D); 140 gpu::MailboxHolder(image->mailbox(), image->syncToken(), GL_TEXTURE_2D);
141 resource.read_lock_fences_enabled = false; 141 resource.read_lock_fences_enabled = false;
142 resource.is_software = false; 142 resource.is_software = false;
143 143
144 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. 144 // Hold ref to |image|, to keep it alive until the browser ReclaimResources.
145 // It guarantees that the resource is not re-used or deleted. 145 // It guarantees that the resource is not re-used or deleted.
146 m_cachedImages.add(m_nextResourceId, std::move(image)); 146 m_cachedImages.add(m_nextResourceId, std::move(image));
147 } 147 }
148 148
149 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( 149 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(
150 RefPtr<StaticBitmapImage> image, 150 RefPtr<StaticBitmapImage> image,
151 double commitStartTime, 151 double commitStartTime,
152 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is 152 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is
153 called on SwiftShader. */) { 153 called on SwiftShader. */) {
154 if (!image) 154 if (!image)
155 return; 155 return;
156 if (!verifyImageSize(image->imageForCurrentFrame())) 156 if (!verifyImageSize(image->size()))
157 return; 157 return;
158 cc::CompositorFrame frame; 158 cc::CompositorFrame frame;
159 // TODO(crbug.com/652931): update the device_scale_factor 159 // TODO(crbug.com/652931): update the device_scale_factor
160 frame.metadata.device_scale_factor = 1.0f; 160 frame.metadata.device_scale_factor = 1.0f;
161 161
162 const gfx::Rect bounds(m_width, m_height); 162 const gfx::Rect bounds(m_width, m_height);
163 const cc::RenderPassId renderPassId(1, 1); 163 const cc::RenderPassId renderPassId(1, 1);
164 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 164 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
165 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); 165 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false);
166 166
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 m_sink->SubmitCompositorFrame(std::move(frame)); 314 m_sink->SubmitCompositorFrame(std::move(frame));
315 } 315 }
316 316
317 void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck() { 317 void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck() {
318 // TODO(fsamuel): Implement this. 318 // TODO(fsamuel): Implement this.
319 } 319 }
320 320
321 void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( 321 void OffscreenCanvasFrameDispatcherImpl::ReclaimResources(
322 const cc::ReturnedResourceArray& resources) { 322 const cc::ReturnedResourceArray& resources) {
323 for (const auto& resource : resources) { 323 for (const auto& resource : resources) {
324 RefPtr<StaticBitmapImage> image = m_cachedImages.get(resource.id);
325 if (image)
326 image->updateSyncToken(resource.sync_token);
324 m_cachedImages.remove(resource.id); 327 m_cachedImages.remove(resource.id);
325 m_sharedBitmaps.remove(resource.id); 328 m_sharedBitmaps.remove(resource.id);
326 m_cachedTextureIds.remove(resource.id); 329 m_cachedTextureIds.remove(resource.id);
327 } 330 }
328 } 331 }
329 332
330 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( 333 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(
331 const sk_sp<SkImage>& image) { 334 const IntSize imageSize) {
332 if (image && image->width() == m_width && image->height() == m_height) 335 if (imageSize.width() == m_width && imageSize.height() == m_height)
333 return true; 336 return true;
334 return false; 337 return false;
335 } 338 }
336 339
337 } // namespace blink 340 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698