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