Skia
2D Graphics Library
SkImage.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkImage_DEFINED
9 #define SkImage_DEFINED
10 
12 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkShader.h"
18 #if SK_SUPPORT_GPU
19 #include "include/gpu/GpuTypes.h"
20 #include "include/gpu/GrTypes.h"
21 #endif
22 #if defined(SK_GRAPHITE_ENABLED)
23 #include "include/gpu/graphite/GraphiteTypes.h"
24 #endif
25 
26 #include <memory>
27 #include <functional>
28 #include <optional>
29 
30 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
31 #include <android/hardware_buffer.h>
32 #endif
33 
34 class GrBackendFormat;
35 class GrBackendTexture;
37 class GrDirectContext;
38 class GrRecordingContext;
41 class SkCanvas;
42 class SkData;
43 class SkImage;
44 class SkImageFilter;
45 class SkImageGenerator;
46 class SkMipmap;
47 class SkPaint;
48 class SkPicture;
49 class SkPixmap;
50 class SkPromiseImageTexture;
51 class SkSurface;
52 class SkYUVAPixmaps;
53 
54 enum class SkEncodedImageFormat;
55 
56 #if defined(SK_GRAPHITE_ENABLED)
57 namespace skgpu::graphite {
58 class BackendTexture;
59 class Recorder;
60 class TextureInfo;
61 enum class Volatile : bool;
62 }
63 #endif
64 
81 class SK_API SkImage : public SkRefCnt {
82 public:
83 
86  typedef void* ReleaseContext;
87 
103  static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap);
104 
120  size_t rowBytes);
121 
125  typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
126 
147  static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
148  RasterReleaseProc rasterReleaseProc,
149  ReleaseContext releaseContext);
150 
167  static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap);
168 
180  static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator);
181 
205  std::optional<SkAlphaType> alphaType = std::nullopt);
206 
207  /*
208  * Experimental:
209  * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK
210  * --------------------------------------------------------------------------------------
211  * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM
212  * | RGB8_ETC2 | |
213  * --------------------------------------------------------------------------------------
214  * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM
215  * --------------------------------------------------------------------------------------
216  * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM
217  */
218  enum class CompressionType {
219  kNone,
220  kETC2_RGB8_UNORM, // the same as ETC1
221 
222  kBC1_RGB8_UNORM,
223  kBC1_RGBA8_UNORM,
224  kLast = kBC1_RGBA8_UNORM,
225  };
226 
227  static constexpr int kCompressionTypeCount = static_cast<int>(CompressionType::kLast) + 1;
228 
229  static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM;
230 
243  int width, int height,
244  CompressionType type);
245 
246  enum class BitDepth {
247  kU8,
248  kF16,
249  };
250 
266  static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
267  const SkMatrix* matrix, const SkPaint* paint,
268  BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace,
269  SkSurfaceProps props = {});
270 
271 #if SK_SUPPORT_GPU
290  static sk_sp<SkImage> MakeTextureFromCompressed(GrDirectContext* direct,
291  sk_sp<SkData> data,
292  int width, int height,
293  CompressionType type,
294  GrMipmapped mipmapped = GrMipmapped::kNo,
295  GrProtected isProtected = GrProtected::kNo);
296 
299  typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
300 
324  static sk_sp<SkImage> MakeFromTexture(GrRecordingContext* context,
325  const GrBackendTexture& backendTexture,
326  GrSurfaceOrigin origin,
327  SkColorType colorType,
328  SkAlphaType alphaType,
329  sk_sp<SkColorSpace> colorSpace,
330  TextureReleaseProc textureReleaseProc = nullptr,
331  ReleaseContext releaseContext = nullptr);
332 
360  static sk_sp<SkImage> MakeFromCompressedTexture(GrRecordingContext* context,
361  const GrBackendTexture& backendTexture,
362  GrSurfaceOrigin origin,
363  SkAlphaType alphaType,
364  sk_sp<SkColorSpace> colorSpace,
365  TextureReleaseProc textureReleaseProc = nullptr,
366  ReleaseContext releaseContext = nullptr);
367 
391  static sk_sp<SkImage> MakeCrossContextFromPixmap(GrDirectContext* context,
392  const SkPixmap& pixmap,
393  bool buildMips,
394  bool limitToMaxTextureSize = false);
395 
410  static sk_sp<SkImage> MakeFromAdoptedTexture(GrRecordingContext* context,
411  const GrBackendTexture& backendTexture,
412  GrSurfaceOrigin textureOrigin,
413  SkColorType colorType);
414  static sk_sp<SkImage> MakeFromAdoptedTexture(GrRecordingContext* context,
415  const GrBackendTexture& backendTexture,
416  GrSurfaceOrigin textureOrigin,
417  SkColorType colorType,
418  SkAlphaType alphaType);
419  static sk_sp<SkImage> MakeFromAdoptedTexture(GrRecordingContext* context,
420  const GrBackendTexture& backendTexture,
421  GrSurfaceOrigin textureOrigin,
422  SkColorType colorType,
423  SkAlphaType alphaType,
424  sk_sp<SkColorSpace> colorSpace);
425 
440  static sk_sp<SkImage> MakeFromYUVATextures(GrRecordingContext* context,
441  const GrYUVABackendTextures& yuvaTextures,
442  sk_sp<SkColorSpace> imageColorSpace = nullptr,
443  TextureReleaseProc textureReleaseProc = nullptr,
444  ReleaseContext releaseContext = nullptr);
445 
469  static sk_sp<SkImage> MakeFromYUVAPixmaps(GrRecordingContext* context,
470  const SkYUVAPixmaps& pixmaps,
471  GrMipmapped buildMips = GrMipmapped::kNo,
472  bool limitToMaxTextureSize = false,
473  sk_sp<SkColorSpace> imageColorSpace = nullptr);
474 
475  using PromiseImageTextureContext = void*;
476  using PromiseImageTextureFulfillProc =
477  sk_sp<SkPromiseImageTexture> (*)(PromiseImageTextureContext);
478  using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext);
479 
511  static sk_sp<SkImage> MakePromiseTexture(sk_sp<GrContextThreadSafeProxy> gpuContextProxy,
512  const GrBackendFormat& backendFormat,
513  SkISize dimensions,
514  GrMipmapped mipmapped,
515  GrSurfaceOrigin origin,
516  SkColorType colorType,
517  SkAlphaType alphaType,
518  sk_sp<SkColorSpace> colorSpace,
519  PromiseImageTextureFulfillProc textureFulfillProc,
520  PromiseImageTextureReleaseProc textureReleaseProc,
521  PromiseImageTextureContext textureContext);
522 
545  static sk_sp<SkImage> MakePromiseYUVATexture(sk_sp<GrContextThreadSafeProxy> gpuContextProxy,
546  const GrYUVABackendTextureInfo& backendTextureInfo,
547  sk_sp<SkColorSpace> imageColorSpace,
548  PromiseImageTextureFulfillProc textureFulfillProc,
549  PromiseImageTextureReleaseProc textureReleaseProc,
550  PromiseImageTextureContext textureContexts[]);
551 
552 #endif // SK_SUPPORT_GPU
553 
554 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
565  static sk_sp<SkImage> MakeFromAHardwareBuffer(
566  AHardwareBuffer* hardwareBuffer,
567  SkAlphaType alphaType = kPremul_SkAlphaType,
568  sk_sp<SkColorSpace> colorSpace = nullptr,
569  GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
570 
582  static sk_sp<SkImage> MakeFromAHardwareBufferWithData(
583  GrDirectContext* context,
584  const SkPixmap& pixmap,
585  AHardwareBuffer* hardwareBuffer,
586  GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
587 #endif
588 
594  const SkImageInfo& imageInfo() const { return fInfo; }
595 
600  int width() const { return fInfo.width(); }
601 
606  int height() const { return fInfo.height(); }
607 
612  SkISize dimensions() const { return SkISize::Make(fInfo.width(), fInfo.height()); }
613 
618  SkIRect bounds() const { return SkIRect::MakeWH(fInfo.width(), fInfo.height()); }
619 
626  uint32_t uniqueID() const { return fUniqueID; }
627 
638 
646 
660 
676 
684  bool isAlphaOnly() const;
685 
690  bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); }
691 
696  const SkMatrix* localMatrix = nullptr) const;
697 
699  const SkMatrix& lm) const {
700  return this->makeShader(tmx, tmy, sampling, &lm);
701  }
702  sk_sp<SkShader> makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const {
703  return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm);
704  }
706  const SkMatrix* lm = nullptr) const {
707  return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm);
708  }
709 
724  const SkMatrix* localMatrix = nullptr) const;
725 
727  const SkMatrix& lm) const {
728  return this->makeRawShader(tmx, tmy, sampling, &lm);
729  }
730  sk_sp<SkShader> makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const {
731  return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm);
732  }
734  const SkMatrix* lm = nullptr) const {
735  return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm);
736  }
737 
739 
749  bool peekPixels(SkPixmap* pixmap) const;
750 
758  bool isTextureBacked() const;
759 
763  size_t textureSize() const;
764 
778  bool isValid(GrRecordingContext* context) const;
779 
780 #if SK_SUPPORT_GPU
792  GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const;
793 
794  void flush(GrDirectContext* context) const { this->flush(context, {}); }
795 
799  void flushAndSubmit(GrDirectContext*) const;
800 
812  GrBackendTexture getBackendTexture(bool flushPendingGrContextIO,
813  GrSurfaceOrigin* origin = nullptr) const;
814 #endif // SK_SUPPORT_GPU
815 
828  enum CachingHint {
831  };
832 
867  const SkImageInfo& dstInfo,
868  void* dstPixels,
869  size_t dstRowBytes,
870  int srcX, int srcY,
871  CachingHint cachingHint = kAllow_CachingHint) const;
872 
905  const SkPixmap& dst,
906  int srcX,
907  int srcY,
908  CachingHint cachingHint = kAllow_CachingHint) const;
909 
910 #ifndef SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API
912  bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
913  int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const;
914  bool readPixels(const SkPixmap& dst, int srcX, int srcY,
915  CachingHint cachingHint = kAllow_CachingHint) const;
916 #endif
917 
920  public:
925 
926  virtual ~AsyncReadResult() = default;
927  virtual int count() const = 0;
928  virtual const void* data(int i) const = 0;
929  virtual size_t rowBytes(int i) const = 0;
930 
931  protected:
932  AsyncReadResult() = default;
933  };
934 
936  using ReadPixelsContext = void*;
937 
941  using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>);
942 
943  enum class RescaleGamma : bool { kSrc, kLinear };
944 
945  enum class RescaleMode {
946  kNearest,
947  kLinear,
948  kRepeatedLinear,
949  kRepeatedCubic,
950  };
951 
983  const SkIRect& srcRect,
984  RescaleGamma rescaleGamma,
985  RescaleMode rescaleMode,
986  ReadPixelsCallback callback,
987  ReadPixelsContext context) const;
988 
1019  sk_sp<SkColorSpace> dstColorSpace,
1020  const SkIRect& srcRect,
1021  const SkISize& dstSize,
1022  RescaleGamma rescaleGamma,
1023  RescaleMode rescaleMode,
1024  ReadPixelsCallback callback,
1025  ReadPixelsContext context) const;
1026 
1045  bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&,
1046  CachingHint cachingHint = kAllow_CachingHint) const;
1047 
1071  sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const;
1072 
1085 
1097 
1115  sk_sp<SkImage> makeSubset(const SkIRect& subset, GrDirectContext* direct = nullptr) const;
1116 
1120  bool hasMipmaps() const;
1121 
1127 
1128 #if SK_SUPPORT_GPU
1150  sk_sp<SkImage> makeTextureImage(GrDirectContext*,
1153 #endif // SK_SUPPORT_GPU
1154 
1155 #ifdef SK_GRAPHITE_ENABLED
1156 
1157  // Passed to both fulfill and imageRelease
1158  using GraphitePromiseImageContext = void*;
1159  // Returned from fulfill and passed into textureRelease
1160  using GraphitePromiseTextureReleaseContext = void*;
1161 
1162  using GraphitePromiseImageFulfillProc =
1163  std::tuple<skgpu::graphite::BackendTexture, GraphitePromiseTextureReleaseContext>
1164  (*)(GraphitePromiseImageContext);
1165  using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext);
1166  using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext);
1167 
1214  static sk_sp<SkImage> MakeGraphitePromiseTexture(skgpu::graphite::Recorder*,
1215  SkISize dimensions,
1216  const skgpu::graphite::TextureInfo&,
1217  const SkColorInfo&,
1218  skgpu::graphite::Volatile,
1219  GraphitePromiseImageFulfillProc,
1220  GraphitePromiseImageReleaseProc,
1221  GraphitePromiseTextureReleaseProc,
1222  GraphitePromiseImageContext);
1223 
1240  static sk_sp<SkImage> MakeGraphiteFromBackendTexture(skgpu::graphite::Recorder*,
1241  const skgpu::graphite::BackendTexture&,
1242  SkColorType colorType,
1243  SkAlphaType alphaType,
1244  sk_sp<SkColorSpace> colorSpace);
1245 
1246  struct RequiredImageProperties {
1247  skgpu::graphite::Mipmapped fMipmapped;
1248  };
1249 
1271  sk_sp<SkImage> makeTextureImage(skgpu::graphite::Recorder*,
1272  RequiredImageProperties = {}) const;
1273 
1291  sk_sp<SkImage> makeSubset(const SkIRect& subset,
1292  skgpu::graphite::Recorder*,
1293  RequiredImageProperties = {}) const;
1294 
1310  sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> targetColorSpace,
1311  skgpu::graphite::Recorder*,
1312  RequiredImageProperties = {}) const;
1313 
1329  sk_sp<SkImage> makeColorTypeAndColorSpace(SkColorType targetColorType,
1330  sk_sp<SkColorSpace> targetColorSpace,
1331  skgpu::graphite::Recorder*,
1332  RequiredImageProperties = {}) const;
1333 
1334 #endif // SK_GRAPHITE_ENABLED
1335 
1347 
1361  sk_sp<SkImage> makeRasterImage(CachingHint cachingHint = kDisallow_CachingHint) const;
1362 
1388  const SkImageFilter* filter, const SkIRect& subset,
1389  const SkIRect& clipBounds, SkIRect* outSubset,
1390  SkIPoint* offset) const;
1391 
1395  typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc;
1396 
1397 #if SK_SUPPORT_GPU
1419  static bool MakeBackendTextureFromSkImage(GrDirectContext* context,
1420  sk_sp<SkImage> image,
1421  GrBackendTexture* backendTexture,
1422  BackendTextureReleaseProc* backendTextureReleaseProc);
1423 #endif
1428  };
1429 
1440  bool asLegacyBitmap(SkBitmap* bitmap,
1441  LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const;
1442 
1451  bool isLazyGenerated() const;
1452 
1470  GrDirectContext* direct = nullptr) const;
1471 
1487  sk_sp<SkColorSpace> targetColorSpace,
1488  GrDirectContext* direct = nullptr) const;
1489 
1495 
1496 private:
1497  SkImage(const SkImageInfo& info, uint32_t uniqueID);
1498 
1499  friend class SkBitmap;
1500  friend class SkImage_Base; // for private ctor
1501  friend class SkImage_Raster; // for withMipmaps
1502  friend class SkMipmapBuilder;
1503 
1504  SkImageInfo fInfo;
1505  const uint32_t fUniqueID;
1506 
1507  sk_sp<SkImage> withMipmaps(sk_sp<SkMipmap>) const;
1508 
1509  using INHERITED = SkRefCnt;
1510 };
1511 
1512 #endif
GrProtected
Definition: GrTypes.h:142
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:153
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:154
GrSemaphoresSubmitted
Enum used as return value when flush with semaphores so the client knows whether the valid semaphores...
Definition: GrTypes.h:238
GrMipmapped
Used to say whether a texture has mip levels allocated or not.
Definition: GrTypes.h:124
static bool SkAlphaTypeIsOpaque(SkAlphaType at)
Returns true if SkAlphaType equals kOpaque_SkAlphaType.
Definition: SkAlphaType.h:41
SkAlphaType
Describes how to interpret the alpha component of a pixel.
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Describes how pixel bits encode color.
Definition: SkColorType.h:19
SkEncodedImageFormat
Enum describing format of encoded data.
Definition: SkEncodedImageFormat.h:16
@ kNone
glyph outlines unchanged
SkYUVColorSpace
Definition: SkImageInfo.h:66
SkTileMode
Definition: SkTileMode.h:13
@ kClamp
Replicate the edge color if the shader draws outside of its original bounds.
Definition: GrBackendSurface.h:63
Definition: GrBackendSurface.h:69
Definition: GrContextThreadSafeProxy.h:164
Definition: GrDirectContext.h:54
Definition: GrRecordingContext.h:45
A description of a set GrBackendTextures that hold the planar data described by a SkYUVAInfo.
Definition: GrYUVABackendTextures.h:19
A set of GrBackendTextures that hold the planar data for an image described a SkYUVAInfo.
Definition: GrYUVABackendTextures.h:82
SkBitmap describes a two-dimensional raster pixel array.
Definition: SkBitmap.h:51
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:102
Describes pixel and encoding.
Definition: SkImageInfo.h:95
Definition: SkColorSpace.h:107
SkData holds an immutable data buffer.
Definition: SkData.h:22
Base class for image filters.
Definition: SkImageFilter.h:30
Definition: SkImageGenerator.h:39
The result from asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420().
Definition: SkImage.h:919
AsyncReadResult(const AsyncReadResult &)=delete
AsyncReadResult & operator=(const AsyncReadResult &)=delete
virtual ~AsyncReadResult()=default
virtual size_t rowBytes(int i) const =0
virtual int count() const =0
AsyncReadResult(AsyncReadResult &&)=delete
virtual const void * data(int i) const =0
AsyncReadResult & operator=(AsyncReadResult &&)=delete
SkImage describes a two dimensional array of pixels to draw.
Definition: SkImage.h:81
sk_sp< SkImage > makeSubset(const SkIRect &subset, GrDirectContext *direct=nullptr) const
Returns subset of this image.
bool readPixels(GrDirectContext *context, const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Copies a SkRect of pixels from SkImage to dst.
bool isAlphaOnly() const
Returns true if SkImage pixels represent transparency only.
sk_sp< SkImage > makeColorSpace(sk_sp< SkColorSpace > target, GrDirectContext *direct=nullptr) const
Creates SkImage in target SkColorSpace.
void * ReleaseContext
Caller data passed to RasterReleaseProc; may be nullptr.
Definition: SkImage.h:86
const SkImageInfo & imageInfo() const
Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the Sk...
Definition: SkImage.h:594
sk_sp< SkImage > makeNonTextureImage() const
Returns raster image or lazy image.
sk_sp< SkColorSpace > refColorSpace() const
Returns a smart pointer to SkColorSpace, the range of colors, associated with SkImage.
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV.
BitDepth
Definition: SkImage.h:246
sk_sp< SkImage > reinterpretColorSpace(sk_sp< SkColorSpace > newColorSpace) const
Creates a new SkImage identical to this one, but with a different SkColorSpace.
SkISize dimensions() const
Returns SkISize { width(), height() }.
Definition: SkImage.h:612
static sk_sp< SkImage > MakeFromEncoded(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
Return an image backed by the encoded data, but attempt to defer decoding until the image is actually...
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
Definition: SkImage.h:705
static sk_sp< SkImage > MakeFromBitmap(const SkBitmap &bitmap)
Creates SkImage from bitmap, sharing or copying bitmap pixels.
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Copies SkRect of pixels from SkImage to dstPixels.
uint32_t uniqueID() const
Returns value unique to image.
Definition: SkImage.h:626
void * ReadPixelsContext
Client-provided context that is passed to client-provided ReadPixelsContext.
Definition: SkImage.h:936
static sk_sp< SkImage > MakeFromRaster(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
Creates SkImage from pixmap, sharing SkPixmap pixels.
SkAlphaType alphaType() const
Returns SkAlphaType.
bool isLazyGenerated() const
Returns true if SkImage is backed by an image-generator or other service that creates and caches its ...
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Defines a callback function, taking one parameter of type GrBackendTexture with no return value.
Definition: SkImage.h:1395
bool readPixels(const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
RescaleMode
Definition: SkImage.h:945
sk_sp< SkData > encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
Encodes SkImage pixels, returning result as SkData.
bool isTextureBacked() const
Returns true if the contents of SkImage was created on or uploaded to GPU memory, and is available as...
sk_sp< SkShader > makeRawShader(const SkSamplingOptions &sampling, const SkMatrix &lm) const
Definition: SkImage.h:730
bool peekPixels(SkPixmap *pixmap) const
Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available,...
int width() const
Returns pixel count in each row.
Definition: SkImage.h:600
RescaleGamma
Definition: SkImage.h:943
sk_sp< SkImage > withDefaultMipmaps() const
Returns an image with the same "base" pixels as the this image, but with mipmap levels automatically ...
sk_sp< SkShader > makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
Definition: SkImage.h:726
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Make a shader with the specified tiling and mipmap sampling.
sk_sp< SkImage > makeColorTypeAndColorSpace(SkColorType targetColorType, sk_sp< SkColorSpace > targetColorSpace, GrDirectContext *direct=nullptr) const
Experimental.
sk_sp< SkShader > makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
makeRawShader functions like makeShader, but for images that contain non-color data.
sk_sp< SkImage > makeRasterImage(CachingHint cachingHint=kDisallow_CachingHint) const
Returns raster image.
static sk_sp< SkImage > MakeRasterData(const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
Creates SkImage from SkImageInfo, sharing pixels.
size_t textureSize() const
Returns an approximation of the amount of texture memory used by the image.
CompressionType
Definition: SkImage.h:218
SkColorType colorType() const
Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
bool isValid(GrRecordingContext *context) const
Returns true if SkImage can be drawn on either raster surface or GPU surface.
void asyncRescaleAndReadPixels(const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
Makes image pixel data available to caller, possibly asynchronously.
static sk_sp< SkImage > MakeFromPicture(sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props={})
Creates SkImage from picture.
sk_sp< SkImage > makeWithFilter(GrRecordingContext *context, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset) const
Creates filtered SkImage.
SkColorSpace * colorSpace() const
Returns SkColorSpace, the range of colors, associated with SkImage.
bool isOpaque() const
Returns true if pixels ignore their alpha value and are treated as fully opaque.
Definition: SkImage.h:690
static sk_sp< SkImage > MakeFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
Creates SkImage from data returned by imageGenerator.
int height() const
Returns pixel row count.
Definition: SkImage.h:606
SkIRect bounds() const
Returns SkIRect { 0, 0, width(), height() }.
Definition: SkImage.h:618
sk_sp< SkData > refEncodedData() const
Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format...
static sk_sp< SkImage > MakeRasterCopy(const SkPixmap &pixmap)
Creates SkImage from SkPixmap and copy of pixels.
CachingHint
Definition: SkImage.h:828
@ kDisallow_CachingHint
disallows internally caching decoded and copied pixels
Definition: SkImage.h:830
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition: SkImage.h:829
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
Definition: SkImage.h:698
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Deprecated.
bool hasMipmaps() const
Returns true if the image has mipmap levels.
sk_sp< SkShader > makeRawShader(const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
Definition: SkImage.h:733
static sk_sp< SkImage > MakeRasterFromCompressed(sk_sp< SkData > data, int width, int height, CompressionType type)
Creates a CPU-backed SkImage from compressed data.
void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >) ReadPixelsCallback
Client-provided callback to asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420() that is ...
Definition: SkImage.h:941
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &, CachingHint cachingHint=kAllow_CachingHint) const
Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to m...
sk_sp< SkData > encodeToData() const
Encodes SkImage pixels, returning result as SkData.
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Deprecated.
sk_sp< SkShader > makeShader(const SkSamplingOptions &sampling, const SkMatrix &lm) const
Definition: SkImage.h:702
LegacyBitmapMode
Deprecated.
Definition: SkImage.h:1426
@ kRO_LegacyBitmapMode
returned bitmap is read-only and immutable
Definition: SkImage.h:1427
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
SkPicture records drawing commands made to SkCanvas.
Definition: SkPicture.h:39
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Definition: SkPixmap.h:31
Definition: SkRefCnt.h:118
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:52
SkSurface is responsible for managing the pixels that a canvas draws into.
Definition: SkSurface.h:60
Helper to store SkPixmap planes as described by a SkYUVAPixmapInfo.
Definition: SkYUVAPixmaps.h:171
Definition: SkCanvas.h:71
Budgeted
Indicates whether an allocation should count against a cache budget.
Definition: GpuTypes.h:30
Struct to supply options to flush calls.
Definition: GrTypes.h:225
Definition: SkSamplingOptions.h:50
SkIPoint holds two 32-bit integer coordinates.
Definition: SkPoint.h:27
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:31
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h)
Returns constructed SkIRect set to (0, 0, w, h).
Definition: SkRect.h:55
Definition: SkSize.h:15
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:19
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:192
Definition: SkSamplingOptions.h:58