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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 * If the surface has direct access to its pixels (i.e. they are in local | 200 * If the surface has direct access to its pixels (i.e. they are in local |
197 * RAM) return the const-address of those pixels, and if not null, return | 201 * 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 | 202 * 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 | 203 * the surface object is in scope, and no API call is made on the surface |
200 * or its canvas. | 204 * or its canvas. |
201 * | 205 * |
202 * On failure, returns NULL and the info and rowBytes parameters are | 206 * On failure, returns NULL and the info and rowBytes parameters are |
203 * ignored. | 207 * ignored. |
204 */ | 208 */ |
205 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 209 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
206 | 210 |
robertphillips
2014/09/16 14:15:17
Why not "const Props&" ?
reed1
2014/09/16 18:16:01
Done.
| |
211 Props props() const { return fProps; } | |
212 | |
207 protected: | 213 protected: |
208 SkSurface(int width, int height); | 214 SkSurface(int width, int height, const Props&); |
209 SkSurface(const SkImageInfo&); | 215 SkSurface(const SkImageInfo&, const Props&); |
210 | 216 |
211 // called by subclass if their contents have changed | 217 // called by subclass if their contents have changed |
212 void dirtyGenerationID() { | 218 void dirtyGenerationID() { |
213 fGenerationID = 0; | 219 fGenerationID = 0; |
214 } | 220 } |
215 | 221 |
216 private: | 222 private: |
223 const Props fProps; | |
217 const int fWidth; | 224 const int fWidth; |
218 const int fHeight; | 225 const int fHeight; |
219 uint32_t fGenerationID; | 226 uint32_t fGenerationID; |
220 | 227 |
221 typedef SkRefCnt INHERITED; | 228 typedef SkRefCnt INHERITED; |
222 }; | 229 }; |
223 | 230 |
224 #endif | 231 #endif |
OLD | NEW |