Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Image |
| 2 | #Alias Image_Reference |
| 3 | |
| 4 | #Class SkImage |
| 5 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 6 | Image describes a two dimensional array of pixels to draw. The pixels may be |
| 7 | unencoded in a Raster_Bitmap, encoded in a Picture or compressed data stream, |
| 8 | or located in GPU memory as a GPU_Texture. |
| 9 | |
| 10 | Image cannot be modified after it is created. Image may allocate additional |
| 11 | storage as needed; for instance, an encoded Image may decode when drawn. |
| 12 | |
| 13 | Image width and height are greater than zero. Creating an Image with zero width |
| 14 | or height returns Image equal to nullptr. |
| 15 | |
| 16 | Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams, |
| 17 | GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported |
| 18 | include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encodings details |
| 19 | vary with platform. |
| 20 | |
| 21 | #Topic Raster_Image |
| 22 | #Alias Raster_Image |
| 23 | Raster_Image pixels are unencoded in a Raster_Bitmap. These pixels may be read |
| 24 | directly and in most cases written to, although edited pixels may not be drawn |
| 25 | if Image has been copied internally. |
| 26 | ## |
| 27 | |
| 28 | #Topic Texture_Image |
| 29 | Texture_Image are located on GPU and pixels are not accessible. Texture_Image |
| 30 | are allocated optimally for best performance. Raster_Image may |
| 31 | be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading |
| 32 | performance. |
| 33 | ## |
| 34 | |
| 35 | #Topic Lazy_Image |
| 36 | Lazy_Image defer allocating buffer for Image pixels and decoding stream until |
| 37 | Image is drawn. Lazy_Image caches result if possible to speed up repeated |
| 38 | drawing. |
| 39 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 40 | |
| 41 | #Topic Overview |
| 42 | |
| 43 | #Subtopic Subtopics |
| 44 | #ToDo manually add subtopics ## |
| 45 | #Table |
| 46 | #Legend |
| 47 | # topics # description ## |
| 48 | #Legend ## |
| 49 | #Table ## |
| 50 | ## |
| 51 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 52 | #Subtopic Member_Functions |
| 53 | #Table |
| 54 | #Legend |
| 55 | # description # function ## |
| 56 | #Legend ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 57 | # MakeBackendTextureFromSkImage # Creates GPU_Texture from Image. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 58 | # MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ## |
| 59 | # MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 60 | # MakeFromAdoptedTexture # Creates Image from GPU_Texture, managed internally. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 61 | # MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 62 | # MakeFromDeferredTextureImageData # ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 63 | # MakeFromEncoded # Creates Image from encoded data. ## |
| 64 | # MakeFromGenerator # Creates Image from a stream of data. ## |
| 65 | # MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ## |
| 66 | # MakeFromPicture # Creates Image from Picture. ## |
| 67 | # MakeFromRaster # Creates Image from Pixmap, with release. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 68 | # MakeFromTexture # Creates Image from GPU_Texture, managed externally. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 69 | # MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ## |
| 70 | # MakeRasterCopy # Creates Image from Pixmap and copied pixels. ## |
| 71 | # MakeRasterData # Creates Image from Image_Info and shared pixels. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 72 | # alphaType # Returns Alpha_Type. ## |
| 73 | # asLegacyBitmap # Returns as Raster_Bitmap. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 74 | # bounds() # Returns width() and height() as Rectangle. ## |
| 75 | # colorSpace # Returns Color_Space. ## |
| 76 | # dimensions() # Returns width() and height(). ## |
| 77 | # encodeToData # Returns encoded Image as SkData. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 78 | # getDeferredTextureImageData # ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 79 | # getTexture # Deprecated. ## |
| 80 | # getTextureHandle # Returns GPU reference to Image as texture. ## |
| 81 | # height() # Returns pixel row count. ## |
| 82 | # isAlphaOnly # Returns if pixels represent a transparency mask. ## |
| 83 | # isLazyGenerated # Returns if Image is created as needed. ## |
| 84 | # isOpaque # Returns if Alpha_Type is kOpaque_SkAlphaType. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 85 | # isTextureBacked # Returns if Image was created from GPU_Texture. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 86 | # isValid # Returns if Image can draw to Raster_Surface or GPU_Context. ## |
| 87 | # makeColorSpace # Creates Image matching Color_Space if possible. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 88 | # makeNonTextureImage # Creates Image without dependency on GPU_Texture. ## |
| 89 | # makeRasterImage # Creates Image compatible with Raster_Surface if possible. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 90 | # makeShader # Creates Shader, Paint element that can tile Image. ## |
| 91 | # makeSubset # Creates Image containing part of original. ## |
| 92 | # makeTextureImage # Creates Image matching Color_Space if possible. ## |
| 93 | # makeWithFilter # Creates filtered, clipped Image. ## |
| 94 | # peekPixels # Returns Pixmap if possible. ## |
| 95 | # readPixels # Copies and converts pixels. ## |
| 96 | # refColorSpace # Returns Image_Info Color_Space. ## |
| 97 | # refEncodedData # Returns Image encoded in SkData if present. ## |
| 98 | # scalePixels # Scales and converts one Image to another. ## |
| 99 | # toString # Converts Image to machine readable form. ## |
| 100 | # uniqueID # Identifier for Image. ## |
| 101 | # width() # Returns pixel column count. ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 102 | #Table ## |
| 103 | #Subtopic ## |
| 104 | |
| 105 | #Topic ## |
| 106 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 107 | #Typedef SkImageInfo Info |
| 108 | |
| 109 | ## |
| 110 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 111 | # ------------------------------------------------------------------------------ |
| 112 | |
| 113 | #Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap) |
| 114 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 115 | Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap |
| 116 | pixels may be modified or deleted without affecting Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 117 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 118 | Image is returned if Pixmap is valid. Valid Pixmap parameters include: |
| 119 | dimensions are greater than zero; |
| 120 | each dimension fits in 29 bits; |
| 121 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 122 | row bytes are large enough to hold one row of pixels; |
| 123 | pixel address is not nullptr. |
| 124 | |
| 125 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 126 | |
| 127 | #Return copy of Pixmap pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 128 | |
| 129 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 130 | #Height 50 |
| 131 | #Description |
| 132 | Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap |
| 133 | alters the bitmap draw, but does not alter the Image draw since the Image |
| 134 | contains a copy of the pixels. |
| 135 | ## |
| 136 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 137 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 138 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 139 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 140 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 141 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 142 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 143 | SkBitmap bitmap; |
| 144 | bitmap.installPixels(pixmap); |
| 145 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 146 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 147 | canvas->scale(10, 10); |
| 148 | canvas->drawBitmap(bitmap, 0, 0); |
| 149 | canvas->drawImage(image, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 150 | ## |
| 151 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 152 | #SeeAlso MakeRasterData MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 153 | |
| 154 | #Method ## |
| 155 | |
| 156 | # ------------------------------------------------------------------------------ |
| 157 | |
| 158 | #Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes) |
| 159 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 160 | Creates Image from Image_Info, sharing pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 161 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 162 | Image is returned if Image_Info is valid. Valid Image_Info parameters include: |
| 163 | dimensions are greater than zero; |
| 164 | each dimension fits in 29 bits; |
| 165 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 166 | rowBytes are large enough to hold one row of pixels; |
| 167 | pixels is not nullptr, and contains enough data for Image. |
| 168 | |
| 169 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 170 | #Param pixels address or pixel storage ## |
| 171 | #Param rowBytes size of pixel row or larger ## |
| 172 | |
| 173 | #Return Image sharing pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 174 | |
| 175 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 176 | #Image 3 |
| 177 | size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); |
| 178 | sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height()); |
| 179 | SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(), |
| 180 | kPremul_SkAlphaType); |
| 181 | image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint); |
| 182 | sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType), |
| 183 | data, rowBytes); |
| 184 | canvas->drawImage(image, 0, 0); |
| 185 | canvas->drawImage(raw.get(), 128, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 186 | ## |
| 187 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 188 | #SeeAlso MakeRasterCopy MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 189 | |
| 190 | #Method ## |
| 191 | |
| 192 | # ------------------------------------------------------------------------------ |
| 193 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 194 | #Typedef void* ReleaseContext |
| 195 | |
| 196 | Caller data passed to RasterReleaseProc; may be nullptr. |
| 197 | |
| 198 | #SeeAlso MakeFromRaster RasterReleaseProc |
| 199 | |
| 200 | ## |
| 201 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 202 | #Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext) |
| 203 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 204 | Function called when Image no longer shares pixels. ReleaseContext is |
| 205 | provided by caller when Image is created, and may be nullptr. |
| 206 | |
| 207 | #SeeAlso ReleaseContext MakeFromRaster |
| 208 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 209 | ## |
| 210 | |
| 211 | #Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, |
| 212 | RasterReleaseProc rasterReleaseProc, |
| 213 | ReleaseContext releaseContext) |
| 214 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 215 | Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 216 | unchanged until rasterReleaseProc is called. rasterReleaseProc is passed |
| 217 | releaseContext when Image is deleted or no longer refers to pixmap pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 218 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 219 | Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback |
| 220 | when Image is released. Pass nullptr for releaseContext if rasterReleaseProc |
| 221 | does not require state. |
| 222 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 223 | Image is returned if pixmap is valid. Valid Pixmap parameters include: |
| 224 | dimensions are greater than zero; |
| 225 | each dimension fits in 29 bits; |
| 226 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 227 | row bytes are large enough to hold one row of pixels; |
| 228 | pixel address is not nullptr. |
| 229 | |
| 230 | #Param pixmap Image_Info, pixel address, and row bytes ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 231 | #Param rasterReleaseProc function called when pixels can be released; or nullptr ## |
| 232 | #Param releaseContext state passed to rasterReleaseProc; or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 233 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 234 | #Return Image sharing pixmap ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 235 | |
| 236 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 237 | #Function |
| 238 | static void releaseProc(const void* pixels, SkImage::ReleaseContext context) { |
| 239 | int* countPtr = static_cast<int*>(context); |
| 240 | *countPtr += 1; |
| 241 | } |
| 242 | ## |
| 243 | |
| 244 | void draw(SkCanvas* canvas) { |
| 245 | SkColor color = 0; |
| 246 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4); |
| 247 | int releaseCount = 0; |
| 248 | sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount)); |
| 249 | SkDebugf("before reset: %d\n", releaseCount); |
| 250 | image.reset(); |
| 251 | SkDebugf("after reset: %d\n", releaseCount); |
| 252 | } |
| 253 | #StdOut |
| 254 | before reset: 0 |
| 255 | after reset: 1 |
| 256 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 257 | ## |
| 258 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 259 | #SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 260 | |
| 261 | #Method ## |
| 262 | |
| 263 | # ------------------------------------------------------------------------------ |
| 264 | |
| 265 | #Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap) |
| 266 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 267 | Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap |
| 268 | is marked immutable, and its pixel memory is shareable, it may be shared |
| 269 | instead of copied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 270 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 271 | Image is returned if bitmap is valid. Valid Bitmap parameters include: |
| 272 | dimensions are greater than zero; |
| 273 | each dimension fits in 29 bits; |
| 274 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 275 | row bytes are large enough to hold one row of pixels; |
| 276 | pixel address is not nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 277 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 278 | #Param bitmap Image_Info, row bytes, and pixels ## |
| 279 | |
| 280 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 281 | |
| 282 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 283 | #Description |
| 284 | The first Bitmap is shared; writing to the pixel memory changes the first |
| 285 | Image. |
| 286 | The second Bitmap is marked immutable, and is copied; writing to the pixel |
| 287 | memory does not alter the second Image. |
| 288 | ## |
| 289 | #Height 50 |
| 290 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 291 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 292 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 293 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 294 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 295 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 296 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 297 | SkBitmap bitmap; |
| 298 | bitmap.installPixels(pixmap); |
| 299 | sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap); |
| 300 | bitmap.setImmutable(); |
| 301 | sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap); |
| 302 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 303 | canvas->scale(10, 10); |
| 304 | canvas->drawImage(image1, 0, 0); |
| 305 | canvas->drawImage(image2, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 306 | ## |
| 307 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 308 | #SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 309 | |
| 310 | #Method ## |
| 311 | |
| 312 | # ------------------------------------------------------------------------------ |
| 313 | |
| 314 | #Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator, |
| 315 | const SkIRect* subset = nullptr) |
| 316 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 317 | Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not |
| 318 | be shared or accessed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 319 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 320 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 321 | otherwise, subset must be contained by image bounds. |
| 322 | |
| 323 | Image is returned if generator data is valid. Valid data parameters vary by type of data |
| 324 | and platform. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 325 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 326 | imageGenerator may wrap Picture data, codec data, or custom data. |
| 327 | |
| 328 | #Param imageGenerator stock or custom routines to retrieve Image ## |
| 329 | #Param subset bounds of returned Image; may be nullptr ## |
| 330 | |
| 331 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 332 | |
| 333 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 334 | #Description |
| 335 | The generator returning Picture cannot be shared; std::move transfers ownership to generated Image. |
| 336 | ## |
| 337 | SkPictureRecorder recorder; |
| 338 | recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); |
| 339 | auto picture = recorder.finishRecordingAsPicture(); |
| 340 | auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, |
| 341 | SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
| 342 | sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen)); |
| 343 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 344 | ## |
| 345 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 346 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 347 | |
| 348 | #Method ## |
| 349 | |
| 350 | # ------------------------------------------------------------------------------ |
| 351 | |
| 352 | #Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr) |
| 353 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 354 | Creates Image from encoded data. |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 355 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 356 | otherwise, subset must be contained by image bounds. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 357 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 358 | Image is returned if format of the encoded data is recognized and supported. |
| 359 | Recognized formats vary by platfrom. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 360 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 361 | #Param encoded data of Image to decode ## |
| 362 | #Param subset bounds of returned Image; may be nullptr ## |
| 363 | |
| 364 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 365 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 366 | #Example |
| 367 | #Image 3 |
| 368 | int x = 0; |
| 369 | for (int quality : { 100, 50, 10, 1} ) { |
| 370 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality); |
| 371 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(encodedData); |
| 372 | canvas->drawImage(image, x, 0); |
| 373 | x += 64; |
| 374 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 375 | ## |
| 376 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 377 | #SeeAlso MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 378 | |
| 379 | #Method ## |
| 380 | |
| 381 | # ------------------------------------------------------------------------------ |
| 382 | |
| 383 | #Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext) |
| 384 | |
| 385 | ## |
| 386 | |
| 387 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 388 | const GrBackendTexture& backendTexture, |
| 389 | GrSurfaceOrigin origin, |
| 390 | SkAlphaType alphaType, |
| 391 | sk_sp<SkColorSpace> colorSpace) |
| 392 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 393 | Deprecated. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 394 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 395 | #Param context GPU_Context ## |
| 396 | #Param backendTexture texture residing on GPU ## |
| 397 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 398 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 399 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 400 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 401 | #Param colorSpace range of colors; may be nullptr ## |
| 402 | |
| 403 | #Return created Image, or nullptr ## |
| 404 | |
| 405 | #NoExample |
| 406 | ## |
| 407 | |
| 408 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
| 409 | |
| 410 | #Method ## |
| 411 | |
| 412 | # ------------------------------------------------------------------------------ |
| 413 | |
| 414 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 415 | const GrBackendTexture& backendTexture, |
| 416 | GrSurfaceOrigin origin, |
| 417 | SkAlphaType alphaType, |
| 418 | sk_sp<SkColorSpace> colorSpace, |
| 419 | TextureReleaseProc textureReleaseProc, |
| 420 | ReleaseContext releaseContext) |
| 421 | |
| 422 | Deprecated. |
| 423 | |
| 424 | #Param context GPU_Context ## |
| 425 | #Param backendTexture texture residing on GPU ## |
| 426 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 427 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 428 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 429 | ## |
| 430 | #Param colorSpace range of colors; may be nullptr ## |
| 431 | #Param textureReleaseProc function called when texture can be released ## |
| 432 | #Param releaseContext state passed to textureReleaseProc ## |
| 433 | |
| 434 | #Return created Image, or nullptr ## |
| 435 | |
| 436 | #NoExample |
| 437 | ## |
| 438 | |
| 439 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
| 440 | |
| 441 | #Method ## |
| 442 | |
| 443 | # ------------------------------------------------------------------------------ |
| 444 | |
| 445 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 446 | const GrBackendTexture& backendTexture, |
| 447 | GrSurfaceOrigin origin, |
| 448 | SkColorType colorType, |
| 449 | SkAlphaType alphaType, |
| 450 | sk_sp<SkColorSpace> colorSpace) |
| 451 | |
| 452 | Creates Image from GPU_Texture associated with context. Caller is responsible for |
| 453 | managing the lifetime of GPU_Texture. |
| 454 | |
| 455 | Image is returned if format of backendTexture is recognized and supported. |
| 456 | Recognized formats vary by GPU back-end. |
| 457 | |
| 458 | #Param context GPU_Context ## |
| 459 | #Param backendTexture texture residing on GPU ## |
| 460 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 461 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 462 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 463 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 464 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 465 | ## |
| 466 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 467 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 468 | ## |
| 469 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 470 | |
| 471 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 472 | |
| 473 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 474 | #Image 3 |
| 475 | #Platform gpu |
| 476 | #Height 128 |
| 477 | #Description |
| 478 | A back-end texture has been created and uploaded to the GPU outside of this example. |
| 479 | ## |
| 480 | GrContext* context = canvas->getGrContext(); |
| 481 | if (!context) { |
| 482 | return; |
| 483 | } |
| 484 | canvas->scale(.25f, .25f); |
| 485 | int x = 0; |
| 486 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 487 | sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 488 | origin, kOpaque_SkAlphaType, nullptr); |
| 489 | canvas->drawImage(image, x, 0); |
| 490 | x += 512; |
| 491 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 492 | ## |
| 493 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 494 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 495 | |
| 496 | #Method ## |
| 497 | |
| 498 | # ------------------------------------------------------------------------------ |
| 499 | |
| 500 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 501 | const GrBackendTexture& backendTexture, |
| 502 | GrSurfaceOrigin origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 503 | SkColorType colorType, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 504 | SkAlphaType alphaType, |
| 505 | sk_sp<SkColorSpace> colorSpace, |
| 506 | TextureReleaseProc textureReleaseProc, |
| 507 | ReleaseContext releaseContext) |
| 508 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 509 | Creates Image from GPU_Texture associated with context. GPU_Texture must stay |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 510 | valid and unchanged until textureReleaseProc is called. textureReleaseProc is |
| 511 | passed releaseContext when Image is deleted or no longer refers to texture. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 512 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 513 | Image is returned if format of backendTexture is recognized and supported. |
| 514 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 515 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 516 | #Param context GPU_Context ## |
| 517 | #Param backendTexture texture residing on GPU ## |
| 518 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 519 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 520 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 521 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 522 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 523 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 524 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 525 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 526 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 527 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 528 | #Param textureReleaseProc function called when texture can be released ## |
| 529 | #Param releaseContext state passed to textureReleaseProc ## |
| 530 | |
| 531 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 532 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 533 | #ToDo |
| 534 | This doesn't do anything clever with TextureReleaseProc because it may not get called |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 535 | fwithin the lifetime of the example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 536 | ## |
| 537 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 538 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 539 | GrContext* context = canvas->getGrContext(); |
| 540 | if (!context) { |
| 541 | return; |
| 542 | } |
| 543 | auto debugster = [](SkImage::ReleaseContext context) -> void { |
| 544 | *((int *) context) += 128; |
| 545 | }; |
| 546 | int x = 0; |
| 547 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 548 | sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 549 | origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 550 | canvas->drawImage(image, x, 0); |
| 551 | x += 128; |
| 552 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 553 | ## |
| 554 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 555 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 556 | |
| 557 | #Method ## |
| 558 | |
| 559 | # ------------------------------------------------------------------------------ |
| 560 | |
| 561 | #Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, |
| 562 | bool buildMips, |
| 563 | SkColorSpace* dstColorSpace) |
| 564 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 565 | Creates Image from encoded data. Image is uploaded to GPU back-end using context. |
| 566 | |
| 567 | Created Image is available to other GPU contexts, and is available across thread |
| 568 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 569 | share resources. |
| 570 | |
| 571 | When Image is no longer referenced, context releases texture memory |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 572 | asynchronously. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 573 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 574 | Texture decoded from data is uploaded to match Surface created with |
| 575 | dstColorSpace. Color_Space of Image is determined by encoded data. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 576 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 577 | Image is returned if format of data is recognized and supported, and if context |
| 578 | supports moving resources. Recognized formats vary by platform and GPU back-end. |
| 579 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 580 | Image is returned using MakeFromEncoded if context is nullptr or does not support |
| 581 | moving resources between contexts. |
| 582 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 583 | #Param context GPU_Context ## |
| 584 | #Param data Image to decode ## |
| 585 | #Param buildMips create Image as Mip_Map if true ## |
| 586 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 587 | |
| 588 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 589 | |
| 590 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 591 | #Image 4 |
| 592 | #Height 128 |
| 593 | GrContext* context = canvas->getGrContext(); |
| 594 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100); |
| 595 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context, |
| 596 | encodedData, false, nullptr); |
| 597 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 598 | ## |
| 599 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 600 | #SeeAlso MakeCrossContextFromPixmap |
| 601 | |
| 602 | #Method ## |
| 603 | |
| 604 | # ------------------------------------------------------------------------------ |
| 605 | |
| 606 | #Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, |
| 607 | bool buildMips, |
| 608 | SkColorSpace* dstColorSpace) |
| 609 | |
| 610 | Creates Image from pixmap. Image is uploaded to GPU back-end using context. |
| 611 | |
| 612 | Created Image is available to other GPU contexts, and is available across thread |
| 613 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 614 | share resources. |
| 615 | |
| 616 | When Image is no longer referenced, context releases texture memory |
| 617 | asynchronously. |
| 618 | |
| 619 | Texture created from pixmap is uploaded to match Surface created with |
| 620 | dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace(). |
| 621 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 622 | Image is returned referring to GPU back-end if context is not nullptr, |
| 623 | format of data is recognized and supported, and if context supports moving |
| 624 | resources between contexts. Otherwise, pixmap pixel data is copied and Image |
| 625 | as returned in raster format if possible; nullptr may be returned. |
| 626 | Recognized GPU formats vary by platform and GPU back-end. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 627 | |
| 628 | #Param context GPU_Context ## |
| 629 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 630 | #Param buildMips create Image as Mip_Map if true ## |
| 631 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 632 | |
| 633 | #Return created Image, or nullptr ## |
| 634 | |
| 635 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 636 | #Image 4 |
| 637 | #Height 128 |
| 638 | GrContext* context = canvas->getGrContext(); |
| 639 | SkPixmap pixmap; |
| 640 | if (source.peekPixels(&pixmap)) { |
| 641 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, |
| 642 | false, nullptr); |
| 643 | canvas->drawImage(image, 0, 0); |
| 644 | } |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 645 | ## |
| 646 | |
| 647 | #SeeAlso MakeCrossContextFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 648 | |
| 649 | #Method ## |
| 650 | |
| 651 | # ------------------------------------------------------------------------------ |
| 652 | |
| 653 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 654 | const GrBackendTexture& backendTexture, |
| 655 | GrSurfaceOrigin surfaceOrigin, |
| 656 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 657 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 658 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 659 | Deprecated. |
| 660 | |
| 661 | #Param context GPU_Context ## |
| 662 | #Param backendTexture texture residing on GPU ## |
| 663 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 664 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 665 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 666 | ## |
| 667 | #Param colorSpace range of colors; may be nullptr ## |
| 668 | |
| 669 | #Return created Image, or nullptr ## |
| 670 | |
| 671 | #NoExample |
| 672 | ## |
| 673 | |
| 674 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
| 675 | |
| 676 | #Method ## |
| 677 | |
| 678 | # ------------------------------------------------------------------------------ |
| 679 | |
| 680 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 681 | const GrBackendTexture& backendTexture, |
| 682 | GrSurfaceOrigin surfaceOrigin, |
| 683 | SkColorType colorType, |
| 684 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 685 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 686 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 687 | Creates Image from backendTexture associated with context. backendTexture and |
| 688 | returned Image are managed internally, and are released when no longer needed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 689 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 690 | Image is returned if format of backendTexture is recognized and supported. |
| 691 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 692 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 693 | #Param context GPU_Context ## |
| 694 | #Param backendTexture texture residing on GPU ## |
| 695 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 696 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 697 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 698 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 699 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 700 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 701 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 702 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 703 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 704 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 705 | |
| 706 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 707 | |
| 708 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 709 | if (!canvas->getGrContext()) { |
| 710 | return; |
| 711 | } |
| 712 | canvas->scale(.5f, .5f); |
| 713 | canvas->clear(0x7f3f5f7f); |
| 714 | int x = 0, y = 0; |
| 715 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 716 | for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 717 | sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(), |
| 718 | backEndTexture, origin, |
| 719 | kRGBA_8888_SkColorType, alpha); |
| 720 | canvas->drawImage(image, x, y); |
| 721 | x += 160; |
| 722 | } |
| 723 | x -= 160 * 3; |
| 724 | y += 256; |
| 725 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 726 | ## |
| 727 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 728 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 729 | |
| 730 | #Method ## |
| 731 | |
| 732 | # ------------------------------------------------------------------------------ |
| 733 | |
| 734 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 735 | const GrBackendObject yuvTextureHandles[3], |
| 736 | const SkISize yuvSizes[3], |
| 737 | GrSurfaceOrigin surfaceOrigin, |
| 738 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 739 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 740 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 741 | yuvTextureHandles contain pixels for YUV planes of Image. |
| 742 | yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 743 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 744 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 745 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 746 | #Param context GPU_Context ## |
| 747 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 748 | kRec709_SkYUVColorSpace |
| 749 | ## |
| 750 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 751 | #Param yuvSizes dimensions of YUV textures ## |
| 752 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 753 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 754 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 755 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 756 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 757 | # seems too complicated to create an example for this |
| 758 | #ToDo |
| 759 | should this be moved to chrome only? |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 760 | ## |
| 761 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 762 | #NoExample |
| 763 | ## |
| 764 | |
| 765 | #SeeAlso MakeFromNV12TexturesCopy |
| 766 | |
| 767 | #Method ## |
| 768 | |
| 769 | # ------------------------------------------------------------------------------ |
| 770 | |
| 771 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 772 | const GrBackendTexture yuvTextureHandles[3], |
| 773 | const SkISize yuvSizes[3], |
| 774 | GrSurfaceOrigin surfaceOrigin, |
| 775 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 776 | |
| 777 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 778 | yuvTextureHandles contain pixels for YUV planes of Image. |
| 779 | yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 780 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 781 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 782 | |
| 783 | #Param context GPU_Context ## |
| 784 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 785 | kRec709_SkYUVColorSpace |
| 786 | ## |
| 787 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 788 | #Param yuvSizes dimensions of YUV textures ## |
| 789 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 790 | #Param colorSpace range of colors; may be nullptr ## |
| 791 | |
| 792 | #Return created Image, or nullptr ## |
| 793 | |
| 794 | # seems too complicated to create an example for this |
| 795 | #ToDo |
| 796 | should this be moved to chrome only? |
| 797 | ## |
| 798 | |
| 799 | #NoExample |
| 800 | ## |
| 801 | |
| 802 | #SeeAlso MakeFromNV12TexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 803 | |
| 804 | #Method ## |
| 805 | |
| 806 | # ------------------------------------------------------------------------------ |
| 807 | |
| 808 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 809 | SkYUVColorSpace yuvColorSpace, |
| 810 | const GrBackendObject nv12TextureHandles[2], |
| 811 | const SkISize nv12Sizes[2], |
| 812 | GrSurfaceOrigin surfaceOrigin, |
| 813 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 814 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 815 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 816 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 817 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 818 | followed by pixels for YUV_Component_V plane. |
| 819 | nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 820 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 821 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 822 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 823 | #Param context GPU_Context ## |
| 824 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 825 | kRec709_SkYUVColorSpace |
| 826 | ## |
| 827 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 828 | #Param nv12Sizes dimensions of YUV textures ## |
| 829 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 830 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 831 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 832 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 833 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 834 | # seems too complicated to create an example for this |
| 835 | #ToDo |
| 836 | should this be moved to chrome only? |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 837 | ## |
| 838 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 839 | #NoExample |
| 840 | ## |
| 841 | |
| 842 | #SeeAlso MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 843 | |
| 844 | #Method ## |
| 845 | |
| 846 | # ------------------------------------------------------------------------------ |
| 847 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 848 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 849 | SkYUVColorSpace yuvColorSpace, |
| 850 | const GrBackendTexture nv12TextureHandles[2], |
| 851 | const SkISize nv12Sizes[2], |
| 852 | GrSurfaceOrigin surfaceOrigin, |
| 853 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 854 | |
| 855 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 856 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 857 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 858 | followed by pixels for YUV_Component_V plane. |
| 859 | nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 860 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 861 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 862 | |
| 863 | #Param context GPU_Context ## |
| 864 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 865 | kRec709_SkYUVColorSpace |
| 866 | ## |
| 867 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 868 | #Param nv12Sizes dimensions of YUV textures ## |
| 869 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 870 | #Param colorSpace range of colors; may be nullptr ## |
| 871 | |
| 872 | #Return created Image, or nullptr ## |
| 873 | |
| 874 | # seems too complicated to create an example for this |
| 875 | #ToDo |
| 876 | should this be moved to chrome only? |
| 877 | ## |
| 878 | |
| 879 | #NoExample |
| 880 | ## |
| 881 | |
| 882 | #SeeAlso MakeFromYUVTexturesCopy |
| 883 | |
| 884 | #Method ## |
| 885 | |
| 886 | # ------------------------------------------------------------------------------ |
| 887 | |
| 888 | #Bug 7424 |
| 889 | currently uncalled by any test or client |
| 890 | ## |
| 891 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 892 | #Enum BitDepth |
| 893 | |
| 894 | #Code |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 895 | enum class BitDepth { |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 896 | kU8, |
| 897 | kF16, |
| 898 | }; |
| 899 | ## |
| 900 | |
| 901 | #Const kU8 0 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 902 | Use 8 bits per Color_ARGB component using unsigned integer format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 903 | ## |
| 904 | #Const kF16 1 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 905 | Use 16 bits per Color_ARGB component using half-precision floating point format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 906 | ## |
| 907 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 908 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 909 | ## |
| 910 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 911 | #SeeAlso MakeFromPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 912 | |
| 913 | #Enum ## |
| 914 | |
| 915 | # ------------------------------------------------------------------------------ |
| 916 | |
| 917 | #Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, |
| 918 | const SkMatrix* matrix, const SkPaint* paint, |
| 919 | BitDepth bitDepth, |
| 920 | sk_sp<SkColorSpace> colorSpace) |
| 921 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 922 | Creates Image from picture. Returned Image width and height are set by dimensions. |
| 923 | Image draws picture with matrix and paint, set to bitDepth and colorSpace. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 924 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 925 | If matrix is nullptr, draws with identity Matrix. If paint is nullptr, draws |
| 926 | with default Paint. colorSpace may be nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 927 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 928 | #Param picture stream of drawing commands ## |
| 929 | #Param dimensions width and height ## |
| 930 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 931 | #Param paint Paint to apply transparency, filtering, and so on; may be nullptr ## |
| 932 | #Param bitDepth 8 bit integer or 16 bit float: per component ## |
| 933 | #Param colorSpace range of colors; may be nullptr ## |
| 934 | |
| 935 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 936 | |
| 937 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 938 | SkPaint paint; |
| 939 | SkPictureRecorder recorder; |
| 940 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 941 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 942 | paint.setColor(color); |
| 943 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 944 | recordingCanvas->translate(10, 10); |
| 945 | recordingCanvas->scale(1.2f, 1.4f); |
| 946 | } |
| 947 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 948 | int x = 0, y = 0; |
| 949 | for (auto alpha : { 70, 140, 210 } ) { |
| 950 | paint.setAlpha(alpha); |
| 951 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
| 952 | sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, |
| 953 | SkImage::BitDepth::kU8, srgbColorSpace); |
| 954 | canvas->drawImage(image, x, y); |
| 955 | x += 70; y += 70; |
| 956 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 957 | ## |
| 958 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 959 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 960 | |
| 961 | #Method ## |
| 962 | |
| 963 | # ------------------------------------------------------------------------------ |
| 964 | |
| 965 | #Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, |
| 966 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 967 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 968 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 969 | #Bug 7447 ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 970 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 971 | Creates Image from Android hardware buffer. |
| 972 | Returned Image takes a reference on the buffer. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 973 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 974 | Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 975 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 976 | #Param hardwareBuffer AHardwareBuffer Android hardware buffer ## |
| 977 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 978 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 979 | ## |
| 980 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 981 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 982 | #Return created Image, or nullptr ## |
| 983 | |
| 984 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 985 | ## |
| 986 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 987 | #SeeAlso MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 988 | |
| 989 | #Method ## |
| 990 | |
| 991 | # ------------------------------------------------------------------------------ |
| 992 | |
| 993 | #Method int width() const |
| 994 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 995 | Returns pixel count in each row. |
| 996 | |
| 997 | #Return pixel width in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 998 | |
| 999 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1000 | #Image 4 |
| 1001 | #Height 168 |
| 1002 | canvas->translate(10, 10); |
| 1003 | canvas->drawImage(image, 0, 0); |
| 1004 | canvas->translate(0, image->height()); |
| 1005 | SkPaint paint; |
| 1006 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1007 | canvas->drawLine(0, 10, image->width(), 10, paint); |
| 1008 | canvas->drawString("width", image->width() / 2, 25, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1009 | ## |
| 1010 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1011 | #SeeAlso dimensions() height() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1012 | |
| 1013 | #Method ## |
| 1014 | |
| 1015 | # ------------------------------------------------------------------------------ |
| 1016 | |
| 1017 | #Method int height() const |
| 1018 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1019 | Returns pixel row count. |
| 1020 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1021 | #Return pixel height in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1022 | |
| 1023 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1024 | #Image 4 |
| 1025 | #Height 148 |
| 1026 | canvas->translate(10, 10); |
| 1027 | canvas->drawImage(image, 0, 0); |
| 1028 | canvas->translate(image->width(), 0); |
| 1029 | SkPaint paint; |
| 1030 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1031 | paint.setVerticalText(true); |
| 1032 | canvas->drawLine(10, 0, 10, image->height(), paint); |
| 1033 | canvas->drawString("height", 25, image->height() / 2, paint);## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1034 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1035 | #SeeAlso dimensions() width() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1036 | |
| 1037 | #Method ## |
| 1038 | |
| 1039 | # ------------------------------------------------------------------------------ |
| 1040 | |
| 1041 | #Method SkISize dimensions() const |
| 1042 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1043 | Returns ISize { width(), height() }. |
| 1044 | |
| 1045 | #Return integral size of width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1046 | |
| 1047 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1048 | #Image 4 |
| 1049 | SkISize dimensions = image->dimensions(); |
| 1050 | SkIRect bounds = image->bounds(); |
| 1051 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 1052 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1053 | ## |
| 1054 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1055 | #SeeAlso height() width() bounds() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1056 | |
| 1057 | #Method ## |
| 1058 | |
| 1059 | # ------------------------------------------------------------------------------ |
| 1060 | |
| 1061 | #Method SkIRect bounds() const |
| 1062 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1063 | Returns IRect { 0, 0, width(), height() }. |
| 1064 | |
| 1065 | #Return integral rectangle from origin to width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1066 | |
| 1067 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1068 | #Height 128 |
| 1069 | #Image 4 |
| 1070 | canvas->scale(.5f, .5f); |
| 1071 | SkIRect bounds = image->bounds(); |
| 1072 | for (int x : { 0, image->width() } ) { |
| 1073 | for (int y : { 0, image->height() } ) { |
| 1074 | canvas->drawImage(image, x, y); |
| 1075 | } |
| 1076 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1077 | ## |
| 1078 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1079 | #SeeAlso dimensions() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1080 | |
| 1081 | #Method ## |
| 1082 | |
| 1083 | # ------------------------------------------------------------------------------ |
| 1084 | |
| 1085 | #Method uint32_t uniqueID() const |
| 1086 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1087 | Returns value unique to image. Image contents cannot change after Image is |
| 1088 | created. Any operation to create a new Image will receive generate a new |
| 1089 | unique number. |
| 1090 | |
| 1091 | #Return unique identifier ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1092 | |
| 1093 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1094 | #Image 5 |
| 1095 | #Height 156 |
| 1096 | sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100}); |
| 1097 | canvas->drawImage(image, 0, 0); |
| 1098 | canvas->drawImage(subset, 128, 0); |
| 1099 | SkPaint paint; |
| 1100 | SkString s; |
| 1101 | s.printf("original id: %d", image->uniqueID()); |
| 1102 | canvas->drawString(s, 20, image->height() + 20, paint); |
| 1103 | s.printf("subset id: %d", subset->uniqueID()); |
| 1104 | canvas->drawString(s, 148, subset->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1105 | ## |
| 1106 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1107 | #SeeAlso isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1108 | |
| 1109 | #Method ## |
| 1110 | |
| 1111 | # ------------------------------------------------------------------------------ |
| 1112 | |
| 1113 | #Method SkAlphaType alphaType() const |
| 1114 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1115 | Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 1116 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 1117 | |
| 1118 | Alpha_Type returned was a parameter to an Image constructor, |
| 1119 | or was parsed from encoded data. |
| 1120 | |
| 1121 | #Return Alpha_Type in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1122 | |
| 1123 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1124 | #Image 4 |
| 1125 | #Height 156 |
| 1126 | const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 1127 | SkAlphaType alphaType = image->alphaType(); |
| 1128 | canvas->drawImage(image, 0, 0); |
| 1129 | SkPaint paint; |
| 1130 | canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1131 | ## |
| 1132 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1133 | #SeeAlso SkImageInfo::alphaType |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1134 | |
| 1135 | #Method ## |
| 1136 | |
| 1137 | # ------------------------------------------------------------------------------ |
| 1138 | |
| 1139 | #Method SkColorSpace* colorSpace() const |
| 1140 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1141 | Returns Color_Space, the range of colors, associated with Image. The |
| 1142 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 1143 | immutable. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1144 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1145 | Color_Space returned was passed to an Image constructor, |
| 1146 | or was parsed from encoded data. Color_Space returned may be ignored when Image |
| 1147 | is drawn, depending on the capabilities of the Surface receiving the drawing. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1148 | |
| 1149 | #Return Color_Space in Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1150 | |
| 1151 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1152 | #Image 3 |
| 1153 | #Set sRGB |
| 1154 | SkPixmap pixmap; |
| 1155 | source.peekPixels(&pixmap); |
| 1156 | canvas->scale(.25f, .25f); |
| 1157 | int y = 0; |
| 1158 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 1159 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 1160 | int x = 0; |
| 1161 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 1162 | for (int index = 0; index < 2; ++index) { |
| 1163 | pixmap.setColorSpace(colorSpace); |
| 1164 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 1165 | canvas->drawImage(image, x, y); |
| 1166 | colorSpace = image->colorSpace()->makeColorSpin(); |
| 1167 | x += 512; |
| 1168 | } |
| 1169 | y += 512; |
| 1170 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1171 | ## |
| 1172 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1173 | #SeeAlso refColorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1174 | |
| 1175 | #Method ## |
| 1176 | |
| 1177 | # ------------------------------------------------------------------------------ |
| 1178 | |
| 1179 | #Method sk_sp<SkColorSpace> refColorSpace() const |
| 1180 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1181 | Returns a smart pointer to Color_Space, the range of colors, associated with |
| 1182 | Image. The smart pointer tracks the number of objects sharing this |
| 1183 | SkColorSpace reference so the memory is released when the owners destruct. |
| 1184 | |
| 1185 | The returned SkColorSpace is immutable. |
| 1186 | |
| 1187 | Color_Space returned was passed to an Image constructor, |
| 1188 | or was parsed from encoded data. Color_Space returned may be ignored when Image |
| 1189 | is drawn, depending on the capabilities of the Surface receiving the drawing. |
| 1190 | |
| 1191 | #Return Color_Space in Image, or nullptr, wrapped in a smart pointer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1192 | |
| 1193 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1194 | #Image 3 |
| 1195 | #Set sRGB |
| 1196 | SkPixmap pixmap; |
| 1197 | source.peekPixels(&pixmap); |
| 1198 | canvas->scale(.25f, .25f); |
| 1199 | int y = 0; |
| 1200 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 1201 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 1202 | int x = 0; |
| 1203 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 1204 | for (int index = 0; index < 2; ++index) { |
| 1205 | pixmap.setColorSpace(colorSpace); |
| 1206 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 1207 | canvas->drawImage(image, x, y); |
| 1208 | colorSpace = image->refColorSpace()->makeColorSpin(); |
| 1209 | x += 512; |
| 1210 | } |
| 1211 | y += 512; |
| 1212 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1213 | ## |
| 1214 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1215 | #SeeAlso colorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1216 | |
| 1217 | #Method ## |
| 1218 | |
| 1219 | # ------------------------------------------------------------------------------ |
| 1220 | |
| 1221 | #Method bool isAlphaOnly() const |
| 1222 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1223 | Returns true if Image pixels represent transparency only. If true, each pixel |
| 1224 | is packed in 8 bits as defined by kAlpha_8_SkColorType. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1225 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1226 | #Return true if pixels represent a transparency mask ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1227 | |
| 1228 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1229 | uint8_t pmColors = 0; |
| 1230 | sk_sp<SkImage> image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1}); |
| 1231 | SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false"); |
| 1232 | #StdOut |
| 1233 | alphaOnly = true |
| 1234 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1235 | ## |
| 1236 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1237 | #SeeAlso alphaType isOpaque |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1238 | |
| 1239 | #Method ## |
| 1240 | |
| 1241 | # ------------------------------------------------------------------------------ |
| 1242 | |
| 1243 | #Method bool isOpaque() const |
| 1244 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1245 | Returns true if pixels ignore their Alpha value and are treated as fully opaque. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1246 | |
| 1247 | #Return true if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1248 | |
| 1249 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1250 | auto check_isopaque = [](const SkImageInfo& imageInfo) -> void { |
| 1251 | auto surface(SkSurface::MakeRaster(imageInfo)); |
| 1252 | auto image(surface->makeImageSnapshot()); |
| 1253 | SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false"); |
| 1254 | }; |
| 1255 | |
| 1256 | check_isopaque(SkImageInfo::MakeN32Premul(5, 5)); |
| 1257 | check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)); |
| 1258 | #StdOut |
| 1259 | isOpaque = false |
| 1260 | isOpaque = true |
| 1261 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1262 | ## |
| 1263 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1264 | #SeeAlso alphaType isAlphaOnly |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1265 | |
| 1266 | #Method ## |
| 1267 | |
| 1268 | # ------------------------------------------------------------------------------ |
| 1269 | |
| 1270 | #Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, |
| 1271 | const SkMatrix* localMatrix = nullptr) const |
| 1272 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1273 | Creates Shader from Image. Shader dimensions are taken from Image. Shader uses |
| 1274 | SkShader::TileMode rules to fill drawn area outside Image. localMatrix permits |
| 1275 | transforming Image before Canvas_Matrix is applied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1276 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1277 | #Param tileMode1 tiling in x, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, |
| 1278 | SkShader::kMirror_TileMode |
| 1279 | ## |
| 1280 | #Param tileMode2 tiling in y, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, |
| 1281 | SkShader::kMirror_TileMode |
| 1282 | ## |
| 1283 | #Param localMatrix Image transformation, or nullptr ## |
| 1284 | |
| 1285 | #Return Shader containing Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1286 | |
| 1287 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1288 | #Image 4 |
| 1289 | SkMatrix matrix; |
| 1290 | matrix.setRotate(45); |
| 1291 | SkPaint paint; |
| 1292 | paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, |
| 1293 | &matrix)); |
| 1294 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1295 | ## |
| 1296 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1297 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1298 | |
| 1299 | #Method ## |
| 1300 | |
| 1301 | # ------------------------------------------------------------------------------ |
| 1302 | |
| 1303 | #Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const |
| 1304 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1305 | Creates Shader from Image. Shader dimensions are taken from Image. Shader uses |
| 1306 | SkShader::kClamp_TileMode to fill drawn area outside Image. localMatrix permits |
| 1307 | transforming Image before Canvas_Matrix is applied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1308 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1309 | #Param localMatrix Image transformation, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1310 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1311 | #Return Shader containing Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1312 | |
| 1313 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1314 | #Image 5 |
| 1315 | SkMatrix matrix; |
| 1316 | matrix.setRotate(45); |
| 1317 | matrix.postTranslate(125, 30); |
| 1318 | SkPaint paint; |
| 1319 | paint.setShader(image->makeShader(&matrix)); |
| 1320 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1321 | ## |
| 1322 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1323 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1324 | |
| 1325 | #Method ## |
| 1326 | |
| 1327 | # ------------------------------------------------------------------------------ |
| 1328 | |
| 1329 | #Method bool peekPixels(SkPixmap* pixmap) const |
| 1330 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1331 | Copies Image pixel address, row bytes, and Image_Info to pixmap, if address |
| 1332 | is available, and returns true. If pixel address is not available, return |
| 1333 | false and leave pixmap unchanged. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1334 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1335 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1336 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1337 | #Return true if Image has direct access to pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1338 | |
| 1339 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1340 | SkBitmap bitmap; |
| 1341 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11)); |
| 1342 | SkCanvas offscreen(bitmap); |
| 1343 | offscreen.clear(SK_ColorWHITE); |
| 1344 | SkPaint paint; |
| 1345 | offscreen.drawString("%", 1, 10, paint); |
| 1346 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 1347 | SkPixmap pixmap; |
| 1348 | if (image->peekPixels(&pixmap)) { |
| 1349 | const SkPMColor* pixels = pixmap.addr32(); |
| 1350 | SkPMColor pmWhite = pixels[0]; |
| 1351 | for (int y = 0; y < image->height(); ++y) { |
| 1352 | for (int x = 0; x < image->width(); ++x) { |
| 1353 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 1354 | } |
| 1355 | SkDebugf("\n"); |
| 1356 | } |
| 1357 | } |
| 1358 | #StdOut |
| 1359 | ------------ |
| 1360 | --xx----x--- |
| 1361 | -x--x--x---- |
| 1362 | -x--x--x---- |
| 1363 | -x--x-x----- |
| 1364 | --xx-xx-xx-- |
| 1365 | -----x-x--x- |
| 1366 | ----x--x--x- |
| 1367 | ----x--x--x- |
| 1368 | ---x----xx-- |
| 1369 | ------------ |
| 1370 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1371 | ## |
| 1372 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1373 | #SeeAlso readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1374 | |
| 1375 | #Method ## |
| 1376 | |
| 1377 | # ------------------------------------------------------------------------------ |
| 1378 | |
| 1379 | #Method GrTexture* getTexture() const |
| 1380 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1381 | Deprecated. |
| 1382 | |
| 1383 | #Deprecated |
| 1384 | ## |
| 1385 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1386 | #Private |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1387 | Currently used by Canvas2DLayerBridge in Chromium. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1388 | ## |
| 1389 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1390 | #Method ## |
| 1391 | |
| 1392 | # ------------------------------------------------------------------------------ |
| 1393 | |
| 1394 | #Method bool isTextureBacked() const |
| 1395 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1396 | Returns true the contents of Image was created on or uploaded to GPU memory, |
| 1397 | and is available as a GPU_Texture. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1398 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1399 | #Return true if Image is a GPU_Texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1400 | |
| 1401 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1402 | #Image 5 |
| 1403 | #Platform gpu |
| 1404 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1405 | if (nullptr == image) { |
| 1406 | return; |
| 1407 | } |
| 1408 | SkPaint paint; |
| 1409 | paint.setAntiAlias(true); |
| 1410 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1411 | canvas->drawImage(image, 0, 0); |
| 1412 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1413 | canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", |
| 1414 | image->width() / 2, image->height() * 3 / 4, paint); |
| 1415 | }; |
| 1416 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1417 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1418 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1419 | drawImage(image, "image"); |
| 1420 | canvas->translate(image->width(), 0); |
| 1421 | drawImage(bitmapImage, "source"); |
| 1422 | canvas->translate(-image->width(), image->height()); |
| 1423 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1424 | ## |
| 1425 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1426 | #SeeAlso MakeFromTexture isValid |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1427 | |
| 1428 | #Method ## |
| 1429 | |
| 1430 | # ------------------------------------------------------------------------------ |
| 1431 | |
| 1432 | #Method bool isValid(GrContext* context) const |
| 1433 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1434 | Returns true if Image can be drawn on either Raster_Surface or GPU_Surface. |
| 1435 | If context is nullptr, tests if Image draws on Raster_Surface; |
| 1436 | otherwise, tests if Image draws on GPU_Surface associated with context. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1437 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1438 | Image backed by GPU_Texture may become invalid if associated GrContext is |
| 1439 | invalid. Lazy_Image may be invalid and may not draw to Raster_Surface or |
| 1440 | GPU_Surface or both. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1441 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1442 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1443 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1444 | #Return true if Image can be drawn ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1445 | |
| 1446 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1447 | #Image 5 |
| 1448 | #Platform gpu |
| 1449 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1450 | if (nullptr == image) { |
| 1451 | return; |
| 1452 | } |
| 1453 | SkPaint paint; |
| 1454 | paint.setAntiAlias(true); |
| 1455 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1456 | canvas->drawImage(image, 0, 0); |
| 1457 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1458 | if (canvas->getGrContext()) { |
| 1459 | canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : |
| 1460 | "not valid on GPU", image->width() / 2, image->height() * 5 / 8, paint); |
| 1461 | } |
| 1462 | canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : |
| 1463 | "not valid on CPU", image->width() / 2, image->height() * 7 / 8, paint); |
| 1464 | }; |
| 1465 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1466 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1467 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1468 | drawImage(image, "image"); |
| 1469 | canvas->translate(image->width(), 0); |
| 1470 | drawImage(bitmapImage, "source"); |
| 1471 | canvas->translate(-image->width(), image->height()); |
| 1472 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1473 | ## |
| 1474 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 1475 | #SeeAlso isTextureBacked isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1476 | |
| 1477 | #Method ## |
| 1478 | |
| 1479 | # ------------------------------------------------------------------------------ |
| 1480 | |
| 1481 | #Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO, |
| 1482 | GrSurfaceOrigin* origin = nullptr) const |
| 1483 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1484 | Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true, |
| 1485 | complete deferred I/O operations. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1486 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1487 | If origin in not nullptr, copies location of content drawn into Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1488 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1489 | #Param flushPendingGrContextIO flag to flush outstanding requests ## |
| 1490 | #Param origin storage for one of: kTopLeft_GrSurfaceOrigin, |
| 1491 | kBottomLeft_GrSurfaceOrigin; or nullptr |
| 1492 | ## |
| 1493 | |
| 1494 | #Return back-end API texture handle ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1495 | |
| 1496 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1497 | #Image 3 |
| 1498 | #Platform gpu |
| 1499 | GrContext* context = canvas->getGrContext(); |
| 1500 | if (!context) { |
| 1501 | return; |
| 1502 | } |
| 1503 | SkPaint paint; |
| 1504 | paint.setAntiAlias(true); |
| 1505 | SkString str; |
| 1506 | int y = 0; |
| 1507 | for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 1508 | sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context, |
| 1509 | backEndTexture, origin, kPremul_SkAlphaType, nullptr)); |
| 1510 | GrSurfaceOrigin readBackOrigin; |
| 1511 | GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin); |
| 1512 | str.printf("readBackHandle: %x", readBackHandle); |
| 1513 | canvas->drawString(str, 5, y += 20, paint); |
| 1514 | str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft"); |
| 1515 | canvas->drawString(str, 5, y += 20, paint); |
| 1516 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1517 | ## |
| 1518 | |
| 1519 | #SeeAlso incomplete |
| 1520 | |
| 1521 | #Method ## |
| 1522 | |
| 1523 | # ------------------------------------------------------------------------------ |
| 1524 | |
| 1525 | #Enum CachingHint |
| 1526 | |
| 1527 | #Code |
| 1528 | enum CachingHint { |
| 1529 | kAllow_CachingHint, |
| 1530 | kDisallow_CachingHint, |
| 1531 | }; |
| 1532 | ## |
| 1533 | |
| 1534 | Hints to image calls where the system might cache computed intermediates (e.g. the results |
| 1535 | of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default |
| 1536 | behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided. |
| 1537 | |
| 1538 | #Const kAllow_CachingHint 0 |
| 1539 | ## |
| 1540 | #Const kDisallow_CachingHint 1 |
| 1541 | ## |
| 1542 | |
| 1543 | #Example |
| 1544 | // incomplete |
| 1545 | ## |
| 1546 | |
| 1547 | #SeeAlso incomplete |
| 1548 | |
| 1549 | #Enum ## |
| 1550 | |
| 1551 | # ------------------------------------------------------------------------------ |
| 1552 | |
| 1553 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1554 | int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const |
| 1555 | |
| 1556 | Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes), |
| 1557 | converting them into the requested format (dstInfo). The image pixels are read |
| 1558 | starting at the specified (srcX, srcY) location. |
| 1559 | dstInfo and (srcX, srcY) offset specifies a source rectangle: |
| 1560 | #Code |
| 1561 | SkRect srcR; |
| 1562 | srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); |
| 1563 | ## |
| 1564 | |
| 1565 | The source rectangle is intersected with the bounds of the image. If this intersection is not empty, |
| 1566 | then we have two sets of pixels (of equal size). Replace dstPixels with the |
| 1567 | corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed |
| 1568 | (in the case where Image and dstInfo have different Color_Types or Alpha_Types). |
| 1569 | This call can fail, returning false, for several reasons: |
| 1570 | if source rectangle does not intersect the image bounds; |
| 1571 | if the requested Color_Type/Alpha_Type cannot be converted from the image's types. |
| 1572 | |
| 1573 | #Param dstInfo incomplete ## |
| 1574 | #Param dstPixels incomplete ## |
| 1575 | #Param dstRowBytes incomplete ## |
| 1576 | #Param srcX incomplete ## |
| 1577 | #Param srcY incomplete ## |
| 1578 | #Param cachingHint incomplete ## |
| 1579 | |
| 1580 | #Return incomplete ## |
| 1581 | |
| 1582 | #Example |
| 1583 | // incomplete |
| 1584 | ## |
| 1585 | |
| 1586 | #SeeAlso incomplete |
| 1587 | |
| 1588 | #Method ## |
| 1589 | |
| 1590 | # ------------------------------------------------------------------------------ |
| 1591 | |
| 1592 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY, |
| 1593 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1594 | |
| 1595 | #Param dst incomplete ## |
| 1596 | #Param srcX incomplete ## |
| 1597 | #Param srcY incomplete ## |
| 1598 | #Param cachingHint incomplete ## |
| 1599 | |
| 1600 | #Return incomplete ## |
| 1601 | |
| 1602 | #Example |
| 1603 | // incomplete |
| 1604 | ## |
| 1605 | |
| 1606 | #SeeAlso incomplete |
| 1607 | |
| 1608 | #Method ## |
| 1609 | |
| 1610 | # ------------------------------------------------------------------------------ |
| 1611 | |
| 1612 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, |
| 1613 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1614 | |
| 1615 | Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type. |
| 1616 | If the conversion cannot be performed, false is returned. |
| 1617 | If dst dimensions differ from Image dimensions, Image is scaled, applying |
| 1618 | filterQuality. |
| 1619 | |
| 1620 | #Param dst incomplete ## |
| 1621 | #Param filterQuality incomplete ## |
| 1622 | #Param cachingHint incomplete ## |
| 1623 | |
| 1624 | #Return incomplete ## |
| 1625 | |
| 1626 | #Example |
| 1627 | // incomplete |
| 1628 | ## |
| 1629 | |
| 1630 | #SeeAlso incomplete |
| 1631 | |
| 1632 | #Method ## |
| 1633 | |
| 1634 | # ------------------------------------------------------------------------------ |
| 1635 | |
| 1636 | #Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const |
| 1637 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1638 | Encodes Image pixels, returning result as SkData. |
| 1639 | |
| 1640 | Returns nullptr if encoding fails, or encodedImageFormat is not supported. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1641 | |
| 1642 | #Param encodedImageFormat incomplete ## |
| 1643 | #Param quality incomplete ## |
| 1644 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1645 | #Return encoded Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1646 | |
| 1647 | #Example |
| 1648 | // incomplete |
| 1649 | ## |
| 1650 | |
| 1651 | #SeeAlso incomplete |
| 1652 | |
| 1653 | #Method ## |
| 1654 | |
| 1655 | # ------------------------------------------------------------------------------ |
| 1656 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1657 | #Method sk_sp<SkData> encodeToData() const |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1658 | |
| 1659 | Encodes Image and returns result as SkData. Will reuse existing encoded data |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1660 | if present, as returned by refEncodedData. If encoded data is missing or invalid, |
| 1661 | Image is encoded as PNG. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1662 | |
| 1663 | Returns nullptr if existing encoded data is missing or invalid and |
| 1664 | encoding fails. |
| 1665 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1666 | #Return incomplete ## |
| 1667 | |
| 1668 | #Example |
| 1669 | // incomplete |
| 1670 | ## |
| 1671 | |
| 1672 | #SeeAlso incomplete |
| 1673 | |
| 1674 | #Method ## |
| 1675 | |
| 1676 | # ------------------------------------------------------------------------------ |
| 1677 | |
| 1678 | #Method sk_sp<SkData> refEncodedData() const |
| 1679 | |
| 1680 | If the image already has its contents in encoded form (e.g. PNG or JPEG), return that |
| 1681 | as SkData. If the image does not already has its contents in encoded form, return nullptr. |
| 1682 | |
| 1683 | To force the image to return its contents as encoded data, call encodeToData. |
| 1684 | |
| 1685 | #Return incomplete ## |
| 1686 | |
| 1687 | #Example |
| 1688 | // incomplete |
| 1689 | ## |
| 1690 | |
| 1691 | #SeeAlso incomplete |
| 1692 | |
| 1693 | #Method ## |
| 1694 | |
| 1695 | # ------------------------------------------------------------------------------ |
| 1696 | |
| 1697 | #Method const char* toString(SkString* string) const |
| 1698 | |
| 1699 | #Param string incomplete ## |
| 1700 | |
| 1701 | #Return incomplete ## |
| 1702 | |
| 1703 | #Example |
| 1704 | // incomplete |
| 1705 | ## |
| 1706 | |
| 1707 | #SeeAlso incomplete |
| 1708 | |
| 1709 | #Method ## |
| 1710 | |
| 1711 | # ------------------------------------------------------------------------------ |
| 1712 | |
| 1713 | #Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const |
| 1714 | |
| 1715 | Return a new image that is a subset of this image. The underlying implementation may |
| 1716 | share the pixels, or it may make a copy. |
| 1717 | If subset does not intersect the bounds of this image, or the copy/share cannot be made, |
| 1718 | nullptr will be returned. |
| 1719 | |
| 1720 | #Param subset incomplete ## |
| 1721 | |
| 1722 | #Return incomplete ## |
| 1723 | |
| 1724 | #Example |
| 1725 | // incomplete |
| 1726 | ## |
| 1727 | |
| 1728 | #SeeAlso incomplete |
| 1729 | |
| 1730 | #Method ## |
| 1731 | |
| 1732 | # ------------------------------------------------------------------------------ |
| 1733 | |
| 1734 | #Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const |
| 1735 | |
| 1736 | Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use |
| 1737 | with surfaces that have the supplied destination color space. If no transformation is |
| 1738 | required, the returned image may be the same as this image. If this image is from a |
| 1739 | different GrContext, this will fail. |
| 1740 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1741 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1742 | #Param dstColorSpace incomplete ## |
| 1743 | |
| 1744 | #Return incomplete ## |
| 1745 | |
| 1746 | #Example |
| 1747 | // incomplete |
| 1748 | ## |
| 1749 | |
| 1750 | #SeeAlso incomplete |
| 1751 | |
| 1752 | #Method ## |
| 1753 | |
| 1754 | # ------------------------------------------------------------------------------ |
| 1755 | |
| 1756 | #Method sk_sp<SkImage> makeNonTextureImage() const |
| 1757 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1758 | Creates raster Image if Image contains GPU_Texture and raster Image , this will make a raster copy of it (or nullptr if reading back |
| 1759 | the pixels fails). Otherwise, it returns the original image. |
| 1760 | |
| 1761 | #Return incomplete ## |
| 1762 | |
| 1763 | #Example |
| 1764 | // incomplete |
| 1765 | ## |
| 1766 | |
| 1767 | #SeeAlso incomplete |
| 1768 | |
| 1769 | #Method ## |
| 1770 | |
| 1771 | # ------------------------------------------------------------------------------ |
| 1772 | |
| 1773 | #Method sk_sp<SkImage> makeRasterImage() const |
| 1774 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1775 | If the image is texture-backed this will make a raster copy of it (or nullptr if reading back |
| 1776 | the pixels fails). Otherwise, it returns the original image. |
| 1777 | |
| 1778 | #Return incomplete ## |
| 1779 | |
| 1780 | #Example |
| 1781 | // incomplete |
| 1782 | ## |
| 1783 | |
| 1784 | #SeeAlso incomplete |
| 1785 | |
| 1786 | #Method ## |
| 1787 | |
| 1788 | # ------------------------------------------------------------------------------ |
| 1789 | |
| 1790 | #Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, |
| 1791 | const SkIRect& clipBounds, SkIRect* outSubset, |
| 1792 | SkIPoint* offset) const |
| 1793 | |
| 1794 | Apply a given image filter to this image, and return the filtered result. |
| 1795 | The subset represents the active portion of this image. The return value is similarly an |
| 1796 | SkImage, with an active subset (outSubset). This is usually used with texture-backed |
| 1797 | images, where the texture may be approx-match and thus larger than the required size. |
| 1798 | clipBounds constrains the device-space extent of the image, stored in outSubset. |
| 1799 | offset is storage, set to the amount to translate the result when drawn. |
| 1800 | If the result image cannot be created, or the result would be transparent black, null |
| 1801 | is returned, in which case the offset and outSubset parameters should be ignored by the |
| 1802 | caller. |
| 1803 | |
| 1804 | #Param filter incomplete ## |
| 1805 | #Param subset incomplete ## |
| 1806 | #Param clipBounds incomplete ## |
| 1807 | #Param outSubset incomplete ## |
| 1808 | #Param offset incomplete ## |
| 1809 | |
| 1810 | #Return incomplete ## |
| 1811 | |
| 1812 | #Example |
| 1813 | // incomplete |
| 1814 | ## |
| 1815 | |
| 1816 | #SeeAlso incomplete |
| 1817 | |
| 1818 | #Method ## |
| 1819 | |
| 1820 | # ------------------------------------------------------------------------------ |
| 1821 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1822 | #Struct DeferredTextureImageUsageParams |
| 1823 | |
| 1824 | #Code |
| 1825 | struct DeferredTextureImageUsageParams { |
| 1826 | DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality, |
| 1827 | int preScaleMipLevel); |
| 1828 | SkMatrix fMatrix; |
| 1829 | SkFilterQuality fQuality; |
| 1830 | int fPreScaleMipLevel; |
| 1831 | }; |
| 1832 | ## |
| 1833 | |
| 1834 | #Member SkMatrix fMatrix |
| 1835 | ## |
| 1836 | |
| 1837 | #Member SkFilterQuality fQuality |
| 1838 | ## |
| 1839 | |
| 1840 | #Member int fPreScaleMipLevel |
| 1841 | ## |
| 1842 | |
| 1843 | #Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality, |
| 1844 | int preScaleMipLevel) |
| 1845 | |
| 1846 | #Param matrix incomplete ## |
| 1847 | #Param quality incomplete ## |
| 1848 | #Param preScaleMipLevel incomplete ## |
| 1849 | |
| 1850 | #Return incomplete ## |
| 1851 | |
| 1852 | #Example |
| 1853 | // incomplete |
| 1854 | ## |
| 1855 | |
| 1856 | #SeeAlso incomplete |
| 1857 | |
| 1858 | ## |
| 1859 | |
| 1860 | #Example |
| 1861 | // incomplete |
| 1862 | ## |
| 1863 | |
| 1864 | #SeeAlso incomplete |
| 1865 | |
| 1866 | ## |
| 1867 | |
| 1868 | #Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy, |
| 1869 | const DeferredTextureImageUsageParams deferredTextureImageUsageParams[], |
| 1870 | int paramCnt, |
| 1871 | void* buffer, |
| 1872 | SkColorSpace* dstColorSpace = nullptr, |
| 1873 | SkColorType dstColorType = kN32_SkColorType) const |
| 1874 | |
| 1875 | This method allows clients to capture the data necessary to turn a SkImage into a texture- |
| 1876 | backed image. If the original image is codec-backed this will decode into a format optimized |
| 1877 | for the context represented by the proxy. This method is thread safe with respect to the |
| 1878 | GrContext whence the proxy came. Clients allocate and manage the storage of the deferred |
| 1879 | texture data and control its lifetime. No cleanup is required, thus it is safe to simply free |
| 1880 | the memory out from under the data. |
| 1881 | |
| 1882 | The same method is used both for getting the size necessary for pre-uploaded texture data |
| 1883 | and for retrieving the data. The params array represents the set of draws over which to |
| 1884 | optimize the pre-upload data. |
| 1885 | |
| 1886 | When called with a null buffer this returns the size that the client must allocate in order |
| 1887 | to create deferred texture data for this image (or zero if this is an inappropriate |
| 1888 | candidate). The buffer allocated by the client should be 8 byte aligned. |
| 1889 | |
| 1890 | When buffer is not null this fills in the deferred texture data for this image in the |
| 1891 | provided buffer (assuming this is an appropriate candidate image and the buffer is |
| 1892 | appropriately aligned). Upon success the size written is returned, otherwise 0. |
| 1893 | |
| 1894 | dstColorSpace is the color space of the surface where this texture will ultimately be used. |
| 1895 | If the method determines that mip-maps are needed, this helps determine the correct strategy |
| 1896 | for building them (gamma-correct or not). |
| 1897 | |
| 1898 | dstColorType is the color type of the surface where this texture will ultimately be used. |
| 1899 | This determines the format with which the image will be uploaded to the GPU. If dstColorType |
| 1900 | does not support color spaces (low bit depth types such as kARGB_4444_SkColorType), |
| 1901 | then dstColorSpace must be null. |
| 1902 | |
| 1903 | #Param contextThreadSafeProxy incomplete ## |
| 1904 | #Param deferredTextureImageUsageParams incomplete ## |
| 1905 | #Param paramCnt incomplete ## |
| 1906 | #Param buffer incomplete ## |
| 1907 | #Param dstColorSpace incomplete ## |
| 1908 | #Param dstColorType incomplete ## |
| 1909 | |
| 1910 | #Return incomplete ## |
| 1911 | |
| 1912 | #Example |
| 1913 | // incomplete |
| 1914 | ## |
| 1915 | |
| 1916 | #SeeAlso incomplete |
| 1917 | |
| 1918 | ## |
| 1919 | |
| 1920 | #Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data, |
| 1921 | SkBudgeted budgeted) |
| 1922 | |
| 1923 | Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData. |
| 1924 | The context must be the context that provided the proxy passed to |
| 1925 | getDeferredTextureImageData. |
| 1926 | |
| 1927 | #Param context GPU_Context ## |
| 1928 | #Param data incomplete ## |
| 1929 | #Param budgeted incomplete ## |
| 1930 | |
| 1931 | #Return incomplete ## |
| 1932 | |
| 1933 | #Example |
| 1934 | // incomplete |
| 1935 | ## |
| 1936 | |
| 1937 | #SeeAlso incomplete |
| 1938 | |
| 1939 | ## |
| 1940 | |
| 1941 | # ------------------------------------------------------------------------------ |
| 1942 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1943 | #Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc |
| 1944 | |
| 1945 | ## |
| 1946 | |
| 1947 | # ------------------------------------------------------------------------------ |
| 1948 | |
| 1949 | #Method static bool MakeBackendTextureFromSkImage(GrContext* context, |
| 1950 | sk_sp<SkImage> image, |
| 1951 | GrBackendTexture* backendTexture, |
| 1952 | BackendTextureReleaseProc* backendTextureReleaseProc) |
| 1953 | |
| 1954 | Creates a GrBackendTexture from the provided SkImage. Returns true on success. The |
| 1955 | GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers |
| 1956 | responsibility to call the BackendTextureReleaseProc once they have deleted the texture. |
| 1957 | Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related |
| 1958 | to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture |
| 1959 | themselves. |
| 1960 | |
| 1961 | If image is both texture backed and singly referenced; that is, its only |
| 1962 | reference was transferred using std::move(): image is returned in backendTexture |
| 1963 | without conversion or making a copy. |
| 1964 | |
| 1965 | If the SkImage is not texture backed, this function will generate a texture with the image's |
| 1966 | contents and return that. |
| 1967 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1968 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1969 | #Param image incomplete ## |
| 1970 | #Param backendTexture incomplete ## |
| 1971 | #Param backendTextureReleaseProc incomplete ## |
| 1972 | |
| 1973 | #Return incomplete ## |
| 1974 | |
| 1975 | #Example |
| 1976 | // incomplete |
| 1977 | ## |
| 1978 | |
| 1979 | #SeeAlso incomplete |
| 1980 | |
| 1981 | #Method ## |
| 1982 | |
| 1983 | # ------------------------------------------------------------------------------ |
| 1984 | |
| 1985 | #Enum LegacyBitmapMode |
| 1986 | |
| 1987 | #Code |
| 1988 | enum LegacyBitmapMode { |
| 1989 | kRO_LegacyBitmapMode, |
| 1990 | kRW_LegacyBitmapMode, |
| 1991 | }; |
| 1992 | ## |
| 1993 | |
| 1994 | Helper functions to convert to SkBitmap |
| 1995 | |
| 1996 | #Const kRO_LegacyBitmapMode 0 |
| 1997 | ## |
| 1998 | #Const kRW_LegacyBitmapMode 1 |
| 1999 | ## |
| 2000 | |
| 2001 | #Example |
| 2002 | // incomplete |
| 2003 | ## |
| 2004 | |
| 2005 | #SeeAlso incomplete |
| 2006 | |
| 2007 | #Enum ## |
| 2008 | |
| 2009 | # ------------------------------------------------------------------------------ |
| 2010 | |
| 2011 | #Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const |
| 2012 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 2013 | Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode, |
| 2014 | returned bitmap is read-only and immutable. |
| 2015 | Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap |
| 2016 | write did not succeed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2017 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 2018 | #Param bitmap storage for legacy Bitmap ## |
| 2019 | #Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2020 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 2021 | #Return true if Bitmap was created ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2022 | |
| 2023 | #Example |
| 2024 | // incomplete |
| 2025 | ## |
| 2026 | |
| 2027 | #SeeAlso incomplete |
| 2028 | |
| 2029 | #Method ## |
| 2030 | |
| 2031 | # ------------------------------------------------------------------------------ |
| 2032 | |
| 2033 | #Method bool isLazyGenerated() const |
| 2034 | |
| 2035 | Returns true if Image is backed by an image-generator or other service that creates |
| 2036 | and caches its pixels or texture on-demand. |
| 2037 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 2038 | #Return true if Image is created as needed ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2039 | |
| 2040 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 2041 | #Height 80 |
| 2042 | #Function |
| 2043 | class TestImageGenerator : public SkImageGenerator { |
| 2044 | public: |
| 2045 | TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} |
| 2046 | ~TestImageGenerator() override {} |
| 2047 | protected: |
| 2048 | bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, |
| 2049 | const Options& options) override { |
| 2050 | SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr); |
| 2051 | for (int y = 0; y < info.height(); ++y) { |
| 2052 | for (int x = 0; x < info.width(); ++x) { |
| 2053 | pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; |
| 2054 | } |
| 2055 | } |
| 2056 | return true; |
| 2057 | } |
| 2058 | }; |
| 2059 | ## |
| 2060 | void draw(SkCanvas* canvas) { |
| 2061 | auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator()); |
| 2062 | sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen))); |
| 2063 | SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); |
| 2064 | canvas->scale(8, 8); |
| 2065 | canvas->drawImage(image, 0, 0, nullptr); |
| 2066 | SkPaint paint; |
| 2067 | paint.setTextSize(4); |
| 2068 | canvas->drawString(lazy, 2, 5, paint); |
| 2069 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2070 | ## |
| 2071 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame^] | 2072 | #Example |
| 2073 | #Image 5 |
| 2074 | #Platform gpu |
| 2075 | void draw(SkCanvas* canvas) { |
| 2076 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 2077 | if (nullptr == image) { |
| 2078 | return; |
| 2079 | } |
| 2080 | SkPaint paint; |
| 2081 | paint.setAntiAlias(true); |
| 2082 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 2083 | canvas->drawImage(image, 0, 0); |
| 2084 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 2085 | canvas->drawString( |
| 2086 | image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", |
| 2087 | image->width() / 2, image->height() * 3 / 4, paint); |
| 2088 | }; |
| 2089 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 2090 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 2091 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 2092 | drawImage(image, "image"); |
| 2093 | canvas->translate(image->width(), 0); |
| 2094 | drawImage(bitmapImage, "source"); |
| 2095 | canvas->translate(-image->width(), image->height()); |
| 2096 | drawImage(textureImage, "backEndTexture"); |
| 2097 | } |
| 2098 | ## |
| 2099 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2100 | #SeeAlso incomplete |
| 2101 | |
| 2102 | #Method ## |
| 2103 | |
| 2104 | # ------------------------------------------------------------------------------ |
| 2105 | |
| 2106 | #Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target, |
| 2107 | SkTransferFunctionBehavior premulBehavior) const |
| 2108 | |
| 2109 | If target is supported, returns an SkImage in target color space. |
| 2110 | Otherwise, returns nullptr. |
| 2111 | This will leave the image as is if it already in target color space. |
| 2112 | Otherwise, it will convert the pixels from Image color space to target |
| 2113 | color space. If this->colorSpace() is nullptr, Image color space will be |
| 2114 | treated as sRGB. |
| 2115 | |
| 2116 | If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image |
| 2117 | pixels to a linear space before converting to match destination Color_Type |
| 2118 | and Color_Space. |
| 2119 | If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image |
| 2120 | pixels are treated as if they are linear, regardless of how they are encoded. |
| 2121 | |
| 2122 | #Param target incomplete ## |
| 2123 | #Param premulBehavior incomplete ## |
| 2124 | |
| 2125 | #Return incomplete ## |
| 2126 | |
| 2127 | #Example |
| 2128 | // incomplete |
| 2129 | ## |
| 2130 | |
| 2131 | #SeeAlso incomplete |
| 2132 | |
| 2133 | #Method ## |
| 2134 | |
| 2135 | #Class SkImage ## |
| 2136 | |
| 2137 | #Topic Image ## |