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" |
| 14 |
| 15 //#define SK_SUPPORT_LEGACY_TEXTRENDERMODE |
13 | 16 |
14 class SkCanvas; | 17 class SkCanvas; |
15 class SkPaint; | 18 class SkPaint; |
16 class GrContext; | 19 class GrContext; |
17 class GrRenderTarget; | 20 class GrRenderTarget; |
18 | 21 |
19 /** | 22 /** |
20 * SkSurface represents the backend/results of drawing to a canvas. For raster | 23 * 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 | 24 * drawing, the surface will be pixels, but (for example) when drawing into |
22 * a PDF or Picture canvas, the surface stores the recorded commands. | 25 * a PDF or Picture canvas, the surface stores the recorded commands. |
23 * | 26 * |
24 * To draw into a canvas, first create the appropriate type of Surface, and | 27 * To draw into a canvas, first create the appropriate type of Surface, and |
25 * then request the canvas from the surface. | 28 * then request the canvas from the surface. |
26 */ | 29 */ |
27 class SK_API SkSurface : public SkRefCnt { | 30 class SK_API SkSurface : public SkRefCnt { |
28 public: | 31 public: |
29 SK_DECLARE_INST_COUNT(SkSurface) | 32 SK_DECLARE_INST_COUNT(SkSurface) |
30 | 33 |
| 34 typedef SkSurfaceProps Props; |
| 35 |
31 /** | 36 /** |
32 * Create a new surface, using the specified pixels/rowbytes as its | 37 * Create a new surface, using the specified pixels/rowbytes as its |
33 * backend. | 38 * backend. |
34 * | 39 * |
35 * If the requested surface cannot be created, or the request is not a | 40 * If the requested surface cannot be created, or the request is not a |
36 * supported configuration, NULL will be returned. | 41 * supported configuration, NULL will be returned. |
37 */ | 42 */ |
38 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes); | 43 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes, |
| 44 const Props* = NULL); |
39 | 45 |
40 /** | 46 /** |
41 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked | 47 * 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. | 48 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. |
43 */ | 49 */ |
44 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, | 50 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, |
45 void (*releaseProc)(void* pixel
s, void* context), | 51 void (*releaseProc)(void* pixel
s, void* context), |
46 void* context); | 52 void* context, const Props* = N
ULL); |
47 | 53 |
48 /** | 54 /** |
49 * Return a new surface, with the memory for the pixels automatically | 55 * Return a new surface, with the memory for the pixels automatically |
50 * allocated. | 56 * allocated. |
51 * | 57 * |
52 * If the requested surface cannot be created, or the request is not a | 58 * If the requested surface cannot be created, or the request is not a |
53 * supported configuration, NULL will be returned. | 59 * supported configuration, NULL will be returned. |
54 */ | 60 */ |
55 static SkSurface* NewRaster(const SkImageInfo&); | 61 static SkSurface* NewRaster(const SkImageInfo&, const Props* = NULL); |
56 | 62 |
57 /** | 63 /** |
58 * Helper version of NewRaster. It creates a SkImageInfo with the | 64 * Helper version of NewRaster. It creates a SkImageInfo with the |
59 * specified width and height, and populates the rest of info to match | 65 * specified width and height, and populates the rest of info to match |
60 * pixels in SkPMColor format. | 66 * pixels in SkPMColor format. |
61 */ | 67 */ |
62 static SkSurface* NewRasterPMColor(int width, int height) { | 68 static SkSurface* NewRasterPMColor(int width, int height, const Props* props
= NULL) { |
63 return NewRaster(SkImageInfo::MakeN32Premul(width, height)); | 69 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); |
64 } | 70 } |
65 | 71 |
66 /** | |
67 * Text rendering modes that can be passed to NewRenderTarget* | |
68 */ | |
69 enum TextRenderMode { | |
70 /** | |
71 * This will use the standard text rendering method | |
72 */ | |
73 kStandard_TextRenderMode, | |
74 /** | |
75 * This will use signed distance fields for text rendering when possibl
e | |
76 */ | |
77 kDistanceField_TextRenderMode, | |
78 }; | |
79 | |
80 enum RenderTargetFlags { | 72 enum RenderTargetFlags { |
81 kNone_RenderTargetFlag = 0x0, | 73 kNone_RenderTargetFlag = 0x0, |
82 /* | 74 /* |
83 * By default a RenderTarget-based surface will be cleared on creation. | 75 * By default a RenderTarget-based surface will be cleared on creation. |
84 * Pass in this flag to prevent the clear from happening. | 76 * Pass in this flag to prevent the clear from happening. |
85 */ | 77 */ |
86 kDontClear_RenderTargetFlag = 0x01, | 78 kDontClear_RenderTargetFlag = 0x01, |
87 }; | 79 }; |
88 | 80 |
89 /** | 81 /** |
90 * Return a new surface using the specified render target. | 82 * Return a new surface using the specified render target. |
91 */ | 83 */ |
92 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, | 84 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*, |
93 TextRenderMode trm = kStandard_TextR
enderMode, | |
94 RenderTargetFlags flags = kNone_Rend
erTargetFlag); | 85 RenderTargetFlags flags = kNone_Rend
erTargetFlag); |
95 | 86 |
| 87 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { |
| 88 return NewRenderTargetDirect(target, NULL, kNone_RenderTargetFlag); |
| 89 } |
| 90 |
96 /** | 91 /** |
97 * Return a new surface whose contents will be drawn to an offscreen | 92 * Return a new surface whose contents will be drawn to an offscreen |
98 * render target, allocated by the surface. | 93 * render target, allocated by the surface. |
99 */ | 94 */ |
100 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count = 0, | 95 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, |
101 TextRenderMode trm = kStandard_TextRenderM
ode, | 96 const SkSurfaceProps*, |
102 RenderTargetFlags flags = kNone_RenderTarg
etFlag); | 97 RenderTargetFlags flags = kNone_RenderTarg
etFlag); |
103 | 98 |
| 99 static SkSurface* NewRenderTarget(GrContext* gr, const SkImageInfo& info) { |
| 100 return NewRenderTarget(gr, info, 0, NULL); |
| 101 } |
| 102 |
| 103 |
104 /** | 104 /** |
105 * Return a new surface whose contents will be drawn to an offscreen | 105 * Return a new surface whose contents will be drawn to an offscreen |
106 * render target, allocated by the surface from the scratch texture pool | 106 * render target, allocated by the surface from the scratch texture pool |
107 * managed by the GrContext. The scratch texture pool serves the purpose | 107 * 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 | 108 * 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 | 109 * re-use them later without having to re-allocate. Scratch textures |
110 * should be used in cases where high turnover is expected. This allows, | 110 * 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 | 111 * for example, the copy on write to recycle a texture from a recently |
112 * released SkImage snapshot of the surface. | 112 * released SkImage snapshot of the surface. |
113 * Note: Scratch textures count against the GrContext's cached resource | 113 * Note: Scratch textures count against the GrContext's cached resource |
114 * budget. | 114 * budget. |
115 */ | 115 */ |
| 116 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, |
| 117 const SkSurfaceProps*, |
| 118 RenderTargetFlags flags = kNone_Ren
derTargetFlag); |
| 119 |
| 120 static SkSurface* NewScratchRenderTarget(GrContext* gr, const SkImageInfo& i
nfo) { |
| 121 return NewScratchRenderTarget(gr, info, 0, NULL); |
| 122 } |
| 123 |
| 124 #ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE |
| 125 /** |
| 126 * Text rendering modes that can be passed to NewRenderTarget* |
| 127 */ |
| 128 enum TextRenderMode { |
| 129 /** |
| 130 * This will use the standard text rendering method |
| 131 */ |
| 132 kStandard_TextRenderMode, |
| 133 /** |
| 134 * This will use signed distance fields for text rendering when possibl
e |
| 135 */ |
| 136 kDistanceField_TextRenderMode, |
| 137 }; |
| 138 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, |
| 139 TextRenderMode trm = kStandard_TextR
enderMode, |
| 140 RenderTargetFlags flags = kNone_Rend
erTargetFlag); |
| 141 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count = 0, |
| 142 TextRenderMode trm = kStandard_TextRenderM
ode, |
| 143 RenderTargetFlags flags = kNone_RenderTarg
etFlag); |
116 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount = 0, | 144 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount = 0, |
117 TextRenderMode trm = kStandard_Text
RenderMode, | 145 TextRenderMode trm = kStandard_Text
RenderMode, |
118 RenderTargetFlags flags = kNone_Ren
derTargetFlag); | 146 RenderTargetFlags flags = kNone_Ren
derTargetFlag); |
| 147 #endif |
119 | 148 |
120 int width() const { return fWidth; } | 149 int width() const { return fWidth; } |
121 int height() const { return fHeight; } | 150 int height() const { return fHeight; } |
122 | 151 |
123 /** | 152 /** |
124 * Returns a unique non-zero, unique value identifying the content of this | 153 * Returns a unique non-zero, unique value identifying the content of this |
125 * surface. Each time the content is changed changed, either by drawing | 154 * surface. Each time the content is changed changed, either by drawing |
126 * into this surface, or explicitly calling notifyContentChanged()) this | 155 * into this surface, or explicitly calling notifyContentChanged()) this |
127 * method will return a new value. | 156 * method will return a new value. |
128 * | 157 * |
(...skipping 68 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 | 226 * 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 | 227 * 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 | 228 * the surface object is in scope, and no API call is made on the surface |
200 * or its canvas. | 229 * or its canvas. |
201 * | 230 * |
202 * On failure, returns NULL and the info and rowBytes parameters are | 231 * On failure, returns NULL and the info and rowBytes parameters are |
203 * ignored. | 232 * ignored. |
204 */ | 233 */ |
205 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 234 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
206 | 235 |
| 236 const Props& props() const { return fProps; } |
| 237 |
207 protected: | 238 protected: |
208 SkSurface(int width, int height); | 239 SkSurface(int width, int height, const Props*); |
209 SkSurface(const SkImageInfo&); | 240 SkSurface(const SkImageInfo&, const Props*); |
210 | 241 |
211 // called by subclass if their contents have changed | 242 // called by subclass if their contents have changed |
212 void dirtyGenerationID() { | 243 void dirtyGenerationID() { |
213 fGenerationID = 0; | 244 fGenerationID = 0; |
214 } | 245 } |
215 | 246 |
216 private: | 247 private: |
| 248 const Props fProps; |
217 const int fWidth; | 249 const int fWidth; |
218 const int fHeight; | 250 const int fHeight; |
219 uint32_t fGenerationID; | 251 uint32_t fGenerationID; |
220 | 252 |
221 typedef SkRefCnt INHERITED; | 253 typedef SkRefCnt INHERITED; |
222 }; | 254 }; |
223 | 255 |
224 #endif | 256 #endif |
OLD | NEW |