Flutter Engine
The Flutter Engine
SpecialImage_Graphite.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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
17
18namespace skgpu::graphite {
19
20class SpecialImage final : public SkSpecialImage {
21public:
24 , fImage(std::move(image)) {
26 }
27
28 size_t getSize() const override {
29 return fImage->textureSize();
30 }
31
32 bool isGraphiteBacked() const override { return true; }
33
35 return fImage->dimensions();
36 }
37
39 SkASSERT(fImage->bounds().contains(subset));
40 return sk_make_sp<skgpu::graphite::SpecialImage>(subset, fImage, this->props());
41 }
42
43 sk_sp<SkImage> asImage() const override { return fImage; }
44
45private:
46 // TODO(b/299474380): SkSpecialImage is intended to go away in favor of just using SkImages
47 // and tracking the intended srcRect explicitly in skif::FilterResult. Since Graphite tracks
48 // device-linked textures via Images, the graphite special image just wraps an image.
49 sk_sp<SkImage> fImage;
50};
51
52} // namespace skgpu::graphite
53
54namespace SkSpecialImages {
55
57 const SkIRect& subset,
59 const SkSurfaceProps& props) {
60 // 'recorder' can be null if we're wrapping a graphite-backed image since there's no work that
61 // needs to be added. This can happen when snapping a special image from a Device that's been
62 // marked as immutable and abandoned its recorder.
63 if (!image || subset.isEmpty()) {
64 return nullptr;
65 }
66
67 SkASSERT(image->bounds().contains(subset));
68
69 // Use the Recorder's client ImageProvider to convert to a graphite-backed image when
70 // possible, but this does not necessarily mean the provider will produce a valid image.
71 if (!as_IB(image)->isGraphiteBacked()) {
72 if (!recorder) {
73 return nullptr;
74 }
75 auto [graphiteImage, _] =
77 if (!graphiteImage) {
78 return nullptr;
79 }
80
81 image = graphiteImage;
82 }
83
84 return sk_make_sp<skgpu::graphite::SpecialImage>(subset, std::move(image), props);
85}
86
87} // namespace SkSpecialImages
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
SkISize dimensions() const
Definition: SkImage.h:297
virtual size_t textureSize() const =0
SkIRect bounds() const
Definition: SkImage.h:303
uint32_t uniqueID() const
const SkIRect & subset() const
const SkSurfaceProps & props() const
const SkColorInfo & colorInfo() const
T * get() const
Definition: SkRefCnt.h:303
sk_sp< SkImage > asImage() const override
SkISize backingStoreDimensions() const override
bool isGraphiteBacked() const override
SpecialImage(const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
sk_sp< SkSpecialImage > onMakeBackingStoreSubset(const SkIRect &subset) const override
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkSpecialImage > MakeGraphite(skgpu::graphite::Recorder *recorder, const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
std::pair< sk_sp< SkImage >, SkSamplingOptions > GetGraphiteBacked(Recorder *recorder, const SkImage *imageIn, SkSamplingOptions sampling)
Definition: ref_ptr.h:256
Definition: SkRect.h:32
bool isEmpty() const
Definition: SkRect.h:202
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
Definition: SkSize.h:16