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