Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SkImage_GaneshBase Class Referenceabstract

#include <SkImage_GaneshBase.h>

Inheritance diagram for SkImage_GaneshBase:
SkImage_Base SkImage SkRefCnt SkRefCntBase SkImage_Ganesh SkImage_GaneshYUVA

Public Member Functions

bool isValid (GrRecordingContext *) const final
 
sk_sp< SkImagemakeColorTypeAndColorSpace (GrDirectContext *dContext, SkColorType targetColorType, sk_sp< SkColorSpace > targetCS) const final
 
sk_sp< SkImagemakeSubset (GrDirectContext *direct, const SkIRect &subset) const final
 
GrImageContextcontext () const final
 
GrDirectContextdirectContext () const final
 
bool getROPixels (GrDirectContext *, SkBitmap *, CachingHint) const final
 
sk_sp< SkImageonMakeSubset (GrDirectContext *, const SkIRect &subset) const final
 
bool onReadPixels (GrDirectContext *dContext, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRB, int srcX, int srcY, CachingHint) const override
 
virtual GrSemaphoresSubmitted flush (GrDirectContext *, const GrFlushInfo &) const =0
 
virtual std::tuple< GrSurfaceProxyView, GrColorTypeasView (GrRecordingContext *, skgpu::Mipmapped, GrImageTexGenPolicy) const =0
 
virtual std::unique_ptr< GrFragmentProcessorasFragmentProcessor (GrRecordingContext *, SkSamplingOptions, const SkTileMode[2], const SkMatrix &, const SkRect *, const SkRect *) const =0
 
virtual GrSurfaceOrigin origin () const =0
 
- 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< SkImagemakeSubset (skgpu::graphite::Recorder *, const SkIRect &, RequiredProperties) const override
 
size_t textureSize () const override
 
virtual bool onPeekPixels (SkPixmap *) const
 
virtual const SkBitmaponPeekBitmap () const
 
virtual bool onHasMipmaps () const =0
 
virtual bool onIsProtected () const =0
 
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 void generatingSurfaceIsDeleted ()
 
virtual sk_sp< SkDataonRefEncoded () const
 
virtual bool onAsLegacyBitmap (GrDirectContext *, SkBitmap *) const
 
virtual Type type () const =0
 
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< SkImageonReinterpretColorSpace (sk_sp< SkColorSpace >) const =0
 
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
 

Static Public Member Functions

