| 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/CrossThreadFunctional.h" | 10 #include "platform/CrossThreadFunctional.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // TODO(ccameron): Canvas should produce sRGB images. | 78 // TODO(ccameron): Canvas should produce sRGB images. |
| 79 // https://crbug.com/672299 | 79 // https://crbug.com/672299 |
| 80 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) | 80 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
| 81 ->readPixels(imageInfo, pixels, imageInfo.minRowBytes(), 0, 0); | 81 ->readPixels(imageInfo, pixels, imageInfo.minRowBytes(), 0, 0); |
| 82 resource.mailbox_holder.mailbox = bitmap->id(); | 82 resource.mailbox_holder.mailbox = bitmap->id(); |
| 83 resource.mailbox_holder.texture_target = 0; | 83 resource.mailbox_holder.texture_target = 0; |
| 84 resource.is_software = true; | 84 resource.is_software = true; |
| 85 | 85 |
| 86 // Hold ref to |bitmap|, to keep it alive until the browser ReclaimResources. | 86 // Hold ref to |bitmap|, to keep it alive until the browser ReclaimResources. |
| 87 // It guarantees that the shared bitmap is not re-used or deleted. | 87 // It guarantees that the shared bitmap is not re-used or deleted. |
| 88 m_sharedBitmaps.add(m_nextResourceId, std::move(bitmap)); | 88 m_sharedBitmaps.insert(m_nextResourceId, std::move(bitmap)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void OffscreenCanvasFrameDispatcherImpl:: | 91 void OffscreenCanvasFrameDispatcherImpl:: |
| 92 setTransferableResourceToSharedGPUContext( | 92 setTransferableResourceToSharedGPUContext( |
| 93 cc::TransferableResource& resource, | 93 cc::TransferableResource& resource, |
| 94 RefPtr<StaticBitmapImage> image) { | 94 RefPtr<StaticBitmapImage> image) { |
| 95 // TODO(crbug.com/652707): When committing the first frame, there is no | 95 // TODO(crbug.com/652707): When committing the first frame, there is no |
| 96 // instance of SharedGpuContext yet, calling SharedGpuContext::gl() will | 96 // instance of SharedGpuContext yet, calling SharedGpuContext::gl() will |
| 97 // trigger a creation of an instace, which requires to create a | 97 // trigger a creation of an instace, which requires to create a |
| 98 // WebGraphicsContext3DProvider. This process is quite expensive, because | 98 // WebGraphicsContext3DProvider. This process is quite expensive, because |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 gpu::SyncToken syncToken; | 139 gpu::SyncToken syncToken; |
| 140 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); | 140 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken.GetData()); |
| 141 | 141 |
| 142 resource.mailbox_holder = | 142 resource.mailbox_holder = |
| 143 gpu::MailboxHolder(mailbox, syncToken, GL_TEXTURE_2D); | 143 gpu::MailboxHolder(mailbox, syncToken, GL_TEXTURE_2D); |
| 144 resource.read_lock_fences_enabled = false; | 144 resource.read_lock_fences_enabled = false; |
| 145 resource.is_software = false; | 145 resource.is_software = false; |
| 146 | 146 |
| 147 // Hold ref to |textureId| for the piece of GPU memory where the pixel data | 147 // Hold ref to |textureId| for the piece of GPU memory where the pixel data |
| 148 // is uploaded to, to keep it alive until the browser ReclaimResources. | 148 // is uploaded to, to keep it alive until the browser ReclaimResources. |
| 149 m_cachedTextureIds.add(m_nextResourceId, textureId); | 149 m_cachedTextureIds.insert(m_nextResourceId, textureId); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void OffscreenCanvasFrameDispatcherImpl:: | 152 void OffscreenCanvasFrameDispatcherImpl:: |
| 153 setTransferableResourceToStaticBitmapImage( | 153 setTransferableResourceToStaticBitmapImage( |
| 154 cc::TransferableResource& resource, | 154 cc::TransferableResource& resource, |
| 155 RefPtr<StaticBitmapImage> image) { | 155 RefPtr<StaticBitmapImage> image) { |
| 156 image->ensureMailbox(); | 156 image->ensureMailbox(); |
| 157 resource.mailbox_holder = | 157 resource.mailbox_holder = |
| 158 gpu::MailboxHolder(image->mailbox(), image->syncToken(), GL_TEXTURE_2D); | 158 gpu::MailboxHolder(image->mailbox(), image->syncToken(), GL_TEXTURE_2D); |
| 159 resource.read_lock_fences_enabled = false; | 159 resource.read_lock_fences_enabled = false; |
| 160 resource.is_software = false; | 160 resource.is_software = false; |
| 161 | 161 |
| 162 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. | 162 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. |
| 163 // It guarantees that the resource is not re-used or deleted. | 163 // It guarantees that the resource is not re-used or deleted. |
| 164 m_cachedImages.add(m_nextResourceId, std::move(image)); | 164 m_cachedImages.insert(m_nextResourceId, std::move(image)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 namespace { | 167 namespace { |
| 168 | 168 |
| 169 void updatePlaceholderImage(WeakPtr<OffscreenCanvasFrameDispatcher> dispatcher, | 169 void updatePlaceholderImage(WeakPtr<OffscreenCanvasFrameDispatcher> dispatcher, |
| 170 RefPtr<WebTaskRunner> taskRunner, | 170 RefPtr<WebTaskRunner> taskRunner, |
| 171 int placeholderCanvasId, | 171 int placeholderCanvasId, |
| 172 RefPtr<blink::StaticBitmapImage> image, | 172 RefPtr<blink::StaticBitmapImage> image, |
| 173 unsigned resourceId) { | 173 unsigned resourceId) { |
| 174 DCHECK(isMainThread()); | 174 DCHECK(isMainThread()); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) { | 440 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) { |
| 441 if (m_width != width || m_height != height) { | 441 if (m_width != width || m_height != height) { |
| 442 m_width = width; | 442 m_width = width; |
| 443 m_height = height; | 443 m_height = height; |
| 444 m_changeSizeForNextCommit = true; | 444 m_changeSizeForNextCommit = true; |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |