Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
 
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)
 
SK_API sk_sp< SkImageWrapTexture (skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc=nullptr, ReleaseContext=nullptr)
 
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)
 
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[])
 
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)
 
SK_API sk_sp< SkImageTextureFromYUVATextures (skgpu::graphite::Recorder *recorder, const skgpu::graphite::YUVABackendTextures &yuvaBackendTextures, sk_sp< SkColorSpace > imageColorSpace, TextureReleaseProc=nullptr, ReleaseContext=nullptr)
 
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

using SkImages::BackendTextureReleaseProc = typedef std::function<void(GrBackendTexture)>

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 36 of file Image.h.

◆ GraphitePromiseImageReleaseProc

Definition at line 46 of file Image.h.

◆ GraphitePromiseTextureFulfillContext

Definition at line 39 of file Image.h.

◆ GraphitePromiseTextureFulfillProc

Definition at line 43 of file Image.h.

◆ GraphitePromiseTextureReleaseContext

Definition at line 41 of file Image.h.

◆ GraphitePromiseTextureReleaseProc

Definition at line 47 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 31 of file Image.h.

31: 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:81
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
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 102 of file Image.h.

109 {
110 return WrapTexture(recorder, tex, colorType, alphaType, colorSpace, origin, trProc, ctx);
111}
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)

◆ 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 113 of file Image.h.

119 {
120 return WrapTexture(recorder, tex, colorType, alphaType, colorSpace, trProc, ctx);
121}

◆ 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:78
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);
405 skgpu::Mipmapped mipmapped = buildMips ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
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)
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
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
SkImageInfo makeWH(int newWidth, int newHeight) const
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)

◆ 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

◆ 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 295 of file ImageFactories.cpp.

298 {
299 auto mm = requiredProps.fMipmapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
301 if (!surface) {
302 SKGPU_LOG_E("Failed to create Surface");
303 return nullptr;
304 }
305
306 img->replay(surface->getCanvas());
307
308 if (requiredProps.fMipmapped) {
311 static_cast<Surface*>(surface.get())->readSurfaceView().refProxy();
312 if (!GenerateMipmaps(recorder, std::move(texture), info.colorInfo())) {
313 SKGPU_LOG_W("Failed to create mipmaps for texture from SkPicture");
314 }
315 }
316
318}
#define SKGPU_LOG_E(fmt,...)
Definition Log.h:38
#define SKGPU_LOG_W(fmt,...)
Definition Log.h:40
const SkSurfaceProps * props() const
void replay(SkCanvas *) const
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkImage > AsImage(sk_sp< const SkSurface >)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
void Flush(sk_sp< SkSurface > surface)

◆ 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
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)

◆ 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)
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_sp< SkImage > image
Definition examples.cpp:29
SK_API bool MakeBackendTextureFromImage(GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc)

◆ 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}
SK_API GrDirectContext * GetContext(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

◆ 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 326 of file ImageFactories.cpp.

328 {
329 // 1. Ask the generator to natively create one.
330 {
332 sk_sp<SkImage> newImage =
334 static_cast<const SkImage_Picture*>(img),
335 img->imageInfo(),
336 requiredProps);
337 if (newImage) {
338 SkASSERT(as_IB(newImage)->isGraphiteBacked());
339 return newImage;
340 }
341 }
342 // There is not an analog to GrTextureGenerator for Graphite yet, but if there was,
343 // we would want to call it here.
344 }
345
346 // 2. Ask the generator to return a bitmap, which the GPU can convert.
347 {
350 return skgpu::graphite::MakeFromBitmap(recorder,
351 img->imageInfo().colorInfo(),
352 bitmap,
353 nullptr,
355 requiredProps);
356 }
357 }
358
359 return nullptr;
360}
#define SkASSERT(cond)
Definition SkAssert.h:116
bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint) const override
SkImage_Base::Type type() const override
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
@ kDisallow_CachingHint
disallows internally caching decoded and copied pixels
Definition SkImage.h:465
static sk_sp< SkImage > generate_picture_texture(skgpu::graphite::Recorder *recorder, const SkImage_Picture *img, const SkImageInfo &info, SkImage::RequiredProperties requiredProps)
sk_sp< SkImage > MakeFromBitmap(Recorder *recorder, const SkColorInfo &colorInfo, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmaps, Budgeted budgeted, SkImage::RequiredProperties requiredProps)
const SkColorInfo & colorInfo() const

