Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | List of all members
SkImage_Lazy Class Reference

#include <SkImage_Lazy.h>

Inheritance diagram for SkImage_Lazy:
SkImage_Base SkImage SkRefCnt SkRefCntBase SkImage_LazyTexture SkImage_Picture

Classes

class  ScopedGenerator
 
struct  Validator
 

Public Member Functions

 SkImage_Lazy (Validator *validator)
 
bool isValid (GrRecordingContext *) const override
 
bool onHasMipmaps () const override
 
bool onIsProtected () const override
 
bool onReadPixels (GrDirectContext *, const SkImageInfo &, void *, size_t, int srcX, int srcY, CachingHint) const override
 
sk_sp< SkDataonRefEncoded () const override
 
sk_sp< SkImageonMakeSubset (GrDirectContext *, const SkIRect &) const override
 
sk_sp< SkImageonMakeSubset (skgpu::graphite::Recorder *, const SkIRect &, RequiredProperties) const override
 
bool getROPixels (GrDirectContext *, SkBitmap *, CachingHint) const override
 
SkImage_Base::Type type () const override
 
sk_sp< SkImageonMakeColorTypeAndColorSpace (SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const override
 
sk_sp< SkImageonReinterpretColorSpace (sk_sp< SkColorSpace >) const final
 
void addUniqueIDListener (sk_sp< SkIDChangeListener >) const
 
sk_sp< SkCachedDatagetPlanes (const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmaps *pixmaps) const
 
sk_sp< SharedGeneratorgenerator () const
 
- Public Member Functions inherited from SkImage_Base
 ~SkImage_Base () override
 
sk_sp< SkImagemakeColorSpace (GrDirectContext *, sk_sp< SkColorSpace >) const override
 
sk_sp< SkImagemakeColorSpace (skgpu::graphite::Recorder *, sk_sp< SkColorSpace >, RequiredProperties) const override
 
sk_sp< SkImagemakeColorTypeAndColorSpace (GrDirectContext *dContext, SkColorType targetColorType, sk_sp< SkColorSpace > targetCS) const override
 
sk_sp< SkImagemakeColorTypeAndColorSpace (skgpu::graphite::Recorder *, SkColorType, sk_sp< SkColorSpace >, RequiredProperties) const override
 
sk_sp< SkImagemakeSubset (GrDirectContext *direct, const SkIRect &subset) const override
 
sk_sp< SkImagemakeSubset (skgpu::graphite::Recorder *, const SkIRect &, RequiredProperties) const override
 
size_t textureSize () const override
 
virtual bool onPeekPixels (SkPixmap *) const
 
virtual const SkBitmaponPeekBitmap () const
 
virtual SkMipmaponPeekMips () const
 
sk_sp< SkMipmaprefMips () const
 
virtual void onAsyncRescaleAndReadPixels (const SkImageInfo &, SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const
 
virtual void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const
 
virtual GrImageContextcontext () const
 
virtual GrDirectContextdirectContext () const
 
virtual void generatingSurfaceIsDeleted ()
 
virtual bool onAsLegacyBitmap (GrDirectContext *, SkBitmap *) const
 
bool isLazyGenerated () const override
 
bool isRasterBacked () const
 
bool isGaneshBacked () const
 
bool isGraphiteBacked () const
 
bool isYUVA () const
 
bool isTextureBacked () const override
 
virtual void notifyAddedToRasterCache () const
 
virtual sk_sp< SkImageonMakeWithMipmaps (sk_sp< SkMipmap >) const
 
- Public Member Functions inherited from SkImage
const SkImageInfoimageInfo () const
 
int width () const
 
int height () const
 
SkISize dimensions () const
 
SkIRect bounds () const
 
uint32_t uniqueID () const
 
SkAlphaType alphaType () const
 
SkColorType colorType () const
 
SkColorSpacecolorSpace () const
 
sk_sp< SkColorSpacerefColorSpace () const
 
bool isAlphaOnly () const
 
bool isOpaque () const
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
 
sk_sp< SkShadermakeRawShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
 
sk_sp< SkShadermakeRawShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeRawShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeRawShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
 
bool peekPixels (SkPixmap *pixmap) const
 
bool readPixels (GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (GrDirectContext *context, const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
void asyncRescaleAndReadPixels (const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
void asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
void asyncRescaleAndReadPixelsYUVA420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
bool scalePixels (const SkPixmap &dst, const SkSamplingOptions &, CachingHint cachingHint=kAllow_CachingHint) const
 
sk_sp< SkDatarefEncodedData () const
 
bool hasMipmaps () const
 
bool isProtected () const
 
sk_sp< SkImagewithDefaultMipmaps () const
 
sk_sp< SkImagemakeNonTextureImage (GrDirectContext *=nullptr) const
 
sk_sp< SkImagemakeRasterImage (GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
 
sk_sp< SkImagemakeRasterImage (CachingHint cachingHint=kDisallow_CachingHint) const
 
bool asLegacyBitmap (SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
 
sk_sp< SkImagereinterpretColorSpace (sk_sp< SkColorSpace > newColorSpace) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

virtual bool readPixelsProxy (GrDirectContext *, const SkPixmap &) const
 
- Protected Member Functions inherited from SkImage_Base
 SkImage_Base (const SkImageInfo &info, uint32_t uniqueID)
 

Additional Inherited Members

- Public Types inherited from SkImage_Base
enum class  Type {
  kRaster , kRasterPinnable , kLazy , kLazyPicture ,
  kGanesh , kGaneshYUVA , kGraphite , kGraphiteYUVA
}
 
- Public Types inherited from SkImage
enum  CachingHint { kAllow_CachingHint , kDisallow_CachingHint }
 
enum class  RescaleGamma : bool { kSrc , kLinear }
 
enum class  RescaleMode { kNearest , kLinear , kRepeatedLinear , kRepeatedCubic }
 
enum  LegacyBitmapMode { kRO_LegacyBitmapMode }
 
using ReadPixelsContext = void *
 
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >)
 

Detailed Description

Definition at line 38 of file SkImage_Lazy.h.

Constructor & Destructor Documentation

◆ SkImage_Lazy()

SkImage_Lazy::SkImage_Lazy ( Validator validator)

Definition at line 100 of file SkImage_Lazy.cpp.

101 : SkImage_Base(validator->fInfo, validator->fUniqueID)
102 , fSharedGenerator(std::move(validator->fSharedGenerator))
103{
104 SkASSERT(fSharedGenerator);
105}
#define SkASSERT(cond)
Definition SkAssert.h:116
friend class SkImage_Base
Definition SkImage.h:936

Member Function Documentation

◆ addUniqueIDListener()

void SkImage_Lazy::addUniqueIDListener ( sk_sp< SkIDChangeListener listener) const

Definition at line 275 of file SkImage_Lazy.cpp.

275 {
276 fUniqueIDListeners.add(std::move(listener));
277}
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)

◆ generator()

sk_sp< SharedGenerator > SkImage_Lazy::generator ( ) const

Definition at line 153 of file SkImage_Lazy.cpp.

153 {
154 return fSharedGenerator;
155}

◆ getPlanes()

sk_sp< SkCachedData > SkImage_Lazy::getPlanes ( const SkYUVAPixmapInfo::SupportedDataTypes supportedDataTypes,
SkYUVAPixmaps pixmaps 
) const

Definition at line 245 of file SkImage_Lazy.cpp.

247 {
248 ScopedGenerator generator(fSharedGenerator);
249
251
252 if (data) {
253 SkASSERT(yuvaPixmaps->isValid());
254 SkASSERT(yuvaPixmaps->yuvaInfo().dimensions() == this->dimensions());
255 return data;
256 }
257 SkYUVAPixmapInfo yuvaPixmapInfo;
258 if (!generator->queryYUVAInfo(supportedDataTypes, &yuvaPixmapInfo) ||
259 yuvaPixmapInfo.yuvaInfo().dimensions() != this->dimensions()) {
260 return nullptr;
261 }
263 SkYUVAPixmaps tempPixmaps = SkYUVAPixmaps::FromExternalMemory(yuvaPixmapInfo,
264 data->writable_data());
265 SkASSERT(tempPixmaps.isValid());
266 if (!generator->getYUVAPlanes(tempPixmaps)) {
267 return nullptr;
268 }
269 // Decoding is done, cache the resulting YUV planes
270 *yuvaPixmaps = tempPixmaps;
271 SkYUVPlanesCache::Add(this->uniqueID(), data.get(), *yuvaPixmaps);
272 return data;
273}
sk_sp< SharedGenerator > generator() const
uint32_t uniqueID() const
Definition SkImage.h:311
static SkCachedData * NewCachedData(size_t bytes)
SkISize dimensions() const
Definition SkYUVAInfo.h:171
const SkYUVAInfo & yuvaInfo() const
size_t computeTotalBytes(size_t planeSizes[kMaxPlanes]=nullptr) const
static SkYUVAPixmaps FromExternalMemory(const SkYUVAPixmapInfo &, void *memory)
bool isValid() const
static void Add(uint32_t genID, SkCachedData *data, const SkYUVAPixmaps &pixmaps, SkResourceCache *localCache=nullptr)
static SkCachedData * FindAndRef(uint32_t genID, SkYUVAPixmaps *pixmaps, SkResourceCache *localCache=nullptr)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ getROPixels()

bool SkImage_Lazy::getROPixels ( GrDirectContext ctx,
SkBitmap bitmap,
SkImage::CachingHint  chint 
) const
overridevirtual

Implements SkImage_Base.

Definition at line 107 of file SkImage_Lazy.cpp.

108 {
109 auto check_output_bitmap = [bitmap]() {
110 SkASSERT(bitmap->isImmutable());
111 SkASSERT(bitmap->getPixels());
112 (void)bitmap;
113 };
114
115 auto desc = SkBitmapCacheDesc::Make(this);
116 if (SkBitmapCache::Find(desc, bitmap)) {
117 check_output_bitmap();
118 return true;
119 }
120
121 if (SkImage::kAllow_CachingHint == chint) {
122 SkPixmap pmap;
123 SkBitmapCache::RecPtr cacheRec = SkBitmapCache::Alloc(desc, this->imageInfo(), &pmap);
124 if (!cacheRec) {
125 return false;
126 }
127 bool success = false;
128 { // make sure ScopedGenerator goes out of scope before we try readPixelsProxy
129 success = ScopedGenerator(fSharedGenerator)->getPixels(pmap);
130 }
131 if (!success && !this->readPixelsProxy(ctx, pmap)) {
132 return false;
133 }
134 SkBitmapCache::Add(std::move(cacheRec), bitmap);
136 } else {
137 if (!bitmap->tryAllocPixels(this->imageInfo())) {
138 return false;
139 }
140 bool success = false;
141 { // make sure ScopedGenerator goes out of scope before we try readPixelsProxy
142 success = ScopedGenerator(fSharedGenerator)->getPixels(bitmap->pixmap());
143 }
144 if (!success && !this->readPixelsProxy(ctx, bitmap->pixmap())) {
145 return false;
146 }
147 bitmap->setImmutable();
148 }
149 check_output_bitmap();
150 return true;
151}
std::unique_ptr< Rec, RecDeleter > RecPtr
static RecPtr Alloc(const SkBitmapCacheDesc &, const SkImageInfo &, SkPixmap *)
static bool Find(const SkBitmapCacheDesc &, SkBitmap *result)
static void Add(RecPtr, SkBitmap *)
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:271
virtual void notifyAddedToRasterCache() const
virtual bool readPixelsProxy(GrDirectContext *, const SkPixmap &) const
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition SkImage.h:464
static SkBitmapCacheDesc Make(const SkImage *)

◆ isValid()

bool SkImage_Lazy::isValid ( GrRecordingContext context) const
overridevirtual

Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; otherwise, tests if SkImage draws on GPU surface associated with context.

SkImage backed by GPU texture may become invalid if associated context is invalid. lazy image may be invalid and may not draw to raster surface or GPU surface or both.

Parameters
contextGPU context
Returns
true if SkImage can be drawn

example: https://fiddle.skia.org/c/@Image_isValid

Implements SkImage.

Definition at line 185 of file SkImage_Lazy.cpp.

185 {
186 ScopedGenerator generator(fSharedGenerator);
187 return generator->isValid(context);
188}
virtual GrImageContext * context() const

◆ onHasMipmaps()

bool SkImage_Lazy::onHasMipmaps ( ) const
inlineoverridevirtual

Implements SkImage_Base.

Definition at line 57 of file SkImage_Lazy.h.

57 {
58 // TODO: Should we defer to the generator? The generator interface currently doesn't have
59 // a way to provide content for levels other than via SkImageGenerator::generateTexture().
60 return false;
61 }

◆ onIsProtected()

bool SkImage_Lazy::onIsProtected ( ) const
overridevirtual

Implements SkImage_Base.

Definition at line 157 of file SkImage_Lazy.cpp.

157 {
158 ScopedGenerator generator(fSharedGenerator);
159 return generator->isProtected();
160}

◆ onMakeColorTypeAndColorSpace()

sk_sp< SkImage > SkImage_Lazy::onMakeColorTypeAndColorSpace ( SkColorType  targetCT,
sk_sp< SkColorSpace targetCS,
GrDirectContext  
) const
overridevirtual

Implements SkImage_Base.

Definition at line 210 of file SkImage_Lazy.cpp.

212 {
213 SkAutoMutexExclusive autoAquire(fOnMakeColorTypeAndSpaceMutex);
214 if (fOnMakeColorTypeAndSpaceResult &&
215 targetCT == fOnMakeColorTypeAndSpaceResult->colorType() &&
216 SkColorSpace::Equals(targetCS.get(), fOnMakeColorTypeAndSpaceResult->colorSpace())) {
217 return fOnMakeColorTypeAndSpaceResult;
218 }
219 Validator validator(fSharedGenerator, &targetCT, targetCS);
220 sk_sp<SkImage> result = validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr;
221 if (result) {
222 fOnMakeColorTypeAndSpaceResult = result;
223 }
224 return result;
225}
static bool Equals(const SkColorSpace *, const SkColorSpace *)
SkColorSpace * colorSpace() const
Definition SkImage.cpp:156
SkColorType colorType() const
Definition SkImage.cpp:152
T * get() const
Definition SkRefCnt.h:303
GAsyncResult * result

◆ onMakeSubset() [1/2]

sk_sp< SkImage > SkImage_Lazy::onMakeSubset ( GrDirectContext ,
const SkIRect subset 
) const
overridevirtual

Implements SkImage_Base.

Reimplemented in SkImage_LazyTexture.

Definition at line 191 of file SkImage_Lazy.cpp.

191 {
192 // neither picture-backed nor codec-backed lazy images need the context to do readbacks.
193 // The subclass for cross-context images *does* use the direct context.
194 auto pixels = this->makeRasterImage(nullptr);
195 return pixels ? pixels->makeSubset(nullptr, subset) : nullptr;
196}
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267

◆ onMakeSubset() [2/2]

sk_sp< SkImage > SkImage_Lazy::onMakeSubset ( skgpu::graphite::Recorder ,
const SkIRect subset,
RequiredProperties  props 
) const
overridevirtual

Implements SkImage_Base.

Definition at line 198 of file SkImage_Lazy.cpp.

200 {
201 // TODO: can we do this more efficiently, by telling the generator we want to
202 // "realize" a subset?
203 sk_sp<SkImage> nonLazyImg = this->makeRasterImage(nullptr);
204 if (!nonLazyImg) {
205 return nullptr;
206 }
207 return nonLazyImg->makeSubset(nullptr, subset, props);
208}

◆ onReadPixels()

bool SkImage_Lazy::onReadPixels ( GrDirectContext dContext,
const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRB,
int  srcX,
int  srcY,
CachingHint  chint 
) const
overridevirtual

Implements SkImage_Base.

Definition at line 162 of file SkImage_Lazy.cpp.

168 {
169 SkBitmap bm;
170 if (this->getROPixels(dContext, &bm, chint)) {
171 return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
172 }
173 return false;
174}
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition SkBitmap.cpp:488
bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint) const override

◆ onRefEncoded()

sk_sp< SkData > SkImage_Lazy::onRefEncoded ( ) const
overridevirtual

Reimplemented from SkImage_Base.

Definition at line 176 of file SkImage_Lazy.cpp.

176 {
177 // check that we aren't a subset or colortype/etc modification of the original
178 if (fSharedGenerator->fGenerator->uniqueID() == this->uniqueID()) {
179 ScopedGenerator generator(fSharedGenerator);
180 return generator->refEncodedData();
181 }
182 return nullptr;
183}
std::unique_ptr< SkImageGenerator > fGenerator

◆ onReinterpretColorSpace()

sk_sp< SkImage > SkImage_Lazy::onReinterpretColorSpace ( sk_sp< SkColorSpace newCS) const
finalvirtual

Implements SkImage_Base.

Definition at line 227 of file SkImage_Lazy.cpp.

227 {
228 // TODO: The correct thing is to clone the generator, and modify its color space. That's hard,
229 // because we don't have a clone method, and generator is public (and derived-from by clients).
230 // So do the simple/inefficient thing here, and fallback to raster when this is called.
231
232 // We allocate the bitmap with the new color space, then generate the image using the original.
234 if (bitmap.tryAllocPixels(this->imageInfo().makeColorSpace(std::move(newCS)))) {
235 SkPixmap pixmap = bitmap.pixmap();
236 pixmap.setColorSpace(this->refColorSpace());
237 if (ScopedGenerator(fSharedGenerator)->getPixels(pixmap)) {
238 bitmap.setImmutable();
239 return bitmap.asImage();
240 }
241 }
242 return nullptr;
243}
sk_sp< SkColorSpace > refColorSpace() const
Definition SkImage.cpp:158
void setColorSpace(sk_sp< SkColorSpace > colorSpace)
Definition SkPixmap.cpp:57

◆ readPixelsProxy()

virtual bool SkImage_Lazy::readPixelsProxy ( GrDirectContext ,
const SkPixmap  
) const
inlineprotectedvirtual

Reimplemented in SkImage_LazyTexture.

Definition at line 87 of file SkImage_Lazy.h.

87{ return false; }

◆ type()

SkImage_Base::Type SkImage_Lazy::type ( ) const
inlineoverridevirtual

Implements SkImage_Base.

Reimplemented in SkImage_Picture.

Definition at line 73 of file SkImage_Lazy.h.


The documentation for this class was generated from the following files: