Flutter Engine
The Flutter Engine
Typedefs | Enumerations | Functions
SkImages Namespace Reference

Typedefs

using ReleaseContext = void *
 
using RasterReleaseProc = void(const void *pixels, ReleaseContext)
 
using BackendTextureReleaseProc = std::function< void(GrBackendTexture)>
 
using TextureReleaseProc = void(*)(ReleaseContext)
 
using GraphitePromiseImageContext = void *
 
using GraphitePromiseTextureFulfillContext = void *
 
using GraphitePromiseTextureReleaseContext = void *
 
using GraphitePromiseTextureFulfillProc = std::tuple< skgpu::graphite::BackendTexture, GraphitePromiseTextureReleaseContext >(*)(GraphitePromiseTextureFulfillContext)
 
using GraphitePromiseImageReleaseProc = void(*)(GraphitePromiseImageContext)
 
using GraphitePromiseTextureReleaseProc = void(*)(GraphitePromiseTextureReleaseContext)
 
using PromiseImageTextureContext = void *
 
using PromiseImageTextureFulfillProc = sk_sp< GrPromiseImageTexture >(*)(PromiseImageTextureContext)
 
using PromiseImageTextureReleaseProc = void(*)(PromiseImageTextureContext)
 

Enumerations

enum class  BitDepth { kU8 , kF16 }
 
enum class  GenerateMipmapsFromBase : bool { kNo , kYes }
 

Functions

SK_API sk_sp< SkImageDeferredFromAHardwareBuffer (AHardwareBuffer *hardwareBuffer, SkAlphaType alphaType=kPremul_SkAlphaType)
 
SK_API sk_sp< SkImageDeferredFromAHardwareBuffer (AHardwareBuffer *hardwareBuffer, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, GrSurfaceOrigin surfaceOrigin=kTopLeft_GrSurfaceOrigin)
 
SK_API sk_sp< SkImageTextureFromAHardwareBufferWithData (GrDirectContext *context, const SkPixmap &pixmap, AHardwareBuffer *hardwareBuffer, GrSurfaceOrigin surfaceOrigin=kTopLeft_GrSurfaceOrigin)
 
SK_API sk_sp< SkImagePinnableRasterFromBitmap (const SkBitmap &)
 
SK_API sk_sp< SkImageRasterFromBitmap (const SkBitmap &bitmap)
 
SK_API sk_sp< SkImageRasterFromCompressedTextureData (sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)
 