◆ 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)
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)
Point 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 275 of file ImageFactories.cpp.

281 {
282 if (!recorder || !src || !filter) {
283 return nullptr;
284 }
285
286 sk_sp<skif::Backend> backend = skif::MakeGraphiteBackend(recorder, {}, src->colorType());
287 return as_IFB(filter)->makeImageWithFilter(std::move(backend),
288 std::move(src),
289 subset,
290 clipBounds,
291 outSubset,
292 offset);
293}

◆ 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
@ kNeedNewImageUniqueID
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()

◆ 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

◆ 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 204 of file ImageFactories.cpp.

212 {
213 return PromiseTextureFrom(recorder,
214 dimensions,
215 textureInfo,
216 colorInfo,
218 isVolatile,
219 fulfillProc,
220 imageReleaseProc,
221 textureReleaseProc,
222 imageContext);
223}
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)

◆ 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 
)

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 153 of file ImageFactories.cpp.

162 {
163 // Our contract is that we will always call the _image_ release proc even on failure.
164 // We use the helper to convey the imageContext, so we need to ensure Make doesn't fail.
165 imageReleaseProc = imageReleaseProc ? imageReleaseProc : [](void*) {};
166 auto releaseHelper = skgpu::RefCntedCallback::Make(imageReleaseProc, imageContext);
167
168 if (!recorder) {
169 SKGPU_LOG_W("Null Recorder");
170 return nullptr;
171 }
172
173 const Caps* caps = recorder->priv().caps();
174
175 SkImageInfo info = SkImageInfo::Make(dimensions, colorInfo);
176 if (!SkImageInfoIsValid(info)) {
177 SKGPU_LOG_W("Invalid SkImageInfo");
178 return nullptr;
179 }
180
181 if (!caps->areColorTypeAndTextureInfoCompatible(colorInfo.colorType(), textureInfo)) {
182 SKGPU_LOG_W("Incompatible SkColorType and TextureInfo");
183 return nullptr;
184 }
185
186 // Non-YUVA promise images use the 'imageContext' for both the release proc and fulfill proc.
188 dimensions,
189 textureInfo,
190 isVolatile,
191 std::move(releaseHelper),
192 fulfillProc,
193 imageContext,
194 textureReleaseProc);
195 if (!proxy) {
196 return nullptr;
197 }
198
199 skgpu::Swizzle swizzle = caps->getReadSwizzle(colorInfo.colorType(), textureInfo);
200 TextureProxyView view(std::move(proxy), swizzle, origin);
201 return sk_make_sp<Image>(view, colorInfo);
202}
SkColorType colorType() const
const Caps * caps() const
sk_sp< TextureProxy > MakePromiseImageLazyProxy(const Caps *caps, SkISize dimensions, TextureInfo textureInfo, Volatile isVolatile, sk_sp< RefCntedCallback > releaseHelper, GraphitePromiseTextureFulfillProc fulfillProc, GraphitePromiseTextureFulfillContext fulfillContext, GraphitePromiseTextureReleaseProc textureReleaseProc)

◆ 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 394 of file SkImage_GaneshYUVA.cpp.

