| OLD | NEW |
| (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 |
| OLD | NEW |