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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); | 61 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); |
62 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456. | 62 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456. |
63 // However, in the case when |image| is texture backed, this function call | 63 // However, in the case when |image| is texture backed, this function call |
64 // does a GPU readback which is required. | 64 // does a GPU readback which is required. |
65 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, | 65 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, |
66 imageInfo.minRowBytes(), 0, 0); | 66 imageInfo.minRowBytes(), 0, 0); |
67 resource.mailbox_holder.mailbox = bitmap->id(); | 67 resource.mailbox_holder.mailbox = bitmap->id(); |
68 resource.mailbox_holder.texture_target = 0; | 68 resource.mailbox_holder.texture_target = 0; |
69 resource.is_software = true; | 69 resource.is_software = true; |
70 | 70 |
71 // Hold ref to |bitmap|, to keep it alive until the browser ReturnResources. | 71 // Hold ref to |bitmap|, to keep it alive until the browser ReclaimResources. |
72 // It guarantees that the shared bitmap is not re-used or deleted. | 72 // It guarantees that the shared bitmap is not re-used or deleted. |
73 m_sharedBitmaps.add(m_nextResourceId, std::move(bitmap)); | 73 m_sharedBitmaps.add(m_nextResourceId, std::move(bitmap)); |
74 } | 74 } |
75 | 75 |
76 void OffscreenCanvasFrameDispatcherImpl:: | 76 void OffscreenCanvasFrameDispatcherImpl:: |
77 setTransferableResourceToSharedGPUContext( | 77 setTransferableResourceToSharedGPUContext( |
78 cc::TransferableResource& resource, | 78 cc::TransferableResource& resource, |
79 RefPtr<StaticBitmapImage> image) { | 79 RefPtr<StaticBitmapImage> image) { |
80 // TODO(crbug.com/652707): When committing the first frame, there is no | 80 // TODO(crbug.com/652707): When committing the first frame, there is no |
81 // instance of SharedGpuContext yet, calling SharedGpuContext::gl() will | 81 // instance of SharedGpuContext yet, calling SharedGpuContext::gl() will |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 gl->ShallowFlushCHROMIUM(); | 119 gl->ShallowFlushCHROMIUM(); |
120 gpu::SyncToken syncToken; | 120 gpu::SyncToken syncToken; |
121 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); | 121 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); |
122 | 122 |
123 resource.mailbox_holder = | 123 resource.mailbox_holder = |
124 gpu::MailboxHolder(mailbox, syncToken, GL_TEXTURE_2D); | 124 gpu::MailboxHolder(mailbox, syncToken, GL_TEXTURE_2D); |
125 resource.read_lock_fences_enabled = false; | 125 resource.read_lock_fences_enabled = false; |
126 resource.is_software = false; | 126 resource.is_software = false; |
127 | 127 |
128 // Hold ref to |textureId| for the piece of GPU memory where the pixel data | 128 // Hold ref to |textureId| for the piece of GPU memory where the pixel data |
129 // is uploaded to, to keep it alive until the browser ReturnResources. | 129 // is uploaded to, to keep it alive until the browser ReclaimResources. |
130 m_cachedTextureIds.add(m_nextResourceId, textureId); | 130 m_cachedTextureIds.add(m_nextResourceId, textureId); |
131 } | 131 } |
132 | 132 |
133 void OffscreenCanvasFrameDispatcherImpl:: | 133 void OffscreenCanvasFrameDispatcherImpl:: |
134 setTransferableResourceToStaticBitmapImage( | 134 setTransferableResourceToStaticBitmapImage( |
135 cc::TransferableResource& resource, | 135 cc::TransferableResource& resource, |
136 RefPtr<StaticBitmapImage> image) { | 136 RefPtr<StaticBitmapImage> image) { |
137 image->ensureMailbox(); | 137 image->ensureMailbox(); |
138 resource.mailbox_holder = gpu::MailboxHolder( | 138 resource.mailbox_holder = gpu::MailboxHolder( |
139 image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D); | 139 image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D); |
140 resource.read_lock_fences_enabled = false; | 140 resource.read_lock_fences_enabled = false; |
141 resource.is_software = false; | 141 resource.is_software = false; |
142 | 142 |
143 // Hold ref to |image|, to keep it alive until the browser ReturnResources. | 143 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. |
144 // It guarantees that the resource is not re-used or deleted. | 144 // It guarantees that the resource is not re-used or deleted. |
145 m_cachedImages.add(m_nextResourceId, std::move(image)); | 145 m_cachedImages.add(m_nextResourceId, std::move(image)); |
146 } | 146 } |
147 | 147 |
148 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( | 148 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( |
149 RefPtr<StaticBitmapImage> image, | 149 RefPtr<StaticBitmapImage> image, |
150 double commitStartTime, | 150 double commitStartTime, |
151 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is | 151 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is |
152 called on SwiftShader. */) { | 152 called on SwiftShader. */) { |
153 if (!image) | 153 if (!image) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 "SoftwareCanvasSoftwareCompositingWorker", | 304 "SoftwareCanvasSoftwareCompositingWorker", |
305 0, 10000000, 50)); | 305 0, 10000000, 50)); |
306 commitSoftwareCanvasSoftwareCompositingWorkerTimer.count(elapsedTime * | 306 commitSoftwareCanvasSoftwareCompositingWorkerTimer.count(elapsedTime * |
307 1000000.0); | 307 1000000.0); |
308 } | 308 } |
309 break; | 309 break; |
310 case OffscreenCanvasCommitTypeCount: | 310 case OffscreenCanvasCommitTypeCount: |
311 NOTREACHED(); | 311 NOTREACHED(); |
312 } | 312 } |
313 | 313 |
314 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); | 314 m_sink->SubmitCompositorFrame(std::move(frame)); |
315 } | 315 } |
316 | 316 |
317 void OffscreenCanvasFrameDispatcherImpl::ReturnResources( | 317 void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck() { |
| 318 // TODO(fsamuel): Implement this. |
| 319 } |
| 320 |
| 321 void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( |
318 const cc::ReturnedResourceArray& resources) { | 322 const cc::ReturnedResourceArray& resources) { |
319 for (const auto& resource : resources) { | 323 for (const auto& resource : resources) { |
320 m_cachedImages.remove(resource.id); | 324 m_cachedImages.remove(resource.id); |
321 m_sharedBitmaps.remove(resource.id); | 325 m_sharedBitmaps.remove(resource.id); |
322 m_cachedTextureIds.remove(resource.id); | 326 m_cachedTextureIds.remove(resource.id); |
323 } | 327 } |
324 } | 328 } |
325 | 329 |
326 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( | 330 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( |
327 const sk_sp<SkImage>& image) { | 331 const sk_sp<SkImage>& image) { |
328 if (image && image->width() == m_width && image->height() == m_height) | 332 if (image && image->width() == m_width && image->height() == m_height) |
329 return true; | 333 return true; |
330 return false; | 334 return false; |
331 } | 335 } |
332 | 336 |
333 } // namespace blink | 337 } // namespace blink |
OLD | NEW |