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