SK_API sk_sp< SkImageDeferredFromEncodedData (sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
 
SK_API sk_sp< SkImageDeferredFromGenerator (std::unique_ptr< SkImageGenerator > imageGenerator)
 
SK_API sk_sp< SkImageDeferredFromPicture (sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
 
SK_API sk_sp< SkImageDeferredFromPicture (sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace)
 
SK_API sk_sp< SkImageRasterFromPixmapCopy (const SkPixmap &pixmap)
 
SK_API sk_sp< SkImageRasterFromPixmap (const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
 
SK_API sk_sp< SkImageRasterFromData (const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
 
SK_API sk_sp< SkImageMakeWithFilter (sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
 
SK_API sk_sp< SkImageDeferredFromTextureGenerator (std::unique_ptr< GrTextureGenerator > gen)
 
SK_API sk_sp< SkImageAdoptTextureFrom (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType)
 
SK_API sk_sp< SkImageAdoptTextureFrom (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType, SkAlphaType alphaType)
 
SK_API sk_sp< SkImageAdoptTextureFrom (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
 
SK_API sk_sp< SkImageBorrowTextureFrom (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 
SK_API sk_sp< SkImageCrossContextTextureFromPixmap (GrDirectContext *context, const SkPixmap &pixmap, bool buildMips, bool limitToMaxTextureSize=false)
 
SK_API sk_sp< SkImageTextureFromCompressedTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 
SK_API sk_sp< SkImageTextureFromCompressedTextureData (GrDirectContext *direct, sk_sp< SkData > data, int width, int height, SkTextureCompressionType type, skgpu::Mipmapped mipmapped=skgpu::Mipmapped::kNo, GrProtected isProtected=GrProtected::kNo)
 
SK_API sk_sp< SkImageTextureFromImage (GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
 
sk_sp< SkImageTextureFromImage (GrDirectContext *ctx, const sk_sp< const SkImage > &img, skgpu::Mipmapped m=skgpu::Mipmapped::kNo, skgpu::Budgeted b=skgpu::Budgeted::kYes)
 
SK_API sk_sp< SkImageTextureFromYUVAPixmaps (GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips, bool limitToMaxTextureSize, sk_sp< SkColorSpace > imageColorSpace)
 
SK_API sk_sp< SkImageTextureFromYUVAPixmaps (GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips=skgpu::Mipmapped::kNo, bool limitToMaxTextureSize=false)
 
SK_API sk_sp< SkImageTextureFromYUVATextures (GrRecordingContext *context, const GrYUVABackendTextures &yuvaTextures, sk_sp< SkColorSpace > imageColorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 
SK_API sk_sp< SkImageTextureFromYUVATextures (GrRecordingContext *context, const GrYUVABackendTextures &yuvaTextures)
 
SK_API bool GetBackendTextureFromImage (const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
 
bool GetBackendTextureFromImage (const sk_sp< const SkImage > &img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
 
SK_API bool MakeBackendTextureFromImage (GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)
 
bool GetBackendTextureFromImage (GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)
 
SK_API sk_sp< SkImageSubsetTextureFrom (GrDirectContext *context, const SkImage *img, const SkIRect &subset)
 
SK_API sk_sp< SkImageMakeWithFilter (GrRecordingContext *context, sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
 
SK_API sk_sp< SkImageWrapTexture (skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
 
SK_API sk_sp< SkImageWrapTexture (skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
 
SK_API sk_sp< SkImageWrapTexture (skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
 
sk_sp< SkImageAdoptTextureFrom (skgpu::graphite::Recorder *recorder, const skgpu::graphite::BackendTexture &tex, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, TextureReleaseProc trProc=nullptr, ReleaseContext ctx=nullptr)
 
sk_sp< SkImageAdoptTextureFrom (skgpu::graphite::Recorder *recorder, const skgpu::graphite::BackendTexture &tex, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc trProc=nullptr, ReleaseContext ctx=nullptr)
 
SK_API sk_sp< SkImagePromiseTextureFrom (skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::Origin origin, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext, std::string_view label={})
 
SK_API sk_sp< SkImagePromiseTextureFrom (skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext)
 
SK_API sk_sp< SkImagePromiseTextureFromYUVA (skgpu::graphite::Recorder *, const skgpu::graphite::YUVABackendTextureInfo &, sk_sp< SkColorSpace > imageColorSpace, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext imageContext, GraphitePromiseTextureFulfillContext planeContexts[], std::string_view label={})
 
SK_API sk_sp< SkImageTextureFromImage (skgpu::graphite::Recorder *, const SkImage *, SkImage::RequiredProperties={})
 
sk_sp< SkImageTextureFromImage (skgpu::graphite::Recorder *r, const sk_sp< const SkImage > &img, SkImage::RequiredProperties props={})
 
SK_API sk_sp< SkImageTextureFromYUVAPixmaps (skgpu::graphite::Recorder *, const SkYUVAPixmaps &pixmaps, SkImage::RequiredProperties={}, bool limitToMaxTextureSize=false, sk_sp< SkColorSpace > imgColorSpace=nullptr, std::string_view label={})
 
SK_API sk_sp< SkImageTextureFromYUVATextures (skgpu::graphite::Recorder *recorder, const skgpu::graphite::YUVABackendTextures &yuvaBackendTextures, sk_sp< SkColorSpace > imageColorSpace, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
 
SK_API sk_sp< SkImageTextureFromYUVAImages (skgpu::graphite::Recorder *recorder, const SkYUVAInfo &yuvaInfo, SkSpan< const sk_sp< SkImage > > images, sk_sp< SkColorSpace > imageColorSpace)
 
SK_API sk_sp< SkImageSubsetTextureFrom (skgpu::graphite::Recorder *recorder, const SkImage *img, const SkIRect &subset, SkImage::RequiredProperties props={})
 
SK_API sk_sp< SkImageMakeWithFilter (skgpu::graphite::Recorder *recorder, sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
 
SK_API sk_sp< SkImagePromiseTextureFrom (sk_sp< GrContextThreadSafeProxy > gpuContextProxy, const GrBackendFormat &backendFormat, SkISize dimensions, skgpu::Mipmapped mipmapped, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext)
 
SK_API sk_sp< SkImagePromiseTextureFromYUVA (sk_sp< GrContextThreadSafeProxy > gpuContextProxy, const GrYUVABackendTextureInfo &backendTextureInfo, sk_sp< SkColorSpace > imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[])
 
SK_API GrDirectContextGetContext (const SkImage *src)
 
GrDirectContextGetContext (const sk_sp< const SkImage > &src)
 
static sk_sp< SkImagenew_wrapped_texture_common (GrRecordingContext *rContext, const GrBackendTexture &backendTex, GrColorType colorType, GrSurfaceOrigin origin, SkAlphaType at, sk_sp< SkColorSpace > colorSpace, GrWrapOwnership ownership, sk_sp< skgpu::RefCntedCallback > releaseHelper)
 
static bool validate_backend_texture (const skgpu::graphite::Caps *caps, const skgpu::graphite::BackendTexture &texture, const SkColorInfo &info)
 
static sk_sp< SkImagegenerate_picture_texture (skgpu::graphite::Recorder *recorder, const SkImage_Picture *img, const SkImageInfo &info, SkImage::RequiredProperties requiredProps)
 
static sk_sp< SkImagemake_texture_image_from_lazy (skgpu::graphite::Recorder *recorder, const SkImage_Lazy *img, SkImage::RequiredProperties requiredProps)
 

Detailed Description

All factories in this file refer to the Ganesh GPU backend when they say GPU.

These functions expose features that are only for external use in Chromium.

Typedef Documentation

◆ BackendTextureReleaseProc

Defines a callback function, taking one parameter of type GrBackendTexture with no return value. Function is called when backend texture is to be released.

Definition at line 43 of file SkImageGanesh.h.

◆ GraphitePromiseImageContext

Definition at line 38 of file Image.h.

◆ GraphitePromiseImageReleaseProc

Definition at line 48 of file Image.h.

◆ GraphitePromiseTextureFulfillContext

Definition at line 41 of file Image.h.

◆ GraphitePromiseTextureFulfillProc

Definition at line 45 of file Image.h.

◆ GraphitePromiseTextureReleaseContext

Definition at line 43 of file Image.h.

◆ GraphitePromiseTextureReleaseProc

Definition at line 49 of file Image.h.

◆ PromiseImageTextureContext

using SkImages::PromiseImageTextureContext = typedef void*

Definition at line 35 of file SkImageChromium.h.

◆ PromiseImageTextureFulfillProc

Definition at line 36 of file SkImageChromium.h.

◆ PromiseImageTextureReleaseProc

Definition at line 37 of file SkImageChromium.h.

◆ RasterReleaseProc

using SkImages::RasterReleaseProc = typedef void(const void* pixels, ReleaseContext)

Function called when SkImage no longer shares pixels. ReleaseContext is provided by caller when SkImage is created, and may be nullptr.

Definition at line 54 of file SkImage.h.

◆ ReleaseContext

using SkImages::ReleaseContext = typedef void*

Caller data passed to RasterReleaseProc; may be nullptr.

Definition at line 50 of file SkImage.h.

◆ TextureReleaseProc

User function called when supplied texture may be deleted.

Definition at line 45 of file SkImageGanesh.h.

Enumeration Type Documentation

◆ BitDepth

enum class SkImages::BitDepth
strong
Enumerator
kU8 

uses 8-bit unsigned int per color component

kF16 

uses 16-bit float per color component

Definition at line 125 of file SkImage.h.

125 {
126 kU8, //!< uses 8-bit unsigned int per color component
127 kF16, //!< uses 16-bit float per color component
128};
@ kF16
uses 16-bit float per color component
@ kU8
uses 8-bit unsigned int per color component

◆ GenerateMipmapsFromBase

enum class SkImages::GenerateMipmapsFromBase : bool
strong
Enumerator
kNo 
kYes 

Definition at line 33 of file Image.h.

33: bool { kNo, kYes };
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.

Function Documentation

◆ AdoptTextureFrom() [1/5]

sk_sp< SkImage > SkImages::AdoptTextureFrom ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  textureOrigin,
SkColorType  colorType 
)

Creates GPU-backed SkImage from backendTexture associated with context. Skia will assume ownership of the resource and will release it when no longer needed. A non-null SkImage is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU backend.

Parameters
contextGPU context
backendTexturetexture residing on GPU
textureOriginorigin of backendTexture
colorTypecolor type of the resulting image
alphaTypealpha type of the resulting image
colorSpacerange of colors; may be nullptr
Returns
created SkImage, or nullptr

Definition at line 230 of file SkImage_GaneshFactories.cpp.

233 {
234 return AdoptTextureFrom(
235 context, backendTexture, textureOrigin, colorType, kPremul_SkAlphaType, nullptr);
236}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API sk_sp< SkImage > AdoptTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType)

◆ AdoptTextureFrom() [2/5]

sk_sp< SkImage > SkImages::AdoptTextureFrom ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  textureOrigin,
SkColorType  colorType,
SkAlphaType  alphaType 
)

Definition at line 238 of file SkImage_GaneshFactories.cpp.

242 {
243 return AdoptTextureFrom(context, backendTexture, textureOrigin, colorType, alphaType, nullptr);
244}

◆ AdoptTextureFrom() [3/5]

sk_sp< SkImage > SkImages::AdoptTextureFrom ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  textureOrigin,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace 
)

Definition at line 246 of file SkImage_GaneshFactories.cpp.

251 {
252 auto dContext = GrAsDirectContext(context);
253 if (!dContext) {
254 // We have a DDL context and we don't support adopted textures for them.
255 return nullptr;
256 }
257
258 const GrCaps* caps = dContext->priv().caps();
259
261 if (GrColorType::kUnknown == grColorType) {
262 return nullptr;
263 }
264
266 caps, backendTexture, grColorType, colorType, alphaType, colorSpace)) {
267 return nullptr;
268 }
269
270 return new_wrapped_texture_common(dContext,
271 backendTexture,
272 grColorType,
273 origin,
274 alphaType,
275 std::move(colorSpace),
277 nullptr);
278}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kAdopt_GrWrapOwnership
Definition: GrTypesPriv.h:82
GrColorType
Definition: GrTypesPriv.h:540
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
Definition: GrCaps.h:57
static bool ValidateBackendTexture(const GrCaps *, const GrBackendTexture &tex, GrColorType grCT, SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
static sk_sp< SkImage > new_wrapped_texture_common(GrRecordingContext *rContext, const GrBackendTexture &backendTex, GrColorType colorType, GrSurfaceOrigin origin, SkAlphaType at, sk_sp< SkColorSpace > colorSpace, GrWrapOwnership ownership, sk_sp< skgpu::RefCntedCallback > releaseHelper)

◆ AdoptTextureFrom() [4/5]

sk_sp< SkImage > SkImages::AdoptTextureFrom ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture tex,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
skgpu::Origin  origin,
TextureReleaseProc  trProc = nullptr,
ReleaseContext  ctx = nullptr 
)
inline

Definition at line 107 of file Image.h.

114 {
115 return WrapTexture(recorder, tex, colorType, alphaType, colorSpace, origin, trProc, ctx);
116}
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})

◆ AdoptTextureFrom() [5/5]

sk_sp< SkImage > SkImages::AdoptTextureFrom ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture tex,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
TextureReleaseProc  trProc = nullptr,
ReleaseContext  ctx = nullptr 
)
inline

Definition at line 118 of file Image.h.

124 {
125 return WrapTexture(recorder, tex, colorType, alphaType, colorSpace, trProc, ctx);
126}

◆ BorrowTextureFrom()

sk_sp< SkImage > SkImages::BorrowTextureFrom ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
TextureReleaseProc  textureReleaseProc = nullptr,
ReleaseContext  releaseContext = nullptr 
)

Creates GPU-backed SkImage from the provided GPU texture associated with context. GPU texture must stay valid and unchanged until textureReleaseProc is called by Skia. Skia will call textureReleaseProc with the passed-in releaseContext when SkImage is deleted or no longer refers to the texture. A non-null SkImage is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU backend.

Note
When using a DDL recording context, textureReleaseProc will be called on the GPU thread after the DDL is played back on the direct context.
Parameters
contextGPU context
backendTexturetexture residing on GPU
colorSpaceThis describes the color space of this image's contents, as seen after sampling. In general, if the format of the backend texture is SRGB, some linear colorSpace should be supplied (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the backend texture is linear, then the colorSpace should include a description of the transfer function as well (e.g., SkColorSpace::MakeSRGB()).
textureReleaseProcfunction called when texture can be released
releaseContextstate passed to textureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 194 of file SkImage_GaneshFactories.cpp.

201 {
202 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
203
204 if (!context) {
205 return nullptr;
206 }
207
208 const GrCaps* caps = context->priv().caps();
209
211 if (GrColorType::kUnknown == grColorType) {
212 return nullptr;
213 }
214
216 caps, backendTexture, grColorType, colorType, alphaType, colorSpace)) {
217 return nullptr;
218 }
219
220 return new_wrapped_texture_common(context,
221 backendTexture,
222 grColorType,
223 origin,
224 alphaType,
225 std::move(colorSpace),
227 std::move(releaseHelper));
228}
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
const GrCaps * caps() const
GrRecordingContextPriv priv()
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)

◆ CrossContextTextureFromPixmap()

sk_sp< SkImage > SkImages::CrossContextTextureFromPixmap ( GrDirectContext context,
const SkPixmap pixmap,
bool  buildMips,
bool  limitToMaxTextureSize = false 
)

Creates a GPU-backed SkImage from pixmap. It is uploaded to GPU backend using context. Created SkImage is available to other GPU contexts, and is available across thread boundaries. All contexts must be in the same GPU share group, or otherwise share resources. When SkImage is no longer referenced, context releases texture memory asynchronously. SkColorSpace of SkImage is determined by pixmap.colorSpace(). SkImage is returned referring to GPU backend if context is not nullptr, format of data is recognized and supported, and if context supports moving resources between contexts. Otherwise, pixmap pixel data is copied and SkImage as returned in raster format if possible; nullptr may be returned. Recognized GPU formats vary by platform and GPU backend.

Parameters
contextGPU context
pixmapSkImageInfo, pixel address, and row bytes
buildMipscreate SkImage as mip map if true
limitToMaxTextureSizedownscale image to GPU maximum texture size, if necessary
Returns
created SkImage, or nullptr

Definition at line 373 of file SkImage_GaneshFactories.cpp.

376 {
377 // Some backends or drivers don't support (safely) moving resources between contexts
378 if (!dContext || !dContext->priv().caps()->crossContextTextureSupport()) {
379 return RasterFromPixmapCopy(originalPixmap);
380 }
381
382 // If non-power-of-two mipmapping isn't supported, ignore the client's request
383 if (!dContext->priv().caps()->mipmapSupport()) {
384 buildMips = false;
385 }
386
387 const SkPixmap* pixmap = &originalPixmap;
388 SkAutoPixmapStorage resized;
389 int maxTextureSize = dContext->priv().caps()->maxTextureSize();
390 int maxDim = std::max(originalPixmap.width(), originalPixmap.height());
391 if (limitToMaxTextureSize && maxDim > maxTextureSize) {
392 float scale = static_cast<float>(maxTextureSize) / maxDim;
393 int newWidth = std::min(static_cast<int>(originalPixmap.width() * scale), maxTextureSize);
394 int newHeight = std::min(static_cast<int>(originalPixmap.height() * scale), maxTextureSize);
395 SkImageInfo info = originalPixmap.info().makeWH(newWidth, newHeight);
397 if (!resized.tryAlloc(info) || !originalPixmap.scalePixels(resized, sampling)) {
398 return nullptr;
399 }
400 pixmap = &resized;
401 }
402 // Turn the pixmap into a GrTextureProxy
403 SkBitmap bmp;
404 bmp.installPixels(*pixmap);
406 auto [view, ct] = GrMakeUncachedBitmapProxyView(dContext, bmp, mipmapped);
407 if (!view) {
408 return RasterFromPixmapCopy(*pixmap);
409 }
410
411 sk_sp<GrTexture> texture = sk_ref_sp(view.proxy()->peekTexture());
412
413 // Flush any writes or uploads
414 dContext->priv().flushSurface(view.proxy());
415 GrGpu* gpu = dContext->priv().getGpu();
416
417 std::unique_ptr<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
418
421 view.origin(),
422 std::move(sema),
423 skCT,
424 pixmap->alphaType(),
425 pixmap->info().refColorSpace());
426 return DeferredFromTextureGenerator(std::move(gen));
427}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:589
SkColorType
Definition: SkColorType.h:19
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition: SkGr.cpp:253
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static std::unique_ptr< GrTextureGenerator > Make(const sk_sp< GrTexture > &, GrSurfaceOrigin, std::unique_ptr< GrSemaphore >, SkColorType, SkAlphaType, sk_sp< SkColorSpace >)
Definition: GrGpu.h:62
virtual std::unique_ptr< GrSemaphore > prepareTextureForCrossContextUsage(GrTexture *)=0
bool tryAlloc(const SkImageInfo &)
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition: SkBitmap.cpp:323
const SkImageInfo & info() const
Definition: SkPixmap.h:135
SkAlphaType alphaType() const
Definition: SkPixmap.h:175
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
FlTexture * texture
SK_API sk_sp< SkImage > DeferredFromTextureGenerator(std::unique_ptr< GrTextureGenerator > gen)
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
SkSamplingOptions sampling
Definition: SkRecords.h:337
Definition: gen.py:1
Mipmapped
Definition: GpuTypes.h:53
const Scalar scale
sk_sp< SkColorSpace > refColorSpace() const

◆ DeferredFromAHardwareBuffer() [1/2]

SK_API sk_sp< SkImage > SkImages::DeferredFromAHardwareBuffer ( AHardwareBuffer hardwareBuffer,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
GrSurfaceOrigin  surfaceOrigin = kTopLeft_GrSurfaceOrigin 
)

◆ DeferredFromAHardwareBuffer() [2/2]

SK_API sk_sp< SkImage > SkImages::DeferredFromAHardwareBuffer ( AHardwareBuffer hardwareBuffer,
SkAlphaType  alphaType = kPremul_SkAlphaType 
)

(See Skia bug 7447) Creates SkImage from Android hardware buffer. Returned SkImage takes a reference on the buffer. Only available on Android, when ANDROID_API is defined to be 26 or greater.

Parameters
hardwareBufferAHardwareBuffer Android hardware buffer
colorSpacerange of colors; may be nullptr
Returns
created SkImage, or nullptr

◆ DeferredFromEncodedData()

sk_sp< SkImage > SkImages::DeferredFromEncodedData ( sk_sp< SkData encoded,
std::optional< SkAlphaType alphaType = std::nullopt 
)

Return a SkImage using the encoded data, but attempts to defer decoding until the image is actually used/drawn. This deferral allows the system to cache the result, either on the CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may be purged, causing the next draw of the image to have to re-decode.

If alphaType is nullopt, the image's alpha type will be chosen automatically based on the image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr.

If the encoded format is not supported, nullptr is returned.

If possible, clients should use SkCodecs::DeferredImage instead.

Parameters
encodedthe encoded data
Returns
created SkImage, or nullptr

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

Definition at line 52 of file SkImageGenerator_FromEncoded.cpp.

53 {
54 if (nullptr == encoded || encoded->isEmpty()) {
55 return nullptr;
56 }
57 return DeferredFromGenerator(SkImageGenerators::MakeFromEncoded(std::move(encoded), alphaType));
58}
bool isEmpty() const
Definition: SkData.h:32
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)

◆ DeferredFromGenerator()

sk_sp< SkImage > SkImages::DeferredFromGenerator ( std::unique_ptr< SkImageGenerator imageGenerator)

Creates SkImage from data returned by imageGenerator. The image data will not be created (on either the CPU or GPU) until the image is actually drawn. Generated data is owned by SkImage and may not be shared or accessed.

SkImage is returned if generator data is valid. Valid data parameters vary by type of data and platform.

imageGenerator may wrap SkPicture data, codec data, or custom data.

Parameters
imageGeneratorstock or custom routines to retrieve SkImage
Returns
created SkImage, or nullptr

Definition at line 282 of file SkImage_Lazy.cpp.

282 {
283 SkImage_Lazy::Validator validator(
284 SharedGenerator::Make(std::move(generator)), nullptr, nullptr);
285
286 return validator ? sk_make_sp<SkImage_Lazy>(&validator) : nullptr;
287}
static sk_sp< SharedGenerator > Make(std::unique_ptr< SkImageGenerator > gen)

◆ DeferredFromPicture() [1/2]

sk_sp< SkImage > SkImages::DeferredFromPicture ( sk_sp< SkPicture picture,
const SkISize dimensions,
const SkMatrix matrix,
const SkPaint paint,
BitDepth  bitDepth,
sk_sp< SkColorSpace colorSpace 
)

Definition at line 23 of file SkImage_LazyFactories.cpp.

28 {
29 return SkImage_Picture::Make(std::move(picture), dimensions, matrix, paint, bitDepth,
30 std::move(colorSpace), {});
31}
static sk_sp< SkImage > Make(sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, SkImages::BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299

◆ DeferredFromPicture() [2/2]

sk_sp< SkImage > SkImages::DeferredFromPicture ( sk_sp< SkPicture picture,
const SkISize dimensions,
const SkMatrix matrix,
const SkPaint paint,
BitDepth  bitDepth,
sk_sp< SkColorSpace colorSpace,
SkSurfaceProps  props 
)

Creates SkImage from picture. Returned SkImage width and height are set by dimensions. SkImage draws picture with matrix and paint, set to bitDepth and colorSpace.

The Picture data is not turned into an image (CPU or GPU) until it is drawn.

If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws with default SkPaint. colorSpace may be nullptr.

Parameters
picturestream of drawing commands
dimensionswidth and height
matrixSkMatrix to rotate, scale, translate, and so on; may be nullptr
paintSkPaint to apply transparency, filtering, and so on; may be nullptr
bitDepth8-bit integer or 16-bit float: per component
colorSpacerange of colors; may be nullptr
propsprops to use when rasterizing the picture
Returns
created SkImage, or nullptr

Definition at line 33 of file SkImage_LazyFactories.cpp.

39 {
40 return SkImage_Picture::Make(std::move(picture), dimensions, matrix, paint, bitDepth,
41 std::move(colorSpace), props);
42}

◆ DeferredFromTextureGenerator()

sk_sp< SkImage > SkImages::DeferredFromTextureGenerator ( std::unique_ptr< GrTextureGenerator gen)

Like SkImages::DeferredFromGenerator except allows for the use of GrTextureGenerator.

Parameters
genproducer of textures
Returns
created SkImage, or nullptr

Definition at line 62 of file SkImage_LazyTexture.cpp.

62 {
64 SharedGenerator::Make(std::move(generator)), nullptr, nullptr);
65
66 return validator ? sk_make_sp<SkImage_LazyTexture>(&validator) : nullptr;
67}

◆ generate_picture_texture()

static sk_sp< SkImage > SkImages::generate_picture_texture ( skgpu::graphite::Recorder recorder,
const SkImage_Picture img,
const SkImageInfo info,
SkImage::RequiredProperties  requiredProps 
)
static

Definition at line 318 of file ImageFactories.cpp.

321 {
322 auto mm = requiredProps.fMipmapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
323 // Use a non-budgeted surface since the image wrapping the surface's texture will be owned by
324 // the client.
326 info,
327 "LazySkImagePictureTexture",
329 mm,
331 img->props());
332
333 if (!surface) {
334 SKGPU_LOG_E("Failed to create Surface");
335 return nullptr;
336 }
337
338 img->replay(surface->getCanvas());
339 // If the surface was created with mipmaps, they will be automatically generated when flushing
340 // the tasks when 'surface' goes out of scope.
341 return surface->asImage();
342}
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
const SkSurfaceProps * props() const
void replay(SkCanvas *) const
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)

