1 | /* |
2 | * Copyright 2014 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #include "include/core/SkCanvas.h" |
9 | #include "include/core/SkRSXform.h" |
10 | #include "include/core/SkTextBlob.h" |
11 | #include "include/core/SkTypes.h" |
12 | #include "include/private/SkTDArray.h" |
13 | #include "src/core/SkCanvasPriv.h" |
14 | #include "src/core/SkDrawShadowInfo.h" |
15 | #include "src/core/SkFontPriv.h" |
16 | #include "src/core/SkPaintPriv.h" |
17 | #include "src/core/SkPictureData.h" |
18 | #include "src/core/SkPicturePlayback.h" |
19 | #include "src/core/SkPictureRecord.h" |
20 | #include "src/core/SkReadBuffer.h" |
21 | #include "src/core/SkSafeMath.h" |
22 | #include "src/core/SkVerticesPriv.h" |
23 | #include "src/utils/SkPatchUtils.h" |
24 | |
25 | // matches old SkCanvas::SaveFlags |
26 | enum LegacySaveFlags { |
27 | kClipToLayer_LegacySaveFlags = 0x10, |
28 | }; |
29 | |
30 | SkCanvas::SaveLayerFlags SkCanvasPriv::LegacySaveFlagsToSaveLayerFlags(uint32_t flags) { |
31 | uint32_t layerFlags = 0; |
32 | |
33 | if (0 == (flags & kClipToLayer_LegacySaveFlags)) { |
34 | layerFlags |= kDontClipToLayer_SaveLayerFlag; |
35 | } |
36 | return layerFlags; |
37 | } |
38 | |
39 | static const SkRect* get_rect_ptr(SkReadBuffer* reader, SkRect* storage) { |
40 | if (reader->readBool()) { |
41 | reader->readRect(storage); |
42 | return storage; |
43 | } else { |
44 | return nullptr; |
45 | } |
46 | } |
47 | |
48 | void SkPicturePlayback::draw(SkCanvas* canvas, |
49 | SkPicture::AbortCallback* callback, |
50 | SkReadBuffer* buffer) { |
51 | AutoResetOpID aroi(this); |
52 | SkASSERT(0 == fCurOffset); |
53 | |
54 | SkReadBuffer reader(fPictureData->opData()->bytes(), |
55 | fPictureData->opData()->size()); |
56 | |
57 | // Record this, so we can concat w/ it if we encounter a setMatrix() |
58 | SkMatrix initialMatrix = canvas->getTotalMatrix(); |
59 | |
60 | SkAutoCanvasRestore acr(canvas, false); |
61 | |
62 | while (!reader.eof()) { |
63 | if (callback && callback->abort()) { |
64 | return; |
65 | } |
66 | |
67 | fCurOffset = reader.offset(); |
68 | |
69 | uint32_t bits = reader.readInt(); |
70 | uint32_t op = bits >> 24, |
71 | size = bits & 0xffffff; |
72 | if (size == 0xffffff) { |
73 | size = reader.readInt(); |
74 | } |
75 | |
76 | if (!reader.validate(size > 0 && op > UNUSED && op <= LAST_DRAWTYPE_ENUM)) { |
77 | return; |
78 | } |
79 | |
80 | this->handleOp(&reader, (DrawType)op, size, canvas, initialMatrix); |
81 | } |
82 | |
83 | // need to propagate invalid state to the parent reader |
84 | if (buffer) { |
85 | buffer->validate(reader.isValid()); |
86 | } |
87 | } |
88 | |
89 | static void validate_offsetToRestore(SkReadBuffer* reader, size_t offsetToRestore) { |
90 | if (offsetToRestore) { |
91 | reader->validate(SkIsAlign4(offsetToRestore) && offsetToRestore >= reader->offset()); |
92 | } |
93 | } |
94 | |
95 | void SkPicturePlayback::handleOp(SkReadBuffer* reader, |
96 | DrawType op, |
97 | uint32_t size, |
98 | SkCanvas* canvas, |
99 | const SkMatrix& initialMatrix) { |
100 | #define BREAK_ON_READ_ERROR(r) if (!r->isValid()) break |
101 | |
102 | switch (op) { |
103 | case NOOP: { |
104 | SkASSERT(size >= 4); |
105 | reader->skip(size - 4); |
106 | } break; |
107 | case FLUSH: |
108 | canvas->flush(); |
109 | break; |
110 | case CLIP_PATH: { |
111 | const SkPath& path = fPictureData->getPath(reader); |
112 | uint32_t packed = reader->readInt(); |
113 | SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed); |
114 | bool doAA = ClipParams_unpackDoAA(packed); |
115 | size_t offsetToRestore = reader->readInt(); |
116 | validate_offsetToRestore(reader, offsetToRestore); |
117 | BREAK_ON_READ_ERROR(reader); |
118 | |
119 | canvas->clipPath(path, clipOp, doAA); |
120 | if (canvas->isClipEmpty() && offsetToRestore) { |
121 | reader->skip(offsetToRestore - reader->offset()); |
122 | } |
123 | } break; |
124 | case CLIP_REGION: { |
125 | SkRegion region; |
126 | reader->readRegion(®ion); |
127 | uint32_t packed = reader->readInt(); |
128 | SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed); |
129 | size_t offsetToRestore = reader->readInt(); |
130 | validate_offsetToRestore(reader, offsetToRestore); |
131 | BREAK_ON_READ_ERROR(reader); |
132 | |
133 | canvas->clipRegion(region, clipOp); |
134 | if (canvas->isClipEmpty() && offsetToRestore) { |
135 | reader->skip(offsetToRestore - reader->offset()); |
136 | } |
137 | } break; |
138 | case CLIP_RECT: { |
139 | SkRect rect; |
140 | reader->readRect(&rect); |
141 | uint32_t packed = reader->readInt(); |
142 | SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed); |
143 | bool doAA = ClipParams_unpackDoAA(packed); |
144 | size_t offsetToRestore = reader->readInt(); |
145 | validate_offsetToRestore(reader, offsetToRestore); |
146 | BREAK_ON_READ_ERROR(reader); |
147 | |
148 | canvas->clipRect(rect, clipOp, doAA); |
149 | if (canvas->isClipEmpty() && offsetToRestore) { |
150 | reader->skip(offsetToRestore - reader->offset()); |
151 | } |
152 | } break; |
153 | case CLIP_RRECT: { |
154 | SkRRect rrect; |
155 | reader->readRRect(&rrect); |
156 | uint32_t packed = reader->readInt(); |
157 | SkClipOp clipOp = ClipParams_unpackRegionOp(reader, packed); |
158 | bool doAA = ClipParams_unpackDoAA(packed); |
159 | size_t offsetToRestore = reader->readInt(); |
160 | validate_offsetToRestore(reader, offsetToRestore); |
161 | BREAK_ON_READ_ERROR(reader); |
162 | |
163 | canvas->clipRRect(rrect, clipOp, doAA); |
164 | if (canvas->isClipEmpty() && offsetToRestore) { |
165 | reader->skip(offsetToRestore - reader->offset()); |
166 | } |
167 | } break; |
168 | case CLIP_SHADER_IN_PAINT: { |
169 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
170 | SkClipOp clipOp = reader->checkRange(SkClipOp::kDifference, SkClipOp::kIntersect); |
171 | BREAK_ON_READ_ERROR(reader); |
172 | |
173 | canvas->clipShader(paint.refShader(), clipOp); |
174 | } break; |
175 | case PUSH_CULL: break; // Deprecated, safe to ignore both push and pop. |
176 | case POP_CULL: break; |
177 | case CONCAT: { |
178 | SkMatrix matrix; |
179 | reader->readMatrix(&matrix); |
180 | BREAK_ON_READ_ERROR(reader); |
181 | |
182 | canvas->concat(matrix); |
183 | break; |
184 | } |
185 | case CONCAT44: { |
186 | const SkScalar* colMaj = reader->skipT<SkScalar>(16); |
187 | BREAK_ON_READ_ERROR(reader); |
188 | canvas->concat(SkM44::ColMajor(colMaj)); |
189 | break; |
190 | } |
191 | case DRAW_ANNOTATION: { |
192 | SkRect rect; |
193 | reader->readRect(&rect); |
194 | SkString key; |
195 | reader->readString(&key); |
196 | sk_sp<SkData> data = reader->readByteArrayAsData(); |
197 | BREAK_ON_READ_ERROR(reader); |
198 | SkASSERT(data); |
199 | |
200 | canvas->drawAnnotation(rect, key.c_str(), data.get()); |
201 | } break; |
202 | case DRAW_ARC: { |
203 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
204 | SkRect rect; |
205 | reader->readRect(&rect); |
206 | SkScalar startAngle = reader->readScalar(); |
207 | SkScalar sweepAngle = reader->readScalar(); |
208 | int useCenter = reader->readInt(); |
209 | BREAK_ON_READ_ERROR(reader); |
210 | |
211 | canvas->drawArc(rect, startAngle, sweepAngle, SkToBool(useCenter), paint); |
212 | } break; |
213 | case DRAW_ATLAS: { |
214 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
215 | const SkImage* atlas = fPictureData->getImage(reader); |
216 | const uint32_t flags = reader->readUInt(); |
217 | const int count = reader->readUInt(); |
218 | const SkRSXform* xform = (const SkRSXform*)reader->skip(count, sizeof(SkRSXform)); |
219 | const SkRect* tex = (const SkRect*)reader->skip(count, sizeof(SkRect)); |
220 | const SkColor* colors = nullptr; |
221 | SkBlendMode mode = SkBlendMode::kDst; |
222 | if (flags & DRAW_ATLAS_HAS_COLORS) { |
223 | colors = (const SkColor*)reader->skip(count, sizeof(SkColor)); |
224 | mode = (SkBlendMode)reader->readUInt(); |
225 | } |
226 | const SkRect* cull = nullptr; |
227 | if (flags & DRAW_ATLAS_HAS_CULL) { |
228 | cull = (const SkRect*)reader->skip(sizeof(SkRect)); |
229 | } |
230 | BREAK_ON_READ_ERROR(reader); |
231 | |
232 | canvas->drawAtlas(atlas, xform, tex, colors, count, mode, cull, paint); |
233 | } break; |
234 | case DRAW_CLEAR: { |
235 | auto c = reader->readInt(); |
236 | BREAK_ON_READ_ERROR(reader); |
237 | |
238 | canvas->clear(c); |
239 | } break; |
240 | case DRAW_DATA: { |
241 | // This opcode is now dead, just need to skip it for backwards compatibility |
242 | size_t length = reader->readInt(); |
243 | (void)reader->skip(length); |
244 | // skip handles padding the read out to a multiple of 4 |
245 | } break; |
246 | case DRAW_DRAWABLE: { |
247 | auto* d = fPictureData->getDrawable(reader); |
248 | BREAK_ON_READ_ERROR(reader); |
249 | |
250 | canvas->drawDrawable(d); |
251 | } break; |
252 | case DRAW_DRAWABLE_MATRIX: { |
253 | SkMatrix matrix; |
254 | reader->readMatrix(&matrix); |
255 | SkDrawable* drawable = fPictureData->getDrawable(reader); |
256 | BREAK_ON_READ_ERROR(reader); |
257 | |
258 | canvas->drawDrawable(drawable, &matrix); |
259 | } break; |
260 | case DRAW_DRRECT: { |
261 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
262 | SkRRect outer, inner; |
263 | reader->readRRect(&outer); |
264 | reader->readRRect(&inner); |
265 | BREAK_ON_READ_ERROR(reader); |
266 | |
267 | canvas->drawDRRect(outer, inner, paint); |
268 | } break; |
269 | case DRAW_EDGEAA_QUAD: { |
270 | SkRect rect; |
271 | reader->readRect(&rect); |
272 | SkCanvas::QuadAAFlags aaFlags = static_cast<SkCanvas::QuadAAFlags>(reader->read32()); |
273 | SkColor4f color; |
274 | reader->readColor4f(&color); |
275 | SkBlendMode blend = static_cast<SkBlendMode>(reader->read32()); |
276 | bool hasClip = reader->readInt(); |
277 | SkPoint* clip = nullptr; |
278 | if (hasClip) { |
279 | clip = (SkPoint*) reader->skip(4, sizeof(SkPoint)); |
280 | } |
281 | BREAK_ON_READ_ERROR(reader); |
282 | canvas->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color, blend); |
283 | } break; |
284 | case DRAW_EDGEAA_IMAGE_SET: { |
285 | static const size_t kEntryReadSize = |
286 | 4 * sizeof(uint32_t) + 2 * sizeof(SkRect) + sizeof(SkScalar); |
287 | static const size_t kMatrixSize = 9 * sizeof(SkScalar); // != sizeof(SkMatrix) |
288 | |
289 | int cnt = reader->readInt(); |
290 | if (!reader->validate(cnt >= 0)) { |
291 | break; |
292 | } |
293 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
294 | |
295 | SkCanvas::SrcRectConstraint constraint = |
296 | reader->checkRange(SkCanvas::kStrict_SrcRectConstraint, |
297 | SkCanvas::kFast_SrcRectConstraint); |
298 | |
299 | if (!reader->validate(SkSafeMath::Mul(cnt, kEntryReadSize) <= reader->available())) { |
300 | break; |
301 | } |
302 | |
303 | // Track minimum necessary clip points and matrices that must be provided to satisfy |
304 | // the entries. |
305 | int expectedClips = 0; |
306 | int maxMatrixIndex = -1; |
307 | SkAutoTArray<SkCanvas::ImageSetEntry> set(cnt); |
308 | for (int i = 0; i < cnt && reader->isValid(); ++i) { |
309 | set[i].fImage = sk_ref_sp(fPictureData->getImage(reader)); |
310 | reader->readRect(&set[i].fSrcRect); |
311 | reader->readRect(&set[i].fDstRect); |
312 | set[i].fMatrixIndex = reader->readInt(); |
313 | set[i].fAlpha = reader->readScalar(); |
314 | set[i].fAAFlags = reader->readUInt(); |
315 | set[i].fHasClip = reader->readInt(); |
316 | |
317 | expectedClips += set[i].fHasClip ? 1 : 0; |
318 | if (set[i].fMatrixIndex > maxMatrixIndex) { |
319 | maxMatrixIndex = set[i].fMatrixIndex; |
320 | } |
321 | } |
322 | |
323 | int dstClipCount = reader->readInt(); |
324 | SkPoint* dstClips = nullptr; |
325 | if (!reader->validate(expectedClips <= dstClipCount)) { |
326 | // Entries request more dstClip points than are provided in the buffer |
327 | break; |
328 | } else if (dstClipCount > 0) { |
329 | dstClips = (SkPoint*) reader->skip(dstClipCount, sizeof(SkPoint)); |
330 | if (dstClips == nullptr) { |
331 | // Not enough bytes remaining so the reader has been invalidated |
332 | break; |
333 | } |
334 | } |
335 | int matrixCount = reader->readInt(); |
336 | if (!reader->validate((maxMatrixIndex + 1) <= matrixCount) || |
337 | !reader->validate( |
338 | SkSafeMath::Mul(matrixCount, kMatrixSize) <= reader->available())) { |
339 | // Entries access out-of-bound matrix indices, given provided matrices or |
340 | // there aren't enough bytes to provide that many matrices |
341 | break; |
342 | } |
343 | SkTArray<SkMatrix> matrices(matrixCount); |
344 | for (int i = 0; i < matrixCount && reader->isValid(); ++i) { |
345 | reader->readMatrix(&matrices.push_back()); |
346 | } |
347 | BREAK_ON_READ_ERROR(reader); |
348 | |
349 | canvas->experimental_DrawEdgeAAImageSet(set.get(), cnt, dstClips, matrices.begin(), |
350 | paint, constraint); |
351 | } break; |
352 | case DRAW_IMAGE: { |
353 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
354 | const SkImage* image = fPictureData->getImage(reader); |
355 | SkPoint loc; |
356 | reader->readPoint(&loc); |
357 | BREAK_ON_READ_ERROR(reader); |
358 | |
359 | canvas->drawImage(image, loc.fX, loc.fY, paint); |
360 | } break; |
361 | case DRAW_IMAGE_LATTICE: { |
362 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
363 | const SkImage* image = fPictureData->getImage(reader); |
364 | SkCanvas::Lattice lattice; |
365 | (void)SkCanvasPriv::ReadLattice(*reader, &lattice); |
366 | const SkRect* dst = reader->skipT<SkRect>(); |
367 | BREAK_ON_READ_ERROR(reader); |
368 | |
369 | canvas->drawImageLattice(image, lattice, *dst, paint); |
370 | } break; |
371 | case DRAW_IMAGE_NINE: { |
372 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
373 | const SkImage* image = fPictureData->getImage(reader); |
374 | SkIRect center; |
375 | reader->readIRect(¢er); |
376 | SkRect dst; |
377 | reader->readRect(&dst); |
378 | BREAK_ON_READ_ERROR(reader); |
379 | |
380 | canvas->drawImageNine(image, center, dst, paint); |
381 | } break; |
382 | case DRAW_IMAGE_RECT: { |
383 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
384 | const SkImage* image = fPictureData->getImage(reader); |
385 | SkRect storage; |
386 | const SkRect* src = get_rect_ptr(reader, &storage); // may be null |
387 | SkRect dst; |
388 | reader->readRect(&dst); // required |
389 | // DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it |
390 | SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint; |
391 | if (DRAW_IMAGE_RECT == op) { |
392 | // newer op-code stores the constraint explicitly |
393 | constraint = reader->checkRange(SkCanvas::kStrict_SrcRectConstraint, |
394 | SkCanvas::kFast_SrcRectConstraint); |
395 | } |
396 | BREAK_ON_READ_ERROR(reader); |
397 | |
398 | canvas->legacy_drawImageRect(image, src, dst, paint, constraint); |
399 | } break; |
400 | case DRAW_OVAL: { |
401 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
402 | SkRect rect; |
403 | reader->readRect(&rect); |
404 | BREAK_ON_READ_ERROR(reader); |
405 | |
406 | canvas->drawOval(rect, paint); |
407 | } break; |
408 | case DRAW_PAINT: { |
409 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
410 | BREAK_ON_READ_ERROR(reader); |
411 | |
412 | canvas->drawPaint(paint); |
413 | } break; |
414 | case DRAW_BEHIND_PAINT: { |
415 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
416 | BREAK_ON_READ_ERROR(reader); |
417 | |
418 | SkCanvasPriv::DrawBehind(canvas, paint); |
419 | } break; |
420 | case DRAW_PATCH: { |
421 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
422 | |
423 | const SkPoint* cubics = (const SkPoint*)reader->skip(SkPatchUtils::kNumCtrlPts, |
424 | sizeof(SkPoint)); |
425 | uint32_t flag = reader->readInt(); |
426 | const SkColor* colors = nullptr; |
427 | if (flag & DRAW_VERTICES_HAS_COLORS) { |
428 | colors = (const SkColor*)reader->skip(SkPatchUtils::kNumCorners, sizeof(SkColor)); |
429 | } |
430 | const SkPoint* texCoords = nullptr; |
431 | if (flag & DRAW_VERTICES_HAS_TEXS) { |
432 | texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorners, |
433 | sizeof(SkPoint)); |
434 | } |
435 | SkBlendMode bmode = SkBlendMode::kModulate; |
436 | if (flag & DRAW_VERTICES_HAS_XFER) { |
437 | unsigned mode = reader->readInt(); |
438 | if (mode <= (unsigned)SkBlendMode::kLastMode) { |
439 | bmode = (SkBlendMode)mode; |
440 | } |
441 | } |
442 | BREAK_ON_READ_ERROR(reader); |
443 | |
444 | canvas->drawPatch(cubics, colors, texCoords, bmode, paint); |
445 | } break; |
446 | case DRAW_PATH: { |
447 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
448 | const auto& path = fPictureData->getPath(reader); |
449 | BREAK_ON_READ_ERROR(reader); |
450 | |
451 | canvas->drawPath(path, paint); |
452 | } break; |
453 | case DRAW_PICTURE: { |
454 | const auto* pic = fPictureData->getPicture(reader); |
455 | BREAK_ON_READ_ERROR(reader); |
456 | |
457 | canvas->drawPicture(pic); |
458 | } break; |
459 | case DRAW_PICTURE_MATRIX_PAINT: { |
460 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
461 | SkMatrix matrix; |
462 | reader->readMatrix(&matrix); |
463 | const SkPicture* pic = fPictureData->getPicture(reader); |
464 | BREAK_ON_READ_ERROR(reader); |
465 | |
466 | canvas->drawPicture(pic, &matrix, paint); |
467 | } break; |
468 | case DRAW_POINTS: { |
469 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
470 | SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt(); |
471 | size_t count = reader->readInt(); |
472 | const SkPoint* pts = (const SkPoint*)reader->skip(count, sizeof(SkPoint)); |
473 | BREAK_ON_READ_ERROR(reader); |
474 | |
475 | canvas->drawPoints(mode, count, pts, paint); |
476 | } break; |
477 | case DRAW_RECT: { |
478 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
479 | SkRect rect; |
480 | reader->readRect(&rect); |
481 | BREAK_ON_READ_ERROR(reader); |
482 | |
483 | canvas->drawRect(rect, paint); |
484 | } break; |
485 | case DRAW_REGION: { |
486 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
487 | SkRegion region; |
488 | reader->readRegion(®ion); |
489 | BREAK_ON_READ_ERROR(reader); |
490 | |
491 | canvas->drawRegion(region, paint); |
492 | } break; |
493 | case DRAW_RRECT: { |
494 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
495 | SkRRect rrect; |
496 | reader->readRRect(&rrect); |
497 | BREAK_ON_READ_ERROR(reader); |
498 | |
499 | canvas->drawRRect(rrect, paint); |
500 | } break; |
501 | case DRAW_SHADOW_REC: { |
502 | const auto& path = fPictureData->getPath(reader); |
503 | SkDrawShadowRec rec; |
504 | reader->readPoint3(&rec.fZPlaneParams); |
505 | reader->readPoint3(&rec.fLightPos); |
506 | rec.fLightRadius = reader->readScalar(); |
507 | rec.fAmbientColor = reader->read32(); |
508 | rec.fSpotColor = reader->read32(); |
509 | rec.fFlags = reader->read32(); |
510 | BREAK_ON_READ_ERROR(reader); |
511 | |
512 | canvas->private_draw_shadow_rec(path, rec); |
513 | } break; |
514 | case DRAW_TEXT_BLOB: { |
515 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
516 | const SkTextBlob* blob = fPictureData->getTextBlob(reader); |
517 | SkScalar x = reader->readScalar(); |
518 | SkScalar y = reader->readScalar(); |
519 | BREAK_ON_READ_ERROR(reader); |
520 | |
521 | canvas->drawTextBlob(blob, x, y, paint); |
522 | } break; |
523 | case DRAW_VERTICES_OBJECT: { |
524 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
525 | const SkVertices* vertices = fPictureData->getVertices(reader); |
526 | const int boneCount = reader->readInt(); |
527 | (void)reader->skip(boneCount, sizeof(SkVertices_DeprecatedBone)); |
528 | SkBlendMode bmode = reader->read32LE(SkBlendMode::kLastMode); |
529 | BREAK_ON_READ_ERROR(reader); |
530 | |
531 | if (vertices) { // TODO: read error if vertices == null? |
532 | canvas->drawVertices(vertices, bmode, paint); |
533 | } |
534 | } break; |
535 | case MARK_CTM: { |
536 | SkString name; |
537 | reader->readString(&name); |
538 | BREAK_ON_READ_ERROR(reader); |
539 | canvas->markCTM(name.c_str()); |
540 | } break; |
541 | case RESTORE: |
542 | canvas->restore(); |
543 | break; |
544 | case ROTATE: { |
545 | auto deg = reader->readScalar(); |
546 | canvas->rotate(deg); |
547 | } break; |
548 | case SAVE: |
549 | canvas->save(); |
550 | break; |
551 | case SAVE_BEHIND: { |
552 | uint32_t flags = reader->readInt(); |
553 | const SkRect* subset = nullptr; |
554 | SkRect storage; |
555 | if (flags & SAVEBEHIND_HAS_SUBSET) { |
556 | reader->readRect(&storage); |
557 | subset = &storage; |
558 | } |
559 | SkCanvasPriv::SaveBehind(canvas, subset); |
560 | } break; |
561 | case SAVE_LAYER_SAVEFLAGS_DEPRECATED: { |
562 | SkRect storage; |
563 | const SkRect* boundsPtr = get_rect_ptr(reader, &storage); |
564 | const SkPaint* paint = fPictureData->optionalPaint(reader); |
565 | auto flags = SkCanvasPriv::LegacySaveFlagsToSaveLayerFlags(reader->readInt()); |
566 | BREAK_ON_READ_ERROR(reader); |
567 | |
568 | canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, flags)); |
569 | } break; |
570 | case SAVE_LAYER_SAVELAYERREC: { |
571 | SkCanvas::SaveLayerRec rec(nullptr, nullptr, nullptr, 0); |
572 | const uint32_t flatFlags = reader->readInt(); |
573 | SkRect bounds; |
574 | if (flatFlags & SAVELAYERREC_HAS_BOUNDS) { |
575 | reader->readRect(&bounds); |
576 | rec.fBounds = &bounds; |
577 | } |
578 | if (flatFlags & SAVELAYERREC_HAS_PAINT) { |
579 | rec.fPaint = &fPictureData->requiredPaint(reader); |
580 | } |
581 | if (flatFlags & SAVELAYERREC_HAS_BACKDROP) { |
582 | const SkPaint& paint = fPictureData->requiredPaint(reader); |
583 | rec.fBackdrop = paint.getImageFilter(); |
584 | } |
585 | if (flatFlags & SAVELAYERREC_HAS_FLAGS) { |
586 | rec.fSaveLayerFlags = reader->readInt(); |
587 | } |
588 | if (flatFlags & SAVELAYERREC_HAS_CLIPMASK_OBSOLETE) { |
589 | (void)fPictureData->getImage(reader); |
590 | } |
591 | if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX_OBSOLETE) { |
592 | SkMatrix clipMatrix_ignored; |
593 | reader->readMatrix(&clipMatrix_ignored); |
594 | } |
595 | BREAK_ON_READ_ERROR(reader); |
596 | |
597 | canvas->saveLayer(rec); |
598 | } break; |
599 | case SCALE: { |
600 | SkScalar sx = reader->readScalar(); |
601 | SkScalar sy = reader->readScalar(); |
602 | canvas->scale(sx, sy); |
603 | } break; |
604 | case SET_MATRIX: { |
605 | SkMatrix matrix; |
606 | reader->readMatrix(&matrix); |
607 | matrix.postConcat(initialMatrix); |
608 | canvas->setMatrix(matrix); |
609 | } break; |
610 | case SKEW: { |
611 | SkScalar sx = reader->readScalar(); |
612 | SkScalar sy = reader->readScalar(); |
613 | canvas->skew(sx, sy); |
614 | } break; |
615 | case TRANSLATE: { |
616 | SkScalar dx = reader->readScalar(); |
617 | SkScalar dy = reader->readScalar(); |
618 | canvas->translate(dx, dy); |
619 | } break; |
620 | default: |
621 | reader->validate(false); // unknown op |
622 | break; |
623 | } |
624 | |
625 | #undef BREAK_ON_READ_ERROR |
626 | } |
627 | |