OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkSurface_DEFINED | 8 #ifndef SkSurface_DEFINED |
9 #define SkSurface_DEFINED | 9 #define SkSurface_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 #include "SkImage.h" | 12 #include "SkImage.h" |
13 #include "SkSurfaceProps.h" | |
13 | 14 |
14 class SkCanvas; | 15 class SkCanvas; |
15 class SkPaint; | 16 class SkPaint; |
16 class GrContext; | 17 class GrContext; |
17 class GrRenderTarget; | 18 class GrRenderTarget; |
18 | 19 |
19 /** | 20 /** |
20 * SkSurface represents the backend/results of drawing to a canvas. For raster | 21 * SkSurface represents the backend/results of drawing to a canvas. For raster |
21 * drawing, the surface will be pixels, but (for example) when drawing into | 22 * drawing, the surface will be pixels, but (for example) when drawing into |
22 * a PDF or Picture canvas, the surface stores the recorded commands. | 23 * a PDF or Picture canvas, the surface stores the recorded commands. |
23 * | 24 * |
24 * To draw into a canvas, first create the appropriate type of Surface, and | 25 * To draw into a canvas, first create the appropriate type of Surface, and |
25 * then request the canvas from the surface. | 26 * then request the canvas from the surface. |
26 */ | 27 */ |
27 class SK_API SkSurface : public SkRefCnt { | 28 class SK_API SkSurface : public SkRefCnt { |
28 public: | 29 public: |
29 SK_DECLARE_INST_COUNT(SkSurface) | 30 SK_DECLARE_INST_COUNT(SkSurface) |
30 | 31 |
32 typedef SkSurfaceProps Props; | |
33 | |
31 /** | 34 /** |
32 * Create a new surface, using the specified pixels/rowbytes as its | 35 * Create a new surface, using the specified pixels/rowbytes as its |
33 * backend. | 36 * backend. |
34 * | 37 * |
35 * If the requested surface cannot be created, or the request is not a | 38 * If the requested surface cannot be created, or the request is not a |
36 * supported configuration, NULL will be returned. | 39 * supported configuration, NULL will be returned. |
37 */ | 40 */ |
38 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r owBytes); | 41 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r owBytes, |
42 const Props* = NULL); | |
39 | 43 |
40 /** | 44 /** |
41 * The same as NewRasterDirect, but also accepts a call-back routine, which is invoked | 45 * The same as NewRasterDirect, but also accepts a call-back routine, which is invoked |
42 * when the surface is deleted, and is passed the pixel memory and the spec ified context. | 46 * when the surface is deleted, and is passed the pixel memory and the spec ified context. |
43 */ | 47 */ |
44 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel s, size_t rowBytes, | 48 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel s, size_t rowBytes, |
45 void (*releaseProc)(void* pixel s, void* context), | 49 void (*releaseProc)(void* pixel s, void* context), |
46 void* context); | 50 void* context, const Props* = N ULL); |
47 | 51 |
48 /** | 52 /** |
49 * Return a new surface, with the memory for the pixels automatically | 53 * Return a new surface, with the memory for the pixels automatically |
50 * allocated. | 54 * allocated. |
51 * | 55 * |
52 * If the requested surface cannot be created, or the request is not a | 56 * If the requested surface cannot be created, or the request is not a |
53 * supported configuration, NULL will be returned. | 57 * supported configuration, NULL will be returned. |
54 */ | 58 */ |
55 static SkSurface* NewRaster(const SkImageInfo&); | 59 static SkSurface* NewRaster(const SkImageInfo&, const Props* = NULL); |
56 | 60 |
57 /** | 61 /** |
58 * Helper version of NewRaster. It creates a SkImageInfo with the | 62 * Helper version of NewRaster. It creates a SkImageInfo with the |
59 * specified width and height, and populates the rest of info to match | 63 * specified width and height, and populates the rest of info to match |
60 * pixels in SkPMColor format. | 64 * pixels in SkPMColor format. |
61 */ | 65 */ |
62 static SkSurface* NewRasterPMColor(int width, int height) { | 66 static SkSurface* NewRasterPMColor(int width, int height, const Props* props = NULL) { |
63 return NewRaster(SkImageInfo::MakeN32Premul(width, height)); | 67 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); |
64 } | 68 } |
65 | 69 |
66 /** | 70 /** |
67 * Text rendering modes that can be passed to NewRenderTarget* | 71 * Text rendering modes that can be passed to NewRenderTarget* |
68 */ | 72 */ |
69 enum TextRenderMode { | 73 enum TextRenderMode { |
70 /** | 74 /** |
71 * This will use the standard text rendering method | 75 * This will use the standard text rendering method |
72 */ | 76 */ |
73 kStandard_TextRenderMode, | 77 kStandard_TextRenderMode, |
(...skipping 20 matching lines...) Expand all Loading... | |
94 RenderTargetFlags flags = kNone_Rend erTargetFlag); | 98 RenderTargetFlags flags = kNone_Rend erTargetFlag); |
95 | 99 |
96 /** | 100 /** |
97 * Return a new surface whose contents will be drawn to an offscreen | 101 * Return a new surface whose contents will be drawn to an offscreen |
98 * render target, allocated by the surface. | 102 * render target, allocated by the surface. |
99 */ | 103 */ |
100 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample Count = 0, | 104 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample Count = 0, |
101 TextRenderMode trm = kStandard_TextRenderM ode, | 105 TextRenderMode trm = kStandard_TextRenderM ode, |
102 RenderTargetFlags flags = kNone_RenderTarg etFlag); | 106 RenderTargetFlags flags = kNone_RenderTarg etFlag); |
103 | 107 |
108 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample Count, | |
bsalomon
2014/09/18 18:43:32
Can we deprecate the above version? What do you th
reed1
2014/09/18 21:03:12
Done.
| |
109 const SkSurfaceProps&, | |
110 RenderTargetFlags flags = kNone_RenderTarg etFlag); | |
111 | |
104 /** | 112 /** |
105 * Return a new surface whose contents will be drawn to an offscreen | 113 * Return a new surface whose contents will be drawn to an offscreen |
106 * render target, allocated by the surface from the scratch texture pool | 114 * render target, allocated by the surface from the scratch texture pool |
107 * managed by the GrContext. The scratch texture pool serves the purpose | 115 * managed by the GrContext. The scratch texture pool serves the purpose |
108 * of retaining textures after they are no longer in use in order to | 116 * of retaining textures after they are no longer in use in order to |
109 * re-use them later without having to re-allocate. Scratch textures | 117 * re-use them later without having to re-allocate. Scratch textures |
110 * should be used in cases where high turnover is expected. This allows, | 118 * should be used in cases where high turnover is expected. This allows, |
111 * for example, the copy on write to recycle a texture from a recently | 119 * for example, the copy on write to recycle a texture from a recently |
112 * released SkImage snapshot of the surface. | 120 * released SkImage snapshot of the surface. |
113 * Note: Scratch textures count against the GrContext's cached resource | 121 * Note: Scratch textures count against the GrContext's cached resource |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 * RAM) return the const-address of those pixels, and if not null, return | 205 * RAM) return the const-address of those pixels, and if not null, return |
198 * the ImageInfo and rowBytes. The returned address is only valid while | 206 * the ImageInfo and rowBytes. The returned address is only valid while |
199 * the surface object is in scope, and no API call is made on the surface | 207 * the surface object is in scope, and no API call is made on the surface |
200 * or its canvas. | 208 * or its canvas. |
201 * | 209 * |
202 * On failure, returns NULL and the info and rowBytes parameters are | 210 * On failure, returns NULL and the info and rowBytes parameters are |
203 * ignored. | 211 * ignored. |
204 */ | 212 */ |
205 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 213 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
206 | 214 |
215 const Props& props() const { return fProps; } | |
216 | |
207 protected: | 217 protected: |
208 SkSurface(int width, int height); | 218 SkSurface(int width, int height, const Props*); |
209 SkSurface(const SkImageInfo&); | 219 SkSurface(const SkImageInfo&, const Props*); |
210 | 220 |
211 // called by subclass if their contents have changed | 221 // called by subclass if their contents have changed |
212 void dirtyGenerationID() { | 222 void dirtyGenerationID() { |
213 fGenerationID = 0; | 223 fGenerationID = 0; |
214 } | 224 } |
215 | 225 |
216 private: | 226 private: |
227 const Props fProps; | |
217 const int fWidth; | 228 const int fWidth; |
218 const int fHeight; | 229 const int fHeight; |
219 uint32_t fGenerationID; | 230 uint32_t fGenerationID; |
220 | 231 |
221 typedef SkRefCnt INHERITED; | 232 typedef SkRefCnt INHERITED; |
222 }; | 233 }; |
223 | 234 |
224 #endif | 235 #endif |
OLD | NEW |