static bool ValidateBackendTexture (const GrCaps *, const GrBackendTexture &tex, GrColorType grCT, SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
 
static bool ValidateCompressedBackendTexture (const GrCaps *, const GrBackendTexture &tex, SkAlphaType)
 
static sk_sp< GrTextureProxyMakePromiseImageLazyProxy (GrContextThreadSafeProxy *, SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, SkImages::PromiseImageTextureFulfillProc, sk_sp< skgpu::RefCntedCallback > releaseHelper)
 

Protected Member Functions

 SkImage_GaneshBase (sk_sp< GrImageContext >, SkImageInfo, uint32_t uniqueID)
 
sk_sp< SkImageonMakeSubset (skgpu::graphite::Recorder *, const SkIRect &subset, RequiredProperties) const final
 
sk_sp< SkImagemakeColorTypeAndColorSpace (skgpu::graphite::Recorder *, SkColorType, sk_sp< SkColorSpace >, RequiredProperties) const final
 
virtual sk_sp< SkImageonMakeColorTypeAndColorSpace (SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const=0
 
- Protected Member Functions inherited from SkImage_Base
 SkImage_Base (const SkImageInfo &info, uint32_t uniqueID)
 

Protected Attributes

sk_sp< GrImageContextfContext
 

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 54 of file SkImage_GaneshBase.h.

Constructor & Destructor Documentation

◆ SkImage_GaneshBase()

SkImage_GaneshBase::SkImage_GaneshBase ( sk_sp< GrImageContext context,
SkImageInfo  info,
uint32_t  uniqueID 
)
protected

Definition at line 61 of file SkImage_GaneshBase.cpp.

64 : SkImage_Base(std::move(info), uniqueID), fContext(std::move(context)) {}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
sk_sp< GrImageContext > fContext
GrImageContext * context() const final
uint32_t uniqueID() const
Definition SkImage.h:311
friend class SkImage_Base
Definition SkImage.h:936

Member Function Documentation

◆ asFragmentProcessor()

virtual std::unique_ptr< GrFragmentProcessor > SkImage_GaneshBase::asFragmentProcessor ( GrRecordingContext ,
SkSamplingOptions  ,
const SkTileMode  [2],
const SkMatrix ,
const SkRect ,
const SkRect  
) const
pure virtual

Implemented in SkImage_Ganesh, and SkImage_GaneshYUVA.

◆ asView()

virtual std::tuple< GrSurfaceProxyView, GrColorType > SkImage_GaneshBase::asView ( GrRecordingContext ,
skgpu::Mipmapped  ,
GrImageTexGenPolicy   
) const
pure virtual

Implemented in SkImage_Ganesh, and SkImage_GaneshYUVA.

◆ context()

GrImageContext * SkImage_GaneshBase::context ( ) const
inlinefinalvirtual

Reimplemented from SkImage_Base.

Definition at line 64 of file SkImage_GaneshBase.h.

64{ return fContext.get(); }
T * get() const
Definition SkRefCnt.h:303

◆ directContext()

GrDirectContext * SkImage_GaneshBase::directContext ( ) const
inlinefinalvirtual

this->context() try-casted to GrDirectContext. Useful for migrations – avoid otherwise!

Reimplemented from SkImage_Base.

Definition at line 65 of file SkImage_GaneshBase.h.

65{ return GrAsDirectContext(this->context()); }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)

◆ flush()

virtual GrSemaphoresSubmitted SkImage_GaneshBase::flush ( GrDirectContext ,
const GrFlushInfo  
) const
pure virtual

Implemented in SkImage_Ganesh, and SkImage_GaneshYUVA.

◆ getROPixels()

bool SkImage_GaneshBase::getROPixels ( GrDirectContext dContext,
SkBitmap dst,
CachingHint  chint 
) const
finalvirtual

Implements SkImage_Base.

Definition at line 118 of file SkImage_GaneshBase.cpp.

120 {
121 if (!fContext->priv().matches(dContext)) {
122 return false;
123 }
124
125 const auto desc = SkBitmapCacheDesc::Make(this);
126 if (SkBitmapCache::Find(desc, dst)) {
127 SkASSERT(dst->isImmutable());
128 SkASSERT(dst->getPixels());
129 return true;
130 }
131
132 SkBitmapCache::RecPtr rec = nullptr;
133 SkPixmap pmap;
134 if (kAllow_CachingHint == chint) {
135 rec = SkBitmapCache::Alloc(desc, this->imageInfo(), &pmap);
136 if (!rec) {
137 return false;
138 }
139 } else {
140 if (!dst->tryAllocPixels(this->imageInfo()) || !dst->peekPixels(&pmap)) {
141 return false;
142 }
143 }
144
145 auto [view, ct] = skgpu::ganesh::AsView(dContext, this, skgpu::Mipmapped::kNo);
146 if (!view) {
147 return false;
148 }
149
150 GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace());
151 auto sContext = dContext->priv().makeSC(std::move(view), std::move(colorInfo));
152 if (!sContext) {
153 return false;
154 }
155
156 if (!sContext->readPixels(dContext, pmap, {0, 0})) {
157 return false;
158 }
159
160 if (rec) {
161 SkBitmapCache::Add(std::move(rec), dst);
163 }
164 return true;
165}
#define SkASSERT(cond)
Definition SkAssert.h:116
bool matches(GrContext_Base *candidate) const
GrDirectContextPriv priv()
GrImageContextPriv priv()
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
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 *)
virtual void notifyAddedToRasterCache() const
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
SkAlphaType alphaType() const
Definition SkImage.cpp:154
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition SkImage.h:464
sk_sp< SkColorSpace > refColorSpace() const
Definition SkImage.cpp:158
dst
Definition cp.py:12
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
static SkBitmapCacheDesc Make(const SkImage *)

◆ isValid()

