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

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: 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
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..03e4f29f5d30af0a84acfb56f55694830b4656f2
--- /dev/null
+++ b/sky/engine/core/painting/PaintingTasks.cpp
@@ -0,0 +1,96 @@
+// 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()
+{
+ Vector<OwnPtr<RequestTask>> local;
+ swap(requests(), local);
+
+ for (auto& request : local) {
+ RenderObject* renderer = request->element->renderer();
+ if (!renderer || !renderer->isBox())
+ continue;
+ request->context = PaintingContext::create(request->element, toRenderBox(renderer)->size());
+ }
+
+ for (const auto& request : local)
+ request->callback->handleEvent(request->context.get());
+
+ return !requests().isEmpty();
+}
+
+void PaintingTasks::drainCommits()
+{
+ Vector<CommitTask> local;
+ swap(commits(), local);
+
+ for (auto& commit : local) {
+ RenderObject* renderer = commit.element->renderer();
+ if (!renderer || !renderer->isBox())
+ return;
+ toRenderBox(renderer)->setCustomPainting(commit.displayList.release());
+ }
+
+ ASSERT(commits().isEmpty());
+}
+
+} // namespace blink
« sky/engine/core/page/PageAnimator.cpp ('K') | « sky/engine/core/painting/PaintingTasks.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698