◆ GetBackendTextureFromImage() [1/3]

bool SkImages::GetBackendTextureFromImage ( const sk_sp< const SkImage > &  img,
GrBackendTexture outTexture,
bool  flushPendingGrContextIO,
GrSurfaceOrigin origin = nullptr 
)
inline

Definition at line 279 of file SkImageGanesh.h.

282 {
283 return GetBackendTextureFromImage(img.get(), outTexture, flushPendingGrContextIO, origin);
284}
T * get() const
Definition: SkRefCnt.h:303
bool GetBackendTextureFromImage(GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)

◆ GetBackendTextureFromImage() [2/3]

bool SkImages::GetBackendTextureFromImage ( const SkImage img,
GrBackendTexture outTexture,
bool  flushPendingGrContextIO,
GrSurfaceOrigin origin = nullptr 
)

Retrieves the existing backend texture. If SkImage is not a Ganesh-backend texture image or otherwise does not have such a texture, false is returned. Otherwise, outTexture will be set to the image's texture.

If flushPendingGrContextIO is true, completes deferred I/O operations. If origin in not nullptr, copies location of content drawn into SkImage.

Parameters
outTextureWill be set to the underlying texture of the image if non-null.
flushPendingGrContextIOflag to flush outstanding requests
originWill be set to the origin orientation of the image if non-null.
Returns
false if a Ganesh backend texture cannot be retrieved.

Definition at line 112 of file SkImage_GaneshFactories.cpp.

115 {
116 if (!img) {
117 return false;
118 }
119 auto ib = as_IB(img);
120 if (ib->type() != SkImage_Base::Type::kGanesh) {
121 return false;
122 }
123 auto ig = static_cast<const SkImage_Ganesh*>(img);
124 return ig->getExistingBackendTexture(outTexture, flushPendingGrContextIO, origin);
125}
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
bool getExistingBackendTexture(GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin) const

◆ GetBackendTextureFromImage() [3/3]

bool SkImages::GetBackendTextureFromImage ( GrDirectContext context,
sk_sp< SkImage image,
GrBackendTexture backendTexture,
BackendTextureReleaseProc backendTextureReleaseProc 
)
inline

Definition at line 303 of file SkImageGanesh.h.

306 {
307 return MakeBackendTextureFromImage(context, std::move(image), backendTexture,
308 backendTextureReleaseProc);
309}
SK_API bool MakeBackendTextureFromImage(GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ GetContext() [1/2]

GrDirectContext * SkImages::GetContext ( const sk_sp< const SkImage > &  src)
inline

Definition at line 111 of file SkImageChromium.h.

111 {
112 return GetContext(src.get());
113}
GrDirectContext * GetContext(const sk_sp< const SkImage > &src)

◆ GetContext() [2/2]

GrDirectContext * SkImages::GetContext ( const SkImage src)

Returns the GPU context associated with this image or nullptr if the image is not Ganesh-backed. We expose this only to help transition certain API calls and do not intend for this to stick around forever.

Definition at line 448 of file SkImage_GaneshBase.cpp.

448 {
449 if (!src || !as_IB(src)->isGaneshBacked()) {
450 return nullptr;
451 }
452 return as_IB(src)->directContext();
453}
virtual GrDirectContext * directContext() const
Definition: SkImage_Base.h:115

◆ make_texture_image_from_lazy()

static sk_sp< SkImage > SkImages::make_texture_image_from_lazy ( skgpu::graphite::Recorder recorder,
const SkImage_Lazy img,
SkImage::RequiredProperties  requiredProps 
)
static

Definition at line 350 of file ImageFactories.cpp.

352 {
353 // 1. Ask the generator to natively create one.
354 {
356 sk_sp<SkImage> newImage =
358 static_cast<const SkImage_Picture*>(img),
359 img->imageInfo(),
360 requiredProps);
361 if (newImage) {
362 SkASSERT(as_IB(newImage)->isGraphiteBacked());
363 return newImage;
364 }
365 }
366 // There is not an analog to GrTextureGenerator for Graphite yet, but if there was,
367 // we would want to call it here.
368 }
369
370 // 2. Ask the generator to return a bitmap, which the GPU can convert.
371 {
373 if (img->getROPixels(nullptr, &bitmap, SkImage_Lazy::CachingHint::kDisallow_CachingHint)) {
374 return skgpu::graphite::MakeFromBitmap(recorder,
375 img->imageInfo().colorInfo(),
376 bitmap,
377 nullptr,
379 requiredProps,
380 "LazySkImageBitmapTexture");
381 }
382 }
383
384 return nullptr;
385}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint) const override
SkImage_Base::Type type() const override
Definition: SkImage_Lazy.h:73
const SkImageInfo & imageInfo() const
Definition: SkImage.h:279
static sk_sp< SkImage > generate_picture_texture(skgpu::graphite::Recorder *recorder, const SkImage_Picture *img, const SkImageInfo &info, SkImage::RequiredProperties requiredProps)
Definition: bitmap.py:1
sk_sp< SkImage > MakeFromBitmap(Recorder *recorder, const SkColorInfo &colorInfo, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmaps, Budgeted budgeted, SkImage::RequiredProperties requiredProps, std::string_view label)
const SkColorInfo & colorInfo() const
Definition: SkImageInfo.h:404

◆ MakeBackendTextureFromImage()

bool SkImages::MakeBackendTextureFromImage ( GrDirectContext context,
sk_sp< SkImage image,
GrBackendTexture backendTexture,
BackendTextureReleaseProc backendTextureReleaseProc 
)

Extracts the backendTexture from an existing SkImage. If the image is not already GPU-backed, the raster data will be uploaded as a texture and returned. If this is the only reference to the image, the old image's texture will be moved out of the passed in image. If the image is shared (has a refcount > 1), the texture will be copied and then returned.

Parameters
contextGPU context
imageimage, either CPU-backed or GPU-backed
backendTextureWill be set to the underlying texture of the image.
backendTextureReleaseProcCalled when the texture is released
Returns
false if image cannot be uploaded.

Definition at line 67 of file SkImage_GaneshFactories.cpp.

70 {
71 if (!image || !backendTexture || !releaseProc) {
72 return false;
73 }
74
75 auto [view, ct] = skgpu::ganesh::AsView(direct, image, skgpu::Mipmapped::kNo);
76 if (!view) {
77 return false;
78 }
79
80 // Flush any pending IO on the texture.
81 direct->priv().flushSurface(view.proxy());
82
83 GrTexture* texture = view.asTextureProxy()->peekTexture();
84 if (!texture) {
85 return false;
86 }
87 // We must make a copy of the image if the image is not unique, if the GrTexture owned by the
88 // image is not unique, or if the texture wraps an external object.
89 if (!image->unique() || !texture->unique() || texture->resourcePriv().refsWrappedObjects()) {
90 // onMakeSubset will always copy the image.
91 image = as_IB(image)->onMakeSubset(direct, image->bounds());
92 if (!image) {
93 return false;
94 }
95 return MakeBackendTextureFromImage(direct, std::move(image), backendTexture, releaseProc);
96 }
97
98 SkASSERT(!texture->resourcePriv().refsWrappedObjects());
99 SkASSERT(texture->unique());
101
102 // Take a reference to the GrTexture and release the image.
103 sk_sp<GrTexture> textureRef = sk_ref_sp(texture);
104 view.reset();
105 image = nullptr;
106 SkASSERT(textureRef->unique());
107
108 // Steal the backend texture from the GrTexture, releasing the GrTexture in the process.
109 return GrTexture::StealBackendTexture(std::move(textureRef), backendTexture, releaseProc);
110}
static void releaseProc(const void *ptr, void *context)
bool unique() const
Definition: GrGpuResource.h:47
static bool StealBackendTexture(sk_sp< GrTexture >, GrBackendTexture *, SkImages::BackendTextureReleaseProc *)
Definition: GrTexture.cpp:61
virtual sk_sp< SkImage > onMakeSubset(GrDirectContext *, const SkIRect &) const =0
SkIRect bounds() const
Definition: SkImage.h:303
bool unique() const
Definition: SkRefCnt.h:50
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)

◆ MakeWithFilter() [1/3]

sk_sp< SkImage > SkImages::MakeWithFilter ( GrRecordingContext context,
sk_sp< SkImage src,
const SkImageFilter filter,
const SkIRect subset,
const SkIRect clipBounds,
SkIRect outSubset,
SkIPoint offset 
)

Creates a filtered SkImage on the GPU. filter processes the src image, potentially changing color, position, and size. subset is the bounds of src that are processed by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset is required storage for the actual bounds of the filtered SkImage. offset is required storage for translation of returned SkImage.

Returns nullptr if SkImage could not be created or if the recording context provided doesn't match the GPU context in which the image was created. If nullptr is returned, outSubset and offset are undefined.

Useful for animation of SkImageFilter that varies size from frame to frame. Returned SkImage is created larger than required by filter so that GPU texture can be reused with different sized effects. outSubset describes the valid bounds of GPU texture returned. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other.