bool SkImage_GaneshBase::isValid ( GrRecordingContext context) const
finalvirtual

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 257 of file SkImage_GaneshBase.cpp.

257 {
258 if (context && context->abandoned()) {
259 return false;
260 }
261 if (fContext->priv().abandoned()) {
262 return false;
263 }
264 if (context && !fContext->priv().matches(context)) {
265 return false;
266 }
267 return true;
268}
virtual SK_API bool abandoned()

◆ makeColorTypeAndColorSpace() [1/2]

sk_sp< SkImage > SkImage_GaneshBase::makeColorTypeAndColorSpace ( GrDirectContext direct,
SkColorType  targetColorType,
sk_sp< SkColorSpace targetCS 
) const
finalvirtual

Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorType and SkColorSpace.

If this image is texture-backed, the context parameter is required and must match the context of the source image.

Parameters
directThe GrDirectContext in play, if it exists
targetColorTypeSkColorType of returned SkImage
targetColorSpaceSkColorSpace of returned SkImage
Returns
created SkImage in target SkColorType and SkColorSpace

Reimplemented from SkImage_Base.

Definition at line 270 of file SkImage_GaneshBase.cpp.

272 {
273 if (kUnknown_SkColorType == targetColorType || !targetCS) {
274 return nullptr;
275 }
276
277 auto myContext = this->context();
278 // This check is also performed in the subclass, but we do it here for the short-circuit below.
279 if (!myContext || !myContext->priv().matches(dContext)) {
280 return nullptr;
281 }
282
285 if (!colorSpace) {
287 }
288 if (colorType == targetColorType &&
289 (SkColorSpace::Equals(colorSpace, targetCS.get()) || this->isAlphaOnly())) {
290 return sk_ref_sp(const_cast<SkImage_GaneshBase*>(this));
291 }
292
293 return this->onMakeColorTypeAndColorSpace(targetColorType, std::move(targetCS), dContext);
294}
SkColorSpace * sk_srgb_singleton()
SkColorType
Definition SkColorType.h:19
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
static bool Equals(const SkColorSpace *, const SkColorSpace *)
virtual sk_sp< SkImage > onMakeColorTypeAndColorSpace(SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const=0
SkColorSpace * colorSpace() const
Definition SkImage.cpp:156
SkColorType colorType() const
Definition SkImage.cpp:152

◆ makeColorTypeAndColorSpace() [2/2]

sk_sp< SkImage > SkImage_GaneshBase::makeColorTypeAndColorSpace ( skgpu::graphite::Recorder ,
SkColorType  targetColorType,
sk_sp< SkColorSpace targetColorSpace,
RequiredProperties   
) const
finalprotectedvirtual

Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorType and SkColorSpace.

If this image is graphite-backed, the recorder parameter is required.

Parameters
targetColorTypeSkColorType of returned SkImage
targetColorSpaceSkColorSpace of returned SkImage
recorderThe Recorder in which to create the new image
RequiredPropertiesproperties the returned SkImage must possess (e.g. mipmaps)
Returns
created SkImage in target SkColorType and SkColorSpace

Reimplemented from SkImage_Base.

Definition at line 225 of file SkImage_GaneshBase.cpp.

228 {
229 SkDEBUGFAIL("Cannot convert Ganesh-backed image to Graphite");
230 return nullptr;
231}
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118

◆ MakePromiseImageLazyProxy()

sk_sp< GrTextureProxy > SkImage_GaneshBase::MakePromiseImageLazyProxy ( GrContextThreadSafeProxy tsp,
SkISize  dimensions,
const GrBackendFormat backendFormat,
skgpu::Mipmapped  mipmapped,
SkImages::PromiseImageTextureFulfillProc  fulfillProc,
sk_sp< skgpu::RefCntedCallback releaseHelper 
)
static

This class is the lazy instantiation callback for promise images. It manages calling the client's Fulfill and Release procs. It attempts to reuse a GrTexture instance in cases where the client provides the same GrPromiseImageTexture as Fulfill results for multiple SkImages. The created GrTexture is given a key based on a unique ID associated with the GrPromiseImageTexture.

A key invalidation message is installed on the GrPromiseImageTexture so that the GrTexture is deleted once it can no longer be used to instantiate a proxy.

Definition at line 296 of file SkImage_GaneshBase.cpp.

302 {
303 SkASSERT(tsp);
305 SkASSERT(releaseHelper);
306
307 if (!fulfillProc) {
308 return nullptr;
309 }
310
311 if (mipmapped == skgpu::Mipmapped::kYes &&
313 // It is invalid to have a GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE and have mips as
314 // well.
315 return nullptr;
316 }
317
318 /**
319 * This class is the lazy instantiation callback for promise images. It manages calling the
320 * client's Fulfill and Release procs. It attempts to reuse a GrTexture instance in
321 * cases where the client provides the same GrPromiseImageTexture as Fulfill results for
322 * multiple SkImages. The created GrTexture is given a key based on a unique ID associated with
323 * the GrPromiseImageTexture.
324 *
325 * A key invalidation message is installed on the GrPromiseImageTexture so that the GrTexture
326 * is deleted once it can no longer be used to instantiate a proxy.
327 */
328 class PromiseLazyInstantiateCallback {
329 public:
330 PromiseLazyInstantiateCallback(SkImages::PromiseImageTextureFulfillProc fulfillProc,
331 sk_sp<skgpu::RefCntedCallback> releaseHelper)
332 : fFulfillProc(fulfillProc), fReleaseHelper(std::move(releaseHelper)) {}
333 PromiseLazyInstantiateCallback(PromiseLazyInstantiateCallback&&) = default;
334 PromiseLazyInstantiateCallback(const PromiseLazyInstantiateCallback&) {
335 // Because we get wrapped in std::function we must be copyable. But we should never
336 // be copied.
337 SkASSERT(false);
338 }
339 PromiseLazyInstantiateCallback& operator=(PromiseLazyInstantiateCallback&&) = default;
340 PromiseLazyInstantiateCallback& operator=(const PromiseLazyInstantiateCallback&) {
341 SkASSERT(false);
342 return *this;
343 }
344
345 ~PromiseLazyInstantiateCallback() {
346 // Our destructor can run on any thread. We trigger the unref of fTexture by message.
347 if (fTexture) {
348 GrResourceCache::ReturnResourceFromThread(std::move(fTexture), fTextureContextID);
349 }
350 }
351
352 GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider,
354 // We use the unique key in a way that is unrelated to the SkImage-based key that the
355 // proxy may receive, hence kUnsynced.
356 static constexpr auto kKeySyncMode =
358
359 // In order to make the SkImage "thread safe" we rely on holding an extra ref to the
360 // texture in the callback and signalling the unref via a message to the resource cache.
361 // We need to extend the callback's lifetime to that of the proxy.
362 static constexpr auto kReleaseCallbackOnInstantiation = false;
363
364 // Our proxy is getting instantiated for the second+ time. We are only allowed to call
365 // Fulfill once. So return our cached result.
366 if (fTexture) {
367 return {fTexture, kReleaseCallbackOnInstantiation, kKeySyncMode};
368 } else if (fFulfillProcFailed) {
369 // We've already called fulfill and it failed. Our contract says that we should only
370 // call each callback once.
371 return {};
372 }
373
374 SkImages::PromiseImageTextureContext textureContext = fReleaseHelper->context();
375 sk_sp<GrPromiseImageTexture> promiseTexture = fFulfillProc(textureContext);
376
377 if (!promiseTexture) {
378 fFulfillProcFailed = true;
379 return {};
380 }
381
382 const GrBackendTexture& backendTexture = promiseTexture->backendTexture();
383 if (!backendTexture.isValid()) {
384 return {};
385 }
386
387 fTexture = resourceProvider->wrapBackendTexture(
389 if (!fTexture) {
390 return {};
391 }
392 fTexture->setRelease(fReleaseHelper);
393 auto dContext = fTexture->getContext();
394 fTextureContextID = dContext->directContextID();
395 return {fTexture, kReleaseCallbackOnInstantiation, kKeySyncMode};
396 }
397
398 private:
400 sk_sp<skgpu::RefCntedCallback> fReleaseHelper;
401 sk_sp<GrTexture> fTexture;
402 GrDirectContext::DirectContextID fTextureContextID;
403 bool fFulfillProcFailed = false;
404 } callback(fulfillProc, std::move(releaseHelper));
405
407 tsp, std::move(callback), backendFormat, dimensions, mipmapped);
408}
@ kRead_GrIOType
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
static bool GrTextureTypeHasRestrictedSampling(GrTextureType type)
GrTextureType textureType() const
static sk_sp< GrTextureProxy > CreatePromiseProxy(GrContextThreadSafeProxy *, LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped)
static std::enable_if_t< std::is_base_of_v< GrGpuResource, T >, void > ReturnResourceFromThread(sk_sp< T > &&resource, GrDirectContext::DirectContextID id)
sk_sp< GrTexture > wrapBackendTexture(const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable, GrIOType)
void setRelease(sk_sp< skgpu::RefCntedCallback > releaseHelper)
Definition GrSurface.cpp:60
SkISize dimensions() const
Definition SkImage.h:297
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void * PromiseImageTextureContext
Definition ref_ptr.h:256
bool isEmpty() const
Definition SkSize.h:31

