blob: 22ba343b64d55f38b9272db7e7041cae0aceedeb [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
28#Subtopic Structs
29#Table
30#Legend
31# description # struct ##
32#Legend ##
33# DeferredTextureImageUsageParams # ##
34#Table ##
35#Subtopic ##
36
37#Subtopic Member_Functions
38#Table
39#Legend
40# description # function ##
41#Legend ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050042# MakeBackendTextureFromSkImage # Creates GPU texture from Image. ##
43# MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ##
44# MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ##
45# MakeFromAdoptedTexture # Creates Image from GPU texture, managed internally. ##
46# MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ##
47# MakeFromDeferredTextureImageData # Creates Image from GPU texture data retrieved earlier. ##
48# MakeFromEncoded # Creates Image from encoded data. ##
49# MakeFromGenerator # Creates Image from a stream of data. ##
50# MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ##
51# MakeFromPicture # Creates Image from Picture. ##
52# MakeFromRaster # Creates Image from Pixmap, with release. ##
53# MakeFromTexture # Creates Image from GPU texture, managed externally. ##
54# MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ##
55# MakeRasterCopy # Creates Image from Pixmap and copied pixels. ##
56# MakeRasterData # Creates Image from Image_Info and shared pixels. ##
57# alphaType # Returns Alpha_Type ##
58# asLegacyBitmap # Returns as raster Bitmap ##
Cary Clarka560c472017-11-27 10:44:06 -050059# bounds # ##
60# colorSpace # ##
61# dimensions # ##
62# encodeToData # ##
63# getDeferredTextureImageData # ##
64# getTexture # ##
65# getTextureHandle # ##
66# height # ##
67# isAlphaOnly # ##
68# isLazyGenerated # ##
69# isOpaque # ##
70# isTextureBacked # ##
71# isValid # ##
72# makeColorSpace # ##
73# makeNonTextureImage # ##
74# makeShader # ##
75# makeSubset # ##
76# makeTextureImage # ##
77# makeWithFilter # ##
78# peekPixels # ##
79# readPixels # ##
80# refColorSpace # ##
81# refEncodedData # ##
82# scalePixels # ##
83# toString # ##
84# uniqueID # ##
85# width # ##
86#Table ##
87#Subtopic ##
88
89#Topic ##
90
91# ------------------------------------------------------------------------------
92
93#Struct DeferredTextureImageUsageParams
94
95#Code
96#ToDo fill this in manually ##
97##
98
99Drawing parameters for which a deferred texture image data should be optimized. */
100
101# ------------------------------------------------------------------------------
102
103#Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality,
104 int preScaleMipLevel)
105
106#Param matrix incomplete ##
107#Param quality incomplete ##
108#Param preScaleMipLevel incomplete ##
109
110#Return incomplete ##
111
112#Example
113// incomplete
114##
115
116#SeeAlso incomplete
117
118#Method ##
119
120#Member SkMatrix fMatrix
121##
122
123#Member SkFilterQuality fQuality
124##
125
126#Member int fPreScaleMipLevel
127##
128
129#Struct DeferredTextureImageUsageParams ##
130
131#Typedef SkImageInfo Info
132
133##
134
Cary Clarka560c472017-11-27 10:44:06 -0500135# ------------------------------------------------------------------------------
136
137#Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)
138
Cary Clark3cd22cc2017-12-01 11:49:58 -0500139Creates Image from Pixmap and copy of pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500140
Cary Clark3cd22cc2017-12-01 11:49:58 -0500141Image is returned if Pixmap is valid. Valid Pixmap parameters include:
142dimensions are greater than zero;
143each dimension fits in 29 bits;
144Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
145row bytes are large enough to hold one row of pixels;
146pixel address is not nullptr.
147
148#Param pixmap Image_Info, pixel address, and row bytes ##
149
150#Return copy of Pixmap pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500151
152#Example
153// incomplete
154##
155
Cary Clark3cd22cc2017-12-01 11:49:58 -0500156#SeeAlso MakeRasterData MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500157
158#Method ##
159
160# ------------------------------------------------------------------------------
161
162#Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes)
163
Cary Clark3cd22cc2017-12-01 11:49:58 -0500164Creates Image from Image_Info, sharing pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500165
Cary Clark3cd22cc2017-12-01 11:49:58 -0500166Image is returned if Image_Info is valid. Valid Image_Info parameters include:
167dimensions are greater than zero;
168each dimension fits in 29 bits;
169Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
170rowBytes are large enough to hold one row of pixels;
171pixels is not nullptr, and contains enough data for Image.
172
173#Param info contains width, height, Alpha_Type, Color_Type, Color_Space ##
174#Param pixels address or pixel storage ##
175#Param rowBytes size of pixel row or larger ##
176
177#Return Image sharing pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500178
179#Example
180// incomplete
181##
182
Cary Clark3cd22cc2017-12-01 11:49:58 -0500183#SeeAlso MakeRasterCopy MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500184
185#Method ##
186
187# ------------------------------------------------------------------------------
188
Cary Clark3cd22cc2017-12-01 11:49:58 -0500189#Typedef void* ReleaseContext
190
191Caller data passed to RasterReleaseProc; may be nullptr.
192
193#SeeAlso MakeFromRaster RasterReleaseProc
194
195##
196
Cary Clarka560c472017-11-27 10:44:06 -0500197#Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext)
198
Cary Clark3cd22cc2017-12-01 11:49:58 -0500199Function called when Image no longer shares pixels. ReleaseContext is
200provided by caller when Image is created, and may be nullptr.
201
202#SeeAlso ReleaseContext MakeFromRaster
203
Cary Clarka560c472017-11-27 10:44:06 -0500204##
205
206#Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
207 RasterReleaseProc rasterReleaseProc,
208 ReleaseContext releaseContext)
209
Cary Clark3cd22cc2017-12-01 11:49:58 -0500210Creates Image from pixmap, sharing pixmap pixels. Pixels must remain valid and
211unchanged until rasterReleaseProc is called. rasterReleaseProc is passed
212releaseContext when Image is deleted or no longer refers to pixmap pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500213
Cary Clark3cd22cc2017-12-01 11:49:58 -0500214Image is returned if pixmap is valid. Valid Pixmap parameters include:
215dimensions are greater than zero;
216each dimension fits in 29 bits;
217Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
218row bytes are large enough to hold one row of pixels;
219pixel address is not nullptr.
220
221#Param pixmap Image_Info, pixel address, and row bytes ##
222#Param rasterReleaseProc function called when pixels can be released ##
223#Param releaseContext state passed to rasterReleaseProc ##
Cary Clarka560c472017-11-27 10:44:06 -0500224
225#Return incomplete ##
226
227#Example
228// incomplete
229##
230
Cary Clark3cd22cc2017-12-01 11:49:58 -0500231#SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
Cary Clarka560c472017-11-27 10:44:06 -0500232
233#Method ##
234
235# ------------------------------------------------------------------------------
236
237#Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)
238
Cary Clark3cd22cc2017-12-01 11:49:58 -0500239Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap
240is marked immutable, and its pixel memory is shareable, it may be shared
241instead of copied.
Cary Clarka560c472017-11-27 10:44:06 -0500242
Cary Clark3cd22cc2017-12-01 11:49:58 -0500243Image is returned if bitmap is valid. Valid Bitmap parameters include:
244dimensions are greater than zero;
245each dimension fits in 29 bits;
246Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
247row bytes are large enough to hold one row of pixels;
248pixel address is not nullptr.
Cary Clarka560c472017-11-27 10:44:06 -0500249
Cary Clark3cd22cc2017-12-01 11:49:58 -0500250#Param bitmap Image_Info, row bytes, and pixels ##
251
252#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500253
254#Example
255// incomplete
256##
257
Cary Clark3cd22cc2017-12-01 11:49:58 -0500258#SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Cary Clarka560c472017-11-27 10:44:06 -0500259
260#Method ##
261
262# ------------------------------------------------------------------------------
263
264#Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
265 const SkIRect* subset = nullptr)
266
Cary Clark3cd22cc2017-12-01 11:49:58 -0500267Creates Image based from imageGenerator.
268Takes ownership of imageGenerator; it may not be used elsewhere.
269If subset is not nullptr, it must be contained within imageGenerator data bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500270
Cary Clark3cd22cc2017-12-01 11:49:58 -0500271Image is returned if generator data is valid. Valid data parameters vary
272by type of data and platform.
Cary Clarka560c472017-11-27 10:44:06 -0500273
Cary Clark3cd22cc2017-12-01 11:49:58 -0500274imageGenerator may wrap Picture data, codec data, or custom data.
275
276#Param imageGenerator stock or custom routines to retrieve Image ##
277#Param subset bounds of returned Image; may be nullptr ##
278
279#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500280
281#Example
282// incomplete
283##
284
Cary Clark3cd22cc2017-12-01 11:49:58 -0500285#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500286
287#Method ##
288
289# ------------------------------------------------------------------------------
290
291#Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)
292
Cary Clark3cd22cc2017-12-01 11:49:58 -0500293Creates Image from encoded data.
294If a subset is not nullptr, it must be contained within encoded data bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500295
Cary Clark3cd22cc2017-12-01 11:49:58 -0500296Image is returned if format of the encoded data is recognized and supported.
297Recognized formats vary by platfrom.
Cary Clarka560c472017-11-27 10:44:06 -0500298
Cary Clark3cd22cc2017-12-01 11:49:58 -0500299#Param encoded data of Image to decode ##
300#Param subset bounds of returned Image; may be nullptr ##
301
302#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500303
304#Example
305// incomplete
306##
307
Cary Clark3cd22cc2017-12-01 11:49:58 -0500308#SeeAlso MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500309
310#Method ##
311
312# ------------------------------------------------------------------------------
313
314#Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext)
315
316##
317
318#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
319 const GrBackendTexture& backendTexture,
320 GrSurfaceOrigin origin,
321 SkAlphaType alphaType,
322 sk_sp<SkColorSpace> colorSpace)
323
Cary Clark3cd22cc2017-12-01 11:49:58 -0500324Creates Image from GPU texture associated with context. Caller is responsible for
325managing the lifetime of GPU texture.
Cary Clarka560c472017-11-27 10:44:06 -0500326
Cary Clark3cd22cc2017-12-01 11:49:58 -0500327Image is returned if format of backendTexture is recognized and supported.
328Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500329
Cary Clark3cd22cc2017-12-01 11:49:58 -0500330#Param context GPU_Context ##
331#Param backendTexture texture residing on GPU ##
332#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
333#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
334 kPremul_SkAlphaType, kUnpremul_SkAlphaType
335##
336#Param colorSpace range of colors ##
337
338#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500339
340#Example
341// incomplete
342##
343
Cary Clark3cd22cc2017-12-01 11:49:58 -0500344#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500345
346#Method ##
347
348# ------------------------------------------------------------------------------
349
350#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
351 const GrBackendTexture& backendTexture,
352 GrSurfaceOrigin origin,
353 SkAlphaType alphaType,
354 sk_sp<SkColorSpace> colorSpace,
355 TextureReleaseProc textureReleaseProc,
356 ReleaseContext releaseContext)
357
Cary Clark3cd22cc2017-12-01 11:49:58 -0500358Creates Image from GPU texture associated with context. GPU texture must stay
359valid and unchanged until textureReleaseProc is called. textureReleaseProc is
360passed releaseContext when Image is deleted or no longer refers to texture.
Cary Clarka560c472017-11-27 10:44:06 -0500361
Cary Clark3cd22cc2017-12-01 11:49:58 -0500362Image is returned if format of backendTexture is recognized and supported.
363Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500364
Cary Clark3cd22cc2017-12-01 11:49:58 -0500365#Param context GPU_Context ##
366#Param backendTexture texture residing on GPU ##
367#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
368#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
369 kPremul_SkAlphaType, kUnpremul_SkAlphaType
370##
371#Param colorSpace range of colors ##
372#Param textureReleaseProc function called when texture can be released ##
373#Param releaseContext state passed to textureReleaseProc ##
374
375#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500376
377#Example
378// incomplete
379##
380
Cary Clark3cd22cc2017-12-01 11:49:58 -0500381#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500382
383#Method ##
384
385# ------------------------------------------------------------------------------
386
387#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
388 bool buildMips,
389 SkColorSpace* dstColorSpace)
390
Cary Clark3cd22cc2017-12-01 11:49:58 -0500391Creates Image from encoded data. Image is uploaded to GPU back-end using context.
392
393Created Image is available to other GPU contexts, and is available across thread
394boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
395share resources.
396
397When Image is no longer referenced, context releases texture memory
Cary Clarka560c472017-11-27 10:44:06 -0500398asynchronously.
Cary Clarka560c472017-11-27 10:44:06 -0500399
Cary Clark3cd22cc2017-12-01 11:49:58 -0500400Texture decoded from data is uploaded to match Surface created with
401dstColorSpace. Color_Space of Image is determined by encoded data.
Cary Clarka560c472017-11-27 10:44:06 -0500402
Cary Clark3cd22cc2017-12-01 11:49:58 -0500403Image is returned if format of data is recognized and supported, and if context
404supports moving resources. Recognized formats vary by platform and GPU back-end.
405
406#Param context GPU_Context ##
407#Param data Image to decode ##
408#Param buildMips create Image as Mip_Map if true ##
409#Param dstColorSpace range of colors of matching Surface on GPU ##
410
411#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500412
413#Example
414// incomplete
415##
416
Cary Clark3cd22cc2017-12-01 11:49:58 -0500417#SeeAlso MakeCrossContextFromPixmap
418
419#Method ##
420
421# ------------------------------------------------------------------------------
422
423#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
424 bool buildMips,
425 SkColorSpace* dstColorSpace)
426
427Creates Image from pixmap. Image is uploaded to GPU back-end using context.
428
429Created Image is available to other GPU contexts, and is available across thread
430boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
431share resources.
432
433When Image is no longer referenced, context releases texture memory
434asynchronously.
435
436Texture created from pixmap is uploaded to match Surface created with
437dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace().
438
439Image is returned referring to GPU back-end if format of data is recognized and
440supported, and if context supports moving resources. Otherwise, pixmap pixel
441data is copied and Image as returned in raster format if possible; nullptr may
442be returned. Recognized GPU formats vary by platform and GPU back-end.
443
444#Param context GPU_Context ##
445#Param pixmap Image_Info, pixel address, and row bytes ##
446#Param buildMips create Image as Mip_Map if true ##
447#Param dstColorSpace range of colors of matching Surface on GPU ##
448
449#Return created Image, or nullptr ##
450
451#Example
452// incomplete
453##
454
455#SeeAlso MakeCrossContextFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500456
457#Method ##
458
459# ------------------------------------------------------------------------------
460
461#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
462 const GrBackendTexture& backendTexture,
463 GrSurfaceOrigin surfaceOrigin,
464 SkAlphaType alphaType = kPremul_SkAlphaType,
465 sk_sp<SkColorSpace> colorSpace = nullptr)
466
Cary Clark3cd22cc2017-12-01 11:49:58 -0500467Creates Image from backendTexture associated with context. backendTexture and
468returned Image are managed internally, and are released when no longer needed.
Cary Clarka560c472017-11-27 10:44:06 -0500469
Cary Clark3cd22cc2017-12-01 11:49:58 -0500470Image is returned if format of backendTexture is recognized and supported.
471Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500472
Cary Clark3cd22cc2017-12-01 11:49:58 -0500473#Param context GPU_Context ##
474#Param backendTexture texture residing on GPU ##
475#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
476#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
477 kPremul_SkAlphaType, kUnpremul_SkAlphaType
478##
479#Param colorSpace range of colors ##
480
481#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500482
483#Example
484// incomplete
485##
486
487#SeeAlso incomplete
488
489#Method ##
490
491# ------------------------------------------------------------------------------
492
493#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
494 const GrBackendObject yuvTextureHandles[3],
495 const SkISize yuvSizes[3],
496 GrSurfaceOrigin surfaceOrigin,
497 sk_sp<SkColorSpace> colorSpace = nullptr)
498
499Create a new image by copying the pixels from the specified y, u, v textures. The data
500from the textures is immediately ingested into the image and the textures can be modified or
501deleted after the function returns. The image will have the dimensions of the y texture.
502
503#Param context incomplete ##
504#Param yuvColorSpace incomplete ##
505#Param yuvTextureHandles incomplete ##
506#Param yuvSizes incomplete ##
507#Param surfaceOrigin incomplete ##
508#Param colorSpace incomplete ##
509
510#Return incomplete ##
511
512#Example
513// incomplete
514##
515
516#SeeAlso incomplete
517
518#Method ##
519
520# ------------------------------------------------------------------------------
521
522#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
523 SkYUVColorSpace yuvColorSpace,
524 const GrBackendObject nv12TextureHandles[2],
525 const SkISize nv12Sizes[2],
526 GrSurfaceOrigin surfaceOrigin,
527 sk_sp<SkColorSpace> colorSpace = nullptr)
528
529Create a new image by copying the pixels from the specified y and UV_Mapping. The data
530from the textures is immediately ingested into the image and the textures can be modified or
531deleted after the function returns. The image will have the dimensions of the y texture.
532
533#Param context incomplete ##
534#Param yuvColorSpace incomplete ##
535#Param nv12TextureHandles incomplete ##
536#Param nv12Sizes incomplete ##
537#Param surfaceOrigin incomplete ##
538#Param colorSpace incomplete ##
539
540#Return incomplete ##
541
542#Example
543// incomplete
544##
545
546#SeeAlso incomplete
547
548#Method ##
549
550# ------------------------------------------------------------------------------
551
552#Enum BitDepth
553
554#Code
555 enum BitDepth {
556 kU8,
557 kF16,
558 };
559##
560
561#Const kU8 0
562##
563#Const kF16 1
564##
565
566#Example
567// incomplete
568##
569
570#SeeAlso incomplete
571
572#Enum ##
573
574# ------------------------------------------------------------------------------
575
576#Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
577 const SkMatrix* matrix, const SkPaint* paint,
578 BitDepth bitDepth,
579 sk_sp<SkColorSpace> colorSpace)
580
581Create a new image from the specified picture.
582On creation of the SkImage, snap the SkPicture to a particular BitDepth and SkColorSpace.
583
584#Param picture incomplete ##
585#Param dimensions incomplete ##
586#Param matrix incomplete ##
587#Param paint incomplete ##
588#Param bitDepth incomplete ##
589#Param colorSpace incomplete ##
590
591#Return incomplete ##
592
593#Example
594// incomplete
595##
596
597#SeeAlso incomplete
598
599#Method ##
600
601# ------------------------------------------------------------------------------
602
603#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
604 SkAlphaType alphaType = kPremul_SkAlphaType,
605 sk_sp<SkColorSpace> colorSpace = nullptr)
606
607 Create a new image from the an Android hardware buffer.
608 The new image takes a reference on the buffer.
609
610 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
611
612#Param hardwareBuffer incomplete ##
613#Param alphaType incomplete ##
614#Param colorSpace incomplete ##
615
616#Return incomplete ##
617
618#Example
619// incomplete
620##
621
622#SeeAlso incomplete
623
624#Method ##
625
626# ------------------------------------------------------------------------------
627
628#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
629 SkAlphaType alphaType = kPremul_SkAlphaType,
630 sk_sp<SkColorSpace> colorSpace = nullptr)
631
632Create a new image from the an Android hardware buffer.
633The new image takes a reference on the buffer.
634
635#Param hardwareBuffer incomplete ##
636#Param alphaType incomplete ##
637#Param colorSpace incomplete ##
638
639#Return incomplete ##
640
641#Example
642// incomplete
643##
644
645#SeeAlso incomplete
646
647#Method ##
648
649# ------------------------------------------------------------------------------
650
651#Method int width() const
652
653#Return incomplete ##
654
655#Example
656// incomplete
657##
658
659#SeeAlso incomplete
660
661#Method ##
662
663# ------------------------------------------------------------------------------
664
665#Method int height() const
666
667#Return incomplete ##
668
669#Example
670// incomplete
671##
672
673#SeeAlso incomplete
674
675#Method ##
676
677# ------------------------------------------------------------------------------
678
679#Method SkISize dimensions() const
680
681#Return incomplete ##
682
683#Example
684// incomplete
685##
686
687#SeeAlso incomplete
688
689#Method ##
690
691# ------------------------------------------------------------------------------
692
693#Method SkIRect bounds() const
694
695#Return incomplete ##
696
697#Example
698// incomplete
699##
700
701#SeeAlso incomplete
702
703#Method ##
704
705# ------------------------------------------------------------------------------
706
707#Method uint32_t uniqueID() const
708
709#Return incomplete ##
710
711#Example
712// incomplete
713##
714
715#SeeAlso incomplete
716
717#Method ##
718
719# ------------------------------------------------------------------------------
720
721#Method SkAlphaType alphaType() const
722
723#Return incomplete ##
724
725#Example
726// incomplete
727##
728
729#SeeAlso incomplete
730
731#Method ##
732
733# ------------------------------------------------------------------------------
734
735#Method SkColorSpace* colorSpace() const
736
737Returns Color_Space of Image. Color_Space may have been a parameter when
738Image was created, or may have been parsed from encoded data. Skia may not be
739able to draw image respecting returned Color_Space or draw into Surface with
740returned Color_Space.
741
742#Return Color_Space Image was created with, or nullptr ##
743
744#Example
745// incomplete
746##
747
748#SeeAlso incomplete
749
750#Method ##
751
752# ------------------------------------------------------------------------------
753
754#Method sk_sp<SkColorSpace> refColorSpace() const
755
756#Return incomplete ##
757
758#Example
759// incomplete
760##
761
762#SeeAlso incomplete
763
764#Method ##
765
766# ------------------------------------------------------------------------------
767
768#Method bool isAlphaOnly() const
769
770Returns true fi the image will be drawn as a mask, with no intrinsic color of its own.
771
772#Return incomplete ##
773
774#Example
775// incomplete
776##
777
778#SeeAlso incomplete
779
780#Method ##
781
782# ------------------------------------------------------------------------------
783
784#Method bool isOpaque() const
785
786#Return incomplete ##
787
788#Example
789// incomplete
790##
791
792#SeeAlso incomplete
793
794#Method ##
795
796# ------------------------------------------------------------------------------
797
798#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
799 const SkMatrix* localMatrix = nullptr) const
800
801#Param tileMode1 incomplete ##
802#Param tileMode2 incomplete ##
803#Param localMatrix incomplete ##
804
805#Return incomplete ##
806
807#Example
808// incomplete
809##
810
811#SeeAlso incomplete
812
813#Method ##
814
815# ------------------------------------------------------------------------------
816
817#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
818
819Helper version of makeShader() that specifies SkShader::kClamp_TileMode.
820
821#Param localMatrix incomplete ##
822
823#Return incomplete ##
824
825#Example
826// incomplete
827##
828
829#SeeAlso incomplete
830
831#Method ##
832
833# ------------------------------------------------------------------------------
834
835#Method bool peekPixels(SkPixmap* pixmap) const
836
837If the image has direct access to its pixels (i.e. they are in local RAM)
838return true, and if not null, return in the pixmap parameter the info about the
839images pixels.
840On failure, return false and ignore the pixmap parameter.
841
842#Param pixmap incomplete ##
843
844#Return incomplete ##
845
846#Example
847// incomplete
848##
849
850#SeeAlso incomplete
851
852#Method ##
853
854# ------------------------------------------------------------------------------
855
856#Method GrTexture* getTexture() const
857
858DEPRECATED -
859#Private
860currently used by Canvas2DLayerBridge in Chromium.
861##
862
863#Return incomplete ##
864
865#Example
866// incomplete
867##
868
869#SeeAlso incomplete
870
871#Method ##
872
873# ------------------------------------------------------------------------------
874
875#Method bool isTextureBacked() const
876
877Returns true if the image is texture backed.
878
879#Return incomplete ##
880
881#Example
882// incomplete
883##
884
885#SeeAlso incomplete
886
887#Method ##
888
889# ------------------------------------------------------------------------------
890
891#Method bool isValid(GrContext* context) const
892
893Returns true if Image can be drawn. If context
894is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image
895draws on GPU_Surface associated with context.
896
897Texture-backed images may become invalid if their underlying GrContext is abandoned. Some
898generator-backed images may be invalid for CPU and/or GPU.
899
900#Param context incomplete ##
901
902#Return incomplete ##
903
904#Example
905// incomplete
906##
907
908#SeeAlso incomplete
909
910#Method ##
911
912# ------------------------------------------------------------------------------
913
914#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
915 GrSurfaceOrigin* origin = nullptr) const
916
917Retrieves the back-end API handle of the texture. If flushPendingGrContextIO then the
918GrContext will issue to the back-end API any deferred I/O operations on the texture before
919returning.
920If 'origin' is supplied it will be filled in with the origin of the content drawn
921into the image.
922
923#Param flushPendingGrContextIO incomplete ##
924#Param origin incomplete ##
925
926#Return incomplete ##
927
928#Example
929// incomplete
930##
931
932#SeeAlso incomplete
933
934#Method ##
935
936# ------------------------------------------------------------------------------
937
938#Enum CachingHint
939
940#Code
941 enum CachingHint {
942 kAllow_CachingHint,
943 kDisallow_CachingHint,
944 };
945##
946
947Hints to image calls where the system might cache computed intermediates (e.g. the results
948of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
949behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
950
951#Const kAllow_CachingHint 0
952##
953#Const kDisallow_CachingHint 1
954##
955
956#Example
957// incomplete
958##
959
960#SeeAlso incomplete
961
962#Enum ##
963
964# ------------------------------------------------------------------------------
965
966#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
967 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
968
969Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
970converting them into the requested format (dstInfo). The image pixels are read
971starting at the specified (srcX, srcY) location.
972dstInfo and (srcX, srcY) offset specifies a source rectangle:
973#Code
974SkRect srcR;
975srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
976##
977
978The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
979then we have two sets of pixels (of equal size). Replace dstPixels with the
980corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
981(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
982This call can fail, returning false, for several reasons:
983if source rectangle does not intersect the image bounds;
984if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
985
986#Param dstInfo incomplete ##
987#Param dstPixels incomplete ##
988#Param dstRowBytes incomplete ##
989#Param srcX incomplete ##
990#Param srcY incomplete ##
991#Param cachingHint incomplete ##
992
993#Return incomplete ##
994
995#Example
996// incomplete
997##
998
999#SeeAlso incomplete
1000
1001#Method ##
1002
1003# ------------------------------------------------------------------------------
1004
1005#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1006 CachingHint cachingHint = kAllow_CachingHint) const
1007
1008#Param dst incomplete ##
1009#Param srcX incomplete ##
1010#Param srcY incomplete ##
1011#Param cachingHint incomplete ##
1012
1013#Return incomplete ##
1014
1015#Example
1016// incomplete
1017##
1018
1019#SeeAlso incomplete
1020
1021#Method ##
1022
1023# ------------------------------------------------------------------------------
1024
1025#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1026 CachingHint cachingHint = kAllow_CachingHint) const
1027
1028Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1029If the conversion cannot be performed, false is returned.
1030If dst dimensions differ from Image dimensions, Image is scaled, applying
1031filterQuality.
1032
1033#Param dst incomplete ##
1034#Param filterQuality incomplete ##
1035#Param cachingHint incomplete ##
1036
1037#Return incomplete ##
1038
1039#Example
1040// incomplete
1041##
1042
1043#SeeAlso incomplete
1044
1045#Method ##
1046
1047# ------------------------------------------------------------------------------
1048
1049#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1050
1051Encode the image's pixels and return the result as SkData.
1052If the image type cannot be encoded, or the requested encoder format is
1053not supported, this will return nullptr.
1054
1055#Param encodedImageFormat incomplete ##
1056#Param quality incomplete ##
1057
1058#Return incomplete ##
1059
1060#Example
1061// incomplete
1062##
1063
1064#SeeAlso incomplete
1065
1066#Method ##
1067
1068# ------------------------------------------------------------------------------
1069
1070#Method sk_sp<SkData> encodeToData(SkPixelSerializer* pixelSerializer = nullptr) const
1071
1072Encodes Image and returns result as SkData. Will reuse existing encoded data
1073if present, as returned by refEncodedData. pixelSerializer validates existing
1074encoded data, and encodes Image when existing encoded data is missing or
1075invalid.
1076
1077Passing nullptr for pixelSerializer selects default serialization which
1078accepts all data and encodes to PNG.
1079
1080Returns nullptr if existing encoded data is missing or invalid and
1081encoding fails.
1082
1083#Param pixelSerializer incomplete ##
1084
1085#Return incomplete ##
1086
1087#Example
1088// incomplete
1089##
1090
1091#SeeAlso incomplete
1092
1093#Method ##
1094
1095# ------------------------------------------------------------------------------
1096
1097#Method sk_sp<SkData> refEncodedData() const
1098
1099If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1100as SkData. If the image does not already has its contents in encoded form, return nullptr.
1101
1102To force the image to return its contents as encoded data, call encodeToData.
1103
1104#Return incomplete ##
1105
1106#Example
1107// incomplete
1108##
1109
1110#SeeAlso incomplete
1111
1112#Method ##
1113
1114# ------------------------------------------------------------------------------
1115
1116#Method const char* toString(SkString* string) const
1117
1118#Param string incomplete ##
1119
1120#Return incomplete ##
1121
1122#Example
1123// incomplete
1124##
1125
1126#SeeAlso incomplete
1127
1128#Method ##
1129
1130# ------------------------------------------------------------------------------
1131
1132#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
1133
1134Return a new image that is a subset of this image. The underlying implementation may
1135share the pixels, or it may make a copy.
1136If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1137nullptr will be returned.
1138
1139#Param subset incomplete ##
1140
1141#Return incomplete ##
1142
1143#Example
1144// incomplete
1145##
1146
1147#SeeAlso incomplete
1148
1149#Method ##
1150
1151# ------------------------------------------------------------------------------
1152
1153#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1154
1155Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1156with surfaces that have the supplied destination color space. If no transformation is
1157required, the returned image may be the same as this image. If this image is from a
1158different GrContext, this will fail.
1159
1160#Param context incomplete ##
1161#Param dstColorSpace incomplete ##
1162
1163#Return incomplete ##
1164
1165#Example
1166// incomplete
1167##
1168
1169#SeeAlso incomplete
1170
1171#Method ##
1172
1173# ------------------------------------------------------------------------------
1174
1175#Method sk_sp<SkImage> makeNonTextureImage() const
1176
1177If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1178the pixels fails). Otherwise, it returns the original image.
1179
1180#Return incomplete ##
1181
1182#Example
1183// incomplete
1184##
1185
1186#SeeAlso incomplete
1187
1188#Method ##
1189
1190# ------------------------------------------------------------------------------
1191
1192#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1193 const SkIRect& clipBounds, SkIRect* outSubset,
1194 SkIPoint* offset) const
1195
1196Apply a given image filter to this image, and return the filtered result.
1197The subset represents the active portion of this image. The return value is similarly an
1198SkImage, with an active subset (outSubset). This is usually used with texture-backed
1199images, where the texture may be approx-match and thus larger than the required size.
1200clipBounds constrains the device-space extent of the image, stored in outSubset.
1201offset is storage, set to the amount to translate the result when drawn.
1202If the result image cannot be created, or the result would be transparent black, null
1203is returned, in which case the offset and outSubset parameters should be ignored by the
1204caller.
1205
1206#Param filter incomplete ##
1207#Param subset incomplete ##
1208#Param clipBounds incomplete ##
1209#Param outSubset incomplete ##
1210#Param offset incomplete ##
1211
1212#Return incomplete ##
1213
1214#Example
1215// incomplete
1216##
1217
1218#SeeAlso incomplete
1219
1220#Method ##
1221
1222# ------------------------------------------------------------------------------
1223
1224#Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy,
1225 const DeferredTextureImageUsageParams deferredTextureImageUsageParams[],
1226 int paramCnt,
1227 void* buffer,
1228 SkColorSpace* dstColorSpace = nullptr,
1229 SkColorType dstColorType = kN32_SkColorType) const
1230
1231This method allows clients to capture the data necessary to turn a SkImage into a texture-
1232backed image. If the original image is codec-backed this will decode into a format optimized
1233for the context represented by the proxy. This method is thread safe with respect to the
1234GrContext whence the proxy came. Clients allocate and manage the storage of the deferred
1235texture data and control its lifetime. No cleanup is required, thus it is safe to simply free
1236the memory out from under the data.
1237
1238The same method is used both for getting the size necessary for uploading
1239and retrieving texture data. The deferredTextureImageUsageParams array represents the set of
1240draws over which to optimize the texture data prior to uploading.
1241
1242When called with a null buffer this returns the size that the client must allocate in order
1243to create deferred texture data for this image (or zero if this is an inappropriate
1244candidate). The buffer allocated by the client should be 8 byte aligned.
1245When buffer is not null this fills in the deferred texture data for this image in the
1246provided buffer (assuming this is an appropriate candidate image and the buffer is
1247appropriately aligned). Upon success the size written is returned, otherwise 0.
1248dstColorSpace is the color space of the surface where this texture will ultimately be used.
1249If the method determines that Mip_Maps are needed, this helps determine the correct strategy
1250for building them (gamma-correct or not).
1251
1252dstColorType is the color type of the surface where this texture will ultimately be used.
1253This determines the format with which the image will be uploaded to the GPU. If dstColorType
1254does not support color spaces (low bit depth types such as kARGB_4444_SkColorType), then dstColorSpace
1255must be null.
1256
1257#Param contextThreadSafeProxy incomplete ##
1258#Param deferredTextureImageUsageParams incomplete ##
1259#Param paramCnt incomplete ##
1260#Param buffer incomplete ##
1261#Param dstColorSpace incomplete ##
1262#Param dstColorType incomplete ##
1263
1264#Return incomplete ##
1265
1266#Example
1267// incomplete
1268##
1269
1270#SeeAlso incomplete
1271
1272#Method ##
1273
1274# ------------------------------------------------------------------------------
1275
1276#Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data,
1277 SkBudgeted budgeted)
1278
Cary Clark3cd22cc2017-12-01 11:49:58 -05001279Returns a texture-backed image from data produced in getDeferredTextureImageData.
Cary Clarka560c472017-11-27 10:44:06 -05001280The context must be the context that provided the proxy passed to
1281getDeferredTextureImageData.
1282
Cary Clark3cd22cc2017-12-01 11:49:58 -05001283#Param context GPU_Context ##
1284#Param data buffer filled by getDeferredTextureImageData ##
1285#Param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes ##
Cary Clarka560c472017-11-27 10:44:06 -05001286
1287#Return incomplete ##
1288
1289#Example
Cary Clark3cd22cc2017-12-01 11:49:58 -05001290#Image 3
1291#Platform gpu
1292 GrContext* context = canvas->getGrContext();
1293 if (!context) {
1294 return;
1295 }
1296 sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
1297 SkImage::DeferredTextureImageUsageParams params = {SkMatrix::I(), kNone_SkFilterQuality, 0};
1298 size_t size = image->getDeferredTextureImageData(*proxy, &params, 1, nullptr,
1299 nullptr, kN32_SkColorType);
1300 void* buffer = sk_malloc_throw(size);
1301 if (image->getDeferredTextureImageData(*proxy, &params, 1, buffer, nullptr, kN32_SkColorType)) {
1302 sk_sp<SkImage> newImage(
1303 SkImage::MakeFromDeferredTextureImageData(context, buffer, SkBudgeted::kNo));
1304 canvas->drawImage(newImage, 0, 0);
1305 }
Cary Clarka560c472017-11-27 10:44:06 -05001306##
1307
1308#SeeAlso incomplete
1309
1310#Method ##
1311
1312#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1313
1314##
1315
1316# ------------------------------------------------------------------------------
1317
1318#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1319 sk_sp<SkImage> image,
1320 GrBackendTexture* backendTexture,
1321 BackendTextureReleaseProc* backendTextureReleaseProc)
1322
1323Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1324GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1325responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1326Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1327to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1328themselves.
1329
1330If image is both texture backed and singly referenced; that is, its only
1331reference was transferred using std::move(): image is returned in backendTexture
1332without conversion or making a copy.
1333
1334If the SkImage is not texture backed, this function will generate a texture with the image's
1335contents and return that.
1336
1337#Param context incomplete ##
1338#Param image incomplete ##
1339#Param backendTexture incomplete ##
1340#Param backendTextureReleaseProc incomplete ##
1341
1342#Return incomplete ##
1343
1344#Example
1345// incomplete
1346##
1347
1348#SeeAlso incomplete
1349
1350#Method ##
1351
1352# ------------------------------------------------------------------------------
1353
1354#Enum LegacyBitmapMode
1355
1356#Code
1357 enum LegacyBitmapMode {
1358 kRO_LegacyBitmapMode,
1359 kRW_LegacyBitmapMode,
1360 };
1361##
1362
1363Helper functions to convert to SkBitmap
1364
1365#Const kRO_LegacyBitmapMode 0
1366##
1367#Const kRW_LegacyBitmapMode 1
1368##
1369
1370#Example
1371// incomplete
1372##
1373
1374#SeeAlso incomplete
1375
1376#Enum ##
1377
1378# ------------------------------------------------------------------------------
1379
1380#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
1381
Cary Clark3cd22cc2017-12-01 11:49:58 -05001382Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
1383returned bitmap is read-only and immutable.
1384Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
1385write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05001386
Cary Clark3cd22cc2017-12-01 11:49:58 -05001387#Param bitmap storage for legacy Bitmap ##
1388#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05001389
Cary Clark3cd22cc2017-12-01 11:49:58 -05001390#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05001391
1392#Example
1393// incomplete
1394##
1395
1396#SeeAlso incomplete
1397
1398#Method ##
1399
1400# ------------------------------------------------------------------------------
1401
1402#Method bool isLazyGenerated() const
1403
1404Returns true if Image is backed by an image-generator or other service that creates
1405and caches its pixels or texture on-demand.
1406
1407#Return incomplete ##
1408
1409#Example
1410// incomplete
1411##
1412
1413#SeeAlso incomplete
1414
1415#Method ##
1416
1417# ------------------------------------------------------------------------------
1418
1419#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
1420 SkTransferFunctionBehavior premulBehavior) const
1421
1422If target is supported, returns an SkImage in target color space.
1423Otherwise, returns nullptr.
1424This will leave the image as is if it already in target color space.
1425Otherwise, it will convert the pixels from Image color space to target
1426color space. If this->colorSpace() is nullptr, Image color space will be
1427treated as sRGB.
1428
1429If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
1430pixels to a linear space before converting to match destination Color_Type
1431and Color_Space.
1432If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
1433pixels are treated as if they are linear, regardless of how they are encoded.
1434
1435#Param target incomplete ##
1436#Param premulBehavior incomplete ##
1437
1438#Return incomplete ##
1439
1440#Example
1441// incomplete
1442##
1443
1444#SeeAlso incomplete
1445
1446#Method ##
1447
1448#Class SkImage ##
1449
1450#Topic Image ##