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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/painting/PaintingTasks.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/painting/PaintingTasks.cpp
diff --git a/sky/engine/core/painting/PaintingTasks.cpp b/sky/engine/core/painting/PaintingTasks.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e266eafc5b20d830a3193efcc59102dcfeed0c60
--- /dev/null
+++ b/sky/engine/core/painting/PaintingTasks.cpp
@@ -0,0 +1,98 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sky/engine/config.h"
+#include "sky/engine/core/painting/PaintingTasks.h"
+
+#include "sky/engine/core/dom/Element.h"
+#include "sky/engine/core/painting/PaintingCallback.h"
+#include "sky/engine/core/painting/PaintingContext.h"
+#include "sky/engine/core/rendering/RenderBox.h"
+#include "sky/engine/platform/graphics/DisplayList.h"
+#include "sky/engine/wtf/OwnPtr.h"
+#include "sky/engine/wtf/RefPtr.h"
+#include "sky/engine/wtf/Vector.h"
+
+namespace blink {
+namespace {
+
+struct RequestTask {
+ RequestTask(PassRefPtr<Element> e, PassOwnPtr<PaintingCallback> c)
+ : element(e), callback(c) { }
+
+ RefPtr<Element> element;
+ OwnPtr<PaintingCallback> callback;
+
+ // Used during serviceRequests.
+ RefPtr<PaintingContext> context;
+};
+
+struct CommitTask {
+ CommitTask(PassRefPtr<Element> e, PassRefPtr<DisplayList> d)
+ : element(e), displayList(d) { }
+
+ RefPtr<Element> element;
+ RefPtr<DisplayList> displayList;
+};
+
+static Vector<OwnPtr<RequestTask>>& requests()
+{
+ DEFINE_STATIC_LOCAL(OwnPtr<Vector<OwnPtr<RequestTask>>>, queue, (adoptPtr(new Vector<OwnPtr<RequestTask>>())));
+ return *queue;
+}
+
+static Vector<CommitTask>& commits()
+{
+ DEFINE_STATIC_LOCAL(OwnPtr<Vector<CommitTask>>, queue, (adoptPtr(new Vector<CommitTask>())));
+ return *queue;
+}
+
+} // namespace
+
+void PaintingTasks::enqueueRequest(PassRefPtr<Element> element, PassOwnPtr<PaintingCallback> callback)
+{
+ requests().append(adoptPtr(new RequestTask(element, callback)));
+}
+
+void PaintingTasks::enqueueCommit(PassRefPtr<Element> element, PassRefPtr<DisplayList> displayList)
+{
+ commits().append(CommitTask(element, displayList));
+}
+
+bool PaintingTasks::serviceRequests()
+{
+ if (requests().isEmpty())
+ return false;
+
+ for (auto& request : requests()) {
+ RenderObject* renderer = request->element->renderer();
+ if (!renderer || !renderer->isBox())
+ continue;
+ request->context = PaintingContext::create(request->element, toRenderBox(renderer)->size());
+ }
+
+ Vector<OwnPtr<RequestTask>> local;
+ swap(requests(), local);
+ for (const auto& request : local) {
+ if (!request->context)
+ continue;
+ request->callback->handleEvent(request->context.get());
+ }
+
+ return true;
+}
+
+void PaintingTasks::drainCommits()
+{
+ for (auto& commit : commits()) {
+ RenderObject* renderer = commit.element->renderer();
+ if (!renderer || !renderer->isBox())
+ return;
+ toRenderBox(renderer)->setCustomPainting(commit.displayList.release());
+ }
+
+ commits().clear();
+}
+
+} // namespace blink
« 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