Flutter Engine
The Flutter Engine
Functions
SkSpecialImages Namespace Reference

Functions

sk_sp< SkSpecialImageMakeFromRaster (const SkIRect &subset, const SkBitmap &bm, const SkSurfaceProps &props)
 
sk_sp< SkSpecialImageCopyFromRaster (const SkIRect &subset, const SkBitmap &bm, const SkSurfaceProps &props)
 
sk_sp< SkSpecialImageMakeFromRaster (const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
 
bool AsBitmap (const SkSpecialImage *img, SkBitmap *result)
 
sk_sp< SkSpecialImageMakeFromTextureImage (GrRecordingContext *rContext, const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
 
sk_sp< SkSpecialImageMakeDeferredFromGpu (GrRecordingContext *context, const SkIRect &subset, uint32_t uniqueID, GrSurfaceProxyView view, const GrColorInfo &colorInfo, const SkSurfaceProps &props)
 
GrSurfaceProxyView AsView (GrRecordingContext *context, const SkSpecialImage *img)
 
GrSurfaceProxyView AsView (GrRecordingContext *rContext, const sk_sp< const SkSpecialImage > &img)
 
sk_sp< SkSpecialImageMakeGraphite (skgpu::graphite::Recorder *recorder, const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
 

Function Documentation

◆ AsBitmap()

bool SkSpecialImages::AsBitmap ( const SkSpecialImage img,
SkBitmap result 
)

Definition at line 198 of file SkSpecialImage.cpp.

198 {
199 if (!img || img->isGaneshBacked() || img->isGraphiteBacked()) {
200 return false;
201 }
202 auto rasterImg = static_cast<const SkSpecialImage_Raster*>(img);
203 return rasterImg->getROPixels(result);
204}
bool getROPixels(SkBitmap *bm) const
virtual bool isGaneshBacked() const
virtual bool isGraphiteBacked() const
GAsyncResult * result

◆ AsView() [1/2]

GrSurfaceProxyView SkSpecialImages::AsView ( GrRecordingContext ,
const SkSpecialImage  
)

Regardless of how the underlying backing data is stored, returns the contents as a GrSurfaceProxyView. The returned view's proxy represents the entire backing image, so texture coordinates must be mapped from the content rect (e.g. relative to 'subset()') to the proxy's space (offset by subset().topLeft()).

Definition at line 115 of file SkSpecialImage_Ganesh.cpp.

115 {
116 if (!context || !img || !img->isGaneshBacked()) {
117 return {};
118 }
119 auto grImg = static_cast<const SkSpecialImage_Gpu*>(img);
120 return grImg->view(context);
121}
GrSurfaceProxyView view(GrRecordingContext *) const

◆ AsView() [2/2]

GrSurfaceProxyView SkSpecialImages::AsView ( GrRecordingContext rContext,
const sk_sp< const SkSpecialImage > &  img 
)
inline

Definition at line 44 of file SkSpecialImage_Ganesh.h.

45 {
46 return AsView(rContext, img.get());
47}
T * get() const
Definition: SkRefCnt.h:303
GrSurfaceProxyView AsView(GrRecordingContext *rContext, const sk_sp< const SkSpecialImage > &img)

◆ CopyFromRaster()

sk_sp< SkSpecialImage > SkSpecialImages::CopyFromRaster ( const SkIRect subset,
const SkBitmap bm,
const SkSurfaceProps props 
)

Definition at line 151 of file SkSpecialImage.cpp.

153 {
154 SkASSERT(bm.bounds().contains(subset));
155
156 if (!bm.pixelRef()) {
157 return nullptr;
158 }
159
160 SkBitmap tmp;
161 SkImageInfo info = bm.info().makeDimensions(subset.size());
162 // As in MakeFromRaster, must force src to N32 for ImageFilters
163 if (!valid_for_imagefilters(bm.info())) {
164 info = info.makeColorType(kN32_SkColorType);
165 }
166 if (!tmp.tryAllocPixels(info)) {
167 return nullptr;
168 }
169 if (!bm.readPixels(tmp.info(), tmp.getPixels(), tmp.rowBytes(), subset.x(), subset.y())) {
170 return nullptr;
171 }
172
173 // Since we're making a copy of the raster, the resulting special image is the exact size
174 // of the requested subset of the original and no longer needs to be offset by subset's left
175 // and top, since those were relative to the original's buffer.
176 return sk_make_sp<SkSpecialImage_Raster>(
177 SkIRect::MakeWH(subset.width(), subset.height()), tmp, props);
178}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool valid_for_imagefilters(const SkImageInfo &info)
SkPixelRef * pixelRef() const
Definition: SkBitmap.h:720
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
const SkImageInfo & info() const
Definition: SkBitmap.h:139
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition: SkBitmap.cpp:488
SkIRect bounds() const
Definition: SkBitmap.h:382
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
constexpr SkISize size() const
Definition: SkRect.h:172
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454

◆ MakeDeferredFromGpu()

sk_sp< SkSpecialImage > SkSpecialImages::MakeDeferredFromGpu ( GrRecordingContext context,
const SkIRect subset,
uint32_t  uniqueID,
GrSurfaceProxyView  view,
const GrColorInfo colorInfo,
const SkSurfaceProps props 
)

Definition at line 93 of file SkSpecialImage_Ganesh.cpp.

98 {
99 if (!context || context->abandoned() || !view.asTextureProxy()) {
100 return nullptr;
101 }
102
104
106 return sk_make_sp<SkSpecialImage_Gpu>(
107 context,
108 subset,
109 uniqueID,
110 std::move(view),
111 SkColorInfo(ct, colorInfo.alphaType(), colorInfo.refColorSpace()),
112 props);
113}
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:589
SkColorType
Definition: SkColorType.h:19
sk_sp< SkColorSpace > refColorSpace() const
Definition: GrColorInfo.cpp:49
GrColorType colorType() const
Definition: GrColorInfo.h:43
SkAlphaType alphaType() const
Definition: GrColorInfo.h:44
bool abandoned() override
GrTextureProxy * asTextureProxy() const
GrSurfaceProxy * proxy() const
SkIRect backingStoreBoundsIRect() const

◆ MakeFromRaster() [1/2]

sk_sp< SkSpecialImage > SkSpecialImages::MakeFromRaster ( const SkIRect subset,
const SkBitmap bm,
const SkSurfaceProps props 
)

Definition at line 128 of file SkSpecialImage.cpp.

130 {
131 SkASSERT(bm.bounds().contains(subset));
132
133 if (!bm.pixelRef()) {
134 return nullptr;
135 }
136
137 const SkBitmap* srcBM = &bm;
138 SkBitmap tmp;
139 // ImageFilters only handle N32 at the moment, so force our src to be that
140 if (!valid_for_imagefilters(bm.info())) {
141 if (!tmp.tryAllocPixels(bm.info().makeColorType(kN32_SkColorType)) ||
142 !bm.readPixels(tmp.info(), tmp.getPixels(), tmp.rowBytes(), 0, 0))
143 {
144 return nullptr;
145 }
146 srcBM = &tmp;
147 }
148 return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props);
149}
SkImageInfo makeColorType(SkColorType newColorType) const
Definition: SkImageInfo.h:475

◆ MakeFromRaster() [2/2]

sk_sp< SkSpecialImage > SkSpecialImages::MakeFromRaster ( const SkIRect subset,
sk_sp< SkImage image,
const SkSurfaceProps props 
)

Definition at line 180 of file SkSpecialImage.cpp.

182 {
183 if (!image || subset.isEmpty()) {
184 return nullptr;
185 }
186
187 SkASSERT(image->bounds().contains(subset));
189
190 // This will not work if the image is uploaded to a GPU render target.
191 SkBitmap bm;
192 if (as_IB(image)->getROPixels(nullptr, &bm)) {
193 return MakeFromRaster(subset, bm, props);
194 }
195 return nullptr;
196}
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
virtual bool isTextureBacked() const =0
SkIRect bounds() const
Definition: SkImage.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkSpecialImage > MakeFromRaster(const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
bool isEmpty() const
Definition: SkRect.h:202

◆ MakeFromTextureImage()

sk_sp< SkSpecialImage > SkSpecialImages::MakeFromTextureImage ( GrRecordingContext rContext,
const SkIRect subset,
sk_sp< SkImage image,
const SkSurfaceProps props 
)

Definition at line 73 of file SkSpecialImage_Ganesh.cpp.

76 {
77 if (!rContext || !image || subset.isEmpty()) {
78 return nullptr;
79 }
80
81 SkASSERT(image->bounds().contains(subset));
82
83 // This will work even if the image is a raster-backed image.
84 auto [view, ct] = skgpu::ganesh::AsView(rContext, image, skgpu::Mipmapped::kNo);
85 return MakeDeferredFromGpu(rContext,
86 subset,
87 image->uniqueID(),
88 std::move(view),
89 {ct, image->alphaType(), image->refColorSpace()},
90 props);
91}
uint32_t uniqueID() const
Definition: SkImage.h:311
sk_sp< SkSpecialImage > MakeDeferredFromGpu(GrRecordingContext *context, const SkIRect &subset, uint32_t uniqueID, GrSurfaceProxyView view, const GrColorInfo &colorInfo, const SkSurfaceProps &props)
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)

◆ MakeGraphite()

sk_sp< SkSpecialImage > SkSpecialImages::MakeGraphite ( skgpu::graphite::Recorder recorder,
const SkIRect subset,
sk_sp< SkImage image,
const SkSurfaceProps props 
)

Definition at line 56 of file SpecialImage_Graphite.cpp.

59 {
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}
std::pair< sk_sp< SkImage >, SkSamplingOptions > GetGraphiteBacked(Recorder *recorder, const SkImage *imageIn, SkSamplingOptions sampling)