Parameters
contextthe GrRecordingContext in play - if it exists
filterhow SkImage is sampled when transformed
subsetbounds of SkImage processed by filter
clipBoundsexpected bounds of filtered SkImage
outSubsetstorage for returned SkImage bounds
offsetstorage for returned SkImage translation
Returns
filtered SkImage, or nullptr

Definition at line 421 of file SkImage_GaneshBase.cpp.

427 {
428 if (!rContext || !src || !filter) {
429 return nullptr;
430 }
431
433 if (as_IB(src)->isGaneshBacked()) {
434 SkImage_GaneshBase* base = static_cast<SkImage_GaneshBase*>(src.get());
435 origin = base->origin();
436 }
437
439 skif::MakeGaneshBackend(sk_ref_sp(rContext), origin, {}, src->colorType());
440 return as_IFB(filter)->makeImageWithFilter(std::move(backend),
441 std::move(src),
442 subset,
443 clipBounds,
444 outSubset,
445 offset);
446}
const char * backend
GrSurfaceOrigin
Definition: GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
static SkImageFilter_Base * as_IFB(SkImageFilter *filter)
sk_sp< SkImage > makeImageWithFilter(sk_sp< skif::Backend > backend, sk_sp< SkImage > src, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset) const
sk_sp< Backend > MakeGaneshBackend(sk_sp< GrRecordingContext > context, GrSurfaceOrigin origin, const SkSurfaceProps &surfaceProps, SkColorType colorType)
SeparatedVector2 offset

◆ MakeWithFilter() [2/3]

sk_sp< SkImage > SkImages::MakeWithFilter ( sk_sp< SkImage src,
const SkImageFilter filter,
const SkIRect subset,
const SkIRect clipBounds,
SkIRect outSubset,
SkIPoint offset 
)

Creates a filtered SkImage on the CPU. filter processes the src image, potentially changing the color, position, and size. subset is the bounds of src that are processed by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset is required storage for the actual bounds of the filtered SkImage. offset is required storage for translation of returned SkImage.

Returns nullptr a filtered result could not be created. If nullptr is returned, outSubset and offset are undefined.

Useful for animation of SkImageFilter that varies size from frame to frame. outSubset describes the valid bounds of returned image. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other.

Parameters
srcthe image to be filtered
filterthe image filter to be applied
subsetbounds of SkImage processed by filter
clipBoundsexpected bounds of filtered SkImage
outSubsetstorage for returned SkImage bounds
offsetstorage for returned SkImage translation
Returns
filtered SkImage, or nullptr

Definition at line 100 of file SkImage_RasterFactories.cpp.

105 {
106 if (!src || !filter) {
107 return nullptr;
108 }
109
111 return as_IFB(filter)->makeImageWithFilter(std::move(backend),
112 std::move(src),
113 subset,
114 clipBounds,
115 outSubset,
116 offset);
117}
sk_sp< Backend > MakeRasterBackend(const SkSurfaceProps &surfaceProps, SkColorType colorType)

◆ MakeWithFilter() [3/3]

sk_sp< SkImage > SkImages::MakeWithFilter ( skgpu::graphite::Recorder recorder,
sk_sp< SkImage src,
const SkImageFilter filter,
const SkIRect subset,
const SkIRect clipBounds,
SkIRect outSubset,
SkIPoint offset 
)

Creates a filtered SkImage on the GPU. filter processes the src image, potentially changing color, position, and size. subset is the bounds of src that are processed by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset is required storage for the actual bounds of the filtered SkImage. offset is required storage for translation of returned SkImage.

Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset and offset are undefined.

Useful for animation of SkImageFilter that varies size from frame to frame. Returned SkImage is created larger than required by filter so that GPU texture can be reused with different sized effects. outSubset describes the valid bounds of GPU texture returned. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other.

Parameters
recorderthe recorder in which the filtering operation is to be performed
filterhow SkImage is sampled when transformed
subsetbounds of SkImage processed by filter
clipBoundsexpected bounds of filtered SkImage
outSubsetstorage for returned SkImage bounds
offsetstorage for returned SkImage translation
Returns
filtered SkImage, or nullptr

Definition at line 298 of file ImageFactories.cpp.

304 {
305 if (!recorder || !src || !filter) {
306 return nullptr;
307 }
308
309 sk_sp<skif::Backend> backend = skif::MakeGraphiteBackend(recorder, {}, src->colorType());
310 return as_IFB(filter)->makeImageWithFilter(std::move(backend),
311 std::move(src),
312 subset,
313 clipBounds,
314 outSubset,
315 offset);
316}
sk_sp< Backend > MakeGraphiteBackend(skgpu::graphite::Recorder *recorder, const SkSurfaceProps &surfaceProps, SkColorType colorType)

◆ new_wrapped_texture_common()

static sk_sp< SkImage > SkImages::new_wrapped_texture_common ( GrRecordingContext rContext,
const GrBackendTexture backendTex,
GrColorType  colorType,
GrSurfaceOrigin  origin,
SkAlphaType  at,
sk_sp< SkColorSpace colorSpace,
GrWrapOwnership  ownership,
sk_sp< skgpu::RefCntedCallback releaseHelper 
)
static

Definition at line 167 of file SkImage_GaneshFactories.cpp.

174 {
175 if (!backendTex.isValid() || backendTex.width() <= 0 || backendTex.height() <= 0) {
176 return nullptr;
177 }
178
179 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
180 sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
181 backendTex, ownership, GrWrapCacheable::kNo, kRead_GrIOType, std::move(releaseHelper));
182 if (!proxy) {
183 return nullptr;
184 }
185
186 skgpu::Swizzle swizzle =
187 rContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType);
188 GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
189 SkColorInfo info(GrColorTypeToSkColorType(colorType), at, std::move(colorSpace));
190 return sk_make_sp<SkImage_Ganesh>(
191 sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(view), std::move(info));
192}
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
@ kNeedNewImageUniqueID
Definition: SkImage_Base.h:33
bool isValid() const
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition: GrCaps.cpp:443
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
GrProxyProvider * proxyProvider()
const GrBackendFormat & backendFormat() const

◆ PinnableRasterFromBitmap()

sk_sp< SkImage > SkImages::PinnableRasterFromBitmap ( const SkBitmap bm)

Like SkImagePriv::SkMakeImageFromRasterBitmap, except this can be pinned using skgpu::ganesh::PinAsTexture and CopyPixelMode is never.

Definition at line 54 of file SkImage_RasterPinnable.cpp.

54 {
55 if (!SkImageInfoIsValid(bm.info()) || bm.rowBytes() < bm.info().minRowBytes()) {
56 return nullptr;
57 }
58
59 return sk_make_sp<SkImage_RasterPinnable>(bm);
60}
static bool SkImageInfoIsValid(const SkImageInfo &info)
size_t rowBytes() const
Definition: SkBitmap.h:238
const SkImageInfo & info() const
Definition: SkBitmap.h:139
size_t minRowBytes() const
Definition: SkImageInfo.h:517

◆ PromiseTextureFrom() [1/3]

sk_sp< SkImage > SkImages::PromiseTextureFrom ( sk_sp< GrContextThreadSafeProxy gpuContextProxy,
const GrBackendFormat backendFormat,
SkISize  dimensions,
skgpu::Mipmapped  mipmapped,
GrSurfaceOrigin  origin,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
PromiseImageTextureFulfillProc  textureFulfillProc,
PromiseImageTextureReleaseProc  textureReleaseProc,
PromiseImageTextureContext  textureContext 
)

Create a new GPU-backed SkImage that is very similar to an SkImage created by BorrowTextureFrom. The difference is that the caller need not have created the texture nor populated it with the image pixel data. Moreover, the SkImage may be created on a thread as the creation of the image does not require access to the backend API or GrDirectContext. Instead of passing a GrBackendTexture the client supplies a description of the texture consisting of GrBackendFormat, width, height, and skgpu::Mipmapped state. The resulting SkImage can be drawn to a GrDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. When the actual texture is required to perform a backend API draw, textureFulfillProc will be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match those set during the SkImage creation, and it must refer to a valid existing texture in the backend API context/device, and be populated with the image pixel data. The texture cannot be deleted until textureReleaseProc is called. There is at most one call to each of textureFulfillProc and textureReleaseProc. textureReleaseProc is always called even if image creation fails or if the image is never fulfilled (e.g. it is never drawn or all draws are clipped out)

Parameters
gpuContextProxythe thread-safe proxy of the gpu context. required.
backendFormatformat of promised gpu texture
dimensionswidth & height of promised gpu texture
mipmappedmip mapped state of promised gpu texture
originsurface origin of promised gpu texture
colorTypecolor type of promised gpu texture
alphaTypealpha type of promised gpu texture
colorSpacerange of colors; may be nullptr
textureFulfillProcfunction called to get actual gpu texture
textureReleaseProcfunction called when texture can be deleted
textureContextstate passed to textureFulfillProc and textureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 316 of file SkImage_GaneshFactories.cpp.

326 {
327 // Our contract is that we will always call the release proc even on failure.
328 // We use the helper to convey the context, so we need to ensure make doesn't fail.
329 textureReleaseProc = textureReleaseProc ? textureReleaseProc : [](void*) {};
330 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, textureContext);
331 SkImageInfo info = SkImageInfo::Make(dimensions, colorType, alphaType, colorSpace);
332 if (!SkImageInfoIsValid(info)) {
333 return nullptr;
334 }
335
336 if (!threadSafeProxy) {
337 return nullptr;
338 }
339
340 if (dimensions.isEmpty()) {
341 return nullptr;
342 }
343
345 if (GrColorType::kUnknown == grColorType) {
346 return nullptr;
347 }
348
349 if (!threadSafeProxy->priv().caps()->areColorTypeAndFormatCompatible(grColorType,
350 backendFormat)) {
351 return nullptr;
352 }
353
354 auto proxy = SkImage_GaneshBase::MakePromiseImageLazyProxy(threadSafeProxy.get(),
355 dimensions,
356 backendFormat,
357 mipmapped,
358 textureFulfillProc,
359 std::move(releaseHelper));
360 if (!proxy) {
361 return nullptr;
362 }
363 skgpu::Swizzle swizzle =
364 threadSafeProxy->priv().caps()->getReadSwizzle(backendFormat, grColorType);
365 GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
366 sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy)));
367 return sk_make_sp<SkImage_Ganesh>(std::move(ctx),
369 std::move(view),
370 SkColorInfo(colorType, alphaType, std::move(colorSpace)));
371}
static sk_sp< GrImageContext > MakeForPromiseImage(sk_sp< GrContextThreadSafeProxy > tsp)
static sk_sp< GrTextureProxy > MakePromiseImageLazyProxy(GrContextThreadSafeProxy *, SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, SkImages::PromiseImageTextureFulfillProc, sk_sp< skgpu::RefCntedCallback > releaseHelper)
bool isEmpty() const
Definition: SkSize.h:31
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ PromiseTextureFrom() [2/3]

sk_sp< SkImage > SkImages::PromiseTextureFrom ( skgpu::graphite::Recorder recorder,
SkISize  dimensions,
const skgpu::graphite::TextureInfo textureInfo,
const SkColorInfo colorInfo,
skgpu::graphite::Volatile  isVolatile,
GraphitePromiseTextureFulfillProc  fulfillProc,
GraphitePromiseImageReleaseProc  imageReleaseProc,
GraphitePromiseTextureReleaseProc  textureReleaseProc,
GraphitePromiseImageContext  imageContext 
)

Definition at line 218 of file ImageFactories.cpp.

226 {
227 return PromiseTextureFrom(recorder,
228 dimensions,
229 textureInfo,
230 colorInfo,
232 isVolatile,
233 fulfillProc,
234 imageReleaseProc,
235 textureReleaseProc,
236 imageContext);
237}
SK_API sk_sp< SkImage > PromiseTextureFrom(skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::Origin origin, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext, std::string_view label={})

◆ PromiseTextureFrom() [3/3]

sk_sp< SkImage > SkImages::PromiseTextureFrom ( skgpu::graphite::Recorder recorder,
SkISize  dimensions,
const skgpu::graphite::TextureInfo textureInfo,
const SkColorInfo colorInfo,
skgpu::Origin  origin,
skgpu::graphite::Volatile  isVolatile,
GraphitePromiseTextureFulfillProc  fulfillProc,
GraphitePromiseImageReleaseProc  imageReleaseProc,
GraphitePromiseTextureReleaseProc  textureReleaseProc,
GraphitePromiseImageContext  imageContext,
std::string_view  label = {} 
)

