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 |
31 /** | 32 /** |
32 * Create a new surface, using the specified pixels/rowbytes as its | 33 * Create a new surface, using the specified pixels/rowbytes as its |
33 * backend. | 34 * backend. |
34 * | 35 * |
35 * If the requested surface cannot be created, or the request is not a | 36 * If the requested surface cannot be created, or the request is not a |
36 * supported configuration, NULL will be returned. | 37 * supported configuration, NULL will be returned. |
37 */ | 38 */ |
38 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes); | 39 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes, |
| 40 const SkSurfaceProps* = NULL); |
39 | 41 |
40 /** | 42 /** |
41 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked | 43 * 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. | 44 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. |
43 */ | 45 */ |
44 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, | 46 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, |
45 void (*releaseProc)(void* pixel
s, void* context), | 47 void (*releaseProc)(void* pixel
s, void* context), |
46 void* context); | 48 void* context, const SkSurfaceP
rops* = NULL); |
47 | 49 |
48 /** | 50 /** |
49 * Return a new surface, with the memory for the pixels automatically | 51 * Return a new surface, with the memory for the pixels automatically |
50 * allocated. | 52 * allocated. |
51 * | 53 * |
52 * If the requested surface cannot be created, or the request is not a | 54 * If the requested surface cannot be created, or the request is not a |
53 * supported configuration, NULL will be returned. | 55 * supported configuration, NULL will be returned. |
54 */ | 56 */ |
55 static SkSurface* NewRaster(const SkImageInfo&); | 57 static SkSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = NULL
); |
56 | 58 |
57 /** | 59 /** |
58 * Helper version of NewRaster. It creates a SkImageInfo with the | 60 * Helper version of NewRaster. It creates a SkImageInfo with the |
59 * specified width and height, and populates the rest of info to match | 61 * specified width and height, and populates the rest of info to match |
60 * pixels in SkPMColor format. | 62 * pixels in SkPMColor format. |
61 */ | 63 */ |
62 static SkSurface* NewRasterPMColor(int width, int height) { | 64 static SkSurface* NewRasterPMColor(int width, int height, const SkSurfacePro
ps* props = NULL) { |
63 return NewRaster(SkImageInfo::MakeN32Premul(width, height)); | 65 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); |
64 } | 66 } |
65 | 67 |
66 /** | 68 /** |
67 * Text rendering modes that can be passed to NewRenderTarget* | 69 * Return a new surface using the specified render target. |
68 */ | 70 */ |
69 enum TextRenderMode { | 71 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*); |
70 /** | 72 |
71 * This will use the standard text rendering method | 73 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { |
72 */ | 74 return NewRenderTargetDirect(target, NULL); |
73 kStandard_TextRenderMode, | 75 } |
74 /** | 76 |
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 /** | 77 /** |
89 * Return a new surface whose contents will be drawn to an offscreen | 78 * Return a new surface whose contents will be drawn to an offscreen |
90 * render target, allocated by the surface. | 79 * render target, allocated by the surface. |
91 */ | 80 */ |
92 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count = 0, | 81 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, |
93 TextRenderMode trm = kStandard_TextRenderM
ode); | 82 const SkSurfaceProps* = NULL); |
| 83 |
| 84 static SkSurface* NewRenderTarget(GrContext* gr, const SkImageInfo& info) { |
| 85 return NewRenderTarget(gr, info, 0, NULL); |
| 86 } |
94 | 87 |
95 /** | 88 /** |
96 * Return a new surface whose contents will be drawn to an offscreen | 89 * Return a new surface whose contents will be drawn to an offscreen |
97 * render target, allocated by the surface from the scratch texture pool | 90 * render target, allocated by the surface from the scratch texture pool |
98 * managed by the GrContext. The scratch texture pool serves the purpose | 91 * 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 | 92 * 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 | 93 * re-use them later without having to re-allocate. Scratch textures |
101 * should be used in cases where high turnover is expected. This allows, | 94 * 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 | 95 * for example, the copy on write to recycle a texture from a recently |
103 * released SkImage snapshot of the surface. | 96 * released SkImage snapshot of the surface. |
104 * Note: Scratch textures count against the GrContext's cached resource | 97 * Note: Scratch textures count against the GrContext's cached resource |
105 * budget. | 98 * budget. |
106 */ | 99 */ |
107 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount = 0, | 100 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, |
108 TextRenderMode trm = kStandard_Text
RenderMode); | 101 const SkSurfaceProps* = NULL); |
| 102 |
| 103 static SkSurface* NewScratchRenderTarget(GrContext* gr, const SkImageInfo& i
nfo) { |
| 104 return NewScratchRenderTarget(gr, info, 0, NULL); |
| 105 } |
| 106 |
| 107 #ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE |
| 108 /** |
| 109 * Text rendering modes that can be passed to NewRenderTarget* |
| 110 */ |
| 111 enum TextRenderMode { |
| 112 /** |
| 113 * This will use the standard text rendering method |
| 114 */ |
| 115 kStandard_TextRenderMode, |
| 116 /** |
| 117 * This will use signed distance fields for text rendering when possibl
e |
| 118 */ |
| 119 kDistanceField_TextRenderMode, |
| 120 }; |
| 121 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, TextRenderMode); |
| 122 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, |
| 123 TextRenderMode); |
| 124 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, |
| 125 TextRenderMode); |
| 126 #endif |
109 | 127 |
110 int width() const { return fWidth; } | 128 int width() const { return fWidth; } |
111 int height() const { return fHeight; } | 129 int height() const { return fHeight; } |
112 | 130 |
113 /** | 131 /** |
114 * Returns a unique non-zero, unique value identifying the content of this | 132 * Returns a unique non-zero, unique value identifying the content of this |
115 * surface. Each time the content is changed changed, either by drawing | 133 * surface. Each time the content is changed changed, either by drawing |
116 * into this surface, or explicitly calling notifyContentChanged()) this | 134 * into this surface, or explicitly calling notifyContentChanged()) this |
117 * method will return a new value. | 135 * method will return a new value. |
118 * | 136 * |
(...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 | 205 * 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 | 206 * 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 | 207 * the surface object is in scope, and no API call is made on the surface |
190 * or its canvas. | 208 * or its canvas. |
191 * | 209 * |
192 * On failure, returns NULL and the info and rowBytes parameters are | 210 * On failure, returns NULL and the info and rowBytes parameters are |
193 * ignored. | 211 * ignored. |
194 */ | 212 */ |
195 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 213 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
196 | 214 |
| 215 const SkSurfaceProps& props() const { return fProps; } |
| 216 |
197 protected: | 217 protected: |
198 SkSurface(int width, int height); | 218 SkSurface(int width, int height, const SkSurfaceProps*); |
199 SkSurface(const SkImageInfo&); | 219 SkSurface(const SkImageInfo&, const SkSurfaceProps*); |
200 | 220 |
201 // called by subclass if their contents have changed | 221 // called by subclass if their contents have changed |
202 void dirtyGenerationID() { | 222 void dirtyGenerationID() { |
203 fGenerationID = 0; | 223 fGenerationID = 0; |
204 } | 224 } |
205 | 225 |
206 private: | 226 private: |
207 const int fWidth; | 227 const SkSurfaceProps fProps; |
208 const int fHeight; | 228 const int fWidth; |
209 uint32_t fGenerationID; | 229 const int fHeight; |
| 230 uint32_t fGenerationID; |
210 | 231 |
211 typedef SkRefCnt INHERITED; | 232 typedef SkRefCnt INHERITED; |
212 }; | 233 }; |
213 | 234 |
214 #endif | 235 #endif |
OLD | NEW |