2012-07-25 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkImage_DEFINED
|
|
|
|
#define SkImage_DEFINED
|
|
|
|
|
2022-03-08 13:05:07 +00:00
|
|
|
#include "include/core/SkImageEncoder.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2020-11-06 14:50:47 +00:00
|
|
|
#include "include/core/SkSamplingOptions.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2021-10-28 11:31:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
2021-10-28 11:31:32 +00:00
|
|
|
#endif
|
2022-03-02 20:43:58 +00:00
|
|
|
#if SK_GRAPHITE_ENABLED
|
|
|
|
#include "experimental/graphite/include/GraphiteTypes.h"
|
|
|
|
#endif
|
2019-08-27 13:12:15 +00:00
|
|
|
#include <functional> // std::function
|
2022-02-06 22:33:23 +00:00
|
|
|
#include <optional>
|
2012-07-27 18:02:50 +00:00
|
|
|
|
2017-10-16 15:57:59 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
|
|
|
|
#include <android/hardware_buffer.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-01 14:57:27 +00:00
|
|
|
class SkData;
|
2022-03-08 13:05:07 +00:00
|
|
|
class SkCanvas;
|
2020-09-17 17:58:26 +00:00
|
|
|
class SkImage;
|
2018-01-23 16:24:08 +00:00
|
|
|
class SkImageFilter;
|
2014-08-18 15:27:09 +00:00
|
|
|
class SkImageGenerator;
|
2020-07-14 21:16:32 +00:00
|
|
|
class SkMipmap;
|
2012-07-27 18:02:50 +00:00
|
|
|
class SkPaint;
|
2015-08-13 16:37:45 +00:00
|
|
|
class SkPicture;
|
2021-02-22 19:08:07 +00:00
|
|
|
class SkPromiseImageTexture;
|
2014-11-21 16:46:37 +00:00
|
|
|
class SkSurface;
|
2020-09-15 15:24:28 +00:00
|
|
|
class SkYUVAPixmaps;
|
2022-03-08 13:05:07 +00:00
|
|
|
class GrBackendFormat;
|
|
|
|
class GrBackendTexture;
|
|
|
|
class GrDirectContext;
|
|
|
|
class GrRecordingContext;
|
|
|
|
class GrContextThreadSafeProxy;
|
|
|
|
class GrYUVABackendTextureInfo;
|
|
|
|
class GrYUVABackendTextures;
|
2012-07-27 18:02:50 +00:00
|
|
|
|
2022-03-02 20:43:58 +00:00
|
|
|
#if SK_GRAPHITE_ENABLED
|
|
|
|
namespace skgpu {
|
|
|
|
class Recorder;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** \class SkImage
|
|
|
|
SkImage describes a two dimensional array of pixels to draw. The pixels may be
|
|
|
|
decoded in a raster bitmap, encoded in a SkPicture or compressed data stream,
|
|
|
|
or located in GPU memory as a GPU texture.
|
|
|
|
|
|
|
|
SkImage cannot be modified after it is created. SkImage may allocate additional
|
|
|
|
storage as needed; for instance, an encoded SkImage may decode when drawn.
|
|
|
|
|
|
|
|
SkImage width and height are greater than zero. Creating an SkImage with zero width
|
|
|
|
or height returns SkImage equal to nullptr.
|
|
|
|
|
|
|
|
SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams,
|
|
|
|
GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported
|
|
|
|
include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details
|
|
|
|
vary with platform.
|
|
|
|
*/
|
2013-04-18 13:28:19 +00:00
|
|
|
class SK_API SkImage : public SkRefCnt {
|
2012-07-25 14:42:15 +00:00
|
|
|
public:
|
2018-06-08 15:49:19 +00:00
|
|
|
|
|
|
|
/** Caller data passed to RasterReleaseProc; may be nullptr.
|
|
|
|
*/
|
2015-06-18 20:41:40 +00:00
|
|
|
typedef void* ReleaseContext;
|
2012-07-25 14:42:15 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param pixmap SkImageInfo, pixel address, and row bytes
|
|
|
|
@return copy of SkPixmap pixels, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_MakeRasterCopy
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap);
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Creates SkImage from SkImageInfo, sharing pixels.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param pixels address or pixel storage
|
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@return SkImage sharing pixels, or nullptr
|
|
|
|
*/
|
2018-05-15 20:06:12 +00:00
|
|
|
static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels,
|
|
|
|
size_t rowBytes);
|
2013-07-25 23:29:40 +00:00
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/** Function called when SkImage no longer shares pixels. ReleaseContext is
|
|
|
|
provided by caller when SkImage is created, and may be nullptr.
|
|
|
|
*/
|
2015-06-18 20:41:40 +00:00
|
|
|
typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates 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.
|
|
|
|
|
|
|
|
@param pixmap SkImageInfo, pixel address, and row bytes
|
|
|
|
@param rasterReleaseProc function called when pixels can be released; or nullptr
|
|
|
|
@param releaseContext state passed to rasterReleaseProc; or nullptr
|
|
|
|
@return SkImage sharing pixmap
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
|
|
|
|
RasterReleaseProc rasterReleaseProc,
|
|
|
|
ReleaseContext releaseContext);
|
2015-06-18 20:41:40 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates 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.
|
|
|
|
|
|
|
|
@param bitmap SkImageInfo, row bytes, and pixels
|
|
|
|
@return created SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_MakeFromBitmap
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap);
|
2017-04-18 19:52:36 +00:00
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
/** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and
|
|
|
|
may not be shared or accessed.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param imageGenerator stock or custom routines to retrieve SkImage
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2020-07-28 16:52:31 +00:00
|
|
|
static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator);
|
2014-08-18 15:27:09 +00:00
|
|
|
|
2019-08-14 15:08:41 +00:00
|
|
|
/**
|
|
|
|
* Return an image backed by the encoded data, but attempt 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.
|
|
|
|
*
|
2021-12-02 15:40:56 +00:00
|
|
|
* 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.
|
2019-08-14 15:08:41 +00:00
|
|
|
*
|
|
|
|
* This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the
|
|
|
|
* actual decode, while the DecodeTo... method explicitly decode and allocate the backend
|
|
|
|
* when the call is made.
|
|
|
|
*
|
2021-12-02 15:40:56 +00:00
|
|
|
* If the encoded format is not supported, nullptr is returned.
|
2019-08-14 15:08:41 +00:00
|
|
|
*
|
|
|
|
* @param encoded the encoded data
|
|
|
|
* @return created SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_MakeFromEncoded
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2021-12-02 15:40:56 +00:00
|
|
|
static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded,
|
2022-02-03 22:08:53 +00:00
|
|
|
std::optional<SkAlphaType> alphaType = std::nullopt);
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2020-01-13 18:02:26 +00:00
|
|
|
/*
|
|
|
|
* Experimental:
|
2020-01-15 17:56:52 +00:00
|
|
|
* Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK
|
|
|
|
* --------------------------------------------------------------------------------------
|
|
|
|
* kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM
|
|
|
|
* | RGB8_ETC2 | |
|
|
|
|
* --------------------------------------------------------------------------------------
|
|
|
|
* kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM
|
|
|
|
* --------------------------------------------------------------------------------------
|
|
|
|
* kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM
|
2020-01-13 18:02:26 +00:00
|
|
|
*/
|
2019-12-10 15:05:06 +00:00
|
|
|
enum class CompressionType {
|
|
|
|
kNone,
|
2020-01-13 18:02:26 +00:00
|
|
|
kETC2_RGB8_UNORM, // the same as ETC1
|
2020-01-15 17:56:52 +00:00
|
|
|
|
2019-12-20 16:32:27 +00:00
|
|
|
kBC1_RGB8_UNORM,
|
2020-01-15 17:56:52 +00:00
|
|
|
kBC1_RGBA8_UNORM,
|
|
|
|
kLast = kBC1_RGBA8_UNORM,
|
2019-01-18 15:36:32 +00:00
|
|
|
};
|
|
|
|
|
2019-12-10 15:05:06 +00:00
|
|
|
static constexpr int kCompressionTypeCount = static_cast<int>(CompressionType::kLast) + 1;
|
|
|
|
|
2020-01-13 18:02:26 +00:00
|
|
|
static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM;
|
2019-12-10 15:05:06 +00:00
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param data compressed data to store in SkImage
|
|
|
|
@param width width of full SkImage
|
|
|
|
@param height height of full SkImage
|
|
|
|
@param type type of compression used
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeRasterFromCompressed(sk_sp<SkData> data,
|
|
|
|
int width, int height,
|
|
|
|
CompressionType type);
|
|
|
|
|
|
|
|
enum class BitDepth {
|
|
|
|
kU8, //!< uses 8-bit unsigned int per color component
|
|
|
|
kF16, //!< uses 16-bit float per color component
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws
|
|
|
|
with default SkPaint. colorSpace may be nullptr.
|
|
|
|
|
|
|
|
@param picture stream of drawing commands
|
|
|
|
@param dimensions width and height
|
|
|
|
@param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
|
|
|
|
@param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
|
|
|
|
@param bitDepth 8-bit integer or 16-bit float: per component
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
|
|
|
|
const SkMatrix* matrix, const SkPaint* paint,
|
|
|
|
BitDepth bitDepth,
|
|
|
|
sk_sp<SkColorSpace> colorSpace);
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
/** Creates a GPU-backed SkImage from compressed data.
|
2019-01-18 15:36:32 +00:00
|
|
|
|
2020-01-27 21:11:57 +00:00
|
|
|
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
|
2020-10-20 14:11:53 +00:00
|
|
|
GrRecordingContext::compressedBackendFormat.
|
2019-01-18 15:36:32 +00:00
|
|
|
|
2020-01-21 20:25:58 +00:00
|
|
|
@param context GPU context
|
|
|
|
@param data compressed data to store in SkImage
|
|
|
|
@param width width of full SkImage
|
|
|
|
@param height height of full SkImage
|
|
|
|
@param type type of compression used
|
|
|
|
@param mipMapped does 'data' contain data for all the mipmap levels?
|
|
|
|
@param isProtected do the contents of 'data' require DRM protection (on Vulkan)?
|
|
|
|
@return created SkImage, or nullptr
|
2019-01-18 15:36:32 +00:00
|
|
|
*/
|
2020-07-16 14:58:58 +00:00
|
|
|
static sk_sp<SkImage> MakeTextureFromCompressed(GrDirectContext* direct,
|
2020-01-28 20:59:31 +00:00
|
|
|
sk_sp<SkData> data,
|
|
|
|
int width, int height,
|
|
|
|
CompressionType type,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped mipMapped = GrMipmapped::kNo,
|
2020-01-28 20:59:31 +00:00
|
|
|
GrProtected isProtected = GrProtected::kNo);
|
2019-01-18 15:36:32 +00:00
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/** User function called when supplied texture may be deleted.
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
|
2015-06-18 20:41:40 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkImage from GPU texture associated with context. GPU texture must stay
|
|
|
|
valid and unchanged until textureReleaseProc is called. textureReleaseProc is
|
|
|
|
passed releaseContext when SkImage is deleted or no longer refers to texture.
|
|
|
|
|
|
|
|
SkImage is returned if format of backendTexture is recognized and supported.
|
|
|
|
Recognized formats vary by GPU back-end.
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
@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.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param context GPU context
|
|
|
|
@param backendTexture texture residing on GPU
|
2019-12-17 19:44:37 +00:00
|
|
|
@param colorSpace This 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()).
|
2018-02-27 15:22:04 +00:00
|
|
|
@param textureReleaseProc function called when texture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2020-08-11 15:48:49 +00:00
|
|
|
static sk_sp<SkImage> MakeFromTexture(GrRecordingContext* context,
|
2017-11-03 12:06:09 +00:00
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin origin,
|
2017-12-18 19:48:15 +00:00
|
|
|
SkColorType colorType,
|
2017-11-03 12:06:09 +00:00
|
|
|
SkAlphaType alphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
2020-08-11 15:48:49 +00:00
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
2017-04-18 19:52:36 +00:00
|
|
|
|
2019-12-17 19:44:37 +00:00
|
|
|
/** Creates an 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 back-end.
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
@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.
|
|
|
|
|
2019-12-17 19:44:37 +00:00
|
|
|
@param context the GPU context
|
|
|
|
@param backendTexture a texture already allocated by the GPU
|
|
|
|
@param alphaType This characterizes the nature of the alpha values in the
|
|
|
|
backend texture. For opaque compressed formats (e.g., ETC1)
|
|
|
|
this should usually be set to kOpaque_SkAlphaType.
|
|
|
|
@param colorSpace This 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()).
|
|
|
|
@param textureReleaseProc function called when the backend texture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2020-08-11 15:48:49 +00:00
|
|
|
static sk_sp<SkImage> MakeFromCompressedTexture(GrRecordingContext* context,
|
2019-12-17 19:44:37 +00:00
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
SkAlphaType alphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context.
|
|
|
|
|
|
|
|
Created SkImage is available to other GPU contexts, and is available across thread
|
2018-06-14 17:21:08 +00:00
|
|
|
boundaries. All contexts must be in the same GPU share group, or otherwise
|
2018-02-27 15:22:04 +00:00
|
|
|
share resources.
|
|
|
|
|
|
|
|
When SkImage is no longer referenced, context releases texture memory
|
|
|
|
asynchronously.
|
|
|
|
|
|
|
|
GrBackendTexture created from pixmap is uploaded to match SkSurface created with
|
|
|
|
dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace().
|
|
|
|
|
|
|
|
SkImage is returned referring to GPU back-end 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 back-end.
|
|
|
|
|
2018-04-13 19:48:26 +00:00
|
|
|
@param context GPU context
|
|
|
|
@param pixmap SkImageInfo, pixel address, and row bytes
|
2018-06-14 17:21:08 +00:00
|
|
|
@param buildMips create SkImage as mip map if true
|
2018-04-13 19:48:26 +00:00
|
|
|
@param dstColorSpace range of colors of matching SkSurface on GPU
|
|
|
|
@param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
|
|
|
|
@return created SkImage, or nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-08-11 15:47:47 +00:00
|
|
|
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrDirectContext* context,
|
|
|
|
const SkPixmap& pixmap,
|
2019-08-15 16:13:53 +00:00
|
|
|
bool buildMips,
|
2018-04-13 19:48:26 +00:00
|
|
|
bool limitToMaxTextureSize = false);
|
2017-04-18 19:52:36 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkImage from backendTexture associated with context. backendTexture and
|
|
|
|
returned SkImage are managed internally, and are released when no longer needed.
|
|
|
|
|
|
|
|
SkImage is returned if format of backendTexture is recognized and supported.
|
|
|
|
Recognized formats vary by GPU back-end.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param backendTexture texture residing on GPU
|
2020-10-05 20:05:23 +00:00
|
|
|
@param textureOrigin origin of backendTexture
|
2020-08-04 18:07:40 +00:00
|
|
|
@param colorType color type of the resulting image
|
|
|
|
@param alphaType alpha type of the resulting image
|
2018-02-27 15:22:04 +00:00
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2020-08-04 18:07:40 +00:00
|
|
|
static sk_sp<SkImage> MakeFromAdoptedTexture(GrRecordingContext* context,
|
2020-07-29 16:50:56 +00:00
|
|
|
const GrBackendTexture& backendTexture,
|
2020-10-05 20:05:23 +00:00
|
|
|
GrSurfaceOrigin textureOrigin,
|
2020-07-29 16:50:56 +00:00
|
|
|
SkColorType colorType,
|
|
|
|
SkAlphaType alphaType = kPremul_SkAlphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr);
|
|
|
|
|
2020-10-19 14:55:45 +00:00
|
|
|
/** Creates an 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.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param yuvaTextures A set of textures containing YUVA data and a description of the
|
|
|
|
data and transformation to RGBA.
|
|
|
|
@param imageColorSpace range of colors of the resulting image after conversion to RGB;
|
|
|
|
may be nullptr
|
|
|
|
@param textureReleaseProc called when the backend textures can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromYUVATextures(GrRecordingContext* context,
|
|
|
|
const GrYUVABackendTextures& yuvaTextures,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr,
|
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
2020-11-20 21:51:24 +00:00
|
|
|
|
2020-09-15 15:24:28 +00:00
|
|
|
/** Creates 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.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param pixmaps The planes as pixmaps with supported SkYUVAInfo that
|
|
|
|
specifies conversion to RGB.
|
|
|
|
@param buildMips create internal YUVA textures as mip map if kYes. This is
|
|
|
|
silently ignored if the context does not support mip maps.
|
|
|
|
@param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
|
|
|
|
@param imageColorSpace range of colors of the resulting image; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromYUVAPixmaps(GrRecordingContext* context,
|
|
|
|
const SkYUVAPixmaps& pixmaps,
|
|
|
|
GrMipMapped buildMips = GrMipmapped::kNo,
|
|
|
|
bool limitToMaxTextureSize = false,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
2017-06-02 14:29:21 +00:00
|
|
|
|
2021-02-22 19:08:07 +00:00
|
|
|
using PromiseImageTextureContext = void*;
|
|
|
|
using PromiseImageTextureFulfillProc =
|
|
|
|
sk_sp<SkPromiseImageTexture> (*)(PromiseImageTextureContext);
|
|
|
|
using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext);
|
|
|
|
|
|
|
|
/** Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. 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 GrMipmapped state. The resulting SkImage can be drawn
|
|
|
|
to a SkDeferredDisplayListRecorder 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)
|
|
|
|
|
|
|
|
@param gpuContextProxy the thread-safe proxy of the gpu context. required.
|
|
|
|
@param backendFormat format of promised gpu texture
|
|
|
|
@param dimensions width & height of promised gpu texture
|
|
|
|
@param mipMapped mip mapped state of promised gpu texture
|
|
|
|
@param origin surface origin of promised gpu texture
|
|
|
|
@param colorType color type of promised gpu texture
|
|
|
|
@param alphaType alpha type of promised gpu texture
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@param textureFulfillProc function called to get actual gpu texture
|
|
|
|
@param textureReleaseProc function called when texture can be deleted
|
|
|
|
@param textureContext state passed to textureFulfillProc and textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakePromiseTexture(sk_sp<GrContextThreadSafeProxy> gpuContextProxy,
|
|
|
|
const GrBackendFormat& backendFormat,
|
|
|
|
SkISize dimensions,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
SkColorType colorType,
|
|
|
|
SkAlphaType alphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
PromiseImageTextureFulfillProc textureFulfillProc,
|
|
|
|
PromiseImageTextureReleaseProc textureReleaseProc,
|
|
|
|
PromiseImageTextureContext textureContext);
|
|
|
|
|
|
|
|
/** This entry point operates like 'MakePromiseTexture' but it is used to construct a 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.
|
|
|
|
|
|
|
|
@param gpuContextProxy the thread-safe proxy of the gpu context. required.
|
|
|
|
@param backendTextureInfo info about the promised yuva gpu texture
|
|
|
|
@param imageColorSpace range of colors; may be nullptr
|
|
|
|
@param textureFulfillProc function called to get actual gpu texture
|
|
|
|
@param textureReleaseProc function called when texture can be deleted
|
|
|
|
@param textureContexts state passed to textureFulfillProc and textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakePromiseYUVATexture(sk_sp<GrContextThreadSafeProxy> gpuContextProxy,
|
|
|
|
const GrYUVABackendTextureInfo& backendTextureInfo,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace,
|
|
|
|
PromiseImageTextureFulfillProc textureFulfillProc,
|
|
|
|
PromiseImageTextureReleaseProc textureReleaseProc,
|
|
|
|
PromiseImageTextureContext textureContexts[]);
|
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
|
|
|
|
/** (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.
|
|
|
|
|
|
|
|
@param hardwareBuffer AHardwareBuffer Android hardware buffer
|
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromAHardwareBuffer(
|
|
|
|
AHardwareBuffer* hardwareBuffer,
|
|
|
|
SkAlphaType alphaType = kPremul_SkAlphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr,
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer
|
|
|
|
@param hardwareBuffer AHardwareBuffer Android hardware buffer
|
|
|
|
@param surfaceOrigin surface origin for resulting image
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromAHardwareBufferWithData(
|
|
|
|
GrDirectContext* context,
|
|
|
|
const SkPixmap& pixmap,
|
|
|
|
AHardwareBuffer* hardwareBuffer,
|
|
|
|
GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
|
|
|
|
#endif
|
|
|
|
|
2019-03-21 19:30:08 +00:00
|
|
|
/** Returns a SkImageInfo describing the width, height, color type, alpha type, and color space
|
|
|
|
of the SkImage.
|
|
|
|
|
|
|
|
@return image info of SkImage.
|
|
|
|
*/
|
|
|
|
const SkImageInfo& imageInfo() const { return fInfo; }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns pixel count in each row.
|
2015-08-13 16:37:45 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@return pixel width in SkImage
|
|
|
|
*/
|
2019-03-21 19:30:08 +00:00
|
|
|
int width() const { return fInfo.width(); }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns pixel row count.
|
|
|
|
|
|
|
|
@return pixel height in SkImage
|
|
|
|
*/
|
2019-03-21 19:30:08 +00:00
|
|
|
int height() const { return fInfo.height(); }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns SkISize { width(), height() }.
|
|
|
|
|
|
|
|
@return integral size of width() and height()
|
|
|
|
*/
|
2019-03-21 19:30:08 +00:00
|
|
|
SkISize dimensions() const { return SkISize::Make(fInfo.width(), fInfo.height()); }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns SkIRect { 0, 0, width(), height() }.
|
|
|
|
|
|
|
|
@return integral rectangle from origin to width() and height()
|
|
|
|
*/
|
2019-03-21 19:30:08 +00:00
|
|
|
SkIRect bounds() const { return SkIRect::MakeWH(fInfo.width(), fInfo.height()); }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns value unique to image. SkImage contents cannot change after SkImage is
|
|
|
|
created. Any operation to create a new SkImage will receive generate a new
|
|
|
|
unique number.
|
|
|
|
|
|
|
|
@return unique identifier
|
|
|
|
*/
|
2012-07-27 18:02:50 +00:00
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2020-02-11 17:24:52 +00:00
|
|
|
/** Returns SkAlphaType.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
SkAlphaType returned was a parameter to an SkImage constructor,
|
|
|
|
or was parsed from encoded data.
|
|
|
|
|
|
|
|
@return SkAlphaType in SkImage
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_alphaType
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2016-08-17 21:01:05 +00:00
|
|
|
SkAlphaType alphaType() const;
|
2016-10-31 12:27:28 +00:00
|
|
|
|
2018-03-14 19:33:42 +00:00
|
|
|
/** Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
@return SkColorType of SkImage
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_colorType
|
2018-03-14 19:33:42 +00:00
|
|
|
*/
|
|
|
|
SkColorType colorType() const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkColorSpace, the range of colors, associated with SkImage. The
|
|
|
|
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
|
|
|
|
immutable.
|
|
|
|
|
|
|
|
SkColorSpace returned was passed to an SkImage constructor,
|
|
|
|
or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage
|
|
|
|
is drawn, depending on the capabilities of the SkSurface receiving the drawing.
|
|
|
|
|
|
|
|
@return SkColorSpace in SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_colorSpace
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-03-02 17:42:35 +00:00
|
|
|
SkColorSpace* colorSpace() const;
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns a smart pointer to SkColorSpace, the range of colors, associated with
|
|
|
|
SkImage. The smart pointer tracks the number of objects sharing this
|
|
|
|
SkColorSpace reference so the memory is released when the owners destruct.
|
|
|
|
|
|
|
|
The returned SkColorSpace is immutable.
|
|
|
|
|
|
|
|
SkColorSpace returned was passed to an SkImage constructor,
|
|
|
|
or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage
|
|
|
|
is drawn, depending on the capabilities of the SkSurface receiving the drawing.
|
|
|
|
|
|
|
|
@return SkColorSpace in SkImage, or nullptr, wrapped in a smart pointer
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_refColorSpace
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-03-02 17:42:35 +00:00
|
|
|
sk_sp<SkColorSpace> refColorSpace() const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkImage pixels represent transparency only. If true, each pixel
|
|
|
|
is packed in 8 bits as defined by kAlpha_8_SkColorType.
|
|
|
|
|
|
|
|
@return true if pixels represent a transparency mask
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_isAlphaOnly
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2016-10-31 12:27:28 +00:00
|
|
|
bool isAlphaOnly() const;
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns true if pixels ignore their alpha value and are treated as fully opaque.
|
|
|
|
|
|
|
|
@return true if SkAlphaType is kOpaque_SkAlphaType
|
|
|
|
*/
|
2016-08-17 21:01:05 +00:00
|
|
|
bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); }
|
2012-07-27 18:02:50 +00:00
|
|
|
|
2020-07-22 20:55:02 +00:00
|
|
|
/**
|
|
|
|
* Make a shader with the specified tiling and mipmap sampling.
|
|
|
|
*/
|
2020-11-06 14:50:47 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&,
|
2020-07-10 12:36:42 +00:00
|
|
|
const SkMatrix* localMatrix = nullptr) const;
|
|
|
|
|
2020-12-08 18:16:56 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling,
|
|
|
|
const SkMatrix& lm) const {
|
|
|
|
return this->makeShader(tmx, tmy, sampling, &lm);
|
|
|
|
}
|
|
|
|
sk_sp<SkShader> makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const {
|
|
|
|
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm);
|
|
|
|
}
|
|
|
|
sk_sp<SkShader> makeShader(const SkSamplingOptions& sampling,
|
|
|
|
const SkMatrix* lm = nullptr) const {
|
|
|
|
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm);
|
|
|
|
}
|
|
|
|
|
2021-11-29 17:27:00 +00:00
|
|
|
/**
|
|
|
|
* makeRawShader functions like makeShader, but for images that contain non-color data.
|
|
|
|
* This includes images encoding things like normals, material properties (eg, roughness),
|
|
|
|
* heightmaps, or any other purely mathematical data that happens to be stored in an image.
|
|
|
|
* These types of images are useful with some programmable shaders (see: SkRuntimeEffect).
|
|
|
|
*
|
|
|
|
* Raw image shaders work like regular image shaders (including filtering and tiling), with
|
|
|
|
* a few major differences:
|
|
|
|
* - No color space transformation is ever applied (the color space of the image is ignored).
|
|
|
|
* - Images with an alpha type of kUnpremul are *not* automatically premultiplied.
|
|
|
|
* - Bicubic filtering is not supported. If SkSamplingOptions::useCubic is true, these
|
|
|
|
* factories will return nullptr.
|
|
|
|
*/
|
|
|
|
sk_sp<SkShader> makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&,
|
|
|
|
const SkMatrix* localMatrix = nullptr) const;
|
|
|
|
|
|
|
|
sk_sp<SkShader> makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling,
|
|
|
|
const SkMatrix& lm) const {
|
|
|
|
return this->makeRawShader(tmx, tmy, sampling, &lm);
|
|
|
|
}
|
|
|
|
sk_sp<SkShader> makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const {
|
|
|
|
return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm);
|
|
|
|
}
|
|
|
|
sk_sp<SkShader> makeRawShader(const SkSamplingOptions& sampling,
|
|
|
|
const SkMatrix* lm = nullptr) const {
|
|
|
|
return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm);
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:50:47 +00:00
|
|
|
using CubicResampler = SkCubicResampler;
|
2020-07-22 20:55:02 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address
|
|
|
|
is available, and returns true. If pixel address is not available, return
|
|
|
|
false and leave pixmap unchanged.
|
|
|
|
|
|
|
|
@param pixmap storage for pixel state if pixels are readable; otherwise, ignored
|
|
|
|
@return true if SkImage has direct access to pixels
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_peekPixels
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2016-03-09 22:26:26 +00:00
|
|
|
bool peekPixels(SkPixmap* pixmap) const;
|
|
|
|
|
2022-03-02 21:46:01 +00:00
|
|
|
/** Returns true if the contents of SkImage was created on or uploaded to GPU memory,
|
2018-02-27 15:22:04 +00:00
|
|
|
and is available as a GPU texture.
|
|
|
|
|
|
|
|
@return true if SkImage is a GPU texture
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_isTextureBacked
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2015-06-10 15:49:28 +00:00
|
|
|
bool isTextureBacked() const;
|
|
|
|
|
2021-02-11 13:59:03 +00:00
|
|
|
/** Returns an approximation of the amount of texture memory used by the image. Returns
|
|
|
|
zero if the image is not texture backed or if the texture has an external format.
|
|
|
|
*/
|
|
|
|
size_t textureSize() const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkImage can be drawn on either raster surface or GPU surface.
|
|
|
|
If context is nullptr, tests if SkImage draws on raster surface;
|
|
|
|
otherwise, tests if SkImage draws on GPU surface associated with context.
|
|
|
|
|
2020-07-10 15:27:43 +00:00
|
|
|
SkImage backed by GPU texture may become invalid if associated context is
|
2018-02-27 15:22:04 +00:00
|
|
|
invalid. lazy image may be invalid and may not draw to raster surface or
|
|
|
|
GPU surface or both.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@return true if SkImage can be drawn
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_isValid
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-07-10 15:27:43 +00:00
|
|
|
bool isValid(GrRecordingContext* context) const;
|
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2019-05-09 14:30:12 +00:00
|
|
|
/** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not
|
2020-07-22 14:22:12 +00:00
|
|
|
texture-backed (including promise texture images) or if the GrDirectContext does not
|
2019-05-09 14:30:12 +00:00
|
|
|
have the same context ID as the context backing the image then this is a no-op.
|
|
|
|
|
2020-07-22 14:22:12 +00:00
|
|
|
If the image was not used in any non-culled draws in the current queue of work for the
|
|
|
|
passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or
|
|
|
|
a finish proc. Those are respected even when the image has not been used.
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
@param context the context on which to flush pending usages of the image.
|
|
|
|
@param info flush options
|
|
|
|
*/
|
2021-10-27 17:35:59 +00:00
|
|
|
GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const;
|
2019-05-09 14:30:12 +00:00
|
|
|
|
2021-10-27 17:35:59 +00:00
|
|
|
void flush(GrDirectContext* context) const { this->flush(context, {}); }
|
2020-06-26 01:00:17 +00:00
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
/** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the
|
|
|
|
GPU.
|
|
|
|
*/
|
2021-10-27 17:35:59 +00:00
|
|
|
void flushAndSubmit(GrDirectContext*) const;
|
2020-07-22 14:22:12 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid
|
2018-04-05 12:18:41 +00:00
|
|
|
object is returned. Call GrBackendTexture::isValid to determine if the result
|
|
|
|
is valid.
|
2018-04-04 19:54:55 +00:00
|
|
|
|
2018-04-05 12:18:41 +00:00
|
|
|
If flushPendingGrContextIO is true, completes deferred I/O operations.
|
|
|
|
|
|
|
|
If origin in not nullptr, copies location of content drawn into SkImage.
|
2018-04-04 19:54:55 +00:00
|
|
|
|
|
|
|
@param flushPendingGrContextIO flag to flush outstanding requests
|
2018-04-05 12:18:41 +00:00
|
|
|
@return back-end API texture handle; invalid on failure
|
|
|
|
*/
|
2018-04-04 19:54:55 +00:00
|
|
|
GrBackendTexture getBackendTexture(bool flushPendingGrContextIO,
|
|
|
|
GrSurfaceOrigin* origin = nullptr) const;
|
2021-10-28 11:31:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2018-04-04 19:54:55 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** \enum SkImage::CachingHint
|
|
|
|
CachingHint selects whether Skia may internally cache SkBitmap generated by
|
|
|
|
decoding SkImage, or by copying SkImage from GPU to CPU. The default behavior
|
|
|
|
allows caching SkBitmap.
|
|
|
|
|
|
|
|
Choose kDisallow_CachingHint if SkImage pixels are to be used only once, or
|
|
|
|
if SkImage pixels reside in a cache outside of Skia, or to reduce memory pressure.
|
|
|
|
|
|
|
|
Choosing kAllow_CachingHint does not ensure that pixels will be cached.
|
|
|
|
SkImage pixels may not be cached if memory requirements are too large or
|
|
|
|
pixels are not accessible.
|
|
|
|
*/
|
|
|
|
enum CachingHint {
|
2018-05-30 13:20:29 +00:00
|
|
|
kAllow_CachingHint, //!< allows internally caching decoded and copied pixels
|
|
|
|
kDisallow_CachingHint, //!< disallows internally caching decoded and copied pixels
|
2015-11-23 20:32:16 +00:00
|
|
|
};
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkRect of pixels from SkImage to dstPixels. Copy starts at offset (srcX, srcY),
|
|
|
|
and does not exceed SkImage (width(), height()).
|
|
|
|
|
|
|
|
dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of
|
2019-05-06 17:04:03 +00:00
|
|
|
destination. dstRowBytes specifies the gap from one destination row to the next.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns true if pixels are copied. Returns false if:
|
|
|
|
- dstInfo.addr() equals nullptr
|
|
|
|
- dstRowBytes is less than dstInfo.minRowBytes()
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
|
|
|
Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
|
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
|
|
|
If SkImage SkColorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
|
|
|
|
If SkImage SkAlphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
|
|
|
|
match. If SkImage SkColorSpace is nullptr, dstInfo.colorSpace() must match. Returns
|
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
|
|
|
Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().
|
|
|
|
|
|
|
|
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
|
|
|
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
@param context the GrDirectContext in play, if it exists
|
2018-02-27 15:22:04 +00:00
|
|
|
@param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
|
|
|
|
@param dstPixels destination pixel storage
|
|
|
|
@param dstRowBytes destination row length
|
|
|
|
@param srcX column index whose absolute value is less than width()
|
|
|
|
@param srcY row index whose absolute value is less than height()
|
2020-08-27 16:44:07 +00:00
|
|
|
@param cachingHint whether the pixels should be cached locally
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels are copied to dstPixels
|
|
|
|
*/
|
2020-08-27 16:44:07 +00:00
|
|
|
bool readPixels(GrDirectContext* context,
|
|
|
|
const SkImageInfo& dstInfo,
|
|
|
|
void* dstPixels,
|
|
|
|
size_t dstRowBytes,
|
|
|
|
int srcX, int srcY,
|
|
|
|
CachingHint cachingHint = kAllow_CachingHint) const;
|
2015-11-23 20:32:16 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies a SkRect of pixels from SkImage to dst. Copy starts at (srcX, srcY), and
|
|
|
|
does not exceed SkImage (width(), height()).
|
|
|
|
|
|
|
|
dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of destination. dst.rowBytes() specifics the gap from one destination
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- dst pixel storage equals nullptr
|
|
|
|
- dst.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
|
|
|
Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
|
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match.
|
|
|
|
If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match.
|
|
|
|
If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must
|
|
|
|
match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
|
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
|
|
|
Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().
|
|
|
|
|
|
|
|
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
|
|
|
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
@param context the GrDirectContext in play, if it exists
|
2018-02-27 15:22:04 +00:00
|
|
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@param srcX column index whose absolute value is less than width()
|
|
|
|
@param srcY row index whose absolute value is less than height()
|
2020-08-27 16:44:07 +00:00
|
|
|
@param cachingHint whether the pixels should be cached locallyZ
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels are copied to dst
|
|
|
|
*/
|
2020-08-27 16:44:07 +00:00
|
|
|
bool readPixels(GrDirectContext* context,
|
|
|
|
const SkPixmap& dst,
|
|
|
|
int srcX,
|
|
|
|
int srcY,
|
|
|
|
CachingHint cachingHint = kAllow_CachingHint) const;
|
|
|
|
|
|
|
|
#ifndef SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API
|
|
|
|
/** Deprecated. Use the variants that accept a GrDirectContext. */
|
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
|
|
|
int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const;
|
2015-11-23 20:32:16 +00:00
|
|
|
bool readPixels(const SkPixmap& dst, int srcX, int srcY,
|
2017-11-03 12:06:09 +00:00
|
|
|
CachingHint cachingHint = kAllow_CachingHint) const;
|
2020-08-27 16:44:07 +00:00
|
|
|
#endif
|
2014-12-10 17:53:42 +00:00
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
/** The result from asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420(). */
|
|
|
|
class AsyncReadResult {
|
|
|
|
public:
|
|
|
|
AsyncReadResult(const AsyncReadResult&) = delete;
|
|
|
|
AsyncReadResult(AsyncReadResult&&) = delete;
|
|
|
|
AsyncReadResult& operator=(const AsyncReadResult&) = delete;
|
|
|
|
AsyncReadResult& operator=(AsyncReadResult&&) = delete;
|
|
|
|
|
|
|
|
virtual ~AsyncReadResult() = default;
|
|
|
|
virtual int count() const = 0;
|
|
|
|
virtual const void* data(int i) const = 0;
|
|
|
|
virtual size_t rowBytes(int i) const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
AsyncReadResult() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Client-provided context that is passed to client-provided ReadPixelsContext. */
|
|
|
|
using ReadPixelsContext = void*;
|
|
|
|
|
|
|
|
/** Client-provided callback to asyncRescaleAndReadPixels() or
|
|
|
|
asyncRescaleAndReadPixelsYUV420() that is called when read result is ready or on failure.
|
|
|
|
*/
|
|
|
|
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>);
|
|
|
|
|
|
|
|
enum class RescaleGamma : bool { kSrc, kLinear };
|
|
|
|
|
2021-01-03 02:44:59 +00:00
|
|
|
enum class RescaleMode {
|
|
|
|
kNearest,
|
|
|
|
kRepeatedLinear,
|
|
|
|
kRepeatedCubic,
|
|
|
|
};
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
/** Makes image pixel data available to caller, possibly asynchronously. It can also rescale
|
|
|
|
the image pixels.
|
|
|
|
|
|
|
|
Currently asynchronous reads are only supported on the GPU backend and only when the
|
|
|
|
underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all
|
|
|
|
other cases this operates synchronously.
|
|
|
|
|
|
|
|
Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is
|
|
|
|
rescaled to the size indicated by 'info', is then converted to the color space, color type,
|
|
|
|
and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image
|
|
|
|
causes failure.
|
|
|
|
|
|
|
|
When the pixel data is ready the caller's ReadPixelsCallback is called with a
|
|
|
|
AsyncReadResult containing pixel data in the requested color type, alpha type, and color
|
|
|
|
space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with
|
|
|
|
nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to
|
|
|
|
guarantee a finite time before the callback is called.
|
|
|
|
|
|
|
|
The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage
|
2020-10-20 14:11:53 +00:00
|
|
|
is GPU-backed the data is immediately invalidated if the context is abandoned or
|
2020-06-26 17:32:09 +00:00
|
|
|
destroyed.
|
|
|
|
|
|
|
|
@param info info of the requested pixels
|
|
|
|
@param srcRect subrectangle of image to read
|
|
|
|
@param rescaleGamma controls whether rescaling is done in the image's gamma or whether
|
|
|
|
the source data is transformed to a linear gamma before rescaling.
|
2021-01-03 02:44:59 +00:00
|
|
|
@param rescaleMode controls the technique (and cost) of the rescaling
|
2020-06-26 17:32:09 +00:00
|
|
|
@param callback function to call with result of the read
|
|
|
|
@param context passed to callback
|
|
|
|
*/
|
|
|
|
void asyncRescaleAndReadPixels(const SkImageInfo& info,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
RescaleGamma rescaleGamma,
|
2021-01-03 02:44:59 +00:00
|
|
|
RescaleMode rescaleMode,
|
2020-06-26 17:32:09 +00:00
|
|
|
ReadPixelsCallback callback,
|
2021-10-27 17:35:59 +00:00
|
|
|
ReadPixelsContext context) const;
|
2020-06-26 17:32:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The
|
|
|
|
RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three
|
|
|
|
planes ordered y, u, v. The u and v planes are half the width and height of the resized
|
|
|
|
rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize'
|
|
|
|
width and height are not even. A 'srcRect' that is not contained by the bounds of the
|
|
|
|
image causes failure.
|
|
|
|
|
|
|
|
When the pixel data is ready the caller's ReadPixelsCallback is called with a
|
|
|
|
AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3.
|
|
|
|
Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU image this
|
|
|
|
flushes work but a submit must occur to guarantee a finite time before the callback is
|
|
|
|
called.
|
|
|
|
|
|
|
|
The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage
|
2020-10-20 14:11:53 +00:00
|
|
|
is GPU-backed the data is immediately invalidated if the context is abandoned or
|
2020-06-26 17:32:09 +00:00
|
|
|
destroyed.
|
|
|
|
|
|
|
|
@param yuvColorSpace The transformation from RGB to YUV. Applied to the resized image
|
|
|
|
after it is converted to dstColorSpace.
|
|
|
|
@param dstColorSpace The color space to convert the resized image to, after rescaling.
|
|
|
|
@param srcRect The portion of the image to rescale and convert to YUV planes.
|
|
|
|
@param dstSize The size to rescale srcRect to
|
|
|
|
@param rescaleGamma controls whether rescaling is done in the image's gamma or whether
|
|
|
|
the source data is transformed to a linear gamma before rescaling.
|
2021-01-03 02:44:59 +00:00
|
|
|
@param rescaleMode controls the technique (and cost) of the rescaling
|
2020-06-26 17:32:09 +00:00
|
|
|
@param callback function to call with the planar read result
|
|
|
|
@param context passed to callback
|
|
|
|
*/
|
|
|
|
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
|
|
|
sk_sp<SkColorSpace> dstColorSpace,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
const SkISize& dstSize,
|
|
|
|
RescaleGamma rescaleGamma,
|
2021-01-03 02:44:59 +00:00
|
|
|
RescaleMode rescaleMode,
|
2020-06-26 17:32:09 +00:00
|
|
|
ReadPixelsCallback callback,
|
2021-10-27 17:35:59 +00:00
|
|
|
ReadPixelsContext context) const;
|
2020-06-26 17:32:09 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and
|
|
|
|
converting pixels to match dst.colorType() and dst.alphaType(). Returns true if
|
|
|
|
pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is
|
|
|
|
less than dst SkImageInfo::minRowBytes.
|
|
|
|
|
|
|
|
Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is
|
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match.
|
|
|
|
If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match.
|
|
|
|
If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must
|
|
|
|
match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns
|
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
|
|
|
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
|
|
|
|
|
|
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@return true if pixels are scaled to fit dst
|
|
|
|
*/
|
2020-11-23 22:41:35 +00:00
|
|
|
bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&,
|
2017-11-03 12:06:09 +00:00
|
|
|
CachingHint cachingHint = kAllow_CachingHint) const;
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Encodes SkImage pixels, returning result as SkData.
|
|
|
|
|
|
|
|
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
|
|
|
|
|
|
|
|
SkImage encoding in a format requires both building with one or more of:
|
2020-03-09 18:23:30 +00:00
|
|
|
SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support
|
2018-02-27 15:22:04 +00:00
|
|
|
for the encoded format.
|
|
|
|
|
|
|
|
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can
|
|
|
|
additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP,
|
|
|
|
SkEncodedImageFormat::kGIF.
|
|
|
|
|
|
|
|
quality is a platform and format specific metric trading off size and encoding
|
|
|
|
error. When used, quality equaling 100 encodes with the least error. quality may
|
|
|
|
be ignored by the encoder.
|
|
|
|
|
|
|
|
@param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG,
|
|
|
|
SkEncodedImageFormat::kWEBP
|
|
|
|
@param quality encoder specific metric with 100 equaling best
|
|
|
|
@return encoded SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_encodeToData
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const;
|
2016-11-08 14:29:46 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data
|
|
|
|
if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia
|
2020-03-09 18:23:30 +00:00
|
|
|
must be built with SK_ENCODE_PNG to encode SkImage.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
Returns nullptr if existing encoded data is missing or invalid, and
|
|
|
|
encoding fails.
|
|
|
|
|
|
|
|
@return encoded SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_encodeToData_2
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-12-16 13:41:28 +00:00
|
|
|
sk_sp<SkData> encodeToData() const;
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns encoded SkImage pixels as SkData, if SkImage was created from supported
|
|
|
|
encoded stream format. Platform support for formats vary and may require building
|
2020-03-09 18:23:30 +00:00
|
|
|
with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
Returns nullptr if SkImage contents are not encoded.
|
|
|
|
|
|
|
|
@return encoded SkImage, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_refEncodedData
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-07-11 20:03:13 +00:00
|
|
|
sk_sp<SkData> refEncodedData() const;
|
|
|
|
|
2020-07-29 00:19:18 +00:00
|
|
|
/** Returns subset of this image.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2020-07-10 18:33:22 +00:00
|
|
|
Returns nullptr if any of the following are true:
|
|
|
|
- Subset is empty
|
2020-07-29 00:19:18 +00:00
|
|
|
- Subset is not contained inside the image's bounds
|
|
|
|
- Pixels in the image could not be read or copied
|
2020-07-10 18:33:22 +00:00
|
|
|
|
|
|
|
If this image is texture-backed, the context parameter is required and must match the
|
2020-07-29 00:19:18 +00:00
|
|
|
context of the source image. If the context parameter is provided, and the image is
|
|
|
|
raster-backed, the subset will be converted to texture-backed.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
@param subset bounds of returned SkImage
|
2020-07-10 18:33:22 +00:00
|
|
|
@param context the GrDirectContext in play, if it exists
|
2020-07-29 00:19:18 +00:00
|
|
|
@return the subsetted image, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_makeSubset
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-07-10 18:33:22 +00:00
|
|
|
sk_sp<SkImage> makeSubset(const SkIRect& subset, GrDirectContext* direct = nullptr) const;
|
2015-01-23 13:58:07 +00:00
|
|
|
|
2020-07-14 15:29:38 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the image has mipmap levels.
|
|
|
|
*/
|
|
|
|
bool hasMipmaps() const;
|
|
|
|
|
2020-09-12 14:38:32 +00:00
|
|
|
/**
|
|
|
|
* Returns an image with the same "base" pixels as the this image, but with mipmap levels
|
|
|
|
* automatically generated and attached.
|
|
|
|
*/
|
|
|
|
sk_sp<SkImage> withDefaultMipmaps() const;
|
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkImage backed by GPU texture associated with context. Returned SkImage is
|
2018-06-14 17:21:08 +00:00
|
|
|
compatible with SkSurface created with dstColorSpace. The returned SkImage respects
|
2020-07-21 13:27:25 +00:00
|
|
|
mipMapped setting; if mipMapped equals GrMipmapped::kYes, the backing texture
|
2020-03-18 14:06:13 +00:00
|
|
|
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. SkBudgeted is ignored in this case.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
Returns nullptr if context is nullptr, or if SkImage was created with another
|
2020-07-16 14:58:58 +00:00
|
|
|
GrDirectContext.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2020-07-16 14:58:58 +00:00
|
|
|
@param GrDirectContext the GrDirectContext in play, if it exists
|
2020-07-21 13:27:25 +00:00
|
|
|
@param GrMipmapped whether created SkImage texture must allocate mip map levels
|
2020-07-16 14:58:58 +00:00
|
|
|
@param SkBudgeted whether to count a newly created texture for the returned image
|
2020-10-20 14:11:53 +00:00
|
|
|
counts against the context's budget.
|
2020-07-16 14:58:58 +00:00
|
|
|
@return created SkImage, or nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-07-16 14:58:58 +00:00
|
|
|
sk_sp<SkImage> makeTextureImage(GrDirectContext*,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped = GrMipmapped::kNo,
|
2020-07-16 14:58:58 +00:00
|
|
|
SkBudgeted = SkBudgeted::kYes) const;
|
2022-03-02 20:43:58 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
|
|
|
/** Graphite version of makeTextureImage.
|
|
|
|
|
|
|
|
Returns SkImage backed by GPU texture, using Recorder for creation and uploads if necessary.
|
|
|
|
The returned SkImage respects mipMapped setting for non-GPU SkImages; if mipMapped
|
|
|
|
equals GrMipmapped::kYes, the backing texture allocates mip map levels.
|
|
|
|
|
|
|
|
It is assumed that MIP maps are always supported by the GPU.
|
|
|
|
|
|
|
|
Returns original SkImage if the image is already texture-backed, the recorder matches, and
|
|
|
|
mipMapped is compatible with the backing GPU texture. If mipmapped is not compatible,
|
|
|
|
it will return nullptr.
|
|
|
|
|
|
|
|
Returns nullptr if recorder is nullptr, or if SkImage was created with another
|
|
|
|
Recorder and work on that Recorder has not been submitted.
|
|
|
|
|
|
|
|
@param Recorder the Recorder to use for storing commands
|
|
|
|
@param Mipmapped whether created SkImage texture must allocate mip map levels
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
sk_sp<SkImage> makeTextureImage(skgpu::Recorder*,
|
|
|
|
skgpu::Mipmapped = skgpu::Mipmapped::kNo,
|
|
|
|
SkBudgeted = SkBudgeted::kYes) const;
|
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
#endif
|
2020-07-28 14:23:33 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns raster image or lazy image. Copies SkImage backed by GPU texture into
|
|
|
|
CPU memory if needed. Returns original SkImage if decoded in raster bitmap,
|
|
|
|
or if encoded in a stream.
|
|
|
|
|
|
|
|
Returns nullptr if backed by GPU texture and copy fails.
|
|
|
|
|
|
|
|
@return raster image, lazy image, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2016-07-13 01:11:17 +00:00
|
|
|
sk_sp<SkImage> makeNonTextureImage() const;
|
2017-12-04 19:27:01 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns raster image. Copies SkImage backed by GPU texture into CPU memory,
|
|
|
|
or decodes SkImage from lazy image. Returns original SkImage if decoded in
|
|
|
|
raster bitmap.
|
|
|
|
|
|
|
|
Returns nullptr if copy, decode, or pixel read fails.
|
|
|
|
|
2020-01-09 15:21:44 +00:00
|
|
|
If cachingHint is kAllow_CachingHint, pixels may be retained locally.
|
|
|
|
If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@return raster image, or nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_makeRasterImage
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-01-09 15:21:44 +00:00
|
|
|
sk_sp<SkImage> makeRasterImage(CachingHint cachingHint = kDisallow_CachingHint) const;
|
2017-12-04 19:27:01 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates filtered SkImage. filter processes original SkImage, potentially changing
|
|
|
|
color, position, and size. subset is the bounds of original SkImage 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.
|
|
|
|
|
2020-07-21 20:50:06 +00:00
|
|
|
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
|
2018-02-27 15:22:04 +00:00
|
|
|
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.
|
|
|
|
|
2020-07-21 20:50:06 +00:00
|
|
|
@param context the GrRecordingContext in play - if it exists
|
2018-02-27 15:22:04 +00:00
|
|
|
@param filter how SkImage is sampled when transformed
|
|
|
|
@param subset bounds of SkImage processed by filter
|
|
|
|
@param clipBounds expected bounds of filtered SkImage
|
|
|
|
@param outSubset storage for returned SkImage bounds
|
|
|
|
@param offset storage for returned SkImage translation
|
|
|
|
@return filtered SkImage, or nullptr
|
|
|
|
*/
|
2020-07-21 20:50:06 +00:00
|
|
|
sk_sp<SkImage> makeWithFilter(GrRecordingContext* context,
|
2019-01-10 21:34:22 +00:00
|
|
|
const SkImageFilter* filter, const SkIRect& subset,
|
|
|
|
const SkIRect& clipBounds, SkIRect* outSubset,
|
|
|
|
SkIPoint* offset) const;
|
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/** Defines a callback function, taking one parameter of type GrBackendTexture with
|
|
|
|
no return value. Function is called when back-end texture is to be released.
|
|
|
|
*/
|
2017-10-12 19:44:50 +00:00
|
|
|
typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc;
|
|
|
|
|
2021-10-28 11:31:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates a GrBackendTexture from the provided SkImage. Returns true and
|
|
|
|
stores result in backendTexture and backendTextureReleaseProc if
|
|
|
|
texture is created; otherwise, returns false and leaves
|
|
|
|
backendTexture and backendTextureReleaseProc unmodified.
|
|
|
|
|
|
|
|
Call backendTextureReleaseProc after deleting backendTexture.
|
|
|
|
backendTextureReleaseProc cleans up auxiliary data related to returned
|
|
|
|
backendTexture. The caller must delete returned backendTexture after use.
|
|
|
|
|
|
|
|
If SkImage is both texture backed and singly referenced, image is returned in
|
|
|
|
backendTexture without conversion or making a copy. SkImage is singly referenced
|
|
|
|
if its was transferred solely using std::move().
|
|
|
|
|
|
|
|
If SkImage is not texture backed, returns texture with SkImage contents.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param image SkImage used for texture
|
2018-05-30 13:20:29 +00:00
|
|
|
@param backendTexture storage for back-end texture
|
2018-02-27 15:22:04 +00:00
|
|
|
@param backendTextureReleaseProc storage for clean up function
|
2018-05-30 13:20:29 +00:00
|
|
|
@return true if back-end texture was created
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-10-20 14:11:53 +00:00
|
|
|
static bool MakeBackendTextureFromSkImage(GrDirectContext* context,
|
2017-11-03 12:06:09 +00:00
|
|
|
sk_sp<SkImage> image,
|
|
|
|
GrBackendTexture* backendTexture,
|
|
|
|
BackendTextureReleaseProc* backendTextureReleaseProc);
|
2021-10-28 11:31:32 +00:00
|
|
|
#endif
|
2018-11-15 13:25:12 +00:00
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2015-07-08 19:46:22 +00:00
|
|
|
enum LegacyBitmapMode {
|
2018-05-30 13:20:29 +00:00
|
|
|
kRO_LegacyBitmapMode, //!< returned bitmap is read-only and immutable
|
2015-07-08 19:46:22 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 13:25:12 +00:00
|
|
|
/** Deprecated.
|
|
|
|
Creates raster SkBitmap with same pixels as SkImage. If legacyBitmapMode is
|
2018-02-27 15:22:04 +00:00
|
|
|
kRO_LegacyBitmapMode, returned bitmap is read-only and immutable.
|
|
|
|
Returns true if SkBitmap is stored in bitmap. Returns false and resets bitmap if
|
|
|
|
SkBitmap write did not succeed.
|
|
|
|
|
|
|
|
@param bitmap storage for legacy SkBitmap
|
2018-11-15 13:25:12 +00:00
|
|
|
@param legacyBitmapMode bitmap is read-only and immutable
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if SkBitmap was created
|
|
|
|
*/
|
2018-10-12 19:00:20 +00:00
|
|
|
bool asLegacyBitmap(SkBitmap* bitmap,
|
|
|
|
LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const;
|
2016-06-03 18:17:42 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkImage is backed by an image-generator or other service that creates
|
|
|
|
and caches its pixels or texture on-demand.
|
|
|
|
|
|
|
|
@return true if SkImage is created as needed
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a
|
|
|
|
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2015-08-20 15:47:26 +00:00
|
|
|
bool isLazyGenerated() const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkImage in target SkColorSpace.
|
|
|
|
Returns nullptr if SkImage could not be created.
|
|
|
|
|
|
|
|
Returns original SkImage if it is in target SkColorSpace.
|
|
|
|
Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace.
|
|
|
|
If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.
|
|
|
|
|
2020-07-15 14:37:50 +00:00
|
|
|
If this image is texture-backed, the context parameter is required and must match the
|
|
|
|
context of the source image.
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
@param target SkColorSpace describing color range of returned SkImage
|
2020-07-15 14:37:50 +00:00
|
|
|
@param direct The GrDirectContext in play, if it exists
|
2018-08-10 17:11:06 +00:00
|
|
|
@return created SkImage in target SkColorSpace
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Image_makeColorSpace
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2020-07-15 14:37:50 +00:00
|
|
|
sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
|
|
|
|
GrDirectContext* direct = nullptr) const;
|
2017-04-05 15:41:27 +00:00
|
|
|
|
2019-01-14 16:15:50 +00:00
|
|
|
/** Experimental.
|
|
|
|
Creates SkImage in target SkColorType and SkColorSpace.
|
|
|
|
Returns nullptr if SkImage could not be created.
|
|
|
|
|
|
|
|
Returns original SkImage if it is in target SkColorType and SkColorSpace.
|
|
|
|
|
2020-07-15 14:37:50 +00:00
|
|
|
If this image is texture-backed, the context parameter is required and must match the
|
|
|
|
context of the source image.
|
|
|
|
|
2019-01-14 16:15:50 +00:00
|
|
|
@param targetColorType SkColorType of returned SkImage
|
|
|
|
@param targetColorSpace SkColorSpace of returned SkImage
|
2020-07-15 14:37:50 +00:00
|
|
|
@param direct The GrDirectContext in play, if it exists
|
2019-01-14 16:15:50 +00:00
|
|
|
@return created SkImage in target SkColorType and SkColorSpace
|
|
|
|
*/
|
|
|
|
sk_sp<SkImage> makeColorTypeAndColorSpace(SkColorType targetColorType,
|
2020-07-15 14:37:50 +00:00
|
|
|
sk_sp<SkColorSpace> targetColorSpace,
|
|
|
|
GrDirectContext* direct = nullptr) const;
|
2019-01-14 16:15:50 +00:00
|
|
|
|
2019-08-14 20:14:51 +00:00
|
|
|
/** Creates a new SkImage identical to this one, but with a different SkColorSpace.
|
|
|
|
This does not convert the underlying pixel data, so the resulting image will draw
|
|
|
|
differently.
|
|
|
|
*/
|
|
|
|
sk_sp<SkImage> reinterpretColorSpace(sk_sp<SkColorSpace> newColorSpace) const;
|
|
|
|
|
2017-05-26 16:54:32 +00:00
|
|
|
private:
|
2019-03-21 19:30:08 +00:00
|
|
|
SkImage(const SkImageInfo& info, uint32_t uniqueID);
|
2020-12-23 16:50:36 +00:00
|
|
|
|
|
|
|
friend class SkBitmap;
|
2017-05-26 16:54:32 +00:00
|
|
|
friend class SkImage_Base;
|
2020-09-17 17:58:26 +00:00
|
|
|
friend class SkMipmapBuilder;
|
2012-07-27 18:02:50 +00:00
|
|
|
|
2019-03-21 19:30:08 +00:00
|
|
|
SkImageInfo fInfo;
|
2012-07-27 18:02:50 +00:00
|
|
|
const uint32_t fUniqueID;
|
|
|
|
|
2020-09-17 17:58:26 +00:00
|
|
|
sk_sp<SkImage> withMipmaps(sk_sp<SkMipmap>) const;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkRefCnt;
|
2012-07-25 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|