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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 resource.is_software = false; | 162 resource.is_software = false; |
163 | 163 |
164 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. | 164 // Hold ref to |image|, to keep it alive until the browser ReclaimResources. |
165 // It guarantees that the resource is not re-used or deleted. | 165 // It guarantees that the resource is not re-used or deleted. |
166 m_cachedImages.add(m_nextResourceId, std::move(image)); | 166 m_cachedImages.add(m_nextResourceId, std::move(image)); |
167 } | 167 } |
168 | 168 |
169 namespace { | 169 namespace { |
170 | 170 |
171 void updatePlaceholderImage(WeakPtr<OffscreenCanvasFrameDispatcher> dispatcher, | 171 void updatePlaceholderImage(WeakPtr<OffscreenCanvasFrameDispatcher> dispatcher, |
172 std::unique_ptr<WebTaskRunner> taskRunner, | 172 RefPtr<WebTaskRunner> taskRunner, |
173 int placeholderCanvasId, | 173 int placeholderCanvasId, |
174 RefPtr<blink::StaticBitmapImage> image, | 174 RefPtr<blink::StaticBitmapImage> image, |
175 unsigned resourceId) { | 175 unsigned resourceId) { |
176 DCHECK(isMainThread()); | 176 DCHECK(isMainThread()); |
177 OffscreenCanvasPlaceholder* placeholderCanvas = | 177 OffscreenCanvasPlaceholder* placeholderCanvas = |
178 OffscreenCanvasPlaceholder::getPlaceholderById(placeholderCanvasId); | 178 OffscreenCanvasPlaceholder::getPlaceholderById(placeholderCanvasId); |
179 if (placeholderCanvas) { | 179 if (placeholderCanvas) { |
180 placeholderCanvas->setPlaceholderFrame(std::move(image), | 180 placeholderCanvas->setPlaceholderFrame(std::move(image), |
181 std::move(dispatcher), | 181 std::move(dispatcher), |
182 std::move(taskRunner), resourceId); | 182 std::move(taskRunner), resourceId); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } else { | 246 } else { |
247 // Case 4: both canvas and compositor are not gpu accelerated. | 247 // Case 4: both canvas and compositor are not gpu accelerated. |
248 commitType = CommitSoftwareCanvasSoftwareCompositing; | 248 commitType = CommitSoftwareCanvasSoftwareCompositing; |
249 setTransferableResourceToSharedBitmap(resource, image); | 249 setTransferableResourceToSharedBitmap(resource, image); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 // After this point, |image| can only be used on the main thread, until | 253 // After this point, |image| can only be used on the main thread, until |
254 // it is returned. | 254 // it is returned. |
255 image->transfer(); | 255 image->transfer(); |
256 std::unique_ptr<WebTaskRunner> dispatcherTaskRunner = | 256 RefPtr<WebTaskRunner> dispatcherTaskRunner = |
257 Platform::current()->currentThread()->getWebTaskRunner()->clone(); | 257 Platform::current()->currentThread()->getWebTaskRunner(); |
258 | 258 |
259 Platform::current()->mainThread()->getWebTaskRunner()->postTask( | 259 Platform::current()->mainThread()->getWebTaskRunner()->postTask( |
260 BLINK_FROM_HERE, | 260 BLINK_FROM_HERE, |
261 crossThreadBind(updatePlaceholderImage, this->createWeakPtr(), | 261 crossThreadBind(updatePlaceholderImage, this->createWeakPtr(), |
262 WTF::passed(std::move(dispatcherTaskRunner)), | 262 WTF::passed(std::move(dispatcherTaskRunner)), |
263 m_placeholderCanvasId, std::move(image), resource.id)); | 263 m_placeholderCanvasId, std::move(image), resource.id)); |
264 m_spareResourceLocks.add(m_nextResourceId); | 264 m_spareResourceLocks.add(m_nextResourceId); |
265 | 265 |
266 commitTypeHistogram.count(commitType); | 266 commitTypeHistogram.count(commitType); |
267 | 267 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 451 |
452 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) { | 452 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) { |
453 if (m_width != width || m_height != height) { | 453 if (m_width != width || m_height != height) { |
454 m_width = width; | 454 m_width = width; |
455 m_height = height; | 455 m_height = height; |
456 m_changeSizeForNextCommit = true; | 456 m_changeSizeForNextCommit = true; |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 } // namespace blink | 460 } // namespace blink |
OLD | NEW |