| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/painting/PaintingTasks.h" | 6 #include "sky/engine/core/painting/PaintingTasks.h" |
| 7 | 7 |
| 8 #include "sky/engine/core/dom/Element.h" | 8 #include "sky/engine/core/dom/Element.h" |
| 9 #include "sky/engine/core/painting/PaintingCallback.h" | 9 #include "sky/engine/core/painting/PaintingCallback.h" |
| 10 #include "sky/engine/core/painting/PaintingContext.h" | 10 #include "sky/engine/core/painting/PaintingContext.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 : element(e), callback(c) { } | 22 : element(e), callback(c) { } |
| 23 | 23 |
| 24 RefPtr<Element> element; | 24 RefPtr<Element> element; |
| 25 OwnPtr<PaintingCallback> callback; | 25 OwnPtr<PaintingCallback> callback; |
| 26 | 26 |
| 27 // Used during serviceRequests. | 27 // Used during serviceRequests. |
| 28 RefPtr<PaintingContext> context; | 28 RefPtr<PaintingContext> context; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 struct CommitTask { | 31 struct CommitTask { |
| 32 CommitTask(PassRefPtr<Element> e, PassRefPtr<DisplayList> d) | 32 CommitTask(PassRefPtr<Node> n, PassRefPtr<DisplayList> d) |
| 33 : element(e), displayList(d) { } | 33 : node(n), displayList(d) { } |
| 34 | 34 |
| 35 RefPtr<Element> element; | 35 RefPtr<Node> node; |
| 36 RefPtr<DisplayList> displayList; | 36 RefPtr<DisplayList> displayList; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 static Vector<OwnPtr<RequestTask>>& requests() | 39 static Vector<OwnPtr<RequestTask>>& requests() |
| 40 { | 40 { |
| 41 DEFINE_STATIC_LOCAL(OwnPtr<Vector<OwnPtr<RequestTask>>>, queue, (adoptPtr(ne
w Vector<OwnPtr<RequestTask>>()))); | 41 DEFINE_STATIC_LOCAL(OwnPtr<Vector<OwnPtr<RequestTask>>>, queue, (adoptPtr(ne
w Vector<OwnPtr<RequestTask>>()))); |
| 42 return *queue; | 42 return *queue; |
| 43 } | 43 } |
| 44 | 44 |
| 45 static Vector<CommitTask>& commits() | 45 static Vector<CommitTask>& commits() |
| 46 { | 46 { |
| 47 DEFINE_STATIC_LOCAL(OwnPtr<Vector<CommitTask>>, queue, (adoptPtr(new Vector<
CommitTask>()))); | 47 DEFINE_STATIC_LOCAL(OwnPtr<Vector<CommitTask>>, queue, (adoptPtr(new Vector<
CommitTask>()))); |
| 48 return *queue; | 48 return *queue; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 void PaintingTasks::enqueueRequest(PassRefPtr<Element> element, PassOwnPtr<Paint
ingCallback> callback) | 53 void PaintingTasks::enqueueRequest(PassRefPtr<Element> element, PassOwnPtr<Paint
ingCallback> callback) |
| 54 { | 54 { |
| 55 requests().append(adoptPtr(new RequestTask(element, callback))); | 55 requests().append(adoptPtr(new RequestTask(element, callback))); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void PaintingTasks::enqueueCommit(PassRefPtr<Element> element, PassRefPtr<Displa
yList> displayList) | 58 void PaintingTasks::enqueueCommit(PassRefPtr<Node> node, PassRefPtr<DisplayList>
displayList) |
| 59 { | 59 { |
| 60 commits().append(CommitTask(element, displayList)); | 60 commits().append(CommitTask(node, displayList)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool PaintingTasks::serviceRequests() | 63 bool PaintingTasks::serviceRequests() |
| 64 { | 64 { |
| 65 if (requests().isEmpty()) | 65 if (requests().isEmpty()) |
| 66 return false; | 66 return false; |
| 67 | 67 |
| 68 for (auto& request : requests()) { | 68 for (auto& request : requests()) { |
| 69 RenderObject* renderer = request->element->renderer(); | 69 RenderObject* renderer = request->element->renderer(); |
| 70 if (!renderer || !renderer->isBox()) | 70 if (!renderer || !renderer->isBox()) |
| 71 continue; | 71 continue; |
| 72 request->context = PaintingContext::create(request->element, toRenderBox
(renderer)->size()); | 72 request->context = PaintingContext::create(request->element, toRenderBox
(renderer)->size()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 Vector<OwnPtr<RequestTask>> local; | 75 Vector<OwnPtr<RequestTask>> local; |
| 76 swap(requests(), local); | 76 swap(requests(), local); |
| 77 for (const auto& request : local) { | 77 for (const auto& request : local) { |
| 78 if (!request->context) | 78 if (!request->context) |
| 79 continue; | 79 continue; |
| 80 request->callback->handleEvent(request->context.get()); | 80 request->callback->handleEvent(request->context.get()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void PaintingTasks::drainCommits() | 86 void PaintingTasks::drainCommits() |
| 87 { | 87 { |
| 88 for (auto& commit : commits()) { | 88 for (auto& commit : commits()) { |
| 89 RenderObject* renderer = commit.element->renderer(); | 89 RenderObject* renderer = commit.node->renderer(); |
| 90 if (!renderer || !renderer->isBox()) | 90 if (!renderer || !renderer->isBox()) |
| 91 return; | 91 return; |
| 92 toRenderBox(renderer)->setCustomPainting(commit.displayList.release()); | 92 toRenderBox(renderer)->setCustomPainting(commit.displayList.release()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 commits().clear(); | 95 commits().clear(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |