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

Side by Side Diff: sky/engine/core/painting/PaintingTasks.cpp

Issue 1027563002: Integrate custom paint with the DocumentLifecycle (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nits Created 5 years, 9 months 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
« no previous file with comments | « sky/engine/core/painting/PaintingTasks.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "sky/engine/config.h"
6 #include "sky/engine/core/painting/PaintingTasks.h"
7
8 #include "sky/engine/core/dom/Element.h"
9 #include "sky/engine/core/painting/PaintingCallback.h"
10 #include "sky/engine/core/painting/PaintingContext.h"
11 #include "sky/engine/core/rendering/RenderBox.h"
12 #include "sky/engine/platform/graphics/DisplayList.h"
13 #include "sky/engine/wtf/OwnPtr.h"
14 #include "sky/engine/wtf/RefPtr.h"
15 #include "sky/engine/wtf/Vector.h"
16
17 namespace blink {
18 namespace {
19
20 struct RequestTask {
21 RequestTask(PassRefPtr<Element> e, PassOwnPtr<PaintingCallback> c)
22 : element(e), callback(c) { }
23
24 RefPtr<Element> element;
25 OwnPtr<PaintingCallback> callback;
26
27 // Used during serviceRequests.
28 RefPtr<PaintingContext> context;
29 };
30
31 struct CommitTask {
32 CommitTask(PassRefPtr<Element> e, PassRefPtr<DisplayList> d)
33 : element(e), displayList(d) { }
34
35 RefPtr<Element> element;
36 RefPtr<DisplayList> displayList;
37 };
38
39 static Vector<OwnPtr<RequestTask>>& requests()
40 {
41 DEFINE_STATIC_LOCAL(OwnPtr<Vector<OwnPtr<RequestTask>>>, queue, (adoptPtr(ne w Vector<OwnPtr<RequestTask>>())));
42 return *queue;
43 }
44
45 static Vector<CommitTask>& commits()
46 {
47 DEFINE_STATIC_LOCAL(OwnPtr<Vector<CommitTask>>, queue, (adoptPtr(new Vector< CommitTask>())));
48 return *queue;
49 }
50
51 } // namespace
52
53 void PaintingTasks::enqueueRequest(PassRefPtr<Element> element, PassOwnPtr<Paint ingCallback> callback)
54 {
55 requests().append(adoptPtr(new RequestTask(element, callback)));
56 }
57
58 void PaintingTasks::enqueueCommit(PassRefPtr<Element> element, PassRefPtr<Displa yList> displayList)
59 {
60 commits().append(CommitTask(element, displayList));
61 }
62
63 bool PaintingTasks::serviceRequests()
64 {
65 if (requests().isEmpty())
66 return false;
67
68 for (auto& request : requests()) {
69 RenderObject* renderer = request->element->renderer();
70 if (!renderer || !renderer->isBox())
71 continue;
72 request->context = PaintingContext::create(request->element, toRenderBox (renderer)->size());
73 }
74
75 Vector<OwnPtr<RequestTask>> local;
76 swap(requests(), local);
77 for (const auto& request : local) {
78 if (!request->context)
79 continue;
80 request->callback->handleEvent(request->context.get());
81 }
82
83 return true;
84 }
85
86 void PaintingTasks::drainCommits()
87 {
88 for (auto& commit : commits()) {
89 RenderObject* renderer = commit.element->renderer();
90 if (!renderer || !renderer->isBox())
91 return;
92 toRenderBox(renderer)->setCustomPainting(commit.displayList.release());
93 }
94
95 commits().clear();
96 }
97
98 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/painting/PaintingTasks.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698