399 {
400 if (!backendTextureInfo.isValid()) {
401 return nullptr;
402 }
403
404 SkISize planeDimensions[SkYUVAInfo::kMaxPlanes];
405 int n = backendTextureInfo.yuvaInfo().planeDimensions(planeDimensions);
406
407 // Our contract is that we will always call the release proc even on failure.
408 // We use the helper to convey the context, so we need to ensure make doesn't fail.
409 textureReleaseProc = textureReleaseProc ? textureReleaseProc : [](void*) {};
410 sk_sp<skgpu::RefCntedCallback> releaseHelpers[4];
411 for (int i = 0; i < n; ++i) {
412 releaseHelpers[i] = skgpu::RefCntedCallback::Make(textureReleaseProc, textureContexts[i]);
413 }
414
415 if (!threadSafeProxy) {
416 return nullptr;
417 }
418
419 SkAlphaType at =
420 backendTextureInfo.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
422 backendTextureInfo.yuvaInfo().dimensions(), kAssumedColorType, at, imageColorSpace);
423 if (!SkImageInfoIsValid(info)) {
424 return nullptr;
425 }
426
427 // Make a lazy proxy for each plane
428 sk_sp<GrSurfaceProxy> proxies[4];
429 for (int i = 0; i < n; ++i) {
430 proxies[i] =
432 planeDimensions[i],
433 backendTextureInfo.planeFormat(i),
434 skgpu::Mipmapped::kNo,
435 textureFulfillProc,
436 std::move(releaseHelpers[i]));
437 if (!proxies[i]) {
438 return nullptr;
439 }
440 }
441 GrYUVATextureProxies yuvaTextureProxies(
442 backendTextureInfo.yuvaInfo(), proxies, backendTextureInfo.textureOrigin());
443 SkASSERT(yuvaTextureProxies.isValid());
444 sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy)));
445 return sk_make_sp<SkImage_GaneshYUVA>(std::move(ctx),
447 std::move(yuvaTextureProxies),
448 std::move(imageColorSpace));
449}
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

◆ 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[] 
)

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 225 of file ImageFactories.cpp.

233 {
234 // Our contract is that we will always call the _image_ release proc even on failure.
235 // We use the helper to convey the imageContext, so we need to ensure Make doesn't fail.
236 auto releaseHelper = skgpu::RefCntedCallback::Make(imageReleaseProc, imageContext);
237 if (!recorder) {
238 return nullptr;
239 }
240 // Precompute the dimensions for all promise texture planes
241 SkISize planeDimensions[SkYUVAInfo::kMaxPlanes];
242 if (!backendTextureInfo.yuvaInfo().planeDimensions(planeDimensions)) {
243 return nullptr;
244 }
245
246 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
247 for (int i = 0; i < backendTextureInfo.numPlanes(); ++i) {
249 recorder->priv().caps(),
250 planeDimensions[i],
251 backendTextureInfo.planeTextureInfo(i),
252 isVolatile,
253 releaseHelper,
254 fulfillProc,
255 planeContexts[i],
256 textureReleaseProc);
257 // Promise YUVA images assume the default rgba swizzle.
258 planes[i] = TextureProxyView(std::move(lazyProxy));
259 }
260 return Image_YUVA::Make(recorder->priv().caps(), backendTextureInfo.yuvaInfo(),
261 SkSpan(planes), std::move(imageColorSpace));
262}
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)
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
int32_t height
int32_t width
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

◆ 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}

◆ 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 264 of file ImageFactories.cpp.

267 {
268 if (!recorder || !img) {
269 return nullptr;
270 }
271 auto subsetImg = img->makeSubset(recorder, subset, props);
272 return SkImages::TextureFromImage(recorder, subsetImg, props);
273}

◆ 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)
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)

◆ 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()) {
293 sk_sp<SkImage> tmp = RasterFromCompressedTextureData(std::move(data), width, height, type);
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)

◆ 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

◆ 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 362 of file ImageFactories.cpp.

