OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" |
9 #include "SkImageFilter.h" | 10 #include "SkImageFilter.h" |
10 #include "SkLiteDL.h" | 11 #include "SkLiteDL.h" |
| 12 #include "SkPicture.h" |
11 #include "SkMutex.h" | 13 #include "SkMutex.h" |
| 14 #include "SkRSXform.h" |
12 #include "SkSpinlock.h" | 15 #include "SkSpinlock.h" |
13 #include "SkTextBlob.h" | 16 #include "SkTextBlob.h" |
14 | 17 |
15 // memcpy_v(dst, src0,bytes0, src1,bytes1, ...) copies an arbitrary number of sr
cs into dst. | 18 // TODO: make sure DrawPosText and DrawPosTextH positions are aligned |
| 19 // (move the text after the positions). |
| 20 |
| 21 // A stand-in for an optional SkRect which was not set, e.g. bounds for a saveLa
yer(). |
| 22 static const SkRect kUnset = {SK_ScalarInfinity, 0,0,0}; |
| 23 static const SkRect* maybe_unset(const SkRect& r) { |
| 24 return r.left() == SK_ScalarInfinity ? nullptr : &r; |
| 25 } |
| 26 |
| 27 // memcpy_v(dst, src,bytes, src,bytes, ...) copies an arbitrary number of srcs i
nto dst. |
16 static void memcpy_v(void* dst) {} | 28 static void memcpy_v(void* dst) {} |
17 | 29 |
18 template <typename... Rest> | 30 template <typename... Rest> |
19 static void memcpy_v(void* dst, const void* src, size_t bytes, Rest&&... rest) { | 31 static void memcpy_v(void* dst, const void* src, size_t bytes, Rest&&... rest) { |
20 memcpy(dst, src, bytes); | 32 sk_careful_memcpy(dst, src, bytes); |
21 memcpy_v(SkTAddOffset<void>(dst, bytes), std::forward<Rest>(rest)...); | 33 memcpy_v(SkTAddOffset<void>(dst, bytes), std::forward<Rest>(rest)...); |
22 } | 34 } |
23 | 35 |
| 36 // Helper for getting back at arrays which have been memcpy_v'd together after a
n Op. |
| 37 template <typename D, typename T> |
| 38 static D* pod(T* op, size_t offset = 0) { |
| 39 return SkTAddOffset<D>(op+1, offset); |
| 40 } |
| 41 |
24 // Convert images and image-based shaders to textures. | 42 // Convert images and image-based shaders to textures. |
25 static void optimize_for(GrContext* ctx, SkPaint* paint, sk_sp<const SkImage>* i
mage = nullptr) { | 43 static void optimize_for(GrContext* ctx, SkPaint* paint, sk_sp<const SkImage>* i
mage = nullptr) { |
26 SkMatrix matrix; | 44 SkMatrix matrix; |
27 SkShader::TileMode xy[2]; | 45 SkShader::TileMode xy[2]; |
28 if (auto shader = paint->getShader()) | 46 if (auto shader = paint->getShader()) |
29 if (auto image = shader->isAImage(&matrix, xy)) { // TODO: compose shaders
, etc. | 47 if (auto image = shader->isAImage(&matrix, xy)) { // TODO: compose shaders
, etc. |
30 paint->setShader(image->makeTextureImage(ctx)->makeShader(xy[0], xy[1],
&matrix)); | 48 paint->setShader(image->makeTextureImage(ctx)->makeShader(xy[0], xy[1],
&matrix)); |
31 } | 49 } |
32 | 50 |
33 if (image) { | 51 if (image) { |
34 *image = (*image)->makeTextureImage(ctx); | 52 *image = (*image)->makeTextureImage(ctx); |
35 } | 53 } |
36 } | 54 } |
37 | 55 |
38 namespace { | 56 namespace { |
39 struct Op { | 57 struct Op { |
40 virtual ~Op() {} | 58 virtual ~Op() {} |
41 virtual void draw(SkCanvas*) = 0; | 59 virtual void draw(SkCanvas*) = 0; |
42 virtual void optimizeFor(GrContext*) {} | 60 virtual void optimizeFor(GrContext*) {} |
43 | 61 |
44 size_t skip; | 62 size_t skip; |
45 }; | 63 }; |
46 | 64 |
47 struct Save final : Op { void draw(SkCanvas* c) override { c-> save();
} }; | 65 struct Save final : Op { void draw(SkCanvas* c) override { c-> save();
} }; |
48 struct Restore final : Op { void draw(SkCanvas* c) override { c->restore();
} }; | 66 struct Restore final : Op { void draw(SkCanvas* c) override { c->restore();
} }; |
49 struct SaveLayer final : Op { | 67 struct SaveLayer final : Op { |
50 SaveLayer(const SkRect* bounds, const SkPaint* paint, | 68 SaveLayer(const SkRect* bounds, const SkPaint* paint, |
51 const SkImageFilter* backdrop, uint32_t flags) { | 69 const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags)
{ |
52 if (bounds) { this->bounds = *bounds; } | 70 if (bounds) { this->bounds = *bounds; } |
53 if (paint) { this->paint = *paint; } | 71 if (paint) { this->paint = *paint; } |
54 this->backdrop = sk_ref_sp(backdrop); | 72 this->backdrop = sk_ref_sp(backdrop); |
55 this->flags = flags; | 73 this->flags = flags; |
56 } | 74 } |
57 SkRect bounds = {SK_ScalarMin,SK_ScalarMin, SK_Scala
rMax,SK_ScalarMax}; | 75 SkRect bounds = kUnset; |
58 SkPaint paint; | 76 SkPaint paint; |
59 sk_sp<const SkImageFilter> backdrop; | 77 sk_sp<const SkImageFilter> backdrop; |
60 uint32_t flags; | 78 SkCanvas::SaveLayerFlags flags; |
61 void draw(SkCanvas* c) override { | 79 void draw(SkCanvas* c) override { |
62 c->saveLayer({ &bounds, &paint, backdrop.get(), flags }); | 80 c->saveLayer({ maybe_unset(bounds), &paint, backdrop.get(), flags })
; |
63 } | 81 } |
64 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 82 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
65 }; | 83 }; |
66 | 84 |
67 struct Concat final : Op { | 85 struct Concat final : Op { |
68 Concat(const SkMatrix& matrix) : matrix(matrix) {} | 86 Concat(const SkMatrix& matrix) : matrix(matrix) {} |
69 SkMatrix matrix; | 87 SkMatrix matrix; |
70 void draw(SkCanvas* c) override { c->concat(matrix); } | 88 void draw(SkCanvas* c) override { c->concat(matrix); } |
71 }; | 89 }; |
72 struct SetMatrix final : Op { | 90 struct SetMatrix final : Op { |
73 SetMatrix(const SkMatrix& matrix) : matrix(matrix) {} | 91 SetMatrix(const SkMatrix& matrix) : matrix(matrix) {} |
74 SkMatrix matrix; | 92 SkMatrix matrix; |
75 void draw(SkCanvas* c) override { c->setMatrix(matrix); } | 93 void draw(SkCanvas* c) override { c->setMatrix(matrix); } |
76 }; | 94 }; |
| 95 struct TranslateZ final : Op { |
| 96 TranslateZ(SkScalar dz) : dz(dz) {} |
| 97 SkScalar dz; |
| 98 void draw(SkCanvas* c) override { |
| 99 #ifdef SK_EXPERIMENTAL_SHADOWING |
| 100 c->translateZ(dz); |
| 101 #endif |
| 102 } |
| 103 }; |
77 | 104 |
78 struct ClipPath final : Op { | 105 struct ClipPath final : Op { |
79 ClipPath(const SkPath& path, SkRegion::Op op, bool aa) : path(path), op(
op), aa(aa) {} | 106 ClipPath(const SkPath& path, SkRegion::Op op, bool aa) : path(path), op(
op), aa(aa) {} |
80 SkPath path; | 107 SkPath path; |
81 SkRegion::Op op; | 108 SkRegion::Op op; |
82 bool aa; | 109 bool aa; |
83 void draw(SkCanvas* c) override { c->clipPath(path, op, aa); } | 110 void draw(SkCanvas* c) override { c->clipPath(path, op, aa); } |
84 }; | 111 }; |
85 struct ClipRect final : Op { | 112 struct ClipRect final : Op { |
86 ClipRect(const SkRect& rect, SkRegion::Op op, bool aa) : rect(rect), op(
op), aa(aa) {} | 113 ClipRect(const SkRect& rect, SkRegion::Op op, bool aa) : rect(rect), op(
op), aa(aa) {} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 }; | 166 }; |
140 struct DrawDRRect final : Op { | 167 struct DrawDRRect final : Op { |
141 DrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& pa
int) | 168 DrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& pa
int) |
142 : outer(outer), inner(inner), paint(paint) {} | 169 : outer(outer), inner(inner), paint(paint) {} |
143 SkRRect outer, inner; | 170 SkRRect outer, inner; |
144 SkPaint paint; | 171 SkPaint paint; |
145 void draw(SkCanvas* c) override { c->drawDRRect(outer, inner, paint); } | 172 void draw(SkCanvas* c) override { c->drawDRRect(outer, inner, paint); } |
146 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 173 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
147 }; | 174 }; |
148 | 175 |
| 176 struct DrawAnnotation final : Op { |
| 177 DrawAnnotation(const SkRect& rect, SkData* value) : rect(rect), value(sk
_ref_sp(value)) {} |
| 178 SkRect rect; |
| 179 sk_sp<SkData> value; |
| 180 void draw(SkCanvas* c) override { c->drawAnnotation(rect, pod<char>(this
), value.get()); } |
| 181 }; |
| 182 struct DrawDrawable final : Op { |
| 183 DrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) : drawable(sk
_ref_sp(drawable)) { |
| 184 if (matrix) { this->matrix = *matrix; } |
| 185 } |
| 186 sk_sp<SkDrawable> drawable; |
| 187 SkMatrix matrix = SkMatrix::I(); |
| 188 void draw(SkCanvas* c) override { c->drawDrawable(drawable.get(), &matri
x); } |
| 189 }; |
| 190 struct DrawPicture final : Op { |
| 191 DrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPa
int* paint) |
| 192 : picture(sk_ref_sp(picture)) { |
| 193 if (matrix) { this->matrix = *matrix; } |
| 194 if (paint) { this->paint = *paint; } |
| 195 } |
| 196 sk_sp<const SkPicture> picture; |
| 197 SkMatrix matrix = SkMatrix::I(); |
| 198 SkPaint paint; |
| 199 void draw(SkCanvas* c) override { c->drawPicture(picture.get(), &matrix,
&paint); } |
| 200 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
| 201 }; |
| 202 struct DrawShadowedPicture final : Op { |
| 203 DrawShadowedPicture(const SkPicture* picture, const SkMatrix* matrix, co
nst SkPaint* paint) |
| 204 : picture(sk_ref_sp(picture)) { |
| 205 if (matrix) { this->matrix = *matrix; } |
| 206 if (paint) { this->paint = *paint; } |
| 207 } |
| 208 sk_sp<const SkPicture> picture; |
| 209 SkMatrix matrix = SkMatrix::I(); |
| 210 SkPaint paint; |
| 211 void draw(SkCanvas* c) override { |
| 212 #ifdef SK_EXPERIMENTAL_SHADOWING |
| 213 c->drawShadowedPicture(picture.get(), &matrix, &paint); |
| 214 #endif |
| 215 } |
| 216 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
| 217 }; |
| 218 |
149 struct DrawImage final : Op { | 219 struct DrawImage final : Op { |
150 DrawImage(sk_sp<const SkImage>&& image, SkScalar x, SkScalar y, const Sk
Paint* paint) | 220 DrawImage(sk_sp<const SkImage>&& image, SkScalar x, SkScalar y, const Sk
Paint* paint) |
151 : image(image), x(x), y(y) { | 221 : image(image), x(x), y(y) { |
152 if (paint) { this->paint = *paint; } | 222 if (paint) { this->paint = *paint; } |
153 } | 223 } |
154 sk_sp<const SkImage> image; | 224 sk_sp<const SkImage> image; |
155 SkScalar x,y; | 225 SkScalar x,y; |
156 SkPaint paint; | 226 SkPaint paint; |
157 void draw(SkCanvas* c) override { c->drawImage(image.get(), x,y, &paint)
; } | 227 void draw(SkCanvas* c) override { c->drawImage(image.get(), x,y, &paint)
; } |
158 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &i
mage); } | 228 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &i
mage); } |
(...skipping 20 matching lines...) Expand all Loading... |
179 } | 249 } |
180 sk_sp<const SkImage> image; | 250 sk_sp<const SkImage> image; |
181 SkRect src, dst; | 251 SkRect src, dst; |
182 SkPaint paint; | 252 SkPaint paint; |
183 SkCanvas::SrcRectConstraint constraint; | 253 SkCanvas::SrcRectConstraint constraint; |
184 void draw(SkCanvas* c) override { | 254 void draw(SkCanvas* c) override { |
185 c->drawImageRect(image.get(), src, dst, &paint, constraint); | 255 c->drawImageRect(image.get(), src, dst, &paint, constraint); |
186 } | 256 } |
187 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &i
mage); } | 257 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &i
mage); } |
188 }; | 258 }; |
| 259 struct DrawImageLattice final : Op { |
| 260 DrawImageLattice(sk_sp<const SkImage>&& image, int xs, int ys, |
| 261 const SkRect& dst, const SkPaint* paint) |
| 262 : image(image), xs(xs), ys(ys), dst(dst) { |
| 263 if (paint) { this->paint = *paint; } |
| 264 } |
| 265 sk_sp<const SkImage> image; |
| 266 int xs, ys; |
| 267 SkRect dst; |
| 268 SkPaint paint; |
| 269 void draw(SkCanvas* c) override { |
| 270 auto xdivs = pod<int>(this, 0), |
| 271 ydivs = pod<int>(this, xs*sizeof(int)); |
| 272 c->drawImageLattice(image.get(), {xdivs, xs, ydivs, ys}, dst, &paint
); |
| 273 } |
| 274 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &i
mage); } |
| 275 }; |
189 | 276 |
190 struct DrawText final : Op { | 277 struct DrawText final : Op { |
191 DrawText(size_t bytes, SkScalar x, SkScalar y, const SkPaint& paint) | 278 DrawText(size_t bytes, SkScalar x, SkScalar y, const SkPaint& paint) |
192 : bytes(bytes), x(x), y(y), paint(paint) {} | 279 : bytes(bytes), x(x), y(y), paint(paint) {} |
193 size_t bytes; | 280 size_t bytes; |
194 SkScalar x,y; | 281 SkScalar x,y; |
195 SkPaint paint; | 282 SkPaint paint; |
196 void draw(SkCanvas* c) override { c->drawText(this+1, bytes, x,y, paint)
; } | 283 void draw(SkCanvas* c) override { c->drawText(pod<void>(this), bytes, x,
y, paint); } |
197 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 284 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
198 }; | 285 }; |
199 struct DrawPosText final : Op { | 286 struct DrawPosText final : Op { |
200 DrawPosText(size_t bytes, const SkPaint& paint) | 287 DrawPosText(size_t bytes, const SkPaint& paint) |
201 : bytes(bytes), paint(paint) {} | 288 : bytes(bytes), paint(paint) {} |
202 size_t bytes; | 289 size_t bytes; |
203 SkPaint paint; | 290 SkPaint paint; |
204 void draw(SkCanvas* c) override { | 291 void draw(SkCanvas* c) override { |
205 auto pos = SkTAddOffset<SkPoint>(this+1, bytes); | 292 c->drawPosText(pod<void>(this), bytes, pod<SkPoint>(this, bytes), pa
int); |
206 c->drawPosText(this+1, bytes, pos, paint); | |
207 } | 293 } |
208 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 294 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
209 }; | 295 }; |
210 struct DrawPosTextH final : Op { | 296 struct DrawPosTextH final : Op { |
211 DrawPosTextH(size_t bytes, SkScalar y, const SkPaint& paint) | 297 DrawPosTextH(size_t bytes, SkScalar y, const SkPaint& paint) |
212 : bytes(bytes), y(y), paint(paint) {} | 298 : bytes(bytes), y(y), paint(paint) {} |
213 size_t bytes; | 299 size_t bytes; |
214 SkScalar y; | 300 SkScalar y; |
215 SkPaint paint; | 301 SkPaint paint; |
216 void draw(SkCanvas* c) override { | 302 void draw(SkCanvas* c) override { |
217 auto xs = SkTAddOffset<SkScalar>(this+1, bytes); | 303 c->drawPosTextH(pod<void>(this), bytes, pod<SkScalar>(this, bytes),
y, paint); |
218 c->drawPosTextH(this+1, bytes, xs, y, paint); | |
219 } | 304 } |
220 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 305 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
221 }; | 306 }; |
| 307 struct DrawTextOnPath final : Op { |
| 308 DrawTextOnPath(size_t bytes, const SkPath& path, |
| 309 const SkMatrix* matrix, const SkPaint& paint) |
| 310 : bytes(bytes), path(path), paint(paint) { |
| 311 if (matrix) { this->matrix = *matrix; } |
| 312 } |
| 313 size_t bytes; |
| 314 SkPath path; |
| 315 SkMatrix matrix = SkMatrix::I(); |
| 316 SkPaint paint; |
| 317 void draw(SkCanvas* c) override { |
| 318 c->drawTextOnPath(pod<void>(this), bytes, path, &matrix, paint); |
| 319 } |
| 320 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
| 321 }; |
| 322 struct DrawTextRSXform final : Op { |
| 323 DrawTextRSXform(size_t bytes, const SkRect* cull, const SkPaint& paint) |
| 324 : bytes(bytes), paint(paint) { |
| 325 if (cull) { this->cull = *cull; } |
| 326 } |
| 327 size_t bytes; |
| 328 SkRect cull = kUnset; |
| 329 SkPaint paint; |
| 330 void draw(SkCanvas* c) override { |
| 331 c->drawTextRSXform(pod<void>(this), bytes, pod<SkRSXform>(this, byte
s), |
| 332 maybe_unset(cull), paint); |
| 333 } |
| 334 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
| 335 }; |
222 struct DrawTextBlob final : Op { | 336 struct DrawTextBlob final : Op { |
223 DrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPai
nt& paint) | 337 DrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPai
nt& paint) |
224 : blob(sk_ref_sp(blob)), x(x), y(y), paint(paint) {} | 338 : blob(sk_ref_sp(blob)), x(x), y(y), paint(paint) {} |
225 sk_sp<const SkTextBlob> blob; | 339 sk_sp<const SkTextBlob> blob; |
226 SkScalar x,y; | 340 SkScalar x,y; |
227 SkPaint paint; | 341 SkPaint paint; |
228 void draw(SkCanvas* c) override { c->drawTextBlob(blob.get(), x,y, paint
); } | 342 void draw(SkCanvas* c) override { c->drawTextBlob(blob.get(), x,y, paint
); } |
229 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } | 343 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
230 }; | 344 }; |
| 345 |
| 346 struct DrawPoints final : Op { |
| 347 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPaint& paint) |
| 348 : mode(mode), count(count), paint(paint) {} |
| 349 SkCanvas::PointMode mode; |
| 350 size_t count; |
| 351 SkPaint paint; |
| 352 void draw(SkCanvas* c) override { c->drawPoints(mode, count, pod<SkPoint
>(this), paint); } |
| 353 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint); } |
| 354 }; |
| 355 struct DrawAtlas final : Op { |
| 356 DrawAtlas(const SkImage* atlas, int count, SkXfermode::Mode xfermode, |
| 357 const SkRect* cull, const SkPaint* paint, bool has_colors) |
| 358 : atlas(sk_ref_sp(atlas)), count(count), xfermode(xfermode), has_col
ors(has_colors) { |
| 359 if (cull) { this->cull = *cull; } |
| 360 if (paint) { this->paint = *paint; } |
| 361 } |
| 362 sk_sp<const SkImage> atlas; |
| 363 int count; |
| 364 SkXfermode::Mode xfermode; |
| 365 SkRect cull = kUnset; |
| 366 SkPaint paint; |
| 367 bool has_colors; |
| 368 void draw(SkCanvas* c) override { |
| 369 auto xforms = pod<SkRSXform>(this, 0); |
| 370 auto texs = pod<SkRect>(this, count*sizeof(SkRSXform)); |
| 371 auto colors = has_colors |
| 372 ? pod<SkColor>(this, count*(sizeof(SkRSXform) + sizeof(SkRect))) |
| 373 : nullptr; |
| 374 c->drawAtlas(atlas.get(), xforms, texs, colors, count, xfermode, |
| 375 maybe_unset(cull), &paint); |
| 376 } |
| 377 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &a
tlas); } |
| 378 }; |
231 } | 379 } |
232 | 380 |
233 template <typename T, typename... Args> | 381 template <typename T, typename... Args> |
234 static void* push(SkTDArray<uint8_t>* bytes, size_t pod, Args&&... args) { | 382 static void* push(SkTDArray<uint8_t>* bytes, size_t pod, Args&&... args) { |
235 size_t skip = SkAlignPtr(sizeof(T) + pod); | 383 size_t skip = SkAlignPtr(sizeof(T) + pod); |
236 auto op = (T*)bytes->append(skip); | 384 auto op = (T*)bytes->append(skip); |
237 new (op) T{ std::forward<Args>(args)... }; | 385 new (op) T{ std::forward<Args>(args)... }; |
238 op->skip = skip; | 386 op->skip = skip; |
239 return op+1; | 387 return op+1; |
240 } | 388 } |
241 | 389 |
242 template <typename Fn> | 390 template <typename Fn> |
243 static void map(SkTDArray<uint8_t>* bytes, Fn&& fn) { | 391 static void map(SkTDArray<uint8_t>* bytes, Fn&& fn) { |
244 for (uint8_t* ptr = bytes->begin(); ptr < bytes->end(); ) { | 392 for (uint8_t* ptr = bytes->begin(); ptr < bytes->end(); ) { |
245 auto op = (Op*)ptr; | 393 auto op = (Op*)ptr; |
246 fn(op); | 394 fn(op); |
247 ptr += op->skip; | 395 ptr += op->skip; |
248 } | 396 } |
249 } | 397 } |
250 | 398 |
251 void SkLiteDL:: save() { push <Save>(&fBytes, 0); } | 399 void SkLiteDL:: save() { push <Save>(&fBytes, 0); } |
252 void SkLiteDL::restore() { push<Restore>(&fBytes, 0); } | 400 void SkLiteDL::restore() { push<Restore>(&fBytes, 0); } |
253 void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint, | 401 void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint, |
254 const SkImageFilter* backdrop, uint32_t flags) { | 402 const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags
flags) { |
255 push<SaveLayer>(&fBytes, 0, bounds, paint, backdrop, flags); | 403 push<SaveLayer>(&fBytes, 0, bounds, paint, backdrop, flags); |
256 } | 404 } |
257 | 405 |
258 void SkLiteDL:: concat(const SkMatrix& matrix) { push <Concat>(&fBytes, 0, m
atrix); } | 406 void SkLiteDL:: concat(const SkMatrix& matrix) { push <Concat>(&fBytes, 0, m
atrix); } |
259 void SkLiteDL::setMatrix(const SkMatrix& matrix) { push<SetMatrix>(&fBytes, 0, m
atrix); } | 407 void SkLiteDL::setMatrix(const SkMatrix& matrix) { push<SetMatrix>(&fBytes, 0, m
atrix); } |
| 408 void SkLiteDL::translateZ(SkScalar dz) { push<TranslateZ>(&fBytes, 0, dz); } |
260 | 409 |
261 void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) { | 410 void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) { |
262 push<ClipPath>(&fBytes, 0, path, op, aa); | 411 push<ClipPath>(&fBytes, 0, path, op, aa); |
263 } | 412 } |
264 void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) { | 413 void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) { |
265 push<ClipRect>(&fBytes, 0, rect, op, aa); | 414 push<ClipRect>(&fBytes, 0, rect, op, aa); |
266 } | 415 } |
267 void SkLiteDL::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) { | 416 void SkLiteDL::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) { |
268 push<ClipRRect>(&fBytes, 0, rrect, op, aa); | 417 push<ClipRRect>(&fBytes, 0, rrect, op, aa); |
269 } | 418 } |
(...skipping 13 matching lines...) Expand all Loading... |
283 void SkLiteDL::drawOval(const SkRect& oval, const SkPaint& paint) { | 432 void SkLiteDL::drawOval(const SkRect& oval, const SkPaint& paint) { |
284 push<DrawOval>(&fBytes, 0, oval, paint); | 433 push<DrawOval>(&fBytes, 0, oval, paint); |
285 } | 434 } |
286 void SkLiteDL::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 435 void SkLiteDL::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
287 push<DrawRRect>(&fBytes, 0, rrect, paint); | 436 push<DrawRRect>(&fBytes, 0, rrect, paint); |
288 } | 437 } |
289 void SkLiteDL::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPa
int& paint) { | 438 void SkLiteDL::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPa
int& paint) { |
290 push<DrawDRRect>(&fBytes, 0, outer, inner, paint); | 439 push<DrawDRRect>(&fBytes, 0, outer, inner, paint); |
291 } | 440 } |
292 | 441 |
| 442 void SkLiteDL::drawAnnotation(const SkRect& rect, const char* key, SkData* value
) { |
| 443 size_t bytes = strlen(key)+1; |
| 444 void* pod = push<DrawAnnotation>(&fBytes, bytes, rect, value); |
| 445 memcpy_v(pod, key,bytes); |
| 446 } |
| 447 void SkLiteDL::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 448 push<DrawDrawable>(&fBytes, 0, drawable, matrix); |
| 449 } |
| 450 void SkLiteDL::drawPicture(const SkPicture* picture, |
| 451 const SkMatrix* matrix, const SkPaint* paint) { |
| 452 push<DrawPicture>(&fBytes, 0, picture, matrix, paint); |
| 453 } |
| 454 void SkLiteDL::drawShadowedPicture(const SkPicture* picture, |
| 455 const SkMatrix* matrix, const SkPaint* paint)
{ |
| 456 push<DrawShadowedPicture>(&fBytes, 0, picture, matrix, paint); |
| 457 } |
| 458 |
293 void SkLiteDL::drawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPa
int* paint) { | 459 void SkLiteDL::drawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPa
int* paint) { |
294 push<DrawImage>(&fBytes, 0, SkImage::MakeFromBitmap(bm), x,y, paint); | 460 push<DrawImage>(&fBytes, 0, SkImage::MakeFromBitmap(bm), x,y, paint); |
295 } | 461 } |
296 void SkLiteDL::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, | 462 void SkLiteDL::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, |
297 const SkRect& dst, const SkPaint* paint) { | 463 const SkRect& dst, const SkPaint* paint) { |
298 push<DrawImageNine>(&fBytes, 0, SkImage::MakeFromBitmap(bm), center, dst, pa
int); | 464 push<DrawImageNine>(&fBytes, 0, SkImage::MakeFromBitmap(bm), center, dst, pa
int); |
299 } | 465 } |
300 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec
t& dst, | 466 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec
t& dst, |
301 const SkPaint* paint, SkCanvas::SrcRectConstraint
constraint) { | 467 const SkPaint* paint, SkCanvas::SrcRectConstraint
constraint) { |
302 push<DrawImageRect>(&fBytes, 0, SkImage::MakeFromBitmap(bm), src, dst, paint
, constraint); | 468 push<DrawImageRect>(&fBytes, 0, SkImage::MakeFromBitmap(bm), src, dst, paint
, constraint); |
303 } | 469 } |
304 | 470 |
305 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { | 471 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { |
306 push<DrawImage>(&fBytes, 0, sk_ref_sp(image), x,y, paint); | 472 push<DrawImage>(&fBytes, 0, sk_ref_sp(image), x,y, paint); |
307 } | 473 } |
308 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center, | 474 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center, |
309 const SkRect& dst, const SkPaint* paint) { | 475 const SkRect& dst, const SkPaint* paint) { |
310 push<DrawImageNine>(&fBytes, 0, sk_ref_sp(image), center, dst, paint); | 476 push<DrawImageNine>(&fBytes, 0, sk_ref_sp(image), center, dst, paint); |
311 } | 477 } |
312 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, | 478 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, |
313 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { | 479 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { |
314 push<DrawImageRect>(&fBytes, 0, sk_ref_sp(image), src, dst, paint, constrain
t); | 480 push<DrawImageRect>(&fBytes, 0, sk_ref_sp(image), src, dst, paint, constrain
t); |
315 } | 481 } |
| 482 void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l
attice, |
| 483 const SkRect& dst, const SkPaint* paint) { |
| 484 int xs = lattice.fXCount, ys = lattice.fYCount; |
| 485 size_t bytes = (xs + ys) * sizeof(int); |
| 486 void* pod = push<DrawImageLattice>(&fBytes, bytes, sk_ref_sp(image), xs, ys,
dst, paint); |
| 487 memcpy_v(pod, lattice.fXDivs,xs*sizeof(int), |
| 488 lattice.fYDivs,ys*sizeof(int)); |
| 489 } |
316 | 490 |
317 void SkLiteDL::drawText(const void* text, size_t bytes, | 491 void SkLiteDL::drawText(const void* text, size_t bytes, |
318 SkScalar x, SkScalar y, const SkPaint& paint) { | 492 SkScalar x, SkScalar y, const SkPaint& paint) { |
319 void* pod = push<DrawText>(&fBytes, bytes, bytes, x, y, paint); | 493 void* pod = push<DrawText>(&fBytes, bytes, bytes, x, y, paint); |
320 memcpy_v(pod, text,bytes); | 494 memcpy_v(pod, text,bytes); |
321 } | 495 } |
322 void SkLiteDL::drawPosText(const void* text, size_t bytes, | 496 void SkLiteDL::drawPosText(const void* text, size_t bytes, |
323 const SkPoint pos[], const SkPaint& paint) { | 497 const SkPoint pos[], const SkPaint& paint) { |
324 int n = paint.countText(text, bytes); | 498 int n = paint.countText(text, bytes); |
325 void* pod = push<DrawPosText>(&fBytes, bytes+n*sizeof(SkPoint), bytes, paint
); | 499 void* pod = push<DrawPosText>(&fBytes, bytes+n*sizeof(SkPoint), bytes, paint
); |
326 memcpy_v(pod, text,bytes, pos,n*sizeof(SkPoint)); | 500 memcpy_v(pod, text,bytes, pos,n*sizeof(SkPoint)); |
327 } | 501 } |
328 void SkLiteDL::drawPosTextH(const void* text, size_t bytes, | 502 void SkLiteDL::drawPosTextH(const void* text, size_t bytes, |
329 const SkScalar xs[], SkScalar y, const SkPaint& paint
) { | 503 const SkScalar xs[], SkScalar y, const SkPaint& paint
) { |
330 int n = paint.countText(text, bytes); | 504 int n = paint.countText(text, bytes); |
331 void* pod = push<DrawPosTextH>(&fBytes, bytes + n*sizeof(SkScalar), bytes, y
, paint); | 505 void* pod = push<DrawPosTextH>(&fBytes, bytes+n*sizeof(SkScalar), bytes, y,
paint); |
332 memcpy_v(pod, text,bytes, xs,n*sizeof(SkScalar)); | 506 memcpy_v(pod, text,bytes, xs,n*sizeof(SkScalar)); |
333 } | 507 } |
| 508 void SkLiteDL::drawTextOnPath(const void* text, size_t bytes, |
| 509 const SkPath& path, const SkMatrix* matrix, const
SkPaint& paint) { |
| 510 void* pod = push<DrawTextOnPath>(&fBytes, bytes, bytes, path, matrix, paint)
; |
| 511 memcpy_v(pod, text,bytes); |
| 512 } |
| 513 void SkLiteDL::drawTextRSXform(const void* text, size_t bytes, |
| 514 const SkRSXform xforms[], const SkRect* cull, con
st SkPaint& paint) { |
| 515 int n = paint.countText(text, bytes); |
| 516 void* pod = push<DrawTextRSXform>(&fBytes, bytes+n*sizeof(SkRSXform), bytes,
cull, paint); |
| 517 memcpy_v(pod, text,bytes, xforms,n*sizeof(SkRSXform)); |
| 518 } |
334 void SkLiteDL::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, cons
t SkPaint& paint) { | 519 void SkLiteDL::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, cons
t SkPaint& paint) { |
335 push<DrawTextBlob>(&fBytes, 0, blob, x,y, paint); | 520 push<DrawTextBlob>(&fBytes, 0, blob, x,y, paint); |
336 } | 521 } |
337 | 522 |
| 523 void SkLiteDL::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint
points[], |
| 524 const SkPaint& paint) { |
| 525 void* pod = push<DrawPoints>(&fBytes, count*sizeof(SkPoint), mode, count, pa
int); |
| 526 memcpy_v(pod, points,count*sizeof(SkPoint)); |
| 527 } |
| 528 void SkLiteDL::drawAtlas(const SkImage* atlas, const SkRSXform xforms[], const S
kRect texs[], |
| 529 const SkColor colors[], int count, SkXfermode::Mode xfe
rmode, |
| 530 const SkRect* cull, const SkPaint* paint) { |
| 531 size_t bytes = count*(sizeof(SkRSXform) + sizeof(SkRect)); |
| 532 if (colors) { |
| 533 bytes += count*sizeof(SkColor); |
| 534 } |
| 535 void* pod = push<DrawAtlas>(&fBytes, bytes, |
| 536 atlas, count, xfermode, cull, paint, colors != n
ullptr); |
| 537 memcpy_v(pod, xforms, count*sizeof(SkRSXform), |
| 538 texs, count*sizeof(SkRect), |
| 539 colors, colors ? count*sizeof(SkColor) : 0); |
| 540 } |
| 541 |
338 | 542 |
339 void SkLiteDL::onDraw(SkCanvas* canvas) { | 543 void SkLiteDL::onDraw(SkCanvas* canvas) { |
340 map(&fBytes, [canvas](Op* op) { op->draw(canvas); }); | 544 map(&fBytes, [canvas](Op* op) { op->draw(canvas); }); |
341 } | 545 } |
342 | 546 |
343 void SkLiteDL::optimizeFor(GrContext* ctx) { | 547 void SkLiteDL::optimizeFor(GrContext* ctx) { |
344 map(&fBytes, [ctx](Op* op) { op->optimizeFor(ctx); }); | 548 map(&fBytes, [ctx](Op* op) { op->optimizeFor(ctx); }); |
345 } | 549 } |
346 | 550 |
347 SkRect SkLiteDL::onGetBounds() { | 551 SkRect SkLiteDL::onGetBounds() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (gFreeStackCount < kFreeStackCountLimit) { | 595 if (gFreeStackCount < kFreeStackCountLimit) { |
392 self->fNext = gFreeStack; | 596 self->fNext = gFreeStack; |
393 gFreeStack = self; | 597 gFreeStack = self; |
394 gFreeStackCount++; | 598 gFreeStackCount++; |
395 return; | 599 return; |
396 } | 600 } |
397 } | 601 } |
398 | 602 |
399 delete this; | 603 delete this; |
400 } | 604 } |
OLD | NEW |