◆ makeSubset()

sk_sp< SkImage > SkImage_GaneshBase::makeSubset ( GrDirectContext direct,
const SkIRect subset 
) const
finalvirtual

Returns subset of this image.

Returns nullptr if any of the following are true:

  • Subset is empty
  • Subset is not contained inside the image's bounds
  • Pixels in the source image could not be read or copied
  • This image is texture-backed and the provided context is null or does not match the source image's context.

If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.

Parameters
directthe GrDirectContext of the source image (nullptr is ok if the source image is not texture-backed).
subsetbounds of returned SkImage
Returns
the subsetted image, or nullptr

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

Reimplemented from SkImage_Base.

Definition at line 167 of file SkImage_GaneshBase.cpp.

168 {
169 if (!fContext->priv().matches(direct)) {
170 return nullptr;
171 }
172
173 if (subset.isEmpty()) {
174 return nullptr;
175 }
176
177 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
178 if (!bounds.contains(subset)) {
179 return nullptr;
180 }
181
182 // optimization : return self if the subset == our bounds
183 if (bounds == subset) {
184 return sk_ref_sp(const_cast<SkImage_GaneshBase*>(this));
185 }
186
187 return this->onMakeSubset(direct, subset);
188}
sk_sp< SkImage > onMakeSubset(GrDirectContext *, const SkIRect &subset) const final
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
SkIRect bounds() const
Definition SkImage.h:303
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
bool isEmpty() const
Definition SkRect.h:202
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463