Create a new SkImage that is very similar to an SkImage created by WrapTexture. The difference is that the caller need not have created the backend texture nor populated it with data when creating the image. Instead of passing a BackendTexture to the factory the client supplies a description of the texture consisting of dimensions, TextureInfo, SkColorInfo and Volatility.

In general, 'fulfill' must return a BackendTexture that matches the properties provided at SkImage creation time. The BackendTexture must refer to a valid existing texture in the backend API context/device, and already be populated with data. The texture cannot be deleted until 'textureRelease' is called. 'textureRelease' will be called with the textureReleaseContext returned by 'fulfill'.

Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will be called:

For non-volatile promise images, 'fulfill' will be called at Context::insertRecording time. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be called only once - when Skia will no longer try calling 'fulfill' to get a backend texture. If 'fulfill' failed (i.e., it didn't return a valid backend texture) then 'textureRelease' will never be called. If 'fulfill' was successful then 'textureRelease' will be called only once when the GPU is done with the contents of the promise image. This will usually occur during a Context::submit call but it could occur earlier due to error conditions. 'fulfill' can be called multiple times if the promise image is used in multiple recordings. If 'fulfill' fails, the insertRecording itself will fail. Subsequent insertRecording calls (with Recordings that use the promise image) will keep calling 'fulfill' until it succeeds.

For volatile promise images, 'fulfill' will be called each time the Recording is inserted into a Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be called only once just like the non-volatile case. If 'fulfill' fails at insertRecording-time, 'textureRelease' will never be called. If 'fulfill' was successful then a 'textureRelease' matching that 'fulfill' will be called when the GPU is done with the contents of the promise image. This will usually occur during a Context::submit call but it could occur earlier due to error conditions.

Parameters
recorderthe recorder that will capture the commands creating the image
dimensionswidth & height of promised gpu texture
textureInfostructural information for the promised gpu texture
colorInfocolor type, alpha type and colorSpace information for the image
originWhether the Texture logically treats the origin as TopLeft or BottomLeft
isVolatilevolatility of the promise image
fulfillfunction called to get the actual backend texture, and the instance for the GraphitePromiseTextureReleaseProc
imageReleasefunction called when any image-centric data can be deleted
textureReleasefunction called when the backend texture can be deleted
imageContextstate passed to fulfill and imageRelease
Returns
created SkImage, or nullptr

Definition at line 165 of file ImageFactories.cpp.

175 {
176 // Our contract is that we will always call the _image_ release proc even on failure.
177 // We use the helper to convey the imageContext, so we need to ensure Make doesn't fail.
178 imageReleaseProc = imageReleaseProc ? imageReleaseProc : [](void*) {};
179 auto releaseHelper = skgpu::RefCntedCallback::Make(imageReleaseProc, imageContext);
180
181 if (!recorder) {
182 SKGPU_LOG_W("Null Recorder");
183 return nullptr;
184 }
185
186 const Caps* caps = recorder->priv().caps();
187
188 SkImageInfo info = SkImageInfo::Make(dimensions, colorInfo);
189 if (!SkImageInfoIsValid(info)) {
190 SKGPU_LOG_W("Invalid SkImageInfo");
191 return nullptr;
192 }
193
194 if (!caps->areColorTypeAndTextureInfoCompatible(colorInfo.colorType(), textureInfo)) {
195 SKGPU_LOG_W("Incompatible SkColorType and TextureInfo");
196 return nullptr;
197 }
198
199 // Non-YUVA promise images use the 'imageContext' for both the release proc and fulfill proc.
201 dimensions,
202 textureInfo,
203 isVolatile,
204 std::move(releaseHelper),
205 fulfillProc,
206 imageContext,
207 textureReleaseProc,
208 std::move(label));
209 if (!proxy) {
210 return nullptr;
211 }
212
213 skgpu::Swizzle swizzle = caps->getReadSwizzle(colorInfo.colorType(), textureInfo);
214 TextureProxyView view(std::move(proxy), swizzle, origin);
215 return sk_make_sp<Image>(view, colorInfo);
216}
#define SKGPU_LOG_W(fmt,...)
Definition: Log.h:40
SkColorType colorType() const
Definition: SkImageInfo.h:140
const Caps * caps() const
Definition: RecorderPriv.h:31
sk_sp< TextureProxy > MakePromiseImageLazyProxy(const Caps *caps, SkISize dimensions, TextureInfo textureInfo, Volatile isVolatile, sk_sp< RefCntedCallback > releaseHelper, GraphitePromiseTextureFulfillProc fulfillProc, GraphitePromiseTextureFulfillContext fulfillContext, GraphitePromiseTextureReleaseProc textureReleaseProc, std::string_view label)

◆ PromiseTextureFromYUVA() [1/2]

sk_sp< SkImage > SkImages::PromiseTextureFromYUVA ( sk_sp< GrContextThreadSafeProxy gpuContextProxy,
const GrYUVABackendTextureInfo backendTextureInfo,
sk_sp< SkColorSpace imageColorSpace,
PromiseImageTextureFulfillProc  textureFulfillProc,
PromiseImageTextureReleaseProc  textureReleaseProc,
PromiseImageTextureContext  textureContexts[] 
)

This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In the extreme Y, U, V, and A are all in different planes and thus the image is specified by four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and 'textureReleaseProc' calls are made for each texture. Each texture has its own PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one entry for each of the up to four textures, as indicated by 'backendTextureInfo'. Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the near future it will be required that if it is kYes then textureFulfillProc must return a mip mapped texture for each plane in order to successfully draw the image.

Parameters
gpuContextProxythe thread-safe proxy of the gpu context. required.
backendTextureInfoinfo about the promised yuva gpu texture
imageColorSpacerange of colors; may be nullptr
textureFulfillProcfunction called to get actual gpu texture
textureReleaseProcfunction called when texture can be deleted
textureContextsstate passed to textureFulfillProc and textureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 395 of file SkImage_GaneshYUVA.cpp.

400 {
401 if (!backendTextureInfo.isValid()) {
402 return nullptr;
403 }
404
405 SkISize planeDimensions[SkYUVAInfo::kMaxPlanes];
406 int n = backendTextureInfo.yuvaInfo().planeDimensions(planeDimensions);
407
408 // Our contract is that we will always call the release proc even on failure.
409 // We use the helper to convey the context, so we need to ensure make doesn't fail.
410 textureReleaseProc = textureReleaseProc ? textureReleaseProc : [](void*) {};
411 sk_sp<skgpu::RefCntedCallback> releaseHelpers[4];
412 for (int i = 0; i < n; ++i) {
413 releaseHelpers[i] = skgpu::RefCntedCallback::Make(textureReleaseProc, textureContexts[i]);
414 }
415
416 if (!threadSafeProxy) {
417 return nullptr;
418 }
419
420 SkAlphaType at =
421 backendTextureInfo.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
423 backendTextureInfo.yuvaInfo().dimensions(), kAssumedColorType, at, imageColorSpace);
424 if (!SkImageInfoIsValid(info)) {
425 return nullptr;
426 }
427
428 // Make a lazy proxy for each plane
429 sk_sp<GrSurfaceProxy> proxies[4];
430 for (int i = 0; i < n; ++i) {
431 proxies[i] =
433 planeDimensions[i],
434 backendTextureInfo.planeFormat(i),
436 textureFulfillProc,
437 std::move(releaseHelpers[i]));
438 if (!proxies[i]) {
439 return nullptr;
440 }
441 }
442 GrYUVATextureProxies yuvaTextureProxies(
443 backendTextureInfo.yuvaInfo(), proxies, backendTextureInfo.textureOrigin());
444 SkASSERT(yuvaTextureProxies.isValid());
445 sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy)));
446 return sk_make_sp<SkImage_GaneshYUVA>(std::move(ctx),
448 std::move(yuvaTextureProxies),
449 std::move(imageColorSpace));
450}
SkAlphaType
Definition: SkAlphaType.h:26
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
static constexpr auto kAssumedColorType
const SkYUVAInfo & yuvaInfo() const
GrSurfaceOrigin textureOrigin() const
const GrBackendFormat & planeFormat(int i) const
static constexpr int kMaxPlanes
Definition: SkYUVAInfo.h:98
bool hasAlpha() const
Definition: SkYUVAInfo.h:185
int planeDimensions(SkISize planeDimensions[kMaxPlanes]) const
Definition: SkYUVAInfo.h:192
SkISize dimensions() const
Definition: SkYUVAInfo.h:171
Definition: SkSize.h:16

◆ PromiseTextureFromYUVA() [2/2]

sk_sp< SkImage > SkImages::PromiseTextureFromYUVA ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::YUVABackendTextureInfo backendTextureInfo,
sk_sp< SkColorSpace imageColorSpace,
skgpu::graphite::Volatile  isVolatile,
GraphitePromiseTextureFulfillProc  fulfillProc,
GraphitePromiseImageReleaseProc  imageReleaseProc,
GraphitePromiseTextureReleaseProc  textureReleaseProc,
GraphitePromiseImageContext  imageContext,
GraphitePromiseTextureFulfillContext  planeContexts[],
std::string_view  label = {} 
)

This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In the extreme Y, U, V, and A are all in different planes and thus the image is specified by four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, and conversion to RGB. Separate 'fulfill' and 'textureRelease' calls are made for each texture. Each texture has its own GraphitePromiseFulfillContext. The GraphitePromiseImageReleaseProc will be made even on failure. 'planeContexts' has one entry for each of the up to four textures, as indicated by 'backendTextureInfo'. Currently the mipmapped property of 'backendTextureInfo' is ignored. However, in the near future it will be required that if it is kYes then the fulfillProc must return a mip mapped texture for each plane in order to successfully draw the image.

Parameters
recorderthe recorder that will capture the commands creating the image
backendTextureInfoinfo about the promised yuva gpu texture(s)
imageColorSpacerange of colors; may be nullptr
isVolatilevolatility of the promise image
fulfillfunction called to get the actual backend texture for a given GraphitePromiseTextureContext, and the instance for the GraphitePromiseTextureReleaseProc
imageReleasefunction called when any image-centric data can be deleted
textureReleasefunction called when the backend texture can be deleted
imageContextstate passed to imageRelease
planeContextsstates passed to fulfill for each plane
Returns
created SkImage, or nullptr

Definition at line 239 of file ImageFactories.cpp.

248 {
249 // Our contract is that we will always call the _image_ release proc even on failure.
250 // We use the helper to convey the imageContext, so we need to ensure Make doesn't fail.
251 auto releaseHelper = skgpu::RefCntedCallback::Make(imageReleaseProc, imageContext);
252 if (!recorder) {
253 return nullptr;
254 }
255 // Precompute the dimensions for all promise texture planes
256 SkISize planeDimensions[SkYUVAInfo::kMaxPlanes];
257 if (!backendTextureInfo.yuvaInfo().planeDimensions(planeDimensions)) {
258 return nullptr;
259 }
260
261 std::string labelStr(label);
262 if (labelStr.empty()) {
263 labelStr = "Wrapped_PromiseYUVPlane";
264 } else {
265 labelStr += "_PromiseYUVPlane";
266 }
267
268 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
269 for (int i = 0; i < backendTextureInfo.numPlanes(); ++i) {
271 recorder->priv().caps(),
272 planeDimensions[i],
273 backendTextureInfo.planeTextureInfo(i),
274 isVolatile,
275 releaseHelper,
276 fulfillProc,
277 planeContexts[i],
278 textureReleaseProc,
279 labelStr);
280 // Promise YUVA images assume the default rgba swizzle.
281 planes[i] = TextureProxyView(std::move(lazyProxy));
282 }
283 return Image_YUVA::Make(recorder->priv().caps(), backendTextureInfo.yuvaInfo(),
284 SkSpan(planes), std::move(imageColorSpace));
285}
const TextureInfo & planeTextureInfo(int i) const

◆ RasterFromBitmap()

sk_sp< SkImage > SkImages::RasterFromBitmap ( const SkBitmap bitmap)

Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap is marked immutable, and its pixel memory is shareable, it may be shared instead of copied.

SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.

Parameters
bitmapSkImageInfo, row bytes, and pixels
Returns
created SkImage, or nullptr

Definition at line 74 of file SkImage_RasterFactories.cpp.

74 {
75 if (!bm.pixelRef()) {
76 return nullptr;
77 }
78
80}
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
@ kIfMutable_SkCopyPixelsMode
only copy src pixels if they are marked mutable
Definition: SkImagePriv.h:18

◆ RasterFromCompressedTextureData()

sk_sp< SkImage > SkImages::RasterFromCompressedTextureData ( sk_sp< SkData data,
int  width,
int  height,
SkTextureCompressionType  type 
)

