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

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

Issue 2493673002: Synchronize OffscreenCanvas content with the placeholder canvas (Closed)
Patch Set: fix obsolete test 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/graphics/OffscreenCanvasPlaceholder.h"
6
7 #include "platform/CrossThreadFunctional.h"
8 #include "platform/WebTaskRunner.h"
9 #include "platform/graphics/Image.h"
10 #include "platform/graphics/OffscreenCanvasFrameDispatcher.h"
11 #include "wtf/HashMap.h"
12
13 namespace {
14
15 typedef HashMap<int, blink::OffscreenCanvasPlaceholder*> PlaceholderIdMap;
16
17 PlaceholderIdMap& placeholderRegistry() {
18 DCHECK(isMainThread());
19 DEFINE_STATIC_LOCAL(PlaceholderIdMap, s_placeholderRegistry, ());
20 return s_placeholderRegistry;
21 }
22
23 void releaseFrameToDispatcher(
24 WeakPtr<blink::OffscreenCanvasFrameDispatcher> dispatcher,
25 RefPtr<blink::Image> oldImage,
26 unsigned resourceId) {
27 oldImage = nullptr; // Needed to unref'ed on the right thread
28 if (dispatcher) {
29 dispatcher->reclaimResource(resourceId);
30 }
31 }
32
33 } // unnamed namespace
34
35 namespace blink {
36
37 OffscreenCanvasPlaceholder::~OffscreenCanvasPlaceholder() {
38 unregisterPlaceholder();
39 }
40
41 OffscreenCanvasPlaceholder* OffscreenCanvasPlaceholder::getPlaceholderById(
42 unsigned placeholderId) {
43 PlaceholderIdMap::iterator it = placeholderRegistry().find(placeholderId);
44 if (it == placeholderRegistry().end())
45 return nullptr;
46 return it->value;
47 }
48
49 void OffscreenCanvasPlaceholder::registerPlaceholder(unsigned placeholderId) {
50 DCHECK(!placeholderRegistry().contains(placeholderId));
51 DCHECK(!isPlaceholderRegistered());
52 placeholderRegistry().add(placeholderId, this);
53 m_placeholderId = placeholderId;
54 }
55
56 void OffscreenCanvasPlaceholder::unregisterPlaceholder() {
57 if (!isPlaceholderRegistered())
58 return;
59 DCHECK(placeholderRegistry().find(m_placeholderId)->value == this);
60 placeholderRegistry().remove(m_placeholderId);
61 m_placeholderId = kNoPlaceholderId;
62 }
63
64 void OffscreenCanvasPlaceholder::setPlaceholderFrame(
65 RefPtr<Image> newFrame,
66 WeakPtr<OffscreenCanvasFrameDispatcher> dispatcher,
67 std::unique_ptr<WebTaskRunner> taskRunner,
68 unsigned resourceId) {
69 DCHECK(isPlaceholderRegistered());
70 releasePlaceholderFrame();
71 m_placeholderFrame = std::move(newFrame);
72 m_frameDispatcher = std::move(dispatcher);
73 m_frameDispatcherTaskRunner = std::move(taskRunner);
74 m_placeholderFrameResourceId = resourceId;
75 }
76
77 void OffscreenCanvasPlaceholder::releasePlaceholderFrame() {
78 DCHECK(isPlaceholderRegistered());
79 if (m_placeholderFrame) {
80 m_placeholderFrame->transfer();
81 m_frameDispatcherTaskRunner->postTask(
82 BLINK_FROM_HERE,
83 crossThreadBind(releaseFrameToDispatcher, std::move(m_frameDispatcher),
84 std::move(m_placeholderFrame),
85 m_placeholderFrameResourceId));
86 }
87 }
88
89 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698