◆ onMakeColorTypeAndColorSpace()

virtual sk_sp< SkImage > SkImage_Base::onMakeColorTypeAndColorSpace ( SkColorType  ,
sk_sp< SkColorSpace ,
GrDirectContext  
) const
protectedvirtual

Implements SkImage_Base.

Reimplemented in SkImage_GaneshYUVA, and SkImage_GaneshYUVA.

◆ onMakeSubset() [1/2]

sk_sp< SkImage > SkImage_GaneshBase::onMakeSubset ( GrDirectContext direct,
const SkIRect subset 
) const
finalvirtual

Implements SkImage_Base.

Definition at line 190 of file SkImage_GaneshBase.cpp.

191 {
192 if (!fContext->priv().matches(direct)) {
193 return nullptr;
194 }
195 auto [view, ct] = skgpu::ganesh::AsView(direct, this, skgpu::Mipmapped::kNo);
196 SkASSERT(view);
198
199 skgpu::Budgeted isBudgeted = view.proxy()->isBudgeted();
200 auto copyView = GrSurfaceProxyView::Copy(direct,
201 std::move(view),
202 skgpu::Mipmapped::kNo,
203 subset,
205 isBudgeted,
206 /*label=*/"ImageGpuBase_MakeSubset");
207
208 if (!copyView) {
209 return nullptr;
210 }
211
212 return sk_make_sp<SkImage_Ganesh>(sk_ref_sp(direct),
214 std::move(copyView),
215 this->imageInfo().colorInfo());
216}
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
@ kNeedNewImageUniqueID
static GrSurfaceProxyView Copy(GrRecordingContext *context, GrSurfaceProxyView src, skgpu::Mipmapped mipmapped, SkIRect srcRect, SkBackingFit fit, skgpu::Budgeted budgeted, std::string_view label)
Budgeted
Definition GpuTypes.h:35

