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 /* Generated by tools/bookmaker from include/core/SkImage.h and docs/SkImage_Reference.bmh 9 on 2018-09-18 07:26:44. Additional documentation and examples can be found at: 10 https://skia.org/user/api/SkImage_Reference 11 12 You may edit either file directly. Structural changes to public interfaces require 13 editing both files. After editing docs/SkImage_Reference.bmh, run: 14 bookmaker -b docs -i include/core/SkImage.h -p 15 to create an updated version of this file. 16 */ 17 18 #ifndef SkImage_DEFINED 19 #define SkImage_DEFINED 20 21 #include "GrTypes.h" 22 #include "SkFilterQuality.h" 23 #include "SkImageInfo.h" 24 #include "SkImageEncoder.h" 25 #include "SkRefCnt.h" 26 #include "SkScalar.h" 27 #include "SkShader.h" 28 29 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 30 #include <android/hardware_buffer.h> 31 #endif 32 33 class SkData; 34 class SkCanvas; 35 class SkImageFilter; 36 class SkImageGenerator; 37 class SkPaint; 38 class SkPicture; 39 class SkString; 40 class SkSurface; 41 class GrBackendTexture; 42 class GrContext; 43 class GrContextThreadSafeProxy; 44 class GrTexture; 45 46 struct SkYUVAIndex; 47 48 /** \class SkImage 49 SkImage describes a two dimensional array of pixels to draw. The pixels may be 50 decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, 51 or located in GPU memory as a GPU texture. 52 53 SkImage cannot be modified after it is created. SkImage may allocate additional 54 storage as needed; for instance, an encoded SkImage may decode when drawn. 55 56 SkImage width and height are greater than zero. Creating an SkImage with zero width 57 or height returns SkImage equal to nullptr. 58 59 SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, 60 GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported 61 include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details 62 vary with platform. 63 */ 64 class SK_API SkImage : public SkRefCnt { 65 public: 66 67 /** Caller data passed to RasterReleaseProc; may be nullptr. 68 */ 69 typedef void* ReleaseContext; 70 71 /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap 72 pixels may be modified or deleted without affecting SkImage. 73 74 SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: 75 dimensions are greater than zero; 76 each dimension fits in 29 bits; 77 SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; 78 row bytes are large enough to hold one row of pixels; 79 pixel address is not nullptr. 80 81 @param pixmap SkImageInfo, pixel address, and row bytes 82 @return copy of SkPixmap pixels, or nullptr 83 */ 84 static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap); 85 86 /** Creates SkImage from SkImageInfo, sharing pixels. 87 88 SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: 89 dimensions are greater than zero; 90 each dimension fits in 29 bits; 91 SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; 92 rowBytes are large enough to hold one row of pixels; 93 pixels is not nullptr, and contains enough data for SkImage. 94 95 @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace 96 @param pixels address or pixel storage 97 @param rowBytes size of pixel row or larger 98 @return SkImage sharing pixels, or nullptr 99 */ 100 static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels, 101 size_t rowBytes); 102 103 /** Function called when SkImage no longer shares pixels. ReleaseContext is 104 provided by caller when SkImage is created, and may be nullptr. 105 */ 106 typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); 107 108 /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and 109 unchanged until rasterReleaseProc is called. rasterReleaseProc is passed 110 releaseContext when SkImage is deleted or no longer refers to pixmap pixels. 111 112 Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback 113 when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc 114 does not require state. 115 116 SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: 117 dimensions are greater than zero; 118 each dimension fits in 29 bits; 119 SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; 120 row bytes are large enough to hold one row of pixels; 121 pixel address is not nullptr. 122 123 @param pixmap SkImageInfo, pixel address, and row bytes 124 @param rasterReleaseProc function called when pixels can be released; or nullptr 125 @param releaseContext state passed to rasterReleaseProc; or nullptr 126 @return SkImage sharing pixmap 127 */ 128 static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, 129 RasterReleaseProc rasterReleaseProc, 130 ReleaseContext releaseContext); 131 132 /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap 133 is marked immutable, and its pixel memory is shareable, it may be shared 134 instead of copied. 135 136 SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: 137 dimensions are greater than zero; 138 each dimension fits in 29 bits; 139 SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; 140 row bytes are large enough to hold one row of pixels; 141 pixel address is not nullptr. 142 143 @param bitmap SkImageInfo, row bytes, and pixels 144 @return created SkImage, or nullptr 145 */ 146 static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap); 147 148 /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and 149 may not be shared or accessed. 150 151 subset allows selecting a portion of the full image. Pass nullptr to select the entire 152 image; otherwise, subset must be contained by image bounds. 153 154 SkImage is returned if generator data is valid. Valid data parameters vary by type of data 155 and platform. 156 157 imageGenerator may wrap SkPicture data, codec data, or custom data. 158 159 @param imageGenerator stock or custom routines to retrieve SkImage 160 @param subset bounds of returned SkImage; may be nullptr 161 @return created SkImage, or nullptr 162 */ 163 static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator, 164 const SkIRect* subset = nullptr); 165 166 /** Creates SkImage from encoded data. 167 subset allows selecting a portion of the full image. Pass nullptr to select the entire 168 image; otherwise, subset must be contained by image bounds. 169 170 SkImage is returned if format of the encoded data is recognized and supported. 171 Recognized formats vary by platform. 172 173 @param encoded data of SkImage to decode 174 @param subset bounds of returned SkImage; may be nullptr 175 @return created SkImage, or nullptr 176 */ 177 static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr); 178 179 // Experimental 180 enum CompressionType { 181 kETC1_CompressionType, 182 kLast_CompressionType = kETC1_CompressionType, 183 }; 184 185 /** Creates a GPU-backed SkImage from compressed data. 186 187 SkImage is returned if format of the compressed data is supported. 188 Supported formats vary by platform. 189 190 @param context GPU context 191 @param data compressed data to store in SkImage 192 @param width width of full SkImage 193 @param height height of full SkImage 194 @param type type of compression used 195 @return created SkImage, or nullptr 196 */ 197 static sk_sp<SkImage> MakeFromCompressed(GrContext* context, sk_sp<SkData> data, 198 int width, int height, CompressionType type); 199 200 /** User function called when supplied texture may be deleted. 201 */ 202 typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); 203 204 /** Creates SkImage from GPU texture associated with context. Caller is responsible for 205 managing the lifetime of GPU texture. 206 207 SkImage is returned if format of backendTexture is recognized and supported. 208 Recognized formats vary by GPU back-end. 209 210 @param context GPU context 211 @param backendTexture texture residing on GPU 212 @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 213 @param colorType one of: 214 kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, 215 kARGB_4444_SkColorType, kRGBA_8888_SkColorType, 216 kRGB_888x_SkColorType, kBGRA_8888_SkColorType, 217 kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, 218 kGray_8_SkColorType, kRGBA_F16_SkColorType 219 @param alphaType one of: 220 kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, 221 kUnpremul_SkAlphaType 222 @param colorSpace range of colors; may be nullptr 223 @return created SkImage, or nullptr 224 */ MakeFromTexture(GrContext * context,const GrBackendTexture & backendTexture,GrSurfaceOrigin origin,SkColorType colorType,SkAlphaType alphaType,sk_sp<SkColorSpace> colorSpace)225 static sk_sp<SkImage> MakeFromTexture(GrContext* context, 226 const GrBackendTexture& backendTexture, 227 GrSurfaceOrigin origin, 228 SkColorType colorType, 229 SkAlphaType alphaType, 230 sk_sp<SkColorSpace> colorSpace) { 231 return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace, 232 nullptr, nullptr); 233 } 234 235 /** Creates SkImage from GPU texture associated with context. GPU texture must stay 236 valid and unchanged until textureReleaseProc is called. textureReleaseProc is 237 passed releaseContext when SkImage is deleted or no longer refers to texture. 238 239 SkImage is returned if format of backendTexture is recognized and supported. 240 Recognized formats vary by GPU back-end. 241 242 @param context GPU context 243 @param backendTexture texture residing on GPU 244 @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 245 @param colorType one of: 246 kUnknown_SkColorType, kAlpha_8_SkColorType, 247 kRGB_565_SkColorType, kARGB_4444_SkColorType, 248 kRGBA_8888_SkColorType, kRGB_888x_SkColorType, 249 kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, 250 kRGB_101010x_SkColorType, kGray_8_SkColorType, 251 kRGBA_F16_SkColorType 252 @param alphaType one of: 253 kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, 254 kUnpremul_SkAlphaType 255 @param colorSpace range of colors; may be nullptr 256 @param textureReleaseProc function called when texture can be released 257 @param releaseContext state passed to textureReleaseProc 258 @return created SkImage, or nullptr 259 */ 260 static sk_sp<SkImage> MakeFromTexture(GrContext* context, 261 const GrBackendTexture& backendTexture, 262 GrSurfaceOrigin origin, 263 SkColorType colorType, 264 SkAlphaType alphaType, 265 sk_sp<SkColorSpace> colorSpace, 266 TextureReleaseProc textureReleaseProc, 267 ReleaseContext releaseContext); 268 269 /** Creates SkImage from encoded data. SkImage is uploaded to GPU back-end using context. 270 271 Created SkImage is available to other GPU contexts, and is available across thread 272 boundaries. All contexts must be in the same GPU share group, or otherwise 273 share resources. 274 275 When SkImage is no longer referenced, context releases texture memory 276 asynchronously. 277 278 GrBackendTexture decoded from data is uploaded to match SkSurface created with 279 dstColorSpace. SkColorSpace of SkImage is determined by encoded data. 280 281 SkImage is returned if format of data is recognized and supported, and if context 282 supports moving resources. Recognized formats vary by platform and GPU back-end. 283 284 SkImage is returned using MakeFromEncoded() if context is nullptr or does not support 285 moving resources between contexts. 286 287 @param context GPU context 288 @param data SkImage to decode 289 @param buildMips create SkImage as mip map if true 290 @param dstColorSpace range of colors of matching SkSurface on GPU 291 @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary 292 @return created SkImage, or nullptr 293 */ 294 static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, 295 bool buildMips, SkColorSpace* dstColorSpace, 296 bool limitToMaxTextureSize = false); 297 298 /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context. 299 300 Created SkImage is available to other GPU contexts, and is available across thread 301 boundaries. All contexts must be in the same GPU share group, or otherwise 302 share resources. 303 304 When SkImage is no longer referenced, context releases texture memory 305 asynchronously. 306 307 GrBackendTexture created from pixmap is uploaded to match SkSurface created with 308 dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace(). 309 310 SkImage is returned referring to GPU back-end if context is not nullptr, 311 format of data is recognized and supported, and if context supports moving 312 resources between contexts. Otherwise, pixmap pixel data is copied and SkImage 313 as returned in raster format if possible; nullptr may be returned. 314 Recognized GPU formats vary by platform and GPU back-end. 315 316 @param context GPU context 317 @param pixmap SkImageInfo, pixel address, and row bytes 318 @param buildMips create SkImage as mip map if true 319 @param dstColorSpace range of colors of matching SkSurface on GPU 320 @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary 321 @return created SkImage, or nullptr 322 */ 323 static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, 324 bool buildMips, SkColorSpace* dstColorSpace, 325 bool limitToMaxTextureSize = false); 326 327 /** Creates SkImage from backendTexture associated with context. backendTexture and 328 returned SkImage are managed internally, and are released when no longer needed. 329 330 SkImage is returned if format of backendTexture is recognized and supported. 331 Recognized formats vary by GPU back-end. 332 333 @param context GPU context 334 @param backendTexture texture residing on GPU 335 @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 336 @param colorType one of: 337 kUnknown_SkColorType, kAlpha_8_SkColorType, 338 kRGB_565_SkColorType, kARGB_4444_SkColorType, 339 kRGBA_8888_SkColorType, kRGB_888x_SkColorType, 340 kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, 341 kRGB_101010x_SkColorType, kGray_8_SkColorType, 342 kRGBA_F16_SkColorType 343 @param alphaType one of: 344 kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, 345 kUnpremul_SkAlphaType 346 @param colorSpace range of colors; may be nullptr 347 @return created SkImage, or nullptr 348 */ 349 static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, 350 const GrBackendTexture& backendTexture, 351 GrSurfaceOrigin surfaceOrigin, 352 SkColorType colorType, 353 SkAlphaType alphaType = kPremul_SkAlphaType, 354 sk_sp<SkColorSpace> colorSpace = nullptr); 355 356 /** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA 357 image. 358 359 @param context GPU context 360 @param yuvColorSpace How the YUV values are converted to RGB. One of: 361 kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 362 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 363 @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the, 364 possibly interleaved, YUVA planes 365 @param yuvaIndices array indicating which texture in yuvaTextures, and channel 366 in that texture, maps to each component of YUVA. 367 @param imageSize size of the resulting image 368 @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin, 369 kTopLeft_GrSurfaceOrigin 370 @param imageColorSpace range of colors of the resulting image; may be nullptr 371 @return created SkImage, or nullptr 372 */ 373 static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context, 374 SkYUVColorSpace yuvColorSpace, 375 const GrBackendTexture yuvaTextures[], 376 const SkYUVAIndex yuvaIndices[4], 377 SkISize imageSize, 378 GrSurfaceOrigin imageOrigin, 379 sk_sp<SkColorSpace> imageColorSpace = nullptr); 380 381 /** Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA 382 image. 'backendTexture' is used to store the result of the flattening. 383 384 @param context GPU context 385 @param yuvColorSpace How the YUV values are converted to RGB. One of: 386 kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 387 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 388 @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the, 389 possibly interleaved, YUVA planes 390 @param yuvaIndices array indicating which texture in yuvaTextures, and channel 391 in that texture, maps to each component of YUVA. 392 @param imageSize size of the resulting image 393 @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin, 394 kTopLeft_GrSurfaceOrigin 395 @param backendTexture the resource that stores the final pixels 396 @param imageColorSpace range of colors of the resulting image; may be nullptr 397 @return created SkImage, or nullptr 398 */ 399 static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend( 400 GrContext* context, 401 SkYUVColorSpace yuvColorSpace, 402 const GrBackendTexture yuvaTextures[], 403 const SkYUVAIndex yuvaIndices[4], 404 SkISize imageSize, 405 GrSurfaceOrigin imageOrigin, 406 const GrBackendTexture& backendTexture, 407 sk_sp<SkColorSpace> imageColorSpace = nullptr); 408 409 /** Creates an SkImage by storing the specified YUVA planes into an image, to be rendered 410 via multitexturing. 411 412 @param context GPU context 413 @param yuvColorSpace How the YUV values are converted to RGB. One of: 414 kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 415 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 416 @param yuvaTextures array of (up to four) YUVA textures on GPU which contain the, 417 possibly interleaved, YUVA planes 418 @param yuvaIndices array indicating which texture in yuvaTextures, and channel 419 in that texture, maps to each component of YUVA. 420 @param imageSize size of the resulting image 421 @param imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin, 422 kTopLeft_GrSurfaceOrigin 423 @param imageColorSpace range of colors of the resulting image; may be nullptr 424 @return created SkImage, or nullptr 425 */ 426 static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context, 427 SkYUVColorSpace yuvColorSpace, 428 const GrBackendTexture yuvaTextures[], 429 const SkYUVAIndex yuvaIndices[4], 430 SkISize imageSize, 431 GrSurfaceOrigin imageOrigin, 432 sk_sp<SkColorSpace> imageColorSpace = nullptr); 433 434 /** Creates SkImage from pixmap array representing YUVA data. 435 SkImage is uploaded to GPU back-end using context. 436 437 Each GrBackendTexture created from yuvaPixmaps array is uploaded to match SkSurface 438 using SkColorSpace of SkPixmap. SkColorSpace of SkImage is determined by imageColorSpace. 439 440 SkImage is returned referring to GPU back-end if context is not nullptr and 441 format of data is recognized and supported. Otherwise, nullptr is returned. 442 Recognized GPU formats vary by platform and GPU back-end. 443 444 @param context GPU context 445 @param yuvColorSpace How the YUV values are converted to RGB. One of: 446 kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 447 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 448 @param yuvaPixmaps array of (up to four) SkPixmap which contain the, 449 possibly interleaved, YUVA planes 450 @param yuvaIndices array indicating which pixmap in yuvaPixmaps, and channel 451 in that pixmap, maps to each component of YUVA. 452 @param imageSize size of the resulting image 453 @param imageOrigin origin of the resulting image. One of: 454 kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 455 @param buildMips create internal YUVA textures as mip map if true 456 @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary 457 @param imageColorSpace range of colors of the resulting image; may be nullptr 458 @return created SkImage, or nullptr 459 */ 460 static sk_sp<SkImage> MakeFromYUVAPixmaps( 461 GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[], 462 const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin, 463 bool buildMips, bool limitToMaxTextureSize = false, 464 sk_sp<SkColorSpace> imageColorSpace = nullptr); 465 466 /** To be deprecated. 467 */ 468 static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, 469 const GrBackendTexture yuvTextures[3], 470 GrSurfaceOrigin imageOrigin, 471 sk_sp<SkColorSpace> imageColorSpace = nullptr); 472 473 /** To be deprecated. 474 */ 475 static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend( 476 GrContext* context, SkYUVColorSpace yuvColorSpace, 477 const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin, 478 const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr); 479 480 /** Creates SkImage from copy of nv12Textures, an array of textures on GPU. 481 nv12Textures[0] contains pixels for YUV component y plane. 482 nv12Textures[1] contains pixels for YUV component u plane, 483 followed by pixels for YUV component v plane. 484 Returned SkImage has the dimensions nv12Textures[2]. 485 yuvColorSpace describes how YUV colors convert to RGB colors. 486 487 @param context GPU context 488 @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 489 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 490 @param nv12Textures array of YUV textures on GPU 491 @param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 492 @param imageColorSpace range of colors; may be nullptr 493 @return created SkImage, or nullptr 494 */ 495 static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, 496 SkYUVColorSpace yuvColorSpace, 497 const GrBackendTexture nv12Textures[2], 498 GrSurfaceOrigin imageOrigin, 499 sk_sp<SkColorSpace> imageColorSpace = nullptr); 500 501 /** Creates SkImage from copy of nv12Textures, an array of textures on GPU. 502 nv12Textures[0] contains pixels for YUV component y plane. 503 nv12Textures[1] contains pixels for YUV component u plane, 504 followed by pixels for YUV component v plane. 505 Returned SkImage has the dimensions nv12Textures[2] and stores pixels in backendTexture. 506 yuvColorSpace describes how YUV colors convert to RGB colors. 507 508 @param context GPU context 509 @param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, 510 kRec709_SkYUVColorSpace, kIdentity_SkYUVColorSpace 511 @param nv12Textures array of YUV textures on GPU 512 @param imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 513 @param backendTexture the resource that stores the final pixels 514 @param imageColorSpace range of colors; may be nullptr 515 @return created SkImage, or nullptr 516 */ 517 static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend( 518 GrContext* context, 519 SkYUVColorSpace yuvColorSpace, 520 const GrBackendTexture nv12Textures[2], 521 GrSurfaceOrigin imageOrigin, 522 const GrBackendTexture& backendTexture, 523 sk_sp<SkColorSpace> imageColorSpace = nullptr); 524 525 enum class BitDepth { 526 kU8, //!< uses 8-bit unsigned int per color component 527 kF16, //!< uses 16-bit float per color component 528 }; 529 530 /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. 531 SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. 532 533 If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws 534 with default SkPaint. colorSpace may be nullptr. 535 536 @param picture stream of drawing commands 537 @param dimensions width and height 538 @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr 539 @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr 540 @param bitDepth 8-bit integer or 16-bit float: per component 541 @param colorSpace range of colors; may be nullptr 542 @return created SkImage, or nullptr 543 */ 544 static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, 545 const SkMatrix* matrix, const SkPaint* paint, 546 BitDepth bitDepth, 547 sk_sp<SkColorSpace> colorSpace); 548 549 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 550 /** (See Skia bug 7447) 551 Creates SkImage from Android hardware buffer. 552 Returned SkImage takes a reference on the buffer. 553 554 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. 555 556 @param hardwareBuffer AHardwareBuffer Android hardware buffer 557 @param alphaType one of: 558 kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, 559 kUnpremul_SkAlphaType 560 @param colorSpace range of colors; may be nullptr 561 @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 562 @return created SkImage, or nullptr 563 */ 564 static sk_sp<SkImage> MakeFromAHardwareBuffer( 565 AHardwareBuffer* hardwareBuffer, 566 SkAlphaType alphaType = kPremul_SkAlphaType, 567 sk_sp<SkColorSpace> colorSpace = nullptr, 568 GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); 569 570 /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. 571 Returned SkImage takes a reference on the buffer. 572 573 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. 574 575 @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer 576 @param hardwareBuffer AHardwareBuffer Android hardware buffer 577 @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin 578 @return created SkImage, or nullptr 579 */ 580 static sk_sp<SkImage> MakeFromAHardwareBufferWithData( 581 GrContext* context, 582 const SkPixmap& pixmap, 583 AHardwareBuffer* hardwareBuffer, 584 GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); 585 #endif 586 587 /** Returns pixel count in each row. 588 589 @return pixel width in SkImage 590 */ width()591 int width() const { return fWidth; } 592 593 /** Returns pixel row count. 594 595 @return pixel height in SkImage 596 */ height()597 int height() const { return fHeight; } 598 599 /** Returns SkISize { width(), height() }. 600 601 @return integral size of width() and height() 602 */ dimensions()603 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } 604 605 /** Returns SkIRect { 0, 0, width(), height() }. 606 607 @return integral rectangle from origin to width() and height() 608 */ bounds()609 SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } 610 611 /** Returns value unique to image. SkImage contents cannot change after SkImage is 612 created. Any operation to create a new SkImage will receive generate a new 613 unique number. 614 615 @return unique identifier 616 */ uniqueID()617 uint32_t uniqueID() const { return fUniqueID; } 618 619 /** Returns SkAlphaType, one of: 620 kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, 621 kUnpremul_SkAlphaType. 622 623 SkAlphaType returned was a parameter to an SkImage constructor, 624 or was parsed from encoded data. 625 626 @return SkAlphaType in SkImage 627 */ 628 SkAlphaType alphaType() const; 629 630 /** Returns SkColorType if known; otherwise, returns kUnknown_SkColorType. 631 632 @return SkColorType of SkImage 633 */ 634 SkColorType colorType() const; 635 636 /** Returns SkColorSpace, the range of colors, associated with SkImage. The 637 reference count of SkColorSpace is unchanged. The returned SkColorSpace is 638 immutable. 639 640 SkColorSpace returned was passed to an SkImage constructor, 641 or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage 642 is drawn, depending on the capabilities of the SkSurface receiving the drawing. 643 644 @return SkColorSpace in SkImage, or nullptr 645 */ 646 SkColorSpace* colorSpace() const; 647 648 /** Returns a smart pointer to SkColorSpace, the range of colors, associated with 649 SkImage. The smart pointer tracks the number of objects sharing this 650 SkColorSpace reference so the memory is released when the owners destruct. 651 652 The returned SkColorSpace is immutable. 653 654 SkColorSpace returned was passed to an SkImage constructor, 655 or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage 656 is drawn, depending on the capabilities of the SkSurface receiving the drawing. 657 658 @return SkColorSpace in SkImage, or nullptr, wrapped in a smart pointer 659 */ 660 sk_sp<SkColorSpace> refColorSpace() const; 661 662 /** Returns true if SkImage pixels represent transparency only. If true, each pixel 663 is packed in 8 bits as defined by kAlpha_8_SkColorType. 664 665 @return true if pixels represent a transparency mask 666 */ 667 bool isAlphaOnly() const; 668 669 /** Returns true if pixels ignore their alpha value and are treated as fully opaque. 670 671 @return true if SkAlphaType is kOpaque_SkAlphaType 672 */ isOpaque()673 bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); } 674 675 /** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses 676 SkShader::TileMode rules to fill drawn area outside SkImage. localMatrix permits 677 transforming SkImage before SkCanvas matrix is applied. 678 679 @param tileMode1 tiling on x-axis, one of: SkShader::kClamp_TileMode, 680 SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode 681 @param tileMode2 tiling on y-axis, one of: SkShader::kClamp_TileMode, 682 SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode 683 @param localMatrix SkImage transformation, or nullptr 684 @return SkShader containing SkImage 685 */ 686 sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, 687 const SkMatrix* localMatrix = nullptr) const; 688 689 /** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses 690 SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits 691 transforming SkImage before SkCanvas matrix is applied. 692 693 @param localMatrix SkImage transformation, or nullptr 694 @return SkShader containing SkImage 695 */ 696 sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const { 697 return this->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, localMatrix); 698 } 699 700 /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address 701 is available, and returns true. If pixel address is not available, return 702 false and leave pixmap unchanged. 703 704 @param pixmap storage for pixel state if pixels are readable; otherwise, ignored 705 @return true if SkImage has direct access to pixels 706 */ 707 bool peekPixels(SkPixmap* pixmap) const; 708 709 /** Deprecated. 710 */ 711 GrTexture* getTexture() const; 712 713 /** Returns true the contents of SkImage was created on or uploaded to GPU memory, 714 and is available as a GPU texture. 715 716 @return true if SkImage is a GPU texture 717 */ 718 bool isTextureBacked() const; 719 720 /** Returns true if SkImage can be drawn on either raster surface or GPU surface. 721 If context is nullptr, tests if SkImage draws on raster surface; 722 otherwise, tests if SkImage draws on GPU surface associated with context. 723 724 SkImage backed by GPU texture may become invalid if associated GrContext is 725 invalid. lazy image may be invalid and may not draw to raster surface or 726 GPU surface or both. 727 728 @param context GPU context 729 @return true if SkImage can be drawn 730 */ 731 bool isValid(GrContext* context) const; 732 733 /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid 734 object is returned. Call GrBackendTexture::isValid to determine if the result 735 is valid. 736 737 If flushPendingGrContextIO is true, completes deferred I/O operations. 738 739 If origin in not nullptr, copies location of content drawn into SkImage. 740 741 @param flushPendingGrContextIO flag to flush outstanding requests 742 @param origin storage for one of: kTopLeft_GrSurfaceOrigin, 743 kBottomLeft_GrSurfaceOrigin; or nullptr 744 @return back-end API texture handle; invalid on failure 745 */ 746 GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, 747 GrSurfaceOrigin* origin = nullptr) const; 748 749 /** \enum SkImage::CachingHint 750 CachingHint selects whether Skia may internally cache SkBitmap generated by 751 decoding SkImage, or by copying SkImage from GPU to CPU. The default behavior 752 allows caching SkBitmap. 753 754 Choose kDisallow_CachingHint if SkImage pixels are to be used only once, or 755 if SkImage pixels reside in a cache outside of Skia, or to reduce memory pressure. 756 757 Choosing kAllow_CachingHint does not ensure that pixels will be cached. 758 SkImage pixels may not be cached if memory requirements are too large or 759 pixels are not accessible. 760 */ 761 enum CachingHint { 762 kAllow_CachingHint, //!< allows internally caching decoded and copied pixels 763 kDisallow_CachingHint, //!< disallows internally caching decoded and copied pixels 764 }; 765 766 /** Copies SkRect of pixels from SkImage to dstPixels. Copy starts at offset (srcX, srcY), 767 and does not exceed SkImage (width(), height()). 768 769 dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of 770 destination. dstRowBytes specifics the gap from one destination row to the next. 771 Returns true if pixels are copied. Returns false if: 772 - dstInfo.addr() equals nullptr 773 - dstRowBytes is less than dstInfo.minRowBytes() 774 - SkPixelRef is nullptr 775 776 Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is 777 kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. 778 If SkImage SkColorType is kGray_8_SkColorType, dstInfo.colorSpace() must match. 779 If SkImage SkAlphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must 780 match. If SkImage SkColorSpace is nullptr, dstInfo.colorSpace() must match. Returns 781 false if pixel conversion is not possible. 782 783 srcX and srcY may be negative to copy only top or left of source. Returns 784 false if width() or height() is zero or negative. 785 Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height(). 786 787 If cachingHint is kAllow_CachingHint, pixels may be retained locally. 788 If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. 789 790 @param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace 791 @param dstPixels destination pixel storage 792 @param dstRowBytes destination row length 793 @param srcX column index whose absolute value is less than width() 794 @param srcY row index whose absolute value is less than height() 795 @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint 796 @return true if pixels are copied to dstPixels 797 */ 798 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 799 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const; 800 801 /** Copies a SkRect of pixels from SkImage to dst. Copy starts at (srcX, srcY), and 802 does not exceed SkImage (width(), height()). 803 804 dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage, 805 and row bytes of destination. dst.rowBytes() specifics the gap from one destination 806 row to the next. Returns true if pixels are copied. Returns false if: 807 - dst pixel storage equals nullptr 808 - dst.rowBytes is less than SkImageInfo::minRowBytes 809 - SkPixelRef is nullptr 810 811 Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is 812 kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. 813 If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match. 814 If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must 815 match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns 816 false if pixel conversion is not possible. 817 818 srcX and srcY may be negative to copy only top or left of source. Returns 819 false if width() or height() is zero or negative. 820 Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height(). 821 822 If cachingHint is kAllow_CachingHint, pixels may be retained locally. 823 If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. 824 825 @param dst destination SkPixmap: SkImageInfo, pixels, row bytes 826 @param srcX column index whose absolute value is less than width() 827 @param srcY row index whose absolute value is less than height() 828 @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint 829 @return true if pixels are copied to dst 830 */ 831 bool readPixels(const SkPixmap& dst, int srcX, int srcY, 832 CachingHint cachingHint = kAllow_CachingHint) const; 833 834 /** Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and 835 converting pixels to match dst.colorType() and dst.alphaType(). Returns true if 836 pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is 837 less than dst SkImageInfo::minRowBytes. 838 839 Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is 840 kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. 841 If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match. 842 If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must 843 match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns 844 false if pixel conversion is not possible. 845 846 Scales the image, with filterQuality, to match dst.width() and dst.height(). 847 filterQuality kNone_SkFilterQuality is fastest, typically implemented with 848 nearest neighbor filter. kLow_SkFilterQuality is typically implemented with 849 bilerp filter. kMedium_SkFilterQuality is typically implemented with 850 bilerp filter, and mip-map filter when size is reduced. 851 kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter. 852 853 If cachingHint is kAllow_CachingHint, pixels may be retained locally. 854 If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. 855 856 @param dst destination SkPixmap: SkImageInfo, pixels, row bytes 857 @param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, 858 kMedium_SkFilterQuality, kHigh_SkFilterQuality 859 @param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint 860 @return true if pixels are scaled to fit dst 861 */ 862 bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, 863 CachingHint cachingHint = kAllow_CachingHint) const; 864 865 /** Encodes SkImage pixels, returning result as SkData. 866 867 Returns nullptr if encoding fails, or if encodedImageFormat is not supported. 868 869 SkImage encoding in a format requires both building with one or more of: 870 SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support 871 for the encoded format. 872 873 If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can 874 additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, 875 SkEncodedImageFormat::kGIF. 876 877 quality is a platform and format specific metric trading off size and encoding 878 error. When used, quality equaling 100 encodes with the least error. quality may 879 be ignored by the encoder. 880 881 @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, 882 SkEncodedImageFormat::kWEBP 883 @param quality encoder specific metric with 100 equaling best 884 @return encoded SkImage, or nullptr 885 */ 886 sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; 887 888 /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data 889 if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia 890 must be built with SK_HAS_PNG_LIBRARY to encode SkImage. 891 892 Returns nullptr if existing encoded data is missing or invalid, and 893 encoding fails. 894 895 @return encoded SkImage, or nullptr 896 */ 897 sk_sp<SkData> encodeToData() const; 898 899 /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported 900 encoded stream format. Platform support for formats vary and may require building 901 with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY. 902 903 Returns nullptr if SkImage contents are not encoded. 904 905 @return encoded SkImage, or nullptr 906 */ 907 sk_sp<SkData> refEncodedData() const; 908 909 /** Returns subset of SkImage. subset must be fully contained by SkImage dimensions(). 910 The implementation may share pixels, or may copy them. 911 912 Returns nullptr if subset is empty, or subset is not contained by bounds, or 913 pixels in SkImage could not be read or copied. 914 915 @param subset bounds of returned SkImage 916 @return partial or full SkImage, or nullptr 917 */ 918 sk_sp<SkImage> makeSubset(const SkIRect& subset) const; 919 920 /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is 921 compatible with SkSurface created with dstColorSpace. The returned SkImage respects 922 mipMapped setting; if mipMapped equals GrMipMapped::kYes, the backing texture 923 allocates mip map levels. Returns original SkImage if context 924 and dstColorSpace match and mipMapped is compatible with backing GPU texture. 925 926 Returns nullptr if context is nullptr, or if SkImage was created with another 927 GrContext. 928 929 @param context GPU context 930 @param dstColorSpace range of colors of matching SkSurface on GPU 931 @param mipMapped whether created SkImage texture must allocate mip map levels 932 @return created SkImage, or nullptr 933 */ 934 sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace, 935 GrMipMapped mipMapped = GrMipMapped::kNo) const; 936 937 /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into 938 CPU memory if needed. Returns original SkImage if decoded in raster bitmap, 939 or if encoded in a stream. 940 941 Returns nullptr if backed by GPU texture and copy fails. 942 943 @return raster image, lazy image, or nullptr 944 */ 945 sk_sp<SkImage> makeNonTextureImage() const; 946 947 /** Returns raster image. Copies SkImage backed by GPU texture into CPU memory, 948 or decodes SkImage from lazy image. Returns original SkImage if decoded in 949 raster bitmap. 950 951 Returns nullptr if copy, decode, or pixel read fails. 952 953 @return raster image, or nullptr 954 */ 955 sk_sp<SkImage> makeRasterImage() const; 956 957 /** Creates filtered SkImage. filter processes original SkImage, potentially changing 958 color, position, and size. subset is the bounds of original SkImage processed 959 by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset 960 is required storage for the actual bounds of the filtered SkImage. offset is 961 required storage for translation of returned SkImage. 962 963 Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset 964 and offset are undefined. 965 966 Useful for animation of SkImageFilter that varies size from frame to frame. 967 Returned SkImage is created larger than required by filter so that GPU texture 968 can be reused with different sized effects. outSubset describes the valid bounds 969 of GPU texture returned. offset translates the returned SkImage to keep subsequent 970 animation frames aligned with respect to each other. 971 972 @param context the GrContext in play - if it exists 973 @param filter how SkImage is sampled when transformed 974 @param subset bounds of SkImage processed by filter 975 @param clipBounds expected bounds of filtered SkImage 976 @param outSubset storage for returned SkImage bounds 977 @param offset storage for returned SkImage translation 978 @return filtered SkImage, or nullptr 979 */ 980 sk_sp<SkImage> makeWithFilter(GrContext* context, 981 const SkImageFilter* filter, const SkIRect& subset, 982 const SkIRect& clipBounds, SkIRect* outSubset, 983 SkIPoint* offset) const; 984 985 /** To be deprecated. 986 */ 987 sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, 988 const SkIRect& clipBounds, SkIRect* outSubset, 989 SkIPoint* offset) const; 990 991 /** Defines a callback function, taking one parameter of type GrBackendTexture with 992 no return value. Function is called when back-end texture is to be released. 993 */ 994 typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc; 995 996 /** Creates a GrBackendTexture from the provided SkImage. Returns true and 997 stores result in backendTexture and backendTextureReleaseProc if 998 texture is created; otherwise, returns false and leaves 999 backendTexture and backendTextureReleaseProc unmodified. 1000 1001 Call backendTextureReleaseProc after deleting backendTexture. 1002 backendTextureReleaseProc cleans up auxiliary data related to returned 1003 backendTexture. The caller must delete returned backendTexture after use. 1004 1005 If SkImage is both texture backed and singly referenced, image is returned in 1006 backendTexture without conversion or making a copy. SkImage is singly referenced 1007 if its was transferred solely using std::move(). 1008 1009 If SkImage is not texture backed, returns texture with SkImage contents. 1010 1011 @param context GPU context 1012 @param image SkImage used for texture 1013 @param backendTexture storage for back-end texture 1014 @param backendTextureReleaseProc storage for clean up function 1015 @return true if back-end texture was created 1016 */ 1017 static bool MakeBackendTextureFromSkImage(GrContext* context, 1018 sk_sp<SkImage> image, 1019 GrBackendTexture* backendTexture, 1020 BackendTextureReleaseProc* backendTextureReleaseProc); 1021 1022 /** Deprecated. 1023 */ 1024 enum LegacyBitmapMode { 1025 kRO_LegacyBitmapMode, //!< returned bitmap is read-only and immutable 1026 }; 1027 1028 /** Deprecated. 1029 Creates raster SkBitmap with same pixels as SkImage. If legacyBitmapMode is 1030 kRO_LegacyBitmapMode, returned bitmap is read-only and immutable. 1031 Returns true if SkBitmap is stored in bitmap. Returns false and resets bitmap if 1032 SkBitmap write did not succeed. 1033 1034 @param bitmap storage for legacy SkBitmap 1035 @param legacyBitmapMode bitmap is read-only and immutable 1036 @return true if SkBitmap was created 1037 */ 1038 bool asLegacyBitmap(SkBitmap* bitmap, 1039 LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const; 1040 1041 /** Returns true if SkImage is backed by an image-generator or other service that creates 1042 and caches its pixels or texture on-demand. 1043 1044 @return true if SkImage is created as needed 1045 */ 1046 bool isLazyGenerated() const; 1047 1048 /** Creates SkImage in target SkColorSpace. 1049 Returns nullptr if SkImage could not be created. 1050 1051 Returns original SkImage if it is in target SkColorSpace. 1052 Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. 1053 If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB. 1054 1055 @param target SkColorSpace describing color range of returned SkImage 1056 @return created SkImage in target SkColorSpace 1057 */ 1058 sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const; 1059 1060 /** Experimental. 1061 Creates SkImage in target SkColorType and SkColorSpace. 1062 Returns nullptr if SkImage could not be created. 1063 1064 Returns original SkImage if it is in target SkColorType and SkColorSpace. 1065 1066 @param targetColorType SkColorType of returned SkImage 1067 @param targetColorSpace SkColorSpace of returned SkImage 1068 @return created SkImage in target SkColorType and SkColorSpace 1069 */ 1070 sk_sp<SkImage> makeColorTypeAndColorSpace(SkColorType targetColorType, 1071 sk_sp<SkColorSpace> targetColorSpace) const; 1072 1073 private: 1074 SkImage(int width, int height, uint32_t uniqueID); 1075 friend class SkImage_Base; 1076 1077 const int fWidth; 1078 const int fHeight; 1079 const uint32_t fUniqueID; 1080 1081 typedef SkRefCnt INHERITED; 1082 }; 1083 1084 #endif 1085