Creates a CPU-backed SkImage from compressed data.

This method will decompress the compressed data and create an image wrapping it. Any mipmap levels present in the compressed data are discarded.

Parameters
datacompressed data to store in SkImage
widthwidth of full SkImage
heightheight of full SkImage
typetype of compression used
Returns
created SkImage, or nullptr

Definition at line 122 of file SkImage_RasterFactories.cpp.

125 {
126 size_t expectedSize = SkCompressedFormatDataSize(type, {width, height}, false);
127 if (!data || data->size() < expectedSize) {
128 return nullptr;
129 }
130
131 SkAlphaType at =
133
135
136 if (!valid_args(ii, ii.minRowBytes(), nullptr)) {
137 return nullptr;
138 }
139
141 if (!bitmap.tryAllocPixels(ii)) {
142 return nullptr;
143 }
144
145 if (!SkDecompress(std::move(data), {width, height}, type, &bitmap)) {
146 return nullptr;
147 }
148
149 bitmap.setImmutable();
150 return RasterFromBitmap(bitmap);
151}
bool SkDecompress(sk_sp< SkData > data, SkISize dimensions, SkTextureCompressionType compressionType, SkBitmap *dst)
size_t SkCompressedFormatDataSize(SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
static constexpr bool SkTextureCompressionTypeIsOpaque(SkTextureCompressionType compression)
static bool valid_args(const SkImageInfo &info, size_t rowBytes, size_t *minSize)
GLenum type
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
int32_t height
int32_t width
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ RasterFromData()

sk_sp< SkImage > SkImages::RasterFromData ( const SkImageInfo info,
sk_sp< SkData pixels,
size_t  rowBytes 
)

Creates CPU-backed SkImage from pixel data described by info. The pixels data will not be copied.

SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; rowBytes are large enough to hold one row of pixels; pixels is not nullptr, and contains enough data for SkImage.

Parameters
infocontains width, height, SkAlphaType, SkColorType, SkColorSpace
pixelsaddress or pixel storage
rowBytessize of pixel row or larger
Returns
SkImage sharing pixels, or nullptr

Definition at line 86 of file SkImage_RasterFactories.cpp.

86 {
87 size_t size;
88 if (!valid_args(info, rowBytes, &size) || !data) {
89 return nullptr;
90 }
91
92 // did they give us enough data?
93 if (data->size() < size) {
94 return nullptr;
95 }
96
97 return sk_make_sp<SkImage_Raster>(info, std::move(data), rowBytes);
98}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ RasterFromPixmap()

sk_sp< SkImage > SkImages::RasterFromPixmap ( const SkPixmap pixmap,
RasterReleaseProc  rasterReleaseProc,
ReleaseContext  releaseContext 
)

Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and unchanged until rasterReleaseProc is called. rasterReleaseProc is passed releaseContext when SkImage is deleted or no longer refers to pixmap pixels.

Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc does not require state.

SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.

Parameters
pixmapSkImageInfo, pixel address, and row bytes
rasterReleaseProcfunction called when pixels can be released; or nullptr
releaseContextstate passed to rasterReleaseProc; or nullptr
Returns
SkImage sharing pixmap

Definition at line 153 of file SkImage_RasterFactories.cpp.

153 {
154 size_t size;
155 if (!valid_args(pmap.info(), pmap.rowBytes(), &size) || !pmap.addr()) {
156 return nullptr;
157 }
158
159 sk_sp<SkData> data(SkData::MakeWithProc(pmap.addr(), size, proc, ctx));
160 return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes());
161}
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
Definition: SkData.cpp:128

◆ RasterFromPixmapCopy()

sk_sp< SkImage > SkImages::RasterFromPixmapCopy ( const SkPixmap pixmap)

Creates a CPU-backed SkImage from pixmap, copying the pixel data. As a result, pixmap pixels may be modified or deleted without affecting SkImage.

SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.

Parameters
pixmapSkImageInfo, pixel address, and row bytes
Returns
copy of SkPixmap pixels, or nullptr

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

Definition at line 82 of file SkImage_RasterFactories.cpp.

82 {
84}
sk_sp< SkImage > MakeRasterCopyPriv(const SkPixmap &pmap, uint32_t id)

◆ SubsetTextureFrom() [1/2]

sk_sp< SkImage > SkImages::SubsetTextureFrom ( GrDirectContext context,
const SkImage img,
const SkIRect subset 
)

Returns subset of this image as a texture-backed 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
  • The source image is texture-backed and context does not match the source image's context.
Parameters
contextthe non-null GrDirectContext to which the subset should be uploaded.
subsetbounds of returned SkImage
Returns
the subsetted image, uploaded as a texture, or nullptr

Definition at line 411 of file SkImage_GaneshBase.cpp.

413 {
414 if (context == nullptr || img == nullptr) {
415 return nullptr;
416 }
417 auto subsetImg = img->makeSubset(context, subset);
418 return SkImages::TextureFromImage(context, subsetImg.get());
419}
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)

◆ SubsetTextureFrom() [2/2]

sk_sp< SkImage > SkImages::SubsetTextureFrom ( skgpu::graphite::Recorder recorder,
const SkImage img,
const SkIRect subset,
SkImage::RequiredProperties  props = {} 
)

Returns subset of this image as a texture-backed 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
  • The source image is texture-backed and context does not match the source image's context.
Parameters
recorderthe non-null recorder in which to create the new image.
imgSource image
subsetbounds of returned SkImage
propsproperties the returned SkImage must possess (e.g. mipmaps)
Returns
the subsetted image, uploaded as a texture, or nullptr

Definition at line 287 of file ImageFactories.cpp.

290 {
291 if (!recorder || !img) {
292 return nullptr;
293 }
294 auto subsetImg = img->makeSubset(recorder, subset, props);
295 return SkImages::TextureFromImage(recorder, subsetImg, props);
296}

◆ TextureFromAHardwareBufferWithData()

SK_API sk_sp< SkImage > SkImages::TextureFromAHardwareBufferWithData ( GrDirectContext context,
const SkPixmap pixmap,
AHardwareBuffer hardwareBuffer,
GrSurfaceOrigin  surfaceOrigin = kTopLeft_GrSurfaceOrigin 
)

Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. Returned SkImage takes a reference on the buffer. Only available on Android, when ANDROID_API is defined to be 26 or greater.

Parameters
contextGPU context
pixmapSkPixmap that contains data to be uploaded to the AHardwareBuffer
hardwareBufferAHardwareBuffer Android hardware buffer
surfaceOriginsurface origin for resulting image
Returns
created SkImage, or nullptr

◆ TextureFromCompressedTexture()

sk_sp< SkImage > SkImages::TextureFromCompressedTexture ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
TextureReleaseProc  textureReleaseProc = nullptr,
ReleaseContext  releaseContext = nullptr 
)

Creates a GPU-backed SkImage from a GPU backend texture. The backend texture must stay valid and unchanged until textureReleaseProc is called. The textureReleaseProc is called when the SkImage is deleted or no longer refers to the texture and will be passed the releaseContext. An SkImage is returned if the format of backendTexture is recognized and supported. Recognized formats vary by GPU backend.

Note
When using a DDL recording context, textureReleaseProc will be called on the GPU thread after the DDL is played back on the direct context.
Parameters
contextthe GPU context
backendTexturea texture already allocated by the GPU
alphaTypeThis characterizes the nature of the alpha values in the backend texture. For opaque compressed formats (e.g., ETC1) this should usually be set to kOpaq ue_SkAlphaType.
colorSpaceThis describes the color space of this image's contents, as seen after sampling. In general, if the format of the backend texture is SRGB, some linear colorSpace should be supplied (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the backend texture is linear, then the colorSpace should include a description of the transfer function as well (e.g., SkColorSpace::MakeSRGB()).
textureReleaseProcfunction called when the backend texture can be released
releaseContextstate passed to textureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 127 of file SkImage_GaneshFactories.cpp.

133 {
134 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
135
136 if (!context) {
137 return nullptr;
138 }
139
140 const GrCaps* caps = context->priv().caps();
141
142 if (!SkImage_GaneshBase::ValidateCompressedBackendTexture(caps, backendTexture, alphaType)) {
143 return nullptr;
144 }
145
146 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
148 proxyProvider->wrapCompressedBackendTexture(backendTexture,
151 std::move(releaseHelper));
152 if (!proxy) {
153 return nullptr;
154 }
155
159
160 GrSurfaceProxyView view(std::move(proxy), origin, skgpu::Swizzle::RGBA());
161 return sk_make_sp<SkImage_Ganesh>(sk_ref_sp(context),
163 std::move(view),
164 SkColorInfo(ct, alphaType, std::move(colorSpace)));
165}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
SkTextureCompressionType
GrBackendFormat getBackendFormat() const
sk_sp< GrTextureProxy > wrapCompressedBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback >)
static bool ValidateCompressedBackendTexture(const GrCaps *, const GrBackendTexture &tex, SkAlphaType)
static constexpr Swizzle RGBA()
Definition: Swizzle.h:66
static constexpr SkColorType CompressionTypeToSkColorType(SkTextureCompressionType compression)
Definition: GpuTypesPriv.h:30

◆ TextureFromCompressedTextureData()

sk_sp< SkImage > SkImages::TextureFromCompressedTextureData ( GrDirectContext direct,
sk_sp< SkData data,
int  width,
int  height,
SkTextureCompressionType  type,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo,
GrProtected  isProtected = GrProtected::kNo 
)

Creates a GPU-backed SkImage from compressed data. This method will return an SkImage representing the compressed data. If the GPU doesn't support the specified compression method, the data will be decompressed and then wrapped in a GPU-backed image. Note: one can query the supported compression formats via GrRecordingContext::compressedBackendFormat.

Parameters
contextGPU context
datacompressed data to store in SkImage
widthwidth of full SkImage
heightheight of full SkImage
typetype of compression used
mipmappeddoes 'data' contain data for all the mipmap levels?
isProtecteddo the contents of 'data' require DRM protection (on Vulkan)?
Returns
created SkImage, or nullptr

Definition at line 280 of file SkImage_GaneshFactories.cpp.

286 {
287 if (!direct || !data) {
288 return nullptr;
289 }
290
291 GrBackendFormat beFormat = direct->compressedBackendFormat(type);
292 if (!beFormat.isValid()) {
294 if (!tmp) {
295 return nullptr;
296 }
297 return TextureFromImage(direct, tmp, mipmapped);
298 }
299
300 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
302 {width, height}, skgpu::Budgeted::kYes, mipmapped, isProtected, type, std::move(data));
303 if (!proxy) {
304 return nullptr;
305 }
306 GrSurfaceProxyView view(std::move(proxy));
307
309
310 return sk_make_sp<SkImage_Ganesh>(sk_ref_sp(direct),
312 std::move(view),
314}
bool isValid() const
SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const
GrDirectContextPriv priv()
sk_sp< GrTextureProxy > createCompressedTextureProxy(SkISize dimensions, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, SkTextureCompressionType, sk_sp< SkData > data)
SK_API sk_sp< SkImage > RasterFromCompressedTextureData(sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)

◆ TextureFromImage() [1/4]

sk_sp< SkImage > SkImages::TextureFromImage ( GrDirectContext dContext,
const SkImage img,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo,
skgpu::Budgeted  budgeted = skgpu::Budgeted::kYes 
)

Returns SkImage backed by GPU texture associated with context. Returned SkImage is compatible with SkSurface created with dstColorSpace. The returned SkImage respects mipmapped setting; if mipmapped equals skgpu::Mipmapped::kYes, the backing texture allocates mip map levels. The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the GPU. Returns original SkImage if the image is already texture-backed, the context matches, and mipmapped is compatible with the backing GPU texture. skgpu::Budgeted is ignored in this case. Returns nullptr if context is nullptr, or if SkImage was created with another GrDirectContext.

Parameters
GrDirectContextthe GrDirectContext in play, if it exists
SkImagea non-null pointer to an SkImage.
skgpu::MipmappedWhether created SkImage texture must allocate mip map levels. Defaults to no.
skgpu::BudgetedWhether to count a newly created texture for the returned image counts against the context's budget. Defaults to yes.
Returns
created SkImage, or nullptr

Definition at line 429 of file SkImage_GaneshFactories.cpp.