◆ onMakeSubset() [2/2]

sk_sp< SkImage > SkImage_GaneshBase::onMakeSubset ( skgpu::graphite::Recorder ,
const SkIRect subset,
RequiredProperties   
) const
finalprotectedvirtual

Implements SkImage_Base.

Definition at line 218 of file SkImage_GaneshBase.cpp.

220 {
221 SkDEBUGFAIL("Cannot convert Ganesh-backed image to Graphite");
222 return nullptr;
223}

◆ onReadPixels()

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

Implements SkImage_Base.

Definition at line 233 of file SkImage_GaneshBase.cpp.

239 {
240 if (!fContext->priv().matches(dContext) ||
241 !SkImageInfoValidConversion(dstInfo, this->imageInfo())) {
242 return false;
243 }
244
245 auto [view, ct] = skgpu::ganesh::AsView(dContext, this, skgpu::Mipmapped::kNo);
246 SkASSERT(view);
247
248 GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace());
249 auto sContext = dContext->priv().makeSC(std::move(view), colorInfo);
250 if (!sContext) {
251 return false;
252 }
253
254 return sContext->readPixels(dContext, {dstInfo, dstPixels, dstRB}, {srcX, srcY});
255}
static bool SkImageInfoValidConversion(const SkImageInfo &dst, const SkImageInfo &src)

◆ origin()

virtual GrSurfaceOrigin SkImage_GaneshBase::origin ( ) const
pure virtual

Implemented in SkImage_Ganesh, and SkImage_GaneshYUVA.

◆ ValidateBackendTexture()

bool SkImage_GaneshBase::ValidateBackendTexture ( const GrCaps caps,
const GrBackendTexture tex,
GrColorType  grCT,
SkColorType  ct,
SkAlphaType  at,
sk_sp< SkColorSpace cs 
)
static

Definition at line 68 of file SkImage_GaneshBase.cpp.

73 {
74 if (!tex.isValid()) {
75 return false;
76 }
77 SkColorInfo info(ct, at, cs);
79 return false;
80 }
81 GrBackendFormat backendFormat = tex.getBackendFormat();
82 if (!backendFormat.isValid()) {
83 return false;
84 }
85
86 return caps->areColorTypeAndFormatCompatible(grCT, backendFormat);
87}
static bool SkColorInfoIsValid(const SkColorInfo &info)
bool isValid() const
GrBackendFormat getBackendFormat() const
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition GrCaps.cpp:428

◆ ValidateCompressedBackendTexture()

bool SkImage_GaneshBase::ValidateCompressedBackendTexture ( const GrCaps caps,
const GrBackendTexture tex,
SkAlphaType  at 
)
static

Definition at line 89 of file SkImage_GaneshBase.cpp.

91 {
92 if (!tex.isValid() || tex.width() <= 0 || tex.height() <= 0) {
93 return false;
94 }
95
96 if (tex.width() > caps->maxTextureSize() || tex.height() > caps->maxTextureSize()) {
97 return false;
98 }
99
100 if (at == kUnknown_SkAlphaType) {
101 return false;
102 }
103
104 GrBackendFormat backendFormat = tex.getBackendFormat();
105 if (!backendFormat.isValid()) {
106 return false;
107 }
108
109 if (!caps->isFormatCompressed(backendFormat)) {
110 return false;
111 }
112
113 return true;
114}
@ kUnknown_SkAlphaType
uninitialized
Definition SkAlphaType.h:27
int maxTextureSize() const
Definition GrCaps.h:229
bool isFormatCompressed(const GrBackendFormat &format) const
Definition GrCaps.cpp:457

Member Data Documentation

◆ fContext

sk_sp<GrImageContext> SkImage_GaneshBase::fContext
protected

Definition at line 127 of file SkImage_GaneshBase.h.


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