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