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 "include/core/SkImage.h"
12#include "include/core/SkPixmap.h"
13#include "include/core/SkRefCnt.h"
14#include "include/core/SkSurfaceProps.h"
15
16#include "include/gpu/GrTypes.h"
17
18#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
19#include <android/hardware_buffer.h>
20#endif
21
22#ifdef SK_METAL
23#include "include/gpu/mtl/GrMtlTypes.h"
24#endif
25
26class SkCanvas;
27class SkDeferredDisplayList;
28class SkPaint;
29class SkSurfaceCharacterization;
30class GrBackendRenderTarget;
31class GrBackendSemaphore;
32class GrBackendSurfaceMutableState;
33class GrBackendTexture;
34class GrContext;
35class GrRecordingContext;
36class GrRenderTarget;
37
38/** \class SkSurface
39 SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
40 allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
41 SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call
42 surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface).
43 SkSurface always has non-zero dimensions. If there is a request for a new surface, and either
44 of the requested dimensions are zero, then nullptr will be returned.
45*/
46class SK_API SkSurface : public SkRefCnt {
47public:
48
49 /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
50
51 SkSurface is returned if all parameters are valid.
52 Valid parameters include:
53 info dimensions are greater than zero;
54 info contains SkColorType and SkAlphaType supported by raster surface;
55 pixels is not nullptr;
56 rowBytes is large enough to contain info width pixels of SkColorType.
57
58 Pixel buffer size should be info height times computed rowBytes.
59 Pixels are not initialized.
60 To access pixels after drawing, peekPixels() or readPixels().
61
62 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
63 of raster surface; width and height must be greater than zero
64 @param pixels pointer to destination pixels buffer
65 @param rowBytes interval from one SkSurface row to the next
66 @param surfaceProps LCD striping orientation and setting for device independent fonts;
67 may be nullptr
68 @return SkSurface if all parameters are valid; otherwise, nullptr
69 */
70 static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels,
71 size_t rowBytes,
72 const SkSurfaceProps* surfaceProps = nullptr);
73
74 static sk_sp<SkSurface> MakeRasterDirect(const SkPixmap& pm,
75 const SkSurfaceProps* props = nullptr) {
76 return MakeRasterDirect(pm.info(), pm.writable_addr(), pm.rowBytes(), props);
77 }
78
79 /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
80 releaseProc is called with pixels and context when SkSurface is deleted.
81
82 SkSurface is returned if all parameters are valid.
83 Valid parameters include:
84 info dimensions are greater than zero;
85 info contains SkColorType and SkAlphaType supported by raster surface;
86 pixels is not nullptr;
87 rowBytes is large enough to contain info width pixels of SkColorType.
88
89 Pixel buffer size should be info height times computed rowBytes.
90 Pixels are not initialized.
91 To access pixels after drawing, call flush() or peekPixels().
92
93 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
94 of raster surface; width and height must be greater than zero
95 @param pixels pointer to destination pixels buffer
96 @param rowBytes interval from one SkSurface row to the next
97 @param releaseProc called when SkSurface is deleted; may be nullptr
98 @param context passed to releaseProc; may be nullptr
99 @param surfaceProps LCD striping orientation and setting for device independent fonts;
100 may be nullptr
101 @return SkSurface if all parameters are valid; otherwise, nullptr
102 */
103 static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels,
104 size_t rowBytes,
105 void (*releaseProc)(void* pixels, void* context),
106 void* context, const SkSurfaceProps* surfaceProps = nullptr);
107
108 /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
109 Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
110 rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero.
111 Pixel memory is deleted when SkSurface is deleted.
112
113 SkSurface is returned if all parameters are valid.
114 Valid parameters include:
115 info dimensions are greater than zero;
116 info contains SkColorType and SkAlphaType supported by raster surface;
117 rowBytes is large enough to contain info width pixels of SkColorType, or is zero.
118
119 If rowBytes is zero, a suitable value will be chosen internally.
120
121 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
122 of raster surface; width and height must be greater than zero
123 @param rowBytes interval from one SkSurface row to the next; may be zero
124 @param surfaceProps LCD striping orientation and setting for device independent fonts;
125 may be nullptr
126 @return SkSurface if all parameters are valid; otherwise, nullptr
127 */
128 static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes,
129 const SkSurfaceProps* surfaceProps);
130
131 /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
132 Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
133 imageInfo.minRowBytes().
134 Pixel memory is deleted when SkSurface is deleted.
135
136 SkSurface is returned if all parameters are valid.
137 Valid parameters include:
138 info dimensions are greater than zero;
139 info contains SkColorType and SkAlphaType supported by raster surface.
140
141 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
142 of raster surface; width and height must be greater than zero
143 @param props LCD striping orientation and setting for device independent fonts;
144 may be nullptr
145 @return SkSurface if all parameters are valid; otherwise, nullptr
146 */
147 static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo,
148 const SkSurfaceProps* props = nullptr) {
149 return MakeRaster(imageInfo, 0, props);
150 }
151
152 /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
153 Allocates and zeroes pixel memory. Pixel memory size is height times width times
154 four. Pixel memory is deleted when SkSurface is deleted.
155
156 Internally, sets SkImageInfo to width, height, native color type, and
157 kPremul_SkAlphaType.
158
159 SkSurface is returned if width and height are greater than zero.
160
161 Use to create SkSurface that matches SkPMColor, the native pixel arrangement on
162 the platform. SkSurface drawn to output device skips converting its pixel format.
163
164 @param width pixel column count; must be greater than zero
165 @param height pixel row count; must be greater than zero
166 @param surfaceProps LCD striping orientation and setting for device independent
167 fonts; may be nullptr
168 @return SkSurface if all parameters are valid; otherwise, nullptr
169 */
170 static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
171 const SkSurfaceProps* surfaceProps = nullptr);
172
173 /** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */
174 typedef void* ReleaseContext;
175
176 /** User function called when supplied render target may be deleted. */
177 typedef void (*RenderTargetReleaseProc)(ReleaseContext releaseContext);
178
179 /** User function called when supplied texture may be deleted. */
180 typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
181
182 /** Wraps a GPU-backed texture into SkSurface. Caller must ensure the texture is
183 valid for the lifetime of returned SkSurface. If sampleCnt greater than zero,
184 creates an intermediate MSAA SkSurface which is used for drawing backendTexture.
185
186 SkSurface is returned if all parameters are valid. backendTexture is valid if
187 its pixel configuration agrees with colorSpace and context; for instance, if
188 backendTexture has an sRGB configuration, then context must support sRGB,
189 and colorSpace must be present. Further, backendTexture width and height must
190 not exceed context capabilities, and the context must be able to support
191 back-end textures.
192
193 Upon success textureReleaseProc is called when it is safe to delete the texture in the
194 backend API (accounting only for use of the texture by this surface). If SkSurface creation
195 fails textureReleaseProc is called before this function returns.
196
197 If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
198
199 @param context GPU context
200 @param backendTexture texture residing on GPU
201 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
202 @param colorSpace range of colors; may be nullptr
203 @param surfaceProps LCD striping orientation and setting for device independent
204 fonts; may be nullptr
205 @param textureReleaseProc function called when texture can be released
206 @param releaseContext state passed to textureReleaseProc
207 @return SkSurface if all parameters are valid; otherwise, nullptr
208 */
209 static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context,
210 const GrBackendTexture& backendTexture,
211 GrSurfaceOrigin origin, int sampleCnt,
212 SkColorType colorType,
213 sk_sp<SkColorSpace> colorSpace,
214 const SkSurfaceProps* surfaceProps,
215 TextureReleaseProc textureReleaseProc = nullptr,
216 ReleaseContext releaseContext = nullptr);
217
218 /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget
219 is valid for the lifetime of returned SkSurface.
220
221 SkSurface is returned if all parameters are valid. backendRenderTarget is valid if
222 its pixel configuration agrees with colorSpace and context; for instance, if
223 backendRenderTarget has an sRGB configuration, then context must support sRGB,
224 and colorSpace must be present. Further, backendRenderTarget width and height must
225 not exceed context capabilities, and the context must be able to support
226 back-end render targets.
227
228 Upon success releaseProc is called when it is safe to delete the render target in the
229 backend API (accounting only for use of the render target by this surface). If SkSurface
230 creation fails releaseProc is called before this function returns.
231
232 If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
233
234 @param context GPU context
235 @param backendRenderTarget GPU intermediate memory buffer
236 @param colorSpace range of colors
237 @param surfaceProps LCD striping orientation and setting for device independent
238 fonts; may be nullptr
239 @param releaseProc function called when backendRenderTarget can be released
240 @param releaseContext state passed to releaseProc
241 @return SkSurface if all parameters are valid; otherwise, nullptr
242 */
243 static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context,
244 const GrBackendRenderTarget& backendRenderTarget,
245 GrSurfaceOrigin origin,
246 SkColorType colorType,
247 sk_sp<SkColorSpace> colorSpace,
248 const SkSurfaceProps* surfaceProps,
249 RenderTargetReleaseProc releaseProc = nullptr,
250 ReleaseContext releaseContext = nullptr);
251
252#if GR_TEST_UTILS
253 // TODO: Remove this.
254 static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context,
255 const GrBackendTexture& backendTexture,
256 GrSurfaceOrigin origin,
257 int sampleCnt,
258 SkColorType colorType,
259 sk_sp<SkColorSpace> colorSpace,
260 const SkSurfaceProps* surfaceProps);
261#endif
262
263#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
264 /** Private.
265 Creates SkSurface from Android hardware buffer.
266 Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released
267 when the SkSurface is destroyed and there is no pending work on the GPU involving the
268 buffer.
269
270 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
271
272 Currently this is only supported for buffers that can be textured as well as rendered to.
273 In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
274 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
275
276 @param context GPU context
277 @param hardwareBuffer AHardwareBuffer Android hardware buffer
278 @param colorSpace range of colors; may be nullptr
279 @param surfaceProps LCD striping orientation and setting for device independent
280 fonts; may be nullptr
281 @return created SkSurface, or nullptr
282 */
283 static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrContext* context,
284 AHardwareBuffer* hardwareBuffer,
285 GrSurfaceOrigin origin,
286 sk_sp<SkColorSpace> colorSpace,
287 const SkSurfaceProps* surfaceProps);
288#endif
289
290#ifdef SK_METAL
291 /** Creates SkSurface from CAMetalLayer.
292 Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be
293 released when the SkSurface is destroyed.
294
295 Only available when Metal API is enabled.
296
297 Will grab the current drawable from the layer and use its texture as a backendRT to
298 create a renderable surface.
299
300 @param context GPU context
301 @param layer GrMTLHandle (expected to be a CAMetalLayer*)
302 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
303 @param colorSpace range of colors; may be nullptr
304 @param surfaceProps LCD striping orientation and setting for device independent
305 fonts; may be nullptr
306 @param drawable Pointer to drawable to be filled in when this surface is
307 instantiated; may not be nullptr
308 @return created SkSurface, or nullptr
309 */
310 static sk_sp<SkSurface> MakeFromCAMetalLayer(GrContext* context,
311 GrMTLHandle layer,
312 GrSurfaceOrigin origin,
313 int sampleCnt,
314 SkColorType colorType,
315 sk_sp<SkColorSpace> colorSpace,
316 const SkSurfaceProps* surfaceProps,
317 GrMTLHandle* drawable)
318 SK_API_AVAILABLE_CA_METAL_LAYER;
319
320 /** Creates SkSurface from MTKView.
321 Returned SkSurface takes a reference on the MTKView. The ref on the layer will be
322 released when the SkSurface is destroyed.
323
324 Only available when Metal API is enabled.
325
326 Will grab the current drawable from the layer and use its texture as a backendRT to
327 create a renderable surface.
328
329 @param context GPU context
330 @param layer GrMTLHandle (expected to be a MTKView*)
331 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
332 @param colorSpace range of colors; may be nullptr
333 @param surfaceProps LCD striping orientation and setting for device independent
334 fonts; may be nullptr
335 @return created SkSurface, or nullptr
336 */
337 static sk_sp<SkSurface> MakeFromMTKView(GrContext* context,
338 GrMTLHandle mtkView,
339 GrSurfaceOrigin origin,
340 int sampleCnt,
341 SkColorType colorType,
342 sk_sp<SkColorSpace> colorSpace,
343 const SkSurfaceProps* surfaceProps)
344 SK_API_AVAILABLE(macos(10.11), ios(9.0));
345#endif
346
347 /** Returns SkSurface on GPU indicated by context. Allocates memory for
348 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
349 selects whether allocation for pixels is tracked by context. imageInfo
350 describes the pixel format in SkColorType, and transparency in
351 SkAlphaType, and color matching in SkColorSpace.
352
353 sampleCount requests the number of samples per pixel.
354 Pass zero to disable multi-sample anti-aliasing. The request is rounded
355 up to the next supported count, or rounded down if it is larger than the
356 maximum supported count.
357
358 surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
359
360 shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
361
362 If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
363
364 @param context GPU context
365 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
366 width, or height, or both, may be zero
367 @param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
368 @param surfaceProps LCD striping orientation and setting for device independent
369 fonts; may be nullptr
370 @param shouldCreateWithMips hint that SkSurface will host mip map images
371 @return SkSurface if all parameters are valid; otherwise, nullptr
372 */
373 static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
374 const SkImageInfo& imageInfo,
375 int sampleCount, GrSurfaceOrigin surfaceOrigin,
376 const SkSurfaceProps* surfaceProps,
377 bool shouldCreateWithMips = false);
378
379 /** Deprecated.
380 */
381 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
382 const SkImageInfo& imageInfo,
383 int sampleCount, GrSurfaceOrigin surfaceOrigin,
384 const SkSurfaceProps* surfaceProps,
385 bool shouldCreateWithMips = false);
386
387 /** Returns SkSurface on GPU indicated by context. Allocates memory for
388 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
389 selects whether allocation for pixels is tracked by context. imageInfo
390 describes the pixel format in SkColorType, and transparency in
391 SkAlphaType, and color matching in SkColorSpace.
392
393 sampleCount requests the number of samples per pixel.
394 Pass zero to disable multi-sample anti-aliasing. The request is rounded
395 up to the next supported count, or rounded down if it is larger than the
396 maximum supported count.
397
398 SkSurface bottom-left corner is pinned to the origin.
399
400 @param context GPU context
401 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
402 of raster surface; width, or height, or both, may be zero
403 @param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
404 @param surfaceProps LCD striping orientation and setting for device independent
405 fonts; may be nullptr
406 @return SkSurface if all parameters are valid; otherwise, nullptr
407 */
408 static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
409 const SkImageInfo& imageInfo, int sampleCount,
410 const SkSurfaceProps* surfaceProps) {
411 return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
412 kBottomLeft_GrSurfaceOrigin, surfaceProps);
413 }
414
415 /** Deprecated.
416 */
417 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
418 const SkImageInfo& imageInfo, int sampleCount,
419 const SkSurfaceProps* surfaceProps);
420
421 /** Returns SkSurface on GPU indicated by context. Allocates memory for
422 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
423 selects whether allocation for pixels is tracked by context. imageInfo
424 describes the pixel format in SkColorType, and transparency in
425 SkAlphaType, and color matching in SkColorSpace.
426
427 SkSurface bottom-left corner is pinned to the origin.
428
429 @param context GPU context
430 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
431 of raster surface; width, or height, or both, may be zero
432 @return SkSurface if all parameters are valid; otherwise, nullptr
433 */
434 static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
435 const SkImageInfo& imageInfo) {
436 if (!imageInfo.width() || !imageInfo.height()) {
437 return nullptr;
438 }
439 return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
440 nullptr);
441 }
442
443 /** Deprecated.
444 */
445 static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
446 const SkImageInfo& imageInfo);
447
448 /** Returns SkSurface on GPU indicated by context that is compatible with the provided
449 characterization. budgeted selects whether allocation for pixels is tracked by context.
450
451 @param context GPU context
452 @param characterization description of the desired SkSurface
453 @return SkSurface if all parameters are valid; otherwise, nullptr
454 */
455 static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
456 const SkSurfaceCharacterization& characterization,
457 SkBudgeted budgeted);
458
459 /** Wraps a backend texture in an SkSurface - setting up the surface to match the provided
460 characterization. The caller must ensure the texture is valid for the lifetime of
461 returned SkSurface.
462
463 If the backend texture and surface characterization are incompatible then null will
464 be returned.
465
466 Usually, the GrContext::createBackendTexture variant that takes a surface characterization
467 should be used to create the backend texture. If not,
468 SkSurfaceCharacterization::isCompatible can be used to determine if a given backend texture
469 is compatible with a specific surface characterization.
470
471 Upon success textureReleaseProc is called when it is safe to delete the texture in the
472 backend API (accounting only for use of the texture by this surface). If SkSurface creation
473 fails textureReleaseProc is called before this function returns.
474
475 @param context GPU context
476 @param characterization characterization of the desired surface
477 @param backendTexture texture residing on GPU
478 @param textureReleaseProc function called when texture can be released
479 @param releaseContext state passed to textureReleaseProc
480 @return SkSurface if all parameters are compatible; otherwise, nullptr
481 */
482 static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context,
483 const SkSurfaceCharacterization& characterzation,
484 const GrBackendTexture& backendTexture,
485 TextureReleaseProc textureReleaseProc = nullptr,
486 ReleaseContext releaseContext = nullptr);
487
488 /** Is this surface compatible with the provided characterization?
489
490 This method can be used to determine if an existing SkSurface is a viable destination
491 for an SkDeferredDisplayList.
492
493 @param characterization The characterization for which a compatibility check is desired
494 @return true if this surface is compatible with the characterization;
495 false otherwise
496 */
497 bool isCompatible(const SkSurfaceCharacterization& characterization) const;
498
499 /** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface
500 has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.
501
502 @param width one or greater
503 @param height one or greater
504 @return SkSurface if width and height are positive; otherwise, nullptr
505
506 example: https://fiddle.skia.org/c/@Surface_MakeNull
507 */
508 static sk_sp<SkSurface> MakeNull(int width, int height);
509
510 /** Returns pixel count in each row; may be zero or greater.
511
512 @return number of pixel columns
513 */
514 int width() const { return fWidth; }
515
516 /** Returns pixel row count; may be zero or greater.
517
518 @return number of pixel rows
519 */
520 int height() const { return fHeight; }
521
522 /** Returns an ImageInfo describing the surface.
523 */
524 SkImageInfo imageInfo();
525
526 /** Returns unique value identifying the content of SkSurface. Returned value changes
527 each time the content changes. Content is changed by drawing, or by calling
528 notifyContentWillChange().
529
530 @return unique content identifier
531
532 example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
533 */
534 uint32_t generationID();
535
536 /** \enum SkSurface::ContentChangeMode
537 ContentChangeMode members are parameters to notifyContentWillChange().
538 */
539 enum ContentChangeMode {
540 kDiscard_ContentChangeMode, //!< discards surface on change
541 kRetain_ContentChangeMode, //!< preserves surface on change
542 };
543
544 /** Notifies that SkSurface contents will be changed by code outside of Skia.
545 Subsequent calls to generationID() return a different value.
546
547 TODO: Can kRetain_ContentChangeMode be deprecated?
548
549 example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
550 */
551 void notifyContentWillChange(ContentChangeMode mode);
552
553 /** Deprecated.
554 This functionality is now achieved via:
555 GrRecordingContext* recordingContext = surface->recordingContext();
556 GrDirectContext* directContext = recordingContext->asDirectContext();
557 Where 'recordingContext' could be null if 'surface' is not GPU backed and
558 'directContext' could be null if the calling code is in the midst of DDL recording.
559 */
560 GrContext* getContext();
561
562 /** Returns the recording context being used by the SkSurface.
563
564 @return the recording context, if available; nullptr otherwise
565 */
566 GrRecordingContext* recordingContext();
567
568 enum BackendHandleAccess {
569 kFlushRead_BackendHandleAccess, //!< back-end object is readable
570 kFlushWrite_BackendHandleAccess, //!< back-end object is writable
571 kDiscardWrite_BackendHandleAccess, //!< back-end object must be overwritten
572 };
573
574 /** Deprecated.
575 */
576 static const BackendHandleAccess kFlushRead_TextureHandleAccess =
577 kFlushRead_BackendHandleAccess;
578
579 /** Deprecated.
580 */
581 static const BackendHandleAccess kFlushWrite_TextureHandleAccess =
582 kFlushWrite_BackendHandleAccess;
583
584 /** Deprecated.
585 */
586 static const BackendHandleAccess kDiscardWrite_TextureHandleAccess =
587 kDiscardWrite_BackendHandleAccess;
588
589 /** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid
590 object is returned. Call GrBackendTexture::isValid to determine if the result
591 is valid.
592
593 The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.
594
595 @return GPU texture reference; invalid on failure
596 */
597 GrBackendTexture getBackendTexture(BackendHandleAccess backendHandleAccess);
598
599 /** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid
600 object is returned. Call GrBackendRenderTarget::isValid to determine if the result
601 is valid.
602
603 The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to
604 or deleted.
605
606 @return GPU render target reference; invalid on failure
607 */
608 GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess);
609
610 /** If the surface was made via MakeFromBackendTexture then it's backing texture may be
611 substituted with a different texture. The contents of the previous backing texture are
612 copied into the new texture. SkCanvas state is preserved. The original sample count is
613 used. The GrBackendFormat and dimensions of replacement texture must match that of
614 the original.
615
616 Upon success textureReleaseProc is called when it is safe to delete the texture in the
617 backend API (accounting only for use of the texture by this surface). If SkSurface creation
618 fails textureReleaseProc is called before this function returns.
619
620 @param backendTexture the new backing texture for the surface
621 @param mode Retain or discard current Content
622 @param textureReleaseProc function called when texture can be released
623 @param releaseContext state passed to textureReleaseProc
624 */
625 bool replaceBackendTexture(const GrBackendTexture& backendTexture,
626 GrSurfaceOrigin origin,
627 ContentChangeMode mode = kRetain_ContentChangeMode,
628 TextureReleaseProc textureReleaseProc = nullptr,
629 ReleaseContext releaseContext = nullptr);
630
631 /** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas.
632 SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface
633 is deleted.
634
635 @return drawing SkCanvas for SkSurface
636
637 example: https://fiddle.skia.org/c/@Surface_getCanvas
638 */
639 SkCanvas* getCanvas();
640
641 /** Returns a compatible SkSurface, or nullptr. Returned SkSurface contains
642 the same raster, GPU, or null properties as the original. Returned SkSurface
643 does not share the same pixels.
644
645 Returns nullptr if imageInfo width or height are zero, or if imageInfo
646 is incompatible with SkSurface.
647
648 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
649 of SkSurface; width and height must be greater than zero
650 @return compatible SkSurface or nullptr
651
652 example: https://fiddle.skia.org/c/@Surface_makeSurface
653 */
654 sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo);
655
656 /** Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the
657 * specified width and height.
658 */
659 sk_sp<SkSurface> makeSurface(int width, int height);
660
661 /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents
662 are not captured. SkImage allocation is accounted for if SkSurface was created with
663 SkBudgeted::kYes.
664
665 @return SkImage initialized with SkSurface contents
666
667 example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
668 */
669 sk_sp<SkImage> makeImageSnapshot();
670
671 /**
672 * Like the no-parameter version, this returns an image of the current surface contents.
673 * This variant takes a rectangle specifying the subset of the surface that is of interest.
674 * These bounds will be sanitized before being used.
675 * - If bounds extends beyond the surface, it will be trimmed to just the intersection of
676 * it and the surface.
677 * - If bounds does not intersect the surface, then this returns nullptr.
678 * - If bounds == the surface, then this is the same as calling the no-parameter variant.
679
680 example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot_2
681 */
682 sk_sp<SkImage> makeImageSnapshot(const SkIRect& bounds);
683
684 /** Draws SkSurface contents to canvas, with its top-left corner at (x, y).
685
686 If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode.
687
688 @param canvas SkCanvas drawn into
689 @param x horizontal offset in SkCanvas
690 @param y vertical offset in SkCanvas
691 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
692 and so on; or nullptr
693
694 example: https://fiddle.skia.org/c/@Surface_draw
695 */
696 void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint);
697
698 /** Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address
699 is available, and returns true. If pixel address is not available, return
700 false and leave SkPixmap unchanged.
701
702 pixmap contents become invalid on any future change to SkSurface.
703
704 @param pixmap storage for pixel state if pixels are readable; otherwise, ignored
705 @return true if SkSurface has direct access to pixels
706
707 example: https://fiddle.skia.org/c/@Surface_peekPixels
708 */
709 bool peekPixels(SkPixmap* pixmap);
710
711 /** Copies SkRect of pixels to dst.
712
713 Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
714 Destination SkRect corners are (0, 0) and (dst.width(), dst.height()).
715 Copies each readable pixel intersecting both rectangles, without scaling,
716 converting to dst.colorType() and dst.alphaType() if required.
717
718 Pixels are readable when SkSurface is raster, or backed by a GPU.
719
720 The destination pixel storage must be allocated by the caller.
721
722 Pixel values are converted only if SkColorType and SkAlphaType
723 do not match. Only pixels within both source and destination rectangles
724 are copied. dst contents outside SkRect intersection are unchanged.
725
726 Pass negative values for srcX or srcY to offset pixels across or down destination.
727
728 Does not copy, and returns false if:
729 - Source and destination rectangles do not intersect.
730 - SkPixmap pixels could not be allocated.
731 - dst.rowBytes() is too small to contain one row of pixels.
732
733 @param dst storage for pixels copied from SkSurface
734 @param srcX offset into readable pixels on x-axis; may be negative
735 @param srcY offset into readable pixels on y-axis; may be negative
736 @return true if pixels were copied
737
738 example: https://fiddle.skia.org/c/@Surface_readPixels
739 */
740 bool readPixels(const SkPixmap& dst, int srcX, int srcY);
741
742 /** Copies SkRect of pixels from SkCanvas into dstPixels.
743
744 Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
745 Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()).
746 Copies each readable pixel intersecting both rectangles, without scaling,
747 converting to dstInfo.colorType() and dstInfo.alphaType() if required.
748
749 Pixels are readable when SkSurface is raster, or backed by a GPU.
750
751 The destination pixel storage must be allocated by the caller.
752
753 Pixel values are converted only if SkColorType and SkAlphaType
754 do not match. Only pixels within both source and destination rectangles
755 are copied. dstPixels contents outside SkRect intersection are unchanged.
756
757 Pass negative values for srcX or srcY to offset pixels across or down destination.
758
759 Does not copy, and returns false if:
760 - Source and destination rectangles do not intersect.
761 - SkSurface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
762 - dstRowBytes is too small to contain one row of pixels.
763
764 @param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels
765 @param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger
766 @param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger
767 @param srcX offset into readable pixels on x-axis; may be negative
768 @param srcY offset into readable pixels on y-axis; may be negative
769 @return true if pixels were copied
770 */
771 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
772 int srcX, int srcY);
773
774 /** Copies SkRect of pixels from SkSurface into bitmap.
775
776 Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()).
777 Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).
778 Copies each readable pixel intersecting both rectangles, without scaling,
779 converting to bitmap.colorType() and bitmap.alphaType() if required.
780
781 Pixels are readable when SkSurface is raster, or backed by a GPU.
782
783 The destination pixel storage must be allocated by the caller.
784
785 Pixel values are converted only if SkColorType and SkAlphaType
786 do not match. Only pixels within both source and destination rectangles
787 are copied. dst contents outside SkRect intersection are unchanged.
788
789 Pass negative values for srcX or srcY to offset pixels across or down destination.
790
791 Does not copy, and returns false if:
792 - Source and destination rectangles do not intersect.
793 - SkSurface pixels could not be converted to dst.colorType() or dst.alphaType().
794 - dst pixels could not be allocated.
795 - dst.rowBytes() is too small to contain one row of pixels.
796
797 @param dst storage for pixels copied from SkSurface
798 @param srcX offset into readable pixels on x-axis; may be negative
799 @param srcY offset into readable pixels on y-axis; may be negative
800 @return true if pixels were copied
801
802 example: https://fiddle.skia.org/c/@Surface_readPixels_3
803 */
804 bool readPixels(const SkBitmap& dst, int srcX, int srcY);
805
806 using AsyncReadResult = SkImage::AsyncReadResult;
807
808 /** Client-provided context that is passed to client-provided ReadPixelsContext. */
809 using ReadPixelsContext = void*;
810
811 /** Client-provided callback to asyncRescaleAndReadPixels() or
812 asyncRescaleAndReadPixelsYUV420() that is called when read result is ready or on failure.
813 */
814 using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>);
815
816 /** Controls the gamma that rescaling occurs in for asyncRescaleAndReadPixels() and
817 asyncRescaleAndReadPixelsYUV420().
818 */
819 using RescaleGamma = SkImage::RescaleGamma;
820
821 /** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale
822 the surface pixels.
823
824 Currently asynchronous reads are only supported on the GPU backend and only when the
825 underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all
826 other cases this operates synchronously.
827
828 Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is
829 rescaled to the size indicated by 'info', is then converted to the color space, color type,
830 and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface
831 causes failure.
832
833 When the pixel data is ready the caller's ReadPixelsCallback is called with a
834 AsyncReadResult containing pixel data in the requested color type, alpha type, and color
835 space. The AsyncReadResult will have count() == 1. Upon failure the callback is called
836 with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must
837 occur to guarantee a finite time before the callback is called.
838
839 The data is valid for the lifetime of AsyncReadResult with the exception that if the
840 SkSurface is GPU-backed the data is immediately invalidated if the GrContext is abandoned
841 or destroyed.
842
843 @param info info of the requested pixels
844 @param srcRect subrectangle of surface to read
845 @param rescaleGamma controls whether rescaling is done in the surface's gamma or whether
846 the source data is transformed to a linear gamma before rescaling.
847 @param rescaleQuality controls the quality (and cost) of the rescaling
848 @param callback function to call with result of the read
849 @param context passed to callback
850 */
851 void asyncRescaleAndReadPixels(const SkImageInfo& info,
852 const SkIRect& srcRect,
853 RescaleGamma rescaleGamma,
854 SkFilterQuality rescaleQuality,
855 ReadPixelsCallback callback,
856 ReadPixelsContext context);
857
858 /**
859 Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The
860 RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three
861 planes ordered y, u, v. The u and v planes are half the width and height of the resized
862 rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize'
863 width and height are not even. A 'srcRect' that is not contained by the bounds of the
864 surface causes failure.
865
866 When the pixel data is ready the caller's ReadPixelsCallback is called with a
867 AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3.
868 Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this
869 flushes work but a submit must occur to guarantee a finite time before the callback is
870 called.
871
872 The data is valid for the lifetime of AsyncReadResult with the exception that if the
873 SkSurface is GPU-backed the data is immediately invalidated if the GrContext is abandoned
874 or destroyed.
875
876 @param yuvColorSpace The transformation from RGB to YUV. Applied to the resized image
877 after it is converted to dstColorSpace.
878 @param dstColorSpace The color space to convert the resized image to, after rescaling.
879 @param srcRect The portion of the surface to rescale and convert to YUV planes.
880 @param dstSize The size to rescale srcRect to
881 @param rescaleGamma controls whether rescaling is done in the surface's gamma or whether
882 the source data is transformed to a linear gamma before rescaling.
883 @param rescaleQuality controls the quality (and cost) of the rescaling
884 @param callback function to call with the planar read result
885 @param context passed to callback
886 */
887 void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
888 sk_sp<SkColorSpace> dstColorSpace,
889 const SkIRect& srcRect,
890 const SkISize& dstSize,
891 RescaleGamma rescaleGamma,
892 SkFilterQuality rescaleQuality,
893 ReadPixelsCallback callback,
894 ReadPixelsContext context);
895
896 /** Copies SkRect of pixels from the src SkPixmap to the SkSurface.
897
898 Source SkRect corners are (0, 0) and (src.width(), src.height()).
899 Destination SkRect corners are (dstX, dstY) and
900 (dstX + Surface width(), dstY + Surface height()).
901
902 Copies each readable pixel intersecting both rectangles, without scaling,
903 converting to SkSurface colorType() and SkSurface alphaType() if required.
904
905 @param src storage for pixels to copy to SkSurface
906 @param dstX x-axis position relative to SkSurface to begin copy; may be negative
907 @param dstY y-axis position relative to SkSurface to begin copy; may be negative
908
909 example: https://fiddle.skia.org/c/@Surface_writePixels
910 */
911 void writePixels(const SkPixmap& src, int dstX, int dstY);
912
913 /** Copies SkRect of pixels from the src SkBitmap to the SkSurface.
914
915 Source SkRect corners are (0, 0) and (src.width(), src.height()).
916 Destination SkRect corners are (dstX, dstY) and
917 (dstX + Surface width(), dstY + Surface height()).
918
919 Copies each readable pixel intersecting both rectangles, without scaling,
920 converting to SkSurface colorType() and SkSurface alphaType() if required.
921
922 @param src storage for pixels to copy to SkSurface
923 @param dstX x-axis position relative to SkSurface to begin copy; may be negative
924 @param dstY y-axis position relative to SkSurface to begin copy; may be negative
925
926 example: https://fiddle.skia.org/c/@Surface_writePixels_2
927 */
928 void writePixels(const SkBitmap& src, int dstX, int dstY);
929
930 /** Returns SkSurfaceProps for surface.
931
932 @return LCD striping orientation and setting for device independent fonts
933 */
934 const SkSurfaceProps& props() const { return fProps; }
935
936 /** Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.
937 Skia will correctly order its own draws and pixel operations. This must to be used to ensure
938 correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of
939 the 3D API or a windowing system). GrContext has additional flush and submit methods that
940 apply to all surfaces and images created from a GrContext. This is equivalent to calling
941 SkSurface::flush with a default GrFlushInfo followed by GrContext::submit.
942 */
943 void flushAndSubmit();
944
945 enum class BackendSurfaceAccess {
946 kNoAccess, //!< back-end object will not be used by client
947 kPresent, //!< back-end surface will be used for presenting to screen
948 };
949
950 /** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
951 MSAA. A call to GrContext::submit is always required to ensure work is actually sent to the
952 gpu. Some specific API details:
953 GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
954 sync objects from the flush will not be valid until a submission occurs.
955
956 Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
957 buffer or encoder objects. However, these objects are not sent to the gpu until a
958 submission occurs.
959
960 The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is
961 passed in.
962
963 If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU.
964
965 If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is
966 treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the
967 SkSurface will be transferred back to its original queue. If the SkSurface was created by
968 wrapping a VkImage, the queue will be set to the queue which was originally passed in on
969 the GrVkImageInfo. Additionally, if the original queue was not external or foreign the
970 layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
971
972 The GrFlushInfo describes additional options to flush. Please see documentation at
973 GrFlushInfo for more info.
974
975 If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
976 submitted to the gpu during the next submit call (it is possible Skia failed to create a
977 subset of the semaphores). The client should not wait on these semaphores until after submit
978 has been called, but must keep them alive until then. If a submit flag was passed in with
979 the flush these valid semaphores can we waited on immediately. If this call returns
980 GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
981 the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
982 with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
983 client is still responsible for deleting any initialized semaphores.
984 Regardleess of semaphore submission the context will still be flushed. It should be
985 emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
986 happen. It simply means there were no semaphores submitted to the GPU. A caller should only
987 take this as a failure if they passed in semaphores to be submitted.
988
989 Pending surface commands are flushed regardless of the return result.
990
991 @param access type of access the call will do on the backend object after flush
992 @param info flush options
993 */
994 GrSemaphoresSubmitted flush(BackendSurfaceAccess access, const GrFlushInfo& info);
995
996 /** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
997 MSAA. A call to GrContext::submit is always required to ensure work is actually sent to the
998 gpu. Some specific API details:
999 GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
1000 sync objects from the flush will not be valid until a submission occurs.
1001
1002 Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
1003 buffer or encoder objects. However, these objects are not sent to the gpu until a
1004 submission occurs.
1005
1006 The GrFlushInfo describes additional options to flush. Please see documentation at
1007 GrFlushInfo for more info.
1008
1009 If a GrBackendSurfaceMutableState is passed in, at the end of the flush we will transition
1010 the surface to be in the state requested by the GrBackendSurfaceMutableState. If the surface
1011 (or SkImage or GrBackendSurface wrapping the same backend object) is used again after this
1012 flush the state may be changed and no longer match what is requested here. This is often
1013 used if the surface will be used for presenting or external use and the client wants backend
1014 object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also
1015 include the work for any requested state change.
1016
1017 If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
1018 submitted to the gpu during the next submit call (it is possible Skia failed to create a
1019 subset of the semaphores). The client should not wait on these semaphores until after submit
1020 has been called, but must keep them alive until then. If a submit flag was passed in with
1021 the flush these valid semaphores can we waited on immediately. If this call returns
1022 GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
1023 the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
1024 with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
1025 client is still responsible for deleting any initialized semaphores.
1026 Regardleess of semaphore submission the context will still be flushed. It should be
1027 emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
1028 happen. It simply means there were no semaphores submitted to the GPU. A caller should only
1029 take this as a failure if they passed in semaphores to be submitted.
1030
1031 Pending surface commands are flushed regardless of the return result.
1032
1033 @param info flush options
1034 @param access optional state change request after flush
1035 */
1036 GrSemaphoresSubmitted flush(const GrFlushInfo& info,
1037 const GrBackendSurfaceMutableState* newState = nullptr);
1038
1039 void flush() { this->flush({}); }
1040
1041 /** Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
1042 executing any more commands on the GPU for this surface. If this call returns false, then
1043 the GPU back-end will not wait on any passed in semaphores, and the client will still own
1044 the semaphores, regardless of the value of deleteSemaphoresAfterWait.
1045
1046 If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case
1047 it is the client's responsibility to not destroy or attempt to reuse the semaphores until it
1048 knows that Skia has finished waiting on them. This can be done by using finishedProcs
1049 on flush calls.
1050
1051 @param numSemaphores size of waitSemaphores array
1052 @param waitSemaphores array of semaphore containers
1053 @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores
1054 @return true if GPU is waiting on semaphores
1055 */
1056 bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
1057 bool deleteSemaphoresAfterWait = true);
1058
1059 /** Initializes SkSurfaceCharacterization that can be used to perform GPU back-end
1060 processing in a separate thread. Typically this is used to divide drawing
1061 into multiple tiles. SkDeferredDisplayListRecorder records the drawing commands
1062 for each tile.
1063
1064 Return true if SkSurface supports characterization. raster surface returns false.
1065
1066 @param characterization properties for parallel drawing
1067 @return true if supported
1068
1069 example: https://fiddle.skia.org/c/@Surface_characterize
1070 */
1071 bool characterize(SkSurfaceCharacterization* characterization) const;
1072
1073 /** Draws deferred display list created using SkDeferredDisplayListRecorder.
1074 Has no effect and returns false if SkSurfaceCharacterization stored in
1075 deferredDisplayList is not compatible with SkSurface.
1076
1077 raster surface returns false.
1078
1079 @param deferredDisplayList drawing commands
1080 @return false if deferredDisplayList is not compatible
1081
1082 example: https://fiddle.skia.org/c/@Surface_draw_2
1083 */
1084 bool draw(sk_sp<const SkDeferredDisplayList> deferredDisplayList);
1085
1086protected:
1087 SkSurface(int width, int height, const SkSurfaceProps* surfaceProps);
1088 SkSurface(const SkImageInfo& imageInfo, const SkSurfaceProps* surfaceProps);
1089
1090 // called by subclass if their contents have changed
1091 void dirtyGenerationID() {
1092 fGenerationID = 0;
1093 }
1094
1095private:
1096 const SkSurfaceProps fProps;
1097 const int fWidth;
1098 const int fHeight;
1099 uint32_t fGenerationID;
1100
1101 typedef SkRefCnt INHERITED;
1102};
1103
1104#endif
1105