| 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 | |
| 16 | 13 |
| 17 class SkCanvas; | 14 class SkCanvas; |
| 18 class SkPaint; | 15 class SkPaint; |
| 19 class GrContext; | 16 class GrContext; |
| 20 class GrRenderTarget; | 17 class GrRenderTarget; |
| 21 | 18 |
| 22 /** | 19 /** |
| 23 * SkSurface represents the backend/results of drawing to a canvas. For raster | 20 * SkSurface represents the backend/results of drawing to a canvas. For raster |
| 24 * drawing, the surface will be pixels, but (for example) when drawing into | 21 * drawing, the surface will be pixels, but (for example) when drawing into |
| 25 * a PDF or Picture canvas, the surface stores the recorded commands. | 22 * a PDF or Picture canvas, the surface stores the recorded commands. |
| 26 * | 23 * |
| 27 * To draw into a canvas, first create the appropriate type of Surface, and | 24 * To draw into a canvas, first create the appropriate type of Surface, and |
| 28 * then request the canvas from the surface. | 25 * then request the canvas from the surface. |
| 29 */ | 26 */ |
| 30 class SK_API SkSurface : public SkRefCnt { | 27 class SK_API SkSurface : public SkRefCnt { |
| 31 public: | 28 public: |
| 32 SK_DECLARE_INST_COUNT(SkSurface) | 29 SK_DECLARE_INST_COUNT(SkSurface) |
| 33 | 30 |
| 34 /** | 31 /** |
| 35 * Create a new surface, using the specified pixels/rowbytes as its | 32 * Create a new surface, using the specified pixels/rowbytes as its |
| 36 * backend. | 33 * backend. |
| 37 * | 34 * |
| 38 * If the requested surface cannot be created, or the request is not a | 35 * If the requested surface cannot be created, or the request is not a |
| 39 * supported configuration, NULL will be returned. | 36 * supported configuration, NULL will be returned. |
| 40 */ | 37 */ |
| 41 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes, | 38 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes); |
| 42 const SkSurfaceProps* = NULL); | |
| 43 | 39 |
| 44 /** | 40 /** |
| 45 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked | 41 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked |
| 46 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. | 42 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. |
| 47 */ | 43 */ |
| 48 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, | 44 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, |
| 49 void (*releaseProc)(void* pixel
s, void* context), | 45 void (*releaseProc)(void* pixel
s, void* context), |
| 50 void* context, const SkSurfaceP
rops* = NULL); | 46 void* context); |
| 51 | 47 |
| 52 /** | 48 /** |
| 53 * Return a new surface, with the memory for the pixels automatically | 49 * Return a new surface, with the memory for the pixels automatically |
| 54 * allocated. | 50 * allocated. |
| 55 * | 51 * |
| 56 * If the requested surface cannot be created, or the request is not a | 52 * If the requested surface cannot be created, or the request is not a |
| 57 * supported configuration, NULL will be returned. | 53 * supported configuration, NULL will be returned. |
| 58 */ | 54 */ |
| 59 static SkSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = NULL
); | 55 static SkSurface* NewRaster(const SkImageInfo&); |
| 60 | 56 |
| 61 /** | 57 /** |
| 62 * Helper version of NewRaster. It creates a SkImageInfo with the | 58 * Helper version of NewRaster. It creates a SkImageInfo with the |
| 63 * specified width and height, and populates the rest of info to match | 59 * specified width and height, and populates the rest of info to match |
| 64 * pixels in SkPMColor format. | 60 * pixels in SkPMColor format. |
| 65 */ | 61 */ |
| 66 static SkSurface* NewRasterPMColor(int width, int height, const SkSurfacePro
ps* props = NULL) { | 62 static SkSurface* NewRasterPMColor(int width, int height) { |
| 67 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); | 63 return NewRaster(SkImageInfo::MakeN32Premul(width, height)); |
| 68 } | 64 } |
| 69 | 65 |
| 70 /** | 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 /** |
| 71 * Return a new surface using the specified render target. | 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. |
| 72 */ | 84 */ |
| 73 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*); | 85 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, |
| 74 | 86 TextRenderMode trm = kStandard_TextR
enderMode); |
| 75 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { | 87 |
| 76 return NewRenderTargetDirect(target, NULL); | |
| 77 } | |
| 78 | |
| 79 /** | 88 /** |
| 80 * 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 |
| 81 * render target, allocated by the surface. | 90 * render target, allocated by the surface. |
| 82 */ | 91 */ |
| 83 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count, | 92 static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sample
Count = 0, |
| 84 const SkSurfaceProps* = NULL); | 93 TextRenderMode trm = kStandard_TextRenderM
ode); |
| 85 | |
| 86 static SkSurface* NewRenderTarget(GrContext* gr, const SkImageInfo& info) { | |
| 87 return NewRenderTarget(gr, info, 0, NULL); | |
| 88 } | |
| 89 | 94 |
| 90 /** | 95 /** |
| 91 * Return a new surface whose contents will be drawn to an offscreen | 96 * Return a new surface whose contents will be drawn to an offscreen |
| 92 * render target, allocated by the surface from the scratch texture pool | 97 * render target, allocated by the surface from the scratch texture pool |
| 93 * managed by the GrContext. The scratch texture pool serves the purpose | 98 * managed by the GrContext. The scratch texture pool serves the purpose |
| 94 * of retaining textures after they are no longer in use in order to | 99 * of retaining textures after they are no longer in use in order to |
| 95 * re-use them later without having to re-allocate. Scratch textures | 100 * re-use them later without having to re-allocate. Scratch textures |
| 96 * should be used in cases where high turnover is expected. This allows, | 101 * should be used in cases where high turnover is expected. This allows, |
| 97 * for example, the copy on write to recycle a texture from a recently | 102 * for example, the copy on write to recycle a texture from a recently |
| 98 * released SkImage snapshot of the surface. | 103 * released SkImage snapshot of the surface. |
| 99 * Note: Scratch textures count against the GrContext's cached resource | 104 * Note: Scratch textures count against the GrContext's cached resource |
| 100 * budget. | 105 * budget. |
| 101 */ | 106 */ |
| 102 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount, | 107 static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int
sampleCount = 0, |
| 103 const SkSurfaceProps*); | 108 TextRenderMode trm = kStandard_Text
RenderMode); |
| 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 | |
| 129 | 109 |
| 130 int width() const { return fWidth; } | 110 int width() const { return fWidth; } |
| 131 int height() const { return fHeight; } | 111 int height() const { return fHeight; } |
| 132 | 112 |
| 133 /** | 113 /** |
| 134 * Returns a unique non-zero, unique value identifying the content of this | 114 * Returns a unique non-zero, unique value identifying the content of this |
| 135 * surface. Each time the content is changed changed, either by drawing | 115 * surface. Each time the content is changed changed, either by drawing |
| 136 * into this surface, or explicitly calling notifyContentChanged()) this | 116 * into this surface, or explicitly calling notifyContentChanged()) this |
| 137 * method will return a new value. | 117 * method will return a new value. |
| 138 * | 118 * |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 * RAM) return the const-address of those pixels, and if not null, return | 187 * RAM) return the const-address of those pixels, and if not null, return |
| 208 * the ImageInfo and rowBytes. The returned address is only valid while | 188 * the ImageInfo and rowBytes. The returned address is only valid while |
| 209 * the surface object is in scope, and no API call is made on the surface | 189 * the surface object is in scope, and no API call is made on the surface |
| 210 * or its canvas. | 190 * or its canvas. |
| 211 * | 191 * |
| 212 * On failure, returns NULL and the info and rowBytes parameters are | 192 * On failure, returns NULL and the info and rowBytes parameters are |
| 213 * ignored. | 193 * ignored. |
| 214 */ | 194 */ |
| 215 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); | 195 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
| 216 | 196 |
| 217 const SkSurfaceProps& props() const { return fProps; } | |
| 218 | |
| 219 protected: | 197 protected: |
| 220 SkSurface(int width, int height, const SkSurfaceProps*); | 198 SkSurface(int width, int height); |
| 221 SkSurface(const SkImageInfo&, const SkSurfaceProps*); | 199 SkSurface(const SkImageInfo&); |
| 222 | 200 |
| 223 // called by subclass if their contents have changed | 201 // called by subclass if their contents have changed |
| 224 void dirtyGenerationID() { | 202 void dirtyGenerationID() { |
| 225 fGenerationID = 0; | 203 fGenerationID = 0; |
| 226 } | 204 } |
| 227 | 205 |
| 228 private: | 206 private: |
| 229 const SkSurfaceProps fProps; | 207 const int fWidth; |
| 230 const int fWidth; | 208 const int fHeight; |
| 231 const int fHeight; | 209 uint32_t fGenerationID; |
| 232 uint32_t fGenerationID; | |
| 233 | 210 |
| 234 typedef SkRefCnt INHERITED; | 211 typedef SkRefCnt INHERITED; |
| 235 }; | 212 }; |
| 236 | 213 |
| 237 #endif | 214 #endif |
| OLD | NEW |