Flutter Engine
The Flutter Engine
SkRecordedDrawable.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
9
12#include "include/core/SkSize.h"
20
21class SkCanvas;
22
24 size_t drawablesSize = 0;
25 if (fDrawableList) {
26 for (auto&& drawable : *fDrawableList) {
27 drawablesSize += drawable->approximateBytesUsed();
28 }
29 }
30 return sizeof(*this) +
31 (fRecord ? fRecord->bytesUsed() : 0) +
32 (fBBH ? fBBH->bytesUsed() : 0) +
33 drawablesSize;
34}
35
37 SkDrawable* const* drawables = nullptr;
38 int drawableCount = 0;
39 if (fDrawableList) {
40 drawables = fDrawableList->begin();
41 drawableCount = fDrawableList->count();
42 }
43 SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, fBBH.get(), nullptr);
44}
45
47 // TODO: should we plumb-down the BBHFactory and recordFlags from our host
48 // PictureRecorder?
49 std::unique_ptr<SkBigPicture::SnapshotArray> pictList{
50 fDrawableList ? fDrawableList->newDrawableSnapshot() : nullptr
51 };
52
53 size_t subPictureBytes = 0;
54 for (int i = 0; pictList && i < pictList->count(); i++) {
55 subPictureBytes += pictList->begin()[i]->approximateBytesUsed();
56 }
57 return sk_make_sp<SkBigPicture>(fBounds, fRecord, std::move(pictList), fBBH, subPictureBytes);
58}
59
61 // Write the bounds.
62 buffer.writeRect(fBounds);
63
64 // Create an SkPictureRecord to record the draw commands.
67
68 // If the query contains the whole picture, don't bother with the bounding box hierarchy.
69 SkBBoxHierarchy* bbh;
70 if (pictureRecord.getLocalClipBounds().contains(fBounds)) {
71 bbh = nullptr;
72 } else {
73 bbh = fBBH.get();
74 }
75
76 // Record the draw commands.
77 SkDrawable* const* drawables = fDrawableList ? fDrawableList->begin() : nullptr;
78 int drawableCount = fDrawableList ? fDrawableList->count() : 0;
79 pictureRecord.beginRecording();
80 SkRecordDraw(*fRecord, &pictureRecord, nullptr, drawables, drawableCount, bbh, nullptr);
81 pictureRecord.endRecording();
82
83 // Flatten the recorded commands and drawables.
84 SkPictureData pictureData(pictureRecord, info);
85 pictureData.flatten(buffer);
86}
87
88sk_sp<SkFlattenable> SkRecordedDrawable::CreateProc(SkReadBuffer& buffer) {
89 // Read the bounds.
91 buffer.readRect(&bounds);
92
93 // Unflatten into a SkPictureData.
95 info.setVersion(buffer.getVersion());
96 info.fCullRect = bounds;
97 std::unique_ptr<SkPictureData> pictureData(SkPictureData::CreateFromBuffer(buffer, info));
98 if (!pictureData) {
99 return nullptr;
100 }
101
102 // Create a drawable.
103 SkPicturePlayback playback(pictureData.get());
105 playback.draw(recorder.beginRecording(bounds), nullptr, &buffer);
106 return recorder.finishRecordingAsDrawable();
107}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const SkRect fBounds
void SkRecordDraw(const SkRecord &record, SkCanvas *canvas, SkPicture const *const drawablePicts[], SkDrawable *const drawables[], int drawableCount, const SkBBoxHierarchy *bbh, SkPicture::AbortCallback *callback)
virtual size_t bytesUsed() const =0
SkRect getLocalClipBounds() const
Definition: SkCanvas.cpp:1586
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
static SkPictureData * CreateFromBuffer(SkReadBuffer &, const SkPictInfo &)
void flatten(SkWriteBuffer &) const
size_t bytesUsed() const
Definition: SkRecord.cpp:25
sk_sp< SkPicture > onMakePictureSnapshot() override
void onDraw(SkCanvas *canvas) override
size_t onApproximateBytesUsed() override
void flatten(SkWriteBuffer &buffer) const override
T * get() const
Definition: SkRefCnt.h:303
Optional< SkRect > bounds
Definition: SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762