blob: 9a2b79e7116ae0ab59c40f05124765eccb00d208 [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 Clark2f466242017-12-11 16:03:17 -05001145Color_Space returned was a parameter to an Image constructor,
1146or was parsed from encoded data. Color_Space may be ignored when
1147drawing Image, and when drawing into Surface constructed with Color_Space.
1148
1149#Return Color_Space in Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001150
1151#Example
1152// incomplete
1153##
1154
1155#SeeAlso incomplete
1156
1157#Method ##
1158
1159# ------------------------------------------------------------------------------
1160
1161#Method sk_sp<SkColorSpace> refColorSpace() const
1162
1163#Return incomplete ##
1164
1165#Example
1166// incomplete
1167##
1168
1169#SeeAlso incomplete
1170
1171#Method ##
1172
1173# ------------------------------------------------------------------------------
1174
1175#Method bool isAlphaOnly() const
1176
Cary Clark2f466242017-12-11 16:03:17 -05001177Returns true if Image pixels represent transparency only. If true, each pixel
1178is packed in 8 bits as defined by kAlpha_8_SkColorType.
Cary Clarka560c472017-11-27 10:44:06 -05001179
Cary Clark2f466242017-12-11 16:03:17 -05001180#Return true if pixels represent a transparency mask ##
Cary Clarka560c472017-11-27 10:44:06 -05001181
1182#Example
1183// incomplete
1184##
1185
1186#SeeAlso incomplete
1187
1188#Method ##
1189
1190# ------------------------------------------------------------------------------
1191
1192#Method bool isOpaque() const
1193
Cary Clark2f466242017-12-11 16:03:17 -05001194Returns if all pixels ignore any Alpha value and are treated as fully opaque.
1195
1196#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clarka560c472017-11-27 10:44:06 -05001197
1198#Example
1199// incomplete
1200##
1201
1202#SeeAlso incomplete
1203
1204#Method ##
1205
1206# ------------------------------------------------------------------------------
1207
1208#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
1209 const SkMatrix* localMatrix = nullptr) const
1210
1211#Param tileMode1 incomplete ##
1212#Param tileMode2 incomplete ##
1213#Param localMatrix incomplete ##
1214
1215#Return incomplete ##
1216
1217#Example
1218// incomplete
1219##
1220
1221#SeeAlso incomplete
1222
1223#Method ##
1224
1225# ------------------------------------------------------------------------------
1226
1227#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
1228
1229Helper version of makeShader() that specifies SkShader::kClamp_TileMode.
1230
1231#Param localMatrix incomplete ##
1232
1233#Return incomplete ##
1234
1235#Example
1236// incomplete
1237##
1238
1239#SeeAlso incomplete
1240
1241#Method ##
1242
1243# ------------------------------------------------------------------------------
1244
1245#Method bool peekPixels(SkPixmap* pixmap) const
1246
1247If the image has direct access to its pixels (i.e. they are in local RAM)
1248return true, and if not null, return in the pixmap parameter the info about the
1249images pixels.
1250On failure, return false and ignore the pixmap parameter.
1251
1252#Param pixmap incomplete ##
1253
1254#Return incomplete ##
1255
1256#Example
1257// incomplete
1258##
1259
1260#SeeAlso incomplete
1261
1262#Method ##
1263
1264# ------------------------------------------------------------------------------
1265
1266#Method GrTexture* getTexture() const
1267
Cary Clark2f466242017-12-11 16:03:17 -05001268Deprecated.
1269
1270#Deprecated
1271##
1272
Cary Clarka560c472017-11-27 10:44:06 -05001273#Private
1274currently used by Canvas2DLayerBridge in Chromium.
1275##
1276
Cary Clarka560c472017-11-27 10:44:06 -05001277#Method ##
1278
1279# ------------------------------------------------------------------------------
1280
1281#Method bool isTextureBacked() const
1282
1283Returns true if the image is texture backed.
1284
1285#Return incomplete ##
1286
1287#Example
1288// incomplete
1289##
1290
1291#SeeAlso incomplete
1292
1293#Method ##
1294
1295# ------------------------------------------------------------------------------
1296
1297#Method bool isValid(GrContext* context) const
1298
1299Returns true if Image can be drawn. If context
1300is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image
1301draws on GPU_Surface associated with context.
1302
1303Texture-backed images may become invalid if their underlying GrContext is abandoned. Some
1304generator-backed images may be invalid for CPU and/or GPU.
1305
Cary Clark61ca7c52018-01-02 11:34:14 -05001306#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001307
1308#Return incomplete ##
1309
1310#Example
1311// incomplete
1312##
1313
1314#SeeAlso incomplete
1315
1316#Method ##
1317
1318# ------------------------------------------------------------------------------
1319
1320#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
1321 GrSurfaceOrigin* origin = nullptr) const
1322
Cary Clark2f466242017-12-11 16:03:17 -05001323Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true,
1324complete deferred I/O operations.
Cary Clarka560c472017-11-27 10:44:06 -05001325
Cary Clark2f466242017-12-11 16:03:17 -05001326If origin in not nullptr, copies location of content drawn into Image.
Cary Clarka560c472017-11-27 10:44:06 -05001327
Cary Clark2f466242017-12-11 16:03:17 -05001328#Param flushPendingGrContextIO flag to flush outstanding requests ##
1329#Param origin storage for one of: kTopLeft_GrSurfaceOrigin,
1330 kBottomLeft_GrSurfaceOrigin; or nullptr
1331##
1332
1333#Return back-end API texture handle ##
Cary Clarka560c472017-11-27 10:44:06 -05001334
1335#Example
Cary Clark2f466242017-12-11 16:03:17 -05001336#Image 3
1337#Platform gpu
1338GrContext* context = canvas->getGrContext();
1339if (!context) {
1340 return;
1341}
1342SkPaint paint;
1343paint.setAntiAlias(true);
1344SkString str;
1345int y = 0;
1346for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
1347 sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
1348 backEndTexture, origin, kPremul_SkAlphaType, nullptr));
1349 GrSurfaceOrigin readBackOrigin;
1350 GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
1351 str.printf("readBackHandle: %x", readBackHandle);
1352 canvas->drawString(str, 5, y += 20, paint);
1353 str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft");
1354 canvas->drawString(str, 5, y += 20, paint);
1355}
Cary Clarka560c472017-11-27 10:44:06 -05001356##
1357
1358#SeeAlso incomplete
1359
1360#Method ##
1361
1362# ------------------------------------------------------------------------------
1363
1364#Enum CachingHint
1365
1366#Code
1367 enum CachingHint {
1368 kAllow_CachingHint,
1369 kDisallow_CachingHint,
1370 };
1371##
1372
1373Hints to image calls where the system might cache computed intermediates (e.g. the results
1374of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
1375behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
1376
1377#Const kAllow_CachingHint 0
1378##
1379#Const kDisallow_CachingHint 1
1380##
1381
1382#Example
1383// incomplete
1384##
1385
1386#SeeAlso incomplete
1387
1388#Enum ##
1389
1390# ------------------------------------------------------------------------------
1391
1392#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1393 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
1394
1395Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
1396converting them into the requested format (dstInfo). The image pixels are read
1397starting at the specified (srcX, srcY) location.
1398dstInfo and (srcX, srcY) offset specifies a source rectangle:
1399#Code
1400SkRect srcR;
1401srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
1402##
1403
1404The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
1405then we have two sets of pixels (of equal size). Replace dstPixels with the
1406corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
1407(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
1408This call can fail, returning false, for several reasons:
1409if source rectangle does not intersect the image bounds;
1410if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
1411
1412#Param dstInfo incomplete ##
1413#Param dstPixels incomplete ##
1414#Param dstRowBytes incomplete ##
1415#Param srcX incomplete ##
1416#Param srcY incomplete ##
1417#Param cachingHint incomplete ##
1418
1419#Return incomplete ##
1420
1421#Example
1422// incomplete
1423##
1424
1425#SeeAlso incomplete
1426
1427#Method ##
1428
1429# ------------------------------------------------------------------------------
1430
1431#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1432 CachingHint cachingHint = kAllow_CachingHint) const
1433
1434#Param dst incomplete ##
1435#Param srcX incomplete ##
1436#Param srcY incomplete ##
1437#Param cachingHint incomplete ##
1438
1439#Return incomplete ##
1440
1441#Example
1442// incomplete
1443##
1444
1445#SeeAlso incomplete
1446
1447#Method ##
1448
1449# ------------------------------------------------------------------------------
1450
1451#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1452 CachingHint cachingHint = kAllow_CachingHint) const
1453
1454Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1455If the conversion cannot be performed, false is returned.
1456If dst dimensions differ from Image dimensions, Image is scaled, applying
1457filterQuality.
1458
1459#Param dst incomplete ##
1460#Param filterQuality incomplete ##
1461#Param cachingHint incomplete ##
1462
1463#Return incomplete ##
1464
1465#Example
1466// incomplete
1467##
1468
1469#SeeAlso incomplete
1470
1471#Method ##
1472
1473# ------------------------------------------------------------------------------
1474
1475#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1476
Cary Clark2f466242017-12-11 16:03:17 -05001477Encodes Image pixels, returning result as SkData.
1478
1479Returns nullptr if encoding fails, or encodedImageFormat is not supported.
Cary Clarka560c472017-11-27 10:44:06 -05001480
1481#Param encodedImageFormat incomplete ##
1482#Param quality incomplete ##
1483
Cary Clark2f466242017-12-11 16:03:17 -05001484#Return encoded Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001485
1486#Example
1487// incomplete
1488##
1489
1490#SeeAlso incomplete
1491
1492#Method ##
1493
1494# ------------------------------------------------------------------------------
1495
Cary Clark61ca7c52018-01-02 11:34:14 -05001496#Method sk_sp<SkData> encodeToData() const
Cary Clarka560c472017-11-27 10:44:06 -05001497
1498Encodes Image and returns result as SkData. Will reuse existing encoded data
Cary Clark61ca7c52018-01-02 11:34:14 -05001499if present, as returned by refEncodedData. If encoded data is missing or invalid,
1500Image is encoded as PNG.
Cary Clarka560c472017-11-27 10:44:06 -05001501
1502Returns nullptr if existing encoded data is missing or invalid and
1503encoding fails.
1504
Cary Clarka560c472017-11-27 10:44:06 -05001505#Return incomplete ##
1506
1507#Example
1508// incomplete
1509##
1510
1511#SeeAlso incomplete
1512
1513#Method ##
1514
1515# ------------------------------------------------------------------------------
1516
1517#Method sk_sp<SkData> refEncodedData() const
1518
1519If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1520as SkData. If the image does not already has its contents in encoded form, return nullptr.
1521
1522To force the image to return its contents as encoded data, call encodeToData.
1523
1524#Return incomplete ##
1525
1526#Example
1527// incomplete
1528##
1529
1530#SeeAlso incomplete
1531
1532#Method ##
1533
1534# ------------------------------------------------------------------------------
1535
1536#Method const char* toString(SkString* string) const
1537
1538#Param string incomplete ##
1539
1540#Return incomplete ##
1541
1542#Example
1543// incomplete
1544##
1545
1546#SeeAlso incomplete
1547
1548#Method ##
1549
1550# ------------------------------------------------------------------------------
1551
1552#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
1553
1554Return a new image that is a subset of this image. The underlying implementation may
1555share the pixels, or it may make a copy.
1556If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1557nullptr will be returned.
1558
1559#Param subset incomplete ##
1560
1561#Return incomplete ##
1562
1563#Example
1564// incomplete
1565##
1566
1567#SeeAlso incomplete
1568
1569#Method ##
1570
1571# ------------------------------------------------------------------------------
1572
1573#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1574
1575Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1576with surfaces that have the supplied destination color space. If no transformation is
1577required, the returned image may be the same as this image. If this image is from a
1578different GrContext, this will fail.
1579
Cary Clark61ca7c52018-01-02 11:34:14 -05001580#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001581#Param dstColorSpace incomplete ##
1582
1583#Return incomplete ##
1584
1585#Example
1586// incomplete
1587##
1588
1589#SeeAlso incomplete
1590
1591#Method ##
1592
1593# ------------------------------------------------------------------------------
1594
1595#Method sk_sp<SkImage> makeNonTextureImage() const
1596
Cary Clark61ca7c52018-01-02 11:34:14 -05001597Creates raster Image if Image contains GPU_Texture and raster Image , this will make a raster copy of it (or nullptr if reading back
1598the pixels fails). Otherwise, it returns the original image.
1599
1600#Return incomplete ##
1601
1602#Example
1603// incomplete
1604##
1605
1606#SeeAlso incomplete
1607
1608#Method ##
1609
1610# ------------------------------------------------------------------------------
1611
1612#Method sk_sp<SkImage> makeRasterImage() const
1613
Cary Clarka560c472017-11-27 10:44:06 -05001614If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1615the pixels fails). Otherwise, it returns the original image.
1616
1617#Return incomplete ##
1618
1619#Example
1620// incomplete
1621##
1622
1623#SeeAlso incomplete
1624
1625#Method ##
1626
1627# ------------------------------------------------------------------------------
1628
1629#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1630 const SkIRect& clipBounds, SkIRect* outSubset,
1631 SkIPoint* offset) const
1632
1633Apply a given image filter to this image, and return the filtered result.
1634The subset represents the active portion of this image. The return value is similarly an
1635SkImage, with an active subset (outSubset). This is usually used with texture-backed
1636images, where the texture may be approx-match and thus larger than the required size.
1637clipBounds constrains the device-space extent of the image, stored in outSubset.
1638offset is storage, set to the amount to translate the result when drawn.
1639If the result image cannot be created, or the result would be transparent black, null
1640is returned, in which case the offset and outSubset parameters should be ignored by the
1641caller.
1642
1643#Param filter incomplete ##
1644#Param subset incomplete ##
1645#Param clipBounds incomplete ##
1646#Param outSubset incomplete ##
1647#Param offset incomplete ##
1648
1649#Return incomplete ##
1650
1651#Example
1652// incomplete
1653##
1654
1655#SeeAlso incomplete
1656
1657#Method ##
1658
1659# ------------------------------------------------------------------------------
1660
Cary Clark61ca7c52018-01-02 11:34:14 -05001661#Struct DeferredTextureImageUsageParams
1662
1663#Code
1664 struct DeferredTextureImageUsageParams {
1665 DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1666 int preScaleMipLevel);
1667 SkMatrix fMatrix;
1668 SkFilterQuality fQuality;
1669 int fPreScaleMipLevel;
1670 };
1671##
1672
1673#Member SkMatrix fMatrix
1674##
1675
1676#Member SkFilterQuality fQuality
1677##
1678
1679#Member int fPreScaleMipLevel
1680##
1681
1682#Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1683 int preScaleMipLevel)
1684
1685#Param matrix incomplete ##
1686#Param quality incomplete ##
1687#Param preScaleMipLevel incomplete ##
1688
1689#Return incomplete ##
1690
1691#Example
1692// incomplete
1693##
1694
1695#SeeAlso incomplete
1696
1697##
1698
1699#Example
1700// incomplete
1701##
1702
1703#SeeAlso incomplete
1704
1705##
1706
1707#Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy,
1708 const DeferredTextureImageUsageParams deferredTextureImageUsageParams[],
1709 int paramCnt,
1710 void* buffer,
1711 SkColorSpace* dstColorSpace = nullptr,
1712 SkColorType dstColorType = kN32_SkColorType) const
1713
1714This method allows clients to capture the data necessary to turn a SkImage into a texture-
1715backed image. If the original image is codec-backed this will decode into a format optimized
1716for the context represented by the proxy. This method is thread safe with respect to the
1717GrContext whence the proxy came. Clients allocate and manage the storage of the deferred
1718texture data and control its lifetime. No cleanup is required, thus it is safe to simply free
1719the memory out from under the data.
1720
1721The same method is used both for getting the size necessary for pre-uploaded texture data
1722and for retrieving the data. The params array represents the set of draws over which to
1723optimize the pre-upload data.
1724
1725When called with a null buffer this returns the size that the client must allocate in order
1726to create deferred texture data for this image (or zero if this is an inappropriate
1727candidate). The buffer allocated by the client should be 8 byte aligned.
1728
1729When buffer is not null this fills in the deferred texture data for this image in the
1730provided buffer (assuming this is an appropriate candidate image and the buffer is
1731appropriately aligned). Upon success the size written is returned, otherwise 0.
1732
1733dstColorSpace is the color space of the surface where this texture will ultimately be used.
1734If the method determines that mip-maps are needed, this helps determine the correct strategy
1735for building them (gamma-correct or not).
1736
1737dstColorType is the color type of the surface where this texture will ultimately be used.
1738This determines the format with which the image will be uploaded to the GPU. If dstColorType
1739does not support color spaces (low bit depth types such as kARGB_4444_SkColorType),
1740then dstColorSpace must be null.
1741
1742#Param contextThreadSafeProxy incomplete ##
1743#Param deferredTextureImageUsageParams incomplete ##
1744#Param paramCnt incomplete ##
1745#Param buffer incomplete ##
1746#Param dstColorSpace incomplete ##
1747#Param dstColorType incomplete ##
1748
1749#Return incomplete ##
1750
1751#Example
1752// incomplete
1753##
1754
1755#SeeAlso incomplete
1756
1757##
1758
1759#Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data,
1760 SkBudgeted budgeted)
1761
1762Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData.
1763The context must be the context that provided the proxy passed to
1764getDeferredTextureImageData.
1765
1766#Param context GPU_Context ##
1767#Param data incomplete ##
1768#Param budgeted incomplete ##
1769
1770#Return incomplete ##
1771
1772#Example
1773// incomplete
1774##
1775
1776#SeeAlso incomplete
1777
1778##
1779
1780# ------------------------------------------------------------------------------
1781
Cary Clarka560c472017-11-27 10:44:06 -05001782#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1783
1784##
1785
1786# ------------------------------------------------------------------------------
1787
1788#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1789 sk_sp<SkImage> image,
1790 GrBackendTexture* backendTexture,
1791 BackendTextureReleaseProc* backendTextureReleaseProc)
1792
1793Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1794GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1795responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1796Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1797to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1798themselves.
1799
1800If image is both texture backed and singly referenced; that is, its only
1801reference was transferred using std::move(): image is returned in backendTexture
1802without conversion or making a copy.
1803
1804If the SkImage is not texture backed, this function will generate a texture with the image's
1805contents and return that.
1806
Cary Clark61ca7c52018-01-02 11:34:14 -05001807#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001808#Param image incomplete ##
1809#Param backendTexture incomplete ##
1810#Param backendTextureReleaseProc incomplete ##
1811
1812#Return incomplete ##
1813
1814#Example
1815// incomplete
1816##
1817
1818#SeeAlso incomplete
1819
1820#Method ##
1821
1822# ------------------------------------------------------------------------------
1823
1824#Enum LegacyBitmapMode
1825
1826#Code
1827 enum LegacyBitmapMode {
1828 kRO_LegacyBitmapMode,
1829 kRW_LegacyBitmapMode,
1830 };
1831##
1832
1833Helper functions to convert to SkBitmap
1834
1835#Const kRO_LegacyBitmapMode 0
1836##
1837#Const kRW_LegacyBitmapMode 1
1838##
1839
1840#Example
1841// incomplete
1842##
1843
1844#SeeAlso incomplete
1845
1846#Enum ##
1847
1848# ------------------------------------------------------------------------------
1849
1850#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
1851
Cary Clark3cd22cc2017-12-01 11:49:58 -05001852Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
1853returned bitmap is read-only and immutable.
1854Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
1855write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05001856
Cary Clark3cd22cc2017-12-01 11:49:58 -05001857#Param bitmap storage for legacy Bitmap ##
1858#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05001859
Cary Clark3cd22cc2017-12-01 11:49:58 -05001860#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05001861
1862#Example
1863// incomplete
1864##
1865
1866#SeeAlso incomplete
1867
1868#Method ##
1869
1870# ------------------------------------------------------------------------------
1871
1872#Method bool isLazyGenerated() const
1873
1874Returns true if Image is backed by an image-generator or other service that creates
1875and caches its pixels or texture on-demand.
1876
Cary Clark2f466242017-12-11 16:03:17 -05001877#Return true if Image is created as needed ##
Cary Clarka560c472017-11-27 10:44:06 -05001878
1879#Example
Cary Clark2f466242017-12-11 16:03:17 -05001880#Height 80
1881#Function
1882class TestImageGenerator : public SkImageGenerator {
1883public:
1884 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
1885 ~TestImageGenerator() override {}
1886protected:
1887 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
1888 const Options& options) override {
1889 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
1890 for (int y = 0; y < info.height(); ++y) {
1891 for (int x = 0; x < info.width(); ++x) {
1892 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
1893 }
1894 }
1895 return true;
1896 }
1897};
1898##
1899void draw(SkCanvas* canvas) {
1900 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
1901 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
1902 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
1903 canvas->scale(8, 8);
1904 canvas->drawImage(image, 0, 0, nullptr);
1905 SkPaint paint;
1906 paint.setTextSize(4);
1907 canvas->drawString(lazy, 2, 5, paint);
1908}
Cary Clarka560c472017-11-27 10:44:06 -05001909##
1910
1911#SeeAlso incomplete
1912
1913#Method ##
1914
1915# ------------------------------------------------------------------------------
1916
1917#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
1918 SkTransferFunctionBehavior premulBehavior) const
1919
1920If target is supported, returns an SkImage in target color space.
1921Otherwise, returns nullptr.
1922This will leave the image as is if it already in target color space.
1923Otherwise, it will convert the pixels from Image color space to target
1924color space. If this->colorSpace() is nullptr, Image color space will be
1925treated as sRGB.
1926
1927If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
1928pixels to a linear space before converting to match destination Color_Type
1929and Color_Space.
1930If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
1931pixels are treated as if they are linear, regardless of how they are encoded.
1932
1933#Param target incomplete ##
1934#Param premulBehavior incomplete ##
1935
1936#Return incomplete ##
1937
1938#Example
1939// incomplete
1940##
1941
1942#SeeAlso incomplete
1943
1944#Method ##
1945
1946#Class SkImage ##
1947
1948#Topic Image ##