Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
skgpu::graphite::Image_Base Class Reference

#include <Image_Base_Graphite.h>

Inheritance diagram for skgpu::graphite::Image_Base:
SkImage_Base SkImage SkRefCnt SkRefCntBase skgpu::graphite::Image skgpu::graphite::Image_YUVA

Public Member Functions

 ~Image_Base () override
 
void notifyInUse (Recorder *) const
 
bool isDynamic () const
 
virtual sk_sp< ImagecopyImage (Recorder *, const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit) const
 
bool isValid (GrRecordingContext *) const override
 
sk_sp< SkImageonMakeSubset (Recorder *, const SkIRect &, RequiredProperties) const override
 
sk_sp< SkImagemakeColorTypeAndColorSpace (Recorder *, SkColorType targetCT, sk_sp< SkColorSpace > targetCS, RequiredProperties) const override
 
bool onReadPixels (GrDirectContext *, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const override
 
bool getROPixels (GrDirectContext *, SkBitmap *, CachingHint=kAllow_CachingHint) const override
 
sk_sp< SkImageonMakeSubset (GrDirectContext *, const SkIRect &) const override
 
sk_sp< SkImageonMakeColorTypeAndColorSpace (SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const override
 
void onAsyncRescaleAndReadPixels (const SkImageInfo &, SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
 
void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace >, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
 
- 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 bool onHasMipmaps () const =0
 
virtual bool onIsProtected () const =0
 
virtual SkMipmaponPeekMips () const
 
sk_sp< SkMipmaprefMips () const
 
virtual GrImageContextcontext () const
 
virtual GrDirectContextdirectContext () 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
 

Protected Member Functions

 Image_Base (const SkImageInfo &info, uint32_t uniqueID)
 
void linkDevices (const Image_Base *)
 
void linkDevice (sk_sp< Device >)
 
- Protected Member Functions inherited from SkImage_Base
 SkImage_Base (const SkImageInfo &info, uint32_t uniqueID)
 

Static Protected Member Functions

static sk_sp< ImageCopyAsDraw (Recorder *, const Image_Base *, const SkIRect &subset, const SkColorInfo &dstColorInfo, Budgeted, Mipmapped, SkBackingFit)
 

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 26 of file Image_Base_Graphite.h.

Constructor & Destructor Documentation

◆ ~Image_Base()

skgpu::graphite::Image_Base::~Image_Base ( )
overridedefault

◆ Image_Base()

skgpu::graphite::Image_Base::Image_Base ( const SkImageInfo info,
uint32_t  uniqueID 
)
protected

Definition at line 19 of file Image_Base_Graphite.cpp.

static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint32_t uniqueID() const
Definition SkImage.h:311
friend class SkImage_Base
Definition SkImage.h:936

Member Function Documentation

◆ CopyAsDraw()

sk_sp< Image > skgpu::graphite::Image_Base::CopyAsDraw ( Recorder recorder,
const Image_Base image,
const SkIRect subset,
const SkColorInfo dstColorInfo,
Budgeted  budgeted,
Mipmapped  mipmapped,
SkBackingFit  backingFit 
)
staticprotected

Definition at line 94 of file Image_Base_Graphite.cpp.

100 {
101 SkImageInfo dstInfo = SkImageInfo::Make(subset.size(),
102 dstColorInfo.makeAlphaType(kPremul_SkAlphaType));
103 // The surface goes out of scope when we return, so it can be scratch, but it may or may
104 // not be budgeted depending on how the copied image is used (or returned to the client).
105 auto surface = Surface::MakeScratch(recorder,
106 dstInfo,
107 budgeted,
108 mipmapped,
109 backingFit);
110 if (!surface) {
111 return nullptr;
112 }
113
115 paint.setBlendMode(SkBlendMode::kSrc);
116 surface->getCanvas()->drawImage(image, -subset.left(), -subset.top(),
118 // And the image draw into `surface` is flushed when it goes out of scope
119 return surface->asImage();
120}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorInfo makeAlphaType(SkAlphaType newAlphaType) const
static sk_sp< Surface > MakeScratch(Recorder *recorder, const SkImageInfo &info, Budgeted budgeted=Budgeted::kYes, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kApprox)
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
constexpr int32_t top() const
Definition SkRect.h:120
constexpr SkISize size() const
Definition SkRect.h:172
constexpr int32_t left() const
Definition SkRect.h:113
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ copyImage()

sk_sp< Image > skgpu::graphite::Image_Base::copyImage ( Recorder recorder,
const SkIRect subset,
Budgeted  budgeted,
Mipmapped  mipmapped,
SkBackingFit  backingFit 
) const
virtual

Reimplemented in skgpu::graphite::Image.

Definition at line 122 of file Image_Base_Graphite.cpp.

126 {
127 return CopyAsDraw(recorder, this, subset, this->imageInfo().colorInfo(),
128 budgeted, mipmapped, backingFit);
129}
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
static sk_sp< Image > CopyAsDraw(Recorder *, const Image_Base *, const SkIRect &subset, const SkColorInfo &dstColorInfo, Budgeted, Mipmapped, SkBackingFit)

◆ getROPixels()

bool skgpu::graphite::Image_Base::getROPixels ( GrDirectContext ,
SkBitmap ,
CachingHint  = kAllow_CachingHint 
) const
inlineoverridevirtual

Implements SkImage_Base.

Definition at line 62 of file Image_Base_Graphite.h.

64 { return false; }

◆ isDynamic()

bool skgpu::graphite::Image_Base::isDynamic ( ) const

Definition at line 75 of file Image_Base_Graphite.cpp.

75 {
76 SkAutoSpinlock lock{fDeviceLinkLock};
77 int emptyCount = 0;
78 if (!fLinkedDevices.empty()) {
79 for (sk_sp<Device>& device : fLinkedDevices) {
80 if (!device || !device->recorder() || device->unique()) {
81 device.reset();
82 emptyCount++;
83 }
84 }
85 if (emptyCount == fLinkedDevices.size()) {
86 fLinkedDevices.clear();
87 emptyCount = 0;
88 }
89 }
90
91 return emptyCount > 0;
92}
VkDevice device
Definition main.cc:53

◆ isValid()

bool skgpu::graphite::Image_Base::isValid ( GrRecordingContext context) const
inlineoverridevirtual

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 44 of file Image_Base_Graphite.h.

44{ return true; }

◆ linkDevice()

void skgpu::graphite::Image_Base::linkDevice ( sk_sp< Device device)
protected

Definition at line 33 of file Image_Base_Graphite.cpp.

33 {
34 // Technically this lock isn't needed since this is only called before the Image is returned to
35 // user code that could expose it to multiple threads. But this quiets threading warnings and
36 // should be uncontested.
37 SkAutoSpinlock lock{fDeviceLinkLock};
38 fLinkedDevices.push_back(std::move(device));
39}

◆ linkDevices()

void skgpu::graphite::Image_Base::linkDevices ( const Image_Base other)
protected

Definition at line 24 of file Image_Base_Graphite.cpp.

24 {
25 SkASSERT(other);
26
27 SkAutoSpinlock lock{other->fDeviceLinkLock};
28 for (const auto& device : other->fLinkedDevices) {
29 this->linkDevice(device);
30 }
31}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ makeColorTypeAndColorSpace()

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

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

Implements SkImage.

Definition at line 151 of file Image_Base_Graphite.cpp.

154 {
155 SkColorInfo dstColorInfo{targetCT, this->alphaType(), std::move(targetCS)};
156 // optimization : return self if there's no color type/space change and the image's texture
157 // is immutable
158 if (this->imageInfo().colorInfo() == dstColorInfo && !this->isDynamic()) {
159 return sk_ref_sp(this);
160 }
161
162 // Use CopyAsDraw directly to perform the color space changes. The copied image is not
163 // considered budgeted because this is a client-invoked API and they will own the image.
164 return CopyAsDraw(recorder,
165 this,
166 this->bounds(),
167 dstColorInfo,
169 requiredProps.fMipmapped ? Mipmapped::kYes : Mipmapped::kNo,
171}
SkBackingFit
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
SkAlphaType alphaType() const
Definition SkImage.cpp:154
SkIRect bounds() const
Definition SkImage.h:303
Mipmapped
Definition GpuTypes.h:53

◆ notifyInUse()

void skgpu::graphite::Image_Base::notifyInUse ( Recorder recorder) const

Definition at line 41 of file Image_Base_Graphite.cpp.

41 {
42 // The ref counts stored on each linked device are thread safe, but the Image's sk_sp's that
43 // track the refs its responsible for are *not* thread safe. Use a spin lock since the majority
44 // of device-linked images will be used only on the Recorder's thread. Since it should be
45 // uncontended, the empty check is also done inside the lock vs. a double-checked locking
46 // pattern that is non-trivial to ensure correctness in C++.
47 SkAutoSpinlock lock{fDeviceLinkLock};
48
49 if (!fLinkedDevices.empty()) {
50 int emptyCount = 0;
51 for (sk_sp<Device>& device : fLinkedDevices) {
52 if (!device) {
53 emptyCount++; // Already unlinked but array isn't empty yet
54 } else {
55 // Automatic flushing of image views only happens when mixing reads and writes on
56 // the originating Recorder. Draws of the view on another Recorder will always see
57 // the texture content dependent on how Recordings are inserted.
58 if (device->recorder() == recorder) {
59 device->flushPendingWorkToRecorder();
60 }
61 if (!device->recorder() || device->unique()) {
62 // The device will not record any more commands that modify the texture, so the
63 // image doesn't need to be linked
64 device.reset();
65 emptyCount++;
66 }
67 }
68 }
69 if (emptyCount == fLinkedDevices.size()) {
70 fLinkedDevices.clear();
71 }
72 }
73}

◆ onAsyncRescaleAndReadPixels()

void skgpu::graphite::Image_Base::onAsyncRescaleAndReadPixels ( const SkImageInfo info,
SkIRect  srcRect,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
) const
overridevirtual

Default implementation does a rescale/read and then calls the callback.

Reimplemented from SkImage_Base.

Definition at line 187 of file Image_Base_Graphite.cpp.

192 {
193 SKGPU_LOG_W("Cannot use Ganesh async API with Graphite-backed image, use API on Context");
194 callback(context, nullptr);
195}
#define SKGPU_LOG_W(fmt,...)
Definition Log.h:40
virtual GrImageContext * context() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ onAsyncRescaleAndReadPixelsYUV420()

void skgpu::graphite::Image_Base::onAsyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  ,
bool  readAlpha,
sk_sp< SkColorSpace dstColorSpace,
SkIRect  srcRect,
SkISize  dstSize,
RescaleGamma  ,
RescaleMode  ,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
) const
overridevirtual

Default implementation does a rescale/read/yuv conversion and then calls the callback.

Reimplemented from SkImage_Base.

Definition at line 197 of file Image_Base_Graphite.cpp.

205 {
206 SKGPU_LOG_W("Cannot use Ganesh async API with Graphite-backed image, use API on Context");
207 callback(context, nullptr);
208}

◆ onMakeColorTypeAndColorSpace()

sk_sp< SkImage > skgpu::graphite::Image_Base::onMakeColorTypeAndColorSpace ( SkColorType  ,
sk_sp< SkColorSpace ,
GrDirectContext  
) const
overridevirtual

Implements SkImage_Base.

Definition at line 180 of file Image_Base_Graphite.cpp.

182 {
183 SKGPU_LOG_W("Cannot convert Graphite-backed image to Ganesh");
184 return nullptr;
185}

◆ onMakeSubset() [1/2]

sk_sp< SkImage > skgpu::graphite::Image_Base::onMakeSubset ( GrDirectContext ,
const SkIRect  
) const
overridevirtual

Implements SkImage_Base.

Definition at line 175 of file Image_Base_Graphite.cpp.

175 {
176 SKGPU_LOG_W("Cannot convert Graphite-backed image to Ganesh");
177 return nullptr;
178}

◆ onMakeSubset() [2/2]

sk_sp< SkImage > skgpu::graphite::Image_Base::onMakeSubset ( Recorder recorder,
const SkIRect subset,
RequiredProperties  requiredProps 
) const
overridevirtual

Implements SkImage_Base.

Definition at line 131 of file Image_Base_Graphite.cpp.

133 {
134 // optimization : return self if the subset == our bounds and requirements met and the image's
135 // texture is immutable
136 if (this->bounds() == subset &&
137 (!requiredProps.fMipmapped || this->hasMipmaps()) &&
138 !this->isDynamic()) {
139 return sk_ref_sp(this);
140 }
141
142 // The copied image is not considered budgeted because this is a client-invoked API and they
143 // will own the image.
144 return this->copyImage(recorder,
145 subset,
147 requiredProps.fMipmapped ? Mipmapped::kYes : Mipmapped::kNo,
149}
virtual sk_sp< Image > copyImage(Recorder *, const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit) const

◆ onReadPixels()

bool skgpu::graphite::Image_Base::onReadPixels ( GrDirectContext ,
const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY,
CachingHint   
) const
inlineoverridevirtual

Implements SkImage_Base.

Definition at line 54 of file Image_Base_Graphite.h.

60 { return false; }

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