blob: 1f61db2917e823f78a02bda126b3cf03474d44ac [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic Image
2#Alias Image_Reference
3
4#Class SkImage
5
Cary Clark61ca7c52018-01-02 11:34:14 -05006Image describes a two dimensional array of pixels to draw. The pixels may be
7unencoded in a Raster_Bitmap, encoded in a Picture or compressed data stream,
8or located in GPU memory as a GPU_Texture.
9
10Image cannot be modified after it is created. Image may allocate additional
11storage as needed; for instance, an encoded Image may decode when drawn.
12
13Image width and height are greater than zero. Creating an Image with zero width
14or height returns Image equal to nullptr.
15
16Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams,
17GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported
18include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encodings details
19vary with platform.
20
21#Topic Raster_Image
22#Alias Raster_Image
23Raster_Image pixels are unencoded in a Raster_Bitmap. These pixels may be read
24directly and in most cases written to, although edited pixels may not be drawn
25if Image has been copied internally.
26##
27
28#Topic Texture_Image
29Texture_Image are located on GPU and pixels are not accessible. Texture_Image
30are allocated optimally for best performance. Raster_Image may
31be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading
32performance.
33##
34
35#Topic Lazy_Image
36Lazy_Image defer allocating buffer for Image pixels and decoding stream until
37Image is drawn. Lazy_Image caches result if possible to speed up repeated
38drawing.
39##
Cary Clarka560c472017-11-27 10:44:06 -050040
41#Topic Overview
42
43#Subtopic Subtopics
44#ToDo manually add subtopics ##
45#Table
46#Legend
47# topics # description ##
48#Legend ##
49#Table ##
50##
51
Cary Clarka560c472017-11-27 10:44:06 -050052#Subtopic Member_Functions
53#Table
54#Legend
55# description # function ##
56#Legend ##
Cary Clark61ca7c52018-01-02 11:34:14 -050057# MakeBackendTextureFromSkImage # Creates GPU_Texture from Image. ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050058# MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ##
59# MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050060# MakeFromAdoptedTexture # Creates Image from GPU_Texture, managed internally. ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050061# MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050062# MakeFromDeferredTextureImageData # ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050063# MakeFromEncoded # Creates Image from encoded data. ##
64# MakeFromGenerator # Creates Image from a stream of data. ##
65# MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ##
66# MakeFromPicture # Creates Image from Picture. ##
67# MakeFromRaster # Creates Image from Pixmap, with release. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050068# MakeFromTexture # Creates Image from GPU_Texture, managed externally. ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050069# MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ##
70# MakeRasterCopy # Creates Image from Pixmap and copied pixels. ##
71# MakeRasterData # Creates Image from Image_Info and shared pixels. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050072# alphaType # Returns Alpha_Type. ##
73# asLegacyBitmap # Returns as Raster_Bitmap. ##
Cary Clark2f466242017-12-11 16:03:17 -050074# bounds() # Returns width() and height() as Rectangle. ##
75# colorSpace # Returns Color_Space. ##
76# dimensions() # Returns width() and height(). ##
77# encodeToData # Returns encoded Image as SkData. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050078# getDeferredTextureImageData # ##
Cary Clark2f466242017-12-11 16:03:17 -050079# getTexture # Deprecated. ##
80# getTextureHandle # Returns GPU reference to Image as texture. ##
81# height() # Returns pixel row count. ##
82# isAlphaOnly # Returns if pixels represent a transparency mask. ##
83# isLazyGenerated # Returns if Image is created as needed. ##
84# isOpaque # Returns if Alpha_Type is kOpaque_SkAlphaType. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050085# isTextureBacked # Returns if Image was created from GPU_Texture. ##
Cary Clark2f466242017-12-11 16:03:17 -050086# isValid # Returns if Image can draw to Raster_Surface or GPU_Context. ##
87# makeColorSpace # Creates Image matching Color_Space if possible. ##
Cary Clark61ca7c52018-01-02 11:34:14 -050088# makeNonTextureImage # Creates Image without dependency on GPU_Texture. ##
89# makeRasterImage # Creates Image compatible with Raster_Surface if possible. ##
Cary Clark2f466242017-12-11 16:03:17 -050090# makeShader # Creates Shader, Paint element that can tile Image. ##
91# makeSubset # Creates Image containing part of original. ##
92# makeTextureImage # Creates Image matching Color_Space if possible. ##
93# makeWithFilter # Creates filtered, clipped Image. ##
94# peekPixels # Returns Pixmap if possible. ##
95# readPixels # Copies and converts pixels. ##
96# refColorSpace # Returns Image_Info Color_Space. ##
97# refEncodedData # Returns Image encoded in SkData if present. ##
98# scalePixels # Scales and converts one Image to another. ##
99# toString # Converts Image to machine readable form. ##
100# uniqueID # Identifier for Image. ##
101# width() # Returns pixel column count. ##
Cary Clarka560c472017-11-27 10:44:06 -0500102#Table ##
103#Subtopic ##
104
105#Topic ##
106
Cary Clarka560c472017-11-27 10:44:06 -0500107#Typedef SkImageInfo Info
108
109##
110
Cary Clarka560c472017-11-27 10:44:06 -0500111# ------------------------------------------------------------------------------
112
113#Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)
114
Cary Clark2f466242017-12-11 16:03:17 -0500115Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap
116pixels may be modified or deleted without affecting Image.
Cary Clarka560c472017-11-27 10:44:06 -0500117
Cary Clark3cd22cc2017-12-01 11:49:58 -0500118Image is returned if Pixmap is valid. Valid Pixmap parameters include:
119dimensions are greater than zero;
120each dimension fits in 29 bits;
121Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
122row bytes are large enough to hold one row of pixels;
123pixel address is not nullptr.
124
125#Param pixmap Image_Info, pixel address, and row bytes ##
126
127#Return copy of Pixmap pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500128
129#Example
Cary Clark2f466242017-12-11 16:03:17 -0500130#Height 50
131#Description
132Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap
133alters the bitmap draw, but does not alter the Image draw since the Image
134contains a copy of the pixels.
135##
136 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
137 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
138 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
139 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
140 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
141 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
142 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
143 SkBitmap bitmap;
144 bitmap.installPixels(pixmap);
145 sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap);
146 *pixmap.writable_addr8(2, 2) = 0x00;
147 canvas->scale(10, 10);
148 canvas->drawBitmap(bitmap, 0, 0);
149 canvas->drawImage(image, 10, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500150##
151
Cary Clark3cd22cc2017-12-01 11:49:58 -0500152#SeeAlso MakeRasterData MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500153
154#Method ##
155
156# ------------------------------------------------------------------------------
157
158#Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes)
159
Cary Clark3cd22cc2017-12-01 11:49:58 -0500160Creates Image from Image_Info, sharing pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500161
Cary Clark3cd22cc2017-12-01 11:49:58 -0500162Image is returned if Image_Info is valid. Valid Image_Info parameters include:
163dimensions are greater than zero;
164each dimension fits in 29 bits;
165Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
166rowBytes are large enough to hold one row of pixels;
167pixels is not nullptr, and contains enough data for Image.
168
169#Param info contains width, height, Alpha_Type, Color_Type, Color_Space ##
170#Param pixels address or pixel storage ##
171#Param rowBytes size of pixel row or larger ##
172
173#Return Image sharing pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500174
175#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500176#Image 3
177 size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType);
178 sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height());
179 SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(),
180 kPremul_SkAlphaType);
181 image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint);
182 sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType),
183 data, rowBytes);
184 canvas->drawImage(image, 0, 0);
185 canvas->drawImage(raw.get(), 128, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500186##
187
Cary Clark3cd22cc2017-12-01 11:49:58 -0500188#SeeAlso MakeRasterCopy MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500189
190#Method ##
191
192# ------------------------------------------------------------------------------
193
Cary Clark3cd22cc2017-12-01 11:49:58 -0500194#Typedef void* ReleaseContext
195
196Caller data passed to RasterReleaseProc; may be nullptr.
197
198#SeeAlso MakeFromRaster RasterReleaseProc
199
200##
201
Cary Clarka560c472017-11-27 10:44:06 -0500202#Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext)
203
Cary Clark3cd22cc2017-12-01 11:49:58 -0500204Function called when Image no longer shares pixels. ReleaseContext is
205provided by caller when Image is created, and may be nullptr.
206
207#SeeAlso ReleaseContext MakeFromRaster
208
Cary Clarka560c472017-11-27 10:44:06 -0500209##
210
211#Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
212 RasterReleaseProc rasterReleaseProc,
213 ReleaseContext releaseContext)
214
Cary Clark0c5f5462017-12-15 11:21:51 -0500215Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and
Cary Clark3cd22cc2017-12-01 11:49:58 -0500216unchanged until rasterReleaseProc is called. rasterReleaseProc is passed
217releaseContext when Image is deleted or no longer refers to pixmap pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500218
Cary Clark0c5f5462017-12-15 11:21:51 -0500219Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback
220when Image is released. Pass nullptr for releaseContext if rasterReleaseProc
221does not require state.
222
Cary Clark3cd22cc2017-12-01 11:49:58 -0500223Image is returned if pixmap is valid. Valid Pixmap parameters include:
224dimensions are greater than zero;
225each dimension fits in 29 bits;
226Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
227row bytes are large enough to hold one row of pixels;
228pixel address is not nullptr.
229
230#Param pixmap Image_Info, pixel address, and row bytes ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500231#Param rasterReleaseProc function called when pixels can be released; or nullptr ##
232#Param releaseContext state passed to rasterReleaseProc; or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500233
Cary Clark0c5f5462017-12-15 11:21:51 -0500234#Return Image sharing pixmap ##
Cary Clarka560c472017-11-27 10:44:06 -0500235
236#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500237#Function
238static void releaseProc(const void* pixels, SkImage::ReleaseContext context) {
239 int* countPtr = static_cast<int*>(context);
240 *countPtr += 1;
241}
242##
243
244void draw(SkCanvas* canvas) {
245 SkColor color = 0;
246 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4);
247 int releaseCount = 0;
248 sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount));
249 SkDebugf("before reset: %d\n", releaseCount);
250 image.reset();
251 SkDebugf("after reset: %d\n", releaseCount);
252}
253#StdOut
254before reset: 0
255after reset: 1
256##
Cary Clarka560c472017-11-27 10:44:06 -0500257##
258
Cary Clark3cd22cc2017-12-01 11:49:58 -0500259#SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
Cary Clarka560c472017-11-27 10:44:06 -0500260
261#Method ##
262
263# ------------------------------------------------------------------------------
264
265#Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)
266
Cary Clark3cd22cc2017-12-01 11:49:58 -0500267Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap
268is marked immutable, and its pixel memory is shareable, it may be shared
269instead of copied.
Cary Clarka560c472017-11-27 10:44:06 -0500270
Cary Clark3cd22cc2017-12-01 11:49:58 -0500271Image is returned if bitmap is valid. Valid Bitmap parameters include:
272dimensions are greater than zero;
273each dimension fits in 29 bits;
274Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
275row bytes are large enough to hold one row of pixels;
276pixel address is not nullptr.
Cary Clarka560c472017-11-27 10:44:06 -0500277
Cary Clark3cd22cc2017-12-01 11:49:58 -0500278#Param bitmap Image_Info, row bytes, and pixels ##
279
280#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500281
282#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500283#Description
284The first Bitmap is shared; writing to the pixel memory changes the first
285Image.
286The second Bitmap is marked immutable, and is copied; writing to the pixel
287memory does not alter the second Image.
288##
289#Height 50
290 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
291 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
292 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
293 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
294 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
295 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
296 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
297 SkBitmap bitmap;
298 bitmap.installPixels(pixmap);
299 sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap);
300 bitmap.setImmutable();
301 sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap);
302 *pixmap.writable_addr8(2, 2) = 0x00;
303 canvas->scale(10, 10);
304 canvas->drawImage(image1, 0, 0);
305 canvas->drawImage(image2, 10, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500306##
307
Cary Clark3cd22cc2017-12-01 11:49:58 -0500308#SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Cary Clarka560c472017-11-27 10:44:06 -0500309
310#Method ##
311
312# ------------------------------------------------------------------------------
313
314#Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
315 const SkIRect* subset = nullptr)
316
Cary Clark0c5f5462017-12-15 11:21:51 -0500317Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not
318be shared or accessed.
Cary Clarka560c472017-11-27 10:44:06 -0500319
Cary Clark0c5f5462017-12-15 11:21:51 -0500320subset allows selecting a portion of the full image. Pass nullptr to select the entire image;
321otherwise, subset must be contained by image bounds.
322
323Image is returned if generator data is valid. Valid data parameters vary by type of data
324and platform.
Cary Clarka560c472017-11-27 10:44:06 -0500325
Cary Clark3cd22cc2017-12-01 11:49:58 -0500326imageGenerator may wrap Picture data, codec data, or custom data.
327
328#Param imageGenerator stock or custom routines to retrieve Image ##
329#Param subset bounds of returned Image; may be nullptr ##
330
331#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500332
333#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500334#Description
335The generator returning Picture cannot be shared; std::move transfers ownership to generated Image.
336##
337 SkPictureRecorder recorder;
338 recorder.beginRecording(100, 100)->drawColor(SK_ColorRED);
339 auto picture = recorder.finishRecordingAsPicture();
340 auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr,
341 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB());
342 sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen));
343 canvas->drawImage(image, 0, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500344##
345
Cary Clark3cd22cc2017-12-01 11:49:58 -0500346#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500347
348#Method ##
349
350# ------------------------------------------------------------------------------
351
352#Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)
353
Cary Clark3cd22cc2017-12-01 11:49:58 -0500354Creates Image from encoded data.
Cary Clark0c5f5462017-12-15 11:21:51 -0500355subset allows selecting a portion of the full image. Pass nullptr to select the entire image;
356otherwise, subset must be contained by image bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500357
Cary Clark3cd22cc2017-12-01 11:49:58 -0500358Image is returned if format of the encoded data is recognized and supported.
359Recognized formats vary by platfrom.
Cary Clarka560c472017-11-27 10:44:06 -0500360
Cary Clark3cd22cc2017-12-01 11:49:58 -0500361#Param encoded data of Image to decode ##
362#Param subset bounds of returned Image; may be nullptr ##
363
364#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500365
Cary Clark61ca7c52018-01-02 11:34:14 -0500366#Example
367#Image 3
368int x = 0;
369for (int quality : { 100, 50, 10, 1} ) {
370 sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality);
371 sk_sp<SkImage> image = SkImage::MakeFromEncoded(encodedData);
372 canvas->drawImage(image, x, 0);
373 x += 64;
374}
Cary Clarka560c472017-11-27 10:44:06 -0500375##
376
Cary Clark3cd22cc2017-12-01 11:49:58 -0500377#SeeAlso MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500378
379#Method ##
380
381# ------------------------------------------------------------------------------
382
383#Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext)
384
385##
386
387#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
388 const GrBackendTexture& backendTexture,
389 GrSurfaceOrigin origin,
390 SkAlphaType alphaType,
391 sk_sp<SkColorSpace> colorSpace)
392
Cary Clark61ca7c52018-01-02 11:34:14 -0500393Deprecated.
Cary Clarka560c472017-11-27 10:44:06 -0500394
Cary Clark3cd22cc2017-12-01 11:49:58 -0500395#Param context GPU_Context ##
396#Param backendTexture texture residing on GPU ##
397#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
398#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
399 kPremul_SkAlphaType, kUnpremul_SkAlphaType
400##
Cary Clark61ca7c52018-01-02 11:34:14 -0500401#Param colorSpace range of colors; may be nullptr ##
402
403#Return created Image, or nullptr ##
404
405#NoExample
406##
407
408#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
409
410#Method ##
411
412# ------------------------------------------------------------------------------
413
414#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
415 const GrBackendTexture& backendTexture,
416 GrSurfaceOrigin origin,
417 SkAlphaType alphaType,
418 sk_sp<SkColorSpace> colorSpace,
419 TextureReleaseProc textureReleaseProc,
420 ReleaseContext releaseContext)
421
422Deprecated.
423
424#Param context GPU_Context ##
425#Param backendTexture texture residing on GPU ##
426#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
427#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
428 kPremul_SkAlphaType, kUnpremul_SkAlphaType
429##
430#Param colorSpace range of colors; may be nullptr ##
431#Param textureReleaseProc function called when texture can be released ##
432#Param releaseContext state passed to textureReleaseProc ##
433
434#Return created Image, or nullptr ##
435
436#NoExample
437##
438
439#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
440
441#Method ##
442
443# ------------------------------------------------------------------------------
444
445#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
446 const GrBackendTexture& backendTexture,
447 GrSurfaceOrigin origin,
448 SkColorType colorType,
449 SkAlphaType alphaType,
450 sk_sp<SkColorSpace> colorSpace)
451
452Creates Image from GPU_Texture associated with context. Caller is responsible for
453managing the lifetime of GPU_Texture.
454
455Image is returned if format of backendTexture is recognized and supported.
456Recognized formats vary by GPU back-end.
457
458#Param context GPU_Context ##
459#Param backendTexture texture residing on GPU ##
460#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
461#Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
462 kRGB_565_SkColorType, kARGB_4444_SkColorType,
463 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
464 kGray_8_SkColorType, kRGBA_F16_SkColorType
465##
466#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
467 kPremul_SkAlphaType, kUnpremul_SkAlphaType
468##
469#Param colorSpace range of colors; may be nullptr ##
Cary Clark3cd22cc2017-12-01 11:49:58 -0500470
471#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500472
473#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500474#Image 3
475#Platform gpu
476#Height 128
477#Description
478A back-end texture has been created and uploaded to the GPU outside of this example.
479##
480GrContext* context = canvas->getGrContext();
481if (!context) {
482 return;
483}
484canvas->scale(.25f, .25f);
485int x = 0;
486for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
487 sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
488 origin, kOpaque_SkAlphaType, nullptr);
489 canvas->drawImage(image, x, 0);
490x += 512;
491}
Cary Clarka560c472017-11-27 10:44:06 -0500492##
493
Cary Clark3cd22cc2017-12-01 11:49:58 -0500494#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500495
496#Method ##
497
498# ------------------------------------------------------------------------------
499
500#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
501 const GrBackendTexture& backendTexture,
502 GrSurfaceOrigin origin,
Cary Clark61ca7c52018-01-02 11:34:14 -0500503 SkColorType colorType,
Cary Clarka560c472017-11-27 10:44:06 -0500504 SkAlphaType alphaType,
505 sk_sp<SkColorSpace> colorSpace,
506 TextureReleaseProc textureReleaseProc,
507 ReleaseContext releaseContext)
508
Cary Clark61ca7c52018-01-02 11:34:14 -0500509Creates Image from GPU_Texture associated with context. GPU_Texture must stay
Cary Clark3cd22cc2017-12-01 11:49:58 -0500510valid and unchanged until textureReleaseProc is called. textureReleaseProc is
511passed releaseContext when Image is deleted or no longer refers to texture.
Cary Clarka560c472017-11-27 10:44:06 -0500512
Cary Clark3cd22cc2017-12-01 11:49:58 -0500513Image is returned if format of backendTexture is recognized and supported.
514Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500515
Cary Clark3cd22cc2017-12-01 11:49:58 -0500516#Param context GPU_Context ##
517#Param backendTexture texture residing on GPU ##
518#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
Cary Clark61ca7c52018-01-02 11:34:14 -0500519#Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
520 kRGB_565_SkColorType, kARGB_4444_SkColorType,
521 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
522 kGray_8_SkColorType, kRGBA_F16_SkColorType
523##
Cary Clark3cd22cc2017-12-01 11:49:58 -0500524#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
525 kPremul_SkAlphaType, kUnpremul_SkAlphaType
526##
Cary Clark61ca7c52018-01-02 11:34:14 -0500527#Param colorSpace range of colors; may be nullptr ##
Cary Clark3cd22cc2017-12-01 11:49:58 -0500528#Param textureReleaseProc function called when texture can be released ##
529#Param releaseContext state passed to textureReleaseProc ##
530
531#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500532
Cary Clark0c5f5462017-12-15 11:21:51 -0500533#ToDo
534This doesn't do anything clever with TextureReleaseProc because it may not get called
Cary Clark61ca7c52018-01-02 11:34:14 -0500535fwithin the lifetime of the example
Cary Clark0c5f5462017-12-15 11:21:51 -0500536##
537
Cary Clarka560c472017-11-27 10:44:06 -0500538#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500539GrContext* context = canvas->getGrContext();
540if (!context) {
541 return;
542}
543auto debugster = [](SkImage::ReleaseContext context) -> void {
544 *((int *) context) += 128;
545};
546int x = 0;
547for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
548 sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clark61ca7c52018-01-02 11:34:14 -0500549 origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x);
Cary Clark0c5f5462017-12-15 11:21:51 -0500550 canvas->drawImage(image, x, 0);
551 x += 128;
552}
Cary Clarka560c472017-11-27 10:44:06 -0500553##
554
Cary Clark3cd22cc2017-12-01 11:49:58 -0500555#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500556
557#Method ##
558
559# ------------------------------------------------------------------------------
560
561#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
562 bool buildMips,
563 SkColorSpace* dstColorSpace)
564
Cary Clark3cd22cc2017-12-01 11:49:58 -0500565Creates Image from encoded data. Image is uploaded to GPU back-end using context.
566
567Created Image is available to other GPU contexts, and is available across thread
568boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
569share resources.
570
571When Image is no longer referenced, context releases texture memory
Cary Clarka560c472017-11-27 10:44:06 -0500572asynchronously.
Cary Clarka560c472017-11-27 10:44:06 -0500573
Cary Clark3cd22cc2017-12-01 11:49:58 -0500574Texture decoded from data is uploaded to match Surface created with
575dstColorSpace. Color_Space of Image is determined by encoded data.
Cary Clarka560c472017-11-27 10:44:06 -0500576
Cary Clark3cd22cc2017-12-01 11:49:58 -0500577Image is returned if format of data is recognized and supported, and if context
578supports moving resources. Recognized formats vary by platform and GPU back-end.
579
Cary Clark61ca7c52018-01-02 11:34:14 -0500580Image is returned using MakeFromEncoded if context is nullptr or does not support
581moving resources between contexts.
582
Cary Clark3cd22cc2017-12-01 11:49:58 -0500583#Param context GPU_Context ##
584#Param data Image to decode ##
585#Param buildMips create Image as Mip_Map if true ##
586#Param dstColorSpace range of colors of matching Surface on GPU ##
587
588#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500589
590#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500591#Image 4
592#Height 128
593GrContext* context = canvas->getGrContext();
594sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100);
595sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context,
596 encodedData, false, nullptr);
597canvas->drawImage(image, 0, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500598##
599
Cary Clark3cd22cc2017-12-01 11:49:58 -0500600#SeeAlso MakeCrossContextFromPixmap
601
602#Method ##
603
604# ------------------------------------------------------------------------------
605
606#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
607 bool buildMips,
608 SkColorSpace* dstColorSpace)
609
610Creates Image from pixmap. Image is uploaded to GPU back-end using context.
611
612Created Image is available to other GPU contexts, and is available across thread
613boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
614share resources.
615
616When Image is no longer referenced, context releases texture memory
617asynchronously.
618
619Texture created from pixmap is uploaded to match Surface created with
620dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace().
621
Cary Clark61ca7c52018-01-02 11:34:14 -0500622Image is returned referring to GPU back-end if context is not nullptr,
623format of data is recognized and supported, and if context supports moving
624resources between contexts. Otherwise, pixmap pixel data is copied and Image
625as returned in raster format if possible; nullptr may be returned.
626Recognized GPU formats vary by platform and GPU back-end.
Cary Clark3cd22cc2017-12-01 11:49:58 -0500627
628#Param context GPU_Context ##
629#Param pixmap Image_Info, pixel address, and row bytes ##
630#Param buildMips create Image as Mip_Map if true ##
631#Param dstColorSpace range of colors of matching Surface on GPU ##
632
633#Return created Image, or nullptr ##
634
635#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500636#Image 4
637#Height 128
638GrContext* context = canvas->getGrContext();
639SkPixmap pixmap;
640if (source.peekPixels(&pixmap)) {
641 sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap,
642 false, nullptr);
643 canvas->drawImage(image, 0, 0);
644}
Cary Clark3cd22cc2017-12-01 11:49:58 -0500645##
646
647#SeeAlso MakeCrossContextFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500648
649#Method ##
650
651# ------------------------------------------------------------------------------
652
653#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
654 const GrBackendTexture& backendTexture,
655 GrSurfaceOrigin surfaceOrigin,
656 SkAlphaType alphaType = kPremul_SkAlphaType,
657 sk_sp<SkColorSpace> colorSpace = nullptr)
658
Cary Clark61ca7c52018-01-02 11:34:14 -0500659Deprecated.
660
661#Param context GPU_Context ##
662#Param backendTexture texture residing on GPU ##
663#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
664#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
665 kPremul_SkAlphaType, kUnpremul_SkAlphaType
666##
667#Param colorSpace range of colors; may be nullptr ##
668
669#Return created Image, or nullptr ##
670
671#NoExample
672##
673
674#SeeAlso MakeFromTexture MakeFromYUVTexturesCopy
675
676#Method ##
677
678# ------------------------------------------------------------------------------
679
680#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
681 const GrBackendTexture& backendTexture,
682 GrSurfaceOrigin surfaceOrigin,
683 SkColorType colorType,
684 SkAlphaType alphaType = kPremul_SkAlphaType,
685 sk_sp<SkColorSpace> colorSpace = nullptr)
686
Cary Clark3cd22cc2017-12-01 11:49:58 -0500687Creates Image from backendTexture associated with context. backendTexture and
688returned Image are managed internally, and are released when no longer needed.
Cary Clarka560c472017-11-27 10:44:06 -0500689
Cary Clark3cd22cc2017-12-01 11:49:58 -0500690Image is returned if format of backendTexture is recognized and supported.
691Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500692
Cary Clark3cd22cc2017-12-01 11:49:58 -0500693#Param context GPU_Context ##
694#Param backendTexture texture residing on GPU ##
695#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
Cary Clark61ca7c52018-01-02 11:34:14 -0500696#Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
697 kRGB_565_SkColorType, kARGB_4444_SkColorType,
698 kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
699 kGray_8_SkColorType, kRGBA_F16_SkColorType
700##
Cary Clark3cd22cc2017-12-01 11:49:58 -0500701#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
702 kPremul_SkAlphaType, kUnpremul_SkAlphaType
703##
Cary Clark61ca7c52018-01-02 11:34:14 -0500704#Param colorSpace range of colors; may be nullptr ##
Cary Clark3cd22cc2017-12-01 11:49:58 -0500705
706#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500707
708#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500709 if (!canvas->getGrContext()) {
710 return;
711 }
712 canvas->scale(.5f, .5f);
713 canvas->clear(0x7f3f5f7f);
714 int x = 0, y = 0;
715 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
716 for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) {
717 sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(),
718 backEndTexture, origin,
719 kRGBA_8888_SkColorType, alpha);
720 canvas->drawImage(image, x, y);
721 x += 160;
722 }
723 x -= 160 * 3;
724 y += 256;
725 }
Cary Clarka560c472017-11-27 10:44:06 -0500726##
727
Cary Clark61ca7c52018-01-02 11:34:14 -0500728#SeeAlso MakeFromTexture MakeFromYUVTexturesCopy
Cary Clarka560c472017-11-27 10:44:06 -0500729
730#Method ##
731
732# ------------------------------------------------------------------------------
733
734#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
735 const GrBackendObject yuvTextureHandles[3],
736 const SkISize yuvSizes[3],
737 GrSurfaceOrigin surfaceOrigin,
738 sk_sp<SkColorSpace> colorSpace = nullptr)
739
Cary Clark61ca7c52018-01-02 11:34:14 -0500740Creates Image from copy of yuvTextureHandles, an array of textures on GPU.
741yuvTextureHandles contain pixels for YUV planes of Image.
742yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than
743zero but may differ from plane to plane. Returned Image has the dimensions
744yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors.
Cary Clarka560c472017-11-27 10:44:06 -0500745
Cary Clark61ca7c52018-01-02 11:34:14 -0500746#Param context GPU_Context ##
747#Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
748 kRec709_SkYUVColorSpace
749##
750#Param yuvTextureHandles array of YUV textures on GPU ##
751#Param yuvSizes dimensions of YUV textures ##
752#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
753#Param colorSpace range of colors; may be nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500754
Cary Clark61ca7c52018-01-02 11:34:14 -0500755#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500756
Cary Clark61ca7c52018-01-02 11:34:14 -0500757# seems too complicated to create an example for this
758#ToDo
759should this be moved to chrome only?
Cary Clarka560c472017-11-27 10:44:06 -0500760##
761
Cary Clark61ca7c52018-01-02 11:34:14 -0500762#NoExample
763##
764
765#SeeAlso MakeFromNV12TexturesCopy
766
767#Method ##
768
769# ------------------------------------------------------------------------------
770
771#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
772 const GrBackendTexture yuvTextureHandles[3],
773 const SkISize yuvSizes[3],
774 GrSurfaceOrigin surfaceOrigin,
775 sk_sp<SkColorSpace> colorSpace = nullptr)
776
777Creates Image from copy of yuvTextureHandles, an array of textures on GPU.
778yuvTextureHandles contain pixels for YUV planes of Image.
779yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than
780zero but may differ from plane to plane. Returned Image has the dimensions
781yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors.
782
783#Param context GPU_Context ##
784#Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
785 kRec709_SkYUVColorSpace
786##
787#Param yuvTextureHandles array of YUV textures on GPU ##
788#Param yuvSizes dimensions of YUV textures ##
789#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
790#Param colorSpace range of colors; may be nullptr ##
791
792#Return created Image, or nullptr ##
793
794# seems too complicated to create an example for this
795#ToDo
796should this be moved to chrome only?
797##
798
799#NoExample
800##
801
802#SeeAlso MakeFromNV12TexturesCopy
Cary Clarka560c472017-11-27 10:44:06 -0500803
804#Method ##
805
806# ------------------------------------------------------------------------------
807
808#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
809 SkYUVColorSpace yuvColorSpace,
810 const GrBackendObject nv12TextureHandles[2],
811 const SkISize nv12Sizes[2],
812 GrSurfaceOrigin surfaceOrigin,
813 sk_sp<SkColorSpace> colorSpace = nullptr)
814
Cary Clark61ca7c52018-01-02 11:34:14 -0500815Creates Image from copy of nv12TextureHandles, an array of textures on GPU.
816nv12TextureHandles[0] contains pixels for YUV_Component_Y plane.
817nv12TextureHandles[1] contains pixels for YUV_Component_U plane,
818followed by pixels for YUV_Component_V plane.
819nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than
820zero but may differ from plane to plane. Returned Image has the dimensions
821nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors.
Cary Clarka560c472017-11-27 10:44:06 -0500822
Cary Clark61ca7c52018-01-02 11:34:14 -0500823#Param context GPU_Context ##
824#Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
825 kRec709_SkYUVColorSpace
826##
827#Param nv12TextureHandles array of YUV textures on GPU ##
828#Param nv12Sizes dimensions of YUV textures ##
829#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
830#Param colorSpace range of colors; may be nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500831
Cary Clark61ca7c52018-01-02 11:34:14 -0500832#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500833
Cary Clark61ca7c52018-01-02 11:34:14 -0500834# seems too complicated to create an example for this
835#ToDo
836should this be moved to chrome only?
Cary Clarka560c472017-11-27 10:44:06 -0500837##
838
Cary Clark61ca7c52018-01-02 11:34:14 -0500839#NoExample
840##
841
842#SeeAlso MakeFromYUVTexturesCopy
Cary Clarka560c472017-11-27 10:44:06 -0500843
844#Method ##
845
846# ------------------------------------------------------------------------------
847
Cary Clark61ca7c52018-01-02 11:34:14 -0500848#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
849 SkYUVColorSpace yuvColorSpace,
850 const GrBackendTexture nv12TextureHandles[2],
851 const SkISize nv12Sizes[2],
852 GrSurfaceOrigin surfaceOrigin,
853 sk_sp<SkColorSpace> colorSpace = nullptr)
854
855Creates Image from copy of nv12TextureHandles, an array of textures on GPU.
856nv12TextureHandles[0] contains pixels for YUV_Component_Y plane.
857nv12TextureHandles[1] contains pixels for YUV_Component_U plane,
858followed by pixels for YUV_Component_V plane.
859nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than
860zero but may differ from plane to plane. Returned Image has the dimensions
861nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors.
862
863#Param context GPU_Context ##
864#Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,
865 kRec709_SkYUVColorSpace
866##
867#Param nv12TextureHandles array of YUV textures on GPU ##
868#Param nv12Sizes dimensions of YUV textures ##
869#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
870#Param colorSpace range of colors; may be nullptr ##
871
872#Return created Image, or nullptr ##
873
874# seems too complicated to create an example for this
875#ToDo
876should this be moved to chrome only?
877##
878
879#NoExample
880##
881
882#SeeAlso MakeFromYUVTexturesCopy
883
884#Method ##
885
886# ------------------------------------------------------------------------------
887
888#Bug 7424
889currently uncalled by any test or client
890##
891
Cary Clarka560c472017-11-27 10:44:06 -0500892#Enum BitDepth
893
894#Code
Cary Clark61ca7c52018-01-02 11:34:14 -0500895 enum class BitDepth {
Cary Clarka560c472017-11-27 10:44:06 -0500896 kU8,
897 kF16,
898 };
899##
900
901#Const kU8 0
Cary Clark61ca7c52018-01-02 11:34:14 -0500902Use 8 bits per Color_ARGB component using unsigned integer format.
Cary Clarka560c472017-11-27 10:44:06 -0500903##
904#Const kF16 1
Cary Clark61ca7c52018-01-02 11:34:14 -0500905Use 16 bits per Color_ARGB component using half-precision floating point format.
Cary Clarka560c472017-11-27 10:44:06 -0500906##
907
Cary Clark61ca7c52018-01-02 11:34:14 -0500908#NoExample
Cary Clarka560c472017-11-27 10:44:06 -0500909##
910
Cary Clark61ca7c52018-01-02 11:34:14 -0500911#SeeAlso MakeFromPicture
Cary Clarka560c472017-11-27 10:44:06 -0500912
913#Enum ##
914
915# ------------------------------------------------------------------------------
916
917#Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
918 const SkMatrix* matrix, const SkPaint* paint,
919 BitDepth bitDepth,
920 sk_sp<SkColorSpace> colorSpace)
921
Cary Clark61ca7c52018-01-02 11:34:14 -0500922Creates Image from picture. Returned Image width and height are set by dimensions.
923Image draws picture with matrix and paint, set to bitDepth and colorSpace.
Cary Clarka560c472017-11-27 10:44:06 -0500924
Cary Clark61ca7c52018-01-02 11:34:14 -0500925If matrix is nullptr, draws with identity Matrix. If paint is nullptr, draws
926with default Paint. colorSpace may be nullptr.
Cary Clarka560c472017-11-27 10:44:06 -0500927
Cary Clark61ca7c52018-01-02 11:34:14 -0500928#Param picture stream of drawing commands ##
929#Param dimensions width and height ##
930#Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ##
931#Param paint Paint to apply transparency, filtering, and so on; may be nullptr ##
932#Param bitDepth 8 bit integer or 16 bit float: per component ##
933#Param colorSpace range of colors; may be nullptr ##
934
935#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500936
937#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500938 SkPaint paint;
939 SkPictureRecorder recorder;
940 SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
941 for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
942 paint.setColor(color);
943 recordingCanvas->drawRect({10, 10, 30, 40}, paint);
944 recordingCanvas->translate(10, 10);
945 recordingCanvas->scale(1.2f, 1.4f);
946 }
947 sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
948 int x = 0, y = 0;
949 for (auto alpha : { 70, 140, 210 } ) {
950 paint.setAlpha(alpha);
951 auto srgbColorSpace = SkColorSpace::MakeSRGB();
952 sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint,
953 SkImage::BitDepth::kU8, srgbColorSpace);
954 canvas->drawImage(image, x, y);
955 x += 70; y += 70;
956 }
Cary Clarka560c472017-11-27 10:44:06 -0500957##
958
Cary Clark61ca7c52018-01-02 11:34:14 -0500959#SeeAlso SkCanvas::drawPicture
Cary Clarka560c472017-11-27 10:44:06 -0500960
961#Method ##
962
963# ------------------------------------------------------------------------------
964
965#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
966 SkAlphaType alphaType = kPremul_SkAlphaType,
967 sk_sp<SkColorSpace> colorSpace = nullptr)
968
Cary Clark61ca7c52018-01-02 11:34:14 -0500969#Bug 7447 ##
Cary Clarka560c472017-11-27 10:44:06 -0500970
Cary Clark61ca7c52018-01-02 11:34:14 -0500971Creates Image from Android hardware buffer.
972Returned Image takes a reference on the buffer.
Cary Clarka560c472017-11-27 10:44:06 -0500973
Cary Clark61ca7c52018-01-02 11:34:14 -0500974Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
Cary Clarka560c472017-11-27 10:44:06 -0500975
Cary Clark61ca7c52018-01-02 11:34:14 -0500976#Param hardwareBuffer AHardwareBuffer Android hardware buffer ##
977#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
978 kPremul_SkAlphaType, kUnpremul_SkAlphaType
979##
980#Param colorSpace range of colors; may be nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500981
Cary Clark61ca7c52018-01-02 11:34:14 -0500982#Return created Image, or nullptr ##
983
984#NoExample
Cary Clarka560c472017-11-27 10:44:06 -0500985##
986
Cary Clark61ca7c52018-01-02 11:34:14 -0500987#SeeAlso MakeFromRaster
Cary Clarka560c472017-11-27 10:44:06 -0500988
989#Method ##
990
991# ------------------------------------------------------------------------------
992
993#Method int width() const
994
Cary Clark61ca7c52018-01-02 11:34:14 -0500995Returns pixel count in each row.
996
997#Return pixel width in Image ##
Cary Clarka560c472017-11-27 10:44:06 -0500998
999#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001000#Image 4
1001#Height 168
1002 canvas->translate(10, 10);
1003 canvas->drawImage(image, 0, 0);
1004 canvas->translate(0, image->height());
1005 SkPaint paint;
1006 paint.setTextAlign(SkPaint::kCenter_Align);
1007 canvas->drawLine(0, 10, image->width(), 10, paint);
1008 canvas->drawString("width", image->width() / 2, 25, paint);
Cary Clarka560c472017-11-27 10:44:06 -05001009##
1010
Cary Clark61ca7c52018-01-02 11:34:14 -05001011#SeeAlso dimensions() height()
Cary Clarka560c472017-11-27 10:44:06 -05001012
1013#Method ##
1014
1015# ------------------------------------------------------------------------------
1016
1017#Method int height() const
1018
Cary Clark2f466242017-12-11 16:03:17 -05001019Returns pixel row count.
1020
Cary Clark61ca7c52018-01-02 11:34:14 -05001021#Return pixel height in Image ##
Cary Clarka560c472017-11-27 10:44:06 -05001022
1023#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001024#Image 4
1025#Height 148
1026 canvas->translate(10, 10);
1027 canvas->drawImage(image, 0, 0);
1028 canvas->translate(image->width(), 0);
1029 SkPaint paint;
1030 paint.setTextAlign(SkPaint::kCenter_Align);
1031 paint.setVerticalText(true);
1032 canvas->drawLine(10, 0, 10, image->height(), paint);
1033 canvas->drawString("height", 25, image->height() / 2, paint);##
Cary Clarka560c472017-11-27 10:44:06 -05001034
Cary Clark61ca7c52018-01-02 11:34:14 -05001035#SeeAlso dimensions() width()
Cary Clarka560c472017-11-27 10:44:06 -05001036
1037#Method ##
1038
1039# ------------------------------------------------------------------------------
1040
1041#Method SkISize dimensions() const
1042
Cary Clark2f466242017-12-11 16:03:17 -05001043Returns ISize { width(), height() }.
1044
1045#Return integral size of width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -05001046
1047#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001048#Image 4
1049 SkISize dimensions = image->dimensions();
1050 SkIRect bounds = image->bounds();
1051 SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions);
1052 SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -05001053##
1054
Cary Clark61ca7c52018-01-02 11:34:14 -05001055#SeeAlso height() width() bounds()
Cary Clarka560c472017-11-27 10:44:06 -05001056
1057#Method ##
1058
1059# ------------------------------------------------------------------------------
1060
1061#Method SkIRect bounds() const
1062
Cary Clark2f466242017-12-11 16:03:17 -05001063Returns IRect { 0, 0, width(), height() }.
1064
1065#Return integral rectangle from origin to width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -05001066
1067#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001068#Height 128
1069#Image 4
1070 canvas->scale(.5f, .5f);
1071 SkIRect bounds = image->bounds();
1072 for (int x : { 0, image->width() } ) {
1073 for (int y : { 0, image->height() } ) {
1074 canvas->drawImage(image, x, y);
1075 }
1076 }
Cary Clarka560c472017-11-27 10:44:06 -05001077##
1078
Cary Clark61ca7c52018-01-02 11:34:14 -05001079#SeeAlso dimensions()
Cary Clarka560c472017-11-27 10:44:06 -05001080
1081#Method ##
1082
1083# ------------------------------------------------------------------------------
1084
1085#Method uint32_t uniqueID() const
1086
Cary Clark61ca7c52018-01-02 11:34:14 -05001087Returns value unique to image. Image contents cannot change after Image is
1088created. Any operation to create a new Image will receive generate a new
1089unique number.
1090
1091#Return unique identifier ##
Cary Clarka560c472017-11-27 10:44:06 -05001092
1093#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001094#Image 5
1095#Height 156
1096 sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100});
1097 canvas->drawImage(image, 0, 0);
1098 canvas->drawImage(subset, 128, 0);
1099 SkPaint paint;
1100 SkString s;
1101 s.printf("original id: %d", image->uniqueID());
1102 canvas->drawString(s, 20, image->height() + 20, paint);
1103 s.printf("subset id: %d", subset->uniqueID());
1104 canvas->drawString(s, 148, subset->height() + 20, paint);
Cary Clarka560c472017-11-27 10:44:06 -05001105##
1106
Cary Clark61ca7c52018-01-02 11:34:14 -05001107#SeeAlso isLazyGenerated
Cary Clarka560c472017-11-27 10:44:06 -05001108
1109#Method ##
1110
1111# ------------------------------------------------------------------------------
1112
1113#Method SkAlphaType alphaType() const
1114
Cary Clark61ca7c52018-01-02 11:34:14 -05001115Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
1116kPremul_SkAlphaType, kUnpremul_SkAlphaType.
1117
1118Alpha_Type returned was a parameter to an Image constructor,
1119or was parsed from encoded data.
1120
1121#Return Alpha_Type in Image ##
Cary Clarka560c472017-11-27 10:44:06 -05001122
1123#Example
Cary Clark61ca7c52018-01-02 11:34:14 -05001124#Image 4
1125#Height 156
1126 const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
1127 SkAlphaType alphaType = image->alphaType();
1128 canvas->drawImage(image, 0, 0);
1129 SkPaint paint;
1130 canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, paint);
Cary Clarka560c472017-11-27 10:44:06 -05001131##
1132
Cary Clark61ca7c52018-01-02 11:34:14 -05001133#SeeAlso SkImageInfo::alphaType
Cary Clarka560c472017-11-27 10:44:06 -05001134
1135#Method ##
1136
1137# ------------------------------------------------------------------------------
1138
1139#Method SkColorSpace* colorSpace() const
1140
Cary Clark2f466242017-12-11 16:03:17 -05001141Returns Color_Space, the range of colors, associated with Image. The
1142reference count of Color_Space is unchanged. The returned Color_Space is
1143immutable.
Cary Clarka560c472017-11-27 10:44:06 -05001144
Cary Clark61dfc3a2018-01-03 08:37:53 -05001145Color_Space returned was passed to an Image constructor,
1146or was parsed from encoded data. Color_Space returned may be ignored when Image
1147is drawn, depending on the capabilities of the Surface receiving the drawing.
Cary Clark2f466242017-12-11 16:03:17 -05001148
1149#Return Color_Space in Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001150
1151#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001152#Image 3
1153#Set sRGB
1154 SkPixmap pixmap;
1155 source.peekPixels(&pixmap);
1156 canvas->scale(.25f, .25f);
1157 int y = 0;
1158 for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma,
1159 SkColorSpace::kSRGB_RenderTargetGamma } ) {
1160 int x = 0;
1161 sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut);
1162 for (int index = 0; index < 2; ++index) {
1163 pixmap.setColorSpace(colorSpace);
1164 sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap);
1165 canvas->drawImage(image, x, y);
1166 colorSpace = image->colorSpace()->makeColorSpin();
1167 x += 512;
1168 }
1169 y += 512;
1170 }
Cary Clarka560c472017-11-27 10:44:06 -05001171##
1172
Cary Clark61dfc3a2018-01-03 08:37:53 -05001173#SeeAlso refColorSpace makeColorSpace
Cary Clarka560c472017-11-27 10:44:06 -05001174
1175#Method ##
1176
1177# ------------------------------------------------------------------------------
1178
1179#Method sk_sp<SkColorSpace> refColorSpace() const
1180
Cary Clark61dfc3a2018-01-03 08:37:53 -05001181Returns a smart pointer to Color_Space, the range of colors, associated with
1182Image. The smart pointer tracks the number of objects sharing this
1183SkColorSpace reference so the memory is released when the owners destruct.
1184
1185The returned SkColorSpace is immutable.
1186
1187Color_Space returned was passed to an Image constructor,
1188or was parsed from encoded data. Color_Space returned may be ignored when Image
1189is drawn, depending on the capabilities of the Surface receiving the drawing.
1190
1191#Return Color_Space in Image, or nullptr, wrapped in a smart pointer ##
Cary Clarka560c472017-11-27 10:44:06 -05001192
1193#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001194#Image 3
1195#Set sRGB
1196 SkPixmap pixmap;
1197 source.peekPixels(&pixmap);
1198 canvas->scale(.25f, .25f);
1199 int y = 0;
1200 for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma,
1201 SkColorSpace::kSRGB_RenderTargetGamma } ) {
1202 int x = 0;
1203 sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut);
1204 for (int index = 0; index < 2; ++index) {
1205 pixmap.setColorSpace(colorSpace);
1206 sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap);
1207 canvas->drawImage(image, x, y);
1208 colorSpace = image->refColorSpace()->makeColorSpin();
1209 x += 512;
1210 }
1211 y += 512;
1212 }
Cary Clarka560c472017-11-27 10:44:06 -05001213##
1214
Cary Clark61dfc3a2018-01-03 08:37:53 -05001215#SeeAlso colorSpace makeColorSpace
Cary Clarka560c472017-11-27 10:44:06 -05001216
1217#Method ##
1218
1219# ------------------------------------------------------------------------------
1220
1221#Method bool isAlphaOnly() const
1222
Cary Clark2f466242017-12-11 16:03:17 -05001223Returns true if Image pixels represent transparency only. If true, each pixel
1224is packed in 8 bits as defined by kAlpha_8_SkColorType.
Cary Clarka560c472017-11-27 10:44:06 -05001225
Cary Clark2f466242017-12-11 16:03:17 -05001226#Return true if pixels represent a transparency mask ##
Cary Clarka560c472017-11-27 10:44:06 -05001227
1228#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001229 uint8_t pmColors = 0;
1230 sk_sp<SkImage> image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1});
1231 SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false");
1232#StdOut
1233alphaOnly = true
1234##
Cary Clarka560c472017-11-27 10:44:06 -05001235##
1236
Cary Clark61dfc3a2018-01-03 08:37:53 -05001237#SeeAlso alphaType isOpaque
Cary Clarka560c472017-11-27 10:44:06 -05001238
1239#Method ##
1240
1241# ------------------------------------------------------------------------------
1242
1243#Method bool isOpaque() const
1244
Cary Clark61dfc3a2018-01-03 08:37:53 -05001245Returns true if pixels ignore their Alpha value and are treated as fully opaque.
Cary Clark2f466242017-12-11 16:03:17 -05001246
1247#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clarka560c472017-11-27 10:44:06 -05001248
1249#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001250 auto check_isopaque = [](const SkImageInfo& imageInfo) -> void {
1251 auto surface(SkSurface::MakeRaster(imageInfo));
1252 auto image(surface->makeImageSnapshot());
1253 SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false");
1254 };
1255
1256 check_isopaque(SkImageInfo::MakeN32Premul(5, 5));
1257 check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType));
1258#StdOut
1259isOpaque = false
1260isOpaque = true
1261##
Cary Clarka560c472017-11-27 10:44:06 -05001262##
1263
Cary Clark61dfc3a2018-01-03 08:37:53 -05001264#SeeAlso alphaType isAlphaOnly
Cary Clarka560c472017-11-27 10:44:06 -05001265
1266#Method ##
1267
1268# ------------------------------------------------------------------------------
1269
1270#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
1271 const SkMatrix* localMatrix = nullptr) const
1272
Cary Clark61dfc3a2018-01-03 08:37:53 -05001273Creates Shader from Image. Shader dimensions are taken from Image. Shader uses
1274SkShader::TileMode rules to fill drawn area outside Image. localMatrix permits
1275transforming Image before Canvas_Matrix is applied.
Cary Clarka560c472017-11-27 10:44:06 -05001276
Cary Clark61dfc3a2018-01-03 08:37:53 -05001277#Param tileMode1 tiling in x, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode,
1278 SkShader::kMirror_TileMode
1279##
1280#Param tileMode2 tiling in y, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode,
1281 SkShader::kMirror_TileMode
1282##
1283#Param localMatrix Image transformation, or nullptr ##
1284
1285#Return Shader containing Image ##
Cary Clarka560c472017-11-27 10:44:06 -05001286
1287#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001288#Image 4
1289SkMatrix matrix;
1290matrix.setRotate(45);
1291SkPaint paint;
1292paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode,
1293 &matrix));
1294canvas->drawPaint(paint);
Cary Clarka560c472017-11-27 10:44:06 -05001295##
1296
Cary Clark61dfc3a2018-01-03 08:37:53 -05001297#SeeAlso scalePixels
Cary Clarka560c472017-11-27 10:44:06 -05001298
1299#Method ##
1300
1301# ------------------------------------------------------------------------------
1302
1303#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
1304
Cary Clark61dfc3a2018-01-03 08:37:53 -05001305Creates Shader from Image. Shader dimensions are taken from Image. Shader uses
1306SkShader::kClamp_TileMode to fill drawn area outside Image. localMatrix permits
1307transforming Image before Canvas_Matrix is applied.
Cary Clarka560c472017-11-27 10:44:06 -05001308
Cary Clark61dfc3a2018-01-03 08:37:53 -05001309#Param localMatrix Image transformation, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001310
Cary Clark61dfc3a2018-01-03 08:37:53 -05001311#Return Shader containing Image ##
Cary Clarka560c472017-11-27 10:44:06 -05001312
1313#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -05001314#Image 5
1315SkMatrix matrix;
1316matrix.setRotate(45);
1317matrix.postTranslate(125, 30);
1318SkPaint paint;
1319paint.setShader(image->makeShader(&matrix));
1320canvas->drawPaint(paint);
Cary Clarka560c472017-11-27 10:44:06 -05001321##
1322
1323#SeeAlso incomplete
1324
1325#Method ##
1326
1327# ------------------------------------------------------------------------------
1328
1329#Method bool peekPixels(SkPixmap* pixmap) const
1330
1331If the image has direct access to its pixels (i.e. they are in local RAM)
1332return true, and if not null, return in the pixmap parameter the info about the
1333images pixels.
1334On failure, return false and ignore the pixmap parameter.
1335
1336#Param pixmap incomplete ##
1337
1338#Return incomplete ##
1339
1340#Example
1341// incomplete
1342##
1343
1344#SeeAlso incomplete
1345
1346#Method ##
1347
1348# ------------------------------------------------------------------------------
1349
1350#Method GrTexture* getTexture() const
1351
Cary Clark2f466242017-12-11 16:03:17 -05001352Deprecated.
1353
1354#Deprecated
1355##
1356
Cary Clarka560c472017-11-27 10:44:06 -05001357#Private
1358currently used by Canvas2DLayerBridge in Chromium.
1359##
1360
Cary Clarka560c472017-11-27 10:44:06 -05001361#Method ##
1362
1363# ------------------------------------------------------------------------------
1364
1365#Method bool isTextureBacked() const
1366
1367Returns true if the image is texture backed.
1368
1369#Return incomplete ##
1370
1371#Example
1372// incomplete
1373##
1374
1375#SeeAlso incomplete
1376
1377#Method ##
1378
1379# ------------------------------------------------------------------------------
1380
1381#Method bool isValid(GrContext* context) const
1382
1383Returns true if Image can be drawn. If context
1384is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image
1385draws on GPU_Surface associated with context.
1386
1387Texture-backed images may become invalid if their underlying GrContext is abandoned. Some
1388generator-backed images may be invalid for CPU and/or GPU.
1389
Cary Clark61ca7c52018-01-02 11:34:14 -05001390#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001391
1392#Return incomplete ##
1393
1394#Example
1395// incomplete
1396##
1397
1398#SeeAlso incomplete
1399
1400#Method ##
1401
1402# ------------------------------------------------------------------------------
1403
1404#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
1405 GrSurfaceOrigin* origin = nullptr) const
1406
Cary Clark2f466242017-12-11 16:03:17 -05001407Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true,
1408complete deferred I/O operations.
Cary Clarka560c472017-11-27 10:44:06 -05001409
Cary Clark2f466242017-12-11 16:03:17 -05001410If origin in not nullptr, copies location of content drawn into Image.
Cary Clarka560c472017-11-27 10:44:06 -05001411
Cary Clark2f466242017-12-11 16:03:17 -05001412#Param flushPendingGrContextIO flag to flush outstanding requests ##
1413#Param origin storage for one of: kTopLeft_GrSurfaceOrigin,
1414 kBottomLeft_GrSurfaceOrigin; or nullptr
1415##
1416
1417#Return back-end API texture handle ##
Cary Clarka560c472017-11-27 10:44:06 -05001418
1419#Example
Cary Clark2f466242017-12-11 16:03:17 -05001420#Image 3
1421#Platform gpu
1422GrContext* context = canvas->getGrContext();
1423if (!context) {
1424 return;
1425}
1426SkPaint paint;
1427paint.setAntiAlias(true);
1428SkString str;
1429int y = 0;
1430for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
1431 sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
1432 backEndTexture, origin, kPremul_SkAlphaType, nullptr));
1433 GrSurfaceOrigin readBackOrigin;
1434 GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
1435 str.printf("readBackHandle: %x", readBackHandle);
1436 canvas->drawString(str, 5, y += 20, paint);
1437 str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft");
1438 canvas->drawString(str, 5, y += 20, paint);
1439}
Cary Clarka560c472017-11-27 10:44:06 -05001440##
1441
1442#SeeAlso incomplete
1443
1444#Method ##
1445
1446# ------------------------------------------------------------------------------
1447
1448#Enum CachingHint
1449
1450#Code
1451 enum CachingHint {
1452 kAllow_CachingHint,
1453 kDisallow_CachingHint,
1454 };
1455##
1456
1457Hints to image calls where the system might cache computed intermediates (e.g. the results
1458of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
1459behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
1460
1461#Const kAllow_CachingHint 0
1462##
1463#Const kDisallow_CachingHint 1
1464##
1465
1466#Example
1467// incomplete
1468##
1469
1470#SeeAlso incomplete
1471
1472#Enum ##
1473
1474# ------------------------------------------------------------------------------
1475
1476#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1477 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
1478
1479Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
1480converting them into the requested format (dstInfo). The image pixels are read
1481starting at the specified (srcX, srcY) location.
1482dstInfo and (srcX, srcY) offset specifies a source rectangle:
1483#Code
1484SkRect srcR;
1485srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
1486##
1487
1488The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
1489then we have two sets of pixels (of equal size). Replace dstPixels with the
1490corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
1491(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
1492This call can fail, returning false, for several reasons:
1493if source rectangle does not intersect the image bounds;
1494if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
1495
1496#Param dstInfo incomplete ##
1497#Param dstPixels incomplete ##
1498#Param dstRowBytes incomplete ##
1499#Param srcX incomplete ##
1500#Param srcY incomplete ##
1501#Param cachingHint incomplete ##
1502
1503#Return incomplete ##
1504
1505#Example
1506// incomplete
1507##
1508
1509#SeeAlso incomplete
1510
1511#Method ##
1512
1513# ------------------------------------------------------------------------------
1514
1515#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1516 CachingHint cachingHint = kAllow_CachingHint) const
1517
1518#Param dst incomplete ##
1519#Param srcX incomplete ##
1520#Param srcY incomplete ##
1521#Param cachingHint incomplete ##
1522
1523#Return incomplete ##
1524
1525#Example
1526// incomplete
1527##
1528
1529#SeeAlso incomplete
1530
1531#Method ##
1532
1533# ------------------------------------------------------------------------------
1534
1535#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1536 CachingHint cachingHint = kAllow_CachingHint) const
1537
1538Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1539If the conversion cannot be performed, false is returned.
1540If dst dimensions differ from Image dimensions, Image is scaled, applying
1541filterQuality.
1542
1543#Param dst incomplete ##
1544#Param filterQuality incomplete ##
1545#Param cachingHint incomplete ##
1546
1547#Return incomplete ##
1548
1549#Example
1550// incomplete
1551##
1552
1553#SeeAlso incomplete
1554
1555#Method ##
1556
1557# ------------------------------------------------------------------------------
1558
1559#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1560
Cary Clark2f466242017-12-11 16:03:17 -05001561Encodes Image pixels, returning result as SkData.
1562
1563Returns nullptr if encoding fails, or encodedImageFormat is not supported.
Cary Clarka560c472017-11-27 10:44:06 -05001564
1565#Param encodedImageFormat incomplete ##
1566#Param quality incomplete ##
1567
Cary Clark2f466242017-12-11 16:03:17 -05001568#Return encoded Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001569
1570#Example
1571// incomplete
1572##
1573
1574#SeeAlso incomplete
1575
1576#Method ##
1577
1578# ------------------------------------------------------------------------------
1579
Cary Clark61ca7c52018-01-02 11:34:14 -05001580#Method sk_sp<SkData> encodeToData() const
Cary Clarka560c472017-11-27 10:44:06 -05001581
1582Encodes Image and returns result as SkData. Will reuse existing encoded data
Cary Clark61ca7c52018-01-02 11:34:14 -05001583if present, as returned by refEncodedData. If encoded data is missing or invalid,
1584Image is encoded as PNG.
Cary Clarka560c472017-11-27 10:44:06 -05001585
1586Returns nullptr if existing encoded data is missing or invalid and
1587encoding fails.
1588
Cary Clarka560c472017-11-27 10:44:06 -05001589#Return incomplete ##
1590
1591#Example
1592// incomplete
1593##
1594
1595#SeeAlso incomplete
1596
1597#Method ##
1598
1599# ------------------------------------------------------------------------------
1600
1601#Method sk_sp<SkData> refEncodedData() const
1602
1603If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1604as SkData. If the image does not already has its contents in encoded form, return nullptr.
1605
1606To force the image to return its contents as encoded data, call encodeToData.
1607
1608#Return incomplete ##
1609
1610#Example
1611// incomplete
1612##
1613
1614#SeeAlso incomplete
1615
1616#Method ##
1617
1618# ------------------------------------------------------------------------------
1619
1620#Method const char* toString(SkString* string) const
1621
1622#Param string incomplete ##
1623
1624#Return incomplete ##
1625
1626#Example
1627// incomplete
1628##
1629
1630#SeeAlso incomplete
1631
1632#Method ##
1633
1634# ------------------------------------------------------------------------------
1635
1636#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
1637
1638Return a new image that is a subset of this image. The underlying implementation may
1639share the pixels, or it may make a copy.
1640If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1641nullptr will be returned.
1642
1643#Param subset incomplete ##
1644
1645#Return incomplete ##
1646
1647#Example
1648// incomplete
1649##
1650
1651#SeeAlso incomplete
1652
1653#Method ##
1654
1655# ------------------------------------------------------------------------------
1656
1657#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1658
1659Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1660with surfaces that have the supplied destination color space. If no transformation is
1661required, the returned image may be the same as this image. If this image is from a
1662different GrContext, this will fail.
1663
Cary Clark61ca7c52018-01-02 11:34:14 -05001664#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001665#Param dstColorSpace incomplete ##
1666
1667#Return incomplete ##
1668
1669#Example
1670// incomplete
1671##
1672
1673#SeeAlso incomplete
1674
1675#Method ##
1676
1677# ------------------------------------------------------------------------------
1678
1679#Method sk_sp<SkImage> makeNonTextureImage() const
1680
Cary Clark61ca7c52018-01-02 11:34:14 -05001681Creates raster Image if Image contains GPU_Texture and raster Image , this will make a raster copy of it (or nullptr if reading back
1682the pixels fails). Otherwise, it returns the original image.
1683
1684#Return incomplete ##
1685
1686#Example
1687// incomplete
1688##
1689
1690#SeeAlso incomplete
1691
1692#Method ##
1693
1694# ------------------------------------------------------------------------------
1695
1696#Method sk_sp<SkImage> makeRasterImage() const
1697
Cary Clarka560c472017-11-27 10:44:06 -05001698If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1699the pixels fails). Otherwise, it returns the original image.
1700
1701#Return incomplete ##
1702
1703#Example
1704// incomplete
1705##
1706
1707#SeeAlso incomplete
1708
1709#Method ##
1710
1711# ------------------------------------------------------------------------------
1712
1713#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1714 const SkIRect& clipBounds, SkIRect* outSubset,
1715 SkIPoint* offset) const
1716
1717Apply a given image filter to this image, and return the filtered result.
1718The subset represents the active portion of this image. The return value is similarly an
1719SkImage, with an active subset (outSubset). This is usually used with texture-backed
1720images, where the texture may be approx-match and thus larger than the required size.
1721clipBounds constrains the device-space extent of the image, stored in outSubset.
1722offset is storage, set to the amount to translate the result when drawn.
1723If the result image cannot be created, or the result would be transparent black, null
1724is returned, in which case the offset and outSubset parameters should be ignored by the
1725caller.
1726
1727#Param filter incomplete ##
1728#Param subset incomplete ##
1729#Param clipBounds incomplete ##
1730#Param outSubset incomplete ##
1731#Param offset incomplete ##
1732
1733#Return incomplete ##
1734
1735#Example
1736// incomplete
1737##
1738
1739#SeeAlso incomplete
1740
1741#Method ##
1742
1743# ------------------------------------------------------------------------------
1744
Cary Clark61ca7c52018-01-02 11:34:14 -05001745#Struct DeferredTextureImageUsageParams
1746
1747#Code
1748 struct DeferredTextureImageUsageParams {
1749 DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1750 int preScaleMipLevel);
1751 SkMatrix fMatrix;
1752 SkFilterQuality fQuality;
1753 int fPreScaleMipLevel;
1754 };
1755##
1756
1757#Member SkMatrix fMatrix
1758##
1759
1760#Member SkFilterQuality fQuality
1761##
1762
1763#Member int fPreScaleMipLevel
1764##
1765
1766#Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1767 int preScaleMipLevel)
1768
1769#Param matrix incomplete ##
1770#Param quality incomplete ##
1771#Param preScaleMipLevel incomplete ##
1772
1773#Return incomplete ##
1774
1775#Example
1776// incomplete
1777##
1778
1779#SeeAlso incomplete
1780
1781##
1782
1783#Example
1784// incomplete
1785##
1786
1787#SeeAlso incomplete
1788
1789##
1790
1791#Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy,
1792 const DeferredTextureImageUsageParams deferredTextureImageUsageParams[],
1793 int paramCnt,
1794 void* buffer,
1795 SkColorSpace* dstColorSpace = nullptr,
1796 SkColorType dstColorType = kN32_SkColorType) const
1797
1798This method allows clients to capture the data necessary to turn a SkImage into a texture-
1799backed image. If the original image is codec-backed this will decode into a format optimized
1800for the context represented by the proxy. This method is thread safe with respect to the
1801GrContext whence the proxy came. Clients allocate and manage the storage of the deferred
1802texture data and control its lifetime. No cleanup is required, thus it is safe to simply free
1803the memory out from under the data.
1804
1805The same method is used both for getting the size necessary for pre-uploaded texture data
1806and for retrieving the data. The params array represents the set of draws over which to
1807optimize the pre-upload data.
1808
1809When called with a null buffer this returns the size that the client must allocate in order
1810to create deferred texture data for this image (or zero if this is an inappropriate
1811candidate). The buffer allocated by the client should be 8 byte aligned.
1812
1813When buffer is not null this fills in the deferred texture data for this image in the
1814provided buffer (assuming this is an appropriate candidate image and the buffer is
1815appropriately aligned). Upon success the size written is returned, otherwise 0.
1816
1817dstColorSpace is the color space of the surface where this texture will ultimately be used.
1818If the method determines that mip-maps are needed, this helps determine the correct strategy
1819for building them (gamma-correct or not).
1820
1821dstColorType is the color type of the surface where this texture will ultimately be used.
1822This determines the format with which the image will be uploaded to the GPU. If dstColorType
1823does not support color spaces (low bit depth types such as kARGB_4444_SkColorType),
1824then dstColorSpace must be null.
1825
1826#Param contextThreadSafeProxy incomplete ##
1827#Param deferredTextureImageUsageParams incomplete ##
1828#Param paramCnt incomplete ##
1829#Param buffer incomplete ##
1830#Param dstColorSpace incomplete ##
1831#Param dstColorType incomplete ##
1832
1833#Return incomplete ##
1834
1835#Example
1836// incomplete
1837##
1838
1839#SeeAlso incomplete
1840
1841##
1842
1843#Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data,
1844 SkBudgeted budgeted)
1845
1846Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData.
1847The context must be the context that provided the proxy passed to
1848getDeferredTextureImageData.
1849
1850#Param context GPU_Context ##
1851#Param data incomplete ##
1852#Param budgeted incomplete ##
1853
1854#Return incomplete ##
1855
1856#Example
1857// incomplete
1858##
1859
1860#SeeAlso incomplete
1861
1862##
1863
1864# ------------------------------------------------------------------------------
1865
Cary Clarka560c472017-11-27 10:44:06 -05001866#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1867
1868##
1869
1870# ------------------------------------------------------------------------------
1871
1872#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1873 sk_sp<SkImage> image,
1874 GrBackendTexture* backendTexture,
1875 BackendTextureReleaseProc* backendTextureReleaseProc)
1876
1877Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1878GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1879responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1880Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1881to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1882themselves.
1883
1884If image is both texture backed and singly referenced; that is, its only
1885reference was transferred using std::move(): image is returned in backendTexture
1886without conversion or making a copy.
1887
1888If the SkImage is not texture backed, this function will generate a texture with the image's
1889contents and return that.
1890
Cary Clark61ca7c52018-01-02 11:34:14 -05001891#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001892#Param image incomplete ##
1893#Param backendTexture incomplete ##
1894#Param backendTextureReleaseProc incomplete ##
1895
1896#Return incomplete ##
1897
1898#Example
1899// incomplete
1900##
1901
1902#SeeAlso incomplete
1903
1904#Method ##
1905
1906# ------------------------------------------------------------------------------
1907
1908#Enum LegacyBitmapMode
1909
1910#Code
1911 enum LegacyBitmapMode {
1912 kRO_LegacyBitmapMode,
1913 kRW_LegacyBitmapMode,
1914 };
1915##
1916
1917Helper functions to convert to SkBitmap
1918
1919#Const kRO_LegacyBitmapMode 0
1920##
1921#Const kRW_LegacyBitmapMode 1
1922##
1923
1924#Example
1925// incomplete
1926##
1927
1928#SeeAlso incomplete
1929
1930#Enum ##
1931
1932# ------------------------------------------------------------------------------
1933
1934#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
1935
Cary Clark3cd22cc2017-12-01 11:49:58 -05001936Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
1937returned bitmap is read-only and immutable.
1938Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
1939write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05001940
Cary Clark3cd22cc2017-12-01 11:49:58 -05001941#Param bitmap storage for legacy Bitmap ##
1942#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05001943
Cary Clark3cd22cc2017-12-01 11:49:58 -05001944#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05001945
1946#Example
1947// incomplete
1948##
1949
1950#SeeAlso incomplete
1951
1952#Method ##
1953
1954# ------------------------------------------------------------------------------
1955
1956#Method bool isLazyGenerated() const
1957
1958Returns true if Image is backed by an image-generator or other service that creates
1959and caches its pixels or texture on-demand.
1960
Cary Clark2f466242017-12-11 16:03:17 -05001961#Return true if Image is created as needed ##
Cary Clarka560c472017-11-27 10:44:06 -05001962
1963#Example
Cary Clark2f466242017-12-11 16:03:17 -05001964#Height 80
1965#Function
1966class TestImageGenerator : public SkImageGenerator {
1967public:
1968 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
1969 ~TestImageGenerator() override {}
1970protected:
1971 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
1972 const Options& options) override {
1973 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
1974 for (int y = 0; y < info.height(); ++y) {
1975 for (int x = 0; x < info.width(); ++x) {
1976 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
1977 }
1978 }
1979 return true;
1980 }
1981};
1982##
1983void draw(SkCanvas* canvas) {
1984 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
1985 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
1986 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
1987 canvas->scale(8, 8);
1988 canvas->drawImage(image, 0, 0, nullptr);
1989 SkPaint paint;
1990 paint.setTextSize(4);
1991 canvas->drawString(lazy, 2, 5, paint);
1992}
Cary Clarka560c472017-11-27 10:44:06 -05001993##
1994
1995#SeeAlso incomplete
1996
1997#Method ##
1998
1999# ------------------------------------------------------------------------------
2000
2001#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
2002 SkTransferFunctionBehavior premulBehavior) const
2003
2004If target is supported, returns an SkImage in target color space.
2005Otherwise, returns nullptr.
2006This will leave the image as is if it already in target color space.
2007Otherwise, it will convert the pixels from Image color space to target
2008color space. If this->colorSpace() is nullptr, Image color space will be
2009treated as sRGB.
2010
2011If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
2012pixels to a linear space before converting to match destination Color_Type
2013and Color_Space.
2014If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
2015pixels are treated as if they are linear, regardless of how they are encoded.
2016
2017#Param target incomplete ##
2018#Param premulBehavior incomplete ##
2019
2020#Return incomplete ##
2021
2022#Example
2023// incomplete
2024##
2025
2026#SeeAlso incomplete
2027
2028#Method ##
2029
2030#Class SkImage ##
2031
2032#Topic Image ##