reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkSurface_DEFINED |
| 9 | #define SkSurface_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkImage.h" |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 13 | #include "SkSurfaceProps.h" |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 14 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 15 | #include "GrTypes.h" |
| 16 | |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 17 | #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 |
| 18 | #include <android/hardware_buffer.h> |
| 19 | #endif |
| 20 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 21 | class SkCanvas; |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 22 | class SkDeferredDisplayList; |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 23 | class SkPaint; |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 24 | class SkSurfaceCharacterization; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 25 | class GrBackendRenderTarget; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 26 | class GrBackendSemaphore; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 27 | class GrBackendTexture; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 28 | class GrContext; |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 29 | class GrRecordingContext; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 30 | class GrRenderTarget; |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 31 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 32 | /** \class SkSurface |
| 33 | SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be |
| 34 | allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface). |
| 35 | SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call |
| 36 | surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface). |
| 37 | SkSurface always has non-zero dimensions. If there is a request for a new surface, and either |
| 38 | of the requested dimensions are zero, then nullptr will be returned. |
| 39 | */ |
junov@chromium.org | 96447be | 2013-04-18 13:28:19 +0000 | [diff] [blame] | 40 | class SK_API SkSurface : public SkRefCnt { |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 41 | public: |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 42 | |
| 43 | /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels. |
| 44 | |
| 45 | SkSurface is returned if all parameters are valid. |
| 46 | Valid parameters include: |
| 47 | info dimensions are greater than zero; |
| 48 | info contains SkColorType and SkAlphaType supported by raster surface; |
| 49 | pixels is not nullptr; |
| 50 | rowBytes is large enough to contain info width pixels of SkColorType. |
| 51 | |
| 52 | Pixel buffer size should be info height times computed rowBytes. |
| 53 | Pixels are not initialized. |
| 54 | To access pixels after drawing, call flush() or peekPixels(). |
| 55 | |
| 56 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 57 | of raster surface; width and height must be greater than zero |
| 58 | @param pixels pointer to destination pixels buffer |
| 59 | @param rowBytes interval from one SkSurface row to the next |
| 60 | @param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 61 | may be nullptr |
| 62 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 63 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 64 | static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels, |
| 65 | size_t rowBytes, |
| 66 | const SkSurfaceProps* surfaceProps = nullptr); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 67 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 68 | /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels. |
| 69 | releaseProc is called with pixels and context when SkSurface is deleted. |
| 70 | |
| 71 | SkSurface is returned if all parameters are valid. |
| 72 | Valid parameters include: |
| 73 | info dimensions are greater than zero; |
| 74 | info contains SkColorType and SkAlphaType supported by raster surface; |
| 75 | pixels is not nullptr; |
| 76 | rowBytes is large enough to contain info width pixels of SkColorType. |
| 77 | |
| 78 | Pixel buffer size should be info height times computed rowBytes. |
| 79 | Pixels are not initialized. |
| 80 | To access pixels after drawing, call flush() or peekPixels(). |
| 81 | |
| 82 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 83 | of raster surface; width and height must be greater than zero |
| 84 | @param pixels pointer to destination pixels buffer |
| 85 | @param rowBytes interval from one SkSurface row to the next |
| 86 | @param releaseProc called when SkSurface is deleted; may be nullptr |
| 87 | @param context passed to releaseProc; may be nullptr |
| 88 | @param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 89 | may be nullptr |
| 90 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 91 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 92 | static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels, |
| 93 | size_t rowBytes, |
| 94 | void (*releaseProc)(void* pixels, void* context), |
| 95 | void* context, const SkSurfaceProps* surfaceProps = nullptr); |
reed | 982542d | 2014-06-27 06:48:14 -0700 | [diff] [blame] | 96 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 97 | /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels. |
| 98 | Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times |
| 99 | rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero. |
| 100 | Pixel memory is deleted when SkSurface is deleted. |
| 101 | |
| 102 | SkSurface is returned if all parameters are valid. |
| 103 | Valid parameters include: |
| 104 | info dimensions are greater than zero; |
| 105 | info contains SkColorType and SkAlphaType supported by raster surface; |
| 106 | rowBytes is large enough to contain info width pixels of SkColorType, or is zero. |
| 107 | |
| 108 | If rowBytes is not zero, subsequent images returned by makeImageSnapshot() |
| 109 | have the same rowBytes. |
| 110 | |
| 111 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 112 | of raster surface; width and height must be greater than zero |
| 113 | @param rowBytes interval from one SkSurface row to the next; may be zero |
| 114 | @param surfaceProps LCD striping orientation and setting for device independent fonts; |
| 115 | may be nullptr |
| 116 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 117 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 118 | static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes, |
| 119 | const SkSurfaceProps* surfaceProps); |
reed | 9cd016e | 2016-01-30 10:01:06 -0800 | [diff] [blame] | 120 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 121 | /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels. |
| 122 | Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times |
| 123 | imageInfo.minRowBytes(). |
| 124 | Pixel memory is deleted when SkSurface is deleted. |
| 125 | |
| 126 | SkSurface is returned if all parameters are valid. |
| 127 | Valid parameters include: |
| 128 | info dimensions are greater than zero; |
| 129 | info contains SkColorType and SkAlphaType supported by raster surface. |
| 130 | |
| 131 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 132 | of raster surface; width and height must be greater than zero |
| 133 | @param props LCD striping orientation and setting for device independent fonts; |
| 134 | may be nullptr |
| 135 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 136 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 137 | static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, |
fmalita | 03912f1 | 2016-07-06 06:22:06 -0700 | [diff] [blame] | 138 | const SkSurfaceProps* props = nullptr) { |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 139 | return MakeRaster(imageInfo, 0, props); |
fmalita | 03912f1 | 2016-07-06 06:22:06 -0700 | [diff] [blame] | 140 | } |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 141 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 142 | /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels. |
| 143 | Allocates and zeroes pixel memory. Pixel memory size is height times width times |
| 144 | four. Pixel memory is deleted when SkSurface is deleted. |
| 145 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 146 | Internally, sets SkImageInfo to width, height, native color type, and |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 147 | kPremul_SkAlphaType. |
| 148 | |
| 149 | SkSurface is returned if width and height are greater than zero. |
| 150 | |
| 151 | Use to create SkSurface that matches SkPMColor, the native pixel arrangement on |
| 152 | the platform. SkSurface drawn to output device skips converting its pixel format. |
| 153 | |
| 154 | @param width pixel column count; must be greater than zero |
| 155 | @param height pixel row count; must be greater than zero |
| 156 | @param surfaceProps LCD striping orientation and setting for device independent |
| 157 | fonts; may be nullptr |
| 158 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 159 | */ |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 160 | static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height, |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 161 | const SkSurfaceProps* surfaceProps = nullptr); |
reed@google.com | 636d87a | 2013-09-17 20:03:43 +0000 | [diff] [blame] | 162 | |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 163 | /** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */ |
| 164 | typedef void* ReleaseContext; |
| 165 | |
| 166 | /** User function called when supplied render target may be deleted. */ |
| 167 | typedef void (*RenderTargetReleaseProc)(ReleaseContext releaseContext); |
| 168 | |
| 169 | /** User function called when supplied texture may be deleted. */ |
| 170 | typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); |
| 171 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 172 | /** Wraps a GPU-backed texture into SkSurface. Caller must ensure the texture is |
| 173 | valid for the lifetime of returned SkSurface. If sampleCnt greater than zero, |
| 174 | creates an intermediate MSAA SkSurface which is used for drawing backendTexture. |
| 175 | |
| 176 | SkSurface is returned if all parameters are valid. backendTexture is valid if |
| 177 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 178 | backendTexture has an sRGB configuration, then context must support sRGB, |
| 179 | and colorSpace must be present. Further, backendTexture width and height must |
| 180 | not exceed context capabilities, and the context must be able to support |
| 181 | back-end textures. |
| 182 | |
| 183 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 184 | |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 185 | @param context GPU context |
| 186 | @param backendTexture texture residing on GPU |
| 187 | @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin |
| 188 | @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing |
| 189 | @param colorType one of: |
| 190 | kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, |
| 191 | kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 192 | kRGB_888x_SkColorType, kBGRA_8888_SkColorType, |
| 193 | kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, |
| 194 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 195 | @param colorSpace range of colors; may be nullptr |
| 196 | @param surfaceProps LCD striping orientation and setting for device independent |
| 197 | fonts; may be nullptr |
| 198 | @param textureReleaseProc function called when texture can be released |
| 199 | @param releaseContext state passed to textureReleaseProc |
| 200 | @return SkSurface if all parameters are valid; otherwise, nullptr |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 201 | */ |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 202 | static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, |
| 203 | const GrBackendTexture& backendTexture, |
| 204 | GrSurfaceOrigin origin, int sampleCnt, |
| 205 | SkColorType colorType, |
| 206 | sk_sp<SkColorSpace> colorSpace, |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 207 | const SkSurfaceProps* surfaceProps, |
| 208 | TextureReleaseProc textureReleaseProc = nullptr, |
| 209 | ReleaseContext releaseContext = nullptr); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 210 | |
Cary Clark | ecf548b | 2018-04-03 11:49:10 -0400 | [diff] [blame] | 211 | /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget |
| 212 | is valid for the lifetime of returned SkSurface. |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 213 | |
| 214 | SkSurface is returned if all parameters are valid. backendRenderTarget is valid if |
| 215 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 216 | backendRenderTarget has an sRGB configuration, then context must support sRGB, |
| 217 | and colorSpace must be present. Further, backendRenderTarget width and height must |
| 218 | not exceed context capabilities, and the context must be able to support |
| 219 | back-end render targets. |
| 220 | |
| 221 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 222 | |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 223 | @param context GPU context |
| 224 | @param backendRenderTarget GPU intermediate memory buffer |
| 225 | @param origin one of: |
| 226 | kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin |
| 227 | @param colorType one of: |
| 228 | kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 229 | kRGB_565_SkColorType, |
| 230 | kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 231 | kRGB_888x_SkColorType, kBGRA_8888_SkColorType, |
| 232 | kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, |
| 233 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 234 | @param colorSpace range of colors |
| 235 | @param surfaceProps LCD striping orientation and setting for device independent |
| 236 | fonts; may be nullptr |
Mike Reed | 186669c | 2019-02-13 14:26:37 -0500 | [diff] [blame] | 237 | @param releaseProc function called when texture can be released |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 238 | @param releaseContext state passed to textureReleaseProc |
| 239 | @return SkSurface if all parameters are valid; otherwise, nullptr |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 240 | */ |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 241 | static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, |
| 242 | const GrBackendRenderTarget& backendRenderTarget, |
| 243 | GrSurfaceOrigin origin, |
| 244 | SkColorType colorType, |
| 245 | sk_sp<SkColorSpace> colorSpace, |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 246 | const SkSurfaceProps* surfaceProps, |
Mike Reed | 186669c | 2019-02-13 14:26:37 -0500 | [diff] [blame] | 247 | RenderTargetReleaseProc releaseProc = nullptr, |
Greg Daniel | 8ce7991 | 2019-02-05 10:08:43 -0500 | [diff] [blame] | 248 | ReleaseContext releaseContext = nullptr); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 249 | |
Cary Clark | ecf548b | 2018-04-03 11:49:10 -0400 | [diff] [blame] | 250 | /** Wraps a GPU-backed texture into SkSurface. Caller must ensure backendTexture is |
| 251 | valid for the lifetime of returned SkSurface. If sampleCnt greater than zero, |
| 252 | creates an intermediate MSAA SkSurface which is used for drawing backendTexture. |
| 253 | |
| 254 | SkSurface is returned if all parameters are valid. backendTexture is valid if |
| 255 | its pixel configuration agrees with colorSpace and context; for instance, if |
| 256 | backendTexture has an sRGB configuration, then context must support sRGB, |
| 257 | and colorSpace must be present. Further, backendTexture width and height must |
| 258 | not exceed context capabilities. |
| 259 | |
| 260 | Returned SkSurface is available only for drawing into, and cannot generate an |
| 261 | SkImage. |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 262 | |
| 263 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 264 | |
| 265 | @param context GPU context |
| 266 | @param backendTexture texture residing on GPU |
| 267 | @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin |
| 268 | @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing |
Cary Clark | ecf548b | 2018-04-03 11:49:10 -0400 | [diff] [blame] | 269 | @param colorType one of: |
| 270 | kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 271 | kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 272 | kRGB_888x_SkColorType, kBGRA_8888_SkColorType, |
| 273 | kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 274 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
Cary Clark | ecf548b | 2018-04-03 11:49:10 -0400 | [diff] [blame] | 275 | @param colorSpace range of colors; may be nullptr |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 276 | @param surfaceProps LCD striping orientation and setting for device independent |
| 277 | fonts; may be nullptr |
| 278 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 279 | */ |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 280 | static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, |
| 281 | const GrBackendTexture& backendTexture, |
| 282 | GrSurfaceOrigin origin, |
| 283 | int sampleCnt, |
Cary Clark | f059e7c | 2017-12-20 14:53:21 -0500 | [diff] [blame] | 284 | SkColorType colorType, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 285 | sk_sp<SkColorSpace> colorSpace, |
| 286 | const SkSurfaceProps* surfaceProps); |
| 287 | |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 288 | #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 |
Mike Reed | 186669c | 2019-02-13 14:26:37 -0500 | [diff] [blame] | 289 | /** Private. |
| 290 | Creates SkSurface from Android hardware buffer. |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 291 | Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released |
| 292 | when the SkSurface is destroyed and there is no pending work on the GPU involving the |
| 293 | buffer. |
| 294 | |
| 295 | Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. |
| 296 | |
| 297 | Currently this is only supported for buffers that can be textured as well as rendered to. |
| 298 | In other workds that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and |
| 299 | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits. |
| 300 | |
| 301 | @param context GPU context |
| 302 | @param hardwareBuffer AHardwareBuffer Android hardware buffer |
| 303 | @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin |
| 304 | @param colorSpace range of colors; may be nullptr |
| 305 | @param surfaceProps LCD striping orientation and setting for device independent |
| 306 | fonts; may be nullptr |
| 307 | @return created SkSurface, or nullptr |
| 308 | */ |
| 309 | static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrContext* context, |
| 310 | AHardwareBuffer* hardwareBuffer, |
| 311 | GrSurfaceOrigin origin, |
| 312 | sk_sp<SkColorSpace> colorSpace, |
| 313 | const SkSurfaceProps* surfaceProps); |
| 314 | #endif |
| 315 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 316 | /** Returns SkSurface on GPU indicated by context. Allocates memory for |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 317 | pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 318 | selects whether allocation for pixels is tracked by context. imageInfo |
| 319 | describes the pixel format in SkColorType, and transparency in |
| 320 | SkAlphaType, and color matching in SkColorSpace. |
| 321 | |
| 322 | sampleCount requests the number of samples per pixel. |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 323 | Pass zero to disable multi-sample anti-aliasing. The request is rounded |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 324 | up to the next supported count, or rounded down if it is larger than the |
| 325 | maximum supported count. |
| 326 | |
| 327 | surfaceOrigin pins either the top-left or the bottom-left corner to the origin. |
| 328 | |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 329 | shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map. |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 330 | |
| 331 | If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. |
| 332 | |
| 333 | @param context GPU context |
| 334 | @param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes |
| 335 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace; |
| 336 | width, or height, or both, may be zero |
| 337 | @param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing |
| 338 | @param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin |
| 339 | @param surfaceProps LCD striping orientation and setting for device independent |
| 340 | fonts; may be nullptr |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 341 | @param shouldCreateWithMips hint that SkSurface will host mip map images |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 342 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 343 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 344 | static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
| 345 | const SkImageInfo& imageInfo, |
| 346 | int sampleCount, GrSurfaceOrigin surfaceOrigin, |
| 347 | const SkSurfaceProps* surfaceProps, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 348 | bool shouldCreateWithMips = false); |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 349 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 350 | /** Returns SkSurface on GPU indicated by context. Allocates memory for |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 351 | pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 352 | selects whether allocation for pixels is tracked by context. imageInfo |
| 353 | describes the pixel format in SkColorType, and transparency in |
| 354 | SkAlphaType, and color matching in SkColorSpace. |
| 355 | |
| 356 | sampleCount requests the number of samples per pixel. |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 357 | Pass zero to disable multi-sample anti-aliasing. The request is rounded |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 358 | up to the next supported count, or rounded down if it is larger than the |
| 359 | maximum supported count. |
| 360 | |
| 361 | SkSurface bottom-left corner is pinned to the origin. |
| 362 | |
| 363 | @param context GPU context |
| 364 | @param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes |
| 365 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 366 | of raster surface; width, or height, or both, may be zero |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 367 | @param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 368 | @param props LCD striping orientation and setting for device independent |
| 369 | fonts; may be nullptr |
| 370 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 371 | */ |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 372 | static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 373 | const SkImageInfo& imageInfo, int sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 374 | const SkSurfaceProps* props) { |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 375 | return MakeRenderTarget(context, budgeted, imageInfo, sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 376 | kBottomLeft_GrSurfaceOrigin, props); |
| 377 | } |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 378 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 379 | /** Returns SkSurface on GPU indicated by context. Allocates memory for |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 380 | pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 381 | selects whether allocation for pixels is tracked by context. imageInfo |
| 382 | describes the pixel format in SkColorType, and transparency in |
| 383 | SkAlphaType, and color matching in SkColorSpace. |
| 384 | |
| 385 | SkSurface bottom-left corner is pinned to the origin. |
| 386 | |
| 387 | @param context GPU context |
| 388 | @param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes |
| 389 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 390 | of raster surface; width, or height, or both, may be zero |
| 391 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 392 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 393 | static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, |
| 394 | const SkImageInfo& imageInfo) { |
| 395 | if (!imageInfo.width() || !imageInfo.height()) { |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 396 | return nullptr; |
| 397 | } |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 398 | return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin, |
| 399 | nullptr); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 402 | /** Returns SkSurface on GPU indicated by context that is compatible with the provided |
| 403 | characterization. budgeted selects whether allocation for pixels is tracked by context. |
| 404 | |
| 405 | @param context GPU context |
| 406 | @param characterization description of the desired SkSurface |
| 407 | @param budgeted one of: SkBudgeted::kNo, SkBudgeted::kYes |
| 408 | @return SkSurface if all parameters are valid; otherwise, nullptr |
| 409 | */ |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 410 | static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 411 | const SkSurfaceCharacterization& characterization, |
| 412 | SkBudgeted budgeted); |
| 413 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 414 | /** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface |
| 415 | has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr. |
| 416 | |
| 417 | @param width one or greater |
| 418 | @param height one or greater |
| 419 | @return SkSurface if width and height are positive; otherwise, nullptr |
| 420 | */ |
Mike Reed | 44d04bd | 2017-06-28 19:57:21 -0400 | [diff] [blame] | 421 | static sk_sp<SkSurface> MakeNull(int width, int height); |
| 422 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 423 | /** Returns pixel count in each row; may be zero or greater. |
| 424 | |
| 425 | @return number of pixel columns |
| 426 | */ |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 427 | int width() const { return fWidth; } |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 428 | |
| 429 | /** Returns pixel row count; may be zero or greater. |
| 430 | |
| 431 | @return number of pixel rows |
| 432 | */ |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 433 | int height() const { return fHeight; } |
| 434 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 435 | /** Returns unique value identifying the content of SkSurface. Returned value changes |
| 436 | each time the content changes. Content is changed by drawing, or by calling |
| 437 | notifyContentWillChange(). |
| 438 | |
| 439 | @return unique content identifier |
| 440 | */ |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 441 | uint32_t generationID(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 442 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 443 | /** \enum SkSurface::ContentChangeMode |
| 444 | ContentChangeMode members are parameters to notifyContentWillChange(). |
| 445 | */ |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 446 | enum ContentChangeMode { |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 447 | kDiscard_ContentChangeMode, //!< discards surface on change |
| 448 | kRetain_ContentChangeMode, //!< preserves surface on change |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 449 | }; |
| 450 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 451 | /** Notifies that SkSurface contents will be changed by code outside of Skia. |
| 452 | Subsequent calls to generationID() return a different value. |
| 453 | |
Cary Clark | abaffd8 | 2018-11-15 08:25:12 -0500 | [diff] [blame] | 454 | TODO: Can kRetain_ContentChangeMode be deprecated? |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 455 | |
| 456 | @param mode one of: kDiscard_ContentChangeMode, kRetain_ContentChangeMode |
| 457 | */ |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 458 | void notifyContentWillChange(ContentChangeMode mode); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 459 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 460 | enum BackendHandleAccess { |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 461 | kFlushRead_BackendHandleAccess, //!< back-end object is readable |
| 462 | kFlushWrite_BackendHandleAccess, //!< back-end object is writable |
| 463 | kDiscardWrite_BackendHandleAccess, //!< back-end object must be overwritten |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 464 | }; |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 465 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 466 | /** Deprecated. |
| 467 | */ |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 468 | static const BackendHandleAccess kFlushRead_TextureHandleAccess = |
| 469 | kFlushRead_BackendHandleAccess; |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 470 | |
| 471 | /** Deprecated. |
| 472 | */ |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 473 | static const BackendHandleAccess kFlushWrite_TextureHandleAccess = |
| 474 | kFlushWrite_BackendHandleAccess; |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 475 | |
| 476 | /** Deprecated. |
| 477 | */ |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 478 | static const BackendHandleAccess kDiscardWrite_TextureHandleAccess = |
| 479 | kDiscardWrite_BackendHandleAccess; |
| 480 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 481 | /** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 482 | object is returned. Call GrBackendTexture::isValid to determine if the result |
| 483 | is valid. |
| 484 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 485 | The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted. |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 486 | |
| 487 | @param backendHandleAccess one of: kFlushRead_BackendHandleAccess, |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 488 | kFlushWrite_BackendHandleAccess, |
| 489 | kDiscardWrite_BackendHandleAccess |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 490 | @return GPU texture reference; invalid on failure |
| 491 | */ |
| 492 | GrBackendTexture getBackendTexture(BackendHandleAccess backendHandleAccess); |
| 493 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 494 | /** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 495 | object is returned. Call GrBackendRenderTarget::isValid to determine if the result |
| 496 | is valid. |
| 497 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 498 | The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 499 | or deleted. |
| 500 | |
| 501 | @param backendHandleAccess one of: kFlushRead_BackendHandleAccess, |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 502 | kFlushWrite_BackendHandleAccess, |
| 503 | kDiscardWrite_BackendHandleAccess |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 504 | @return GPU render target reference; invalid on failure |
| 505 | */ |
| 506 | GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess); |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 507 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 508 | /** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas. |
| 509 | SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface |
| 510 | is deleted. |
| 511 | |
| 512 | @return drawing SkCanvas for SkSurface |
| 513 | */ |
reed@google.com | 9ea5a3b | 2012-07-30 21:03:46 +0000 | [diff] [blame] | 514 | SkCanvas* getCanvas(); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 515 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 516 | /** Returns a compatible SkSurface, or nullptr. Returned SkSurface contains |
| 517 | the same raster, GPU, or null properties as the original. Returned SkSurface |
| 518 | does not share the same pixels. |
| 519 | |
| 520 | Returns nullptr if imageInfo width or height are zero, or if imageInfo |
| 521 | is incompatible with SkSurface. |
| 522 | |
| 523 | @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace, |
| 524 | of SkSurface; width and height must be greater than zero |
| 525 | @return compatible SkSurface or nullptr |
| 526 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 527 | sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 528 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 529 | /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents |
| 530 | are not captured. SkImage allocation is accounted for if SkSurface was created with |
| 531 | SkBudgeted::kYes. |
| 532 | |
| 533 | @return SkImage initialized with SkSurface contents |
| 534 | */ |
Robert Phillips | ac6b1fa | 2017-03-20 08:38:50 -0400 | [diff] [blame] | 535 | sk_sp<SkImage> makeImageSnapshot(); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 536 | |
Mike Reed | 114bde8 | 2018-11-21 09:12:09 -0500 | [diff] [blame] | 537 | /** |
| 538 | * Like the no-parameter version, this returns an image of the current surface contents. |
| 539 | * This variant takes a rectangle specifying the subset of the surface that is of interest. |
| 540 | * These bounds will be sanitized before being used. |
| 541 | * - If bounds extends beyond the surface, it will be trimmed to just the intersection of |
| 542 | * it and the surface. |
| 543 | * - If bounds does not intersect the surface, then this returns nullptr. |
| 544 | * - If bounds == the surface, then this is the same as calling the no-parameter variant. |
| 545 | */ |
| 546 | sk_sp<SkImage> makeImageSnapshot(const SkIRect& bounds); |
| 547 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 548 | /** Draws SkSurface contents to canvas, with its top-left corner at (x, y). |
| 549 | |
Cary Clark | 462505f | 2018-05-30 09:20:29 -0400 | [diff] [blame] | 550 | If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 551 | SkBlendMode, and SkDrawLooper. |
| 552 | |
| 553 | @param canvas SkCanvas drawn into |
| 554 | @param x horizontal offset in SkCanvas |
| 555 | @param y vertical offset in SkCanvas |
| 556 | @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, |
| 557 | and so on; or nullptr |
| 558 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 559 | void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 560 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 561 | /** Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address |
| 562 | is available, and returns true. If pixel address is not available, return |
| 563 | false and leave SkPixmap unchanged. |
| 564 | |
| 565 | pixmap contents become invalid on any future change to SkSurface. |
| 566 | |
| 567 | @param pixmap storage for pixel state if pixels are readable; otherwise, ignored |
| 568 | @return true if SkSurface has direct access to pixels |
| 569 | */ |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 570 | bool peekPixels(SkPixmap* pixmap); |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 571 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 572 | /** Copies SkRect of pixels to dst. |
| 573 | |
| 574 | Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). |
| 575 | Destination SkRect corners are (0, 0) and (dst.width(), dst.height()). |
| 576 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 577 | converting to dst.colorType() and dst.alphaType() if required. |
| 578 | |
| 579 | Pixels are readable when SkSurface is raster, or backed by a GPU. |
| 580 | |
| 581 | The destination pixel storage must be allocated by the caller. |
| 582 | |
| 583 | Pixel values are converted only if SkColorType and SkAlphaType |
| 584 | do not match. Only pixels within both source and destination rectangles |
| 585 | are copied. dst contents outside SkRect intersection are unchanged. |
| 586 | |
| 587 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 588 | |
| 589 | Does not copy, and returns false if: |
| 590 | - Source and destination rectangles do not intersect. |
| 591 | - SkPixmap pixels could not be allocated. |
| 592 | - dst.rowBytes() is too small to contain one row of pixels. |
| 593 | |
| 594 | @param dst storage for pixels copied from SkSurface |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 595 | @param srcX offset into readable pixels on x-axis; may be negative |
| 596 | @param srcY offset into readable pixels on y-axis; may be negative |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 597 | @return true if pixels were copied |
| 598 | */ |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 599 | bool readPixels(const SkPixmap& dst, int srcX, int srcY); |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 600 | |
| 601 | /** Copies SkRect of pixels from SkCanvas into dstPixels. |
| 602 | |
| 603 | Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). |
| 604 | Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
| 605 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 606 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
| 607 | |
| 608 | Pixels are readable when SkSurface is raster, or backed by a GPU. |
| 609 | |
| 610 | The destination pixel storage must be allocated by the caller. |
| 611 | |
| 612 | Pixel values are converted only if SkColorType and SkAlphaType |
| 613 | do not match. Only pixels within both source and destination rectangles |
| 614 | are copied. dstPixels contents outside SkRect intersection are unchanged. |
| 615 | |
| 616 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 617 | |
| 618 | Does not copy, and returns false if: |
| 619 | - Source and destination rectangles do not intersect. |
| 620 | - SkSurface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). |
| 621 | - dstRowBytes is too small to contain one row of pixels. |
| 622 | |
| 623 | @param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels |
| 624 | @param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger |
| 625 | @param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 626 | @param srcX offset into readable pixels on x-axis; may be negative |
| 627 | @param srcY offset into readable pixels on y-axis; may be negative |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 628 | @return true if pixels were copied |
| 629 | */ |
reed | 7543aa2 | 2014-12-09 14:39:44 -0800 | [diff] [blame] | 630 | bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 631 | int srcX, int srcY); |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 632 | |
| 633 | /** Copies SkRect of pixels from SkSurface into bitmap. |
| 634 | |
| 635 | Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). |
| 636 | Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
| 637 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 638 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
| 639 | |
| 640 | Pixels are readable when SkSurface is raster, or backed by a GPU. |
| 641 | |
| 642 | The destination pixel storage must be allocated by the caller. |
| 643 | |
| 644 | Pixel values are converted only if SkColorType and SkAlphaType |
| 645 | do not match. Only pixels within both source and destination rectangles |
| 646 | are copied. dst contents outside SkRect intersection are unchanged. |
| 647 | |
| 648 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 649 | |
| 650 | Does not copy, and returns false if: |
| 651 | - Source and destination rectangles do not intersect. |
| 652 | - SkSurface pixels could not be converted to dst.colorType() or dst.alphaType(). |
| 653 | - dst pixels could not be allocated. |
| 654 | - dst.rowBytes() is too small to contain one row of pixels. |
| 655 | |
| 656 | @param dst storage for pixels copied from SkSurface |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 657 | @param srcX offset into readable pixels on x-axis; may be negative |
| 658 | @param srcY offset into readable pixels on y-axis; may be negative |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 659 | @return true if pixels were copied |
| 660 | */ |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 661 | bool readPixels(const SkBitmap& dst, int srcX, int srcY); |
reed | 7543aa2 | 2014-12-09 14:39:44 -0800 | [diff] [blame] | 662 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 663 | /** Copies SkRect of pixels from the src SkPixmap to the SkSurface. |
| 664 | |
| 665 | Source SkRect corners are (0, 0) and (src.width(), src.height()). |
Cary Clark | 9bb34b7 | 2018-09-13 14:08:12 -0400 | [diff] [blame] | 666 | Destination SkRect corners are (dstX, dstY) and |
| 667 | (dstX + Surface width(), dstY + Surface height()). |
Cary Clark | 7651c16 | 2018-07-13 08:21:59 -0400 | [diff] [blame] | 668 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 669 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 670 | converting to SkSurface colorType() and SkSurface alphaType() if required. |
| 671 | |
| 672 | @param src storage for pixels to copy to SkSurface |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 673 | @param dstX x-axis position relative to SkSurface to begin copy; may be negative |
| 674 | @param dstY y-axis position relative to SkSurface to begin copy; may be negative |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 675 | */ |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 676 | void writePixels(const SkPixmap& src, int dstX, int dstY); |
| 677 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 678 | /** Copies SkRect of pixels from the src SkBitmap to the SkSurface. |
| 679 | |
| 680 | Source SkRect corners are (0, 0) and (src.width(), src.height()). |
Cary Clark | 9bb34b7 | 2018-09-13 14:08:12 -0400 | [diff] [blame] | 681 | Destination SkRect corners are (dstX, dstY) and |
| 682 | (dstX + Surface width(), dstY + Surface height()). |
Cary Clark | 7651c16 | 2018-07-13 08:21:59 -0400 | [diff] [blame] | 683 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 684 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 685 | converting to SkSurface colorType() and SkSurface alphaType() if required. |
| 686 | |
| 687 | @param src storage for pixels to copy to SkSurface |
Cary Clark | ca6a245 | 2018-06-14 13:21:08 -0400 | [diff] [blame] | 688 | @param dstX x-axis position relative to SkSurface to begin copy; may be negative |
| 689 | @param dstY y-axis position relative to SkSurface to begin copy; may be negative |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 690 | */ |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 691 | void writePixels(const SkBitmap& src, int dstX, int dstY); |
| 692 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 693 | /** Returns SkSurfaceProps for surface. |
| 694 | |
| 695 | @return LCD striping orientation and setting for device independent fonts |
| 696 | */ |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 697 | const SkSurfaceProps& props() const { return fProps; } |
| 698 | |
Cary Clark | abaffd8 | 2018-11-15 08:25:12 -0500 | [diff] [blame] | 699 | /** Deprecated. |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 700 | */ |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 701 | void prepareForExternalIO(); |
| 702 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 703 | /** Issues pending SkSurface commands to the GPU-backed API and resolves any SkSurface MSAA. |
| 704 | |
| 705 | Skia flushes as needed, so it is not necessary to call this if Skia manages |
| 706 | drawing and object lifetime. Call when interleaving Skia calls with native |
| 707 | GPU calls. |
| 708 | */ |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 709 | void flush(); |
| 710 | |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 711 | enum class BackendSurfaceAccess { |
| 712 | kNoAccess, //!< back-end object will not be used by client |
| 713 | kPresent, //!< back-end surface will be used for presenting to screen |
| 714 | }; |
| 715 | |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 716 | /** Issues pending SkSurface commands to the GPU-backed API and resolves any SkSurface MSAA. |
| 717 | After issuing all commands, signalSemaphores of count numSemaphores are signaled by the GPU. |
| 718 | The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is |
| 719 | passed in. |
| 720 | |
| 721 | If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU. |
| 722 | |
| 723 | If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is |
| 724 | treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the |
| 725 | SkSurface will be transferred back to its original queue. If the SkSurface was created by |
| 726 | wrapping a VkImage, the queue will be set to the queue which was originally passed in on |
| 727 | the GrVkImageInfo. Additionally, if the original queue was not external or foreign the |
| 728 | layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR. |
| 729 | |
| 730 | For each GrBackendSemaphore in signalSemaphores: |
| 731 | if GrBackendSemaphore is initialized, the GPU back-end uses the semaphore as is; |
| 732 | otherwise, a new semaphore is created and initializes GrBackendSemaphore. |
| 733 | |
| 734 | The caller must delete the semaphores created and returned in signalSemaphores. |
| 735 | GrBackendSemaphore can be deleted as soon as this function returns. |
| 736 | |
| 737 | If the back-end API is OpenGL only uninitialized backend semaphores are supported. |
| 738 | |
| 739 | If the back-end API is Vulkan semaphores may be initialized or uninitialized. |
| 740 | If uninitialized, created semaphores are valid only with the VkDevice |
| 741 | with which they were created. |
| 742 | |
| 743 | If GrSemaphoresSubmitted::kNo is returned, the GPU back-end did not create or |
| 744 | add any semaphores to signal on the GPU; the caller should not instruct the GPU |
| 745 | to wait on any of the semaphores. |
| 746 | |
| 747 | Pending surface commands are flushed regardless of the return result. |
| 748 | |
| 749 | @param access type of access the call will do on the backend object after flush |
| 750 | @param flags flush options |
| 751 | @param numSemaphores size of signalSemaphores array |
| 752 | @param signalSemaphores array of semaphore containers |
| 753 | @return one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo |
| 754 | */ |
Greg Daniel | b9990e4 | 2019-04-10 16:28:52 -0400 | [diff] [blame^] | 755 | GrSemaphoresSubmitted flush(BackendSurfaceAccess access, GrFlushFlags flags, |
| 756 | int numSemaphores, GrBackendSemaphore signalSemaphores[]); |
| 757 | |
| 758 | /** The below enum and flush call are deprected |
| 759 | */ |
| 760 | |
| 761 | enum FlushFlags { |
| 762 | kNone_FlushFlags = 0, |
| 763 | // flush will wait till all submitted GPU work is finished before returning. |
| 764 | kSyncCpu_FlushFlag = 0x1, |
| 765 | }; |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 766 | GrSemaphoresSubmitted flush(BackendSurfaceAccess access, FlushFlags flags, |
| 767 | int numSemaphores, GrBackendSemaphore signalSemaphores[]); |
| 768 | |
Greg Daniel | b9990e4 | 2019-04-10 16:28:52 -0400 | [diff] [blame^] | 769 | /** Deprecated. |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 770 | */ |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 771 | GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, |
| 772 | GrBackendSemaphore signalSemaphores[]); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 773 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 774 | /** Inserts a list of GPU semaphores that the current GPU-backed API must wait on before |
| 775 | executing any more commands on the GPU for this surface. Skia will take ownership of the |
| 776 | underlying semaphores and delete them once they have been signaled and waited on. |
| 777 | If this call returns false, then the GPU back-end will not wait on any passed in semaphores, |
| 778 | and the client will still own the semaphores. |
| 779 | |
| 780 | @param numSemaphores size of waitSemaphores array |
| 781 | @param waitSemaphores array of semaphore containers |
| 782 | @return true if GPU is waiting on semaphores |
| 783 | */ |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 784 | bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 785 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 786 | /** Initializes SkSurfaceCharacterization that can be used to perform GPU back-end |
| 787 | processing in a separate thread. Typically this is used to divide drawing |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 788 | into multiple tiles. SkDeferredDisplayListRecorder records the drawing commands |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 789 | for each tile. |
| 790 | |
| 791 | Return true if SkSurface supports characterization. raster surface returns false. |
| 792 | |
| 793 | @param characterization properties for parallel drawing |
| 794 | @return true if supported |
| 795 | */ |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 796 | bool characterize(SkSurfaceCharacterization* characterization) const; |
| 797 | |
Cary Clark | 7595939 | 2018-02-27 10:22:04 -0500 | [diff] [blame] | 798 | /** Draws deferred display list created using SkDeferredDisplayListRecorder. |
| 799 | Has no effect and returns false if SkSurfaceCharacterization stored in |
| 800 | deferredDisplayList is not compatible with SkSurface. |
| 801 | |
| 802 | raster surface returns false. |
| 803 | |
| 804 | @param deferredDisplayList drawing commands |
| 805 | @return false if deferredDisplayList is not compatible |
| 806 | */ |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 807 | bool draw(SkDeferredDisplayList* deferredDisplayList); |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 808 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 809 | protected: |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 810 | SkSurface(int width, int height, const SkSurfaceProps* surfaceProps); |
| 811 | SkSurface(const SkImageInfo& imageInfo, const SkSurfaceProps* surfaceProps); |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 812 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 813 | // called by subclass if their contents have changed |
| 814 | void dirtyGenerationID() { |
| 815 | fGenerationID = 0; |
| 816 | } |
| 817 | |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 818 | private: |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 819 | const SkSurfaceProps fProps; |
| 820 | const int fWidth; |
| 821 | const int fHeight; |
| 822 | uint32_t fGenerationID; |
skia.committer@gmail.com | a27096b | 2012-08-30 14:38:00 +0000 | [diff] [blame] | 823 | |
reed@google.com | 7edfb49 | 2012-08-28 12:48:35 +0000 | [diff] [blame] | 824 | typedef SkRefCnt INHERITED; |
reed@google.com | 889b09e | 2012-07-27 21:10:42 +0000 | [diff] [blame] | 825 | }; |
| 826 | |
| 827 | #endif |