364 {
365 if (!recorder || !image) {
366 return nullptr;
367 }
368 if (image->dimensions().area() <= 1) {
369 requiredProps.fMipmapped = false;
370 }
371
372 auto ib = as_IB(image);
373 SkASSERT(!ib->isGaneshBacked());
374
375 if (ib->isRasterBacked()) {
376 auto raster = static_cast<const SkImage_Raster*>(ib);
377 return skgpu::graphite::MakeFromBitmap(recorder,
378 raster->imageInfo().colorInfo(),
379 raster->bitmap(),
380 raster->refMips(),
382 requiredProps);
383 }
384 if (ib->isLazyGenerated()) {
386 recorder, static_cast<const SkImage_Lazy*>(ib), requiredProps);
387 }
388 SkASSERT(ib->isGraphiteBacked());
389 return ib->makeSubset(recorder, ib->bounds(), requiredProps);
390}
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 247 of file Image.h.

249 {}) {
250 return TextureFromImage(r, img.get(), props);
251}

◆ 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 470 of file ImageFactories.cpp.

473 {
474 // This factory is just a view of the images, so does not actually trigger any work on the
475 // recorder. It is just used to provide the Caps.
476 return Image_YUVA::WrapImages(recorder->priv().caps(), yuvaInfo, images, imageColorSpace);
477}

◆ 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 324 of file SkImage_GaneshYUVA.cpp.

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

320 {
321 return TextureFromYUVAPixmaps(context, pixmaps, buildMips, limitToMaxTextureSize, nullptr);
322}
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 
)

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 392 of file ImageFactories.cpp.

396 {
397 if (!recorder) {
398 return nullptr;
399 }
400
401 // Determine if we have to resize the pixmaps
402 const int maxTextureSize = recorder->priv().caps()->maxTextureSize();
403 const int maxDim = std::max(pixmaps.yuvaInfo().width(), pixmaps.yuvaInfo().height());
404
405 SkYUVAPixmapInfo finalInfo = pixmaps.pixmapsInfo();
406 if (maxDim > maxTextureSize) {
407 if (!limitToMaxTextureSize) {
408 return nullptr;
409 }
410 float scale = static_cast<float>(maxTextureSize) / maxDim;
411 SkISize newDimensions = {
412 std::min(static_cast<int>(pixmaps.yuvaInfo().width() * scale), maxTextureSize),
413 std::min(static_cast<int>(pixmaps.yuvaInfo().height() * scale), maxTextureSize)};
414 finalInfo = SkYUVAPixmapInfo(pixmaps.yuvaInfo().makeDimensions(newDimensions),
415 pixmaps.dataType(),
416 /*rowBytes=*/nullptr);
417 }
418
419 auto mipmapped = requiredProps.fMipmapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
420 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
421 for (int i = 0; i < finalInfo.yuvaInfo().numPlanes(); ++i) {
422 SkBitmap bmp;
423 if (maxDim > maxTextureSize) {
424 // Rescale the data before uploading
425 if (!bmp.tryAllocPixels(finalInfo.planeInfo(i)) ||
426 !pixmaps.plane(i).scalePixels(bmp.pixmap(), SkFilterMode::kLinear)) {
427 return nullptr;
428 }
429 } else {
430 // Use original data to upload
431 if (!bmp.installPixels(pixmaps.plane(i))) {
432 return nullptr;
433 }
434 }
435
436 auto [view, _] = MakeBitmapProxyView(recorder, bmp, /*mipmapsIn=*/nullptr,
437 mipmapped, skgpu::Budgeted::kNo);
438 planes[i] = std::move(view);
439 }
440 return Image_YUVA::Make(recorder->priv().caps(), finalInfo.yuvaInfo(),
441 SkSpan(planes), std::move(imageColorSpace));
442}
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:134
std::tuple< TextureProxyView, SkColorType > MakeBitmapProxyView(Recorder *recorder, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmapsIn, Mipmapped mipmapped, Budgeted budgeted)

◆ TextureFromYUVATextures() [1/3]

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

Definition at line 281 of file SkImage_GaneshYUVA.cpp.

282 {
283 return TextureFromYUVATextures(context, yuvaTextures, nullptr, nullptr, nullptr);
284}
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 286 of file SkImage_GaneshYUVA.cpp.

