| OLD | NEW |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(); |
| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::OnBeginFrame( | 321 void OffscreenCanvasFrameDispatcherImpl::OnBeginFrame( |
| 322 const cc::BeginFrameArgs& beginFrameArgs) {} | 322 const cc::BeginFrameArgs& beginFrameArgs) {} |
| 323 | 323 |
| 324 void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( | 324 void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( |
| 325 const cc::ReturnedResourceArray& resources) { | 325 const cc::ReturnedResourceArray& resources) { |
| 326 for (const auto& resource : resources) { | 326 for (const auto& resource : resources) { |
| 327 RefPtr<StaticBitmapImage> image = m_cachedImages.get(resource.id); |
| 328 if (image) |
| 329 image->updateSyncToken(resource.sync_token); |
| 327 m_cachedImages.remove(resource.id); | 330 m_cachedImages.remove(resource.id); |
| 328 m_sharedBitmaps.remove(resource.id); | 331 m_sharedBitmaps.remove(resource.id); |
| 329 m_cachedTextureIds.remove(resource.id); | 332 m_cachedTextureIds.remove(resource.id); |
| 330 } | 333 } |
| 331 } | 334 } |
| 332 | 335 |
| 333 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( | 336 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( |
| 334 const sk_sp<SkImage>& image) { | 337 const IntSize imageSize) { |
| 335 if (image && image->width() == m_width && image->height() == m_height) | 338 if (imageSize.width() == m_width && imageSize.height() == m_height) |
| 336 return true; | 339 return true; |
| 337 return false; | 340 return false; |
| 338 } | 341 } |
| 339 | 342 |
| 340 } // namespace blink | 343 } // namespace blink |
| OLD | NEW |