blob: 0d9c98b211eb81946b56bbd9a504fb0fef4516f2 [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
Cary Clarkf5404bb2018-01-05 12:10:09 -05001323#SeeAlso scalePixels
Cary Clarka560c472017-11-27 10:44:06 -05001324
1325#Method ##
1326
1327# ------------------------------------------------------------------------------
1328
1329#Method bool peekPixels(SkPixmap* pixmap) const
1330
Cary Clarkf5404bb2018-01-05 12:10:09 -05001331Copies Image pixel address, row bytes, and Image_Info to pixmap, if address
1332is available, and returns true. If pixel address is not available, return
1333false and leave pixmap unchanged.
Cary Clarka560c472017-11-27 10:44:06 -05001334
Cary Clarkf5404bb2018-01-05 12:10:09 -05001335#Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ##
Cary Clarka560c472017-11-27 10:44:06 -05001336
Cary Clarkf5404bb2018-01-05 12:10:09 -05001337#Return true if Image has direct access to pixels ##
Cary Clarka560c472017-11-27 10:44:06 -05001338
1339#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -05001340 SkBitmap bitmap;
1341 bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11));
1342 SkCanvas offscreen(bitmap);
1343 offscreen.clear(SK_ColorWHITE);
1344 SkPaint paint;
1345 offscreen.drawString("%", 1, 10, paint);
1346 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
1347 SkPixmap pixmap;
1348 if (image->peekPixels(&pixmap)) {
1349 const SkPMColor* pixels = pixmap.addr32();
1350 SkPMColor pmWhite = pixels[0];
1351 for (int y = 0; y < image->height(); ++y) {
1352 for (int x = 0; x < image->width(); ++x) {
1353 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
1354 }
1355 SkDebugf("\n");
1356 }
1357 }
1358#StdOut
1359------------
1360--xx----x---
1361-x--x--x----
1362-x--x--x----
1363-x--x-x-----
1364--xx-xx-xx--
1365-----x-x--x-
1366----x--x--x-
1367----x--x--x-
1368---x----xx--
1369------------
1370##
Cary Clarka560c472017-11-27 10:44:06 -05001371##
1372
Cary Clarkf5404bb2018-01-05 12:10:09 -05001373#SeeAlso readPixels
Cary Clarka560c472017-11-27 10:44:06 -05001374
1375#Method ##
1376
1377# ------------------------------------------------------------------------------
1378
1379#Method GrTexture* getTexture() const
1380
Cary Clark2f466242017-12-11 16:03:17 -05001381Deprecated.
1382
1383#Deprecated
1384##
1385
Cary Clarka560c472017-11-27 10:44:06 -05001386#Private
Cary Clarkf5404bb2018-01-05 12:10:09 -05001387Currently used by Canvas2DLayerBridge in Chromium.
Cary Clarka560c472017-11-27 10:44:06 -05001388##
1389
Cary Clarka560c472017-11-27 10:44:06 -05001390#Method ##
1391
1392# ------------------------------------------------------------------------------
1393
1394#Method bool isTextureBacked() const
1395
Cary Clarkf5404bb2018-01-05 12:10:09 -05001396Returns true the contents of Image was created on or uploaded to GPU memory,
1397and is available as a GPU_Texture.
Cary Clarka560c472017-11-27 10:44:06 -05001398
Cary Clarkf5404bb2018-01-05 12:10:09 -05001399#Return true if Image is a GPU_Texture ##
Cary Clarka560c472017-11-27 10:44:06 -05001400
1401#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -05001402#Image 5
1403#Platform gpu
1404auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
1405 if (nullptr == image) {
1406 return;
1407 }
1408 SkPaint paint;
1409 paint.setAntiAlias(true);
1410 paint.setTextAlign(SkPaint::kCenter_Align);
1411 canvas->drawImage(image, 0, 0);
1412 canvas->drawString(label, image->width() / 2, image->height() / 4, paint);
1413 canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture",
1414 image->width() / 2, image->height() * 3 / 4, paint);
1415};
1416sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1417sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
1418 kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr));
1419drawImage(image, "image");
1420canvas->translate(image->width(), 0);
1421drawImage(bitmapImage, "source");
1422canvas->translate(-image->width(), image->height());
1423drawImage(textureImage, "backEndTexture");
Cary Clarka560c472017-11-27 10:44:06 -05001424##
1425
Cary Clarkf5404bb2018-01-05 12:10:09 -05001426#SeeAlso MakeFromTexture isValid
Cary Clarka560c472017-11-27 10:44:06 -05001427
1428#Method ##
1429
1430# ------------------------------------------------------------------------------
1431
1432#Method bool isValid(GrContext* context) const
1433
Cary Clarkf5404bb2018-01-05 12:10:09 -05001434Returns true if Image can be drawn on either Raster_Surface or GPU_Surface.
1435If context is nullptr, tests if Image draws on Raster_Surface;
1436otherwise, tests if Image draws on GPU_Surface associated with context.
Cary Clarka560c472017-11-27 10:44:06 -05001437
Cary Clarkf5404bb2018-01-05 12:10:09 -05001438Image backed by GPU_Texture may become invalid if associated GrContext is
1439invalid. Lazy_Image may be invalid and may not draw to Raster_Surface or
1440GPU_Surface or both.
Cary Clarka560c472017-11-27 10:44:06 -05001441
Cary Clark61ca7c52018-01-02 11:34:14 -05001442#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001443
Cary Clarkf5404bb2018-01-05 12:10:09 -05001444#Return true if Image can be drawn ##
Cary Clarka560c472017-11-27 10:44:06 -05001445
1446#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -05001447#Image 5
1448#Platform gpu
1449auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
1450 if (nullptr == image) {
1451 return;
1452 }
1453 SkPaint paint;
1454 paint.setAntiAlias(true);
1455 paint.setTextAlign(SkPaint::kCenter_Align);
1456 canvas->drawImage(image, 0, 0);
1457 canvas->drawString(label, image->width() / 2, image->height() / 4, paint);
1458 if (canvas->getGrContext()) {
1459 canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" :
1460 "not valid on GPU", image->width() / 2, image->height() * 5 / 8, paint);
1461 }
1462 canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" :
1463 "not valid on CPU", image->width() / 2, image->height() * 7 / 8, paint);
1464};
1465sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1466sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
1467 kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr));
1468drawImage(image, "image");
1469canvas->translate(image->width(), 0);
1470drawImage(bitmapImage, "source");
1471canvas->translate(-image->width(), image->height());
1472drawImage(textureImage, "backEndTexture");
Cary Clarka560c472017-11-27 10:44:06 -05001473##
1474
Cary Clarkf5404bb2018-01-05 12:10:09 -05001475#SeeAlso isTextureBacked isLazyGenerated
Cary Clarka560c472017-11-27 10:44:06 -05001476
1477#Method ##
1478
1479# ------------------------------------------------------------------------------
1480
1481#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
1482 GrSurfaceOrigin* origin = nullptr) const
1483
Cary Clark2f466242017-12-11 16:03:17 -05001484Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true,
1485complete deferred I/O operations.
Cary Clarka560c472017-11-27 10:44:06 -05001486
Cary Clark2f466242017-12-11 16:03:17 -05001487If origin in not nullptr, copies location of content drawn into Image.
Cary Clarka560c472017-11-27 10:44:06 -05001488
Cary Clark2f466242017-12-11 16:03:17 -05001489#Param flushPendingGrContextIO flag to flush outstanding requests ##
1490#Param origin storage for one of: kTopLeft_GrSurfaceOrigin,
1491 kBottomLeft_GrSurfaceOrigin; or nullptr
1492##
1493
1494#Return back-end API texture handle ##
Cary Clarka560c472017-11-27 10:44:06 -05001495
1496#Example
Cary Clark2f466242017-12-11 16:03:17 -05001497#Image 3
1498#Platform gpu
1499GrContext* context = canvas->getGrContext();
1500if (!context) {
1501 return;
1502}
1503SkPaint paint;
1504paint.setAntiAlias(true);
1505SkString str;
1506int y = 0;
1507for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
1508 sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
1509 backEndTexture, origin, kPremul_SkAlphaType, nullptr));
1510 GrSurfaceOrigin readBackOrigin;
1511 GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
1512 str.printf("readBackHandle: %x", readBackHandle);
1513 canvas->drawString(str, 5, y += 20, paint);
1514 str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft");
1515 canvas->drawString(str, 5, y += 20, paint);
1516}
Cary Clarka560c472017-11-27 10:44:06 -05001517##
1518
1519#SeeAlso incomplete
1520
1521#Method ##
1522
1523# ------------------------------------------------------------------------------
1524
1525#Enum CachingHint
1526
1527#Code
1528 enum CachingHint {
1529 kAllow_CachingHint,
1530 kDisallow_CachingHint,
1531 };
1532##
1533
1534Hints to image calls where the system might cache computed intermediates (e.g. the results
1535of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
1536behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
1537
1538#Const kAllow_CachingHint 0
1539##
1540#Const kDisallow_CachingHint 1
1541##
1542
1543#Example
1544// incomplete
1545##
1546
1547#SeeAlso incomplete
1548
1549#Enum ##
1550
1551# ------------------------------------------------------------------------------
1552
1553#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1554 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
1555
1556Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
1557converting them into the requested format (dstInfo). The image pixels are read
1558starting at the specified (srcX, srcY) location.
1559dstInfo and (srcX, srcY) offset specifies a source rectangle:
1560#Code
1561SkRect srcR;
1562srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
1563##
1564
1565The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
1566then we have two sets of pixels (of equal size). Replace dstPixels with the
1567corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
1568(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
1569This call can fail, returning false, for several reasons:
1570if source rectangle does not intersect the image bounds;
1571if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
1572
1573#Param dstInfo incomplete ##
1574#Param dstPixels incomplete ##
1575#Param dstRowBytes incomplete ##
1576#Param srcX incomplete ##
1577#Param srcY incomplete ##
1578#Param cachingHint incomplete ##
1579
1580#Return incomplete ##
1581
1582#Example
1583// incomplete
1584##
1585
1586#SeeAlso incomplete
1587
1588#Method ##
1589
1590# ------------------------------------------------------------------------------
1591
1592#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1593 CachingHint cachingHint = kAllow_CachingHint) const
1594
1595#Param dst incomplete ##
1596#Param srcX incomplete ##
1597#Param srcY incomplete ##
1598#Param cachingHint incomplete ##
1599
1600#Return incomplete ##
1601
1602#Example
1603// incomplete
1604##
1605
1606#SeeAlso incomplete
1607
1608#Method ##
1609
1610# ------------------------------------------------------------------------------
1611
1612#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1613 CachingHint cachingHint = kAllow_CachingHint) const
1614
1615Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1616If the conversion cannot be performed, false is returned.
1617If dst dimensions differ from Image dimensions, Image is scaled, applying
1618filterQuality.
1619
1620#Param dst incomplete ##
1621#Param filterQuality incomplete ##
1622#Param cachingHint 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<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1637
Cary Clark2f466242017-12-11 16:03:17 -05001638Encodes Image pixels, returning result as SkData.
1639
1640Returns nullptr if encoding fails, or encodedImageFormat is not supported.
Cary Clarka560c472017-11-27 10:44:06 -05001641
1642#Param encodedImageFormat incomplete ##
1643#Param quality incomplete ##
1644
Cary Clark2f466242017-12-11 16:03:17 -05001645#Return encoded Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001646
1647#Example
1648// incomplete
1649##
1650
1651#SeeAlso incomplete
1652
1653#Method ##
1654
1655# ------------------------------------------------------------------------------
1656
Cary Clark61ca7c52018-01-02 11:34:14 -05001657#Method sk_sp<SkData> encodeToData() const
Cary Clarka560c472017-11-27 10:44:06 -05001658
1659Encodes Image and returns result as SkData. Will reuse existing encoded data
Cary Clark61ca7c52018-01-02 11:34:14 -05001660if present, as returned by refEncodedData. If encoded data is missing or invalid,
1661Image is encoded as PNG.
Cary Clarka560c472017-11-27 10:44:06 -05001662
1663Returns nullptr if existing encoded data is missing or invalid and
1664encoding fails.
1665
Cary Clarka560c472017-11-27 10:44:06 -05001666#Return incomplete ##
1667
1668#Example
1669// incomplete
1670##
1671
1672#SeeAlso incomplete
1673
1674#Method ##
1675
1676# ------------------------------------------------------------------------------
1677
1678#Method sk_sp<SkData> refEncodedData() const
1679
1680If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1681as SkData. If the image does not already has its contents in encoded form, return nullptr.
1682
1683To force the image to return its contents as encoded data, call encodeToData.
1684
1685#Return incomplete ##
1686
1687#Example
1688// incomplete
1689##
1690
1691#SeeAlso incomplete
1692
1693#Method ##
1694
1695# ------------------------------------------------------------------------------
1696
1697#Method const char* toString(SkString* string) const
1698
1699#Param string incomplete ##
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> makeSubset(const SkIRect& subset) const
1714
1715Return a new image that is a subset of this image. The underlying implementation may
1716share the pixels, or it may make a copy.
1717If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1718nullptr will be returned.
1719
1720#Param subset incomplete ##
1721
1722#Return incomplete ##
1723
1724#Example
1725// incomplete
1726##
1727
1728#SeeAlso incomplete
1729
1730#Method ##
1731
1732# ------------------------------------------------------------------------------
1733
1734#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1735
1736Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1737with surfaces that have the supplied destination color space. If no transformation is
1738required, the returned image may be the same as this image. If this image is from a
1739different GrContext, this will fail.
1740
Cary Clark61ca7c52018-01-02 11:34:14 -05001741#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001742#Param dstColorSpace incomplete ##
1743
1744#Return incomplete ##
1745
1746#Example
1747// incomplete
1748##
1749
1750#SeeAlso incomplete
1751
1752#Method ##
1753
1754# ------------------------------------------------------------------------------
1755
1756#Method sk_sp<SkImage> makeNonTextureImage() const
1757
Cary Clark61ca7c52018-01-02 11:34:14 -05001758Creates raster Image if Image contains GPU_Texture and raster Image , this will make a raster copy of it (or nullptr if reading back
1759the pixels fails). Otherwise, it returns the original image.
1760
1761#Return incomplete ##
1762
1763#Example
1764// incomplete
1765##
1766
1767#SeeAlso incomplete
1768
1769#Method ##
1770
1771# ------------------------------------------------------------------------------
1772
1773#Method sk_sp<SkImage> makeRasterImage() const
1774
Cary Clarka560c472017-11-27 10:44:06 -05001775If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1776the pixels fails). Otherwise, it returns the original image.
1777
1778#Return incomplete ##
1779
1780#Example
1781// incomplete
1782##
1783
1784#SeeAlso incomplete
1785
1786#Method ##
1787
1788# ------------------------------------------------------------------------------
1789
1790#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1791 const SkIRect& clipBounds, SkIRect* outSubset,
1792 SkIPoint* offset) const
1793
1794Apply a given image filter to this image, and return the filtered result.
1795The subset represents the active portion of this image. The return value is similarly an
1796SkImage, with an active subset (outSubset). This is usually used with texture-backed
1797images, where the texture may be approx-match and thus larger than the required size.
1798clipBounds constrains the device-space extent of the image, stored in outSubset.
1799offset is storage, set to the amount to translate the result when drawn.
1800If the result image cannot be created, or the result would be transparent black, null
1801is returned, in which case the offset and outSubset parameters should be ignored by the
1802caller.
1803
1804#Param filter incomplete ##
1805#Param subset incomplete ##
1806#Param clipBounds incomplete ##
1807#Param outSubset incomplete ##
1808#Param offset incomplete ##
1809
1810#Return incomplete ##
1811
1812#Example
1813// incomplete
1814##
1815
1816#SeeAlso incomplete
1817
1818#Method ##
1819
1820# ------------------------------------------------------------------------------
1821
Cary Clark61ca7c52018-01-02 11:34:14 -05001822#Struct DeferredTextureImageUsageParams
1823
1824#Code
1825 struct DeferredTextureImageUsageParams {
1826 DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1827 int preScaleMipLevel);
1828 SkMatrix fMatrix;
1829 SkFilterQuality fQuality;
1830 int fPreScaleMipLevel;
1831 };
1832##
1833
1834#Member SkMatrix fMatrix
1835##
1836
1837#Member SkFilterQuality fQuality
1838##
1839
1840#Member int fPreScaleMipLevel
1841##
1842
1843#Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
1844 int preScaleMipLevel)
1845
1846#Param matrix incomplete ##
1847#Param quality incomplete ##
1848#Param preScaleMipLevel incomplete ##
1849
1850#Return incomplete ##
1851
1852#Example
1853// incomplete
1854##
1855
1856#SeeAlso incomplete
1857
1858##
1859
1860#Example
1861// incomplete
1862##
1863
1864#SeeAlso incomplete
1865
1866##
1867
1868#Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy,
1869 const DeferredTextureImageUsageParams deferredTextureImageUsageParams[],
1870 int paramCnt,
1871 void* buffer,
1872 SkColorSpace* dstColorSpace = nullptr,
1873 SkColorType dstColorType = kN32_SkColorType) const
1874
1875This method allows clients to capture the data necessary to turn a SkImage into a texture-
1876backed image. If the original image is codec-backed this will decode into a format optimized
1877for the context represented by the proxy. This method is thread safe with respect to the
1878GrContext whence the proxy came. Clients allocate and manage the storage of the deferred
1879texture data and control its lifetime. No cleanup is required, thus it is safe to simply free
1880the memory out from under the data.
1881
1882The same method is used both for getting the size necessary for pre-uploaded texture data
1883and for retrieving the data. The params array represents the set of draws over which to
1884optimize the pre-upload data.
1885
1886When called with a null buffer this returns the size that the client must allocate in order
1887to create deferred texture data for this image (or zero if this is an inappropriate
1888candidate). The buffer allocated by the client should be 8 byte aligned.
1889
1890When buffer is not null this fills in the deferred texture data for this image in the
1891provided buffer (assuming this is an appropriate candidate image and the buffer is
1892appropriately aligned). Upon success the size written is returned, otherwise 0.
1893
1894dstColorSpace is the color space of the surface where this texture will ultimately be used.
1895If the method determines that mip-maps are needed, this helps determine the correct strategy
1896for building them (gamma-correct or not).
1897
1898dstColorType is the color type of the surface where this texture will ultimately be used.
1899This determines the format with which the image will be uploaded to the GPU. If dstColorType
1900does not support color spaces (low bit depth types such as kARGB_4444_SkColorType),
1901then dstColorSpace must be null.
1902
1903#Param contextThreadSafeProxy incomplete ##
1904#Param deferredTextureImageUsageParams incomplete ##
1905#Param paramCnt incomplete ##
1906#Param buffer incomplete ##
1907#Param dstColorSpace incomplete ##
1908#Param dstColorType incomplete ##
1909
1910#Return incomplete ##
1911
1912#Example
1913// incomplete
1914##
1915
1916#SeeAlso incomplete
1917
1918##
1919
1920#Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data,
1921 SkBudgeted budgeted)
1922
1923Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData.
1924The context must be the context that provided the proxy passed to
1925getDeferredTextureImageData.
1926
1927#Param context GPU_Context ##
1928#Param data incomplete ##
1929#Param budgeted incomplete ##
1930
1931#Return incomplete ##
1932
1933#Example
1934// incomplete
1935##
1936
1937#SeeAlso incomplete
1938
1939##
1940
1941# ------------------------------------------------------------------------------
1942
Cary Clarka560c472017-11-27 10:44:06 -05001943#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1944
1945##
1946
1947# ------------------------------------------------------------------------------
1948
1949#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1950 sk_sp<SkImage> image,
1951 GrBackendTexture* backendTexture,
1952 BackendTextureReleaseProc* backendTextureReleaseProc)
1953
1954Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1955GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1956responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1957Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1958to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1959themselves.
1960
1961If image is both texture backed and singly referenced; that is, its only
1962reference was transferred using std::move(): image is returned in backendTexture
1963without conversion or making a copy.
1964
1965If the SkImage is not texture backed, this function will generate a texture with the image's
1966contents and return that.
1967
Cary Clark61ca7c52018-01-02 11:34:14 -05001968#Param context GPU_Context ##
Cary Clarka560c472017-11-27 10:44:06 -05001969#Param image incomplete ##
1970#Param backendTexture incomplete ##
1971#Param backendTextureReleaseProc incomplete ##
1972
1973#Return incomplete ##
1974
1975#Example
1976// incomplete
1977##
1978
1979#SeeAlso incomplete
1980
1981#Method ##
1982
1983# ------------------------------------------------------------------------------
1984
1985#Enum LegacyBitmapMode
1986
1987#Code
1988 enum LegacyBitmapMode {
1989 kRO_LegacyBitmapMode,
1990 kRW_LegacyBitmapMode,
1991 };
1992##
1993
1994Helper functions to convert to SkBitmap
1995
1996#Const kRO_LegacyBitmapMode 0
1997##
1998#Const kRW_LegacyBitmapMode 1
1999##
2000
2001#Example
2002// incomplete
2003##
2004
2005#SeeAlso incomplete
2006
2007#Enum ##
2008
2009# ------------------------------------------------------------------------------
2010
2011#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
2012
Cary Clark3cd22cc2017-12-01 11:49:58 -05002013Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
2014returned bitmap is read-only and immutable.
2015Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
2016write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05002017
Cary Clark3cd22cc2017-12-01 11:49:58 -05002018#Param bitmap storage for legacy Bitmap ##
2019#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05002020
Cary Clark3cd22cc2017-12-01 11:49:58 -05002021#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05002022
2023#Example
2024// incomplete
2025##
2026
2027#SeeAlso incomplete
2028
2029#Method ##
2030
2031# ------------------------------------------------------------------------------
2032
2033#Method bool isLazyGenerated() const
2034
2035Returns true if Image is backed by an image-generator or other service that creates
2036and caches its pixels or texture on-demand.
2037
Cary Clark2f466242017-12-11 16:03:17 -05002038#Return true if Image is created as needed ##
Cary Clarka560c472017-11-27 10:44:06 -05002039
2040#Example
Cary Clark2f466242017-12-11 16:03:17 -05002041#Height 80
2042#Function
2043class TestImageGenerator : public SkImageGenerator {
2044public:
2045 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
2046 ~TestImageGenerator() override {}
2047protected:
2048 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
2049 const Options& options) override {
2050 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
2051 for (int y = 0; y < info.height(); ++y) {
2052 for (int x = 0; x < info.width(); ++x) {
2053 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
2054 }
2055 }
2056 return true;
2057 }
2058};
2059##
2060void draw(SkCanvas* canvas) {
2061 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
2062 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
2063 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
2064 canvas->scale(8, 8);
2065 canvas->drawImage(image, 0, 0, nullptr);
2066 SkPaint paint;
2067 paint.setTextSize(4);
2068 canvas->drawString(lazy, 2, 5, paint);
2069}
Cary Clarka560c472017-11-27 10:44:06 -05002070##
2071
Cary Clarkf5404bb2018-01-05 12:10:09 -05002072#Example
2073#Image 5
2074#Platform gpu
2075void draw(SkCanvas* canvas) {
2076 auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
2077 if (nullptr == image) {
2078 return;
2079 }
2080 SkPaint paint;
2081 paint.setAntiAlias(true);
2082 paint.setTextAlign(SkPaint::kCenter_Align);
2083 canvas->drawImage(image, 0, 0);
2084 canvas->drawString(label, image->width() / 2, image->height() / 4, paint);
2085 canvas->drawString(
2086 image->isLazyGenerated() ? "is lazily generated" : "not lazily generated",
2087 image->width() / 2, image->height() * 3 / 4, paint);
2088 };
2089 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
2090 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
2091 kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr));
2092 drawImage(image, "image");
2093 canvas->translate(image->width(), 0);
2094 drawImage(bitmapImage, "source");
2095 canvas->translate(-image->width(), image->height());
2096 drawImage(textureImage, "backEndTexture");
2097}
2098##
2099
Cary Clarka560c472017-11-27 10:44:06 -05002100#SeeAlso incomplete
2101
2102#Method ##
2103
2104# ------------------------------------------------------------------------------
2105
2106#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
2107 SkTransferFunctionBehavior premulBehavior) const
2108
2109If target is supported, returns an SkImage in target color space.
2110Otherwise, returns nullptr.
2111This will leave the image as is if it already in target color space.
2112Otherwise, it will convert the pixels from Image color space to target
2113color space. If this->colorSpace() is nullptr, Image color space will be
2114treated as sRGB.
2115
2116If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
2117pixels to a linear space before converting to match destination Color_Type
2118and Color_Space.
2119If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
2120pixels are treated as if they are linear, regardless of how they are encoded.
2121
2122#Param target incomplete ##
2123#Param premulBehavior incomplete ##
2124
2125#Return incomplete ##
2126
2127#Example
2128// incomplete
2129##
2130
2131#SeeAlso incomplete
2132
2133#Method ##
2134
2135#Class SkImage ##
2136
2137#Topic Image ##