290 {
291 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
292
293 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
294 int numPlanes = yuvaTextures.yuvaInfo().numPlanes();
296 for (int plane = 0; plane < numPlanes; ++plane) {
297 proxies[plane] = proxyProvider->wrapBackendTexture(yuvaTextures.texture(plane),
301 releaseHelper);
302 if (!proxies[plane]) {
303 return {};
304 }
305 }
306 GrYUVATextureProxies yuvaProxies(
307 yuvaTextures.yuvaInfo(), proxies, yuvaTextures.textureOrigin());
308
309 if (!yuvaProxies.isValid()) {
310 return nullptr;
311 }
312
313 return sk_make_sp<SkImage_GaneshYUVA>(
314 sk_ref_sp(context), kNeedNewImageUniqueID, yuvaProxies, imageColorSpace);
315}
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 
)

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 444 of file ImageFactories.cpp.

448 {
449 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseP, releaseC);
450 if (!recorder) {
451 return nullptr;
452 }
453
454 TextureProxyView planes[SkYUVAInfo::kMaxPlanes];
455 for (int i = 0; i < yuvaTextures.yuvaInfo().numPlanes(); ++i) {
457 yuvaTextures.planeTexture(i));
458 if (!texture) {
459 SKGPU_LOG_W("Failed to wrap backend texture for YUVA plane %d", i);
460 return nullptr;
461 }
462 texture->setReleaseCallback(releaseHelper);
463 planes[i] = TextureProxyView(TextureProxy::Wrap(std::move(texture)));
464 }
465
466 return Image_YUVA::Make(recorder->priv().caps(), yuvaTextures.yuvaInfo(),
467 SkSpan(planes), std::move(imageColorSpace));
468}
ResourceProvider * resourceProvider()
virtual sk_sp< Texture > createWrappedTexture(const BackendTexture &)=0

◆ 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 46 of file ImageFactories.cpp.

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

◆ 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 
)

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 65 of file ImageFactories.cpp.

73 {
74 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseP, releaseC);
75
76 if (!recorder) {
77 return nullptr;
78 }
79
80 const Caps* caps = recorder->priv().caps();
81
82 SkColorInfo info(ct, at, std::move(cs));
83
84 if (!validate_backend_texture(caps, backendTex, info)) {
85 return nullptr;
86 }
87
89 if (!texture) {
90 SKGPU_LOG_W("Texture creation failed");
91 return nullptr;
92 }
93 texture->setReleaseCallback(std::move(releaseHelper));
94
95 sk_sp<TextureProxy> proxy = TextureProxy::Wrap(std::move(texture));
96 SkASSERT(proxy);
97
98 skgpu::Swizzle swizzle = caps->getReadSwizzle(ct, backendTex.info());
99 TextureProxyView view(std::move(proxy), swizzle, origin);
100
101 if (genMipmaps == GenerateMipmapsFromBase::kYes) {
102 if (view.proxy()->mipmapped() == skgpu::Mipmapped::kNo) {
103 SKGPU_LOG_W("Failed SkImage:::WrapTexture because asked to generate mipmaps for "
104 "nonmipmapped texture");
105 return nullptr;
106 }
107 if (!GenerateMipmaps(recorder, view.refProxy(), info)) {
108 SKGPU_LOG_W("Failed SkImage::WrapTexture. Could not generate mipmaps.");
109 return nullptr;
110 }
111 }
112
113 return sk_make_sp<skgpu::graphite::Image>(view, info);
114}
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 
)

Definition at line 116 of file ImageFactories.cpp.

123 {
124 return WrapTexture(recorder,
125 backendTex,
126 ct,
127 at,
128 std::move(cs),
129 origin,
131 releaseP,
132 releaseC);
133}

◆ 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 
)

Definition at line 135 of file ImageFactories.cpp.

141 {
142 return WrapTexture(recorder,
143 backendTex,
144 ct,
145 at,
146 std::move(cs),
149 releaseP,
150 releaseC);
151}