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

Side by Side 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, 8 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 unified diff | Download patch
« no previous file with comments | « skia/ext/SkFutureDrawable.h ('k') | skia/ext/skia_utils_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "skia/ext/SkFutureDrawable.h"
9
10 #include "base/logging.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/core/SkPictureRecorder.h"
13 #include "third_party/skia/include/core/SkScalar.h"
14 #include "third_party/skia/include/core/SkWriteBuffer.h"
15 #include "third_party/skia/src/core/SkReadBuffer.h"
16
17 const char SkFutureDrawable::kTypeName[] = "SkFutureDrawable";
18
19 std::unordered_map<int, std::unique_ptr<SkDrawable>>
20 SkFutureDrawable::fDrawableRefMap = {};
21
22 void SkFutureDrawable::flatten(SkWriteBuffer& buffer) const {
23 // Write the bounds.
24 buffer.writeRect(fBounds);
25 // Write the unique id.
26 buffer.writeInt(id);
27 }
28
29 // static
30 sk_sp<SkFlattenable> SkFutureDrawable::CreateProc(SkReadBuffer& buffer) {
31 // Read the bounds.
32 SkRect bounds;
33 buffer.readRect(&bounds);
34
35 // Read the unique id.
36 int id = buffer.readInt();
37 sk_sp<SkFutureDrawable> drawable = sk_make_sp<SkFutureDrawable>(bounds, id);
38
39 // Check whether the drawable reference is there
40 const auto ptr = fDrawableRefMap.find(id);
41 if (ptr != fDrawableRefMap.end())
42 drawable->setDrawableRef(ptr->second.get());
43
44 return drawable;
45 }
46
47 void SkFutureDrawable::onDraw(SkCanvas* canvas) {
48 if (!fDrawableRef)
49 return;
50 fDrawableRef->draw(canvas);
51 }
52
53 SkPicture* SkFutureDrawable::onNewPictureSnapshot() {
54 SkPictureRecorder recorder;
55
56 SkCanvas* canvas = recorder.beginRecording(fBounds, nullptr, 0);
57 canvas->translate(fBounds.x(), fBounds.y());
58 draw(canvas);
59 return recorder.finishRecordingAsPicture().release();
60 }
OLDNEW
« 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