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