432 {
433 if (!dContext || !img) {
434 return nullptr;
435 }
436 auto ib = as_IB(img);
437 if (!dContext->priv().caps()->mipmapSupport() || ib->dimensions().area() <= 1) {
438 mipmapped = skgpu::Mipmapped::kNo;
439 }
440
441 if (ib->isGaneshBacked()) {
442 if (!ib->context()->priv().matches(dContext)) {
443 return nullptr;
444 }
445
446 if (mipmapped == skgpu::Mipmapped::kNo || ib->hasMipmaps()) {
447 return sk_ref_sp(const_cast<SkImage_Base*>(ib));
448 }
449 }
453 // TODO: Don't flatten YUVA images here. Add mips to the planes instead.
454 auto [view, ct] = skgpu::ganesh::AsView(dContext, ib, mipmapped, policy);
455 if (!view) {
456 return nullptr;
457 }
458 SkASSERT(view.asTextureProxy());
459 SkASSERT(mipmapped == skgpu::Mipmapped::kNo ||
460 view.asTextureProxy()->mipmapped() == skgpu::Mipmapped::kYes);
461 SkColorInfo colorInfo(GrColorTypeToSkColorType(ct), ib->alphaType(), ib->refColorSpace());
462 return sk_make_sp<SkImage_Ganesh>(
463 sk_ref_sp(dContext), ib->uniqueID(), std::move(view), std::move(colorInfo));
464}
GrImageTexGenPolicy
Definition: SkGr.h:141
bool mipmapSupport() const
Definition: GrCaps.h:72
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network policy
Definition: switches.h:248

◆ TextureFromImage() [2/4]

sk_sp< SkImage > SkImages::TextureFromImage ( GrDirectContext ctx,
const sk_sp< const SkImage > &  img,
skgpu::Mipmapped  m = skgpu::Mipmapped::kNo,
skgpu::Budgeted  b = skgpu::Budgeted::kYes 
)
inline

Definition at line 208 of file SkImageGanesh.h.

211 {
212 return TextureFromImage(ctx, img.get(), m, b);
213}
static bool b
sk_sp< SkImage > TextureFromImage(GrDirectContext *ctx, const sk_sp< const SkImage > &img, skgpu::Mipmapped m=skgpu::Mipmapped::kNo, skgpu::Budgeted b=skgpu::Budgeted::kYes)

◆ TextureFromImage() [3/4]

sk_sp< SkImage > SkImages::TextureFromImage ( skgpu::graphite::Recorder recorder,
const SkImage image,
SkImage::RequiredProperties  requiredProps = {} 
)

Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation and uploads if necessary. The returned SkImage respects the required image properties' mipmap setting for non-Graphite SkImages; i.e., if mipmapping is required, the backing Graphite texture will have allocated mip map levels.

It is assumed that MIP maps are always supported by the GPU.

Returns original SkImage if the image is already Graphite-backed and the required mipmapping is compatible with the backing Graphite texture. If the required mipmapping is not compatible, nullptr will be returned.

Returns nullptr if no Recorder is provided, or if SkImage was created with another Recorder and work on that Recorder has not been submitted.

Parameters
Recorderthe Recorder to use for storing commands
RequiredPropertiesproperties the returned SkImage must possess (e.g. mipmaps)
Returns
created SkImage, or nullptr

Definition at line 387 of file ImageFactories.cpp.

389 {
390 if (!recorder || !image) {
391 return nullptr;
392 }
393 if (image->dimensions().area() <= 1) {
394 requiredProps.fMipmapped = false;
395 }
396
397 auto ib = as_IB(image);
398 SkASSERT(!ib->isGaneshBacked());
399
400 if (ib->isRasterBacked()) {
401 auto raster = static_cast<const SkImage_Raster*>(ib);
402 return skgpu::graphite::MakeFromBitmap(recorder,
403 raster->imageInfo().colorInfo(),
404 raster->bitmap(),
405 raster->refMips(),
407 requiredProps,
408 "RasterBitmapTexture");
409 }
410 if (ib->isLazyGenerated()) {
412 recorder, static_cast<const SkImage_Lazy*>(ib), requiredProps);
413 }
414 SkASSERT(ib->isGraphiteBacked());
415 return ib->makeSubset(recorder, ib->bounds(), requiredProps);
416}
SkISize dimensions() const
Definition: SkImage.h:297
static sk_sp< SkImage > make_texture_image_from_lazy(skgpu::graphite::Recorder *recorder, const SkImage_Lazy *img, SkImage::RequiredProperties requiredProps)
constexpr int64_t area() const
Definition: SkSize.h:39

◆ TextureFromImage() [4/4]

sk_sp< SkImage > SkImages::TextureFromImage ( skgpu::graphite::Recorder r,
const sk_sp< const SkImage > &  img,
SkImage::RequiredProperties  props = {} 
)
inline

Definition at line 254 of file Image.h.

256 {}) {
257 return TextureFromImage(r, img.get(), props);
258}
sk_sp< SkImage > TextureFromImage(skgpu::graphite::Recorder *r, const sk_sp< const SkImage > &img, SkImage::RequiredProperties props={})
Definition: Image.h:254

◆ TextureFromYUVAImages()

sk_sp< SkImage > SkImages::TextureFromYUVAImages ( skgpu::graphite::Recorder recorder,
const SkYUVAInfo yuvaInfo,
SkSpan< const sk_sp< SkImage > >  images,
sk_sp< SkColorSpace imageColorSpace 
)

Creates an SkImage from YUV[A] planar SkImages associated with the recorder.

The images should have kGraphite type, and the result will be nullptr if any are not. The resulting SkImage will not take a ref on the given SkImages but will take a ref on the underlying TextureProxies. The releaseProcs, if any, for those Textures will be the ones set when the given SkImages were created.

Parameters
recorderThe recorder.
yuvaInfoStructure describing the YUVA format
imagesA set of SkImages containing YUVA data
imageColorSpaceRange of colors of the resulting image after conversion to RGB; may be nullptr
Returns
created SkImage, or nullptr

Definition at line 513 of file ImageFactories.cpp.

516 {
517 // This factory is just a view of the images, so does not actually trigger any work on the
518 // recorder. It is just used to provide the Caps.
519 return Image_YUVA::WrapImages(recorder->priv().caps(), yuvaInfo, images, imageColorSpace);
520}
std::array< MockImage, 3 > images
Definition: mock_vulkan.cc:41

◆ TextureFromYUVAPixmaps() [1/3]

sk_sp< SkImage > SkImages::TextureFromYUVAPixmaps ( GrRecordingContext context,
const SkYUVAPixmaps pixmaps,
skgpu::Mipmapped  buildMips,
bool  limitToMaxTextureSize,
sk_sp< SkColorSpace imageColorSpace 
)

Creates a GPU-backed SkImage from SkYUVAPixmaps. The image will remain planar with each plane converted to a texture using the passed GrRecordingContext. SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will be the SkColorSpace reported by the image and when drawn the RGB values will be converted from this space into the destination space (if the destination is tagged). Currently, this is only supported using the GPU backend and will fail if context is nullptr. SkYUVAPixmaps does not need to remain valid after this returns.

Parameters
contextGPU context
pixmapsThe planes as pixmaps with supported SkYUVAInfo that specifies conversion to RGB.
buildMipscreate internal YUVA textures as mip map if kYes. This is silently ignored if the context does not support mip maps.
limitToMaxTextureSizedownscale image to GPU maximum texture size, if necessary
imageColorSpacerange of colors of the resulting image; may be nullptr
Returns
created SkImage, or nullptr

Definition at line 325 of file SkImage_GaneshYUVA.cpp.

329 {
330 if (!context) {
331 return nullptr;
332 }
333
334 if (!pixmaps.isValid()) {
335 return nullptr;
336 }
337
338 if (!context->priv().caps()->mipmapSupport()) {
339 buildMips = skgpu::Mipmapped::kNo;
340 }
341
342 // Resize the pixmaps if necessary.
343 int numPlanes = pixmaps.numPlanes();
344 int maxTextureSize = context->priv().caps()->maxTextureSize();
345 int maxDim = std::max(pixmaps.yuvaInfo().width(), pixmaps.yuvaInfo().height());
346
347 SkYUVAPixmaps tempPixmaps;
348 const SkYUVAPixmaps* pixmapsToUpload = &pixmaps;
349 // We assume no plane is larger than the image size (and at least one plane is as big).
350 if (maxDim > maxTextureSize) {
351 if (!limitToMaxTextureSize) {
352 return nullptr;
353 }
354 float scale = static_cast<float>(maxTextureSize) / maxDim;
355 SkISize newDimensions = {
356 std::min(static_cast<int>(pixmaps.yuvaInfo().width() * scale), maxTextureSize),
357 std::min(static_cast<int>(pixmaps.yuvaInfo().height() * scale), maxTextureSize)};
358 SkYUVAInfo newInfo = pixmaps.yuvaInfo().makeDimensions(newDimensions);
359 SkYUVAPixmapInfo newPixmapInfo(newInfo, pixmaps.dataType(), /*row bytes*/ nullptr);
360 tempPixmaps = SkYUVAPixmaps::Allocate(newPixmapInfo);
362 if (!tempPixmaps.isValid()) {
363 return nullptr;
364 }
365 for (int i = 0; i < numPlanes; ++i) {
366 if (!pixmaps.plane(i).scalePixels(tempPixmaps.plane(i), sampling)) {
367 return nullptr;
368 }
369 }
370 pixmapsToUpload = &tempPixmaps;
371 }
372
373 // Convert to texture proxies.
375 GrColorType pixmapColorTypes[SkYUVAInfo::kMaxPlanes];
376 for (int i = 0; i < numPlanes; ++i) {
377 // Turn the pixmap into a GrTextureProxy
378 SkBitmap bmp;
379 bmp.installPixels(pixmapsToUpload->plane(i));
380 std::tie(views[i], std::ignore) = GrMakeUncachedBitmapProxyView(context, bmp, buildMips);
381 if (!views[i]) {
382 return nullptr;
383 }
384 pixmapColorTypes[i] = SkColorTypeToGrColorType(bmp.colorType());
385 }
386
387 GrYUVATextureProxies yuvaProxies(pixmapsToUpload->yuvaInfo(), views, pixmapColorTypes);
388 SkASSERT(yuvaProxies.isValid());
389 return sk_make_sp<SkImage_GaneshYUVA>(sk_ref_sp(context),
391 std::move(yuvaProxies),
392 std::move(imageColorSpace));
393}
int maxTextureSize() const
Definition: GrCaps.h:229
SkColorType colorType() const
Definition: SkBitmap.h:160
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &) const
int width() const
Definition: SkYUVAInfo.h:172
SkYUVAInfo makeDimensions(SkISize) const
Definition: SkYUVAInfo.cpp:366
int height() const
Definition: SkYUVAInfo.h:173
DataType dataType() const
const SkYUVAInfo & yuvaInfo() const
const SkPixmap & plane(int i) const
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo &yuvaPixmapInfo)
int numPlanes() const
bool isValid() const

◆ TextureFromYUVAPixmaps() [2/3]

sk_sp< SkImage > SkImages::TextureFromYUVAPixmaps ( GrRecordingContext context,
const SkYUVAPixmaps pixmaps,
skgpu::Mipmapped  buildMips = skgpu::Mipmapped::kNo,
bool  limitToMaxTextureSize = false 
)

Definition at line 318 of file SkImage_GaneshYUVA.cpp.

321 {
322 return TextureFromYUVAPixmaps(context, pixmaps, buildMips, limitToMaxTextureSize, nullptr);
323}
SK_API sk_sp< SkImage > TextureFromYUVAPixmaps(GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips, bool limitToMaxTextureSize, sk_sp< SkColorSpace > imageColorSpace)

◆ TextureFromYUVAPixmaps() [3/3]

sk_sp< SkImage > SkImages::TextureFromYUVAPixmaps ( skgpu::graphite::Recorder recorder,
const SkYUVAPixmaps pixmaps,
SkImage::RequiredProperties  requiredProps = {},
bool  limitToMaxTextureSize = false,
sk_sp< SkColorSpace imgColorSpace = nullptr,
std::string_view  label = {} 
)

Creates SkImage from SkYUVAPixmaps.

The image will remain planar with each plane converted to a texture using the passed Recorder.

SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. The SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will be the SkColorSpace reported by the image and when drawn the RGB values will be converted from this space into the destination space (if the destination is tagged).

This is only supported using the GPU backend and will fail if recorder is nullptr.

SkYUVAPixmaps does not need to remain valid after this returns.

Parameters
RecorderThe Recorder to use for storing commands
pixmapsThe planes as pixmaps with supported SkYUVAInfo that specifies conversion to RGB.
RequiredPropertiesProperties the returned SkImage must possess (e.g. mipmaps)
limitToMaxTextureSizeDownscale image to GPU maximum texture size, if necessary
imgColorSpaceRange of colors of the resulting image; may be nullptr
Returns
Created SkImage, or nullptr

