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

Unified Diff: skia/ext/SkFutureDrawable.cc

Issue 2653963002: [Experimental] Supporting OOPIF printing
Patch Set: Rename service, fix for webview, and connect to DiscardableMemoryManager Created 3 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 | « skia/ext/SkFutureDrawable.h ('k') | skia/ext/skia_utils_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/SkFutureDrawable.cc
diff --git a/skia/ext/SkFutureDrawable.cc b/skia/ext/SkFutureDrawable.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f42107d96401d7667e24890c6de77491d16a00d8
--- /dev/null
+++ b/skia/ext/SkFutureDrawable.cc
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "skia/ext/SkFutureDrawable.h"
+
+#include "base/logging.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkPictureRecorder.h"
+#include "third_party/skia/include/core/SkScalar.h"
+#include "third_party/skia/include/core/SkWriteBuffer.h"
+#include "third_party/skia/src/core/SkReadBuffer.h"
+
+const char SkFutureDrawable::kTypeName[] = "SkFutureDrawable";
+
+std::unordered_map<int, std::unique_ptr<SkDrawable>>
+ SkFutureDrawable::fDrawableRefMap = {};
+
+void SkFutureDrawable::flatten(SkWriteBuffer& buffer) const {
+ // Write the bounds.
+ buffer.writeRect(fBounds);
+ // Write the unique id.
+ buffer.writeInt(id);
+}
+
+// static
+sk_sp<SkFlattenable> SkFutureDrawable::CreateProc(SkReadBuffer& buffer) {
+ // Read the bounds.
+ SkRect bounds;
+ buffer.readRect(&bounds);
+
+ // Read the unique id.
+ int id = buffer.readInt();
+ sk_sp<SkFutureDrawable> drawable = sk_make_sp<SkFutureDrawable>(bounds, id);
+
+ // Check whether the drawable reference is there
+ const auto ptr = fDrawableRefMap.find(id);
+ if (ptr != fDrawableRefMap.end())
+ drawable->setDrawableRef(ptr->second.get());
+
+ return drawable;
+}
+
+void SkFutureDrawable::onDraw(SkCanvas* canvas) {
+ if (!fDrawableRef)
+ return;
+ fDrawableRef->draw(canvas);
+}
+
+SkPicture* SkFutureDrawable::onNewPictureSnapshot() {
+ SkPictureRecorder recorder;
+
+ SkCanvas* canvas = recorder.beginRecording(fBounds, nullptr, 0);
+ canvas->translate(fBounds.x(), fBounds.y());
+ draw(canvas);
+ return recorder.finishRecordingAsPicture().release();
+}
« no previous file with comments | « skia/ext/SkFutureDrawable.h ('k') | skia/ext/skia_utils_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698