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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 */ | 30 */ |
31 class SK_API SkSurface : public SkRefCnt { | 31 class SK_API SkSurface : public SkRefCnt { |
32 public: | 32 public: |
33 /** | 33 /** |
34 * Create a new surface, using the specified pixels/rowbytes as its | 34 * Create a new surface, using the specified pixels/rowbytes as its |
35 * backend. | 35 * backend. |
36 * | 36 * |
37 * If the requested surface cannot be created, or the request is not a | 37 * If the requested surface cannot be created, or the request is not a |
38 * supported configuration, NULL will be returned. | 38 * supported configuration, NULL will be returned. |
39 */ | 39 */ |
40 static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t r
owBytes, | 40 static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo&, void* pixels, s
ize_t rowBytes, |
41 const SkSurfaceProps* = NULL); | 41 const SkSurfaceProps* = nullptr); |
42 | 42 |
43 /** | 43 /** |
44 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked | 44 * The same as NewRasterDirect, but also accepts a call-back routine, which
is invoked |
45 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. | 45 * when the surface is deleted, and is passed the pixel memory and the spec
ified context. |
46 */ | 46 */ |
47 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixel
s, size_t rowBytes, | 47 static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo&, void
* pixels, size_t rowBytes, |
48 void (*releaseProc)(void* pixel
s, void* context), | 48 void (*releaseProc)(void* pixel
s, void* context), |
49 void* context, const SkSurfaceP
rops* = NULL); | 49 void* context, const SkSurfaceP
rops* = nullptr); |
50 | 50 |
51 /** | 51 /** |
52 * Return a new surface, with the memory for the pixels automatically alloc
ated, but respecting | 52 * Return a new surface, with the memory for the pixels automatically alloc
ated, but respecting |
53 * the specified rowBytes. If rowBytes==0, then a default value will be cho
sen. If a non-zero | 53 * the specified rowBytes. If rowBytes==0, then a default value will be cho
sen. If a non-zero |
54 * rowBytes is specified, then any images snapped off of this surface (via
newImageSnapshot()) | 54 * rowBytes is specified, then any images snapped off of this surface (via
newImageSnapshot()) |
55 * are guaranteed to have the same rowBytes. | 55 * are guaranteed to have the same rowBytes. |
56 * | 56 * |
57 * If the requested surface cannot be created, or the request is not a | 57 * If the requested surface cannot be created, or the request is not a |
58 * supported configuration, NULL will be returned. | 58 * supported configuration, NULL will be returned. |
59 */ | 59 */ |
60 static SkSurface* NewRaster(const SkImageInfo&, size_t rowBytes, const SkSur
faceProps*); | 60 static sk_sp<SkSurface> MakeRaster(const SkImageInfo&, size_t rowBytes, cons
t SkSurfaceProps*); |
61 | 61 |
62 /** | 62 /** |
63 * Allocate a new surface, automatically computing the rowBytes. | 63 * Allocate a new surface, automatically computing the rowBytes. |
64 */ | 64 */ |
65 static SkSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = NULL
); | 65 static sk_sp<SkSurface> MakeRaster(const SkImageInfo&, const SkSurfaceProps*
= nullptr); |
66 | 66 |
67 /** | 67 /** |
68 * Helper version of NewRaster. It creates a SkImageInfo with the | 68 * Helper version of NewRaster. It creates a SkImageInfo with the |
69 * specified width and height, and populates the rest of info to match | 69 * specified width and height, and populates the rest of info to match |
70 * pixels in SkPMColor format. | 70 * pixels in SkPMColor format. |
71 */ | 71 */ |
72 static SkSurface* NewRasterN32Premul(int width, int height, const SkSurfaceP
rops* props = NULL) { | 72 static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height, |
73 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); | 73 const SkSurfaceProps* props = nu
llptr) { |
| 74 return MakeRaster(SkImageInfo::MakeN32Premul(width, height), props); |
74 } | 75 } |
75 | 76 |
76 /** | 77 /** |
77 * Return a new surface using the specified render target. | 78 * Return a new surface using the specified render target. |
78 */ | 79 */ |
79 static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProp
s*); | 80 static sk_sp<SkSurface> MakeRenderTargetDirect(GrRenderTarget*, |
80 | 81 const SkSurfaceProps* = nullp
tr); |
81 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { | |
82 return NewRenderTargetDirect(target, NULL); | |
83 } | |
84 | 82 |
85 /** | 83 /** |
86 * Used to wrap a pre-existing backend 3D API texture as a SkSurface. The k
RenderTarget flag | 84 * Used to wrap a pre-existing backend 3D API texture as a SkSurface. The k
RenderTarget flag |
87 * must be set on GrBackendTextureDesc for this to succeed. Skia will not a
ssume ownership | 85 * must be set on GrBackendTextureDesc for this to succeed. Skia will not a
ssume ownership |
88 * of the texture and the client must ensure the texture is valid for the l
ifetime of the | 86 * of the texture and the client must ensure the texture is valid for the l
ifetime of the |
89 * SkSurface. | 87 * SkSurface. |
90 */ | 88 */ |
91 static SkSurface* NewFromBackendTexture(GrContext*, const GrBackendTextureDe
sc&, | 89 static sk_sp<SkSurface> MakeFromBackendTexture(GrContext*, const GrBackendTe
xtureDesc&, |
92 const SkSurfaceProps*); | 90 const SkSurfaceProps*); |
93 // Legacy alias | |
94 static SkSurface* NewWrappedRenderTarget(GrContext* ctx, const GrBackendText
ureDesc& desc, | |
95 const SkSurfaceProps* props) { | |
96 return NewFromBackendTexture(ctx, desc, props); | |
97 } | |
98 | 91 |
99 /** | 92 /** |
100 * Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia
will not assume | 93 * Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia
will not assume |
101 * ownership of the render target and the client must ensure the render tar
get is valid for the | 94 * ownership of the render target and the client must ensure the render tar
get is valid for the |
102 * lifetime of the SkSurface. | 95 * lifetime of the SkSurface. |
103 */ | 96 */ |
104 static SkSurface* NewFromBackendRenderTarget(GrContext*, const GrBackendRend
erTargetDesc&, | 97 static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*, |
105 const SkSurfaceProps*); | 98 const GrBackendRenderTar
getDesc&, |
| 99 const SkSurfaceProps*); |
106 | 100 |
107 /** | 101 /** |
108 * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will tre
at the texture as | 102 * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will tre
at the texture as |
109 * a rendering target only, but unlike NewFromBackendRenderTarget, Skia wil
l manage and own | 103 * a rendering target only, but unlike NewFromBackendRenderTarget, Skia wil
l manage and own |
110 * the associated render target objects (but not the provided texture). The
kRenderTarget flag | 104 * the associated render target objects (but not the provided texture). The
kRenderTarget flag |
111 * must be set on GrBackendTextureDesc for this to succeed. Skia will not a
ssume ownership | 105 * must be set on GrBackendTextureDesc for this to succeed. Skia will not a
ssume ownership |
112 * of the texture and the client must ensure the texture is valid for the l
ifetime of the | 106 * of the texture and the client must ensure the texture is valid for the l
ifetime of the |
113 * SkSurface. | 107 * SkSurface. |
114 */ | 108 */ |
115 static SkSurface* NewFromBackendTextureAsRenderTarget( | 109 static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget( |
116 GrContext*, const GrBackendTextureDesc&, const SkSurfaceProps*); | 110 GrContext*, const GrBackendTextureDesc&, const SkSurfaceProps*); |
117 | 111 |
118 /** | 112 /** |
119 * Return a new surface whose contents will be drawn to an offscreen | 113 * Return a new surface whose contents will be drawn to an offscreen |
120 * render target, allocated by the surface. | 114 * render target, allocated by the surface. |
121 * | 115 * |
122 * The GrTextureStorageAllocator will be reused if SkImage snapshots create | 116 * The GrTextureStorageAllocator will be reused if SkImage snapshots create |
123 * additional textures. | 117 * additional textures. |
124 */ | 118 */ |
125 static SkSurface* NewRenderTarget( | 119 static sk_sp<SkSurface> MakeRenderTarget( |
126 GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, | 120 GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, const S
kSurfaceProps*, |
127 const SkSurfaceProps* = NULL, GrTextureStorageAllocator = GrTextureS
torageAllocator()); | 121 GrTextureStorageAllocator = GrTextureStorageAllocator()); |
128 | 122 |
| 123 static sk_sp<SkSurface> MakeRenderTarget(GrContext* gr, SkBudgeted b, const
SkImageInfo& info) { |
| 124 return MakeRenderTarget(gr, b, info, 0, nullptr); |
| 125 } |
| 126 |
| 127 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
| 128 static SkSurface* NewRasterDirect(const SkImageInfo& info, void* pixels, siz
e_t rowBytes, |
| 129 const SkSurfaceProps* props = NULL) { |
| 130 return MakeRasterDirect(info, pixels, rowBytes, props).release(); |
| 131 } |
| 132 static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo& info, void*
pixels, |
| 133 size_t rowBytes, |
| 134 void (*releaseProc)(void* pixel
s, void* context), |
| 135 void* context, const SkSurfaceP
rops* props = NULL){ |
| 136 return MakeRasterDirectReleaseProc(info, pixels, rowBytes, releaseProc,
context, |
| 137 props).release(); |
| 138 } |
| 139 static SkSurface* NewRaster(const SkImageInfo& info, size_t rowBytes, |
| 140 const SkSurfaceProps* props) { |
| 141 return MakeRaster(info, rowBytes, props).release(); |
| 142 } |
| 143 static SkSurface* NewRaster(const SkImageInfo& info, const SkSurfaceProps* p
rops = NULL) { |
| 144 return MakeRaster(info, props).release(); |
| 145 } |
| 146 static SkSurface* NewRasterN32Premul(int width, int height, |
| 147 const SkSurfaceProps* props = NULL) { |
| 148 return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); |
| 149 } |
| 150 static SkSurface* NewRenderTargetDirect(GrRenderTarget* rt, const SkSurfaceP
rops* props) { |
| 151 return MakeRenderTargetDirect(rt, props).release(); |
| 152 } |
| 153 static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { |
| 154 return NewRenderTargetDirect(target, NULL); |
| 155 } |
| 156 static SkSurface* NewFromBackendTexture(GrContext* ctx, const GrBackendTextu
reDesc& desc, |
| 157 const SkSurfaceProps* props) { |
| 158 return MakeFromBackendTexture(ctx, desc, props).release(); |
| 159 } |
| 160 // Legacy alias |
| 161 static SkSurface* NewWrappedRenderTarget(GrContext* ctx, const GrBackendText
ureDesc& desc, |
| 162 const SkSurfaceProps* props) { |
| 163 return NewFromBackendTexture(ctx, desc, props); |
| 164 } |
| 165 static SkSurface* NewFromBackendRenderTarget(GrContext* ctx, const GrBackend
RenderTargetDesc& d, |
| 166 const SkSurfaceProps* props) { |
| 167 return MakeFromBackendRenderTarget(ctx, d, props).release(); |
| 168 } |
| 169 static SkSurface* NewFromBackendTextureAsRenderTarget(GrContext* ctx, |
| 170 const GrBackendTexture
Desc& desc, |
| 171 const SkSurfaceProps*
props) { |
| 172 return MakeFromBackendTextureAsRenderTarget(ctx, desc, props).release(); |
| 173 } |
| 174 static SkSurface* NewRenderTarget(GrContext* ctx, SkBudgeted b, const SkImag
eInfo& info, |
| 175 int sampleCount, const SkSurfaceProps* pro
ps = NULL, |
| 176 GrTextureStorageAllocator a = GrTextureSto
rageAllocator()) { |
| 177 return MakeRenderTarget(ctx, b, info, sampleCount, props, a).release(); |
| 178 } |
129 static SkSurface* NewRenderTarget(GrContext* gr, SkBudgeted b, const SkImage
Info& info) { | 179 static SkSurface* NewRenderTarget(GrContext* gr, SkBudgeted b, const SkImage
Info& info) { |
130 return NewRenderTarget(gr, b, info, 0); | 180 return NewRenderTarget(gr, b, info, 0); |
131 } | 181 } |
| 182 SkSurface* newSurface(const SkImageInfo& info) { return this->makeSurface(in
fo).release(); } |
| 183 #endif |
132 | 184 |
133 int width() const { return fWidth; } | 185 int width() const { return fWidth; } |
134 int height() const { return fHeight; } | 186 int height() const { return fHeight; } |
135 | 187 |
136 /** | 188 /** |
137 * Returns a unique non-zero, unique value identifying the content of this | 189 * Returns a unique non-zero, unique value identifying the content of this |
138 * surface. Each time the content is changed changed, either by drawing | 190 * surface. Each time the content is changed changed, either by drawing |
139 * into this surface, or explicitly calling notifyContentChanged()) this | 191 * into this surface, or explicitly calling notifyContentChanged()) this |
140 * method will return a new value. | 192 * method will return a new value. |
141 * | 193 * |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 * pattern: | 268 * pattern: |
217 * | 269 * |
218 * SkSurface* A = SkSurface::New...(); | 270 * SkSurface* A = SkSurface::New...(); |
219 * SkCanvas* canvasA = surfaceA->newCanvas(); | 271 * SkCanvas* canvasA = surfaceA->newCanvas(); |
220 * ... | 272 * ... |
221 * SkSurface* surfaceB = surfaceA->newSurface(...); | 273 * SkSurface* surfaceB = surfaceA->newSurface(...); |
222 * SkCanvas* canvasB = surfaceB->newCanvas(); | 274 * SkCanvas* canvasB = surfaceB->newCanvas(); |
223 * ... // draw using canvasB | 275 * ... // draw using canvasB |
224 * canvasA->drawSurface(surfaceB); // <--- this will always be optimal! | 276 * canvasA->drawSurface(surfaceB); // <--- this will always be optimal! |
225 */ | 277 */ |
226 SkSurface* newSurface(const SkImageInfo&); | 278 sk_sp<SkSurface> makeSurface(const SkImageInfo&); |
227 | 279 |
228 /** | 280 /** |
229 * Returns an image of the current state of the surface pixels up to this | 281 * Returns an image of the current state of the surface pixels up to this |
230 * point. Subsequent changes to the surface (by drawing into its canvas) | 282 * point. Subsequent changes to the surface (by drawing into its canvas) |
231 * will not be reflected in this image. If a copy must be made the Budgeted | 283 * will not be reflected in this image. If a copy must be made the Budgeted |
232 * parameter controls whether it counts against the resource budget | 284 * parameter controls whether it counts against the resource budget |
233 * (currently for the gpu backend only). | 285 * (currently for the gpu backend only). |
234 */ | 286 */ |
235 sk_sp<SkImage> makeImageSnapshot(SkBudgeted = SkBudgeted::kYes); | 287 sk_sp<SkImage> makeImageSnapshot(SkBudgeted = SkBudgeted::kYes); |
236 | 288 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 private: | 371 private: |
320 const SkSurfaceProps fProps; | 372 const SkSurfaceProps fProps; |
321 const int fWidth; | 373 const int fWidth; |
322 const int fHeight; | 374 const int fHeight; |
323 uint32_t fGenerationID; | 375 uint32_t fGenerationID; |
324 | 376 |
325 typedef SkRefCnt INHERITED; | 377 typedef SkRefCnt INHERITED; |
326 }; | 378 }; |
327 | 379 |
328 #endif | 380 #endif |
OLD | NEW |