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 |
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 SkSurfaceProps* = 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 SkSurfaceP
rops* = NULL); |
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 SkSurfaceProps* = 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 SkSurfacePro
ps* 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 * Return a new surface using the specified render target. |
68 */ | 72 */ |
69 enum TextRenderMode { | 73 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*); |
70 /** | 74 |
71 * This will use the standard text rendering method | 75 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { |
72 */ | 76 return NewRenderTargetDirect(target, NULL); |
73 kStandard_TextRenderMode, | 77 } |
74 /** | 78 |
75 * This will use signed distance fields for text rendering when possibl
e | |
76 */ | |
77 kDistanceField_TextRenderMode, | |
78 }; | |
79 | |
80 /** | |
81 * Return a new surface using the specified render target. | |
82 * The pixels in the rendertarget are not cleared or otherwised changed whe
n the surface | |
83 * is created. | |
84 */ | |
85 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, | |
86 TextRenderMode trm = kStandard_TextR
enderMode); | |
87 | |
88 /** | 79 /** |
89 * Return a new surface whose contents will be drawn to an offscreen | 80 * Return a new surface whose contents will be drawn to an offscreen |
90 * render target, allocated by the surface. | 81 * render target, allocated by the surface. |
91 */ | 82 */ |
92 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count = 0, | 83 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, |
93 TextRenderMode trm = kStandard_TextRenderM
ode); | 84 const SkSurfaceProps* = NULL); |
| 85 |
| 86 static SkSurface* NewRenderTarget(GrContext* gr, const SkImageInfo& info) { |
| 87 return NewRenderTarget(gr, info, 0, NULL); |
| 88 } |
94 | 89 |
95 /** | 90 /** |
96 * Return a new surface whose contents will be drawn to an offscreen | 91 * Return a new surface whose contents will be drawn to an offscreen |
97 * render target, allocated by the surface from the scratch texture pool | 92 * render target, allocated by the surface from the scratch texture pool |
98 * managed by the GrContext. The scratch texture pool serves the purpose | 93 * managed by the GrContext. The scratch texture pool serves the purpose |
99 * of retaining textures after they are no longer in use in order to | 94 * of retaining textures after they are no longer in use in order to |
100 * re-use them later without having to re-allocate. Scratch textures | 95 * re-use them later without having to re-allocate. Scratch textures |
101 * should be used in cases where high turnover is expected. This allows, | 96 * should be used in cases where high turnover is expected. This allows, |
102 * for example, the copy on write to recycle a texture from a recently | 97 * for example, the copy on write to recycle a texture from a recently |
103 * released SkImage snapshot of the surface. | 98 * released SkImage snapshot of the surface. |
104 * Note: Scratch textures count against the GrContext's cached resource | 99 * Note: Scratch textures count against the GrContext's cached resource |
105 * budget. | 100 * budget. |
106 */ | 101 */ |
107 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount = 0, | 102 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, |
108 TextRenderMode trm = kStandard_Text
RenderMode); | 103 const SkSurfaceProps*); |
| 104 |
| 105 static SkSurface* NewScratchRenderTarget(GrContext* gr, const SkImageInfo& i
nfo) { |
| 106 return NewScratchRenderTarget(gr, info, 0, NULL); |
| 107 } |
| 108 |
| 109 #ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE |
| 110 /** |
| 111 * Text rendering modes that can be passed to NewRenderTarget* |
| 112 */ |
| 113 enum TextRenderMode { |
| 114 /** |
| 115 * This will use the standard text rendering method |
| 116 */ |
| 117 kStandard_TextRenderMode, |
| 118 /** |
| 119 * This will use signed distance fields for text rendering when possibl
e |
| 120 */ |
| 121 kDistanceField_TextRenderMode, |
| 122 }; |
| 123 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, TextRenderMode); |
| 124 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, |
| 125 TextRenderMode); |
| 126 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, |
| 127 TextRenderMode); |
| 128 #endif |
109 | 129 |
110 int width() const { return fWidth; } | 130 int width() const { return fWidth; } |
111 int height() const { return fHeight; } | 131 int height() const { return fHeight; } |
112 | 132 |
113 /** | 133 /** |
114 * Returns a unique non-zero, unique value identifying the content of this | 134 * Returns a unique non-zero, unique value identifying the content of this |
115 * surface. Each time the content is changed changed, either by drawing | 135 * surface. Each time the content is changed changed, either by drawing |
116 * into this surface, or explicitly calling notifyContentChanged()) this | 136 * into this surface, or explicitly calling notifyContentChanged()) this |
117 * method will return a new value. | 137 * method will return a new value. |
118 * | 138 * |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 * RAM) return the const-address of those pixels, and if not null, return | 207 * RAM) return the const-address of those pixels, and if not null, return |
188 * the ImageInfo and rowBytes. The returned address is only valid while | 208 * the ImageInfo and rowBytes. The returned address is only valid while |
189 * the surface object is in scope, and no API call is made on the surface | 209 * the surface object is in scope, and no API call is made on the surface |
190 * or its canvas. | 210 * or its canvas. |
191 * | 211 * |
192 * On failure, returns NULL and the info and rowBytes parameters are | 212 * On failure, returns NULL and the info and rowBytes parameters are |
193 * ignored. | 213 * ignored. |
194 */ | 214 */ |
195 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 215 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
196 | 216 |
| 217 const SkSurfaceProps& props() const { return fProps; } |
| 218 |
197 protected: | 219 protected: |
198 SkSurface(int width, int height); | 220 SkSurface(int width, int height, const SkSurfaceProps*); |
199 SkSurface(const SkImageInfo&); | 221 SkSurface(const SkImageInfo&, const SkSurfaceProps*); |
200 | 222 |
201 // called by subclass if their contents have changed | 223 // called by subclass if their contents have changed |
202 void dirtyGenerationID() { | 224 void dirtyGenerationID() { |
203 fGenerationID = 0; | 225 fGenerationID = 0; |
204 } | 226 } |
205 | 227 |
206 private: | 228 private: |
207 const int fWidth; | 229 const SkSurfaceProps fProps; |
208 const int fHeight; | 230 const int fWidth; |
209 uint32_t fGenerationID; | 231 const int fHeight; |
| 232 uint32_t fGenerationID; |
210 | 233 |
211 typedef SkRefCnt INHERITED; | 234 typedef SkRefCnt INHERITED; |
212 }; | 235 }; |
213 | 236 |
214 #endif | 237 #endif |
OLD | NEW |