blob: b0e319291d3bd53228c6275ea16f2ecd73fc437f [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic Image
2#Alias Image_Reference
3
4#Class SkImage
5
6SkImage is an abstraction for drawing a rectangle of pixels, though the
7particular type of image could be actually storing its data on the GPU, or
8as drawing commands (picture or PDF or otherwise), ready to be played back
9into another canvas.
10The content of SkImage is always immutable, though the actual storage may
11change, if for example that image can be re-created via encoded data or
12other means.
13SkImage always has a non-zero dimensions. If there is a request to create a new
14image, either directly or via SkSurface, and either of the requested dimensions
15are zero, then nullptr will be returned.
16
17#Topic Overview
18
19#Subtopic Subtopics
20#ToDo manually add subtopics ##
21#Table
22#Legend
23# topics # description ##
24#Legend ##
25#Table ##
26##
27
Cary Clarka560c472017-11-27 10:44:06 -050028#Subtopic Member_Functions
29#Table
30#Legend
31# description # function ##
32#Legend ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050033# MakeBackendTextureFromSkImage # Creates GPU texture from Image. ##
34# MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ##
35# MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ##
36# MakeFromAdoptedTexture # Creates Image from GPU texture, managed internally. ##
37# MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050038# MakeFromEncoded # Creates Image from encoded data. ##
39# MakeFromGenerator # Creates Image from a stream of data. ##
40# MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ##
41# MakeFromPicture # Creates Image from Picture. ##
42# MakeFromRaster # Creates Image from Pixmap, with release. ##
43# MakeFromTexture # Creates Image from GPU texture, managed externally. ##
44# MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ##
45# MakeRasterCopy # Creates Image from Pixmap and copied pixels. ##
46# MakeRasterData # Creates Image from Image_Info and shared pixels. ##
47# alphaType # Returns Alpha_Type ##
Cary Clark2f466242017-12-11 16:03:17 -050048# asLegacyBitmap # Returns as Raster_Bitmap ##
49# bounds() # Returns width() and height() as Rectangle. ##
50# colorSpace # Returns Color_Space. ##
51# dimensions() # Returns width() and height(). ##
52# encodeToData # Returns encoded Image as SkData. ##
53# getTexture # Deprecated. ##
54# getTextureHandle # Returns GPU reference to Image as texture. ##
55# height() # Returns pixel row count. ##
56# isAlphaOnly # Returns if pixels represent a transparency mask. ##
57# isLazyGenerated # Returns if Image is created as needed. ##
58# isOpaque # Returns if Alpha_Type is kOpaque_SkAlphaType. ##
59# isTextureBacked # Returns if Image was created from GPU texture. ##
60# isValid # Returns if Image can draw to Raster_Surface or GPU_Context. ##
61# makeColorSpace # Creates Image matching Color_Space if possible. ##
62# makeNonTextureImage # Creates Raster_Image if possible. ##
63# makeShader # Creates Shader, Paint element that can tile Image. ##
64# makeSubset # Creates Image containing part of original. ##
65# makeTextureImage # Creates Image matching Color_Space if possible. ##
66# makeWithFilter # Creates filtered, clipped Image. ##
67# peekPixels # Returns Pixmap if possible. ##
68# readPixels # Copies and converts pixels. ##
69# refColorSpace # Returns Image_Info Color_Space. ##
70# refEncodedData # Returns Image encoded in SkData if present. ##
71# scalePixels # Scales and converts one Image to another. ##
72# toString # Converts Image to machine readable form. ##
73# uniqueID # Identifier for Image. ##
74# width() # Returns pixel column count. ##
Cary Clarka560c472017-11-27 10:44:06 -050075#Table ##
76#Subtopic ##
77
78#Topic ##
79
Cary Clarka560c472017-11-27 10:44:06 -050080#Typedef SkImageInfo Info
81
82##
83
Cary Clarka560c472017-11-27 10:44:06 -050084# ------------------------------------------------------------------------------
85
86#Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)
87
Cary Clark2f466242017-12-11 16:03:17 -050088Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap
89pixels may be modified or deleted without affecting Image.
Cary Clarka560c472017-11-27 10:44:06 -050090
Cary Clark3cd22cc2017-12-01 11:49:58 -050091Image is returned if Pixmap is valid. Valid Pixmap parameters include:
92dimensions are greater than zero;
93each dimension fits in 29 bits;
94Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
95row bytes are large enough to hold one row of pixels;
96pixel address is not nullptr.
97
98#Param pixmap Image_Info, pixel address, and row bytes ##
99
100#Return copy of Pixmap pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500101
102#Example
Cary Clark2f466242017-12-11 16:03:17 -0500103#Height 50
104#Description
105Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap
106alters the bitmap draw, but does not alter the Image draw since the Image
107contains a copy of the pixels.
108##
109 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
110 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
111 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
112 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
113 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
114 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
115 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
116 SkBitmap bitmap;
117 bitmap.installPixels(pixmap);
118 sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap);
119 *pixmap.writable_addr8(2, 2) = 0x00;
120 canvas->scale(10, 10);
121 canvas->drawBitmap(bitmap, 0, 0);
122 canvas->drawImage(image, 10, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500123##
124
Cary Clark3cd22cc2017-12-01 11:49:58 -0500125#SeeAlso MakeRasterData MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500126
127#Method ##
128
129# ------------------------------------------------------------------------------
130
131#Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes)
132
Cary Clark3cd22cc2017-12-01 11:49:58 -0500133Creates Image from Image_Info, sharing pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500134
Cary Clark3cd22cc2017-12-01 11:49:58 -0500135Image is returned if Image_Info is valid. Valid Image_Info parameters include:
136dimensions are greater than zero;
137each dimension fits in 29 bits;
138Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
139rowBytes are large enough to hold one row of pixels;
140pixels is not nullptr, and contains enough data for Image.
141
142#Param info contains width, height, Alpha_Type, Color_Type, Color_Space ##
143#Param pixels address or pixel storage ##
144#Param rowBytes size of pixel row or larger ##
145
146#Return Image sharing pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500147
148#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500149#Image 3
150 size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType);
151 sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height());
152 SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(),
153 kPremul_SkAlphaType);
154 image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint);
155 sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType),
156 data, rowBytes);
157 canvas->drawImage(image, 0, 0);
158 canvas->drawImage(raw.get(), 128, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500159##
160
Cary Clark3cd22cc2017-12-01 11:49:58 -0500161#SeeAlso MakeRasterCopy MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500162
163#Method ##
164
165# ------------------------------------------------------------------------------
166
Cary Clark3cd22cc2017-12-01 11:49:58 -0500167#Typedef void* ReleaseContext
168
169Caller data passed to RasterReleaseProc; may be nullptr.
170
171#SeeAlso MakeFromRaster RasterReleaseProc
172
173##
174
Cary Clarka560c472017-11-27 10:44:06 -0500175#Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext)
176
Cary Clark3cd22cc2017-12-01 11:49:58 -0500177Function called when Image no longer shares pixels. ReleaseContext is
178provided by caller when Image is created, and may be nullptr.
179
180#SeeAlso ReleaseContext MakeFromRaster
181
Cary Clarka560c472017-11-27 10:44:06 -0500182##
183
184#Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
185 RasterReleaseProc rasterReleaseProc,
186 ReleaseContext releaseContext)
187
Cary Clark0c5f5462017-12-15 11:21:51 -0500188Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and
Cary Clark3cd22cc2017-12-01 11:49:58 -0500189unchanged until rasterReleaseProc is called. rasterReleaseProc is passed
190releaseContext when Image is deleted or no longer refers to pixmap pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500191
Cary Clark0c5f5462017-12-15 11:21:51 -0500192Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback
193when Image is released. Pass nullptr for releaseContext if rasterReleaseProc
194does not require state.
195
Cary Clark3cd22cc2017-12-01 11:49:58 -0500196Image is returned if pixmap is valid. Valid Pixmap parameters include:
197dimensions are greater than zero;
198each dimension fits in 29 bits;
199Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
200row bytes are large enough to hold one row of pixels;
201pixel address is not nullptr.
202
203#Param pixmap Image_Info, pixel address, and row bytes ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500204#Param rasterReleaseProc function called when pixels can be released; or nullptr ##
205#Param releaseContext state passed to rasterReleaseProc; or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500206
Cary Clark0c5f5462017-12-15 11:21:51 -0500207#Return Image sharing pixmap ##
Cary Clarka560c472017-11-27 10:44:06 -0500208
209#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500210#Function
211static void releaseProc(const void* pixels, SkImage::ReleaseContext context) {
212 int* countPtr = static_cast<int*>(context);
213 *countPtr += 1;
214}
215##
216
217void draw(SkCanvas* canvas) {
218 SkColor color = 0;
219 SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4);
220 int releaseCount = 0;
221 sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount));
222 SkDebugf("before reset: %d\n", releaseCount);
223 image.reset();
224 SkDebugf("after reset: %d\n", releaseCount);
225}
226#StdOut
227before reset: 0
228after reset: 1
229##
Cary Clarka560c472017-11-27 10:44:06 -0500230##
231
Cary Clark3cd22cc2017-12-01 11:49:58 -0500232#SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
Cary Clarka560c472017-11-27 10:44:06 -0500233
234#Method ##
235
236# ------------------------------------------------------------------------------
237
238#Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)
239
Cary Clark3cd22cc2017-12-01 11:49:58 -0500240Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap
241is marked immutable, and its pixel memory is shareable, it may be shared
242instead of copied.
Cary Clarka560c472017-11-27 10:44:06 -0500243
Cary Clark3cd22cc2017-12-01 11:49:58 -0500244Image is returned if bitmap is valid. Valid Bitmap parameters include:
245dimensions are greater than zero;
246each dimension fits in 29 bits;
247Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
248row bytes are large enough to hold one row of pixels;
249pixel address is not nullptr.
Cary Clarka560c472017-11-27 10:44:06 -0500250
Cary Clark3cd22cc2017-12-01 11:49:58 -0500251#Param bitmap Image_Info, row bytes, and pixels ##
252
253#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500254
255#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500256#Description
257The first Bitmap is shared; writing to the pixel memory changes the first
258Image.
259The second Bitmap is marked immutable, and is copied; writing to the pixel
260memory does not alter the second Image.
261##
262#Height 50
263 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
264 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
265 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
266 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
267 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
268 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
269 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
270 SkBitmap bitmap;
271 bitmap.installPixels(pixmap);
272 sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap);
273 bitmap.setImmutable();
274 sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap);
275 *pixmap.writable_addr8(2, 2) = 0x00;
276 canvas->scale(10, 10);
277 canvas->drawImage(image1, 0, 0);
278 canvas->drawImage(image2, 10, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500279##
280
Cary Clark3cd22cc2017-12-01 11:49:58 -0500281#SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Cary Clarka560c472017-11-27 10:44:06 -0500282
283#Method ##
284
285# ------------------------------------------------------------------------------
286
287#Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
288 const SkIRect* subset = nullptr)
289
Cary Clark0c5f5462017-12-15 11:21:51 -0500290Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not
291be shared or accessed.
Cary Clarka560c472017-11-27 10:44:06 -0500292
Cary Clark0c5f5462017-12-15 11:21:51 -0500293subset allows selecting a portion of the full image. Pass nullptr to select the entire image;
294otherwise, subset must be contained by image bounds.
295
296Image is returned if generator data is valid. Valid data parameters vary by type of data
297and platform.
Cary Clarka560c472017-11-27 10:44:06 -0500298
Cary Clark3cd22cc2017-12-01 11:49:58 -0500299imageGenerator may wrap Picture data, codec data, or custom data.
300
301#Param imageGenerator stock or custom routines to retrieve Image ##
302#Param subset bounds of returned Image; may be nullptr ##
303
304#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500305
306#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500307#Description
308The generator returning Picture cannot be shared; std::move transfers ownership to generated Image.
309##
310 SkPictureRecorder recorder;
311 recorder.beginRecording(100, 100)->drawColor(SK_ColorRED);
312 auto picture = recorder.finishRecordingAsPicture();
313 auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr,
314 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB());
315 sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen));
316 canvas->drawImage(image, 0, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500317##
318
Cary Clark3cd22cc2017-12-01 11:49:58 -0500319#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500320
321#Method ##
322
323# ------------------------------------------------------------------------------
324
325#Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)
326
Cary Clark3cd22cc2017-12-01 11:49:58 -0500327Creates Image from encoded data.
Cary Clark0c5f5462017-12-15 11:21:51 -0500328subset allows selecting a portion of the full image. Pass nullptr to select the entire image;
329otherwise, subset must be contained by image bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500330
Cary Clark3cd22cc2017-12-01 11:49:58 -0500331Image is returned if format of the encoded data is recognized and supported.
332Recognized formats vary by platfrom.
Cary Clarka560c472017-11-27 10:44:06 -0500333
Cary Clark3cd22cc2017-12-01 11:49:58 -0500334#Param encoded data of Image to decode ##
335#Param subset bounds of returned Image; may be nullptr ##
336
337#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500338
Cary Clark0c5f5462017-12-15 11:21:51 -0500339#Bug 7343
340Waiting on fiddle to support returning image as SkData
341##
342
343#NoExample
Cary Clarka560c472017-11-27 10:44:06 -0500344##
345
Cary Clark3cd22cc2017-12-01 11:49:58 -0500346#SeeAlso MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500347
348#Method ##
349
350# ------------------------------------------------------------------------------
351
352#Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext)
353
354##
355
356#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
357 const GrBackendTexture& backendTexture,
358 GrSurfaceOrigin origin,
359 SkAlphaType alphaType,
360 sk_sp<SkColorSpace> colorSpace)
361
Cary Clark3cd22cc2017-12-01 11:49:58 -0500362Creates Image from GPU texture associated with context. Caller is responsible for
363managing the lifetime of GPU texture.
Cary Clarka560c472017-11-27 10:44:06 -0500364
Cary Clark3cd22cc2017-12-01 11:49:58 -0500365Image is returned if format of backendTexture is recognized and supported.
366Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500367
Cary Clark3cd22cc2017-12-01 11:49:58 -0500368#Param context GPU_Context ##
369#Param backendTexture texture residing on GPU ##
370#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
371#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
372 kPremul_SkAlphaType, kUnpremul_SkAlphaType
373##
374#Param colorSpace range of colors ##
375
376#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500377
378#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500379#Image 3
380#Platform gpu
381#Height 128
382#Description
383A back-end texture has been created and uploaded to the GPU outside of this example.
384##
385GrContext* context = canvas->getGrContext();
386if (!context) {
387 return;
388}
389canvas->scale(.25f, .25f);
390int x = 0;
391for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
392 sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
393 origin, kOpaque_SkAlphaType, nullptr);
394 canvas->drawImage(image, x, 0);
395x += 512;
396}
Cary Clarka560c472017-11-27 10:44:06 -0500397##
398
Cary Clark3cd22cc2017-12-01 11:49:58 -0500399#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500400
401#Method ##
402
403# ------------------------------------------------------------------------------
404
405#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
406 const GrBackendTexture& backendTexture,
407 GrSurfaceOrigin origin,
408 SkAlphaType alphaType,
409 sk_sp<SkColorSpace> colorSpace,
410 TextureReleaseProc textureReleaseProc,
411 ReleaseContext releaseContext)
412
Cary Clark3cd22cc2017-12-01 11:49:58 -0500413Creates Image from GPU texture associated with context. GPU texture must stay
414valid and unchanged until textureReleaseProc is called. textureReleaseProc is
415passed releaseContext when Image is deleted or no longer refers to texture.
Cary Clarka560c472017-11-27 10:44:06 -0500416
Cary Clark3cd22cc2017-12-01 11:49:58 -0500417Image is returned if format of backendTexture is recognized and supported.
418Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500419
Cary Clark3cd22cc2017-12-01 11:49:58 -0500420#Param context GPU_Context ##
421#Param backendTexture texture residing on GPU ##
422#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
423#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
424 kPremul_SkAlphaType, kUnpremul_SkAlphaType
425##
426#Param colorSpace range of colors ##
427#Param textureReleaseProc function called when texture can be released ##
428#Param releaseContext state passed to textureReleaseProc ##
429
430#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500431
Cary Clark0c5f5462017-12-15 11:21:51 -0500432#ToDo
433This doesn't do anything clever with TextureReleaseProc because it may not get called
434within the lifetime of the example
435##
436
Cary Clarka560c472017-11-27 10:44:06 -0500437#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500438GrContext* context = canvas->getGrContext();
439if (!context) {
440 return;
441}
442auto debugster = [](SkImage::ReleaseContext context) -> void {
443 *((int *) context) += 128;
444};
445int x = 0;
446for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
447 sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
448 origin, kOpaque_SkAlphaType, nullptr, debugster, &x);
449 canvas->drawImage(image, x, 0);
450 x += 128;
451}
Cary Clarka560c472017-11-27 10:44:06 -0500452##
453
Cary Clark3cd22cc2017-12-01 11:49:58 -0500454#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500455
456#Method ##
457
458# ------------------------------------------------------------------------------
459
460#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
461 bool buildMips,
462 SkColorSpace* dstColorSpace)
463
Cary Clark3cd22cc2017-12-01 11:49:58 -0500464Creates Image from encoded data. Image is uploaded to GPU back-end using context.
465
466Created Image is available to other GPU contexts, and is available across thread
467boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
468share resources.
469
470When Image is no longer referenced, context releases texture memory
Cary Clarka560c472017-11-27 10:44:06 -0500471asynchronously.
Cary Clarka560c472017-11-27 10:44:06 -0500472
Cary Clark3cd22cc2017-12-01 11:49:58 -0500473Texture decoded from data is uploaded to match Surface created with
474dstColorSpace. Color_Space of Image is determined by encoded data.
Cary Clarka560c472017-11-27 10:44:06 -0500475
Cary Clark3cd22cc2017-12-01 11:49:58 -0500476Image is returned if format of data is recognized and supported, and if context
477supports moving resources. Recognized formats vary by platform and GPU back-end.
478
479#Param context GPU_Context ##
480#Param data Image to decode ##
481#Param buildMips create Image as Mip_Map if true ##
482#Param dstColorSpace range of colors of matching Surface on GPU ##
483
484#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500485
486#Example
487// incomplete
488##
489
Cary Clark3cd22cc2017-12-01 11:49:58 -0500490#SeeAlso MakeCrossContextFromPixmap
491
492#Method ##
493
494# ------------------------------------------------------------------------------
495
496#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
497 bool buildMips,
498 SkColorSpace* dstColorSpace)
499
500Creates Image from pixmap. Image is uploaded to GPU back-end using context.
501
502Created Image is available to other GPU contexts, and is available across thread
503boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
504share resources.
505
506When Image is no longer referenced, context releases texture memory
507asynchronously.
508
509Texture created from pixmap is uploaded to match Surface created with
510dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace().
511
512Image is returned referring to GPU back-end if format of data is recognized and
513supported, and if context supports moving resources. Otherwise, pixmap pixel
514data is copied and Image as returned in raster format if possible; nullptr may
515be returned. Recognized GPU formats vary by platform and GPU back-end.
516
517#Param context GPU_Context ##
518#Param pixmap Image_Info, pixel address, and row bytes ##
519#Param buildMips create Image as Mip_Map if true ##
520#Param dstColorSpace range of colors of matching Surface on GPU ##
521
522#Return created Image, or nullptr ##
523
524#Example
525// incomplete
526##
527
528#SeeAlso MakeCrossContextFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500529
530#Method ##
531
532# ------------------------------------------------------------------------------
533
534#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
535 const GrBackendTexture& backendTexture,
536 GrSurfaceOrigin surfaceOrigin,
537 SkAlphaType alphaType = kPremul_SkAlphaType,
538 sk_sp<SkColorSpace> colorSpace = nullptr)
539
Cary Clark3cd22cc2017-12-01 11:49:58 -0500540Creates Image from backendTexture associated with context. backendTexture and
541returned Image are managed internally, and are released when no longer needed.
Cary Clarka560c472017-11-27 10:44:06 -0500542
Cary Clark3cd22cc2017-12-01 11:49:58 -0500543Image is returned if format of backendTexture is recognized and supported.
544Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500545
Cary Clark3cd22cc2017-12-01 11:49:58 -0500546#Param context GPU_Context ##
547#Param backendTexture texture residing on GPU ##
548#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
549#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
550 kPremul_SkAlphaType, kUnpremul_SkAlphaType
551##
552#Param colorSpace range of colors ##
553
554#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500555
556#Example
557// incomplete
558##
559
560#SeeAlso incomplete
561
562#Method ##
563
564# ------------------------------------------------------------------------------
565
566#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
567 const GrBackendObject yuvTextureHandles[3],
568 const SkISize yuvSizes[3],
569 GrSurfaceOrigin surfaceOrigin,
570 sk_sp<SkColorSpace> colorSpace = nullptr)
571
572Create a new image by copying the pixels from the specified y, u, v textures. The data
573from the textures is immediately ingested into the image and the textures can be modified or
574deleted after the function returns. The image will have the dimensions of the y texture.
575
576#Param context incomplete ##
577#Param yuvColorSpace incomplete ##
578#Param yuvTextureHandles incomplete ##
579#Param yuvSizes incomplete ##
580#Param surfaceOrigin incomplete ##
581#Param colorSpace incomplete ##
582
583#Return incomplete ##
584
585#Example
586// incomplete
587##
588
589#SeeAlso incomplete
590
591#Method ##
592
593# ------------------------------------------------------------------------------
594
595#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
596 SkYUVColorSpace yuvColorSpace,
597 const GrBackendObject nv12TextureHandles[2],
598 const SkISize nv12Sizes[2],
599 GrSurfaceOrigin surfaceOrigin,
600 sk_sp<SkColorSpace> colorSpace = nullptr)
601
602Create a new image by copying the pixels from the specified y and UV_Mapping. The data
603from the textures is immediately ingested into the image and the textures can be modified or
604deleted after the function returns. The image will have the dimensions of the y texture.
605
606#Param context incomplete ##
607#Param yuvColorSpace incomplete ##
608#Param nv12TextureHandles incomplete ##
609#Param nv12Sizes incomplete ##
610#Param surfaceOrigin incomplete ##
611#Param colorSpace incomplete ##
612
613#Return incomplete ##
614
615#Example
616// incomplete
617##
618
619#SeeAlso incomplete
620
621#Method ##
622
623# ------------------------------------------------------------------------------
624
625#Enum BitDepth
626
627#Code
628 enum BitDepth {
629 kU8,
630 kF16,
631 };
632##
633
634#Const kU8 0
635##
636#Const kF16 1
637##
638
639#Example
640// incomplete
641##
642
643#SeeAlso incomplete
644
645#Enum ##
646
647# ------------------------------------------------------------------------------
648
649#Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
650 const SkMatrix* matrix, const SkPaint* paint,
651 BitDepth bitDepth,
652 sk_sp<SkColorSpace> colorSpace)
653
654Create a new image from the specified picture.
655On creation of the SkImage, snap the SkPicture to a particular BitDepth and SkColorSpace.
656
657#Param picture incomplete ##
658#Param dimensions incomplete ##
659#Param matrix incomplete ##
660#Param paint incomplete ##
661#Param bitDepth incomplete ##
662#Param colorSpace incomplete ##
663
664#Return incomplete ##
665
666#Example
667// incomplete
668##
669
670#SeeAlso incomplete
671
672#Method ##
673
674# ------------------------------------------------------------------------------
675
676#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
677 SkAlphaType alphaType = kPremul_SkAlphaType,
678 sk_sp<SkColorSpace> colorSpace = nullptr)
679
680 Create a new image from the an Android hardware buffer.
681 The new image takes a reference on the buffer.
682
683 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
684
685#Param hardwareBuffer incomplete ##
686#Param alphaType incomplete ##
687#Param colorSpace incomplete ##
688
689#Return incomplete ##
690
691#Example
692// incomplete
693##
694
695#SeeAlso incomplete
696
697#Method ##
698
699# ------------------------------------------------------------------------------
700
701#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
702 SkAlphaType alphaType = kPremul_SkAlphaType,
703 sk_sp<SkColorSpace> colorSpace = nullptr)
704
705Create a new image from the an Android hardware buffer.
706The new image takes a reference on the buffer.
707
708#Param hardwareBuffer incomplete ##
709#Param alphaType incomplete ##
710#Param colorSpace incomplete ##
711
712#Return incomplete ##
713
714#Example
715// incomplete
716##
717
718#SeeAlso incomplete
719
720#Method ##
721
722# ------------------------------------------------------------------------------
723
724#Method int width() const
725
726#Return incomplete ##
727
728#Example
729// incomplete
730##
731
732#SeeAlso incomplete
733
734#Method ##
735
736# ------------------------------------------------------------------------------
737
738#Method int height() const
739
Cary Clark2f466242017-12-11 16:03:17 -0500740Returns pixel row count.
741
Cary Clarka560c472017-11-27 10:44:06 -0500742#Return incomplete ##
743
744#Example
745// incomplete
746##
747
748#SeeAlso incomplete
749
750#Method ##
751
752# ------------------------------------------------------------------------------
753
754#Method SkISize dimensions() const
755
Cary Clark2f466242017-12-11 16:03:17 -0500756Returns ISize { width(), height() }.
757
758#Return integral size of width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -0500759
760#Example
761// incomplete
762##
763
Cary Clark2f466242017-12-11 16:03:17 -0500764#SeeAlso height() width()
Cary Clarka560c472017-11-27 10:44:06 -0500765
766#Method ##
767
768# ------------------------------------------------------------------------------
769
770#Method SkIRect bounds() const
771
Cary Clark2f466242017-12-11 16:03:17 -0500772Returns IRect { 0, 0, width(), height() }.
773
774#Return integral rectangle from origin to width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -0500775
776#Example
777// incomplete
778##
779
780#SeeAlso incomplete
781
782#Method ##
783
784# ------------------------------------------------------------------------------
785
786#Method uint32_t uniqueID() const
787
788#Return incomplete ##
789
790#Example
791// incomplete
792##
793
794#SeeAlso incomplete
795
796#Method ##
797
798# ------------------------------------------------------------------------------
799
800#Method SkAlphaType alphaType() const
801
802#Return incomplete ##
803
804#Example
805// incomplete
806##
807
808#SeeAlso incomplete
809
810#Method ##
811
812# ------------------------------------------------------------------------------
813
814#Method SkColorSpace* colorSpace() const
815
Cary Clark2f466242017-12-11 16:03:17 -0500816Returns Color_Space, the range of colors, associated with Image. The
817reference count of Color_Space is unchanged. The returned Color_Space is
818immutable.
Cary Clarka560c472017-11-27 10:44:06 -0500819
Cary Clark2f466242017-12-11 16:03:17 -0500820Color_Space returned was a parameter to an Image constructor,
821or was parsed from encoded data. Color_Space may be ignored when
822drawing Image, and when drawing into Surface constructed with Color_Space.
823
824#Return Color_Space in Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500825
826#Example
827// incomplete
828##
829
830#SeeAlso incomplete
831
832#Method ##
833
834# ------------------------------------------------------------------------------
835
836#Method sk_sp<SkColorSpace> refColorSpace() const
837
838#Return incomplete ##
839
840#Example
841// incomplete
842##
843
844#SeeAlso incomplete
845
846#Method ##
847
848# ------------------------------------------------------------------------------
849
850#Method bool isAlphaOnly() const
851
Cary Clark2f466242017-12-11 16:03:17 -0500852Returns true if Image pixels represent transparency only. If true, each pixel
853is packed in 8 bits as defined by kAlpha_8_SkColorType.
Cary Clarka560c472017-11-27 10:44:06 -0500854
Cary Clark2f466242017-12-11 16:03:17 -0500855#Return true if pixels represent a transparency mask ##
Cary Clarka560c472017-11-27 10:44:06 -0500856
857#Example
858// incomplete
859##
860
861#SeeAlso incomplete
862
863#Method ##
864
865# ------------------------------------------------------------------------------
866
867#Method bool isOpaque() const
868
Cary Clark2f466242017-12-11 16:03:17 -0500869Returns if all pixels ignore any Alpha value and are treated as fully opaque.
870
871#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clarka560c472017-11-27 10:44:06 -0500872
873#Example
874// incomplete
875##
876
877#SeeAlso incomplete
878
879#Method ##
880
881# ------------------------------------------------------------------------------
882
883#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
884 const SkMatrix* localMatrix = nullptr) const
885
886#Param tileMode1 incomplete ##
887#Param tileMode2 incomplete ##
888#Param localMatrix incomplete ##
889
890#Return incomplete ##
891
892#Example
893// incomplete
894##
895
896#SeeAlso incomplete
897
898#Method ##
899
900# ------------------------------------------------------------------------------
901
902#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
903
904Helper version of makeShader() that specifies SkShader::kClamp_TileMode.
905
906#Param localMatrix incomplete ##
907
908#Return incomplete ##
909
910#Example
911// incomplete
912##
913
914#SeeAlso incomplete
915
916#Method ##
917
918# ------------------------------------------------------------------------------
919
920#Method bool peekPixels(SkPixmap* pixmap) const
921
922If the image has direct access to its pixels (i.e. they are in local RAM)
923return true, and if not null, return in the pixmap parameter the info about the
924images pixels.
925On failure, return false and ignore the pixmap parameter.
926
927#Param pixmap incomplete ##
928
929#Return incomplete ##
930
931#Example
932// incomplete
933##
934
935#SeeAlso incomplete
936
937#Method ##
938
939# ------------------------------------------------------------------------------
940
941#Method GrTexture* getTexture() const
942
Cary Clark2f466242017-12-11 16:03:17 -0500943Deprecated.
944
945#Deprecated
946##
947
Cary Clarka560c472017-11-27 10:44:06 -0500948#Private
949currently used by Canvas2DLayerBridge in Chromium.
950##
951
Cary Clarka560c472017-11-27 10:44:06 -0500952#Method ##
953
954# ------------------------------------------------------------------------------
955
956#Method bool isTextureBacked() const
957
958Returns true if the image is texture backed.
959
960#Return incomplete ##
961
962#Example
963// incomplete
964##
965
966#SeeAlso incomplete
967
968#Method ##
969
970# ------------------------------------------------------------------------------
971
972#Method bool isValid(GrContext* context) const
973
974Returns true if Image can be drawn. If context
975is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image
976draws on GPU_Surface associated with context.
977
978Texture-backed images may become invalid if their underlying GrContext is abandoned. Some
979generator-backed images may be invalid for CPU and/or GPU.
980
981#Param context incomplete ##
982
983#Return incomplete ##
984
985#Example
986// incomplete
987##
988
989#SeeAlso incomplete
990
991#Method ##
992
993# ------------------------------------------------------------------------------
994
995#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
996 GrSurfaceOrigin* origin = nullptr) const
997
Cary Clark2f466242017-12-11 16:03:17 -0500998Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true,
999complete deferred I/O operations.
Cary Clarka560c472017-11-27 10:44:06 -05001000
Cary Clark2f466242017-12-11 16:03:17 -05001001If origin in not nullptr, copies location of content drawn into Image.
Cary Clarka560c472017-11-27 10:44:06 -05001002
Cary Clark2f466242017-12-11 16:03:17 -05001003#Param flushPendingGrContextIO flag to flush outstanding requests ##
1004#Param origin storage for one of: kTopLeft_GrSurfaceOrigin,
1005 kBottomLeft_GrSurfaceOrigin; or nullptr
1006##
1007
1008#Return back-end API texture handle ##
Cary Clarka560c472017-11-27 10:44:06 -05001009
1010#Example
Cary Clark2f466242017-12-11 16:03:17 -05001011#Image 3
1012#Platform gpu
1013GrContext* context = canvas->getGrContext();
1014if (!context) {
1015 return;
1016}
1017SkPaint paint;
1018paint.setAntiAlias(true);
1019SkString str;
1020int y = 0;
1021for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
1022 sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
1023 backEndTexture, origin, kPremul_SkAlphaType, nullptr));
1024 GrSurfaceOrigin readBackOrigin;
1025 GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
1026 str.printf("readBackHandle: %x", readBackHandle);
1027 canvas->drawString(str, 5, y += 20, paint);
1028 str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft");
1029 canvas->drawString(str, 5, y += 20, paint);
1030}
Cary Clarka560c472017-11-27 10:44:06 -05001031##
1032
1033#SeeAlso incomplete
1034
1035#Method ##
1036
1037# ------------------------------------------------------------------------------
1038
1039#Enum CachingHint
1040
1041#Code
1042 enum CachingHint {
1043 kAllow_CachingHint,
1044 kDisallow_CachingHint,
1045 };
1046##
1047
1048Hints to image calls where the system might cache computed intermediates (e.g. the results
1049of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
1050behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
1051
1052#Const kAllow_CachingHint 0
1053##
1054#Const kDisallow_CachingHint 1
1055##
1056
1057#Example
1058// incomplete
1059##
1060
1061#SeeAlso incomplete
1062
1063#Enum ##
1064
1065# ------------------------------------------------------------------------------
1066
1067#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
1068 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
1069
1070Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
1071converting them into the requested format (dstInfo). The image pixels are read
1072starting at the specified (srcX, srcY) location.
1073dstInfo and (srcX, srcY) offset specifies a source rectangle:
1074#Code
1075SkRect srcR;
1076srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
1077##
1078
1079The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
1080then we have two sets of pixels (of equal size). Replace dstPixels with the
1081corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
1082(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
1083This call can fail, returning false, for several reasons:
1084if source rectangle does not intersect the image bounds;
1085if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
1086
1087#Param dstInfo incomplete ##
1088#Param dstPixels incomplete ##
1089#Param dstRowBytes incomplete ##
1090#Param srcX incomplete ##
1091#Param srcY incomplete ##
1092#Param cachingHint incomplete ##
1093
1094#Return incomplete ##
1095
1096#Example
1097// incomplete
1098##
1099
1100#SeeAlso incomplete
1101
1102#Method ##
1103
1104# ------------------------------------------------------------------------------
1105
1106#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1107 CachingHint cachingHint = kAllow_CachingHint) const
1108
1109#Param dst incomplete ##
1110#Param srcX incomplete ##
1111#Param srcY incomplete ##
1112#Param cachingHint incomplete ##
1113
1114#Return incomplete ##
1115
1116#Example
1117// incomplete
1118##
1119
1120#SeeAlso incomplete
1121
1122#Method ##
1123
1124# ------------------------------------------------------------------------------
1125
1126#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1127 CachingHint cachingHint = kAllow_CachingHint) const
1128
1129Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1130If the conversion cannot be performed, false is returned.
1131If dst dimensions differ from Image dimensions, Image is scaled, applying
1132filterQuality.
1133
1134#Param dst incomplete ##
1135#Param filterQuality incomplete ##
1136#Param cachingHint incomplete ##
1137
1138#Return incomplete ##
1139
1140#Example
1141// incomplete
1142##
1143
1144#SeeAlso incomplete
1145
1146#Method ##
1147
1148# ------------------------------------------------------------------------------
1149
1150#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1151
Cary Clark2f466242017-12-11 16:03:17 -05001152Encodes Image pixels, returning result as SkData.
1153
1154Returns nullptr if encoding fails, or encodedImageFormat is not supported.
Cary Clarka560c472017-11-27 10:44:06 -05001155
1156#Param encodedImageFormat incomplete ##
1157#Param quality incomplete ##
1158
Cary Clark2f466242017-12-11 16:03:17 -05001159#Return encoded Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001160
1161#Example
1162// incomplete
1163##
1164
1165#SeeAlso incomplete
1166
1167#Method ##
1168
1169# ------------------------------------------------------------------------------
1170
1171#Method sk_sp<SkData> encodeToData(SkPixelSerializer* pixelSerializer = nullptr) const
1172
1173Encodes Image and returns result as SkData. Will reuse existing encoded data
1174if present, as returned by refEncodedData. pixelSerializer validates existing
1175encoded data, and encodes Image when existing encoded data is missing or
1176invalid.
1177
1178Passing nullptr for pixelSerializer selects default serialization which
1179accepts all data and encodes to PNG.
1180
1181Returns nullptr if existing encoded data is missing or invalid and
1182encoding fails.
1183
1184#Param pixelSerializer incomplete ##
1185
1186#Return incomplete ##
1187
1188#Example
1189// incomplete
1190##
1191
1192#SeeAlso incomplete
1193
1194#Method ##
1195
1196# ------------------------------------------------------------------------------
1197
1198#Method sk_sp<SkData> refEncodedData() const
1199
1200If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1201as SkData. If the image does not already has its contents in encoded form, return nullptr.
1202
1203To force the image to return its contents as encoded data, call encodeToData.
1204
1205#Return incomplete ##
1206
1207#Example
1208// incomplete
1209##
1210
1211#SeeAlso incomplete
1212
1213#Method ##
1214
1215# ------------------------------------------------------------------------------
1216
1217#Method const char* toString(SkString* string) const
1218
1219#Param string incomplete ##
1220
1221#Return incomplete ##
1222
1223#Example
1224// incomplete
1225##
1226
1227#SeeAlso incomplete
1228
1229#Method ##
1230
1231# ------------------------------------------------------------------------------
1232
1233#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
1234
1235Return a new image that is a subset of this image. The underlying implementation may
1236share the pixels, or it may make a copy.
1237If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1238nullptr will be returned.
1239
1240#Param subset incomplete ##
1241
1242#Return incomplete ##
1243
1244#Example
1245// incomplete
1246##
1247
1248#SeeAlso incomplete
1249
1250#Method ##
1251
1252# ------------------------------------------------------------------------------
1253
1254#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1255
1256Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1257with surfaces that have the supplied destination color space. If no transformation is
1258required, the returned image may be the same as this image. If this image is from a
1259different GrContext, this will fail.
1260
1261#Param context incomplete ##
1262#Param dstColorSpace incomplete ##
1263
1264#Return incomplete ##
1265
1266#Example
1267// incomplete
1268##
1269
1270#SeeAlso incomplete
1271
1272#Method ##
1273
1274# ------------------------------------------------------------------------------
1275
1276#Method sk_sp<SkImage> makeNonTextureImage() const
1277
1278If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1279the pixels fails). Otherwise, it returns the original image.
1280
1281#Return incomplete ##
1282
1283#Example
1284// incomplete
1285##
1286
1287#SeeAlso incomplete
1288
1289#Method ##
1290
1291# ------------------------------------------------------------------------------
1292
1293#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1294 const SkIRect& clipBounds, SkIRect* outSubset,
1295 SkIPoint* offset) const
1296
1297Apply a given image filter to this image, and return the filtered result.
1298The subset represents the active portion of this image. The return value is similarly an
1299SkImage, with an active subset (outSubset). This is usually used with texture-backed
1300images, where the texture may be approx-match and thus larger than the required size.
1301clipBounds constrains the device-space extent of the image, stored in outSubset.
1302offset is storage, set to the amount to translate the result when drawn.
1303If the result image cannot be created, or the result would be transparent black, null
1304is returned, in which case the offset and outSubset parameters should be ignored by the
1305caller.
1306
1307#Param filter incomplete ##
1308#Param subset incomplete ##
1309#Param clipBounds incomplete ##
1310#Param outSubset incomplete ##
1311#Param offset incomplete ##
1312
1313#Return incomplete ##
1314
1315#Example
1316// incomplete
1317##
1318
1319#SeeAlso incomplete
1320
1321#Method ##
1322
1323# ------------------------------------------------------------------------------
1324
Cary Clarka560c472017-11-27 10:44:06 -05001325#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1326
1327##
1328
1329# ------------------------------------------------------------------------------
1330
1331#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1332 sk_sp<SkImage> image,
1333 GrBackendTexture* backendTexture,
1334 BackendTextureReleaseProc* backendTextureReleaseProc)
1335
1336Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1337GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1338responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1339Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1340to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1341themselves.
1342
1343If image is both texture backed and singly referenced; that is, its only
1344reference was transferred using std::move(): image is returned in backendTexture
1345without conversion or making a copy.
1346
1347If the SkImage is not texture backed, this function will generate a texture with the image's
1348contents and return that.
1349
1350#Param context incomplete ##
1351#Param image incomplete ##
1352#Param backendTexture incomplete ##
1353#Param backendTextureReleaseProc incomplete ##
1354
1355#Return incomplete ##
1356
1357#Example
1358// incomplete
1359##
1360
1361#SeeAlso incomplete
1362
1363#Method ##
1364
1365# ------------------------------------------------------------------------------
1366
1367#Enum LegacyBitmapMode
1368
1369#Code
1370 enum LegacyBitmapMode {
1371 kRO_LegacyBitmapMode,
1372 kRW_LegacyBitmapMode,
1373 };
1374##
1375
1376Helper functions to convert to SkBitmap
1377
1378#Const kRO_LegacyBitmapMode 0
1379##
1380#Const kRW_LegacyBitmapMode 1
1381##
1382
1383#Example
1384// incomplete
1385##
1386
1387#SeeAlso incomplete
1388
1389#Enum ##
1390
1391# ------------------------------------------------------------------------------
1392
1393#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
1394
Cary Clark3cd22cc2017-12-01 11:49:58 -05001395Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
1396returned bitmap is read-only and immutable.
1397Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
1398write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05001399
Cary Clark3cd22cc2017-12-01 11:49:58 -05001400#Param bitmap storage for legacy Bitmap ##
1401#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05001402
Cary Clark3cd22cc2017-12-01 11:49:58 -05001403#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05001404
1405#Example
1406// incomplete
1407##
1408
1409#SeeAlso incomplete
1410
1411#Method ##
1412
1413# ------------------------------------------------------------------------------
1414
1415#Method bool isLazyGenerated() const
1416
1417Returns true if Image is backed by an image-generator or other service that creates
1418and caches its pixels or texture on-demand.
1419
Cary Clark2f466242017-12-11 16:03:17 -05001420#Return true if Image is created as needed ##
Cary Clarka560c472017-11-27 10:44:06 -05001421
1422#Example
Cary Clark2f466242017-12-11 16:03:17 -05001423#Height 80
1424#Function
1425class TestImageGenerator : public SkImageGenerator {
1426public:
1427 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
1428 ~TestImageGenerator() override {}
1429protected:
1430 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
1431 const Options& options) override {
1432 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
1433 for (int y = 0; y < info.height(); ++y) {
1434 for (int x = 0; x < info.width(); ++x) {
1435 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
1436 }
1437 }
1438 return true;
1439 }
1440};
1441##
1442void draw(SkCanvas* canvas) {
1443 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
1444 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
1445 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
1446 canvas->scale(8, 8);
1447 canvas->drawImage(image, 0, 0, nullptr);
1448 SkPaint paint;
1449 paint.setTextSize(4);
1450 canvas->drawString(lazy, 2, 5, paint);
1451}
Cary Clarka560c472017-11-27 10:44:06 -05001452##
1453
1454#SeeAlso incomplete
1455
1456#Method ##
1457
1458# ------------------------------------------------------------------------------
1459
1460#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
1461 SkTransferFunctionBehavior premulBehavior) const
1462
1463If target is supported, returns an SkImage in target color space.
1464Otherwise, returns nullptr.
1465This will leave the image as is if it already in target color space.
1466Otherwise, it will convert the pixels from Image color space to target
1467color space. If this->colorSpace() is nullptr, Image color space will be
1468treated as sRGB.
1469
1470If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
1471pixels to a linear space before converting to match destination Color_Type
1472and Color_Space.
1473If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
1474pixels are treated as if they are linear, regardless of how they are encoded.
1475
1476#Param target incomplete ##
1477#Param premulBehavior incomplete ##
1478
1479#Return incomplete ##
1480
1481#Example
1482// incomplete
1483##
1484
1485#SeeAlso incomplete
1486
1487#Method ##
1488
1489#Class SkImage ##
1490
1491#Topic Image ##