Flutter Engine
The Flutter Engine
SkPictureImageFilter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 The Android Open Source Project
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
13#include "include/core/SkRect.h"
22
23#include <optional>
24#include <utility>
25
26namespace {
27
28class SkPictureImageFilter final : public SkImageFilter_Base {
29public:
30 SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cullRect)
31 : SkImageFilter_Base(nullptr, 0)
32 , fPicture(std::move(picture))
33 , fCullRect(cullRect) {
34 // The external cullrect should already have been intersected with the internal cull rect
35 SkASSERT(fPicture && fPicture->cullRect().contains(cullRect));
36 }
37
38 SkRect computeFastBounds(const SkRect&) const override { return SkRect(fCullRect); }
39
40protected:
41 void flatten(SkWriteBuffer&) const override;
42
43private:
45 SK_FLATTENABLE_HOOKS(SkPictureImageFilter)
46
48
49 skif::FilterResult onFilterImage(const skif::Context& ctx) const override;
50
52 const skif::Mapping& mapping,
53 const skif::LayerSpace<SkIRect>& desiredOutput,
54 std::optional<skif::LayerSpace<SkIRect>> contentBounds) const override;
55
56 std::optional<skif::LayerSpace<SkIRect>> onGetOutputLayerBounds(
57 const skif::Mapping& mapping,
58 std::optional<skif::LayerSpace<SkIRect>> contentBounds) const override;
59
60 sk_sp<SkPicture> fPicture;
62};
63
64} // end namespace
65
67 if (pic) {
68 SkRect cullRect = pic->cullRect();
69 if (cullRect.intersect(targetRect)) {
70 return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(pic), cullRect));
71 }
72 }
73 return SkImageFilters::Empty();
74}
75
77 SK_REGISTER_FLATTENABLE(SkPictureImageFilter);
78 // TODO (michaelludwig) - Remove after grace period for SKPs to stop using old name
79 SkFlattenable::Register("SkPictureImageFilterImpl", SkPictureImageFilter::CreateProc);
80}
81
82sk_sp<SkFlattenable> SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
84 if (buffer.readBool()) {
86 }
87
88 SkRect cullRect;
89 buffer.readRect(&cullRect);
90 return SkImageFilters::Picture(std::move(picture), cullRect);
91}
92
93void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
94 buffer.writeBool(SkToBool(fPicture));
95 if (fPicture) {
97 }
98 buffer.writeRect(SkRect(fCullRect));
99}
100
101///////////////////////////////////////////////////////////////////////////////////////////////////
102
103skif::FilterResult SkPictureImageFilter::onFilterImage(const skif::Context& ctx) const {
104 return skif::FilterResult::MakeFromPicture(ctx, fPicture, fCullRect);
105}
106
107skif::LayerSpace<SkIRect> SkPictureImageFilter::onGetInputLayerBounds(
108 const skif::Mapping&,
110 std::optional<skif::LayerSpace<SkIRect>>) const {
111 // This is a leaf filter, it requires no input and no further recursion
113}
114
115std::optional<skif::LayerSpace<SkIRect>> SkPictureImageFilter::onGetOutputLayerBounds(
116 const skif::Mapping& mapping,
117 std::optional<skif::LayerSpace<SkIRect>>) const {
118 // The output is the transformed bounds of the picture.
119 return mapping.paramToLayer(fCullRect).roundOut();
120}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_FLATTENABLE_HOOKS(type)
#define SK_REGISTER_FLATTENABLE(type)
void SkRegisterPictureImageFilterFlattenable()
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
static void Register(const char name[], Factory)
virtual skif::LayerSpace< SkIRect > onGetInputLayerBounds(const skif::Mapping &mapping, const skif::LayerSpace< SkIRect > &desiredOutput, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const =0
void flatten(SkWriteBuffer &) const override
virtual std::optional< skif::LayerSpace< SkIRect > > onGetOutputLayerBounds(const skif::Mapping &mapping, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const =0
virtual skif::FilterResult onFilterImage(const skif::Context &context) const =0
virtual MatrixCapability onGetCTMCapability() const
virtual SkRect computeFastBounds(const SkRect &bounds) const
static sk_sp< SkImageFilter > Empty()
static sk_sp< SkImageFilter > Picture(sk_sp< SkPicture > pic, const SkRect &targetRect)
static void Flatten(const sk_sp< const SkPicture >, SkWriteBuffer &buffer)
Definition: SkPicture.cpp:314
static sk_sp< SkPicture > MakeFromBuffer(SkReadBuffer &buffer)
Definition: SkPicture.cpp:213
virtual SkRect cullRect() const =0
static FilterResult MakeFromPicture(const Context &ctx, sk_sp< SkPicture > pic, ParameterSpace< SkRect > cullRect)
LayerSpace< T > paramToLayer(const ParameterSpace< T > &paramGeometry) const
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
SK_API sk_sp< SkShader > Empty()
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
Definition: ref_ptr.h:256
bool intersect(const SkRect &r)
Definition: SkRect.cpp:114