Definition at line 418 of file ImageFactories.cpp.

423 {
424 if (!recorder) {
425 return nullptr;
426 }
427
428 // Determine if we have to resize the pixmaps
429 const int maxTextureSize = recorder->priv().caps()->maxTextureSize();
430 const int maxDim = std::max(pixmaps.yuvaInfo().width(), pixmaps.yuvaInfo().height());
431
432 SkYUVAPixmapInfo finalInfo = pixmaps.pixmapsInfo();
433 if (maxDim > maxTextureSize) {
434 if (!limitToMaxTextureSize) {
435 return nullptr;
436 }
437 float scale = static_cast<float>(maxTextureSize) / maxDim;
438 SkISize newDimensions = {
439 std::min(static_cast<int>(pixmaps.yuvaInfo().width() * scale), maxTextureSize),
440 std::min(static_cast<int>(pixmaps.yuvaInfo().height() * scale), maxTextureSize)};
441 finalInfo = SkYUVAPixmapInfo(pixmaps.yuvaInfo().makeDimensions(newDimensions),
442 pixmaps.dataType(),
443 /*rowBytes=*/nullptr);
444 }
445
446 std::string labelStr(label);
447 if (labelStr.empty()) {
448 labelStr = "YUVRasterBitmapPlane";
449 } else {
450 labelStr += "_YUVBitmapPlane";
451 }
452
453 auto mipmapped = requiredProps.fMipmapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
454 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
455 for (int i = 0; i < finalInfo.yuvaInfo().numPlanes(); ++i) {
456 SkBitmap bmp;
457 if (maxDim > maxTextureSize) {
458 // Rescale the data before uploading
459 if (!bmp.tryAllocPixels(finalInfo.planeInfo(i)) ||
460 !pixmaps.plane(i).scalePixels(bmp.pixmap(), SkFilterMode::kLinear)) {
461 return nullptr;
462 }
463 } else {
464 // Use original data to upload
465 if (!bmp.installPixels(pixmaps.plane(i))) {
466 return nullptr;
467 }
468 }
469
470 auto [view, _] = MakeBitmapProxyView(recorder, bmp, /*mipmapsIn=*/nullptr,
471 mipmapped, skgpu::Budgeted::kNo,
472 labelStr);
473 planes[i] = std::move(view);
474 }
475 return Image_YUVA::Make(recorder->priv().caps(), finalInfo.yuvaInfo(),
476 SkSpan(planes), std::move(imageColorSpace));
477}
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
const SkYUVAInfo & yuvaInfo() const
const SkImageInfo & planeInfo(int i) const
SkYUVAPixmapInfo pixmapsInfo() const
int maxTextureSize() const
Definition: Caps.h:141
std::tuple< TextureProxyView, SkColorType > MakeBitmapProxyView(Recorder *recorder, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmapsIn, Mipmapped mipmapped, Budgeted budgeted, std::string_view label)

◆ TextureFromYUVATextures() [1/3]

sk_sp< SkImage > SkImages::TextureFromYUVATextures ( GrRecordingContext context,
const GrYUVABackendTextures yuvaTextures 
)

Definition at line 282 of file SkImage_GaneshYUVA.cpp.

283 {
284 return TextureFromYUVATextures(context, yuvaTextures, nullptr, nullptr, nullptr);
285}
SK_API sk_sp< SkImage > TextureFromYUVATextures(GrRecordingContext *context, const GrYUVABackendTextures &yuvaTextures, sk_sp< SkColorSpace > imageColorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)

◆ TextureFromYUVATextures() [2/3]

sk_sp< SkImage > SkImages::TextureFromYUVATextures ( GrRecordingContext context,
const GrYUVABackendTextures yuvaTextures,
sk_sp< SkColorSpace imageColorSpace,
TextureReleaseProc  textureReleaseProc = nullptr,
ReleaseContext  releaseContext = nullptr 
)

Creates a GPU-backed SkImage from YUV[A] planar textures. This requires that the textures stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called before return on failure.

Parameters
contextGPU context
yuvaTexturesA set of textures containing YUVA data and a description of the data and transformation to RGBA.
imageColorSpacerange of colors of the resulting image after conversion to RGB; may be nullptr
textureReleaseProccalled when the backend textures can be released
releaseContextstate passed to textureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 287 of file SkImage_GaneshYUVA.cpp.

291 {
292 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
293
294 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
295 int numPlanes = yuvaTextures.yuvaInfo().numPlanes();
297 for (int plane = 0; plane < numPlanes; ++plane) {
298 proxies[plane] = proxyProvider->wrapBackendTexture(yuvaTextures.texture(plane),
302 releaseHelper);
303 if (!proxies[plane]) {
304 return {};
305 }
306 }
307 GrYUVATextureProxies yuvaProxies(
308 yuvaTextures.yuvaInfo(), proxies, yuvaTextures.textureOrigin());
309
310 if (!yuvaProxies.isValid()) {
311 return nullptr;
312 }
313
314 return sk_make_sp<SkImage_GaneshYUVA>(
315 sk_ref_sp(context), kNeedNewImageUniqueID, yuvaProxies, imageColorSpace);
316}
const SkYUVAInfo & yuvaInfo() const
GrBackendTexture texture(int i) const
GrSurfaceOrigin textureOrigin() const
int numPlanes() const
Definition: SkYUVAInfo.h:204

◆ TextureFromYUVATextures() [3/3]

sk_sp< SkImage > SkImages::TextureFromYUVATextures ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::YUVABackendTextures yuvaBackendTextures,
sk_sp< SkColorSpace imageColorSpace,
TextureReleaseProc  releaseP = nullptr,
ReleaseContext  releaseC = nullptr,
std::string_view  label = {} 
)

Creates an SkImage from YUV[A] planar textures associated with the recorder.

Parameters
recorderThe recorder.
yuvaBackendTexturesA set of textures containing YUVA data and a description of the data and transformation to RGBA.
imageColorSpacerange of colors of the resulting image after conversion to RGB; may be nullptr
TextureReleaseProccalled when the backend textures can be released
ReleaseContextstate passed to TextureReleaseProc
Returns
created SkImage, or nullptr

Definition at line 479 of file ImageFactories.cpp.

484 {
485 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseP, releaseC);
486 if (!recorder) {
487 return nullptr;
488 }
489
490 std::string labelStr(label);
491 if (labelStr.empty()) {
492 labelStr = "Wrapped_YUVPlane";
493 } else {
494 labelStr += "_YUVPlane";
495 }
496
497 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
498 for (int i = 0; i < yuvaTextures.yuvaInfo().numPlanes(); ++i) {
500 yuvaTextures.planeTexture(i), labelStr);
501 if (!texture) {
502 SKGPU_LOG_W("Failed to wrap backend texture for YUVA plane %d", i);
503 return nullptr;
504 }
505 texture->setReleaseCallback(releaseHelper);
506 planes[i] = TextureProxyView(TextureProxy::Wrap(std::move(texture)));
507 }
508
509 return Image_YUVA::Make(recorder->priv().caps(), yuvaTextures.yuvaInfo(),
510 SkSpan(planes), std::move(imageColorSpace));
511}
ResourceProvider * resourceProvider()
Definition: RecorderPriv.h:33
sk_sp< Texture > createWrappedTexture(const BackendTexture &, std::string_view label)
GrSamplerState::WrapMode Wrap
Definition: texelsubset.cpp:40

◆ validate_backend_texture()

static bool SkImages::validate_backend_texture ( const skgpu::graphite::Caps caps,
const skgpu::graphite::BackendTexture texture,
const SkColorInfo info 
)
static

Definition at line 48 of file ImageFactories.cpp.

50 {
51 if (!texture.isValid() || texture.dimensions().width() <= 0 ||
52 texture.dimensions().height() <= 0) {
53 return false;
54 }
55
57 return false;
58 }
59
60 if (!caps->isTexturable(texture.info())) {
61 return false;
62 }
63
64 return caps->areColorTypeAndTextureInfoCompatible(info.colorType(), texture.info());
65}
static bool SkColorInfoIsValid(const SkColorInfo &info)
bool isTexturable(const TextureInfo &) const
Definition: Caps.cpp:66
bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:85

◆ WrapTexture() [1/3]

sk_sp< SkImage > SkImages::WrapTexture ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture backendTex,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
skgpu::Origin  origin,
GenerateMipmapsFromBase  generateMipmapsFromBase,
TextureReleaseProc  releaseP = nullptr,
ReleaseContext  releaseC = nullptr,
std::string_view  label = {} 
)

Creates an SkImage from a GPU texture associated with the recorder. The client is still responsible for managing the backend texture's lifetime.

SkImage is returned if the format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.

Parameters
recorderThe recorder
backendTexturetexture residing on GPU
colorSpaceThis describes the color space of this image's contents, as seen after sampling. In general, if the format of the backend texture is SRGB, some linear colorSpace should be supplied (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the backend texture is linear, then the colorSpace should include a description of the transfer function as well (e.g., SkColorSpace::MakeSRGB()).
originWhether the Texture logically treats the origin as TopLeft or BottomLeft
generateMipmapsFromBaseIf kYes then the pixel contents of the textures upper mipmap levels are generated by successive downsampling of the base level. If the texture is not mipmapped or isn't renderable then image creation will fail. If kNo and the texture is mipmapped then the contents of upper levels are assumed to already be valid.
Returns
created SkImage, or nullptr

Definition at line 67 of file ImageFactories.cpp.

76 {
77 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseP, releaseC);
78
79 if (!recorder) {
80 return nullptr;
81 }
82
83 const Caps* caps = recorder->priv().caps();
84
85 SkColorInfo info(ct, at, std::move(cs));
86
87 if (!validate_backend_texture(caps, backendTex, info)) {
88 return nullptr;
89 }
90
91 if (label.empty()) {
92 label = "WrappedImage";
93 }
94
96 recorder->priv().resourceProvider()->createWrappedTexture(backendTex, std::move(label));
97 if (!texture) {
98 SKGPU_LOG_W("Texture creation failed");
99 return nullptr;
100 }
101 texture->setReleaseCallback(std::move(releaseHelper));
102
104 SkASSERT(proxy);
105
106 skgpu::Swizzle swizzle = caps->getReadSwizzle(ct, backendTex.info());
107 TextureProxyView view(std::move(proxy), swizzle, origin);
108
109 if (genMipmaps == GenerateMipmapsFromBase::kYes) {
110 if (view.proxy()->mipmapped() == skgpu::Mipmapped::kNo) {
111 SKGPU_LOG_W("Failed SkImage:::WrapTexture because asked to generate mipmaps for "
112 "nonmipmapped texture");
113 return nullptr;
114 }
115 if (!GenerateMipmaps(recorder, view.refProxy(), info)) {
116 SKGPU_LOG_W("Failed SkImage::WrapTexture. Could not generate mipmaps.");
117 return nullptr;
118 }
119 }
120
121 return sk_make_sp<skgpu::graphite::Image>(view, info);
122}
static bool validate_backend_texture(const GrCaps *caps, const GrBackendTexture &tex, int sampleCnt, GrColorType grCT, bool texturable)
const TextureInfo & info() const
bool GenerateMipmaps(Recorder *recorder, sk_sp< TextureProxy > texture, const SkColorInfo &colorInfo)

◆ WrapTexture() [2/3]

sk_sp< SkImage > SkImages::WrapTexture ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture backendTex,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
skgpu::Origin  origin,
TextureReleaseProc  releaseP = nullptr,
ReleaseContext  releaseC = nullptr,
std::string_view  label = {} 
)

Definition at line 124 of file ImageFactories.cpp.

132 {
133 return WrapTexture(recorder,
134 backendTex,
135 ct,
136 at,
137 std::move(cs),
138 origin,
140 releaseP,
141 releaseC,
142 std::move(label));
143}
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})

◆ WrapTexture() [3/3]

sk_sp< SkImage > SkImages::WrapTexture ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture backendTex,
SkColorType  colorType,
SkAlphaType  alphaType,
sk_sp< SkColorSpace colorSpace,
TextureReleaseProc  releaseP = nullptr,
ReleaseContext  releaseC = nullptr,
std::string_view  label = {} 
)

Definition at line 145 of file ImageFactories.cpp.

152 {
153 return WrapTexture(recorder,
154 backendTex,
155 ct,
156 at,
157 std::move(cs),
160 releaseP,
161 releaseC,
162 std::move(label));
163}