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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFilterQuality.h"
|
|
|
|
#include "include/core/SkImageEncoder.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
2019-08-27 13:12:15 +00:00
|
|
|
#include <functional> // std::function
|
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
|
|
|
|
|
2012-07-27 18:02:50 +00:00
|
|
|
class SkData;
|
|
|
|
class SkCanvas;
|
2018-01-23 16:24:08 +00:00
|
|
|
class SkImageFilter;
|
2014-08-18 15:27:09 +00:00
|
|
|
class SkImageGenerator;
|
2012-07-27 18:02:50 +00:00
|
|
|
class SkPaint;
|
2015-08-13 16:37:45 +00:00
|
|
|
class SkPicture;
|
2014-11-21 16:46:37 +00:00
|
|
|
class SkSurface;
|
2017-04-18 19:52:36 +00:00
|
|
|
class GrBackendTexture;
|
2012-07-31 15:45:27 +00:00
|
|
|
class GrContext;
|
2016-03-11 14:46:33 +00:00
|
|
|
class GrContextThreadSafeProxy;
|
2012-10-31 14:58:16 +00:00
|
|
|
class GrTexture;
|
2012-07-27 18:02:50 +00:00
|
|
|
|
2018-10-05 14:31:34 +00:00
|
|
|
struct SkYUVAIndex;
|
|
|
|
|
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
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
subset allows selecting a portion of the full image. Pass nullptr to select the entire
|
|
|
|
image; otherwise, subset must be contained by image bounds.
|
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
|
|
|
|
@param subset bounds of returned SkImage; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
|
2017-02-15 20:14:16 +00:00
|
|
|
const SkIRect* subset = nullptr);
|
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.
|
|
|
|
*
|
|
|
|
* The subset parameter specifies a area within the decoded image to create the image from.
|
|
|
|
* If subset is null, then the entire image is returned.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* If the encoded format is not supported, or subset is outside of the bounds of the decoded
|
|
|
|
* image, nullptr is returned.
|
|
|
|
*
|
|
|
|
* @param encoded the encoded data
|
|
|
|
* @param length the number of bytes of encoded data
|
|
|
|
* @param subset the bounds of the pixels within the decoded image to return. may be null.
|
|
|
|
* @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
|
|
|
*/
|
2016-07-20 20:55:39 +00:00
|
|
|
static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr);
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2019-08-14 15:08:41 +00:00
|
|
|
/**
|
|
|
|
* Decode the data in encoded/length into a raster image.
|
|
|
|
*
|
|
|
|
* The subset parameter specifies a area within the decoded image to create the image from.
|
|
|
|
* If subset is null, then the entire image is returned.
|
|
|
|
*
|
|
|
|
* This is similar to MakeFromEncoded, but this method will always decode immediately, and
|
|
|
|
* allocate the memory for the pixels for the lifetime of the returned image.
|
|
|
|
*
|
|
|
|
* If the encoded format is not supported, or subset is outside of the bounds of the decoded
|
|
|
|
* image, nullptr is returned.
|
|
|
|
*
|
|
|
|
* @param encoded the encoded data
|
|
|
|
* @param length the number of bytes of encoded data
|
|
|
|
* @param subset the bounds of the pixels within the decoded image to return. may be null.
|
|
|
|
* @return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> DecodeToRaster(const void* encoded, size_t length,
|
|
|
|
const SkIRect* subset = nullptr);
|
|
|
|
static sk_sp<SkImage> DecodeToRaster(const sk_sp<SkData>& data,
|
|
|
|
const SkIRect* subset = nullptr) {
|
|
|
|
return DecodeToRaster(data->data(), data->size(), subset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode the data in encoded/length into a texture-backed image.
|
|
|
|
*
|
|
|
|
* The subset parameter specifies a area within the decoded image to create the image from.
|
|
|
|
* If subset is null, then the entire image is returned.
|
|
|
|
*
|
|
|
|
* This is similar to MakeFromEncoded, but this method will always decode immediately, and
|
|
|
|
* allocate the texture for the pixels for the lifetime of the returned image.
|
|
|
|
*
|
|
|
|
* If the encoded format is not supported, or subset is outside of the bounds of the decoded
|
|
|
|
* image, nullptr is returned.
|
|
|
|
*
|
|
|
|
* @param encoded the encoded data
|
|
|
|
* @param length the number of bytes of encoded data
|
|
|
|
* @param subset the bounds of the pixels within the decoded image to return. may be null.
|
|
|
|
* @return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> DecodeToTexture(GrContext* ctx, const void* encoded, size_t length,
|
|
|
|
const SkIRect* subset = nullptr);
|
|
|
|
static sk_sp<SkImage> DecodeToTexture(GrContext* ctx, const sk_sp<SkData>& data,
|
|
|
|
const SkIRect* subset = nullptr) {
|
|
|
|
return DecodeToTexture(ctx, data->data(), data->size(), subset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-01-18 15:36:32 +00:00
|
|
|
/** Creates a GPU-backed SkImage from compressed data.
|
|
|
|
|
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
|
|
|
|
GrContext::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-01-27 21:11:57 +00:00
|
|
|
static sk_sp<SkImage> MakeFromCompressed(GrContext* context,
|
|
|
|
sk_sp<SkData> data,
|
|
|
|
int width, int height,
|
|
|
|
CompressionType type,
|
2020-01-21 20:25:58 +00:00
|
|
|
GrMipMapped mipMapped = GrMipMapped::kNo,
|
|
|
|
GrProtected isProtected = GrProtected::kNo);
|
2019-01-18 15:36:32 +00:00
|
|
|
|
2020-01-27 21:11:57 +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);
|
|
|
|
|
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. Caller is responsible for
|
|
|
|
managing the lifetime of GPU texture.
|
|
|
|
|
|
|
|
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
|
|
|
|
@param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
2018-04-03 15:49:10 +00:00
|
|
|
@param colorType one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
2018-10-31 14:54:50 +00:00
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
|
|
|
|
kRGB_888x_SkColorType, kBGRA_8888_SkColorType,
|
|
|
|
kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
2018-02-27 15:22:04 +00:00
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
2018-04-03 15:49:10 +00:00
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
2018-02-27 15:22:04 +00:00
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2017-12-18 19:48:15 +00:00
|
|
|
static sk_sp<SkImage> MakeFromTexture(GrContext* context,
|
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
SkColorType colorType,
|
|
|
|
SkAlphaType alphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace,
|
|
|
|
nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param backendTexture texture residing on GPU
|
|
|
|
@param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
2018-04-03 15:49:10 +00:00
|
|
|
@param colorType one of:
|
2018-10-31 14:54:50 +00:00
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType,
|
|
|
|
kRGB_565_SkColorType, kARGB_4444_SkColorType,
|
|
|
|
kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType,
|
|
|
|
kRGB_101010x_SkColorType, kGray_8_SkColorType,
|
|
|
|
kRGBA_F16_SkColorType
|
2018-04-03 15:49:10 +00:00
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
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
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromTexture(GrContext* context,
|
|
|
|
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,
|
|
|
|
TextureReleaseProc textureReleaseProc,
|
|
|
|
ReleaseContext releaseContext);
|
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.
|
|
|
|
|
|
|
|
@param context the GPU context
|
|
|
|
@param backendTexture a texture already allocated by the GPU
|
|
|
|
@param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
|
|
|
@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
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromCompressedTexture(GrContext* context,
|
|
|
|
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
|
|
|
*/
|
2017-11-07 15:37:00 +00:00
|
|
|
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* 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
|
|
|
|
@param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
2018-04-03 15:49:10 +00:00
|
|
|
@param colorType one of:
|
2018-10-31 14:54:50 +00:00
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType,
|
|
|
|
kRGB_565_SkColorType, kARGB_4444_SkColorType,
|
|
|
|
kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType,
|
|
|
|
kRGB_101010x_SkColorType, kGray_8_SkColorType,
|
|
|
|
kRGBA_F16_SkColorType
|
2018-04-03 15:49:10 +00:00
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
2018-02-27 15:22:04 +00:00
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
|
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
GrSurfaceOrigin surfaceOrigin,
|
2017-12-18 19:48:15 +00:00
|
|
|
SkColorType colorType,
|
2017-11-03 12:06:09 +00:00
|
|
|
SkAlphaType alphaType = kPremul_SkAlphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr);
|
2017-04-18 19:52:36 +00:00
|
|
|
|
2018-10-05 14:31:34 +00:00
|
|
|
/** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA
|
|
|
|
image.
|
|
|
|
|
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2018-10-31 14:54:50 +00:00
|
|
|
@param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
|
2018-10-05 14:31:34 +00:00
|
|
|
possibly interleaved, YUVA planes
|
2018-10-31 14:54:50 +00:00
|
|
|
@param yuvaIndices array indicating which texture in yuvaTextures, and channel
|
|
|
|
in that texture, maps to each component of YUVA.
|
2018-10-05 14:31:34 +00:00
|
|
|
@param imageSize size of the resulting image
|
|
|
|
@param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,
|
|
|
|
kTopLeft_GrSurfaceOrigin
|
|
|
|
@param imageColorSpace range of colors of the resulting image; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
|
|
|
const GrBackendTexture yuvaTextures[],
|
|
|
|
const SkYUVAIndex yuvaIndices[4],
|
|
|
|
SkISize imageSize,
|
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
2018-10-30 19:53:36 +00:00
|
|
|
|
2018-10-05 14:31:34 +00:00
|
|
|
/** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA
|
|
|
|
image. 'backendTexture' is used to store the result of the flattening.
|
|
|
|
|
2019-08-19 17:35:48 +00:00
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2019-08-19 17:35:48 +00:00
|
|
|
@param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
|
|
|
|
possibly interleaved, YUVA planes
|
|
|
|
@param yuvaIndices array indicating which texture in yuvaTextures, and channel
|
|
|
|
in that texture, maps to each component of YUVA.
|
|
|
|
@param imageSize size of the resulting image
|
|
|
|
@param imageOrigin origin of the resulting image. One of:
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
kTopLeft_GrSurfaceOrigin
|
|
|
|
@param backendTexture the resource that stores the final pixels
|
|
|
|
@param imageColorSpace range of colors of the resulting image; may be nullptr
|
|
|
|
@param textureReleaseProc function called when backendTexture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
2018-10-05 14:31:34 +00:00
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend(
|
|
|
|
GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
|
|
|
const GrBackendTexture yuvaTextures[],
|
|
|
|
const SkYUVAIndex yuvaIndices[4],
|
|
|
|
SkISize imageSize,
|
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
const GrBackendTexture& backendTexture,
|
2019-08-19 17:35:48 +00:00
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr,
|
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
2018-10-05 14:31:34 +00:00
|
|
|
|
2018-11-20 16:12:37 +00:00
|
|
|
/** Creates an SkImage by storing the specified YUVA planes into an image, to be rendered
|
|
|
|
via multitexturing.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-10-05 14:31:34 +00:00
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2018-11-20 16:12:37 +00:00
|
|
|
@param yuvaTextures array of (up to four) YUVA textures on GPU which contain the,
|
|
|
|
possibly interleaved, YUVA planes
|
|
|
|
@param yuvaIndices array indicating which texture in yuvaTextures, and channel
|
|
|
|
in that texture, maps to each component of YUVA.
|
|
|
|
@param imageSize size of the resulting image
|
|
|
|
@param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,
|
|
|
|
kTopLeft_GrSurfaceOrigin
|
|
|
|
@param imageColorSpace range of colors of the resulting image; may be nullptr
|
2018-10-05 14:31:34 +00:00
|
|
|
@return created SkImage, or nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2018-11-20 16:12:37 +00:00
|
|
|
static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
|
|
|
const GrBackendTexture yuvaTextures[],
|
|
|
|
const SkYUVAIndex yuvaIndices[4],
|
|
|
|
SkISize imageSize,
|
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
|
|
|
|
|
|
|
/** Creates SkImage from pixmap array representing YUVA data.
|
|
|
|
SkImage is uploaded to GPU back-end using context.
|
|
|
|
|
|
|
|
Each GrBackendTexture created from yuvaPixmaps array is uploaded to match SkSurface
|
|
|
|
using SkColorSpace of SkPixmap. SkColorSpace of SkImage is determined by imageColorSpace.
|
|
|
|
|
|
|
|
SkImage is returned referring to GPU back-end if context is not nullptr and
|
|
|
|
format of data is recognized and supported. Otherwise, nullptr is returned.
|
|
|
|
Recognized GPU formats vary by platform and GPU back-end.
|
|
|
|
|
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2018-11-20 16:12:37 +00:00
|
|
|
@param yuvaPixmaps array of (up to four) SkPixmap which contain the,
|
|
|
|
possibly interleaved, YUVA planes
|
|
|
|
@param yuvaIndices array indicating which pixmap in yuvaPixmaps, and channel
|
|
|
|
in that pixmap, maps to each component of YUVA.
|
|
|
|
@param imageSize size of the resulting image
|
|
|
|
@param imageOrigin origin of the resulting image. One of:
|
|
|
|
kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
|
|
|
@param buildMips create internal YUVA textures as mip map if true
|
|
|
|
@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(
|
|
|
|
GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[],
|
|
|
|
const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin,
|
|
|
|
bool buildMips, bool limitToMaxTextureSize = false,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
|
|
|
|
|
|
|
/** To be deprecated.
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
|
2018-03-15 16:16:02 +00:00
|
|
|
const GrBackendTexture yuvTextures[3],
|
2018-10-05 14:31:34 +00:00
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
2015-05-29 18:37:25 +00:00
|
|
|
|
2018-11-20 16:12:37 +00:00
|
|
|
/** To be deprecated.
|
2018-09-18 01:57:11 +00:00
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
|
2019-08-19 17:35:48 +00:00
|
|
|
GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
|
|
|
const GrBackendTexture yuvTextures[3],
|
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
const GrBackendTexture& backendTexture,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
2018-09-18 01:57:11 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Creates SkImage from copy of nv12Textures, an array of textures on GPU.
|
2018-06-14 17:21:08 +00:00
|
|
|
nv12Textures[0] contains pixels for YUV component y plane.
|
|
|
|
nv12Textures[1] contains pixels for YUV component u plane,
|
|
|
|
followed by pixels for YUV component v plane.
|
2018-04-03 15:49:10 +00:00
|
|
|
Returned SkImage has the dimensions nv12Textures[2].
|
|
|
|
yuvColorSpace describes how YUV colors convert to RGB colors.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
2018-10-05 14:31:34 +00:00
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2018-10-05 14:31:34 +00:00
|
|
|
@param nv12Textures array of YUV textures on GPU
|
|
|
|
@param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
|
|
|
@param imageColorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
2018-02-27 15:22:04 +00:00
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
2018-03-15 16:16:02 +00:00
|
|
|
const GrBackendTexture nv12Textures[2],
|
2018-10-05 14:31:34 +00:00
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr);
|
2017-12-13 14:22:45 +00:00
|
|
|
|
2018-09-18 01:57:11 +00:00
|
|
|
/** Creates SkImage from copy of nv12Textures, an array of textures on GPU.
|
2018-09-18 11:31:37 +00:00
|
|
|
nv12Textures[0] contains pixels for YUV component y plane.
|
|
|
|
nv12Textures[1] contains pixels for YUV component u plane,
|
|
|
|
followed by pixels for YUV component v plane.
|
2018-09-18 01:57:11 +00:00
|
|
|
Returned SkImage has the dimensions nv12Textures[2] and stores pixels in backendTexture.
|
|
|
|
yuvColorSpace describes how YUV colors convert to RGB colors.
|
|
|
|
|
2019-08-19 17:35:48 +00:00
|
|
|
@param context GPU context
|
2019-10-30 16:06:51 +00:00
|
|
|
@param yuvColorSpace How the YUV values are converted to RGB
|
2019-08-19 17:35:48 +00:00
|
|
|
@param nv12Textures array of YUV textures on GPU
|
|
|
|
@param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
|
|
|
@param backendTexture the resource that stores the final pixels
|
|
|
|
@param imageColorSpace range of colors; may be nullptr
|
|
|
|
@param textureReleaseProc function called when backendTexture can be released
|
|
|
|
@param releaseContext state passed to textureReleaseProc
|
|
|
|
@return created SkImage, or nullptr
|
2018-09-18 01:57:11 +00:00
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
|
|
|
|
GrContext* context,
|
|
|
|
SkYUVColorSpace yuvColorSpace,
|
|
|
|
const GrBackendTexture nv12Textures[2],
|
2018-10-05 14:31:34 +00:00
|
|
|
GrSurfaceOrigin imageOrigin,
|
|
|
|
const GrBackendTexture& backendTexture,
|
2019-08-19 17:35:48 +00:00
|
|
|
sk_sp<SkColorSpace> imageColorSpace = nullptr,
|
|
|
|
TextureReleaseProc textureReleaseProc = nullptr,
|
|
|
|
ReleaseContext releaseContext = nullptr);
|
2018-09-18 01:57:11 +00:00
|
|
|
|
2017-01-09 17:38:59 +00:00
|
|
|
enum class BitDepth {
|
2018-05-30 13:20:29 +00:00
|
|
|
kU8, //!< uses 8-bit unsigned int per color component
|
|
|
|
kF16, //!< uses 16-bit float per color component
|
2017-01-09 17:38:59 +00:00
|
|
|
};
|
2016-12-16 16:55:18 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** 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
|
2018-05-30 13:20:29 +00:00
|
|
|
@param bitDepth 8-bit integer or 16-bit float: per component
|
2018-02-27 15:22:04 +00:00
|
|
|
@param colorSpace range of colors; may be nullptr
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
|
|
|
|
const SkMatrix* matrix, const SkPaint* paint,
|
|
|
|
BitDepth bitDepth,
|
|
|
|
sk_sp<SkColorSpace> colorSpace);
|
2015-08-13 16:37:45 +00:00
|
|
|
|
2017-06-27 19:37:25 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
|
2018-10-31 14:54:50 +00:00
|
|
|
/** (See Skia bug 7447)
|
2018-02-27 15:22:04 +00:00
|
|
|
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
|
2018-04-03 15:49:10 +00:00
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
2018-02-27 15:22:04 +00:00
|
|
|
@param colorSpace range of colors; may be nullptr
|
2018-09-13 18:20:03 +00:00
|
|
|
@param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
2018-02-27 15:22:04 +00:00
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2018-09-13 18:20:03 +00:00
|
|
|
static sk_sp<SkImage> MakeFromAHardwareBuffer(
|
|
|
|
AHardwareBuffer* hardwareBuffer,
|
|
|
|
SkAlphaType alphaType = kPremul_SkAlphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr,
|
|
|
|
GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
|
2019-03-04 18:08:25 +00:00
|
|
|
|
|
|
|
/** 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 pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer
|
|
|
|
@param hardwareBuffer AHardwareBuffer Android hardware buffer
|
|
|
|
@param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
|
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> MakeFromAHardwareBufferWithData(
|
|
|
|
GrContext* context,
|
|
|
|
const SkPixmap& pixmap,
|
|
|
|
AHardwareBuffer* hardwareBuffer,
|
|
|
|
GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
|
2017-06-02 14:29:21 +00:00
|
|
|
#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
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns SkAlphaType, one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_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
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
|
2019-04-02 21:49:12 +00:00
|
|
|
SkTileMode rules to fill drawn area outside SkImage. localMatrix permits
|
2018-02-27 15:22:04 +00:00
|
|
|
transforming SkImage before SkCanvas matrix is applied.
|
|
|
|
|
2019-04-02 21:49:12 +00:00
|
|
|
@param tmx tiling in the x direction
|
|
|
|
@param tmy tiling in the y direction
|
2018-02-27 15:22:04 +00:00
|
|
|
@param localMatrix SkImage transformation, or nullptr
|
|
|
|
@return SkShader containing SkImage
|
|
|
|
*/
|
2019-04-02 21:49:12 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy,
|
2016-03-09 22:47:34 +00:00
|
|
|
const SkMatrix* localMatrix = nullptr) const;
|
2019-11-14 21:17:50 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix& localMatrix) const {
|
|
|
|
return this->makeShader(tmx, tmy, &localMatrix);
|
|
|
|
}
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
|
|
|
|
SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits
|
|
|
|
transforming SkImage before SkCanvas matrix is applied.
|
|
|
|
|
|
|
|
@param localMatrix SkImage transformation, or nullptr
|
|
|
|
@return SkShader containing SkImage
|
|
|
|
*/
|
2017-04-28 15:12:19 +00:00
|
|
|
sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const {
|
2019-04-02 21:49:12 +00:00
|
|
|
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, localMatrix);
|
2017-04-28 15:12:19 +00:00
|
|
|
}
|
2019-11-14 21:17:50 +00:00
|
|
|
sk_sp<SkShader> makeShader(const SkMatrix& localMatrix) const {
|
|
|
|
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, &localMatrix);
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:02:50 +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;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2015-06-10 15:49:28 +00:00
|
|
|
GrTexture* getTexture() const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true the contents of SkImage was created on or uploaded to GPU memory,
|
|
|
|
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;
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
SkImage backed by GPU texture may become invalid if associated GrContext is
|
|
|
|
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
|
|
|
*/
|
2017-05-08 15:07:42 +00:00
|
|
|
bool isValid(GrContext* context) const;
|
|
|
|
|
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
|
|
|
|
texture-backed (including promise texture images) or if the the GrContext does not
|
|
|
|
have the same context ID as the context backing the image then this is a no-op.
|
|
|
|
|
|
|
|
If the image was not used in any non-culled draws recorded on the passed GrContext then
|
|
|
|
this is a no-op unless the GrFlushInfo contains semaphores, a finish proc, or uses
|
|
|
|
kSyncCpu_GrFlushFlag. Those are respected even when the image has not been used.
|
|
|
|
|
|
|
|
@param context the context on which to flush pending usages of the image.
|
|
|
|
@param info flush options
|
|
|
|
@return one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo
|
|
|
|
*/
|
|
|
|
GrSemaphoresSubmitted flush(GrContext* context, const GrFlushInfo& flushInfo);
|
|
|
|
|
|
|
|
/** Version of flush() that uses a default GrFlushInfo. */
|
|
|
|
void flush(GrContext*);
|
|
|
|
|
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
|
|
|
|
@param origin storage for one of: kTopLeft_GrSurfaceOrigin,
|
|
|
|
kBottomLeft_GrSurfaceOrigin; or nullptr
|
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;
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@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()
|
|
|
|
@param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
|
|
|
|
@return true if pixels are copied to dstPixels
|
|
|
|
*/
|
2014-12-10 17:53:42 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
2017-11-03 12:06:09 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@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()
|
|
|
|
@param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
|
|
|
|
@return true if pixels are copied to dst
|
|
|
|
*/
|
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;
|
2014-12-10 17:53:42 +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.
|
|
|
|
|
|
|
|
Scales the image, with filterQuality, to match dst.width() and dst.height().
|
|
|
|
filterQuality kNone_SkFilterQuality is fastest, typically implemented with
|
|
|
|
nearest neighbor filter. kLow_SkFilterQuality is typically implemented with
|
|
|
|
bilerp filter. kMedium_SkFilterQuality is typically implemented with
|
2018-10-31 14:54:50 +00:00
|
|
|
bilerp filter, and mip-map filter when size is reduced.
|
|
|
|
kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.
|
2018-02-27 15:22:04 +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.
|
|
|
|
|
|
|
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
|
|
|
|
kMedium_SkFilterQuality, kHigh_SkFilterQuality
|
|
|
|
@param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
|
|
|
|
@return true if pixels are scaled to fit dst
|
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
|
|
|
|
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:
|
|
|
|
SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support
|
|
|
|
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
|
|
|
|
must be built with SK_HAS_PNG_LIBRARY to encode SkImage.
|
|
|
|
|
|
|
|
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
|
|
|
|
with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY.
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns subset of SkImage. subset must be fully contained by SkImage dimensions().
|
|
|
|
The implementation may share pixels, or may copy them.
|
|
|
|
|
|
|
|
Returns nullptr if subset is empty, or subset is not contained by bounds, or
|
|
|
|
pixels in SkImage could not be read or copied.
|
|
|
|
|
|
|
|
@param subset bounds of returned SkImage
|
|
|
|
@return partial or full SkImage, 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
|
|
|
*/
|
2016-03-11 12:33:52 +00:00
|
|
|
sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
|
2015-01-23 13:58:07 +00:00
|
|
|
|
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
|
|
|
|
mipMapped setting; if mipMapped equals GrMipMapped::kYes, the backing texture
|
|
|
|
allocates mip map levels. Returns original SkImage if context
|
|
|
|
and dstColorSpace match and mipMapped is compatible with backing GPU texture.
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
Returns nullptr if context is nullptr, or if SkImage was created with another
|
|
|
|
GrContext.
|
|
|
|
|
|
|
|
@param context GPU context
|
|
|
|
@param dstColorSpace range of colors of matching SkSurface on GPU
|
2018-06-14 17:21:08 +00:00
|
|
|
@param mipMapped whether created SkImage texture must allocate mip map levels
|
2018-02-27 15:22:04 +00:00
|
|
|
@return created SkImage, or nullptr
|
|
|
|
*/
|
2019-08-14 17:19:04 +00:00
|
|
|
sk_sp<SkImage> makeTextureImage(GrContext* context, GrMipMapped = GrMipMapped::kNo) const;
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2019-01-10 21:34:22 +00:00
|
|
|
@param context the GrContext 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
|
|
|
|
*/
|
2019-01-10 21:34:22 +00:00
|
|
|
sk_sp<SkImage> makeWithFilter(GrContext* context,
|
|
|
|
const SkImageFilter* filter, const SkIRect& subset,
|
|
|
|
const SkIRect& clipBounds, SkIRect* outSubset,
|
|
|
|
SkIPoint* offset) const;
|
|
|
|
|
|
|
|
/** To be deprecated.
|
|
|
|
*/
|
2016-05-19 21:50:29 +00:00
|
|
|
sk_sp<SkImage> makeWithFilter(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;
|
|
|
|
|
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
|
|
|
*/
|
2017-11-03 12:06:09 +00:00
|
|
|
static bool MakeBackendTextureFromSkImage(GrContext* context,
|
|
|
|
sk_sp<SkImage> image,
|
|
|
|
GrBackendTexture* backendTexture,
|
|
|
|
BackendTextureReleaseProc* backendTextureReleaseProc);
|
2017-10-12 19:44:50 +00:00
|
|
|
|
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.
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
@param target SkColorSpace describing color range of returned SkImage
|
|
|
|
@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
|
|
|
*/
|
2018-07-16 17:06:02 +00:00
|
|
|
sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) 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.
|
|
|
|
|
|
|
|
@param targetColorType SkColorType of returned SkImage
|
|
|
|
@param targetColorSpace SkColorSpace of returned SkImage
|
|
|
|
@return created SkImage in target SkColorType and SkColorSpace
|
|
|
|
*/
|
|
|
|
sk_sp<SkImage> makeColorTypeAndColorSpace(SkColorType targetColorType,
|
|
|
|
sk_sp<SkColorSpace> targetColorSpace) const;
|
|
|
|
|
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);
|
2017-05-26 16:54:32 +00:00
|
|
|
friend class SkImage_Base;
|
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;
|
|
|
|
|
2012-08-28 12:48:35 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2012-07-25 14:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|