1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
|
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkPatchUtils.h"
#include "SkPictureData.h"
#include "SkPicturePlayback.h"
#include "SkPictureRecord.h"
#include "SkReadBuffer.h"
#include "SkRSXform.h"
#include "SkTextBlob.h"
#include "SkTDArray.h"
#include "SkTypes.h"
// matches old SkCanvas::SaveFlags
enum LegacySaveFlags {
kHasAlphaLayer_LegacySaveFlags = 0x04,
kClipToLayer_LegacySaveFlags = 0x10,
};
SkCanvas::SaveLayerFlags SkCanvas::LegacySaveFlagsToSaveLayerFlags(uint32_t flags) {
uint32_t layerFlags = 0;
if (0 == (flags & kClipToLayer_LegacySaveFlags)) {
layerFlags |= SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag;
}
if (0 == (flags & kHasAlphaLayer_LegacySaveFlags)) {
layerFlags |= kIsOpaque_SaveLayerFlag;
}
return layerFlags;
}
/*
* Read the next op code and chunk size from 'reader'. The returned size
* is the entire size of the chunk (including the opcode). Thus, the
* offset just prior to calling ReadOpAndSize + 'size' is the offset
* to the next chunk's op code. This also means that the size of a chunk
* with no arguments (just an opcode) will be 4.
*/
DrawType SkPicturePlayback::ReadOpAndSize(SkReadBuffer* reader, uint32_t* size) {
uint32_t temp = reader->readInt();
uint32_t op;
if (((uint8_t)temp) == temp) {
// old skp file - no size information
op = temp;
*size = 0;
} else {
UNPACK_8_24(temp, op, *size);
if (MASK_24 == *size) {
*size = reader->readInt();
}
}
return (DrawType)op;
}
static const SkRect* get_rect_ptr(SkReadBuffer* reader, SkRect* storage) {
if (reader->readBool()) {
reader->readRect(storage);
return storage;
} else {
return nullptr;
}
}
class TextContainer {
public:
size_t length() { return fByteLength; }
const void* text() { return (const void*)fText; }
size_t fByteLength;
const char* fText;
};
void get_text(SkReadBuffer* reader, TextContainer* text) {
size_t length = text->fByteLength = reader->readInt();
text->fText = (const char*)reader->skip(length);
}
void SkPicturePlayback::draw(SkCanvas* canvas,
SkPicture::AbortCallback* callback,
SkReadBuffer* buffer) {
AutoResetOpID aroi(this);
SkASSERT(0 == fCurOffset);
std::unique_ptr<SkReadBuffer> reader;
if (buffer) {
reader.reset(buffer->clone(fPictureData->opData()->bytes(),
fPictureData->opData()->size()));
} else {
reader.reset(new SkReadBuffer(fPictureData->opData()->bytes(),
fPictureData->opData()->size()));
}
// Record this, so we can concat w/ it if we encounter a setMatrix()
SkMatrix initialMatrix = canvas->getTotalMatrix();
SkAutoCanvasRestore acr(canvas, false);
while (!reader->eof()) {
if (callback && callback->abort()) {
return;
}
fCurOffset = reader->offset();
uint32_t size;
DrawType op = ReadOpAndSize(reader.get(), &size);
if (!reader->validate(op > UNUSED && op <= LAST_DRAWTYPE_ENUM)) {
return;
}
this->handleOp(reader.get(), op, size, canvas, initialMatrix);
}
// need to propagate invalid state to the parent reader
if (buffer) {
buffer->validate(reader->isValid());
}
}
void SkPicturePlayback::handleOp(SkReadBuffer* reader,
DrawType op,
uint32_t size,
SkCanvas* canvas,
const SkMatrix& initialMatrix) {
#define BREAK_ON_READ_ERROR(r) if (!r->isValid()) { break; }
switch (op) {
case NOOP: {
SkASSERT(size >= 4);
reader->skip(size - 4);
} break;
case CLIP_PATH: {
const SkPath& path = fPictureData->getPath(reader);
uint32_t packed = reader->readInt();
SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed);
bool doAA = ClipParams_unpackDoAA(packed);
size_t offsetToRestore = reader->readInt();
BREAK_ON_READ_ERROR(reader);
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipPath(path, clipOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_REGION: {
SkRegion region;
reader->readRegion(®ion);
uint32_t packed = reader->readInt();
SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed);
size_t offsetToRestore = reader->readInt();
BREAK_ON_READ_ERROR(reader);
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRegion(region, clipOp);
if (canvas->isClipEmpty() && offsetToRestore) {
reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_RECT: {
SkRect rect;
reader->readRect(&rect);
uint32_t packed = reader->readInt();
SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed);
bool doAA = ClipParams_unpackDoAA(packed);
size_t offsetToRestore = reader->readInt();
BREAK_ON_READ_ERROR(reader);
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRect(rect, clipOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_RRECT: {
SkRRect rrect;
reader->readRRect(&rrect);
uint32_t packed = reader->readInt();
SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed);
bool doAA = ClipParams_unpackDoAA(packed);
size_t offsetToRestore = reader->readInt();
BREAK_ON_READ_ERROR(reader);
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRRect(rrect, clipOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
reader->skip(offsetToRestore - reader->offset());
}
} break;
case PUSH_CULL: break; // Deprecated, safe to ignore both push and pop.
case POP_CULL: break;
case CONCAT: {
SkMatrix matrix;
reader->readMatrix(&matrix);
BREAK_ON_READ_ERROR(reader);
canvas->concat(matrix);
break;
}
case DRAW_ANNOTATION: {
SkRect rect;
reader->readRect(&rect);
SkString key;
reader->readString(&key);
sk_sp<SkData> data = reader->readByteArrayAsData();
BREAK_ON_READ_ERROR(reader);
canvas->drawAnnotation(rect, key.c_str(), data.get());
} break;
case DRAW_ARC: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRect rect;
reader->readRect(&rect);
SkScalar startAngle = reader->readScalar();
SkScalar sweepAngle = reader->readScalar();
int useCenter = reader->readInt();
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawArc(rect, startAngle, sweepAngle, SkToBool(useCenter), *paint);
}
} break;
case DRAW_ATLAS: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* atlas = fPictureData->getImage(reader);
const uint32_t flags = reader->readUInt();
const int count = reader->readUInt();
const SkRSXform* xform = (const SkRSXform*)reader->skip(count * sizeof(SkRSXform));
const SkRect* tex = (const SkRect*)reader->skip(count * sizeof(SkRect));
const SkColor* colors = nullptr;
SkBlendMode mode = SkBlendMode::kDst;
if (flags & DRAW_ATLAS_HAS_COLORS) {
colors = (const SkColor*)reader->skip(count * sizeof(SkColor));
mode = (SkBlendMode)reader->readUInt();
}
const SkRect* cull = nullptr;
if (flags & DRAW_ATLAS_HAS_CULL) {
cull = (const SkRect*)reader->skip(sizeof(SkRect));
}
BREAK_ON_READ_ERROR(reader);
canvas->drawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
} break;
case DRAW_BITMAP: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getBitmapAsImage(reader);
SkPoint loc;
reader->readPoint(&loc);
BREAK_ON_READ_ERROR(reader);
canvas->drawImage(image, loc.fX, loc.fY, paint);
} break;
case DRAW_BITMAP_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getBitmapAsImage(reader);
SkRect storage;
const SkRect* src = get_rect_ptr(reader, &storage); // may be null
SkRect dst;
reader->readRect(&dst); // required
SkCanvas::SrcRectConstraint constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
BREAK_ON_READ_ERROR(reader);
if (src) {
canvas->drawImageRect(image, *src, dst, paint, constraint);
} else {
canvas->drawImageRect(image, dst, paint, constraint);
}
} break;
case DRAW_BITMAP_MATRIX: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getBitmapAsImage(reader);
SkMatrix matrix;
reader->readMatrix(&matrix);
BREAK_ON_READ_ERROR(reader);
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(matrix);
canvas->drawImage(image, 0, 0, paint);
} break;
case DRAW_BITMAP_NINE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getBitmapAsImage(reader);
SkIRect src;
reader->readIRect(&src);
SkRect dst;
reader->readRect(&dst);
BREAK_ON_READ_ERROR(reader);
canvas->drawImageNine(image, src, dst, paint);
} break;
case DRAW_CLEAR: {
auto c = reader->readInt();
BREAK_ON_READ_ERROR(reader);
canvas->clear(c);
} break;
case DRAW_DATA: {
// This opcode is now dead, just need to skip it for backwards compatibility
size_t length = reader->readInt();
(void)reader->skip(length);
// skip handles padding the read out to a multiple of 4
} break;
case DRAW_DRAWABLE: {
auto* d = fPictureData->getDrawable(reader);
BREAK_ON_READ_ERROR(reader);
canvas->drawDrawable(d);
} break;
case DRAW_DRAWABLE_MATRIX: {
SkMatrix matrix;
reader->readMatrix(&matrix);
SkDrawable* drawable = fPictureData->getDrawable(reader);
BREAK_ON_READ_ERROR(reader);
canvas->drawDrawable(drawable, &matrix);
} break;
case DRAW_DRRECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRRect outer, inner;
reader->readRRect(&outer);
reader->readRRect(&inner);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawDRRect(outer, inner, *paint);
}
} break;
case BEGIN_COMMENT_GROUP: {
SkString tmp;
reader->readString(&tmp);
// deprecated (M44)
break;
}
case COMMENT: {
SkString tmp;
reader->readString(&tmp);
reader->readString(&tmp);
// deprecated (M44)
break;
}
case END_COMMENT_GROUP:
// deprecated (M44)
break;
case DRAW_IMAGE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
SkPoint loc;
reader->readPoint(&loc);
BREAK_ON_READ_ERROR(reader);
canvas->drawImage(image, loc.fX, loc.fY, paint);
} break;
case DRAW_IMAGE_LATTICE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
SkCanvas::Lattice lattice;
lattice.fXCount = reader->readInt();
lattice.fXDivs = (const int*) reader->skip(lattice.fXCount * sizeof(int32_t));
lattice.fYCount = reader->readInt();
lattice.fYDivs = (const int*) reader->skip(lattice.fYCount * sizeof(int32_t));
int flagCount = reader->readInt();
lattice.fFlags = (0 == flagCount) ? nullptr : (const SkCanvas::Lattice::Flags*)
reader->skip(SkAlign4(flagCount * sizeof(SkCanvas::Lattice::Flags)));
SkIRect src;
reader->readIRect(&src);
lattice.fBounds = &src;
SkRect dst;
reader->readRect(&dst);
BREAK_ON_READ_ERROR(reader);
canvas->drawImageLattice(image, lattice, dst, paint);
} break;
case DRAW_IMAGE_NINE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
SkIRect center;
reader->readIRect(¢er);
SkRect dst;
reader->readRect(&dst);
BREAK_ON_READ_ERROR(reader);
canvas->drawImageNine(image, center, dst, paint);
} break;
case DRAW_IMAGE_RECT_STRICT:
case DRAW_IMAGE_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
SkRect storage;
const SkRect* src = get_rect_ptr(reader, &storage); // may be null
SkRect dst;
reader->readRect(&dst); // required
// DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it
SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint;
if (DRAW_IMAGE_RECT == op) {
// newer op-code stores the constraint explicitly
constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
}
BREAK_ON_READ_ERROR(reader);
canvas->legacy_drawImageRect(image, src, dst, paint, constraint);
} break;
case DRAW_OVAL: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRect rect;
reader->readRect(&rect);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawOval(rect, *paint);
}
} break;
case DRAW_PAINT: {
const SkPaint* paint = fPictureData->getPaint(reader);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawPaint(*paint);
}
} break;
case DRAW_PATCH: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkPoint* cubics = (const SkPoint*)reader->skip(SkPatchUtils::kNumCtrlPts *
sizeof(SkPoint));
uint32_t flag = reader->readInt();
const SkColor* colors = nullptr;
if (flag & DRAW_VERTICES_HAS_COLORS) {
colors = (const SkColor*)reader->skip(SkPatchUtils::kNumCorners * sizeof(SkColor));
}
const SkPoint* texCoords = nullptr;
if (flag & DRAW_VERTICES_HAS_TEXS) {
texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorners *
sizeof(SkPoint));
}
SkBlendMode bmode = SkBlendMode::kModulate;
if (flag & DRAW_VERTICES_HAS_XFER) {
unsigned mode = reader->readInt();
if (mode <= (unsigned)SkBlendMode::kLastMode) {
bmode = (SkBlendMode)mode;
}
}
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawPatch(cubics, colors, texCoords, bmode, *paint);
}
} break;
case DRAW_PATH: {
const SkPaint* paint = fPictureData->getPaint(reader);
const auto& path = fPictureData->getPath(reader);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawPath(path, *paint);
}
} break;
case DRAW_PICTURE: {
const auto* pic = fPictureData->getPicture(reader);
BREAK_ON_READ_ERROR(reader);
canvas->drawPicture(pic);
} break;
case DRAW_PICTURE_MATRIX_PAINT: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkMatrix matrix;
reader->readMatrix(&matrix);
const SkPicture* pic = fPictureData->getPicture(reader);
BREAK_ON_READ_ERROR(reader);
canvas->drawPicture(pic, &matrix, paint);
} break;
case DRAW_POINTS: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt();
size_t count = reader->readInt();
const SkPoint* pts = (const SkPoint*)reader->skip(sizeof(SkPoint)* count);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawPoints(mode, count, pts, *paint);
}
} break;
case DRAW_POS_TEXT: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
size_t points = reader->readInt();
const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(SkPoint));
BREAK_ON_READ_ERROR(reader);
if (paint && text.text()) {
canvas->drawPosText(text.text(), text.length(), pos, *paint);
}
} break;
case DRAW_POS_TEXT_TOP_BOTTOM: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
size_t points = reader->readInt();
const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(SkPoint));
const SkScalar top = reader->readScalar();
const SkScalar bottom = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
SkRect clip = canvas->getLocalClipBounds();
if (top < clip.fBottom && bottom > clip.fTop && paint && text.text()) {
canvas->drawPosText(text.text(), text.length(), pos, *paint);
}
} break;
case DRAW_POS_TEXT_H: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
size_t xCount = reader->readInt();
const SkScalar constY = reader->readScalar();
const SkScalar* xpos = (const SkScalar*)reader->skip(xCount * sizeof(SkScalar));
BREAK_ON_READ_ERROR(reader);
if (paint && text.text()) {
canvas->drawPosTextH(text.text(), text.length(), xpos, constY, *paint);
}
} break;
case DRAW_POS_TEXT_H_TOP_BOTTOM: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
size_t xCount = reader->readInt();
const SkScalar* xpos = (const SkScalar*)reader->skip((3 + xCount) * sizeof(SkScalar));
BREAK_ON_READ_ERROR(reader);
const SkScalar top = *xpos++;
const SkScalar bottom = *xpos++;
const SkScalar constY = *xpos++;
SkRect clip = canvas->getLocalClipBounds();
if (top < clip.fBottom && bottom > clip.fTop && paint && text.text()) {
canvas->drawPosTextH(text.text(), text.length(), xpos, constY, *paint);
}
} break;
case DRAW_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRect rect;
reader->readRect(&rect);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawRect(rect, *paint);
}
} break;
case DRAW_REGION: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRegion region;
reader->readRegion(®ion);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawRegion(region, *paint);
}
} break;
case DRAW_RRECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
SkRRect rrect;
reader->readRRect(&rrect);
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawRRect(rrect, *paint);
}
} break;
case DRAW_SPRITE: {
/* const SkPaint* paint = */ fPictureData->getPaint(reader);
/* const SkImage* image = */ fPictureData->getBitmapAsImage(reader);
/* int left = */ reader->readInt();
/* int top = */ reader->readInt();
// drawSprite removed dec-2015
} break;
case DRAW_TEXT: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
SkScalar x = reader->readScalar();
SkScalar y = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
if (paint && text.text()) {
canvas->drawText(text.text(), text.length(), x, y, *paint);
}
} break;
case DRAW_TEXT_BLOB: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkTextBlob* blob = fPictureData->getTextBlob(reader);
SkScalar x = reader->readScalar();
SkScalar y = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawTextBlob(blob, x, y, *paint);
}
} break;
case DRAW_TEXT_TOP_BOTTOM: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
const SkScalar* ptr = (const SkScalar*)reader->skip(4 * sizeof(SkScalar));
BREAK_ON_READ_ERROR(reader);
// ptr[0] == x
// ptr[1] == y
// ptr[2] == top
// ptr[3] == bottom
SkRect clip = canvas->getLocalClipBounds();
float top = ptr[2];
float bottom = ptr[3];
if (top < clip.fBottom && bottom > clip.fTop && paint && text.text()) {
canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], *paint);
}
} break;
case DRAW_TEXT_ON_PATH: {
const SkPaint* paint = fPictureData->getPaint(reader);
TextContainer text;
get_text(reader, &text);
const SkPath& path = fPictureData->getPath(reader);
SkMatrix matrix;
reader->readMatrix(&matrix);
BREAK_ON_READ_ERROR(reader);
if (paint && text.text()) {
canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, *paint);
}
} break;
case DRAW_TEXT_RSXFORM: {
const SkPaint* paint = fPictureData->getPaint(reader);
int count = reader->readInt();
uint32_t flags = reader->read32();
TextContainer text;
get_text(reader, &text);
const SkRSXform* xform = (const SkRSXform*)reader->skip(count * sizeof(SkRSXform));
const SkRect* cull = nullptr;
if (flags & DRAW_TEXT_RSXFORM_HAS_CULL) {
cull = (const SkRect*)reader->skip(sizeof(SkRect));
}
BREAK_ON_READ_ERROR(reader);
if (text.text()) {
canvas->drawTextRSXform(text.text(), text.length(), xform, cull, *paint);
}
} break;
case DRAW_VERTICES: {
const SkPaint* paint = fPictureData->getPaint(reader);
DrawVertexFlags flags = (DrawVertexFlags)reader->readInt();
SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt();
int vCount = reader->readInt();
const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
const SkPoint* texs = nullptr;
const SkColor* colors = nullptr;
const uint16_t* indices = nullptr;
int iCount = 0;
if (flags & DRAW_VERTICES_HAS_TEXS) {
texs = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
}
if (flags & DRAW_VERTICES_HAS_COLORS) {
colors = (const SkColor*)reader->skip(vCount * sizeof(SkColor));
}
if (flags & DRAW_VERTICES_HAS_INDICES) {
iCount = reader->readInt();
indices = (const uint16_t*)reader->skip(iCount * sizeof(uint16_t));
}
SkBlendMode bmode = SkBlendMode::kModulate;
if (flags & DRAW_VERTICES_HAS_XFER) {
unsigned mode = reader->readInt();
if (mode <= (unsigned)SkBlendMode::kLastMode) {
bmode = (SkBlendMode)mode;
}
}
BREAK_ON_READ_ERROR(reader);
if (paint) {
canvas->drawVertices(SkVertices::MakeCopy(vmode, vCount, verts, texs, colors,
iCount, indices), bmode, *paint);
}
} break;
case DRAW_VERTICES_OBJECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkVertices* vertices = fPictureData->getVertices(reader);
SkBlendMode bmode = static_cast<SkBlendMode>(reader->readInt());
BREAK_ON_READ_ERROR(reader);
if (paint && vertices) {
canvas->drawVertices(vertices, bmode, *paint);
}
} break;
case RESTORE:
canvas->restore();
break;
case ROTATE: {
auto deg = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
canvas->rotate(deg);
} break;
case SAVE:
canvas->save();
break;
case SAVE_LAYER_SAVEFLAGS_DEPRECATED: {
SkRect storage;
const SkRect* boundsPtr = get_rect_ptr(reader, &storage);
const SkPaint* paint = fPictureData->getPaint(reader);
auto flags = SkCanvas::LegacySaveFlagsToSaveLayerFlags(reader->readInt());
BREAK_ON_READ_ERROR(reader);
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, flags));
} break;
case SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016: {
SkRect storage;
const SkRect* boundsPtr = get_rect_ptr(reader, &storage);
const SkPaint* paint = fPictureData->getPaint(reader);
auto flags = reader->readInt();
BREAK_ON_READ_ERROR(reader);
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, flags));
} break;
case SAVE_LAYER_SAVELAYERREC: {
SkCanvas::SaveLayerRec rec(nullptr, nullptr, nullptr, 0);
const uint32_t flatFlags = reader->readInt();
SkRect bounds;
if (flatFlags & SAVELAYERREC_HAS_BOUNDS) {
reader->readRect(&bounds);
rec.fBounds = &bounds;
}
if (flatFlags & SAVELAYERREC_HAS_PAINT) {
rec.fPaint = fPictureData->getPaint(reader);
}
if (flatFlags & SAVELAYERREC_HAS_BACKDROP) {
if (const auto* paint = fPictureData->getPaint(reader)) {
rec.fBackdrop = paint->getImageFilter();
}
}
if (flatFlags & SAVELAYERREC_HAS_FLAGS) {
rec.fSaveLayerFlags = reader->readInt();
}
BREAK_ON_READ_ERROR(reader);
canvas->saveLayer(rec);
} break;
case SCALE: {
SkScalar sx = reader->readScalar();
SkScalar sy = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
canvas->scale(sx, sy);
} break;
case SET_MATRIX: {
SkMatrix matrix;
reader->readMatrix(&matrix);
BREAK_ON_READ_ERROR(reader);
matrix.postConcat(initialMatrix);
canvas->setMatrix(matrix);
} break;
case SKEW: {
SkScalar sx = reader->readScalar();
SkScalar sy = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
canvas->skew(sx, sy);
} break;
case TRANSLATE: {
SkScalar dx = reader->readScalar();
SkScalar dy = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
canvas->translate(dx, dy);
} break;
case TRANSLATE_Z: {
#ifdef SK_EXPERIMENTAL_SHADOWING
SkScalar dz = reader->readScalar();
BREAK_ON_READ_ERROR(reader);
canvas->translateZ(dz);
#endif
} break;
default:
SkASSERTF(false, "Unknown draw type: %d", op);
}
#undef BREAK_ON_READ_ERROR
}
|