blob: 48ec1f6342465a1166868b85660e208b6202d471 [file] [log] [blame]
reed@google.com889b09e2012-07-27 21:10:42 +00001/*
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"
reed4a8126e2014-09-22 07:29:03 -070013#include "SkSurfaceProps.h"
reed@google.com889b09e2012-07-27 21:10:42 +000014
Greg Daniel51316782017-08-02 15:10:09 +000015#include "GrTypes.h"
16
Greg Daniel173464d2019-02-06 15:30:34 -050017#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
18#include <android/hardware_buffer.h>
19#endif
20
reed@google.com889b09e2012-07-27 21:10:42 +000021class SkCanvas;
Robert Phillipsad8a43f2017-08-30 12:06:35 -040022class SkDeferredDisplayList;
reed@google.com889b09e2012-07-27 21:10:42 +000023class SkPaint;
Robert Phillipsad8a43f2017-08-30 12:06:35 -040024class SkSurfaceCharacterization;
Greg Daniel94403452017-04-18 15:52:36 -040025class GrBackendRenderTarget;
Greg Daniela5cb7812017-06-16 09:45:32 -040026class GrBackendSemaphore;
Robert Phillips8caf85f2018-04-05 09:30:38 -040027class GrBackendTexture;
reed@google.com5d4ba882012-07-31 15:45:27 +000028class GrContext;
Robert Phillips9338c602019-02-19 12:52:29 -050029class GrRecordingContext;
reed@google.com5d4ba882012-07-31 15:45:27 +000030class GrRenderTarget;
reed@google.com889b09e2012-07-27 21:10:42 +000031
Cary Clark75959392018-02-27 10:22:04 -050032/** \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.org96447be2013-04-18 13:28:19 +000040class SK_API SkSurface : public SkRefCnt {
reed@google.com889b09e2012-07-27 21:10:42 +000041public:
Cary Clark75959392018-02-27 10:22:04 -050042
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 Clark60aaeb22017-11-03 08:06:09 -040064 static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels,
65 size_t rowBytes,
66 const SkSurfaceProps* surfaceProps = nullptr);
reed@google.com889b09e2012-07-27 21:10:42 +000067
Cary Clark75959392018-02-27 10:22:04 -050068 /** 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 Clark60aaeb22017-11-03 08:06:09 -040092 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);
reed982542d2014-06-27 06:48:14 -070096
Cary Clark75959392018-02-27 10:22:04 -050097 /** 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 Clark60aaeb22017-11-03 08:06:09 -0400118 static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes,
119 const SkSurfaceProps* surfaceProps);
reed9cd016e2016-01-30 10:01:06 -0800120
Cary Clark75959392018-02-27 10:22:04 -0500121 /** 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 Clark60aaeb22017-11-03 08:06:09 -0400137 static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo,
fmalita03912f12016-07-06 06:22:06 -0700138 const SkSurfaceProps* props = nullptr) {
Cary Clark60aaeb22017-11-03 08:06:09 -0400139 return MakeRaster(imageInfo, 0, props);
fmalita03912f12016-07-06 06:22:06 -0700140 }
reed@google.com889b09e2012-07-27 21:10:42 +0000141
Cary Clark75959392018-02-27 10:22:04 -0500142 /** 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 Clark462505f2018-05-30 09:20:29 -0400146 Internally, sets SkImageInfo to width, height, native color type, and
Cary Clark75959392018-02-27 10:22:04 -0500147 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 */
reede8f30622016-03-23 18:59:25 -0700160 static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
Mike Klein9707e902019-02-07 16:18:22 -0500161 const SkSurfaceProps* surfaceProps = nullptr);
reed@google.com636d87a2013-09-17 20:03:43 +0000162
Greg Daniel8ce79912019-02-05 10:08:43 -0500163 /** 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 Clark75959392018-02-27 10:22:04 -0500172 /** 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 Daniel8ce79912019-02-05 10:08:43 -0500185 @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 Clark75959392018-02-27 10:22:04 -0500201 */
Greg Danielfaa095e2017-12-19 13:15:02 -0500202 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 Daniel8ce79912019-02-05 10:08:43 -0500207 const SkSurfaceProps* surfaceProps,
208 TextureReleaseProc textureReleaseProc = nullptr,
209 ReleaseContext releaseContext = nullptr);
Greg Danielfaa095e2017-12-19 13:15:02 -0500210
Cary Clarkecf548b2018-04-03 11:49:10 -0400211 /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget
212 is valid for the lifetime of returned SkSurface.
Cary Clark75959392018-02-27 10:22:04 -0500213
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 Daniel8ce79912019-02-05 10:08:43 -0500223 @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 Reed186669c2019-02-13 14:26:37 -0500237 @param releaseProc function called when texture can be released
Greg Daniel8ce79912019-02-05 10:08:43 -0500238 @param releaseContext state passed to textureReleaseProc
239 @return SkSurface if all parameters are valid; otherwise, nullptr
Cary Clark75959392018-02-27 10:22:04 -0500240 */
Greg Danielfaa095e2017-12-19 13:15:02 -0500241 static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context,
242 const GrBackendRenderTarget& backendRenderTarget,
243 GrSurfaceOrigin origin,
244 SkColorType colorType,
245 sk_sp<SkColorSpace> colorSpace,
Greg Daniel8ce79912019-02-05 10:08:43 -0500246 const SkSurfaceProps* surfaceProps,
Mike Reed186669c2019-02-13 14:26:37 -0500247 RenderTargetReleaseProc releaseProc = nullptr,
Greg Daniel8ce79912019-02-05 10:08:43 -0500248 ReleaseContext releaseContext = nullptr);
Greg Danielfaa095e2017-12-19 13:15:02 -0500249
Cary Clarkecf548b2018-04-03 11:49:10 -0400250 /** 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 Clark75959392018-02-27 10:22:04 -0500262
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 Clarkecf548b2018-04-03 11:49:10 -0400269 @param colorType one of:
270 kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
Cary Clark82456492018-10-31 10:54:50 -0400271 kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
272 kRGB_888x_SkColorType, kBGRA_8888_SkColorType,
273 kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
Cary Clark75959392018-02-27 10:22:04 -0500274 kGray_8_SkColorType, kRGBA_F16_SkColorType
Cary Clarkecf548b2018-04-03 11:49:10 -0400275 @param colorSpace range of colors; may be nullptr
Cary Clark75959392018-02-27 10:22:04 -0500276 @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 Danielfaa095e2017-12-19 13:15:02 -0500280 static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context,
281 const GrBackendTexture& backendTexture,
282 GrSurfaceOrigin origin,
283 int sampleCnt,
Cary Clarkf059e7c2017-12-20 14:53:21 -0500284 SkColorType colorType,
Greg Danielfaa095e2017-12-19 13:15:02 -0500285 sk_sp<SkColorSpace> colorSpace,
286 const SkSurfaceProps* surfaceProps);
287
Greg Daniel173464d2019-02-06 15:30:34 -0500288#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
Mike Reed186669c2019-02-13 14:26:37 -0500289 /** Private.
290 Creates SkSurface from Android hardware buffer.
Greg Daniel173464d2019-02-06 15:30:34 -0500291 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 Clark75959392018-02-27 10:22:04 -0500316 /** Returns SkSurface on GPU indicated by context. Allocates memory for
Cary Clark82456492018-10-31 10:54:50 -0400317 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
Cary Clark75959392018-02-27 10:22:04 -0500318 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 Clarkca6a2452018-06-14 13:21:08 -0400323 Pass zero to disable multi-sample anti-aliasing. The request is rounded
Cary Clark75959392018-02-27 10:22:04 -0500324 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 Clarkca6a2452018-06-14 13:21:08 -0400329 shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
Cary Clark75959392018-02-27 10:22:04 -0500330
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 Clarkca6a2452018-06-14 13:21:08 -0400341 @param shouldCreateWithMips hint that SkSurface will host mip map images
Cary Clark75959392018-02-27 10:22:04 -0500342 @return SkSurface if all parameters are valid; otherwise, nullptr
343 */
Cary Clark60aaeb22017-11-03 08:06:09 -0400344 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
345 const SkImageInfo& imageInfo,
346 int sampleCount, GrSurfaceOrigin surfaceOrigin,
347 const SkSurfaceProps* surfaceProps,
Greg Daniele252f082017-10-23 16:05:23 -0400348 bool shouldCreateWithMips = false);
robertphillips7e922762016-07-26 11:38:17 -0700349
Cary Clark75959392018-02-27 10:22:04 -0500350 /** Returns SkSurface on GPU indicated by context. Allocates memory for
Cary Clark82456492018-10-31 10:54:50 -0400351 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
Cary Clark75959392018-02-27 10:22:04 -0500352 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 Clarkca6a2452018-06-14 13:21:08 -0400357 Pass zero to disable multi-sample anti-aliasing. The request is rounded
Cary Clark75959392018-02-27 10:22:04 -0500358 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 Clarkca6a2452018-06-14 13:21:08 -0400367 @param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
Cary Clark75959392018-02-27 10:22:04 -0500368 @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 */
robertphillips7e922762016-07-26 11:38:17 -0700372 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
Cary Clark60aaeb22017-11-03 08:06:09 -0400373 const SkImageInfo& imageInfo, int sampleCount,
robertphillips7e922762016-07-26 11:38:17 -0700374 const SkSurfaceProps* props) {
Cary Clark60aaeb22017-11-03 08:06:09 -0400375 return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
robertphillips7e922762016-07-26 11:38:17 -0700376 kBottomLeft_GrSurfaceOrigin, props);
377 }
reed4a8126e2014-09-22 07:29:03 -0700378
Cary Clark75959392018-02-27 10:22:04 -0500379 /** Returns SkSurface on GPU indicated by context. Allocates memory for
Cary Clark82456492018-10-31 10:54:50 -0400380 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
Cary Clark75959392018-02-27 10:22:04 -0500381 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 Clark60aaeb22017-11-03 08:06:09 -0400393 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
394 const SkImageInfo& imageInfo) {
395 if (!imageInfo.width() || !imageInfo.height()) {
Robert Phillipsd6214d42016-11-07 08:23:48 -0500396 return nullptr;
397 }
Cary Clark60aaeb22017-11-03 08:06:09 -0400398 return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
399 nullptr);
reede8f30622016-03-23 18:59:25 -0700400 }
401
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400402 /** 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 Phillips9338c602019-02-19 12:52:29 -0500410 static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400411 const SkSurfaceCharacterization& characterization,
412 SkBudgeted budgeted);
413
Cary Clark75959392018-02-27 10:22:04 -0500414 /** 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 Reed44d04bd2017-06-28 19:57:21 -0400421 static sk_sp<SkSurface> MakeNull(int width, int height);
422
Cary Clark75959392018-02-27 10:22:04 -0500423 /** Returns pixel count in each row; may be zero or greater.
424
425 @return number of pixel columns
426 */
reed@google.com889b09e2012-07-27 21:10:42 +0000427 int width() const { return fWidth; }
Cary Clark75959392018-02-27 10:22:04 -0500428
429 /** Returns pixel row count; may be zero or greater.
430
431 @return number of pixel rows
432 */
reed@google.com889b09e2012-07-27 21:10:42 +0000433 int height() const { return fHeight; }
434
Cary Clark75959392018-02-27 10:22:04 -0500435 /** 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.com97af1a62012-08-28 12:19:02 +0000441 uint32_t generationID();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000442
Cary Clark75959392018-02-27 10:22:04 -0500443 /** \enum SkSurface::ContentChangeMode
444 ContentChangeMode members are parameters to notifyContentWillChange().
445 */
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000446 enum ContentChangeMode {
Cary Clark462505f2018-05-30 09:20:29 -0400447 kDiscard_ContentChangeMode, //!< discards surface on change
448 kRetain_ContentChangeMode, //!< preserves surface on change
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000449 };
450
Cary Clark75959392018-02-27 10:22:04 -0500451 /** Notifies that SkSurface contents will be changed by code outside of Skia.
452 Subsequent calls to generationID() return a different value.
453
Cary Clarkabaffd82018-11-15 08:25:12 -0500454 TODO: Can kRetain_ContentChangeMode be deprecated?
Cary Clark75959392018-02-27 10:22:04 -0500455
456 @param mode one of: kDiscard_ContentChangeMode, kRetain_ContentChangeMode
457 */
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000458 void notifyContentWillChange(ContentChangeMode mode);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000459
joshualitt81793412015-07-08 12:54:04 -0700460 enum BackendHandleAccess {
Cary Clark462505f2018-05-30 09:20:29 -0400461 kFlushRead_BackendHandleAccess, //!< back-end object is readable
462 kFlushWrite_BackendHandleAccess, //!< back-end object is writable
463 kDiscardWrite_BackendHandleAccess, //!< back-end object must be overwritten
reedfa5e68e2015-06-29 07:37:01 -0700464 };
joshualitt81793412015-07-08 12:54:04 -0700465
Cary Clark75959392018-02-27 10:22:04 -0500466 /** Deprecated.
467 */
joshualitt81793412015-07-08 12:54:04 -0700468 static const BackendHandleAccess kFlushRead_TextureHandleAccess =
469 kFlushRead_BackendHandleAccess;
Cary Clark75959392018-02-27 10:22:04 -0500470
471 /** Deprecated.
472 */
joshualitt81793412015-07-08 12:54:04 -0700473 static const BackendHandleAccess kFlushWrite_TextureHandleAccess =
474 kFlushWrite_BackendHandleAccess;
Cary Clark75959392018-02-27 10:22:04 -0500475
476 /** Deprecated.
477 */
joshualitt81793412015-07-08 12:54:04 -0700478 static const BackendHandleAccess kDiscardWrite_TextureHandleAccess =
479 kDiscardWrite_BackendHandleAccess;
480
Cary Clark462505f2018-05-30 09:20:29 -0400481 /** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid
Robert Phillips8caf85f2018-04-05 09:30:38 -0400482 object is returned. Call GrBackendTexture::isValid to determine if the result
483 is valid.
484
Cary Clark462505f2018-05-30 09:20:29 -0400485 The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.
Robert Phillips8caf85f2018-04-05 09:30:38 -0400486
487 @param backendHandleAccess one of: kFlushRead_BackendHandleAccess,
Cary Clark82456492018-10-31 10:54:50 -0400488 kFlushWrite_BackendHandleAccess,
489 kDiscardWrite_BackendHandleAccess
Robert Phillips8caf85f2018-04-05 09:30:38 -0400490 @return GPU texture reference; invalid on failure
491 */
492 GrBackendTexture getBackendTexture(BackendHandleAccess backendHandleAccess);
493
Cary Clark462505f2018-05-30 09:20:29 -0400494 /** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid
Robert Phillips8caf85f2018-04-05 09:30:38 -0400495 object is returned. Call GrBackendRenderTarget::isValid to determine if the result
496 is valid.
497
Cary Clark462505f2018-05-30 09:20:29 -0400498 The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to
Robert Phillips8caf85f2018-04-05 09:30:38 -0400499 or deleted.
500
501 @param backendHandleAccess one of: kFlushRead_BackendHandleAccess,
Cary Clark82456492018-10-31 10:54:50 -0400502 kFlushWrite_BackendHandleAccess,
503 kDiscardWrite_BackendHandleAccess
Robert Phillips8caf85f2018-04-05 09:30:38 -0400504 @return GPU render target reference; invalid on failure
505 */
506 GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess);
Robert Phillips8caf85f2018-04-05 09:30:38 -0400507
Cary Clark75959392018-02-27 10:22:04 -0500508 /** 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.com9ea5a3b2012-07-30 21:03:46 +0000514 SkCanvas* getCanvas();
reed@google.com889b09e2012-07-27 21:10:42 +0000515
Cary Clark75959392018-02-27 10:22:04 -0500516 /** 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 Clark60aaeb22017-11-03 08:06:09 -0400527 sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo);
reed@google.com889b09e2012-07-27 21:10:42 +0000528
Cary Clark75959392018-02-27 10:22:04 -0500529 /** 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 Phillipsac6b1fa2017-03-20 08:38:50 -0400535 sk_sp<SkImage> makeImageSnapshot();
reed@google.com889b09e2012-07-27 21:10:42 +0000536
Mike Reed114bde82018-11-21 09:12:09 -0500537 /**
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 Clark75959392018-02-27 10:22:04 -0500548 /** Draws SkSurface contents to canvas, with its top-left corner at (x, y).
549
Cary Clark462505f2018-05-30 09:20:29 -0400550 If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter,
Cary Clark75959392018-02-27 10:22:04 -0500551 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 Clark60aaeb22017-11-03 08:06:09 -0400559 void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint);
reed@google.com889b09e2012-07-27 21:10:42 +0000560
Cary Clark75959392018-02-27 10:22:04 -0500561 /** 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 Clark60aaeb22017-11-03 08:06:09 -0400570 bool peekPixels(SkPixmap* pixmap);
reed6ceeebd2016-03-09 14:26:26 -0800571
Cary Clark75959392018-02-27 10:22:04 -0500572 /** 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 Clarkca6a2452018-06-14 13:21:08 -0400595 @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 Clark75959392018-02-27 10:22:04 -0500597 @return true if pixels were copied
598 */
Mike Reed353196f2017-07-21 11:01:18 -0400599 bool readPixels(const SkPixmap& dst, int srcX, int srcY);
Cary Clark75959392018-02-27 10:22:04 -0500600
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 Clarkca6a2452018-06-14 13:21:08 -0400626 @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 Clark75959392018-02-27 10:22:04 -0500628 @return true if pixels were copied
629 */
reed7543aa22014-12-09 14:39:44 -0800630 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
631 int srcX, int srcY);
Cary Clark75959392018-02-27 10:22:04 -0500632
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 Clarkca6a2452018-06-14 13:21:08 -0400657 @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 Clark75959392018-02-27 10:22:04 -0500659 @return true if pixels were copied
660 */
Mike Reed353196f2017-07-21 11:01:18 -0400661 bool readPixels(const SkBitmap& dst, int srcX, int srcY);
reed7543aa22014-12-09 14:39:44 -0800662
Cary Clark75959392018-02-27 10:22:04 -0500663 /** 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 Clark9bb34b72018-09-13 14:08:12 -0400666 Destination SkRect corners are (dstX, dstY) and
667 (dstX + Surface width(), dstY + Surface height()).
Cary Clark7651c162018-07-13 08:21:59 -0400668
Cary Clark75959392018-02-27 10:22:04 -0500669 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 Clarkca6a2452018-06-14 13:21:08 -0400673 @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 Clark75959392018-02-27 10:22:04 -0500675 */
Mike Reed4c790bd2018-02-08 14:10:40 -0500676 void writePixels(const SkPixmap& src, int dstX, int dstY);
677
Cary Clark75959392018-02-27 10:22:04 -0500678 /** 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 Clark9bb34b72018-09-13 14:08:12 -0400681 Destination SkRect corners are (dstX, dstY) and
682 (dstX + Surface width(), dstY + Surface height()).
Cary Clark7651c162018-07-13 08:21:59 -0400683
Cary Clark75959392018-02-27 10:22:04 -0500684 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 Clarkca6a2452018-06-14 13:21:08 -0400688 @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 Clark75959392018-02-27 10:22:04 -0500690 */
Mike Reed4c790bd2018-02-08 14:10:40 -0500691 void writePixels(const SkBitmap& src, int dstX, int dstY);
692
Cary Clark75959392018-02-27 10:22:04 -0500693 /** Returns SkSurfaceProps for surface.
694
695 @return LCD striping orientation and setting for device independent fonts
696 */
reed4a8126e2014-09-22 07:29:03 -0700697 const SkSurfaceProps& props() const { return fProps; }
698
Cary Clarkabaffd82018-11-15 08:25:12 -0500699 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500700 */
ericrkf7b8b8a2016-02-24 14:49:51 -0800701 void prepareForExternalIO();
702
Cary Clark75959392018-02-27 10:22:04 -0500703 /** 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 Daniela5cb7812017-06-16 09:45:32 -0400709 void flush();
710
Greg Danielbae71212019-03-01 15:24:35 -0500711 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 Danielbae71212019-03-01 15:24:35 -0500716 /** 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 Danielb9990e42019-04-10 16:28:52 -0400755 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 Danielbae71212019-03-01 15:24:35 -0500766 GrSemaphoresSubmitted flush(BackendSurfaceAccess access, FlushFlags flags,
767 int numSemaphores, GrBackendSemaphore signalSemaphores[]);
768
Greg Danielb9990e42019-04-10 16:28:52 -0400769 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500770 */
Greg Daniel51316782017-08-02 15:10:09 +0000771 GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores,
772 GrBackendSemaphore signalSemaphores[]);
Greg Daniela5cb7812017-06-16 09:45:32 -0400773
Cary Clark75959392018-02-27 10:22:04 -0500774 /** 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 Danielc64ee462017-06-15 16:59:49 -0400784 bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
Greg Daniela5cb7812017-06-16 09:45:32 -0400785
Cary Clark75959392018-02-27 10:22:04 -0500786 /** 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 Clark82456492018-10-31 10:54:50 -0400788 into multiple tiles. SkDeferredDisplayListRecorder records the drawing commands
Cary Clark75959392018-02-27 10:22:04 -0500789 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 Phillipsad8a43f2017-08-30 12:06:35 -0400796 bool characterize(SkSurfaceCharacterization* characterization) const;
797
Cary Clark75959392018-02-27 10:22:04 -0500798 /** 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 Phillips7ffbcf92017-12-04 12:52:46 -0500807 bool draw(SkDeferredDisplayList* deferredDisplayList);
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400808
reed@google.com889b09e2012-07-27 21:10:42 +0000809protected:
Cary Clark60aaeb22017-11-03 08:06:09 -0400810 SkSurface(int width, int height, const SkSurfaceProps* surfaceProps);
811 SkSurface(const SkImageInfo& imageInfo, const SkSurfaceProps* surfaceProps);
reed@google.com889b09e2012-07-27 21:10:42 +0000812
reed@google.com97af1a62012-08-28 12:19:02 +0000813 // called by subclass if their contents have changed
814 void dirtyGenerationID() {
815 fGenerationID = 0;
816 }
817
reed@google.com889b09e2012-07-27 21:10:42 +0000818private:
reed4a8126e2014-09-22 07:29:03 -0700819 const SkSurfaceProps fProps;
820 const int fWidth;
821 const int fHeight;
822 uint32_t fGenerationID;
skia.committer@gmail.coma27096b2012-08-30 14:38:00 +0000823
reed@google.com7edfb492012-08-28 12:48:35 +0000824 typedef SkRefCnt INHERITED;
reed@google.com889b09e2012-07-27 21:10:42 +0000825};
826
827#endif