• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1SkSurface Reference
2===
3
4# <a name="Surface"></a> Surface
5
6## <a name="Overview"></a> Overview
7
8## <a name="Subtopics"></a> Subtopics
9
10| name | description |
11| --- | --- |
12| Constants | enum and enum class, const values |
13| <a href="#Constructors">Constructors</a> | functions that construct <a href="SkSurface_Reference#SkSurface">SkSurface</a> |
14| <a href="#Member_Functions">Member Functions</a> | static functions and member methods |
15
16# <a name="SkSurface"></a> Class SkSurface
17<a href="#SkSurface">SkSurface</a> is responsible for managing the pixels that a canvas draws into. The pixels can be
18allocated either in CPU memory (a raster surface) or on the GPU (a <a href="undocumented#GrRenderTarget">GrRenderTarget</a> surface).
19<a href="#SkSurface">SkSurface</a> takes care of allocating a <a href="SkCanvas_Reference#SkCanvas">SkCanvas</a> that will draw into the surface. Call
20surface-><a href="#SkSurface_getCanvas">getCanvas</a> to use that canvas (but don't delete it, it is owned by the surface).
21<a href="#SkSurface">SkSurface</a> always has non-zero dimensions. If there is a request for a new surface, and either
22of the requested dimensions are zero, then nullptr will be returned.
23
24## <a name="Constructors"></a> Constructors
25
26| name | description |
27| --- | --- |
28| <a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a> | creates <a href="#Surface">Surface</a> from GPU memory buffer |
29| <a href="#SkSurface_MakeFromBackendTexture">MakeFromBackendTexture</a> | creates <a href="#Surface">Surface</a> from GPU-backed texture |
30| <a href="#SkSurface_MakeFromBackendTextureAsRenderTarget">MakeFromBackendTextureAsRenderTarget</a> | creates <a href="#Surface">Surface</a> from GPU-backed texture |
31| <a href="#SkSurface_MakeNull">MakeNull</a> | creates <a href="#Surface">Surface</a> without backing pixels |
32| <a href="#SkSurface_MakeRaster">MakeRaster</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> |
33| <a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> and <a href="#Storage">Pixel Storage</a> |
34| <a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> and <a href="#Storage">Pixel Storage</a> |
35| <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> | creates <a href="#Surface">Surface</a> from width, height matching output |
36| <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a> | creates <a href="#Surface">Surface</a> pointing to new GPU memory buffer |
37| <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> | creates <a href="SkImage_Reference#Image">Image</a> capturing <a href="#Surface">Surface</a> contents |
38| <a href="#SkSurface_makeSurface">makeSurface</a> | creates a compatible <a href="#Surface">Surface</a> |
39
40## <a name="Member_Functions"></a> Member Functions
41
42| name | description |
43| --- | --- |
44| <a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a> | creates <a href="#Surface">Surface</a> from GPU memory buffer |
45| <a href="#SkSurface_MakeFromBackendTexture">MakeFromBackendTexture</a> | creates <a href="#Surface">Surface</a> from GPU-backed texture |
46| <a href="#SkSurface_MakeFromBackendTextureAsRenderTarget">MakeFromBackendTextureAsRenderTarget</a> | creates <a href="#Surface">Surface</a> from GPU-backed texture |
47| <a href="#SkSurface_MakeNull">MakeNull</a> | creates <a href="#Surface">Surface</a> without backing pixels |
48| <a href="#SkSurface_MakeRaster">MakeRaster</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> |
49| <a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> and <a href="#Storage">Pixel Storage</a> |
50| <a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a> | creates <a href="#Surface">Surface</a> from <a href="SkImageInfo_Reference#SkImageInfo">SkImageInfo</a> and <a href="#Storage">Pixel Storage</a> |
51| <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> | creates <a href="#Surface">Surface</a> from width, height matching output |
52| <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a> | creates <a href="#Surface">Surface</a> pointing to new GPU memory buffer |
53| <a href="#SkSurface_characterize">characterize</a> | sets <a href="#Characterization">Surface Characterization</a> for threaded pre-processing |
54| <a href="#SkSurface_draw">draw</a> | draws <a href="#Surface">Surface</a> contents to canvas |
55| <a href="#SkSurface_flush">flush</a> | resolve pending I/O |
56| <a href="#SkSurface_flushAndSignalSemaphores">flushAndSignalSemaphores</a> | resolve pending I/O, and signal |
57| <a href="#SkSurface_generationID">generationID</a> | returns unique ID |
58| <a href="#SkSurface_getCanvas">getCanvas</a> | returns <a href="SkCanvas_Reference#Canvas">Canvas</a> that draws into <a href="#Surface">Surface</a> |
59| <a href="#SkSurface_getRenderTargetHandle">getRenderTargetHandle</a> | returns the GPU reference to render target |
60| <a href="#SkSurface_getTextureHandle">getTextureHandle</a> | returns the GPU reference to texture |
61| <a href="#SkSurface_height">height</a> | returns pixel row count |
62| <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> | creates <a href="SkImage_Reference#Image">Image</a> capturing <a href="#Surface">Surface</a> contents |
63| <a href="#SkSurface_makeSurface">makeSurface</a> | creates a compatible <a href="#Surface">Surface</a> |
64| <a href="#SkSurface_notifyContentWillChange">notifyContentWillChange</a> | notifies that contents will be changed outside of Skia |
65| <a href="#SkSurface_peekPixels">peekPixels</a> | copies <a href="#Surface">Surface</a> parameters to <a href="SkPixmap_Reference#Pixmap">Pixmap</a> |
66| <a href="#SkSurface_prepareForExternalIO">prepareForExternalIO</a> | to be deprecated |
67| <a href="#SkSurface_props">props</a> | returns <a href="#Properties">Surface Properties</a> |
68| <a href="#SkSurface_readPixels">readPixels</a> | copies <a href="SkRect_Reference#Rect">Rect</a> of pixels |
69| <a href="#SkSurface_wait">wait</a> | rause commands until signaled |
70| <a href="#SkSurface_width">width</a> | returns pixel column count |
71
72<a name="SkSurface_MakeRasterDirect"></a>
73## MakeRasterDirect
74
75<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
76static sk_sp&lt;SkSurface&gt; MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels, size_t rowBytes,
77                                         const SkSurfaceProps* surfaceProps = nullptr)
78</pre>
79
80Allocates raster <a href="#Surface">Surface</a>. <a href="SkCanvas_Reference#Canvas">Canvas</a> returned by <a href="#Surface">Surface</a> draws directly into <a href="#SkSurface_MakeRasterDirect_pixels">pixels</a>.
81
82<a href="#Surface">Surface</a> is returned if all parameters are valid.
83Valid parameters include:
84info dimensions are greater than zero;
85info contains <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a> supported by <a href="undocumented#Raster_Surface">Raster Surface</a>;
86<a href="#SkSurface_MakeRasterDirect_pixels">pixels</a> is not nullptr;
87<a href="#SkSurface_MakeRasterDirect_rowBytes">rowBytes</a> is large enough to contain info width <a href="#SkSurface_MakeRasterDirect_pixels">pixels</a> of <a href="SkImageInfo_Reference#Color_Type">Color Type</a>.
88
89<a href="undocumented#Pixel">Pixel</a> buffer size should be info height times computed <a href="#SkSurface_MakeRasterDirect_rowBytes">rowBytes</a>.
90Pixels are not initialized.
91To access <a href="#SkSurface_MakeRasterDirect_pixels">pixels</a> after drawing, call <a href="#SkSurface_flush">flush</a> or <a href="#SkSurface_peekPixels">peekPixels</a>.
92
93### Parameters
94
95<table>  <tr>    <td><a name="SkSurface_MakeRasterDirect_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
96width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
97of <a href="undocumented#Raster_Surface">Raster Surface</a>; width and height must be greater than zero</td>
98  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirect_pixels"> <code><strong>pixels </strong></code> </a></td> <td>
99pointer to destination <a href="#SkSurface_MakeRasterDirect_pixels">pixels</a> buffer</td>
100  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirect_rowBytes"> <code><strong>rowBytes </strong></code> </a></td> <td>
101interval from one <a href="#Surface">Surface</a> row to the next</td>
102  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirect_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
103LCD striping orientation and setting for device independent fonts;
104may be nullptr</td>
105  </tr>
106</table>
107
108### Return Value
109
110<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
111
112### Example
113
114<div><fiddle-embed name="3f5aeb870104187643197354a7f1d27a">
115
116#### Example Output
117
118~~~~
119---
120-x-
121---
122~~~~
123
124</fiddle-embed></div>
125
126### See Also
127
128<a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a> <a href="#SkSurface_MakeRaster">MakeRaster</a><sup><a href="#SkSurface_MakeRaster_2">[2]</a></sup> <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> <a href="#SkCanvas_MakeRasterDirect">SkCanvas::MakeRasterDirect</a>
129
130---
131
132<a name="SkSurface_MakeRasterDirectReleaseProc"></a>
133## MakeRasterDirectReleaseProc
134
135<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
136static sk_sp&lt;SkSurface&gt; MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels,
137                                           size_t rowBytes, void (*releaseProc) (void* pixels,
138                                           void* context) , void* context,
139                                           const SkSurfaceProps* surfaceProps = nullptr)
140</pre>
141
142Allocates raster <a href="#Surface">Surface</a>. <a href="SkCanvas_Reference#Canvas">Canvas</a> returned by <a href="#Surface">Surface</a> draws directly into <a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a>.
143<a href="#SkSurface_MakeRasterDirectReleaseProc_releaseProc">releaseProc</a> is called with <a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a> and <a href="#SkSurface_MakeRasterDirectReleaseProc_context">context</a> when <a href="#Surface">Surface</a> is deleted.
144
145<a href="#Surface">Surface</a> is returned if all parameters are valid.
146Valid parameters include:
147info dimensions are greater than zero;
148info contains <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a> supported by <a href="undocumented#Raster_Surface">Raster Surface</a>;
149<a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a> is not nullptr;
150<a href="#SkSurface_MakeRasterDirectReleaseProc_rowBytes">rowBytes</a> is large enough to contain info width <a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a> of <a href="SkImageInfo_Reference#Color_Type">Color Type</a>.
151
152<a href="undocumented#Pixel">Pixel</a> buffer size should be info height times computed <a href="#SkSurface_MakeRasterDirectReleaseProc_rowBytes">rowBytes</a>.
153Pixels are not initialized.
154To access <a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a> after drawing, call <a href="#SkSurface_flush">flush</a> or <a href="#SkSurface_peekPixels">peekPixels</a>.
155
156### Parameters
157
158<table>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
159width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
160of <a href="undocumented#Raster_Surface">Raster Surface</a>; width and height must be greater than zero</td>
161  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_pixels"> <code><strong>pixels </strong></code> </a></td> <td>
162pointer to destination <a href="#SkSurface_MakeRasterDirectReleaseProc_pixels">pixels</a> buffer</td>
163  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_rowBytes"> <code><strong>rowBytes </strong></code> </a></td> <td>
164interval from one <a href="#Surface">Surface</a> row to the next</td>
165  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_releaseProc"> <code><strong>releaseProc </strong></code> </a></td> <td>
166called when <a href="#Surface">Surface</a> is deleted; may be nullptr</td>
167  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_context"> <code><strong>context </strong></code> </a></td> <td>
168passed to <a href="#SkSurface_MakeRasterDirectReleaseProc_releaseProc">releaseProc</a>; may be nullptr</td>
169  </tr>  <tr>    <td><a name="SkSurface_MakeRasterDirectReleaseProc_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
170LCD striping orientation and setting for device independent fonts;
171may be nullptr</td>
172  </tr>
173</table>
174
175### Return Value
176
177<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
178
179### Example
180
181<div><fiddle-embed name="8e6530b26ab4096a9a91cfaadda1c568">
182
183#### Example Output
184
185~~~~
186---
187-x-
188---
189expected release context
190~~~~
191
192</fiddle-embed></div>
193
194### See Also
195
196<a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> <a href="#SkSurface_MakeRaster">MakeRaster</a><sup><a href="#SkSurface_MakeRaster_2">[2]</a></sup>
197
198---
199
200<a name="SkSurface_MakeRaster"></a>
201## MakeRaster
202
203<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
204static sk_sp&lt;SkSurface&gt; MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes,
205                                   const SkSurfaceProps* surfaceProps)
206</pre>
207
208Allocates raster <a href="#Surface">Surface</a>. <a href="SkCanvas_Reference#Canvas">Canvas</a> returned by <a href="#Surface">Surface</a> draws directly into pixels.
209Allocates and zeroes pixel memory. <a href="undocumented#Pixel">Pixel</a> memory size is <a href="#SkSurface_MakeRaster_imageInfo">imageInfo</a>.<a href="#SkSurface_height">height</a> times
210<a href="#SkSurface_MakeRaster_rowBytes">rowBytes</a>, or times <a href="#SkSurface_MakeRaster_imageInfo">imageInfo</a>.minRowBytes() if <a href="#SkSurface_MakeRaster_rowBytes">rowBytes</a> is zero.
211<a href="undocumented#Pixel">Pixel</a> memory is deleted when <a href="#Surface">Surface</a> is deleted.
212
213<a href="#Surface">Surface</a> is returned if all parameters are valid.
214Valid parameters include:
215info dimensions are greater than zero;
216info contains <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a> supported by <a href="undocumented#Raster_Surface">Raster Surface</a>;
217<a href="#SkSurface_MakeRaster_rowBytes">rowBytes</a> is large enough to contain info width pixels of <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, or is zero.
218
219If <a href="#SkSurface_MakeRaster_rowBytes">rowBytes</a> is not zero, subsequent images returned by <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a>
220have the same <a href="#SkSurface_MakeRaster_rowBytes">rowBytes</a>.
221
222### Parameters
223
224<table>  <tr>    <td><a name="SkSurface_MakeRaster_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
225width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
226of <a href="undocumented#Raster_Surface">Raster Surface</a>; width and height must be greater than zero</td>
227  </tr>  <tr>    <td><a name="SkSurface_MakeRaster_rowBytes"> <code><strong>rowBytes </strong></code> </a></td> <td>
228interval from one <a href="#Surface">Surface</a> row to the next; may be zero</td>
229  </tr>  <tr>    <td><a name="SkSurface_MakeRaster_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
230LCD striping orientation and setting for device independent fonts;
231may be nullptr</td>
232  </tr>
233</table>
234
235### Return Value
236
237<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
238
239### Example
240
241<div><fiddle-embed name="a803910ada4f8733f0b62456afead55f">
242
243#### Example Output
244
245~~~~
246---
247-x-
248---
249~~~~
250
251</fiddle-embed></div>
252
253### See Also
254
255<a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> <a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a>
256
257---
258
259<a name="SkSurface_MakeRaster_2"></a>
260
261<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
262static sk_sp&lt;SkSurface&gt; MakeRaster(const SkImageInfo& imageInfo,
263                                   const SkSurfaceProps* props = nullptr)
264</pre>
265
266Allocates raster <a href="#Surface">Surface</a>. <a href="SkCanvas_Reference#Canvas">Canvas</a> returned by <a href="#Surface">Surface</a> draws directly into pixels.
267Allocates and zeroes pixel memory. <a href="undocumented#Pixel">Pixel</a> memory size is <a href="#SkSurface_MakeRaster_2_imageInfo">imageInfo</a>.<a href="#SkSurface_height">height</a> times
268<a href="#SkSurface_MakeRaster_2_imageInfo">imageInfo</a>.minRowBytes().
269<a href="undocumented#Pixel">Pixel</a> memory is deleted when <a href="#Surface">Surface</a> is deleted.
270
271<a href="#Surface">Surface</a> is returned if all parameters are valid.
272Valid parameters include:
273info dimensions are greater than zero;
274info contains <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a> supported by <a href="undocumented#Raster_Surface">Raster Surface</a>.
275
276### Parameters
277
278<table>  <tr>    <td><a name="SkSurface_MakeRaster_2_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
279width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
280of <a href="undocumented#Raster_Surface">Raster Surface</a>; width and height must be greater than zero</td>
281  </tr>  <tr>    <td><a name="SkSurface_MakeRaster_2_props"> <code><strong>props </strong></code> </a></td> <td>
282LCD striping orientation and setting for device independent fonts;
283may be nullptr</td>
284  </tr>
285</table>
286
287### Return Value
288
289<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
290
291### Example
292
293<div><fiddle-embed name="c6197d204ef9e4ccfb583242651fb2a7"></fiddle-embed></div>
294
295### See Also
296
297<a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> <a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a>
298
299---
300
301<a name="SkSurface_MakeRasterN32Premul"></a>
302## MakeRasterN32Premul
303
304<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
305static sk_sp&lt;SkSurface&gt; MakeRasterN32Premul(int width, int height,
306                                            const SkSurfaceProps* surfaceProps = nullptr)
307</pre>
308
309Allocates raster <a href="#Surface">Surface</a>. <a href="SkCanvas_Reference#Canvas">Canvas</a> returned by <a href="#Surface">Surface</a> draws directly into pixels.
310Allocates and zeroes pixel memory. <a href="undocumented#Pixel">Pixel</a> memory size is height times width times
311four. <a href="undocumented#Pixel">Pixel</a> memory is deleted when <a href="#Surface">Surface</a> is deleted.
312
313Internally, sets <a href="SkImageInfo_Reference#Image_Info">Image Info</a> to width, height, <a href="SkImageInfo_Reference#Color_Type">Native Color Type</a>, and
314<a href="SkImageInfo_Reference#SkAlphaType">kPremul SkAlphaType</a>.
315
316<a href="#Surface">Surface</a> is returned if width and height are greater than zero.
317
318Use to create <a href="#Surface">Surface</a> that matches <a href="undocumented#SkPMColor">SkPMColor</a>, the native pixel arrangement on
319the platform. <a href="#Surface">Surface</a> drawn to output device skips converting its pixel format.
320
321### Parameters
322
323<table>  <tr>    <td><a name="SkSurface_MakeRasterN32Premul_width"> <code><strong>width </strong></code> </a></td> <td>
324pixel column count; must be greater than zero</td>
325  </tr>  <tr>    <td><a name="SkSurface_MakeRasterN32Premul_height"> <code><strong>height </strong></code> </a></td> <td>
326pixel row count; must be greater than zero</td>
327  </tr>  <tr>    <td><a name="SkSurface_MakeRasterN32Premul_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
328LCD striping orientation and setting for device independent
329fonts; may be nullptr</td>
330  </tr>
331</table>
332
333### Return Value
334
335<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
336
337### Example
338
339<div><fiddle-embed name="b932a2bd68455fb0af2e7a1ed19e36b3">
340
341#### Example Output
342
343~~~~
344---
345-x-
346---
347~~~~
348
349</fiddle-embed></div>
350
351### See Also
352
353<a href="#SkSurface_MakeRasterDirect">MakeRasterDirect</a> <a href="#SkSurface_MakeRasterN32Premul">MakeRasterN32Premul</a> <a href="#SkSurface_MakeRasterDirectReleaseProc">MakeRasterDirectReleaseProc</a>
354
355---
356
357<a name="SkSurface_MakeFromBackendTexture"></a>
358## MakeFromBackendTexture
359
360<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
361static sk_sp&lt;SkSurface&gt; MakeFromBackendTexture(GrContext* context,
362                                               const GrBackendTexture& backendTexture,
363                                               GrSurfaceOrigin origin, int sampleCnt,
364                                               sk_sp&lt;SkColorSpace&gt; colorSpace,
365                                               const SkSurfaceProps* surfaceProps)
366</pre>
367
368Wraps a GPU-backed texture into <a href="#Surface">Surface</a>. Caller must ensure the texture is
369valid for the lifetime of returned <a href="#Surface">Surface</a>. If <a href="#SkSurface_MakeFromBackendTexture_sampleCnt">sampleCnt</a> greater than zero,
370creates an intermediate MSAA <a href="#Surface">Surface</a> which is used for drawing <a href="#SkSurface_MakeFromBackendTexture_backendTexture">backendTexture</a>.
371
372<a href="#Surface">Surface</a> is returned if all parameters are valid. <a href="#SkSurface_MakeFromBackendTexture_backendTexture">backendTexture</a> is valid if
373its pixel configuration agrees with <a href="#SkSurface_MakeFromBackendTexture_colorSpace">colorSpace</a> and <a href="#SkSurface_MakeFromBackendTexture_context">context</a>; for instance, if
374<a href="#SkSurface_MakeFromBackendTexture_backendTexture">backendTexture</a> has an sRGB configuration, then <a href="#SkSurface_MakeFromBackendTexture_context">context</a> must support sRGB,
375and <a href="#SkSurface_MakeFromBackendTexture_colorSpace">colorSpace</a> must be present. Further, <a href="#SkSurface_MakeFromBackendTexture_backendTexture">backendTexture</a> width and height must
376not exceed <a href="#SkSurface_MakeFromBackendTexture_context">context</a> capabilities, and the <a href="#SkSurface_MakeFromBackendTexture_context">context</a> must be able to support
377back-end textures.
378
379If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
380
381### Parameters
382
383<table>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_context"> <code><strong>context </strong></code> </a></td> <td>
384<a href="undocumented#GPU_Context">GPU Context</a></td>
385  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_backendTexture"> <code><strong>backendTexture </strong></code> </a></td> <td>
386texture residing on GPU</td>
387  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_origin"> <code><strong>origin </strong></code> </a></td> <td>
388one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
389  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_sampleCnt"> <code><strong>sampleCnt </strong></code> </a></td> <td>
390samples per pixel, or 0 to disable full scene anti-aliasing</td>
391  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
392range of colors</td>
393  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
394LCD striping orientation and setting for device independent
395fonts; may be nullptr</td>
396  </tr>
397</table>
398
399### Return Value
400
401<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
402
403### Example
404
405<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
406void draw(SkCanvas* canvas) {
407    SkPaint paint;
408    paint.setTextSize(32);
409    GrContext* context = canvas->getGrContext();
410    if (!context) {
411         canvas->drawString("GPU only!", 20, 40, paint);
412         return;
413    }
414    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(context,
415            backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, nullptr, nullptr);
416    auto surfaceCanvas = gpuSurface->getCanvas();
417    surfaceCanvas->clear(SK_ColorWHITE);
418    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
419    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
420    canvas->drawImage(image, 0, 0);
421}
422</pre>
423
424### See Also
425
426<a href="undocumented#GrBackendTexture">GrBackendTexture</a> <a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
427
428---
429
430<a name="SkSurface_MakeFromBackendTexture_2"></a>
431
432<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
433static sk_sp&lt;SkSurface&gt; MakeFromBackendTexture(GrContext* context,
434                                               const GrBackendTexture& backendTexture,
435                                               GrSurfaceOrigin origin, int sampleCnt,
436                                               SkColorType colorType,
437                                               sk_sp&lt;SkColorSpace&gt; colorSpace,
438                                               const SkSurfaceProps* surfaceProps)
439</pre>
440
441Wraps a GPU-backed texture into <a href="#Surface">Surface</a>. Caller must ensure the texture is
442valid for the lifetime of returned <a href="#Surface">Surface</a>. If <a href="#SkSurface_MakeFromBackendTexture_2_sampleCnt">sampleCnt</a> greater than zero,
443creates an intermediate MSAA <a href="#Surface">Surface</a> which is used for drawing <a href="#SkSurface_MakeFromBackendTexture_2_backendTexture">backendTexture</a>.
444
445<a href="#Surface">Surface</a> is returned if all parameters are valid. <a href="#SkSurface_MakeFromBackendTexture_2_backendTexture">backendTexture</a> is valid if
446its pixel configuration agrees with <a href="#SkSurface_MakeFromBackendTexture_2_colorSpace">colorSpace</a> and <a href="#SkSurface_MakeFromBackendTexture_2_context">context</a>; for instance, if
447<a href="#SkSurface_MakeFromBackendTexture_2_backendTexture">backendTexture</a> has an sRGB configuration, then <a href="#SkSurface_MakeFromBackendTexture_2_context">context</a> must support sRGB,
448and <a href="#SkSurface_MakeFromBackendTexture_2_colorSpace">colorSpace</a> must be present. Further, <a href="#SkSurface_MakeFromBackendTexture_2_backendTexture">backendTexture</a> width and height must
449not exceed <a href="#SkSurface_MakeFromBackendTexture_2_context">context</a> capabilities, and the <a href="#SkSurface_MakeFromBackendTexture_2_context">context</a> must be able to support
450back-end textures.
451
452If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
453
454### Parameters
455
456<table>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_context"> <code><strong>context </strong></code> </a></td> <td>
457<a href="undocumented#GPU_Context">GPU Context</a></td>
458  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_backendTexture"> <code><strong>backendTexture </strong></code> </a></td> <td>
459texture residing on GPU</td>
460  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_origin"> <code><strong>origin </strong></code> </a></td> <td>
461one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
462  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_sampleCnt"> <code><strong>sampleCnt </strong></code> </a></td> <td>
463samples per pixel, or 0 to disable full scene anti-aliasing</td>
464  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_colorType"> <code><strong>colorType </strong></code> </a></td> <td>
465one of: <a href="SkImageInfo_Reference#SkColorType">kUnknown SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kAlpha 8 SkColorType</a>,
466<a href="SkImageInfo_Reference#SkColorType">kRGB 565 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kARGB 4444 SkColorType</a>,
467<a href="SkImageInfo_Reference#SkColorType">kRGBA 8888 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kBGRA 8888 SkColorType</a>,
468<a href="SkImageInfo_Reference#SkColorType">kGray 8 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kRGBA F16 SkColorType</a></td>
469  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
470range of colors</td>
471  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTexture_2_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
472LCD striping orientation and setting for device independent
473fonts; may be nullptr</td>
474  </tr>
475</table>
476
477### Return Value
478
479<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
480
481### Example
482
483<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
484void draw(SkCanvas* canvas) {
485    SkPaint paint;
486    paint.setTextSize(32);
487    GrContext* context = canvas->getGrContext();
488    if (!context) {
489         canvas->drawString("GPU only!", 20, 40, paint);
490         return;
491    }
492    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(context,
493            backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin,
494            kRGBA_8888_SkColorType, 0, nullptr, nullptr);
495    auto surfaceCanvas = gpuSurface->getCanvas();
496    surfaceCanvas->clear(SK_ColorWHITE);
497    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
498    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
499    canvas->drawImage(image, 0, 0);
500}
501</pre>
502
503### See Also
504
505<a href="undocumented#GrBackendTexture">GrBackendTexture</a> <a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
506
507---
508
509<a name="SkSurface_MakeFromBackendRenderTarget"></a>
510## MakeFromBackendRenderTarget
511
512<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
513static sk_sp&lt;SkSurface&gt; MakeFromBackendRenderTarget(GrContext* context,
514                                                   const GrBackendRenderTarget& backendRenderTarget,
515                                                   GrSurfaceOrigin origin,
516                                                   sk_sp&lt;SkColorSpace&gt; colorSpace,
517                                                   const SkSurfaceProps* surfaceProps)
518</pre>
519
520Wraps a GPU-backed buffer into <a href="#Surface">Surface</a>. Caller must ensure render target is
521valid for the lifetime of returned <a href="#Surface">Surface</a>.
522
523<a href="#Surface">Surface</a> is returned if all parameters are valid. <a href="#SkSurface_MakeFromBackendRenderTarget_backendRenderTarget">backendRenderTarget</a> is valid if
524its pixel configuration agrees with <a href="#SkSurface_MakeFromBackendRenderTarget_colorSpace">colorSpace</a> and <a href="#SkSurface_MakeFromBackendRenderTarget_context">context</a>; for instance, if
525<a href="#SkSurface_MakeFromBackendRenderTarget_backendRenderTarget">backendRenderTarget</a> has an sRGB configuration, then <a href="#SkSurface_MakeFromBackendRenderTarget_context">context</a> must support sRGB,
526and <a href="#SkSurface_MakeFromBackendRenderTarget_colorSpace">colorSpace</a> must be present. Further, <a href="#SkSurface_MakeFromBackendRenderTarget_backendRenderTarget">backendRenderTarget</a> width and height must
527not exceed <a href="#SkSurface_MakeFromBackendRenderTarget_context">context</a> capabilities, and the <a href="#SkSurface_MakeFromBackendRenderTarget_context">context</a> must be able to support
528back-end render targets.
529
530If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
531
532### Parameters
533
534<table>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_context"> <code><strong>context </strong></code> </a></td> <td>
535<a href="undocumented#GPU_Context">GPU Context</a></td>
536  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_backendRenderTarget"> <code><strong>backendRenderTarget </strong></code> </a></td> <td>
537GPU intermediate memory buffer</td>
538  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_origin"> <code><strong>origin </strong></code> </a></td> <td>
539one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
540  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
541range of colors</td>
542  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
543LCD striping orientation and setting for device independent
544fonts; may be nullptr</td>
545  </tr>
546</table>
547
548### Return Value
549
550<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
551
552### Example
553
554<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
555void draw(SkCanvas* canvas) {
556    SkPaint paint;
557    paint.setTextSize(32);
558    GrContext* context = canvas->getGrContext();
559    if (!context) {
560         canvas->drawString("GPU only!", 20, 40, paint);
561         return;
562    }
563    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendRenderTarget(context,
564            backEndRenderTarget, kTopLeft_GrSurfaceOrigin, nullptr, nullptr);
565    auto surfaceCanvas = gpuSurface->getCanvas();
566    surfaceCanvas->clear(SK_ColorWHITE);
567    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
568    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
569    canvas->drawImage(image, 0, 0);
570}
571</pre>
572
573### See Also
574
575<a href="#SkSurface_MakeFromBackendTexture">MakeFromBackendTexture</a><sup><a href="#SkSurface_MakeFromBackendTexture_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
576
577---
578
579<a name="SkSurface_MakeFromBackendRenderTarget_2"></a>
580
581<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
582static sk_sp&lt;SkSurface&gt; MakeFromBackendRenderTarget(GrContext* context,
583                                                   const GrBackendRenderTarget& backendRenderTarget,
584                                                   GrSurfaceOrigin origin, SkColorType colorType,
585                                                   sk_sp&lt;SkColorSpace&gt; colorSpace,
586                                                   const SkSurfaceProps* surfaceProps)
587</pre>
588
589Wraps a GPU-backed buffer into <a href="#Surface">Surface</a>. Caller must ensure render target is
590valid for the lifetime of returned <a href="#Surface">Surface</a>.
591
592<a href="#Surface">Surface</a> is returned if all parameters are valid. <a href="#SkSurface_MakeFromBackendRenderTarget_2_backendRenderTarget">backendRenderTarget</a> is valid if
593its pixel configuration agrees with <a href="#SkSurface_MakeFromBackendRenderTarget_2_colorSpace">colorSpace</a> and <a href="#SkSurface_MakeFromBackendRenderTarget_2_context">context</a>; for instance, if
594<a href="#SkSurface_MakeFromBackendRenderTarget_2_backendRenderTarget">backendRenderTarget</a> has an sRGB configuration, then <a href="#SkSurface_MakeFromBackendRenderTarget_2_context">context</a> must support sRGB,
595and <a href="#SkSurface_MakeFromBackendRenderTarget_2_colorSpace">colorSpace</a> must be present. Further, <a href="#SkSurface_MakeFromBackendRenderTarget_2_backendRenderTarget">backendRenderTarget</a> width and height must
596not exceed <a href="#SkSurface_MakeFromBackendRenderTarget_2_context">context</a> capabilities, and the <a href="#SkSurface_MakeFromBackendRenderTarget_2_context">context</a> must be able to support
597back-end render targets.
598
599If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
600
601### Parameters
602
603<table>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_context"> <code><strong>context </strong></code> </a></td> <td>
604<a href="undocumented#GPU_Context">GPU Context</a></td>
605  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_backendRenderTarget"> <code><strong>backendRenderTarget </strong></code> </a></td> <td>
606GPU intermediate memory buffer</td>
607  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_origin"> <code><strong>origin </strong></code> </a></td> <td>
608one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
609  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_colorType"> <code><strong>colorType </strong></code> </a></td> <td>
610one of: <a href="SkImageInfo_Reference#SkColorType">kUnknown SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kAlpha 8 SkColorType</a>,
611<a href="SkImageInfo_Reference#SkColorType">kRGB 565 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kARGB 4444 SkColorType</a>,
612<a href="SkImageInfo_Reference#SkColorType">kRGBA 8888 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kBGRA 8888 SkColorType</a>,
613<a href="SkImageInfo_Reference#SkColorType">kGray 8 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kRGBA F16 SkColorType</a></td>
614  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
615range of colors</td>
616  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendRenderTarget_2_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
617LCD striping orientation and setting for device independent
618fonts; may be nullptr</td>
619  </tr>
620</table>
621
622### Return Value
623
624<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
625
626### Example
627
628<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
629void draw(SkCanvas* canvas) {
630    SkPaint paint;
631    paint.setTextSize(32);
632    GrContext* context = canvas->getGrContext();
633    if (!context) {
634         canvas->drawString("GPU only!", 20, 40, paint);
635         return;
636    }
637    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendRenderTarget(context,
638            backEndRenderTarget, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
639            nullptr, nullptr);
640    auto surfaceCanvas = gpuSurface->getCanvas();
641    surfaceCanvas->clear(SK_ColorWHITE);
642    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
643    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
644    canvas->drawImage(image, 0, 0);
645}
646</pre>
647
648### See Also
649
650<a href="#SkSurface_MakeFromBackendTexture">MakeFromBackendTexture</a><sup><a href="#SkSurface_MakeFromBackendTexture_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
651
652---
653
654<a name="SkSurface_MakeFromBackendTextureAsRenderTarget"></a>
655## MakeFromBackendTextureAsRenderTarget
656
657<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
658static sk_sp&lt;SkSurface&gt; MakeFromBackendTextureAsRenderTarget(GrContext* context,
659                                            const GrBackendTexture& backendTexture,
660                                            GrSurfaceOrigin origin, int sampleCnt,
661                                            sk_sp&lt;SkColorSpace&gt; colorSpace,
662                                            const SkSurfaceProps* surfaceProps)
663</pre>
664
665Used to wrap a GPU-backed texture as a <a href="#SkSurface">SkSurface</a>. Skia will treat the texture as
666a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own
667the associated render target objects (but not the provided texture). Skia will not assume
668ownership of the texture and the client must ensure the texture is valid for the lifetime
669of the <a href="#SkSurface">SkSurface</a>.
670
671If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
672
673### Parameters
674
675<table>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_context"> <code><strong>context </strong></code> </a></td> <td>
676<a href="undocumented#GPU_Context">GPU Context</a></td>
677  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_backendTexture"> <code><strong>backendTexture </strong></code> </a></td> <td>
678texture residing on GPU</td>
679  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_origin"> <code><strong>origin </strong></code> </a></td> <td>
680one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
681  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_sampleCnt"> <code><strong>sampleCnt </strong></code> </a></td> <td>
682samples per pixel, or 0 to disable full scene anti-aliasing</td>
683  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
684range of colors</td>
685  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
686LCD striping orientation and setting for device independent
687fonts; may be nullptr</td>
688  </tr>
689</table>
690
691### Return Value
692
693<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
694
695### Example
696
697<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
698void draw(SkCanvas* canvas) {SkPaint paint;
699    paint.setTextSize(32);
700    GrContext* context = canvas->getGrContext();
701    if (!context) {
702         canvas->drawString("GPU only!", 20, 40, paint);
703         return;
704    }
705    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget(
706            context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0,
707            nullptr, nullptr);
708    auto surfaceCanvas = gpuSurface->getCanvas();
709    surfaceCanvas->clear(SK_ColorWHITE);
710    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
711    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
712    canvas->drawImage(image, 0, 0);
713}
714</pre>
715
716### See Also
717
718<a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
719
720---
721
722<a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2"></a>
723
724<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
725static sk_sp&lt;SkSurface&gt; MakeFromBackendTextureAsRenderTarget(GrContext* context,
726                                            const GrBackendTexture& backendTexture,
727                                            GrSurfaceOrigin origin, int sampleCnt,
728                                            SkColorType colorType, sk_sp&lt;SkColorSpace&gt; colorSpace,
729                                            const SkSurfaceProps* surfaceProps)
730</pre>
731
732Used to wrap a GPU-backed texture as a <a href="#SkSurface">SkSurface</a>. Skia will treat the texture as
733a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own
734the associated render target objects (but not the provided texture). Skia will not assume
735ownership of the texture and the client must ensure the texture is valid for the lifetime
736of the <a href="#SkSurface">SkSurface</a>.
737
738If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
739
740### Parameters
741
742<table>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_context"> <code><strong>context </strong></code> </a></td> <td>
743<a href="undocumented#GPU_Context">GPU Context</a></td>
744  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_backendTexture"> <code><strong>backendTexture </strong></code> </a></td> <td>
745texture residing on GPU</td>
746  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_origin"> <code><strong>origin </strong></code> </a></td> <td>
747one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
748  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_sampleCnt"> <code><strong>sampleCnt </strong></code> </a></td> <td>
749samples per pixel, or 0 to disable full scene anti-aliasing</td>
750  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_colorType"> <code><strong>colorType </strong></code> </a></td> <td>
751one of: <a href="SkImageInfo_Reference#SkColorType">kUnknown SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kAlpha 8 SkColorType</a>,
752<a href="SkImageInfo_Reference#SkColorType">kRGB 565 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kARGB 4444 SkColorType</a>,
753<a href="SkImageInfo_Reference#SkColorType">kRGBA 8888 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kBGRA 8888 SkColorType</a>,
754<a href="SkImageInfo_Reference#SkColorType">kGray 8 SkColorType</a>, <a href="SkImageInfo_Reference#SkColorType">kRGBA F16 SkColorType</a></td>
755  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_colorSpace"> <code><strong>colorSpace </strong></code> </a></td> <td>
756range of colors</td>
757  </tr>  <tr>    <td><a name="SkSurface_MakeFromBackendTextureAsRenderTarget_2_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
758LCD striping orientation and setting for device independent
759fonts; may be nullptr</td>
760  </tr>
761</table>
762
763### Return Value
764
765<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
766
767### Example
768
769<pre style="padding: 1em 1em 1em 1em; font-size: 13px width: 62.5em; background-color: #f0f0f0">
770void draw(SkCanvas* canvas) {SkPaint paint;
771    paint.setTextSize(32);
772    GrContext* context = canvas->getGrContext();
773    if (!context) {
774         canvas->drawString("GPU only!", 20, 40, paint);
775         return;
776    }
777    sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget(
778            context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0,
779            kRGBA_8888_SkColorType, nullptr, nullptr);
780    auto surfaceCanvas = gpuSurface->getCanvas();
781    surfaceCanvas->clear(SK_ColorWHITE);
782    surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
783    sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
784    canvas->drawImage(image, 0, 0);
785}
786</pre>
787
788### See Also
789
790<a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
791
792---
793
794<a name="SkSurface_MakeRenderTarget"></a>
795## MakeRenderTarget
796
797<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
798static sk_sp&lt;SkSurface&gt; MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
799                                         const SkImageInfo& imageInfo, int sampleCount,
800                                         GrSurfaceOrigin surfaceOrigin,
801                                         const SkSurfaceProps* surfaceProps,
802                                         bool shouldCreateWithMips = false)
803</pre>
804
805Returns offscreen <a href="#Surface">Surface</a> on GPU indicated by <a href="#SkSurface_MakeRenderTarget_context">context</a>. Allocates memory for
806pixels, based on the width, height, and <a href="SkImageInfo_Reference#Color_Type">Color Type</a> in ImageInfo.  <a href="#SkSurface_MakeRenderTarget_budgeted">budgeted</a>
807selects whether allocation for offscreen pixels is tracked by <a href="#SkSurface_MakeRenderTarget_context">context</a>. <a href="#SkSurface_MakeRenderTarget_imageInfo">imageInfo</a>
808describes the pixel format in <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, and transparency in
809<a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, and color matching in <a href="undocumented#Color_Space">Color Space</a>.
810
811<a href="#SkSurface_MakeRenderTarget_sampleCount">sampleCount</a> requests the number of samples per pixel.
812Pass zero to disable Multi_Sample_Anti_Aliasing.  The request is rounded
813up to the next supported count, or rounded down if it is larger than the
814maximum supported count.
815
816<a href="#SkSurface_MakeRenderTarget_surfaceOrigin">surfaceOrigin</a> pins either the top-left or the bottom-left corner to the origin.
817
818<a href="#SkSurface_MakeRenderTarget_shouldCreateWithMips">shouldCreateWithMips</a> hints that <a href="SkImage_Reference#Image">Image</a> returned by <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> is <a href="undocumented#Mip_Map">Mip Map</a>.
819
820If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
821
822### Parameters
823
824<table>  <tr>    <td><a name="SkSurface_MakeRenderTarget_context"> <code><strong>context </strong></code> </a></td> <td>
825<a href="undocumented#GPU_Context">GPU Context</a></td>
826  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_budgeted"> <code><strong>budgeted </strong></code> </a></td> <td>
827one of: <a href="#SkBudgeted_kNo">SkBudgeted::kNo</a>, <a href="#SkBudgeted_kYes">SkBudgeted::kYes</a></td>
828  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
829width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>;
830width, or height, or both, may be zero</td>
831  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_sampleCount"> <code><strong>sampleCount </strong></code> </a></td> <td>
832samples per pixel, or 0 to disable full scene anti-aliasing</td>
833  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_surfaceOrigin"> <code><strong>surfaceOrigin </strong></code> </a></td> <td>
834one of: <a href="undocumented#GrSurfaceOrigin">kBottomLeft GrSurfaceOrigin</a>, <a href="undocumented#GrSurfaceOrigin">kTopLeft GrSurfaceOrigin</a></td>
835  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_surfaceProps"> <code><strong>surfaceProps </strong></code> </a></td> <td>
836LCD striping orientation and setting for device independent
837fonts; may be nullptr</td>
838  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_shouldCreateWithMips"> <code><strong>shouldCreateWithMips </strong></code> </a></td> <td>
839hint that <a href="#Surface">Surface</a> will host <a href="undocumented#Mip_Map">Mip Map</a> images</td>
840  </tr>
841</table>
842
843### Return Value
844
845<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
846
847### Example
848
849<div><fiddle-embed name="67b6609471a3f1ed0f4b1657004cdecb" gpu="true"></fiddle-embed></div>
850
851### See Also
852
853<a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeFromBackendTextureAsRenderTarget">MakeFromBackendTextureAsRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendTextureAsRenderTarget_2">[2]</a></sup>
854
855---
856
857<a name="SkSurface_MakeRenderTarget_2"></a>
858
859<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
860static sk_sp&lt;SkSurface&gt; MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
861                                         const SkImageInfo& imageInfo, int sampleCount,
862                                         const SkSurfaceProps* props)
863</pre>
864
865Returns offscreen <a href="#Surface">Surface</a> on GPU indicated by <a href="#SkSurface_MakeRenderTarget_2_context">context</a>. Allocates memory for
866pixels, based on the width, height, and <a href="SkImageInfo_Reference#Color_Type">Color Type</a> in ImageInfo.  <a href="#SkSurface_MakeRenderTarget_2_budgeted">budgeted</a>
867selects whether allocation for offscreen pixels is tracked by <a href="#SkSurface_MakeRenderTarget_2_context">context</a>. <a href="#SkSurface_MakeRenderTarget_2_imageInfo">imageInfo</a>
868describes the pixel format in <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, and transparency in
869<a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, and color matching in <a href="undocumented#Color_Space">Color Space</a>.
870
871<a href="#SkSurface_MakeRenderTarget_2_sampleCount">sampleCount</a> requests the number of samples per pixel.
872Pass zero to disable Multi_Sample_Anti_Aliasing.  The request is rounded
873up to the next supported count, or rounded down if it is larger than the
874maximum supported count.
875
876<a href="#Surface">Surface</a> bottom-left corner is pinned to the origin.
877
878### Parameters
879
880<table>  <tr>    <td><a name="SkSurface_MakeRenderTarget_2_context"> <code><strong>context </strong></code> </a></td> <td>
881<a href="undocumented#GPU_Context">GPU Context</a></td>
882  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_2_budgeted"> <code><strong>budgeted </strong></code> </a></td> <td>
883one of: <a href="#SkBudgeted_kNo">SkBudgeted::kNo</a>, <a href="#SkBudgeted_kYes">SkBudgeted::kYes</a></td>
884  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_2_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
885width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
886of <a href="undocumented#Raster_Surface">Raster Surface</a>; width, or height, or both, may be zero</td>
887  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_2_sampleCount"> <code><strong>sampleCount </strong></code> </a></td> <td>
888samples per pixel, or 0 to disable Multi_Sample_Anti_Aliasing</td>
889  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_2_props"> <code><strong>props </strong></code> </a></td> <td>
890LCD striping orientation and setting for device independent
891fonts; may be nullptr</td>
892  </tr>
893</table>
894
895### Return Value
896
897<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
898
899### Example
900
901<div><fiddle-embed name="640321e8ecfb3f9329f3bc6e1f02485f" gpu="true" cpu="true"><div>LCD text takes advantage of raster striping to improve resolution. Only one of
902the four combinations is correct, depending on whether the monitor's LCD is
903horizontal or vertical, and whether the order of the stripes is red blue green
904or red green blue.</div></fiddle-embed></div>
905
906### See Also
907
908<a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeFromBackendTextureAsRenderTarget">MakeFromBackendTextureAsRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendTextureAsRenderTarget_2">[2]</a></sup>
909
910---
911
912<a name="SkSurface_MakeRenderTarget_3"></a>
913
914<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
915static sk_sp&lt;SkSurface&gt; MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
916                                         const SkImageInfo& imageInfo)
917</pre>
918
919Returns offscreen <a href="#Surface">Surface</a> on GPU indicated by <a href="#SkSurface_MakeRenderTarget_3_context">context</a>. Allocates memory for
920pixels, based on the width, height, and <a href="SkImageInfo_Reference#Color_Type">Color Type</a> in ImageInfo.  <a href="#SkSurface_MakeRenderTarget_3_budgeted">budgeted</a>
921selects whether allocation for offscreen pixels is tracked by <a href="#SkSurface_MakeRenderTarget_3_context">context</a>. <a href="#SkSurface_MakeRenderTarget_3_imageInfo">imageInfo</a>
922describes the pixel format in <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, and transparency in
923<a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, and color matching in <a href="undocumented#Color_Space">Color Space</a>.
924
925<a href="#Surface">Surface</a> bottom-left corner is pinned to the origin.
926
927### Parameters
928
929<table>  <tr>    <td><a name="SkSurface_MakeRenderTarget_3_context"> <code><strong>context </strong></code> </a></td> <td>
930<a href="undocumented#GPU_Context">GPU Context</a></td>
931  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_3_budgeted"> <code><strong>budgeted </strong></code> </a></td> <td>
932one of: <a href="#SkBudgeted_kNo">SkBudgeted::kNo</a>, <a href="#SkBudgeted_kYes">SkBudgeted::kYes</a></td>
933  </tr>  <tr>    <td><a name="SkSurface_MakeRenderTarget_3_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
934width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
935of <a href="undocumented#Raster_Surface">Raster Surface</a>; width, or height, or both, may be zero</td>
936  </tr>
937</table>
938
939### Return Value
940
941<a href="#Surface">Surface</a> if all parameters are valid; otherwise, nullptr
942
943### Example
944
945<div><fiddle-embed name="5c7629c15e9ac93f098335e72560fa2e" gpu="true"></fiddle-embed></div>
946
947### See Also
948
949<a href="#SkSurface_MakeFromBackendRenderTarget">MakeFromBackendRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendRenderTarget_2">[2]</a></sup> <a href="#SkSurface_MakeFromBackendTextureAsRenderTarget">MakeFromBackendTextureAsRenderTarget</a><sup><a href="#SkSurface_MakeFromBackendTextureAsRenderTarget_2">[2]</a></sup>
950
951---
952
953<a name="SkSurface_MakeNull"></a>
954## MakeNull
955
956<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
957static sk_sp&lt;SkSurface&gt; MakeNull(int width, int height)
958</pre>
959
960Returns <a href="#Surface">Surface</a> without backing pixels. Drawing to <a href="SkCanvas_Reference#Canvas">Canvas</a> returned from <a href="#Surface">Surface</a>
961has no effect. Calling <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> on returned <a href="#Surface">Surface</a> returns nullptr.
962
963### Parameters
964
965<table>  <tr>    <td><a name="SkSurface_MakeNull_width"> <code><strong>width </strong></code> </a></td> <td>
966one or greater</td>
967  </tr>  <tr>    <td><a name="SkSurface_MakeNull_height"> <code><strong>height </strong></code> </a></td> <td>
968one or greater</td>
969  </tr>
970</table>
971
972### Return Value
973
974<a href="#Surface">Surface</a> if width and height are positive; otherwise, nullptr
975
976### Example
977
978<div><fiddle-embed name="99a54b814ccab7d2b1143c88581649ff">
979
980#### Example Output
981
982~~~~
983SkSurface::MakeNull(0, 0) == nullptr
984surf->makeImageSnapshot() == nullptr
985~~~~
986
987</fiddle-embed></div>
988
989### See Also
990
991<a href="#SkSurface_MakeRaster">MakeRaster</a><sup><a href="#SkSurface_MakeRaster_2">[2]</a></sup> <a href="#SkSurface_MakeRenderTarget">MakeRenderTarget</a><sup><a href="#SkSurface_MakeRenderTarget_2">[2]</a></sup><sup><a href="#SkSurface_MakeRenderTarget_3">[3]</a></sup>
992
993---
994
995<a name="SkSurface_width"></a>
996## width
997
998<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
999int width() const
1000</pre>
1001
1002Returns pixel count in each row; may be zero or greater.
1003
1004### Return Value
1005
1006number of pixel columns
1007
1008### Example
1009
1010<div><fiddle-embed name="df066b56dd97c7c589fd2bb6a2539de8">
1011
1012#### Example Output
1013
1014~~~~
1015surface width=37  canvas width=37
1016~~~~
1017
1018</fiddle-embed></div>
1019
1020### See Also
1021
1022<a href="#SkSurface_height">height</a>
1023
1024---
1025
1026<a name="SkSurface_height"></a>
1027## height
1028
1029<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1030int height() const
1031</pre>
1032
1033Returns pixel row count; may be zero or greater.
1034
1035### Return Value
1036
1037number of pixel rows
1038
1039### Example
1040
1041<div><fiddle-embed name="20571cc23e3146deaa09046b64cc0aef">
1042
1043#### Example Output
1044
1045~~~~
1046surface height=1000  canvas height=1000
1047~~~~
1048
1049</fiddle-embed></div>
1050
1051### See Also
1052
1053<a href="#SkSurface_width">width</a>
1054
1055---
1056
1057<a name="SkSurface_generationID"></a>
1058## generationID
1059
1060<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1061uint32_t generationID()
1062</pre>
1063
1064Returns unique value identifying the content of <a href="#Surface">Surface</a>. Returned value changes
1065each time the content changes. Content is changed by drawing, or by calling
1066<a href="#SkSurface_notifyContentWillChange">notifyContentWillChange</a>.
1067
1068### Return Value
1069
1070unique content identifier
1071
1072### Example
1073
1074<div><fiddle-embed name="be9574c4a14f891e1abb4ec2b1e51d6c">
1075
1076#### Example Output
1077
1078~~~~
1079surface generationID: 1
1080surface generationID: 2
1081surface generationID: 3
1082~~~~
1083
1084</fiddle-embed></div>
1085
1086### See Also
1087
1088<a href="#SkSurface_notifyContentWillChange">notifyContentWillChange</a> <a href="#SkSurface_ContentChangeMode">ContentChangeMode</a> <a href="#SkSurface_getCanvas">getCanvas</a>
1089
1090---
1091
1092## <a name="SkSurface_ContentChangeMode"></a> Enum SkSurface::ContentChangeMode
1093
1094<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1095enum <a href="#SkSurface_ContentChangeMode">ContentChangeMode</a> {
1096<a href="#SkSurface_kDiscard_ContentChangeMode">kDiscard ContentChangeMode</a>,
1097<a href="#SkSurface_kRetain_ContentChangeMode">kRetain ContentChangeMode</a>,
1098};</pre>
1099
1100<a href="#SkSurface_ContentChangeMode">ContentChangeMode</a> members are parameters to <a href="#SkSurface_notifyContentWillChange">notifyContentWillChange</a>.
1101
1102### Constants
1103
1104<table>
1105  <tr>
1106    <td><a name="SkSurface_kDiscard_ContentChangeMode"> <code><strong>SkSurface::kDiscard_ContentChangeMode </strong></code> </a></td><td>Pass to notifyContentWillChange to discard surface contents when</td><td>the surface is cleared or overwritten.</td>
1107  </tr>
1108  <tr>
1109    <td><a name="SkSurface_kRetain_ContentChangeMode"> <code><strong>SkSurface::kRetain_ContentChangeMode </strong></code> </a></td><td>Pass to notifyContentWillChange when to preserve surface contents.</td><td>If a snapshot has been generated, this copies the <a href="#Surface">Surface</a> contents.</td>
1110  </tr>
1111</table>
1112
1113### See Also
1114
1115<a href="#SkSurface_notifyContentWillChange">notifyContentWillChange</a> <a href="#SkSurface_generationID">generationID</a>
1116
1117
1118
1119<a name="SkSurface_notifyContentWillChange"></a>
1120## notifyContentWillChange
1121
1122<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1123void notifyContentWillChange(ContentChangeMode mode)
1124</pre>
1125
1126Notifies that <a href="#Surface">Surface</a> contents will be changed by code outside of Skia.
1127Subsequent calls to <a href="#SkSurface_generationID">generationID</a> return a different value.
1128
1129<a href="#SkSurface_notifyContentWillChange_mode">mode</a> is normally passed as <a href="#SkSurface_kRetain_ContentChangeMode">kRetain ContentChangeMode</a>.
1130
1131### Parameters
1132
1133<table>  <tr>    <td><a name="SkSurface_notifyContentWillChange_mode"> <code><strong>mode </strong></code> </a></td> <td>
1134one of: <a href="#SkSurface_kDiscard_ContentChangeMode">kDiscard ContentChangeMode</a>, <a href="#SkSurface_kRetain_ContentChangeMode">kRetain ContentChangeMode</a></td>
1135  </tr>
1136</table>
1137
1138### Example
1139
1140<div><fiddle-embed name="be9574c4a14f891e1abb4ec2b1e51d6c"></fiddle-embed></div>
1141
1142### See Also
1143
1144<a href="#SkSurface_ContentChangeMode">ContentChangeMode</a> <a href="#SkSurface_generationID">generationID</a>
1145
1146---
1147
1148## <a name="SkSurface_BackendHandleAccess"></a> Enum SkSurface::BackendHandleAccess
1149
1150<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1151enum <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a> {
1152<a href="#SkSurface_kFlushRead_BackendHandleAccess">kFlushRead BackendHandleAccess</a>,
1153<a href="#SkSurface_kFlushWrite_BackendHandleAccess">kFlushWrite BackendHandleAccess</a>,
1154<a href="#SkSurface_kDiscardWrite_BackendHandleAccess">kDiscardWrite BackendHandleAccess</a>,
1155};
1156
1157static const <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a> <a href="#SkSurface_kFlushRead_TextureHandleAccess">kFlushRead TextureHandleAccess</a> =
1158<a href="#SkSurface_kFlushRead_BackendHandleAccess">kFlushRead BackendHandleAccess</a>;
1159static const <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a> <a href="#SkSurface_kFlushWrite_TextureHandleAccess">kFlushWrite TextureHandleAccess</a> =
1160<a href="#SkSurface_kFlushWrite_BackendHandleAccess">kFlushWrite BackendHandleAccess</a>;
1161static const <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a> <a href="#SkSurface_kDiscardWrite_TextureHandleAccess">kDiscardWrite TextureHandleAccess</a> =
1162<a href="#SkSurface_kDiscardWrite_BackendHandleAccess">kDiscardWrite BackendHandleAccess</a>;</pre>
1163
1164### Constants
1165
1166<table>
1167  <tr>
1168    <td><a name="SkSurface_kFlushRead_BackendHandleAccess"> <code><strong>SkSurface::kFlushRead_BackendHandleAccess </strong></code> </a></td><td>0</td><td>Caller may read from the back-end object.</td>
1169  </tr>
1170  <tr>
1171    <td><a name="SkSurface_kFlushWrite_BackendHandleAccess"> <code><strong>SkSurface::kFlushWrite_BackendHandleAccess </strong></code> </a></td><td>1</td><td>Caller may write to the back-end object.</td>
1172  </tr>
1173  <tr>
1174    <td><a name="SkSurface_kDiscardWrite_BackendHandleAccess"> <code><strong>SkSurface::kDiscardWrite_BackendHandleAccess </strong></code> </a></td><td>2</td><td>Caller must overwrite the entire back-end object.</td>
1175  </tr>
1176  <tr>
1177    <td><a name="SkSurface_kFlushRead_TextureHandleAccess"> <code><strong>SkSurface::kFlushRead_TextureHandleAccess </strong></code> </a></td><td>0</td><td>Deprecated.
1178</td>
1179  </tr>
1180  <tr>
1181    <td><a name="SkSurface_kFlushWrite_TextureHandleAccess"> <code><strong>SkSurface::kFlushWrite_TextureHandleAccess </strong></code> </a></td><td>1</td><td>Deprecated.
1182</td>
1183  </tr>
1184  <tr>
1185    <td><a name="SkSurface_kDiscardWrite_TextureHandleAccess"> <code><strong>SkSurface::kDiscardWrite_TextureHandleAccess </strong></code> </a></td><td>2</td><td>Deprecated.
1186</td>
1187  </tr>
1188</table>
1189
1190### Example
1191
1192<div><fiddle-embed name="260a5ba014b00eeb5a74b3c6b8d31be4" gpu="true"></fiddle-embed></div>
1193
1194### See Also
1195
1196<a href="#SkSurface_getTextureHandle">getTextureHandle</a> <a href="#SkSurface_getRenderTargetHandle">getRenderTargetHandle</a>
1197
1198
1199
1200<a name="SkSurface_getTextureHandle"></a>
1201## getTextureHandle
1202
1203<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1204GrBackendObject getTextureHandle(BackendHandleAccess backendHandleAccess)
1205</pre>
1206
1207Returns the GPU back-end reference of the texture used by <a href="#Surface">Surface</a>, or zero
1208if <a href="#Surface">Surface</a> is not backed by a GPU texture.
1209
1210The returned texture handle is only valid until the next draw into <a href="#Surface">Surface</a>,
1211or when <a href="#Surface">Surface</a> is deleted.
1212
1213### Parameters
1214
1215<table>  <tr>    <td><a name="SkSurface_getTextureHandle_backendHandleAccess"> <code><strong>backendHandleAccess </strong></code> </a></td> <td>
1216one of:  <a href="#SkSurface_kFlushRead_BackendHandleAccess">kFlushRead BackendHandleAccess</a>,
1217<a href="#SkSurface_kFlushWrite_BackendHandleAccess">kFlushWrite BackendHandleAccess</a>, <a href="#SkSurface_kDiscardWrite_BackendHandleAccess">kDiscardWrite BackendHandleAccess</a></td>
1218  </tr>
1219</table>
1220
1221### Return Value
1222
1223GPU texture reference
1224
1225### Example
1226
1227<div><fiddle-embed name="4b5720038daaf65ba1ba546e678ddd6e" gpu="true"></fiddle-embed></div>
1228
1229### See Also
1230
1231<a href="#SkSurface_getRenderTargetHandle">getRenderTargetHandle</a> <a href="undocumented#GrBackendObject">GrBackendObject</a> <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a>
1232
1233---
1234
1235<a name="SkSurface_getRenderTargetHandle"></a>
1236## getRenderTargetHandle
1237
1238<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1239bool getRenderTargetHandle(GrBackendObject* backendObject, BackendHandleAccess backendHandleAccess)
1240</pre>
1241
1242Returns true and stores the GPU back-end reference of the render target used
1243by <a href="#Surface">Surface</a> in <a href="#SkSurface_getRenderTargetHandle_backendObject">backendObject</a>.
1244
1245Return false if <a href="#Surface">Surface</a> is not backed by a GPU render target, and leaves
1246<a href="#SkSurface_getRenderTargetHandle_backendObject">backendObject</a> unchanged.
1247
1248The returned render target handle is only valid until the next draw into <a href="#Surface">Surface</a>,
1249or when <a href="#Surface">Surface</a> is deleted.
1250
1251In OpenGL this returns the frame buffer object ID.
1252
1253### Parameters
1254
1255<table>  <tr>    <td><a name="SkSurface_getRenderTargetHandle_backendObject"> <code><strong>backendObject </strong></code> </a></td> <td>
1256GPU intermediate memory buffer</td>
1257  </tr>  <tr>    <td><a name="SkSurface_getRenderTargetHandle_backendHandleAccess"> <code><strong>backendHandleAccess </strong></code> </a></td> <td>
1258one of:  <a href="#SkSurface_kFlushRead_BackendHandleAccess">kFlushRead BackendHandleAccess</a>,
1259<a href="#SkSurface_kFlushWrite_BackendHandleAccess">kFlushWrite BackendHandleAccess</a>, <a href="#SkSurface_kDiscardWrite_BackendHandleAccess">kDiscardWrite BackendHandleAccess</a></td>
1260  </tr>
1261</table>
1262
1263### Return Value
1264
1265true if <a href="#Surface">Surface</a> is backed by GPU texture
1266
1267### Example
1268
1269<div><fiddle-embed name="16e848a4405ce08f8393bba13cc3b8bf" gpu="true"></fiddle-embed></div>
1270
1271### See Also
1272
1273<a href="#SkSurface_getTextureHandle">getTextureHandle</a> <a href="undocumented#GrBackendObject">GrBackendObject</a> <a href="#SkSurface_BackendHandleAccess">BackendHandleAccess</a>
1274
1275---
1276
1277<a name="SkSurface_getCanvas"></a>
1278## getCanvas
1279
1280<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1281SkCanvas* getCanvas()
1282</pre>
1283
1284Returns <a href="SkCanvas_Reference#Canvas">Canvas</a> that draws into <a href="#Surface">Surface</a>. Subsequent calls return the same <a href="SkCanvas_Reference#Canvas">Canvas</a>.
1285<a href="SkCanvas_Reference#Canvas">Canvas</a> returned is managed and owned by <a href="#Surface">Surface</a>, and is deleted when <a href="#Surface">Surface</a>
1286is deleted.
1287
1288### Return Value
1289
1290drawing <a href="SkCanvas_Reference#Canvas">Canvas</a> for <a href="#Surface">Surface</a>
1291
1292### Example
1293
1294<div><fiddle-embed name="33d0c5ad5a4810e533ae1010e29f8b75"></fiddle-embed></div>
1295
1296### See Also
1297
1298<a href="#SkSurface_makeSurface">makeSurface</a> <a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> <a href="#SkSurface_draw">draw</a><sup><a href="#SkSurface_draw_2">[2]</a></sup>
1299
1300---
1301
1302<a name="SkSurface_makeSurface"></a>
1303## makeSurface
1304
1305<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1306sk_sp&lt;SkSurface&gt; makeSurface(const SkImageInfo& imageInfo)
1307</pre>
1308
1309Returns a compatible <a href="#Surface">Surface</a>, or nullptr. Returned <a href="#Surface">Surface</a> contains
1310the same raster, GPU, or null properties as the original. Returned <a href="#Surface">Surface</a>
1311does not share the same pixels.
1312
1313Returns nullptr if <a href="#SkSurface_makeSurface_imageInfo">imageInfo</a> width or height are zero, or if <a href="#SkSurface_makeSurface_imageInfo">imageInfo</a>
1314is incompatible with <a href="#Surface">Surface</a>.
1315
1316### Parameters
1317
1318<table>  <tr>    <td><a name="SkSurface_makeSurface_imageInfo"> <code><strong>imageInfo </strong></code> </a></td> <td>
1319width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>, <a href="undocumented#Color_Space">Color Space</a>,
1320of <a href="#Surface">Surface</a>; width and height must be greater than zero</td>
1321  </tr>
1322</table>
1323
1324### Return Value
1325
1326compatible <a href="#Surface">Surface</a> or nullptr
1327
1328### Example
1329
1330<div><fiddle-embed name="a9889b519a26896b900da0444e423c61"></fiddle-embed></div>
1331
1332### See Also
1333
1334<a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> <a href="#SkSurface_getCanvas">getCanvas</a> <a href="#SkSurface_draw">draw</a><sup><a href="#SkSurface_draw_2">[2]</a></sup>
1335
1336---
1337
1338<a name="SkSurface_makeImageSnapshot"></a>
1339## makeImageSnapshot
1340
1341<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1342sk_sp&lt;SkImage&gt; makeImageSnapshot()
1343</pre>
1344
1345Returns <a href="SkImage_Reference#Image">Image</a> capturing <a href="#Surface">Surface</a> contents. Subsequent drawing to <a href="#Surface">Surface</a> contents
1346are not captured. <a href="SkImage_Reference#Image">Image</a> allocation is accounted for if <a href="#Surface">Surface</a> was created with
1347<a href="#SkBudgeted_kYes">SkBudgeted::kYes</a>.
1348
1349### Return Value
1350
1351<a href="SkImage_Reference#Image">Image</a> initialized with <a href="#Surface">Surface</a> contents
1352
1353### Example
1354
1355<div><fiddle-embed name="46f1fa0d95e590a64bed0140407ce5f7"></fiddle-embed></div>
1356
1357### See Also
1358
1359<a href="#SkSurface_draw">draw</a><sup><a href="#SkSurface_draw_2">[2]</a></sup> <a href="#SkSurface_getCanvas">getCanvas</a>
1360
1361---
1362
1363<a name="SkSurface_draw"></a>
1364## draw
1365
1366<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1367void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
1368</pre>
1369
1370Draws <a href="#Surface">Surface</a> contents to <a href="#SkSurface_draw_canvas">canvas</a>, with its top-left corner at (<a href="#SkSurface_draw_x">x</a>, <a href="#SkSurface_draw_y">y</a>).
1371
1372If <a href="SkPaint_Reference#Paint">Paint</a> <a href="#SkSurface_draw_paint">paint</a> is not nullptr, apply <a href="undocumented#Color_Filter">Color Filter</a>, <a href="#Alpha">Color Alpha</a>, <a href="undocumented#Image_Filter">Image Filter</a>,
1373<a href="undocumented#Blend_Mode">Blend Mode</a>, and <a href="undocumented#Draw_Looper">Draw Looper</a>.
1374
1375### Parameters
1376
1377<table>  <tr>    <td><a name="SkSurface_draw_canvas"> <code><strong>canvas </strong></code> </a></td> <td>
1378<a href="SkCanvas_Reference#Canvas">Canvas</a> drawn into</td>
1379  </tr>  <tr>    <td><a name="SkSurface_draw_x"> <code><strong>x </strong></code> </a></td> <td>
1380horizontal offset in <a href="SkCanvas_Reference#Canvas">Canvas</a></td>
1381  </tr>  <tr>    <td><a name="SkSurface_draw_y"> <code><strong>y </strong></code> </a></td> <td>
1382vertical offset in <a href="SkCanvas_Reference#Canvas">Canvas</a></td>
1383  </tr>  <tr>    <td><a name="SkSurface_draw_paint"> <code><strong>paint </strong></code> </a></td> <td>
1384<a href="SkPaint_Reference#Paint">Paint</a> containing <a href="undocumented#Blend_Mode">Blend Mode</a>, <a href="undocumented#Color_Filter">Color Filter</a>, <a href="undocumented#Image_Filter">Image Filter</a>,
1385and so on; or nullptr</td>
1386  </tr>
1387</table>
1388
1389### Example
1390
1391<div><fiddle-embed name="0de693f4d8dd898a60be8cfba23952be"></fiddle-embed></div>
1392
1393### See Also
1394
1395<a href="#SkSurface_makeImageSnapshot">makeImageSnapshot</a> <a href="#SkSurface_getCanvas">getCanvas</a>
1396
1397---
1398
1399<a name="SkSurface_peekPixels"></a>
1400## peekPixels
1401
1402<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1403bool peekPixels(SkPixmap* pixmap)
1404</pre>
1405
1406Copies <a href="#Surface">Surface</a> pixel address, row bytes, and <a href="SkImageInfo_Reference#Image_Info">Image Info</a> to <a href="SkPixmap_Reference#Pixmap">Pixmap</a>, if address
1407is available, and returns true. If pixel address is not available, return
1408false and leave <a href="SkPixmap_Reference#Pixmap">Pixmap</a> unchanged.
1409
1410<a href="#SkSurface_peekPixels_pixmap">pixmap</a> contents become invalid on any future change to <a href="#Surface">Surface</a>.
1411
1412### Parameters
1413
1414<table>  <tr>    <td><a name="SkSurface_peekPixels_pixmap"> <code><strong>pixmap </strong></code> </a></td> <td>
1415storage for pixel state if pixels are readable; otherwise, ignored</td>
1416  </tr>
1417</table>
1418
1419### Return Value
1420
1421true if <a href="#Surface">Surface</a> has direct access to pixels
1422
1423### Example
1424
1425<div><fiddle-embed name="8c6184f22cfe068f021704cf92a147a1"></fiddle-embed></div>
1426
1427### See Also
1428
1429<a href="#SkSurface_readPixels">readPixels</a><sup><a href="#SkSurface_readPixels_2">[2]</a></sup><sup><a href="#SkSurface_readPixels_3">[3]</a></sup>
1430
1431---
1432
1433<a name="SkSurface_readPixels"></a>
1434## readPixels
1435
1436<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1437bool readPixels(const SkPixmap& dst, int srcX, int srcY)
1438</pre>
1439
1440Copies <a href="SkRect_Reference#Rect">Rect</a> of pixels to <a href="#SkSurface_readPixels_dst">dst</a>.
1441
1442Source <a href="SkRect_Reference#Rect">Rect</a> corners are (<a href="#SkSurface_readPixels_srcX">srcX</a>, <a href="#SkSurface_readPixels_srcY">srcY</a>) and <a href="#Surface">Surface</a> (<a href="#SkSurface_width">width</a>, <a href="#SkSurface_height">height</a>).
1443Destination <a href="SkRect_Reference#Rect">Rect</a> corners are (0, 0) and (<a href="#SkSurface_readPixels_dst">dst</a>.<a href="#SkSurface_width">width</a>, <a href="#SkSurface_readPixels_dst">dst</a>.<a href="#SkSurface_height">height</a>).
1444Copies each readable pixel intersecting both rectangles, without scaling,
1445converting to <a href="#SkSurface_readPixels_dst">dst</a>.colorType() and <a href="#SkSurface_readPixels_dst">dst</a>.alphaType() if required.
1446
1447Pixels are readable when <a href="#Surface">Surface</a> is raster, or backed by a GPU.
1448
1449The destination pixel storage must be allocated by the caller.
1450
1451<a href="undocumented#Pixel">Pixel</a> values are converted only if <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>
1452do not match. Only pixels within both source and destination rectangles
1453are copied. <a href="#SkSurface_readPixels_dst">dst</a> contents outside <a href="SkRect_Reference#Rect">Rect</a> intersection are unchanged.
1454
1455Pass negative values for <a href="#SkSurface_readPixels_srcX">srcX</a> or <a href="#SkSurface_readPixels_srcY">srcY</a> to offset pixels across or down destination.
1456
1457Does not copy, and returns false if:
1458
1459<table>  <tr>
1460    <td>Source and destination rectangles do not intersect.</td>  </tr>  <tr>
1461    <td><a href="SkPixmap_Reference#Pixmap">Pixmap</a> pixels could not be allocated.</td>  </tr>  <tr>
1462    <td><a href="#SkSurface_readPixels_dst">dst</a>.rowBytes() is too small to contain one row of pixels.</td>  </tr>
1463</table>
1464
1465### Parameters
1466
1467<table>  <tr>    <td><a name="SkSurface_readPixels_dst"> <code><strong>dst </strong></code> </a></td> <td>
1468storage for pixels copied from <a href="#Surface">Surface</a></td>
1469  </tr>  <tr>    <td><a name="SkSurface_readPixels_srcX"> <code><strong>srcX </strong></code> </a></td> <td>
1470offset into readable pixels in x; may be negative</td>
1471  </tr>  <tr>    <td><a name="SkSurface_readPixels_srcY"> <code><strong>srcY </strong></code> </a></td> <td>
1472offset into readable pixels in y; may be negative</td>
1473  </tr>
1474</table>
1475
1476### Return Value
1477
1478true if pixels were copied
1479
1480### Example
1481
1482<div><fiddle-embed name="9f454fb93bca6482598d198b4121f0a6"></fiddle-embed></div>
1483
1484### See Also
1485
1486<a href="#SkSurface_peekPixels">peekPixels</a>
1487
1488---
1489
1490<a name="SkSurface_readPixels_2"></a>
1491
1492<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1493bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY)
1494</pre>
1495
1496Copies <a href="SkRect_Reference#Rect">Rect</a> of pixels from <a href="SkCanvas_Reference#Canvas">Canvas</a> into <a href="#SkSurface_readPixels_2_dstPixels">dstPixels</a>.
1497
1498Source <a href="SkRect_Reference#Rect">Rect</a> corners are (<a href="#SkSurface_readPixels_2_srcX">srcX</a>, <a href="#SkSurface_readPixels_2_srcY">srcY</a>) and <a href="#Surface">Surface</a> (<a href="#SkSurface_width">width</a>, <a href="#SkSurface_height">height</a>).
1499Destination <a href="SkRect_Reference#Rect">Rect</a> corners are (0, 0) and (<a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.<a href="#SkSurface_width">width</a>, <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.<a href="#SkSurface_height">height</a>).
1500Copies each readable pixel intersecting both rectangles, without scaling,
1501converting to <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.colorType() and <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.alphaType() if required.
1502
1503Pixels are readable when <a href="#Surface">Surface</a> is raster, or backed by a GPU.
1504
1505The destination pixel storage must be allocated by the caller.
1506
1507<a href="undocumented#Pixel">Pixel</a> values are converted only if <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>
1508do not match. Only pixels within both source and destination rectangles
1509are copied. <a href="#SkSurface_readPixels_2_dstPixels">dstPixels</a> contents outside <a href="SkRect_Reference#Rect">Rect</a> intersection are unchanged.
1510
1511Pass negative values for <a href="#SkSurface_readPixels_2_srcX">srcX</a> or <a href="#SkSurface_readPixels_2_srcY">srcY</a> to offset pixels across or down destination.
1512
1513Does not copy, and returns false if:
1514
1515<table>  <tr>
1516    <td>Source and destination rectangles do not intersect.</td>  </tr>  <tr>
1517    <td><a href="#Surface">Surface</a> pixels could not be converted to <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.colorType() or <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.alphaType().</td>  </tr>  <tr>
1518    <td><a href="#SkSurface_readPixels_2_dstRowBytes">dstRowBytes</a> is too small to contain one row of pixels.</td>  </tr>
1519</table>
1520
1521### Parameters
1522
1523<table>  <tr>    <td><a name="SkSurface_readPixels_2_dstInfo"> <code><strong>dstInfo </strong></code> </a></td> <td>
1524width, height, <a href="SkImageInfo_Reference#Color_Type">Color Type</a>, and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a> of <a href="#SkSurface_readPixels_2_dstPixels">dstPixels</a></td>
1525  </tr>  <tr>    <td><a name="SkSurface_readPixels_2_dstPixels"> <code><strong>dstPixels </strong></code> </a></td> <td>
1526storage for pixels; <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.<a href="#SkSurface_height">height</a> times <a href="#SkSurface_readPixels_2_dstRowBytes">dstRowBytes</a>, or larger</td>
1527  </tr>  <tr>    <td><a name="SkSurface_readPixels_2_dstRowBytes"> <code><strong>dstRowBytes </strong></code> </a></td> <td>
1528size of one destination row; <a href="#SkSurface_readPixels_2_dstInfo">dstInfo</a>.<a href="#SkSurface_width">width</a> times pixel size, or larger</td>
1529  </tr>  <tr>    <td><a name="SkSurface_readPixels_2_srcX"> <code><strong>srcX </strong></code> </a></td> <td>
1530offset into readable pixels in x; may be negative</td>
1531  </tr>  <tr>    <td><a name="SkSurface_readPixels_2_srcY"> <code><strong>srcY </strong></code> </a></td> <td>
1532offset into readable pixels in y; may be negative</td>
1533  </tr>
1534</table>
1535
1536### Return Value
1537
1538true if pixels were copied
1539
1540### Example
1541
1542<div><fiddle-embed name="d141d6c662d201d191fb1eea26d014fd"><div>A black oval drawn on a red background provides an image to copy.
1543<a href="#SkSurface_readPixels">readPixels</a> copies one quarter of the <a href="#Surface">Surface</a> into each of the four corners.
1544The copied quarter ovals overdraw the original oval.</div></fiddle-embed></div>
1545
1546### See Also
1547
1548<a href="#SkSurface_peekPixels">peekPixels</a>
1549
1550---
1551
1552<a name="SkSurface_readPixels_3"></a>
1553
1554<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1555bool readPixels(const SkBitmap& dst, int srcX, int srcY)
1556</pre>
1557
1558Copies <a href="SkRect_Reference#Rect">Rect</a> of pixels from <a href="#Surface">Surface</a> into bitmap.
1559
1560Source <a href="SkRect_Reference#Rect">Rect</a> corners are (<a href="#SkSurface_readPixels_3_srcX">srcX</a>, <a href="#SkSurface_readPixels_3_srcY">srcY</a>) and <a href="#Surface">Surface</a> (<a href="#SkSurface_width">width</a>, <a href="#SkSurface_height">height</a>).
1561Destination <a href="SkRect_Reference#Rect">Rect</a> corners are (0, 0) and (bitmap.<a href="#SkSurface_width">width</a>, bitmap.<a href="#SkSurface_height">height</a>).
1562Copies each readable pixel intersecting both rectangles, without scaling,
1563converting to bitmap.colorType() and bitmap.alphaType() if required.
1564
1565Pixels are readable when <a href="#Surface">Surface</a> is raster, or backed by a GPU.
1566
1567The destination pixel storage must be allocated by the caller.
1568
1569<a href="undocumented#Pixel">Pixel</a> values are converted only if <a href="SkImageInfo_Reference#Color_Type">Color Type</a> and <a href="SkImageInfo_Reference#Alpha_Type">Alpha Type</a>
1570do not match. Only pixels within both source and destination rectangles
1571are copied. <a href="#SkSurface_readPixels_3_dst">dst</a> contents outside <a href="SkRect_Reference#Rect">Rect</a> intersection are unchanged.
1572
1573Pass negative values for <a href="#SkSurface_readPixels_3_srcX">srcX</a> or <a href="#SkSurface_readPixels_3_srcY">srcY</a> to offset pixels across or down destination.
1574
1575Does not copy, and returns false if:
1576
1577<table>  <tr>
1578    <td>Source and destination rectangles do not intersect.</td>  </tr>  <tr>
1579    <td><a href="#Surface">Surface</a> pixels could not be converted to <a href="#SkSurface_readPixels_3_dst">dst</a>.colorType() or <a href="#SkSurface_readPixels_3_dst">dst</a>.alphaType().</td>  </tr>  <tr>
1580    <td><a href="#SkSurface_readPixels_3_dst">dst</a> pixels could not be allocated.</td>  </tr>  <tr>
1581    <td><a href="#SkSurface_readPixels_3_dst">dst</a>.rowBytes() is too small to contain one row of pixels.</td>  </tr>
1582</table>
1583
1584### Parameters
1585
1586<table>  <tr>    <td><a name="SkSurface_readPixels_3_dst"> <code><strong>dst </strong></code> </a></td> <td>
1587storage for pixels copied from <a href="#Surface">Surface</a></td>
1588  </tr>  <tr>    <td><a name="SkSurface_readPixels_3_srcX"> <code><strong>srcX </strong></code> </a></td> <td>
1589offset into readable pixels in x; may be negative</td>
1590  </tr>  <tr>    <td><a name="SkSurface_readPixels_3_srcY"> <code><strong>srcY </strong></code> </a></td> <td>
1591offset into readable pixels in y; may be negative</td>
1592  </tr>
1593</table>
1594
1595### Return Value
1596
1597true if pixels were copied
1598
1599### Example
1600
1601<div><fiddle-embed name="dcbd4af9151820f63de45a35f3a8d110"></fiddle-embed></div>
1602
1603### See Also
1604
1605<a href="#SkSurface_peekPixels">peekPixels</a>
1606
1607---
1608
1609<a name="SkSurface_props"></a>
1610## props
1611
1612<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1613const SkSurfaceProps& props() const
1614</pre>
1615
1616Returns <a href="#Properties">Surface Properties</a> for surface.
1617
1618### Return Value
1619
1620LCD striping orientation and setting for device independent fonts
1621
1622### Example
1623
1624<div><fiddle-embed name="13cf9e7b2894ae6e98c1fd719040bf01">
1625
1626#### Example Output
1627
1628~~~~
1629surf.props(): kRGB_H_SkPixelGeometry
1630~~~~
1631
1632</fiddle-embed></div>
1633
1634### See Also
1635
1636<a href="undocumented#SkSurfaceProps">SkSurfaceProps</a>
1637
1638---
1639
1640<a name="SkSurface_prepareForExternalIO"></a>
1641## prepareForExternalIO
1642
1643<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1644void prepareForExternalIO()
1645</pre>
1646
1647To be deprecated.
1648
1649---
1650
1651<a name="SkSurface_flush"></a>
1652## flush
1653
1654<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1655void flush()
1656</pre>
1657
1658Issues pending <a href="#Surface">Surface</a> commands to the GPU-backed API and resolves any <a href="#Surface">Surface</a> MSAA.
1659
1660Skia flushes as needed, so it is not necessary to call this if Skia manages
1661drawing and object lifetime. Call when interleaving Skia calls with native
1662GPU calls.
1663
1664### See Also
1665
1666<a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a>
1667
1668---
1669
1670<a name="SkSurface_flushAndSignalSemaphores"></a>
1671## flushAndSignalSemaphores
1672
1673<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1674GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores,
1675                                               GrBackendSemaphore signalSemaphores[])
1676</pre>
1677
1678Issues pending <a href="#Surface">Surface</a> commands to the GPU-backed API and resolves any <a href="#Surface">Surface</a> MSAA.
1679After issuing all commands, <a href="#SkSurface_flushAndSignalSemaphores_signalSemaphores">signalSemaphores</a> of count <a href="#SkSurface_flushAndSignalSemaphores_numSemaphores">numSemaphores</a> semaphores
1680are signaled by the GPU.
1681
1682For each <a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a> in <a href="#SkSurface_flushAndSignalSemaphores_signalSemaphores">signalSemaphores</a>:
1683if <a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a> is initialized, the GPU back-end uses the semaphore as is;
1684otherwise, a new semaphore is created and initializes <a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a>.
1685
1686The caller must delete the semaphores created and returned in <a href="#SkSurface_flushAndSignalSemaphores_signalSemaphores">signalSemaphores</a>.
1687<a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a> can be deleted as soon as this function returns.
1688
1689If the back-end API is OpenGL only uninitialized <a href="#GrBackendSemaphore">GrBackendSemaphores</a> are supported.
1690
1691If the back-end API is Vulkan semaphores may be initialized or uninitialized.
1692If uninitialized, created semaphores are valid only with the VkDevice
1693with which they were created.
1694
1695If <a href="#kNo">GrSemaphoresSubmitted::kNo</a> is returned, the GPU back-end did not create or
1696add any semaphores to signal on the GPU; the caller should not instruct the GPU
1697to wait on any of the semaphores.
1698
1699Pending surface commands are flushed regardless of the return result.
1700
1701### Parameters
1702
1703<table>  <tr>    <td><a name="SkSurface_flushAndSignalSemaphores_numSemaphores"> <code><strong>numSemaphores </strong></code> </a></td> <td>
1704size of <a href="#SkSurface_flushAndSignalSemaphores_signalSemaphores">signalSemaphores</a> array</td>
1705  </tr>  <tr>    <td><a name="SkSurface_flushAndSignalSemaphores_signalSemaphores"> <code><strong>signalSemaphores </strong></code> </a></td> <td>
1706array of semaphore containers</td>
1707  </tr>
1708</table>
1709
1710### Return Value
1711
1712one of: <a href="#kYes">GrSemaphoresSubmitted::kYes</a>, <a href="#kNo">GrSemaphoresSubmitted::kNo</a>
1713
1714### See Also
1715
1716<a href="#SkSurface_wait">wait</a> <a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a>
1717
1718---
1719
1720<a name="SkSurface_wait"></a>
1721## wait
1722
1723<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1724bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores)
1725</pre>
1726
1727Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
1728executing any more commands on the GPU for this surface. Skia will take ownership of the
1729underlying semaphores and delete them once they have been signaled and waited on.
1730If this call returns false, then the GPU back-end will not wait on any passed in semaphores,
1731and the client will still own the semaphores.
1732
1733### Parameters
1734
1735<table>  <tr>    <td><a name="SkSurface_wait_numSemaphores"> <code><strong>numSemaphores </strong></code> </a></td> <td>
1736size of <a href="#SkSurface_wait_waitSemaphores">waitSemaphores</a> array</td>
1737  </tr>  <tr>    <td><a name="SkSurface_wait_waitSemaphores"> <code><strong>waitSemaphores </strong></code> </a></td> <td>
1738array of semaphore containers</td>
1739  </tr>
1740</table>
1741
1742### Return Value
1743
1744true if GPU is waiting on semaphores
1745
1746### Example
1747
1748<div><fiddle-embed name="c9033080af68efc0f270d748f1c0e011"></fiddle-embed></div>
1749
1750### See Also
1751
1752<a href="#SkSurface_flushAndSignalSemaphores">flushAndSignalSemaphores</a> <a href="undocumented#GrBackendSemaphore">GrBackendSemaphore</a>
1753
1754---
1755
1756<a name="SkSurface_characterize"></a>
1757## characterize
1758
1759<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1760bool characterize(SkSurfaceCharacterization* characterization) const
1761</pre>
1762
1763Initializes <a href="#Characterization">Surface Characterization</a> that can be used to perform GPU back-end
1764pre-processing in a separate thread. Typically this is used to divide drawing
1765into multiple tiles. DeferredDisplayListRecorder records the drawing commands
1766for each tile.
1767
1768Return true if <a href="#Surface">Surface</a> supports <a href="#SkSurface_characterize_characterization">characterization</a>. <a href="undocumented#Raster_Surface">Raster Surface</a> returns false.
1769
1770### Parameters
1771
1772<table>  <tr>    <td><a name="SkSurface_characterize_characterization"> <code><strong>characterization </strong></code> </a></td> <td>
1773properties for parallel drawing</td>
1774  </tr>
1775</table>
1776
1777### Return Value
1778
1779true if supported
1780
1781### Example
1782
1783<div><fiddle-embed name="3df4e2fc63483a3fa19589b5388080bc" gpu="true"></fiddle-embed></div>
1784
1785### See Also
1786
1787<a href="#SkSurface_draw">draw</a><sup><a href="#SkSurface_draw_2">[2]</a></sup> <a href="undocumented#SkSurfaceCharacterization">SkSurfaceCharacterization</a> <a href="undocumented#SkDeferredDisplayList">SkDeferredDisplayList</a>
1788
1789---
1790
1791<a name="SkSurface_draw_2"></a>
1792
1793<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
1794bool draw(SkDeferredDisplayList* deferredDisplayList)
1795</pre>
1796
1797Draws deferred display list created using <a href="undocumented#SkDeferredDisplayListRecorder">SkDeferredDisplayListRecorder</a>.
1798Has no effect and returns false if <a href="#Characterization">Surface Characterization</a> stored in
1799<a href="#SkSurface_draw_2_deferredDisplayList">deferredDisplayList</a> is not compatible with <a href="#Surface">Surface</a>.
1800
1801<a href="undocumented#Raster_Surface">Raster Surface</a> returns false.
1802
1803### Parameters
1804
1805<table>  <tr>    <td><a name="SkSurface_draw_2_deferredDisplayList"> <code><strong>deferredDisplayList </strong></code> </a></td> <td>
1806drawing commands</td>
1807  </tr>
1808</table>
1809
1810### Return Value
1811
1812false if <a href="#SkSurface_draw_2_deferredDisplayList">deferredDisplayList</a> is not compatible
1813
1814### Example
1815
1816<div><fiddle-embed name="3dfa7496268dfb2c7465cda5da39dfbd" gpu="true" cpu="true"></fiddle-embed></div>
1817
1818### See Also
1819
1820<a href="#SkSurface_characterize">characterize</a> <a href="undocumented#SkSurfaceCharacterization">SkSurfaceCharacterization</a> <a href="undocumented#SkDeferredDisplayList">SkDeferredDisplayList</a>
1821
1822---
1823
1824