Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Surface |
| 2 | #Alias Surface_Reference |
| 3 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4 | #Subtopic Overview |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5 | #Subtopic Subtopic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 6 | #Populate |
| 7 | ## |
| 8 | ## |
| 9 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 10 | #Class SkSurface |
| 11 | |
| 12 | SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be |
| 13 | allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface). |
| 14 | SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call |
| 15 | surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface). |
| 16 | SkSurface always has non-zero dimensions. If there is a request for a new surface, and either |
| 17 | of the requested dimensions are zero, then nullptr will be returned. |
| 18 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 19 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 20 | #Populate |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 21 | #Subtopic ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 22 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 23 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 24 | #Populate |
| 25 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 26 | |
| 27 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 28 | #Subtopic Constructor |
| 29 | #Populate |
| 30 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 31 | |
| 32 | #Method static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels, |
| 33 | size_t rowBytes, |
| 34 | const SkSurfaceProps* surfaceProps = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 35 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 36 | #Line # creates Surface from SkImageInfo and Pixel_Storage ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 37 | |
| 38 | Allocates raster Surface. Canvas returned by Surface draws directly into pixels. |
| 39 | |
| 40 | Surface is returned if all parameters are valid. |
| 41 | Valid parameters include: |
| 42 | info dimensions are greater than zero; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 43 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 44 | pixels is not nullptr; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 45 | rowBytes is large enough to contain info width pixels of Color_Type. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 46 | |
| 47 | Pixel buffer size should be info height times computed rowBytes. |
| 48 | Pixels are not initialized. |
| 49 | To access pixels after drawing, call flush() or peekPixels. |
| 50 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 51 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 52 | of Raster_Surface; width and height must be greater than zero |
| 53 | ## |
| 54 | #Param pixels pointer to destination pixels buffer ## |
| 55 | #Param rowBytes interval from one Surface row to the next ## |
| 56 | #Param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 57 | may be nullptr |
| 58 | ## |
| 59 | |
| 60 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 61 | |
| 62 | #Example |
| 63 | void draw(SkCanvas* ) { |
| 64 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); |
| 65 | const size_t size = info.computeMinByteSize(); |
| 66 | SkAutoTMalloc<SkPMColor> storage(size); |
| 67 | SkPMColor* pixels = storage.get(); |
| 68 | sk_sp<SkSurface> surface(SkSurface::MakeRasterDirect(info, pixels, info.minRowBytes())); |
| 69 | SkCanvas* canvas = surface->getCanvas(); |
| 70 | canvas->clear(SK_ColorWHITE); |
| 71 | SkPMColor pmWhite = pixels[0]; |
| 72 | SkPaint paint; |
| 73 | canvas->drawPoint(1, 1, paint); |
| 74 | canvas->flush(); // ensure that point was drawn |
| 75 | for (int y = 0; y < info.height(); ++y) { |
| 76 | for (int x = 0; x < info.width(); ++x) { |
| 77 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 78 | } |
| 79 | SkDebugf("\n"); |
| 80 | } |
| 81 | } |
| 82 | #StdOut |
| 83 | --- |
| 84 | -x- |
| 85 | --- |
| 86 | ## |
| 87 | ## |
| 88 | |
| 89 | #SeeAlso MakeRasterDirectReleaseProc MakeRaster MakeRasterN32Premul SkCanvas::MakeRasterDirect |
| 90 | |
| 91 | #Method ## |
| 92 | |
| 93 | # ------------------------------------------------------------------------------ |
| 94 | |
| 95 | #Method static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels, |
| 96 | size_t rowBytes, |
| 97 | void (*releaseProc)(void* pixels, void* context), |
| 98 | void* context, const SkSurfaceProps* surfaceProps = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 99 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 100 | #Line # creates Surface from SkImageInfo and Pixel_Storage ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 101 | |
| 102 | Allocates raster Surface. Canvas returned by Surface draws directly into pixels. |
| 103 | releaseProc is called with pixels and context when Surface is deleted. |
| 104 | |
| 105 | Surface is returned if all parameters are valid. |
| 106 | Valid parameters include: |
| 107 | info dimensions are greater than zero; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 108 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 109 | pixels is not nullptr; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 110 | rowBytes is large enough to contain info width pixels of Color_Type. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 111 | |
| 112 | Pixel buffer size should be info height times computed rowBytes. |
| 113 | Pixels are not initialized. |
| 114 | To access pixels after drawing, call flush() or peekPixels. |
| 115 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 116 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 117 | of Raster_Surface; width and height must be greater than zero |
| 118 | ## |
| 119 | #Param pixels pointer to destination pixels buffer ## |
| 120 | #Param rowBytes interval from one Surface row to the next ## |
| 121 | #Param releaseProc called when Surface is deleted; may be nullptr ## |
| 122 | #Param context passed to releaseProc; may be nullptr ## |
| 123 | #Param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 124 | may be nullptr |
| 125 | ## |
| 126 | |
| 127 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 128 | |
| 129 | #Example |
| 130 | #Function |
| 131 | static void release_direct_surface_storage(void* pixels, void* context) { |
| 132 | if (pixels == context) { |
| 133 | SkDebugf("expected release context\n"); |
| 134 | } |
| 135 | sk_free(pixels); |
| 136 | } |
| 137 | |
| 138 | ## |
| 139 | void draw(SkCanvas* ) { |
| 140 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); |
| 141 | const size_t rowBytes = info.minRowBytes(); |
| 142 | void* pixels = sk_malloc_throw(info.computeByteSize(rowBytes)); |
| 143 | sk_sp<SkSurface> surface(SkSurface::MakeRasterDirectReleaseProc(info, pixels, rowBytes, |
| 144 | release_direct_surface_storage, pixels)); |
| 145 | SkCanvas* canvas = surface->getCanvas(); |
| 146 | canvas->clear(SK_ColorWHITE); |
| 147 | SkPMColor* colorPtr = (SkPMColor*) pixels; |
| 148 | SkPMColor pmWhite = colorPtr[0]; |
| 149 | SkPaint paint; |
| 150 | canvas->drawPoint(1, 1, paint); |
| 151 | canvas->flush(); // ensure that point was drawn |
| 152 | for (int y = 0; y < info.height(); ++y) { |
| 153 | for (int x = 0; x < info.width(); ++x) { |
| 154 | SkDebugf("%c", *colorPtr++ == pmWhite ? '-' : 'x'); |
| 155 | } |
| 156 | SkDebugf("\n"); |
| 157 | } |
| 158 | } |
| 159 | #StdOut |
| 160 | --- |
| 161 | -x- |
| 162 | --- |
| 163 | expected release context |
| 164 | ## |
| 165 | ## |
| 166 | |
| 167 | #SeeAlso MakeRasterDirect MakeRasterN32Premul MakeRaster |
| 168 | |
| 169 | #Method ## |
| 170 | |
| 171 | # ------------------------------------------------------------------------------ |
| 172 | |
| 173 | #Method static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes, |
| 174 | const SkSurfaceProps* surfaceProps) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 175 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 176 | #Line # creates Surface from SkImageInfo ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 177 | |
| 178 | Allocates raster Surface. Canvas returned by Surface draws directly into pixels. |
| 179 | Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times |
| 180 | rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero. |
| 181 | Pixel memory is deleted when Surface is deleted. |
| 182 | |
| 183 | Surface is returned if all parameters are valid. |
| 184 | Valid parameters include: |
| 185 | info dimensions are greater than zero; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 186 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
| 187 | rowBytes is large enough to contain info width pixels of Color_Type, or is zero. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 188 | |
| 189 | If rowBytes is not zero, subsequent images returned by makeImageSnapshot |
| 190 | have the same rowBytes. |
| 191 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 192 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 193 | of Raster_Surface; width and height must be greater than zero |
| 194 | ## |
| 195 | #Param rowBytes interval from one Surface row to the next; may be zero ## |
| 196 | #Param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 197 | may be nullptr |
| 198 | ## |
| 199 | |
| 200 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 201 | |
| 202 | #Example |
| 203 | void draw(SkCanvas* ) { |
| 204 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); |
| 205 | const size_t rowBytes = 64; |
| 206 | sk_sp<SkSurface> surface(SkSurface::MakeRaster(info, rowBytes, nullptr)); |
| 207 | SkCanvas* canvas = surface->getCanvas(); |
| 208 | canvas->clear(SK_ColorWHITE); |
| 209 | SkPixmap pixmap; |
| 210 | if (surface->peekPixels(&pixmap)) { |
| 211 | const uint32_t* colorPtr = pixmap.addr32(); |
| 212 | SkPMColor pmWhite = colorPtr[0]; |
| 213 | SkPaint paint; |
| 214 | canvas->drawPoint(1, 1, paint); |
| 215 | canvas->flush(); // ensure that point was drawn |
| 216 | for (int y = 0; y < info.height(); ++y) { |
| 217 | for (int x = 0; x < info.width(); ++x) { |
| 218 | SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); |
| 219 | } |
| 220 | colorPtr += rowBytes / sizeof(colorPtr[0]); |
| 221 | SkDebugf("\n"); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | #StdOut |
| 226 | --- |
| 227 | -x- |
| 228 | --- |
| 229 | ## |
| 230 | ## |
| 231 | |
| 232 | #SeeAlso MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc |
| 233 | |
| 234 | #Method ## |
| 235 | |
| 236 | # ------------------------------------------------------------------------------ |
| 237 | |
| 238 | #Method static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, |
| 239 | const SkSurfaceProps* props = nullptr) |
| 240 | |
| 241 | Allocates raster Surface. Canvas returned by Surface draws directly into pixels. |
| 242 | Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times |
| 243 | imageInfo.minRowBytes(). |
| 244 | Pixel memory is deleted when Surface is deleted. |
| 245 | |
| 246 | Surface is returned if all parameters are valid. |
| 247 | Valid parameters include: |
| 248 | info dimensions are greater than zero; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 249 | info contains Color_Type and Alpha_Type supported by Raster_Surface. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 250 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 251 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 252 | of Raster_Surface; width and height must be greater than zero |
| 253 | ## |
| 254 | #Param props LCD striping orientation and setting for device independent fonts; |
| 255 | may be nullptr |
| 256 | ## |
| 257 | |
| 258 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 259 | |
| 260 | #Example |
| 261 | void draw(SkCanvas* ) { |
| 262 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); |
| 263 | sk_sp<SkSurface> surface(SkSurface::MakeRaster(info)); |
| 264 | SkCanvas* canvas = surface->getCanvas(); |
| 265 | canvas->clear(SK_ColorWHITE); |
| 266 | SkPixmap pixmap; |
| 267 | if (surface->peekPixels(&pixmap)) { |
| 268 | const uint32_t* colorPtr = pixmap.addr32(); |
| 269 | SkPMColor pmWhite = colorPtr[0]; |
| 270 | SkPaint paint; |
| 271 | canvas->drawPoint(1, 1, paint); |
| 272 | canvas->flush(); // ensure that point was drawn |
| 273 | for (int y = 0; y < info.height(); ++y) { |
| 274 | for (int x = 0; x < info.width(); ++x) { |
| 275 | SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); |
| 276 | } |
| 277 | colorPtr += info.width(); |
| 278 | SkDebugf("\n"); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | ## |
| 283 | |
| 284 | #SeeAlso MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc |
| 285 | |
| 286 | #Method ## |
| 287 | |
| 288 | # ------------------------------------------------------------------------------ |
| 289 | |
| 290 | #Method static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height, |
| 291 | const SkSurfaceProps* surfaceProps = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 292 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 293 | #Line # creates Surface from width, height matching output ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 294 | |
| 295 | Allocates raster Surface. Canvas returned by Surface draws directly into pixels. |
| 296 | Allocates and zeroes pixel memory. Pixel memory size is height times width times |
| 297 | four. Pixel memory is deleted when Surface is deleted. |
| 298 | |
| 299 | Internally, sets Image_Info to width, height, Native_Color_Type, and |
| 300 | kPremul_SkAlphaType. |
| 301 | |
| 302 | Surface is returned if width and height are greater than zero. |
| 303 | |
| 304 | Use to create Surface that matches SkPMColor, the native pixel arrangement on |
| 305 | the platform. Surface drawn to output device skips converting its pixel format. |
| 306 | |
| 307 | #Param width pixel column count; must be greater than zero ## |
| 308 | #Param height pixel row count; must be greater than zero ## |
| 309 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 310 | fonts; may be nullptr |
| 311 | ## |
| 312 | |
| 313 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 314 | |
| 315 | #Example |
| 316 | void draw(SkCanvas* ) { |
| 317 | sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(3, 3)); |
| 318 | SkCanvas* canvas = surface->getCanvas(); |
| 319 | canvas->clear(SK_ColorWHITE); |
| 320 | SkPixmap pixmap; |
| 321 | if (surface->peekPixels(&pixmap)) { |
| 322 | const uint32_t* colorPtr = pixmap.addr32(); |
| 323 | SkPMColor pmWhite = colorPtr[0]; |
| 324 | SkPaint paint; |
| 325 | canvas->drawPoint(1, 1, paint); |
| 326 | canvas->flush(); // ensure that point was drawn |
| 327 | for (int y = 0; y < surface->height(); ++y) { |
| 328 | for (int x = 0; x < surface->width(); ++x) { |
| 329 | SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); |
| 330 | } |
| 331 | colorPtr += surface->width(); |
| 332 | SkDebugf("\n"); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | #StdOut |
| 337 | --- |
| 338 | -x- |
| 339 | --- |
| 340 | ## |
| 341 | ## |
| 342 | |
| 343 | #SeeAlso MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc |
| 344 | |
| 345 | #Method ## |
| 346 | |
| 347 | # ------------------------------------------------------------------------------ |
| 348 | |
| 349 | #Method static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, |
| 350 | const GrBackendTexture& backendTexture, |
| 351 | GrSurfaceOrigin origin, int sampleCnt, |
| 352 | sk_sp<SkColorSpace> colorSpace, |
| 353 | const SkSurfaceProps* surfaceProps) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 354 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 355 | #Line # creates Surface from GPU-backed texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 356 | |
| 357 | Wraps a GPU-backed texture into Surface. Caller must ensure the texture is |
| 358 | valid for the lifetime of returned Surface. If sampleCnt greater than zero, |
| 359 | creates an intermediate MSAA Surface which is used for drawing backendTexture. |
| 360 | |
| 361 | Surface is returned if all parameters are valid. backendTexture is valid if |
| 362 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 363 | backendTexture has an sRGB configuration, then context must support sRGB, |
| 364 | and colorSpace must be present. Further, backendTexture width and height must |
| 365 | not exceed context capabilities, and the context must be able to support |
| 366 | back-end textures. |
| 367 | |
| 368 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 369 | |
| 370 | #Param context GPU_Context ## |
| 371 | #Param backendTexture texture residing on GPU ## |
| 372 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 373 | #Param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing ## |
| 374 | #Param colorSpace range of colors ## |
| 375 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 376 | fonts; may be nullptr |
| 377 | ## |
| 378 | |
| 379 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 380 | |
| 381 | #Example |
| 382 | #ToDo remove !fiddle below once backEndTextureRenderTarget is available ## |
| 383 | #Platform !fiddle gpu cpu |
| 384 | SkPaint paint; |
| 385 | paint.setTextSize(32); |
| 386 | GrContext* context = canvas->getGrContext(); |
| 387 | if (!context) { |
| 388 | canvas->drawString("GPU only!", 20, 40, paint); |
| 389 | return; |
| 390 | } |
| 391 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(context, |
| 392 | backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, nullptr, nullptr); |
| 393 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 394 | surfaceCanvas->clear(SK_ColorWHITE); |
| 395 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 396 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 397 | canvas->drawImage(image, 0, 0); |
| 398 | ## |
| 399 | |
| 400 | #SeeAlso GrBackendTexture MakeFromBackendRenderTarget MakeRenderTarget |
| 401 | |
| 402 | #Method ## |
| 403 | |
| 404 | # ------------------------------------------------------------------------------ |
| 405 | |
Cary Clark | f059e7c | 2017-12-20 14:53:21 -0500 | [diff] [blame] | 406 | #Method static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, |
| 407 | const GrBackendTexture& backendTexture, |
| 408 | GrSurfaceOrigin origin, int sampleCnt, |
| 409 | SkColorType colorType, |
| 410 | sk_sp<SkColorSpace> colorSpace, |
| 411 | const SkSurfaceProps* surfaceProps) |
| 412 | |
| 413 | Wraps a GPU-backed texture into Surface. Caller must ensure the texture is |
| 414 | valid for the lifetime of returned Surface. If sampleCnt greater than zero, |
| 415 | creates an intermediate MSAA Surface which is used for drawing backendTexture. |
| 416 | |
| 417 | Surface is returned if all parameters are valid. backendTexture is valid if |
| 418 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 419 | backendTexture has an sRGB configuration, then context must support sRGB, |
| 420 | and colorSpace must be present. Further, backendTexture width and height must |
| 421 | not exceed context capabilities, and the context must be able to support |
| 422 | back-end textures. |
| 423 | |
| 424 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 425 | |
| 426 | #Param context GPU_Context ## |
| 427 | #Param backendTexture texture residing on GPU ## |
| 428 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 429 | #Param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing ## |
| 430 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 431 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 432 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 433 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 434 | ## |
| 435 | #Param colorSpace range of colors ## |
| 436 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 437 | fonts; may be nullptr |
| 438 | ## |
| 439 | |
| 440 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 441 | |
| 442 | #Example |
| 443 | #ToDo remove !fiddle below once backEndTextureRenderTarget is available ## |
| 444 | #Platform !fiddle gpu cpu |
| 445 | SkPaint paint; |
| 446 | paint.setTextSize(32); |
| 447 | GrContext* context = canvas->getGrContext(); |
| 448 | if (!context) { |
| 449 | canvas->drawString("GPU only!", 20, 40, paint); |
| 450 | return; |
| 451 | } |
| 452 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(context, |
| 453 | backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, |
| 454 | kRGBA_8888_SkColorType, 0, nullptr, nullptr); |
| 455 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 456 | surfaceCanvas->clear(SK_ColorWHITE); |
| 457 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 458 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 459 | canvas->drawImage(image, 0, 0); |
| 460 | ## |
| 461 | |
| 462 | #SeeAlso GrBackendTexture MakeFromBackendRenderTarget MakeRenderTarget |
| 463 | |
| 464 | #Method ## |
| 465 | |
| 466 | # ------------------------------------------------------------------------------ |
| 467 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 468 | #Method static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, |
| 469 | const GrBackendRenderTarget& backendRenderTarget, |
| 470 | GrSurfaceOrigin origin, |
| 471 | sk_sp<SkColorSpace> colorSpace, |
| 472 | const SkSurfaceProps* surfaceProps) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 473 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 474 | #Line # creates Surface from GPU memory buffer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 475 | |
| 476 | Wraps a GPU-backed buffer into Surface. Caller must ensure render target is |
| 477 | valid for the lifetime of returned Surface. |
| 478 | |
| 479 | Surface is returned if all parameters are valid. backendRenderTarget is valid if |
| 480 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 481 | backendRenderTarget has an sRGB configuration, then context must support sRGB, |
| 482 | and colorSpace must be present. Further, backendRenderTarget width and height must |
| 483 | not exceed context capabilities, and the context must be able to support |
| 484 | back-end render targets. |
| 485 | |
| 486 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 487 | |
| 488 | #Param context GPU_Context ## |
| 489 | #Param backendRenderTarget GPU intermediate memory buffer ## |
| 490 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 491 | #Param colorSpace range of colors ## |
| 492 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 493 | fonts; may be nullptr |
| 494 | ## |
| 495 | |
| 496 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 497 | |
| 498 | #Example |
| 499 | #ToDo remove !fiddle below once backEndTextureRenderTarget is available ## |
| 500 | #Platform !fiddle gpu |
| 501 | SkPaint paint; |
| 502 | paint.setTextSize(32); |
| 503 | GrContext* context = canvas->getGrContext(); |
| 504 | if (!context) { |
| 505 | canvas->drawString("GPU only!", 20, 40, paint); |
| 506 | return; |
| 507 | } |
| 508 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendRenderTarget(context, |
| 509 | backEndRenderTarget, kTopLeft_GrSurfaceOrigin, nullptr, nullptr); |
| 510 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 511 | surfaceCanvas->clear(SK_ColorWHITE); |
| 512 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 513 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 514 | canvas->drawImage(image, 0, 0); |
| 515 | ## |
| 516 | |
| 517 | #SeeAlso MakeFromBackendTexture MakeRenderTarget |
| 518 | |
| 519 | #Method ## |
| 520 | |
| 521 | # ------------------------------------------------------------------------------ |
| 522 | |
Cary Clark | f059e7c | 2017-12-20 14:53:21 -0500 | [diff] [blame] | 523 | #Method static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, |
| 524 | const GrBackendRenderTarget& backendRenderTarget, |
| 525 | GrSurfaceOrigin origin, |
| 526 | SkColorType colorType, |
| 527 | sk_sp<SkColorSpace> colorSpace, |
| 528 | const SkSurfaceProps* surfaceProps) |
| 529 | |
| 530 | Wraps a GPU-backed buffer into Surface. Caller must ensure render target is |
| 531 | valid for the lifetime of returned Surface. |
| 532 | |
| 533 | Surface is returned if all parameters are valid. backendRenderTarget is valid if |
| 534 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 535 | backendRenderTarget has an sRGB configuration, then context must support sRGB, |
| 536 | and colorSpace must be present. Further, backendRenderTarget width and height must |
| 537 | not exceed context capabilities, and the context must be able to support |
| 538 | back-end render targets. |
| 539 | |
| 540 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 541 | |
| 542 | #Param context GPU_Context ## |
| 543 | #Param backendRenderTarget GPU intermediate memory buffer ## |
| 544 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 545 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 546 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 547 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 548 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 549 | ## |
| 550 | #Param colorSpace range of colors ## |
| 551 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 552 | fonts; may be nullptr |
| 553 | ## |
| 554 | |
| 555 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 556 | |
| 557 | #Example |
| 558 | #ToDo remove !fiddle below once backEndTextureRenderTarget is available ## |
| 559 | #Platform !fiddle gpu |
| 560 | SkPaint paint; |
| 561 | paint.setTextSize(32); |
| 562 | GrContext* context = canvas->getGrContext(); |
| 563 | if (!context) { |
| 564 | canvas->drawString("GPU only!", 20, 40, paint); |
| 565 | return; |
| 566 | } |
| 567 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendRenderTarget(context, |
| 568 | backEndRenderTarget, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 569 | nullptr, nullptr); |
| 570 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 571 | surfaceCanvas->clear(SK_ColorWHITE); |
| 572 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 573 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 574 | canvas->drawImage(image, 0, 0); |
| 575 | ## |
| 576 | |
| 577 | #SeeAlso MakeFromBackendTexture MakeRenderTarget |
| 578 | |
| 579 | #Method ## |
| 580 | |
| 581 | # ------------------------------------------------------------------------------ |
| 582 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 583 | #Method static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, |
| 584 | const GrBackendTexture& backendTexture, |
| 585 | GrSurfaceOrigin origin, |
| 586 | int sampleCnt, |
| 587 | sk_sp<SkColorSpace> colorSpace, |
| 588 | const SkSurfaceProps* surfaceProps) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 589 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 590 | #Line # creates Surface from GPU-backed texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 591 | |
| 592 | Used to wrap a GPU-backed texture as a SkSurface. Skia will treat the texture as |
| 593 | a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own |
| 594 | the associated render target objects (but not the provided texture). Skia will not assume |
| 595 | ownership of the texture and the client must ensure the texture is valid for the lifetime |
| 596 | of the SkSurface. |
| 597 | |
| 598 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 599 | |
| 600 | #Param context GPU_Context ## |
| 601 | #Param backendTexture texture residing on GPU ## |
| 602 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 603 | #Param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing ## |
| 604 | #Param colorSpace range of colors ## |
| 605 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 606 | fonts; may be nullptr |
| 607 | ## |
| 608 | |
| 609 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 610 | |
| 611 | #Example |
| 612 | #Platform !fiddle gpu |
| 613 | SkPaint paint; |
| 614 | paint.setTextSize(32); |
| 615 | GrContext* context = canvas->getGrContext(); |
| 616 | if (!context) { |
| 617 | canvas->drawString("GPU only!", 20, 40, paint); |
| 618 | return; |
| 619 | } |
| 620 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 621 | context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, |
| 622 | nullptr, nullptr); |
| 623 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 624 | surfaceCanvas->clear(SK_ColorWHITE); |
| 625 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 626 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 627 | canvas->drawImage(image, 0, 0); |
| 628 | ## |
| 629 | |
| 630 | #SeeAlso MakeFromBackendRenderTarget MakeRenderTarget |
| 631 | |
| 632 | #Method ## |
| 633 | |
| 634 | # ------------------------------------------------------------------------------ |
| 635 | |
Cary Clark | f059e7c | 2017-12-20 14:53:21 -0500 | [diff] [blame] | 636 | #Method static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, |
| 637 | const GrBackendTexture& backendTexture, |
| 638 | GrSurfaceOrigin origin, |
| 639 | int sampleCnt, |
| 640 | SkColorType colorType, |
| 641 | sk_sp<SkColorSpace> colorSpace, |
| 642 | const SkSurfaceProps* surfaceProps) |
| 643 | |
| 644 | Used to wrap a GPU-backed texture as a SkSurface. Skia will treat the texture as |
| 645 | a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own |
| 646 | the associated render target objects (but not the provided texture). Skia will not assume |
| 647 | ownership of the texture and the client must ensure the texture is valid for the lifetime |
| 648 | of the SkSurface. |
| 649 | |
| 650 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 651 | |
| 652 | #Param context GPU_Context ## |
| 653 | #Param backendTexture texture residing on GPU ## |
| 654 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 655 | #Param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing ## |
| 656 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 657 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 658 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 659 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 660 | ## |
| 661 | #Param colorSpace range of colors ## |
| 662 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 663 | fonts; may be nullptr |
| 664 | ## |
| 665 | |
| 666 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 667 | |
| 668 | #Example |
| 669 | #Platform !fiddle gpu |
| 670 | SkPaint paint; |
| 671 | paint.setTextSize(32); |
| 672 | GrContext* context = canvas->getGrContext(); |
| 673 | if (!context) { |
| 674 | canvas->drawString("GPU only!", 20, 40, paint); |
| 675 | return; |
| 676 | } |
| 677 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 678 | context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, |
| 679 | kRGBA_8888_SkColorType, nullptr, nullptr); |
| 680 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 681 | surfaceCanvas->clear(SK_ColorWHITE); |
| 682 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 683 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 684 | canvas->drawImage(image, 0, 0); |
| 685 | ## |
| 686 | |
| 687 | #SeeAlso MakeFromBackendRenderTarget MakeRenderTarget |
| 688 | |
| 689 | #Method ## |
| 690 | |
| 691 | # ------------------------------------------------------------------------------ |
| 692 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 693 | #Method static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
| 694 | const SkImageInfo& imageInfo, |
| 695 | int sampleCount, GrSurfaceOrigin surfaceOrigin, |
| 696 | const SkSurfaceProps* surfaceProps, |
| 697 | bool shouldCreateWithMips = false) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 698 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 699 | #Line # creates Surface pointing to new GPU memory buffer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 700 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 701 | Returns Surface on GPU indicated by context. Allocates memory for |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 702 | pixels, based on the width, height, and Color_Type in ImageInfo. budgeted |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 703 | selects whether allocation for pixels is tracked by context. imageInfo |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 704 | describes the pixel format in Color_Type, and transparency in |
| 705 | Alpha_Type, and color matching in Color_Space. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 706 | |
| 707 | sampleCount requests the number of samples per pixel. |
| 708 | Pass zero to disable Multi_Sample_Anti_Aliasing. The request is rounded |
| 709 | up to the next supported count, or rounded down if it is larger than the |
| 710 | maximum supported count. |
| 711 | |
| 712 | surfaceOrigin pins either the top-left or the bottom-left corner to the origin. |
| 713 | |
| 714 | shouldCreateWithMips hints that Image returned by makeImageSnapshot is Mip_Map. |
| 715 | |
| 716 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 717 | |
| 718 | #Param context GPU_Context ## |
| 719 | #Param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 720 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 721 | width, or height, or both, may be zero |
| 722 | ## |
| 723 | #Param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing ## |
| 724 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 725 | #Param surfaceProps LCD striping orientation and setting for device independent |
| 726 | fonts; may be nullptr |
| 727 | ## |
| 728 | #Param shouldCreateWithMips hint that Surface will host Mip_Map images ## |
| 729 | |
| 730 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 731 | |
| 732 | #ToDo not sure that this example is relevant; surfaceOrigin doesn't appear to do anything ## |
| 733 | #Example |
| 734 | #Platform gpu |
| 735 | #Height 64 |
| 736 | SkPaint paint; |
| 737 | paint.setTextSize(32); |
| 738 | GrContext* context = canvas->getGrContext(); |
| 739 | if (!context) { |
| 740 | canvas->drawString("GPU only!", 20, 40, paint); |
| 741 | return; |
| 742 | } |
| 743 | SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); |
| 744 | for (auto surfaceOrigin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 745 | auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, |
| 746 | surfaceOrigin, nullptr)); |
| 747 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 748 | surfaceCanvas->clear(SK_ColorWHITE); |
| 749 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 750 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 751 | canvas->drawImage(image, 0, 0); |
| 752 | canvas->translate(0, 128); |
| 753 | } |
| 754 | ## |
| 755 | |
| 756 | #SeeAlso MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget |
| 757 | |
| 758 | #Method ## |
| 759 | |
| 760 | # ------------------------------------------------------------------------------ |
| 761 | |
| 762 | #Method static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
| 763 | const SkImageInfo& imageInfo, int sampleCount, |
| 764 | const SkSurfaceProps* props) |
| 765 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 766 | Returns Surface on GPU indicated by context. Allocates memory for |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 767 | pixels, based on the width, height, and Color_Type in ImageInfo. budgeted |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 768 | selects whether allocation for pixels is tracked by context. imageInfo |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 769 | describes the pixel format in Color_Type, and transparency in |
| 770 | Alpha_Type, and color matching in Color_Space. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 771 | |
| 772 | sampleCount requests the number of samples per pixel. |
| 773 | Pass zero to disable Multi_Sample_Anti_Aliasing. The request is rounded |
| 774 | up to the next supported count, or rounded down if it is larger than the |
| 775 | maximum supported count. |
| 776 | |
| 777 | Surface bottom-left corner is pinned to the origin. |
| 778 | |
| 779 | #Param context GPU_Context ## |
| 780 | #Param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 781 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 782 | of Raster_Surface; width, or height, or both, may be zero |
| 783 | ## |
| 784 | #Param sampleCount samples per pixel, or 0 to disable Multi_Sample_Anti_Aliasing ## |
| 785 | #Param props LCD striping orientation and setting for device independent |
| 786 | fonts; may be nullptr |
| 787 | ## |
| 788 | |
| 789 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 790 | |
| 791 | #Example |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 792 | #Platform cpu gpu |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 793 | #Description |
| 794 | LCD text takes advantage of raster striping to improve resolution. Only one of |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 795 | the four combinations is correct, depending on whether monitor LCD striping is |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 796 | horizontal or vertical, and whether the order of the stripes is red blue green |
| 797 | or red green blue. |
| 798 | ## |
| 799 | void draw(SkCanvas* canvas) { |
| 800 | auto test_draw = [](SkCanvas* surfaceCanvas) -> void { |
| 801 | SkPaint paint; |
| 802 | paint.setAntiAlias(true); |
| 803 | paint.setLCDRenderText(true); |
| 804 | paint.setColor(0xFFBBBBBB); |
| 805 | surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint); |
| 806 | paint.setColor(SK_ColorWHITE); |
| 807 | paint.setTextSize(32); |
| 808 | surfaceCanvas->drawString("Pest", 0, 25, paint); |
| 809 | }; |
| 810 | GrContext* context = canvas->getGrContext(); |
| 811 | SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 812 | int y = 0; |
| 813 | for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry, |
| 814 | kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) { |
| 815 | SkSurfaceProps props(0, geometry); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 816 | sk_sp<SkSurface> surface = context ? SkSurface::MakeRenderTarget( |
| 817 | context, SkBudgeted::kNo, info, 0, &props) : SkSurface::MakeRaster(info, &props); |
| 818 | test_draw(surface->getCanvas()); |
| 819 | surface->draw(canvas, 0, y, nullptr); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 820 | sk_sp<SkImage> image(surface->makeImageSnapshot()); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 821 | SkAutoCanvasRestore acr(canvas, true); |
| 822 | canvas->scale(8, 8); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 823 | canvas->drawImage(image, 12, y / 8); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 824 | y += 64; |
| 825 | } |
| 826 | } |
| 827 | ## |
| 828 | |
| 829 | #SeeAlso MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget |
| 830 | |
| 831 | #Method ## |
| 832 | |
| 833 | # ------------------------------------------------------------------------------ |
| 834 | |
| 835 | #Method static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
| 836 | const SkImageInfo& imageInfo) |
| 837 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 838 | Returns Surface on GPU indicated by context. Allocates memory for |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 839 | pixels, based on the width, height, and Color_Type in ImageInfo. budgeted |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 840 | selects whether allocation for pixels is tracked by context. imageInfo |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 841 | describes the pixel format in Color_Type, and transparency in |
| 842 | Alpha_Type, and color matching in Color_Space. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 843 | |
| 844 | Surface bottom-left corner is pinned to the origin. |
| 845 | |
| 846 | #Param context GPU_Context ## |
| 847 | #Param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes ## |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 848 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 849 | of Raster_Surface; width, or height, or both, may be zero |
| 850 | ## |
| 851 | |
| 852 | #Return Surface if all parameters are valid; otherwise, nullptr ## |
| 853 | |
| 854 | #Example |
| 855 | #Platform gpu |
| 856 | SkPaint paint; |
| 857 | paint.setTextSize(32); |
| 858 | GrContext* context = canvas->getGrContext(); |
| 859 | if (!context) { |
| 860 | canvas->drawString("GPU only!", 20, 40, paint); |
| 861 | return; |
| 862 | } |
| 863 | SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); |
| 864 | auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
| 865 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 866 | surfaceCanvas->clear(SK_ColorWHITE); |
| 867 | surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); |
| 868 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 869 | canvas->drawImage(image, 0, 0); |
| 870 | ## |
| 871 | |
| 872 | #SeeAlso MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget |
| 873 | |
| 874 | #Method ## |
| 875 | |
| 876 | # ------------------------------------------------------------------------------ |
| 877 | |
| 878 | #Method static sk_sp<SkSurface> MakeNull(int width, int height) |
| 879 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 880 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 881 | #Line # creates Surface without backing pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 882 | Returns Surface without backing pixels. Drawing to Canvas returned from Surface |
| 883 | has no effect. Calling makeImageSnapshot() on returned Surface returns nullptr. |
| 884 | |
| 885 | #Param width one or greater ## |
| 886 | #Param height one or greater ## |
| 887 | |
| 888 | #Return Surface if width and height are positive; otherwise, nullptr ## |
| 889 | |
| 890 | #Example |
| 891 | SkDebugf("SkSurface::MakeNull(0, 0) %c= nullptr\n", SkSurface::MakeNull(0, 0) == nullptr ? |
| 892 | '=' : '!'); |
| 893 | const int w = 37; |
| 894 | const int h = 1000; |
| 895 | auto surf = SkSurface::MakeNull(w, h); |
| 896 | auto nullCanvas = surf->getCanvas(); |
| 897 | nullCanvas->drawPaint(SkPaint()); // does not crash, nothing draws |
| 898 | SkDebugf("surf->makeImageSnapshot() %c= nullptr\n", surf->makeImageSnapshot() == nullptr ? |
| 899 | '=' : '!'); |
| 900 | #StdOut |
| 901 | SkSurface::MakeNull(0, 0) == nullptr |
| 902 | surf->makeImageSnapshot() == nullptr |
| 903 | ## |
| 904 | ## |
| 905 | |
| 906 | #SeeAlso MakeRaster MakeRenderTarget |
| 907 | |
| 908 | #Method ## |
| 909 | |
| 910 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 911 | #Subtopic Property |
| 912 | #Populate |
| 913 | #Line # member values ## |
| 914 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 915 | |
| 916 | #Method int width() const |
| 917 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 918 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 919 | #Line # returns pixel column count ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 920 | Returns pixel count in each row; may be zero or greater. |
| 921 | |
| 922 | #Return number of pixel columns ## |
| 923 | |
| 924 | #Example |
| 925 | const int width = 37; |
| 926 | const int height = 1000; |
| 927 | auto surf = SkSurface::MakeNull(width, height); |
| 928 | auto nullCanvas = surf->getCanvas(); |
| 929 | SkDebugf("surface width=%d canvas width=%d\n", surf->width(), |
| 930 | nullCanvas->getBaseLayerSize().fWidth); |
| 931 | #StdOut |
| 932 | surface width=37 canvas width=37 |
| 933 | ## |
| 934 | ## |
| 935 | |
| 936 | #SeeAlso height() |
| 937 | |
| 938 | #Method ## |
| 939 | |
| 940 | # ------------------------------------------------------------------------------ |
| 941 | |
| 942 | #Method int height() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 943 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 944 | #Line # returns pixel row count ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 945 | Returns pixel row count; may be zero or greater. |
| 946 | |
| 947 | #Return number of pixel rows ## |
| 948 | |
| 949 | #Example |
| 950 | const int width = 37; |
| 951 | const int height = 1000; |
| 952 | auto surf = SkSurface::MakeNull(width, height); |
| 953 | auto nullCanvas = surf->getCanvas(); |
| 954 | SkDebugf("surface height=%d canvas height=%d\n", surf->height(), |
| 955 | nullCanvas->getBaseLayerSize().fHeight); |
| 956 | #StdOut |
| 957 | surface height=1000 canvas height=1000 |
| 958 | ## |
| 959 | ## |
| 960 | |
| 961 | #SeeAlso width() |
| 962 | |
| 963 | #Method ## |
| 964 | |
| 965 | # ------------------------------------------------------------------------------ |
| 966 | |
| 967 | #Method uint32_t generationID() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 968 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 969 | #Line # returns unique ID ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 970 | Returns unique value identifying the content of Surface. Returned value changes |
| 971 | each time the content changes. Content is changed by drawing, or by calling |
| 972 | notifyContentWillChange. |
| 973 | |
| 974 | #Return unique content identifier ## |
| 975 | |
| 976 | #Example |
| 977 | auto surface = SkSurface::MakeRasterN32Premul(1, 1); |
| 978 | for (int i = 0; i < 3; ++i) { |
| 979 | SkDebugf("surface generationID: %d\n", surface->generationID()); |
| 980 | if (0 == i) { |
| 981 | surface->getCanvas()->drawColor(SK_ColorBLACK); |
| 982 | } else { |
| 983 | surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 984 | } |
| 985 | } |
| 986 | #StdOut |
| 987 | surface generationID: 1 |
| 988 | surface generationID: 2 |
| 989 | surface generationID: 3 |
| 990 | ## |
| 991 | ## |
| 992 | |
| 993 | #SeeAlso notifyContentWillChange ContentChangeMode getCanvas |
| 994 | |
| 995 | #Method ## |
| 996 | |
| 997 | # ------------------------------------------------------------------------------ |
| 998 | |
| 999 | #Enum ContentChangeMode |
| 1000 | |
| 1001 | #Code |
| 1002 | enum ContentChangeMode { |
| 1003 | kDiscard_ContentChangeMode, |
| 1004 | kRetain_ContentChangeMode, |
| 1005 | }; |
| 1006 | ## |
| 1007 | |
| 1008 | ContentChangeMode members are parameters to notifyContentWillChange. |
| 1009 | |
| 1010 | #Const kDiscard_ContentChangeMode |
| 1011 | Pass to notifyContentWillChange to discard surface contents when |
| 1012 | the surface is cleared or overwritten. |
| 1013 | ## |
| 1014 | #Const kRetain_ContentChangeMode |
| 1015 | Pass to notifyContentWillChange when to preserve surface contents. |
| 1016 | If a snapshot has been generated, this copies the Surface contents. |
| 1017 | ## |
| 1018 | |
| 1019 | #SeeAlso notifyContentWillChange generationID |
| 1020 | |
| 1021 | #Enum ## |
| 1022 | |
| 1023 | # ------------------------------------------------------------------------------ |
| 1024 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1025 | #ToDo not crazy about misc catagory -- hopefully will become clear with time |
| 1026 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1027 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1028 | #Subtopic Miscellaneous |
| 1029 | #Populate |
| 1030 | #Line # other functions ## |
| 1031 | ## |
| 1032 | |
| 1033 | #Method void notifyContentWillChange(ContentChangeMode mode) |
| 1034 | #In Miscellaneous |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1035 | #Line # notifies that contents will be changed outside of Skia ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1036 | Notifies that Surface contents will be changed by code outside of Skia. |
| 1037 | Subsequent calls to generationID return a different value. |
| 1038 | |
| 1039 | mode is normally passed as kRetain_ContentChangeMode. |
| 1040 | |
| 1041 | #Private |
| 1042 | CAN WE DEPRECATE THIS? |
| 1043 | ## |
| 1044 | |
| 1045 | #Param mode one of: kDiscard_ContentChangeMode, kRetain_ContentChangeMode ## |
| 1046 | |
| 1047 | #Example |
| 1048 | auto surface = SkSurface::MakeRasterN32Premul(1, 1); |
| 1049 | for (int i = 0; i < 3; ++i) { |
| 1050 | SkDebugf("surface generationID: %d\n", surface->generationID()); |
| 1051 | if (0 == i) { |
| 1052 | surface->getCanvas()->drawColor(SK_ColorBLACK); |
| 1053 | } else { |
| 1054 | surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 1055 | } |
| 1056 | } |
| 1057 | ## |
| 1058 | |
| 1059 | #SeeAlso ContentChangeMode generationID |
| 1060 | |
| 1061 | #Method ## |
| 1062 | |
| 1063 | # ------------------------------------------------------------------------------ |
| 1064 | |
| 1065 | #Enum BackendHandleAccess |
| 1066 | |
| 1067 | #Code |
| 1068 | enum BackendHandleAccess { |
| 1069 | kFlushRead_BackendHandleAccess, |
| 1070 | kFlushWrite_BackendHandleAccess, |
| 1071 | kDiscardWrite_BackendHandleAccess, |
| 1072 | }; |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1073 | |
| 1074 | static const BackendHandleAccess kFlushRead_TextureHandleAccess = |
| 1075 | kFlushRead_BackendHandleAccess; |
| 1076 | static const BackendHandleAccess kFlushWrite_TextureHandleAccess = |
| 1077 | kFlushWrite_BackendHandleAccess; |
| 1078 | static const BackendHandleAccess kDiscardWrite_TextureHandleAccess = |
| 1079 | kDiscardWrite_BackendHandleAccess; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1080 | ## |
| 1081 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1082 | #Const kFlushRead_BackendHandleAccess 0 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1083 | Caller may read from the back-end object. |
| 1084 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1085 | #Const kFlushWrite_BackendHandleAccess 1 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1086 | Caller may write to the back-end object. |
| 1087 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1088 | #Const kDiscardWrite_BackendHandleAccess 2 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1089 | Caller must overwrite the entire back-end object. |
| 1090 | ## |
| 1091 | |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1092 | #Const kFlushRead_TextureHandleAccess 0 |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1093 | #Deprecated |
| 1094 | ## |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1095 | #Const kFlushWrite_TextureHandleAccess 1 |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1096 | #Deprecated |
| 1097 | ## |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1098 | #Const kDiscardWrite_TextureHandleAccess 2 |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1099 | #Deprecated |
| 1100 | ## |
Cary Clark | 7cfcbca | 2018-01-04 16:11:51 -0500 | [diff] [blame] | 1101 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1102 | #Example |
| 1103 | #Platform gpu |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1104 | SkPaint paint; |
| 1105 | paint.setTextSize(32); |
| 1106 | GrContext* context = canvas->getGrContext(); |
| 1107 | if (!context) { |
| 1108 | canvas->drawString("GPU only!", 20, 40, paint); |
| 1109 | return; |
| 1110 | } |
| 1111 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget( |
| 1112 | context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(10, 10)); |
| 1113 | int y = 20; |
| 1114 | SkString str; |
| 1115 | paint.setTextSize(16); |
| 1116 | for (auto access : { SkSurface::kFlushRead_BackendHandleAccess, |
| 1117 | SkSurface::kFlushWrite_BackendHandleAccess, |
| 1118 | SkSurface::kDiscardWrite_BackendHandleAccess } ) { |
| 1119 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 1120 | str.printf("uniqueID=%d", image->uniqueID()); |
| 1121 | canvas->drawString(str, 20, y += 20, paint); |
| 1122 | GrBackendObject backendObject = gpuSurface->getTextureHandle(access); |
| 1123 | str.printf("backendObject %c= 0", backendObject != 0 ? '!' : '='); |
| 1124 | canvas->drawString(str, 20, y += 20, paint); |
| 1125 | } |
| 1126 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 1127 | str.printf("final image uniqueID=%d", image->uniqueID()); |
| 1128 | canvas->drawString(str, 20, y += 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1129 | ## |
| 1130 | |
| 1131 | #SeeAlso getTextureHandle getRenderTargetHandle |
| 1132 | |
| 1133 | #Enum ## |
| 1134 | |
| 1135 | # ------------------------------------------------------------------------------ |
| 1136 | |
| 1137 | #Method GrBackendObject getTextureHandle(BackendHandleAccess backendHandleAccess) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1138 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1139 | #Line # returns the GPU reference to texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1140 | Returns the GPU back-end reference of the texture used by Surface, or zero |
| 1141 | if Surface is not backed by a GPU texture. |
| 1142 | |
| 1143 | The returned texture handle is only valid until the next draw into Surface, |
| 1144 | or when Surface is deleted. |
| 1145 | |
| 1146 | #Param backendHandleAccess one of: kFlushRead_BackendHandleAccess, |
| 1147 | kFlushWrite_BackendHandleAccess, kDiscardWrite_BackendHandleAccess |
| 1148 | ## |
| 1149 | |
| 1150 | #Return GPU texture reference ## |
| 1151 | |
| 1152 | #Example |
| 1153 | #Platform gpu |
| 1154 | #Height 64 |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1155 | SkPaint paint; |
| 1156 | paint.setTextSize(32); |
| 1157 | GrContext* context = canvas->getGrContext(); |
| 1158 | if (!context) { |
| 1159 | canvas->drawString("GPU only!", 20, 40, paint); |
| 1160 | return; |
| 1161 | } |
| 1162 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget( |
| 1163 | context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(10, 10)); |
| 1164 | GrBackendObject backendObject = gpuSurface->getTextureHandle( |
| 1165 | SkSurface::kFlushRead_BackendHandleAccess); |
| 1166 | if (backendObject) { |
| 1167 | SkString str; |
| 1168 | str.printf("backendObject=%08x", backendObject); |
| 1169 | paint.setTextSize(16); |
| 1170 | canvas->drawString(str, 20, 40, paint); |
| 1171 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1172 | ## |
| 1173 | |
| 1174 | #SeeAlso getRenderTargetHandle GrBackendObject BackendHandleAccess |
| 1175 | |
| 1176 | #Method ## |
| 1177 | |
| 1178 | # ------------------------------------------------------------------------------ |
| 1179 | |
| 1180 | #Method bool getRenderTargetHandle(GrBackendObject* backendObject, |
| 1181 | BackendHandleAccess backendHandleAccess) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1182 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1183 | #Line # returns the GPU reference to render target ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1184 | |
| 1185 | Returns true and stores the GPU back-end reference of the render target used |
| 1186 | by Surface in backendObject. |
| 1187 | |
| 1188 | Return false if Surface is not backed by a GPU render target, and leaves |
| 1189 | backendObject unchanged. |
| 1190 | |
| 1191 | The returned render target handle is only valid until the next draw into Surface, |
| 1192 | or when Surface is deleted. |
| 1193 | |
| 1194 | In OpenGL this returns the frame buffer object ID. |
| 1195 | |
| 1196 | #Param backendObject GPU intermediate memory buffer ## |
| 1197 | #Param backendHandleAccess one of: kFlushRead_BackendHandleAccess, |
| 1198 | kFlushWrite_BackendHandleAccess, kDiscardWrite_BackendHandleAccess |
| 1199 | ## |
| 1200 | |
| 1201 | #Return true if Surface is backed by GPU texture ## |
| 1202 | |
| 1203 | #Example |
| 1204 | #Platform gpu |
| 1205 | #Height 64 |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1206 | SkPaint paint; |
| 1207 | paint.setTextSize(32); |
| 1208 | GrContext* context = canvas->getGrContext(); |
| 1209 | if (!context) { |
| 1210 | canvas->drawString("GPU only!", 20, 40, paint); |
| 1211 | return; |
| 1212 | } |
| 1213 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget( |
| 1214 | context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(10, 10)); |
| 1215 | GrBackendObject backendObject; |
| 1216 | if (gpuSurface->getRenderTargetHandle(&backendObject, |
| 1217 | SkSurface::kFlushRead_BackendHandleAccess)) { |
| 1218 | SkString str; |
| 1219 | str.printf("backendObject=%d", backendObject); |
| 1220 | paint.setTextSize(16); |
| 1221 | canvas->drawString(str, 20, 40, paint); |
| 1222 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1223 | ## |
| 1224 | |
| 1225 | #SeeAlso getTextureHandle GrBackendObject BackendHandleAccess |
| 1226 | |
| 1227 | #Method ## |
| 1228 | |
| 1229 | # ------------------------------------------------------------------------------ |
| 1230 | |
| 1231 | #Method SkCanvas* getCanvas() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1232 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1233 | #Line # returns Canvas that draws into Surface ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1234 | Returns Canvas that draws into Surface. Subsequent calls return the same Canvas. |
| 1235 | Canvas returned is managed and owned by Surface, and is deleted when Surface |
| 1236 | is deleted. |
| 1237 | |
| 1238 | #Return drawing Canvas for Surface ## |
| 1239 | |
| 1240 | #Example |
| 1241 | #Height 64 |
| 1242 | sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1243 | SkCanvas* surfaceCanvas = surface->getCanvas(); |
| 1244 | surfaceCanvas->clear(SK_ColorBLUE); |
| 1245 | SkPaint paint; |
| 1246 | paint.setTextSize(40); |
| 1247 | surfaceCanvas->drawString("\xF0\x9F\x98\x81", 12, 45, paint); |
| 1248 | surface->draw(canvas, 0, 0, nullptr); |
| 1249 | ## |
| 1250 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1251 | #SeeAlso makeSurface makeImageSnapshot draw |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1252 | |
| 1253 | #Method ## |
| 1254 | |
| 1255 | # ------------------------------------------------------------------------------ |
| 1256 | |
| 1257 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1258 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1259 | #Line # creates a compatible Surface ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1260 | Returns a compatible Surface, or nullptr. Returned Surface contains |
| 1261 | the same raster, GPU, or null properties as the original. Returned Surface |
| 1262 | does not share the same pixels. |
| 1263 | |
| 1264 | Returns nullptr if imageInfo width or height are zero, or if imageInfo |
| 1265 | is incompatible with Surface. |
| 1266 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1267 | #Param imageInfo width, height, Color_Type, Alpha_Type, Color_Space, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1268 | of Surface; width and height must be greater than zero |
| 1269 | ## |
| 1270 | |
| 1271 | #Return compatible Surface or nullptr ## |
| 1272 | |
| 1273 | #Example |
| 1274 | #Height 96 |
| 1275 | sk_sp<SkSurface> big(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1276 | sk_sp<SkSurface> lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); |
| 1277 | big->getCanvas()->clear(SK_ColorRED); |
| 1278 | lil->getCanvas()->clear(SK_ColorBLACK); |
| 1279 | SkPixmap pixmap; |
| 1280 | if (big->peekPixels(&pixmap)) { |
| 1281 | SkBitmap bigBits; |
| 1282 | bigBits.installPixels(pixmap); |
| 1283 | canvas->drawBitmap(bigBits, 0, 0); |
| 1284 | } |
| 1285 | if (lil->peekPixels(&pixmap)) { |
| 1286 | SkBitmap lilBits; |
| 1287 | lilBits.installPixels(pixmap); |
| 1288 | canvas->drawBitmap(lilBits, 64, 64); |
| 1289 | } |
| 1290 | ## |
| 1291 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1292 | #SeeAlso makeImageSnapshot getCanvas draw |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1293 | |
| 1294 | #Method ## |
| 1295 | |
| 1296 | # ------------------------------------------------------------------------------ |
| 1297 | |
| 1298 | #Method sk_sp<SkImage> makeImageSnapshot() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1299 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1300 | #Line # creates Image capturing Surface contents ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1301 | Returns Image capturing Surface contents. Subsequent drawing to Surface contents |
| 1302 | are not captured. Image allocation is accounted for if Surface was created with |
| 1303 | SkBudgeted::kYes. |
| 1304 | |
| 1305 | #Return Image initialized with Surface contents ## |
| 1306 | |
| 1307 | #Example |
| 1308 | #Height 64 |
| 1309 | sk_sp<SkSurface> big(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1310 | sk_sp<SkSurface> lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); |
| 1311 | big->getCanvas()->clear(SK_ColorRED); |
| 1312 | lil->getCanvas()->clear(SK_ColorBLACK); |
| 1313 | sk_sp<SkImage> early(big->makeImageSnapshot()); |
| 1314 | lil->draw(big->getCanvas(), 16, 16, nullptr); |
| 1315 | sk_sp<SkImage> later(big->makeImageSnapshot()); |
| 1316 | canvas->drawImage(early, 0, 0); |
| 1317 | canvas->drawImage(later, 128, 0); |
| 1318 | ## |
| 1319 | |
| 1320 | #SeeAlso draw getCanvas |
| 1321 | |
| 1322 | #Method ## |
| 1323 | |
| 1324 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1325 | #Subtopic Pixels |
| 1326 | #Populate |
| 1327 | #Line # functions with pixel access ## |
| 1328 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1329 | |
| 1330 | #Method void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1331 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1332 | #Line # draws Surface contents to canvas ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1333 | Draws Surface contents to canvas, with its top-left corner at (x, y). |
| 1334 | |
| 1335 | If Paint paint is not nullptr, apply Color_Filter, Color_Alpha, Image_Filter, |
| 1336 | Blend_Mode, and Draw_Looper. |
| 1337 | |
| 1338 | #Param canvas Canvas drawn into ## |
| 1339 | #Param x horizontal offset in Canvas ## |
| 1340 | #Param y vertical offset in Canvas ## |
| 1341 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 1342 | and so on; or nullptr |
| 1343 | ## |
| 1344 | |
| 1345 | #Example |
| 1346 | #Height 64 |
| 1347 | sk_sp<SkSurface> big(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1348 | sk_sp<SkSurface> lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); |
| 1349 | big->getCanvas()->clear(SK_ColorRED); |
| 1350 | lil->getCanvas()->clear(SK_ColorBLACK); |
| 1351 | lil->draw(big->getCanvas(), 16, 16, nullptr); |
| 1352 | SkPixmap pixmap; |
| 1353 | if (big->peekPixels(&pixmap)) { |
| 1354 | SkBitmap bigBits; |
| 1355 | bigBits.installPixels(pixmap); |
| 1356 | canvas->drawBitmap(bigBits, 0, 0); |
| 1357 | } |
| 1358 | ## |
| 1359 | |
| 1360 | #SeeAlso makeImageSnapshot getCanvas |
| 1361 | |
| 1362 | #Method ## |
| 1363 | |
| 1364 | # ------------------------------------------------------------------------------ |
| 1365 | |
| 1366 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1367 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1368 | #Line # copies Surface parameters to Pixmap ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1369 | Copies Surface pixel address, row bytes, and Image_Info to Pixmap, if address |
| 1370 | is available, and returns true. If pixel address is not available, return |
| 1371 | false and leave Pixmap unchanged. |
| 1372 | |
| 1373 | pixmap contents become invalid on any future change to Surface. |
| 1374 | |
| 1375 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
| 1376 | |
| 1377 | #Return true if Surface has direct access to pixels ## |
| 1378 | |
| 1379 | #Example |
| 1380 | #Height 64 |
| 1381 | sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1382 | auto surfCanvas = surf->getCanvas(); |
| 1383 | surfCanvas->clear(SK_ColorRED); |
| 1384 | SkPaint paint; |
| 1385 | paint.setTextSize(40); |
| 1386 | surfCanvas->drawString("&", 16, 48, paint); |
| 1387 | SkPixmap pixmap; |
| 1388 | if (surf->peekPixels(&pixmap)) { |
| 1389 | SkBitmap surfBits; |
| 1390 | surfBits.installPixels(pixmap); |
| 1391 | canvas->drawBitmap(surfBits, 0, 0); |
| 1392 | } |
| 1393 | ## |
| 1394 | |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1395 | #SeeAlso readPixels writePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1396 | |
| 1397 | #Method ## |
| 1398 | |
| 1399 | # ------------------------------------------------------------------------------ |
| 1400 | |
| 1401 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1402 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1403 | #Line # copies Rect of pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1404 | Copies Rect of pixels to dst. |
| 1405 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1406 | Source Rect corners are (srcX, srcY) and Surface (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1407 | Destination Rect corners are (0, 0) and (dst.width(), dst.height()). |
| 1408 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1409 | converting to dst.colorType() and dst.alphaType() if required. |
| 1410 | |
| 1411 | Pixels are readable when Surface is raster, or backed by a GPU. |
| 1412 | |
| 1413 | The destination pixel storage must be allocated by the caller. |
| 1414 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1415 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1416 | do not match. Only pixels within both source and destination rectangles |
| 1417 | are copied. dst contents outside Rect intersection are unchanged. |
| 1418 | |
| 1419 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 1420 | |
| 1421 | Does not copy, and returns false if: |
| 1422 | |
| 1423 | #List |
| 1424 | # Source and destination rectangles do not intersect. ## |
| 1425 | # Pixmap pixels could not be allocated. ## |
| 1426 | # dst.rowBytes() is too small to contain one row of pixels. ## |
| 1427 | ## |
| 1428 | |
| 1429 | #Param dst storage for pixels copied from Surface ## |
| 1430 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1431 | #Param srcY offset into readable pixels in y; may be negative ## |
| 1432 | |
| 1433 | #Return true if pixels were copied ## |
| 1434 | |
| 1435 | #Example |
| 1436 | #Height 32 |
| 1437 | sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1438 | auto surfCanvas = surf->getCanvas(); |
| 1439 | surfCanvas->clear(SK_ColorRED); |
| 1440 | SkPaint paint; |
| 1441 | paint.setTextSize(40); |
| 1442 | surfCanvas->drawString("&", 0, 32, paint); |
| 1443 | std::vector<SkPMColor> storage; |
| 1444 | storage.resize(surf->width() * surf->height()); |
| 1445 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(32, 32), &storage.front(), |
| 1446 | surf->width() * sizeof(storage[0])); |
| 1447 | if (surf->readPixels(pixmap, 0, 0)) { |
| 1448 | SkBitmap surfBits; |
| 1449 | surfBits.installPixels(pixmap); |
| 1450 | canvas->drawBitmap(surfBits, 0, 0); |
| 1451 | } |
| 1452 | ## |
| 1453 | |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1454 | #SeeAlso peekPixels writePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1455 | |
| 1456 | #Method ## |
| 1457 | |
| 1458 | # ------------------------------------------------------------------------------ |
| 1459 | |
| 1460 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1461 | int srcX, int srcY) |
| 1462 | |
| 1463 | Copies Rect of pixels from Canvas into dstPixels. |
| 1464 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1465 | Source Rect corners are (srcX, srcY) and Surface (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1466 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
| 1467 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1468 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
| 1469 | |
| 1470 | Pixels are readable when Surface is raster, or backed by a GPU. |
| 1471 | |
| 1472 | The destination pixel storage must be allocated by the caller. |
| 1473 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1474 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1475 | do not match. Only pixels within both source and destination rectangles |
| 1476 | are copied. dstPixels contents outside Rect intersection are unchanged. |
| 1477 | |
| 1478 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 1479 | |
| 1480 | Does not copy, and returns false if: |
| 1481 | |
| 1482 | #List |
| 1483 | # Source and destination rectangles do not intersect. ## |
| 1484 | # Surface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 1485 | # dstRowBytes is too small to contain one row of pixels. ## |
| 1486 | ## |
| 1487 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1488 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1489 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 1490 | #Param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger ## |
| 1491 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1492 | #Param srcY offset into readable pixels in y; may be negative ## |
| 1493 | |
| 1494 | #Return true if pixels were copied ## |
| 1495 | |
| 1496 | #Example |
| 1497 | #Height 64 |
| 1498 | #Description |
| 1499 | A black oval drawn on a red background provides an image to copy. |
| 1500 | readPixels copies one quarter of the Surface into each of the four corners. |
| 1501 | The copied quarter ovals overdraw the original oval. |
| 1502 | ## |
| 1503 | sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1504 | auto surfCanvas = surf->getCanvas(); |
| 1505 | surfCanvas->clear(SK_ColorRED); |
| 1506 | SkPaint paint; |
| 1507 | surfCanvas->drawOval({4, 8, 58, 54}, paint); |
| 1508 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 1509 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 1510 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 1511 | for (int x : { 32, -32 } ) { |
| 1512 | for (int y : { 32, -32 } ) { |
| 1513 | surf->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
| 1514 | } |
| 1515 | } |
| 1516 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 1517 | canvas->drawImage(image, 0, 0); |
| 1518 | ## |
| 1519 | |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1520 | #SeeAlso peekPixels writePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1521 | |
| 1522 | #Method ## |
| 1523 | |
| 1524 | # ------------------------------------------------------------------------------ |
| 1525 | |
| 1526 | #Method bool readPixels(const SkBitmap& dst, int srcX, int srcY) |
| 1527 | |
| 1528 | Copies Rect of pixels from Surface into bitmap. |
| 1529 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1530 | Source Rect corners are (srcX, srcY) and Surface (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1531 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
| 1532 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1533 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
| 1534 | |
| 1535 | Pixels are readable when Surface is raster, or backed by a GPU. |
| 1536 | |
| 1537 | The destination pixel storage must be allocated by the caller. |
| 1538 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1539 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1540 | do not match. Only pixels within both source and destination rectangles |
| 1541 | are copied. dst contents outside Rect intersection are unchanged. |
| 1542 | |
| 1543 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 1544 | |
| 1545 | Does not copy, and returns false if: |
| 1546 | |
| 1547 | #List |
| 1548 | # Source and destination rectangles do not intersect. ## |
| 1549 | # Surface pixels could not be converted to dst.colorType() or dst.alphaType(). ## |
| 1550 | # dst pixels could not be allocated. ## |
| 1551 | # dst.rowBytes() is too small to contain one row of pixels. ## |
| 1552 | ## |
| 1553 | |
| 1554 | #Param dst storage for pixels copied from Surface ## |
| 1555 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1556 | #Param srcY offset into readable pixels in y; may be negative ## |
| 1557 | |
| 1558 | #Return true if pixels were copied ## |
| 1559 | |
| 1560 | #Example |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1561 | sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64)); |
| 1562 | auto surfCanvas = surf->getCanvas(); |
| 1563 | surfCanvas->clear(SK_ColorGREEN); |
| 1564 | SkPaint paint; |
| 1565 | surfCanvas->drawOval({2, 10, 58, 54}, paint); |
| 1566 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 1567 | SkBitmap bitmap; |
| 1568 | bitmap.setInfo(info); |
| 1569 | bitmap.allocPixels(); |
| 1570 | for (int x : { 32, -32 } ) { |
| 1571 | for (int y : { 32, -32 } ) { |
| 1572 | surf->readPixels(bitmap, x, y); |
| 1573 | } |
| 1574 | } |
| 1575 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1576 | ## |
| 1577 | |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1578 | #SeeAlso peekPixels writePixels |
| 1579 | |
| 1580 | #Method ## |
| 1581 | |
| 1582 | # ------------------------------------------------------------------------------ |
| 1583 | |
| 1584 | #Method void writePixels(const SkPixmap& src, int dstX, int dstY) |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1585 | #In Pixels |
| 1586 | #Line # copies Rect of pixels ## |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1587 | Copies Rect of pixels from the src Pixmap to the Surface. |
| 1588 | |
| 1589 | Source Rect corners are (0, 0) and (src.width(), src.height()). |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1590 | Destination Rect corners are (dstX, dstY) and |
| 1591 | #Formula |
| 1592 | (dstX + Surface width(), dstY + Surface height()) |
| 1593 | ## |
| 1594 | . |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1595 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1596 | converting to Surface colorType() and Surface alphaType() if required. |
| 1597 | |
| 1598 | #Param src storage for pixels to copy to Surface ## |
| 1599 | #Param dstX x position relative to Surface to begin copy; may be negative ## |
| 1600 | #Param dstY x position relative to Surface to begin copy; may be negative ## |
| 1601 | |
| 1602 | #Example |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1603 | // incomplete |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1604 | ## |
| 1605 | |
| 1606 | #SeeAlso readPixels peekPixels |
| 1607 | |
| 1608 | #Method ## |
| 1609 | |
| 1610 | # ------------------------------------------------------------------------------ |
| 1611 | |
| 1612 | #Method void writePixels(const SkBitmap& src, int dstX, int dstY) |
| 1613 | |
| 1614 | Copies Rect of pixels from the src Bitmap to the Surface. |
| 1615 | |
| 1616 | Source Rect corners are (0, 0) and (src.width(), src.height()). |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1617 | Destination Rect corners are (dstX, dstY) and |
| 1618 | #Formula |
| 1619 | (dstX + Surface width(), dstY + Surface height()) |
| 1620 | ## |
| 1621 | . |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1622 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1623 | converting to Surface colorType() and Surface alphaType() if required. |
| 1624 | |
| 1625 | #Param src storage for pixels to copy to Surface ## |
| 1626 | #Param dstX x position relative to Surface to begin copy; may be negative ## |
| 1627 | #Param dstY x position relative to Surface to begin copy; may be negative ## |
| 1628 | |
| 1629 | #Example |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1630 | // incomplete |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 1631 | ## |
| 1632 | |
| 1633 | #SeeAlso readPixels peekPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1634 | |
| 1635 | #Method ## |
| 1636 | |
| 1637 | # ------------------------------------------------------------------------------ |
| 1638 | |
| 1639 | #Method const SkSurfaceProps& props() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1640 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1641 | #Line # returns Surface_Properties ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1642 | Returns Surface_Properties for surface. |
| 1643 | |
| 1644 | #Return LCD striping orientation and setting for device independent fonts ## |
| 1645 | |
| 1646 | #Example |
| 1647 | const char* names[] = { "Unknown", "RGB_H", "BGR_H", "RGB_V", "BGR_V" }; |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1648 | sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64)); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1649 | SkDebugf("surf.props(): k%s_SkPixelGeometry\n", names[surf->props().pixelGeometry()]); |
| 1650 | #StdOut |
| 1651 | surf.props(): kRGB_H_SkPixelGeometry |
| 1652 | ## |
| 1653 | ## |
| 1654 | |
| 1655 | #SeeAlso SkSurfaceProps |
| 1656 | |
| 1657 | #Method ## |
| 1658 | |
| 1659 | # ------------------------------------------------------------------------------ |
| 1660 | |
| 1661 | #Method void prepareForExternalIO() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1662 | #Deprecated soon |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1663 | #Method ## |
| 1664 | |
| 1665 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1666 | #Subtopic Utility |
| 1667 | #Populate |
| 1668 | #Line # rarely called management functions ## |
| 1669 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1670 | |
| 1671 | #Method void flush() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1672 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1673 | #Line # resolve pending I/O ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1674 | Issues pending Surface commands to the GPU-backed API and resolves any Surface MSAA. |
| 1675 | |
| 1676 | Skia flushes as needed, so it is not necessary to call this if Skia manages |
| 1677 | drawing and object lifetime. Call when interleaving Skia calls with native |
| 1678 | GPU calls. |
| 1679 | |
| 1680 | #NoExample |
| 1681 | ## |
| 1682 | |
| 1683 | #SeeAlso GrBackendSemaphore |
| 1684 | |
| 1685 | #Method ## |
| 1686 | |
| 1687 | # ------------------------------------------------------------------------------ |
| 1688 | |
| 1689 | #Method GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, |
| 1690 | GrBackendSemaphore signalSemaphores[]) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1691 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1692 | #Line # resolve pending I/O, and signal ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1693 | |
| 1694 | Issues pending Surface commands to the GPU-backed API and resolves any Surface MSAA. |
| 1695 | After issuing all commands, signalSemaphores of count numSemaphores semaphores |
| 1696 | are signaled by the GPU. |
| 1697 | |
| 1698 | For each GrBackendSemaphore in signalSemaphores: |
| 1699 | if GrBackendSemaphore is initialized, the GPU back-end uses the semaphore as is; |
| 1700 | otherwise, a new semaphore is created and initializes GrBackendSemaphore. |
| 1701 | |
| 1702 | The caller must delete the semaphores created and returned in signalSemaphores. |
| 1703 | GrBackendSemaphore can be deleted as soon as this function returns. |
| 1704 | |
Cary Clark | 2a8c48b | 2018-02-15 17:31:24 -0500 | [diff] [blame] | 1705 | If the back-end API is OpenGL only uninitialized Backend_Semaphores are supported. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1706 | |
| 1707 | If the back-end API is Vulkan semaphores may be initialized or uninitialized. |
| 1708 | If uninitialized, created semaphores are valid only with the VkDevice |
| 1709 | with which they were created. |
| 1710 | |
| 1711 | If GrSemaphoresSubmitted::kNo is returned, the GPU back-end did not create or |
| 1712 | add any semaphores to signal on the GPU; the caller should not instruct the GPU |
| 1713 | to wait on any of the semaphores. |
| 1714 | |
| 1715 | Pending surface commands are flushed regardless of the return result. |
| 1716 | |
| 1717 | #Param numSemaphores size of signalSemaphores array ## |
| 1718 | #Param signalSemaphores array of semaphore containers ## |
| 1719 | |
| 1720 | #Return one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo ## |
| 1721 | |
| 1722 | #NoExample |
| 1723 | ## |
| 1724 | |
| 1725 | #SeeAlso wait GrBackendSemaphore |
| 1726 | |
| 1727 | #Method ## |
| 1728 | |
| 1729 | # ------------------------------------------------------------------------------ |
| 1730 | |
| 1731 | #Method bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1732 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1733 | #Line # rause commands until signaled ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1734 | Inserts a list of GPU semaphores that the current GPU-backed API must wait on before |
| 1735 | executing any more commands on the GPU for this surface. Skia will take ownership of the |
| 1736 | underlying semaphores and delete them once they have been signaled and waited on. |
| 1737 | If this call returns false, then the GPU back-end will not wait on any passed in semaphores, |
| 1738 | and the client will still own the semaphores. |
| 1739 | |
| 1740 | #Param numSemaphores size of waitSemaphores array ## |
| 1741 | #Param waitSemaphores array of semaphore containers ## |
| 1742 | |
| 1743 | #Return true if GPU is waiting on semaphores ## |
| 1744 | |
| 1745 | #Example |
| 1746 | #ToDo this is copy and paste silliness masquerading as an example. Probably need gpu |
| 1747 | globals and definitely need gpu expertise to make a real example out of this |
| 1748 | ## |
| 1749 | #Platform !fiddle gpu |
| 1750 | #Height 64 |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1751 | SkPaint paint; |
| 1752 | paint.setTextSize(32); |
| 1753 | GrContext* context = canvas->getGrContext(); |
| 1754 | if (!context) { |
| 1755 | canvas->drawString("GPU only!", 20, 40, paint); |
| 1756 | return; |
| 1757 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1758 | GrBackendSemaphore semaphore; |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1759 | sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
| 1760 | context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(64, 64)); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1761 | surface->flushAndSignalSemaphores(1, &semaphore); |
| 1762 | sk_sp<SkImage> image = surface->makeImageSnapshot(); |
| 1763 | GrBackendObject backendImage = image->getTextureHandle(false); // unused |
| 1764 | SkASSERT(backendImage); |
| 1765 | const SkImageInfo childImageInfo = SkImageInfo::Make(64, 64, |
| 1766 | kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 1767 | sk_sp<SkSurface> childSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, |
| 1768 | childImageInfo, 0, kTopLeft_GrSurfaceOrigin, nullptr)); |
| 1769 | GrBackendTexture backendTexture; |
| 1770 | sk_sp<SkImage> childImage = SkImage::MakeFromTexture(context, |
| 1771 | backendTexture, // undefined |
| 1772 | kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, nullptr); |
| 1773 | SkCanvas* childCanvas = childSurface->getCanvas(); |
| 1774 | childCanvas->clear(SK_ColorRED); |
| 1775 | childSurface->wait(1, &semaphore); |
| 1776 | childCanvas->drawImage(childImage, 32, 0); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1777 | childSurface->draw(canvas, 0, 0, nullptr); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1778 | ## |
| 1779 | |
| 1780 | #SeeAlso flushAndSignalSemaphores GrBackendSemaphore |
| 1781 | |
| 1782 | #Method ## |
| 1783 | |
| 1784 | # ------------------------------------------------------------------------------ |
| 1785 | |
| 1786 | #Method bool characterize(SkSurfaceCharacterization* characterization) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1787 | #In Utility |
| 1788 | #Line # sets Surface_Characterization for threaded GPU processing ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1789 | Initializes Surface_Characterization that can be used to perform GPU back-end |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1790 | processing in a separate thread. Typically this is used to divide drawing |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1791 | into multiple tiles. DeferredDisplayListRecorder records the drawing commands |
| 1792 | for each tile. |
| 1793 | |
| 1794 | Return true if Surface supports characterization. Raster_Surface returns false. |
| 1795 | |
| 1796 | #Param characterization properties for parallel drawing ## |
| 1797 | |
| 1798 | #Return true if supported ## |
| 1799 | |
| 1800 | #Example |
| 1801 | #Platform gpu |
| 1802 | #Height 64 |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1803 | SkPaint paint; |
| 1804 | paint.setTextSize(32); |
| 1805 | GrContext* context = canvas->getGrContext(); |
| 1806 | if (!context) { |
| 1807 | canvas->drawString("GPU only!", 20, 40, paint); |
| 1808 | return; |
| 1809 | } |
| 1810 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget( |
| 1811 | context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(64, 64)); |
| 1812 | SkSurfaceCharacterization characterization; |
| 1813 | if (!gpuSurface->characterize(&characterization)) { |
| 1814 | canvas->drawString("characterization unsupported", 20, 40, paint); |
| 1815 | return; |
| 1816 | } |
| 1817 | // start of threadable work |
| 1818 | SkDeferredDisplayListRecorder recorder(characterization); |
| 1819 | SkCanvas* subCanvas = recorder.getCanvas(); |
| 1820 | subCanvas->clear(SK_ColorGREEN); |
| 1821 | std::unique_ptr<SkDeferredDisplayList> displayList = recorder.detach(); |
| 1822 | // end of threadable work |
| 1823 | gpuSurface->draw(displayList.get()); |
| 1824 | sk_sp<SkImage> img = gpuSurface->makeImageSnapshot(); |
| 1825 | canvas->drawImage(std::move(img), 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1826 | ## |
| 1827 | |
| 1828 | #SeeAlso draw() SkSurfaceCharacterization SkDeferredDisplayList |
| 1829 | |
| 1830 | #Method ## |
| 1831 | |
| 1832 | # ------------------------------------------------------------------------------ |
| 1833 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1834 | #Method bool draw(SkDeferredDisplayList* deferredDisplayList) |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1835 | |
| 1836 | Draws deferred display list created using SkDeferredDisplayListRecorder. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1837 | Has no effect and returns false if Surface_Characterization stored in |
| 1838 | deferredDisplayList is not compatible with Surface. |
| 1839 | |
| 1840 | Raster_Surface returns false. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1841 | |
| 1842 | #Param deferredDisplayList drawing commands ## |
| 1843 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1844 | #Return false if deferredDisplayList is not compatible ## |
| 1845 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1846 | #Example |
| 1847 | #Height 64 |
| 1848 | #Platform gpu cpu |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1849 | SkPaint paint; |
| 1850 | paint.setTextSize(16); |
| 1851 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeRasterN32Premul(64, 64); |
| 1852 | SkSurfaceCharacterization characterization; |
| 1853 | if (!gpuSurface->characterize(&characterization)) { |
| 1854 | canvas->drawString("characterization unsupported", 20, 40, paint); |
| 1855 | return; |
| 1856 | } |
| 1857 | // start of threadable work |
| 1858 | SkDeferredDisplayListRecorder recorder(characterization); |
| 1859 | SkCanvas* subCanvas = recorder.getCanvas(); |
| 1860 | subCanvas->clear(SK_ColorGREEN); |
| 1861 | std::unique_ptr<SkDeferredDisplayList> displayList = recorder.detach(); |
| 1862 | // end of threadable work |
| 1863 | gpuSurface->draw(displayList.get()); |
| 1864 | sk_sp<SkImage> img = gpuSurface->makeImageSnapshot(); |
| 1865 | canvas->drawImage(std::move(img), 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1866 | ## |
| 1867 | |
| 1868 | #SeeAlso characterize() SkSurfaceCharacterization SkDeferredDisplayList |
| 1869 | |
| 1870 | #Method ## |
| 1871 | |
| 1872 | #Class SkSurface ## |
| 1873 | |
| 1874 | #Topic Surface ## |