OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkPictureData.h" | 9 #include "SkPictureData.h" |
10 #include "SkPicturePlayback.h" | 10 #include "SkPicturePlayback.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 } else { | 87 } else { |
88 UNPACK_8_24(temp, op, *size); | 88 UNPACK_8_24(temp, op, *size); |
89 if (MASK_24 == *size) { | 89 if (MASK_24 == *size) { |
90 *size = reader->readInt(); | 90 *size = reader->readInt(); |
91 } | 91 } |
92 } | 92 } |
93 return (DrawType)op; | 93 return (DrawType)op; |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 static const SkRect* get_rect_ptr(SkReader32& reader) { | 97 static const SkRect* get_rect_ptr(SkReader32* reader) { |
98 if (reader.readBool()) { | 98 if (reader->readBool()) { |
99 return &reader.skipT<SkRect>(); | 99 return &reader->skipT<SkRect>(); |
100 } else { | 100 } else { |
101 return NULL; | 101 return NULL; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 class TextContainer { | 105 class TextContainer { |
106 public: | 106 public: |
107 size_t length() { return fByteLength; } | 107 size_t length() { return fByteLength; } |
108 const void* text() { return (const void*)fText; } | 108 const void* text() { return (const void*)fText; } |
109 size_t fByteLength; | 109 size_t fByteLength; |
110 const char* fText; | 110 const char* fText; |
111 }; | 111 }; |
112 | 112 |
113 void get_text(SkReader32* reader, TextContainer* text) { | 113 void get_text(SkReader32* reader, TextContainer* text) { |
114 size_t length = text->fByteLength = reader->readInt(); | 114 size_t length = text->fByteLength = reader->readInt(); |
115 text->fText = (const char*)reader->skip(length); | 115 text->fText = (const char*)reader->skip(length); |
116 } | 116 } |
117 | 117 |
118 // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multip le threads. | 118 // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multip le threads. |
119 static SkBitmap shallow_copy(const SkBitmap& bitmap) { | 119 static SkBitmap shallow_copy(const SkBitmap& bitmap) { |
120 return bitmap; | 120 return bitmap; |
121 } | 121 } |
122 | 122 |
123 void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback) { | 123 void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback) { |
124 SkAutoResetOpID aroi(this); | 124 SkAutoResetOpID aroi(this); |
125 SkASSERT(0 == fCurOffset); | 125 SkASSERT(0 == fCurOffset); |
126 | 126 |
127 #ifdef ENABLE_TIME_DRAW | |
128 SkAutoTime at("SkPicture::draw", 50); | |
129 #endif | |
130 | |
131 #ifdef SPEW_CLIP_SKIPPING | |
132 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; | |
133 int opCount = 0; | |
134 #endif | |
135 | |
136 // kDrawComplete will be the signal that we have reached the end of | 127 // kDrawComplete will be the signal that we have reached the end of |
137 // the command stream | 128 // the command stream |
138 static const uint32_t kDrawComplete = SK_MaxU32; | 129 static const uint32_t kDrawComplete = SK_MaxU32; |
139 | 130 |
140 SkReader32 reader(fPictureData->fOpData->bytes(), fPictureData->fOpData->siz e()); | 131 SkReader32 reader(fPictureData->fOpData->bytes(), fPictureData->fOpData->siz e()); |
141 TextContainer text; | |
142 SkAutoTDelete<const SkPicture::OperationList> activeOpsList; | 132 SkAutoTDelete<const SkPicture::OperationList> activeOpsList; |
143 const SkTDArray<void*>* activeOps = NULL; | 133 const SkTDArray<void*>* activeOps = NULL; |
144 | 134 |
145 // When draw limits are enabled (i.e., 0 != fStart || 0 != fStop) the state | 135 // When draw limits are enabled (i.e., 0 != fStart || 0 != fStop) the state |
146 // tree isn't used to pick and choose the draw operations | 136 // tree isn't used to pick and choose the draw operations |
147 if (0 == fStart && 0 == fStop) { | 137 if (0 == fStart && 0 == fStop) { |
148 if (fUseBBH && NULL != fPictureData->fStateTree && NULL != fPictureData- >fBoundingHierarchy) { | 138 if (fUseBBH && NULL != fPictureData->fStateTree && NULL != fPictureData- >fBoundingHierarchy) { |
149 SkRect clipBounds; | 139 SkRect clipBounds; |
150 if (canvas->getClipBounds(&clipBounds)) { | 140 if (canvas->getClipBounds(&clipBounds)) { |
151 SkIRect query; | 141 SkIRect query; |
152 clipBounds.roundOut(&query); | 142 clipBounds.roundOut(&query); |
153 | 143 |
154 activeOpsList.reset(fPictureData->getActiveOps(query)); | 144 activeOpsList.reset(fPictureData->getActiveOps(query)); |
155 if (NULL != activeOpsList.get()) { | 145 if (NULL != activeOpsList.get()) { |
156 if (0 == activeOpsList->numOps()) { | 146 if (0 == activeOpsList->numOps()) { |
157 return; // nothing to draw | 147 return; // nothing to draw |
158 } | 148 } |
159 | 149 |
160 // Since the opList is valid we know it is our derived class | 150 // Since the opList is valid we know it is our derived class |
mtklein
2014/07/08 12:55:13
Remove the comment too?
| |
161 activeOps = &((const SkPictureData::OperationList*)activeOps List.get())->fOps; | 151 activeOps = &(activeOpsList.get()->fOps); |
162 } | 152 } |
163 } | 153 } |
164 } | 154 } |
165 } | 155 } |
166 | 156 |
167 SkPictureStateTree::Iterator it = (NULL == activeOps) ? | 157 SkPictureStateTree::Iterator it = (NULL == activeOps) ? |
168 SkPictureStateTree::Iterator() : | 158 SkPictureStateTree::Iterator() : |
169 fPictureData->fStateTree->getIterator(*activeOps, canvas); | 159 fPictureData->fStateTree->getIterator(*activeOps, canvas); |
170 | 160 |
171 if (0 != fStart || 0 != fStop) { | 161 if (0 != fStart || 0 != fStop) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 } else { | 255 } else { |
266 reader.setOffset(temp->fStop); | 256 reader.setOffset(temp->fStop); |
267 uint32_t size; | 257 uint32_t size; |
268 SkDEBUGCODE(DrawType op = ) read_op_and_size(&reader, &size) ; | 258 SkDEBUGCODE(DrawType op = ) read_op_and_size(&reader, &size) ; |
269 SkASSERT(RESTORE == op); | 259 SkASSERT(RESTORE == op); |
270 } | 260 } |
271 continue; | 261 continue; |
272 } | 262 } |
273 } | 263 } |
274 | 264 |
275 #ifdef SPEW_CLIP_SKIPPING | |
276 opCount++; | |
277 #endif | |
278 | |
279 fCurOffset = reader.offset(); | 265 fCurOffset = reader.offset(); |
280 uint32_t size; | 266 uint32_t size; |
281 DrawType op = read_op_and_size(&reader, &size); | 267 DrawType op = read_op_and_size(&reader, &size); |
282 size_t skipTo = 0; | 268 size_t skipTo = 0; |
283 if (NOOP == op) { | 269 if (NOOP == op) { |
284 // NOOPs are to be ignored - do not propagate them any further | 270 // NOOPs are to be ignored - do not propagate them any further |
285 skipTo = fCurOffset + size; | 271 skipTo = fCurOffset + size; |
286 #ifdef SK_DEVELOPER | 272 #ifdef SK_DEVELOPER |
287 } else { | 273 } else { |
288 opIndex++; | 274 opIndex++; |
(...skipping 13 matching lines...) Expand all Loading... | |
302 } while (adjustedSkipTo < skipTo); | 288 } while (adjustedSkipTo < skipTo); |
303 skipTo = adjustedSkipTo; | 289 skipTo = adjustedSkipTo; |
304 } | 290 } |
305 if (kDrawComplete == skipTo) { | 291 if (kDrawComplete == skipTo) { |
306 break; | 292 break; |
307 } | 293 } |
308 reader.setOffset(skipTo); | 294 reader.setOffset(skipTo); |
309 continue; | 295 continue; |
310 } | 296 } |
311 | 297 |
312 switch (op) { | 298 this->handleOp(&reader, op, size, canvas, initialMatrix); |
299 | |
300 #ifdef SK_DEVELOPER | |
301 this->postDraw(opIndex); | |
302 #endif | |
303 | |
304 if (it.isValid()) { | |
305 uint32_t skipTo = it.nextDraw(); | |
306 if (kDrawComplete == skipTo) { | |
307 break; | |
308 } | |
309 reader.setOffset(skipTo); | |
310 } | |
311 } | |
312 } | |
313 | |
314 void SkPicturePlayback::handleOp(SkReader32* reader, | |
315 DrawType op, | |
316 uint32_t size, | |
317 SkCanvas* canvas, | |
318 const SkMatrix& initialMatrix) { | |
319 switch (op) { | |
313 case CLIP_PATH: { | 320 case CLIP_PATH: { |
314 const SkPath& path = fPictureData->getPath(reader); | 321 const SkPath& path = fPictureData->getPath(reader); |
315 uint32_t packed = reader.readInt(); | 322 uint32_t packed = reader->readInt(); |
316 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); | 323 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); |
317 bool doAA = ClipParams_unpackDoAA(packed); | 324 bool doAA = ClipParams_unpackDoAA(packed); |
318 size_t offsetToRestore = reader.readInt(); | 325 size_t offsetToRestore = reader->readInt(); |
319 SkASSERT(!offsetToRestore || offsetToRestore >= reader.offset()); | 326 SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset()); |
320 canvas->clipPath(path, regionOp, doAA); | 327 canvas->clipPath(path, regionOp, doAA); |
321 if (canvas->isClipEmpty() && offsetToRestore) { | 328 if (canvas->isClipEmpty() && offsetToRestore) { |
322 #ifdef SPEW_CLIP_SKIPPING | 329 reader->setOffset(offsetToRestore); |
323 skipPath.recordSkip(offsetToRestore - reader.offset()); | |
324 #endif | |
325 reader.setOffset(offsetToRestore); | |
326 } | 330 } |
327 } break; | 331 } break; |
328 case CLIP_REGION: { | 332 case CLIP_REGION: { |
329 SkRegion region; | 333 SkRegion region; |
330 reader.readRegion(®ion); | 334 reader->readRegion(®ion); |
331 uint32_t packed = reader.readInt(); | 335 uint32_t packed = reader->readInt(); |
332 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); | 336 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); |
333 size_t offsetToRestore = reader.readInt(); | 337 size_t offsetToRestore = reader->readInt(); |
334 SkASSERT(!offsetToRestore || offsetToRestore >= reader.offset()); | 338 SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset()); |
335 canvas->clipRegion(region, regionOp); | 339 canvas->clipRegion(region, regionOp); |
336 if (canvas->isClipEmpty() && offsetToRestore) { | 340 if (canvas->isClipEmpty() && offsetToRestore) { |
337 #ifdef SPEW_CLIP_SKIPPING | 341 reader->setOffset(offsetToRestore); |
338 skipRegion.recordSkip(offsetToRestore - reader.offset()); | |
339 #endif | |
340 reader.setOffset(offsetToRestore); | |
341 } | 342 } |
342 } break; | 343 } break; |
343 case CLIP_RECT: { | 344 case CLIP_RECT: { |
344 const SkRect& rect = reader.skipT<SkRect>(); | 345 const SkRect& rect = reader->skipT<SkRect>(); |
345 uint32_t packed = reader.readInt(); | 346 uint32_t packed = reader->readInt(); |
346 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); | 347 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); |
347 bool doAA = ClipParams_unpackDoAA(packed); | 348 bool doAA = ClipParams_unpackDoAA(packed); |
348 size_t offsetToRestore = reader.readInt(); | 349 size_t offsetToRestore = reader->readInt(); |
349 SkASSERT(!offsetToRestore || offsetToRestore >= reader.offset()); | 350 SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset()); |
350 canvas->clipRect(rect, regionOp, doAA); | 351 canvas->clipRect(rect, regionOp, doAA); |
351 if (canvas->isClipEmpty() && offsetToRestore) { | 352 if (canvas->isClipEmpty() && offsetToRestore) { |
352 #ifdef SPEW_CLIP_SKIPPING | 353 reader->setOffset(offsetToRestore); |
353 skipRect.recordSkip(offsetToRestore - reader.offset()); | |
354 #endif | |
355 reader.setOffset(offsetToRestore); | |
356 } | 354 } |
357 } break; | 355 } break; |
358 case CLIP_RRECT: { | 356 case CLIP_RRECT: { |
359 SkRRect rrect; | 357 SkRRect rrect; |
360 reader.readRRect(&rrect); | 358 reader->readRRect(&rrect); |
361 uint32_t packed = reader.readInt(); | 359 uint32_t packed = reader->readInt(); |
362 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); | 360 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed); |
363 bool doAA = ClipParams_unpackDoAA(packed); | 361 bool doAA = ClipParams_unpackDoAA(packed); |
364 size_t offsetToRestore = reader.readInt(); | 362 size_t offsetToRestore = reader->readInt(); |
365 SkASSERT(!offsetToRestore || offsetToRestore >= reader.offset()); | 363 SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset()); |
366 canvas->clipRRect(rrect, regionOp, doAA); | 364 canvas->clipRRect(rrect, regionOp, doAA); |
367 if (canvas->isClipEmpty() && offsetToRestore) { | 365 if (canvas->isClipEmpty() && offsetToRestore) { |
368 #ifdef SPEW_CLIP_SKIPPING | 366 reader->setOffset(offsetToRestore); |
369 skipRRect.recordSkip(offsetToRestore - reader.offset()); | |
370 #endif | |
371 reader.setOffset(offsetToRestore); | |
372 } | 367 } |
373 } break; | 368 } break; |
374 case PUSH_CULL: { | 369 case PUSH_CULL: { |
375 const SkRect& cullRect = reader.skipT<SkRect>(); | 370 const SkRect& cullRect = reader->skipT<SkRect>(); |
376 size_t offsetToRestore = reader.readInt(); | 371 size_t offsetToRestore = reader->readInt(); |
377 if (offsetToRestore && canvas->quickReject(cullRect)) { | 372 if (offsetToRestore && canvas->quickReject(cullRect)) { |
378 #ifdef SPEW_CLIP_SKIPPING | 373 reader->setOffset(offsetToRestore); |
379 skipCull.recordSkip(offsetToRestore - reader.offset()); | |
380 #endif | |
381 reader.setOffset(offsetToRestore); | |
382 } else { | 374 } else { |
383 canvas->pushCull(cullRect); | 375 canvas->pushCull(cullRect); |
384 } | 376 } |
385 } break; | 377 } break; |
386 case POP_CULL: | 378 case POP_CULL: |
387 canvas->popCull(); | 379 canvas->popCull(); |
388 break; | 380 break; |
389 case CONCAT: { | 381 case CONCAT: { |
390 SkMatrix matrix; | 382 SkMatrix matrix; |
391 reader.readMatrix(&matrix); | 383 reader->readMatrix(&matrix); |
392 canvas->concat(matrix); | 384 canvas->concat(matrix); |
393 break; | 385 break; |
394 } | 386 } |
395 case DRAW_BITMAP: { | 387 case DRAW_BITMAP: { |
396 const SkPaint* paint = fPictureData->getPaint(reader); | 388 const SkPaint* paint = fPictureData->getPaint(reader); |
397 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); | 389 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); |
398 const SkPoint& loc = reader.skipT<SkPoint>(); | 390 const SkPoint& loc = reader->skipT<SkPoint>(); |
399 canvas->drawBitmap(bitmap, loc.fX, loc.fY, paint); | 391 canvas->drawBitmap(bitmap, loc.fX, loc.fY, paint); |
400 } break; | 392 } break; |
401 case DRAW_BITMAP_RECT_TO_RECT: { | 393 case DRAW_BITMAP_RECT_TO_RECT: { |
402 const SkPaint* paint = fPictureData->getPaint(reader); | 394 const SkPaint* paint = fPictureData->getPaint(reader); |
403 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); | 395 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); |
404 const SkRect* src = get_rect_ptr(reader); // may be null | 396 const SkRect* src = get_rect_ptr(reader); // may be null |
405 const SkRect& dst = reader.skipT<SkRect>(); // required | 397 const SkRect& dst = reader->skipT<SkRect>(); // required |
406 SkCanvas::DrawBitmapRectFlags flags; | 398 SkCanvas::DrawBitmapRectFlags flags; |
407 flags = (SkCanvas::DrawBitmapRectFlags) reader.readInt(); | 399 flags = (SkCanvas::DrawBitmapRectFlags) reader->readInt(); |
408 canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 400 canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
409 } break; | 401 } break; |
410 case DRAW_BITMAP_MATRIX: { | 402 case DRAW_BITMAP_MATRIX: { |
411 const SkPaint* paint = fPictureData->getPaint(reader); | 403 const SkPaint* paint = fPictureData->getPaint(reader); |
412 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); | 404 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); |
413 SkMatrix matrix; | 405 SkMatrix matrix; |
414 reader.readMatrix(&matrix); | 406 reader->readMatrix(&matrix); |
415 canvas->drawBitmapMatrix(bitmap, matrix, paint); | 407 canvas->drawBitmapMatrix(bitmap, matrix, paint); |
416 } break; | 408 } break; |
417 case DRAW_BITMAP_NINE: { | 409 case DRAW_BITMAP_NINE: { |
418 const SkPaint* paint = fPictureData->getPaint(reader); | 410 const SkPaint* paint = fPictureData->getPaint(reader); |
419 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); | 411 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); |
420 const SkIRect& src = reader.skipT<SkIRect>(); | 412 const SkIRect& src = reader->skipT<SkIRect>(); |
421 const SkRect& dst = reader.skipT<SkRect>(); | 413 const SkRect& dst = reader->skipT<SkRect>(); |
422 canvas->drawBitmapNine(bitmap, src, dst, paint); | 414 canvas->drawBitmapNine(bitmap, src, dst, paint); |
423 } break; | 415 } break; |
424 case DRAW_CLEAR: | 416 case DRAW_CLEAR: |
425 canvas->clear(reader.readInt()); | 417 canvas->clear(reader->readInt()); |
426 break; | 418 break; |
427 case DRAW_DATA: { | 419 case DRAW_DATA: { |
428 size_t length = reader.readInt(); | 420 size_t length = reader->readInt(); |
429 canvas->drawData(reader.skip(length), length); | 421 canvas->drawData(reader->skip(length), length); |
430 // skip handles padding the read out to a multiple of 4 | 422 // skip handles padding the read out to a multiple of 4 |
431 } break; | 423 } break; |
432 case DRAW_DRRECT: { | 424 case DRAW_DRRECT: { |
433 const SkPaint& paint = *fPictureData->getPaint(reader); | 425 const SkPaint& paint = *fPictureData->getPaint(reader); |
434 SkRRect outer, inner; | 426 SkRRect outer, inner; |
435 reader.readRRect(&outer); | 427 reader->readRRect(&outer); |
436 reader.readRRect(&inner); | 428 reader->readRRect(&inner); |
437 canvas->drawDRRect(outer, inner, paint); | 429 canvas->drawDRRect(outer, inner, paint); |
438 } break; | 430 } break; |
439 case BEGIN_COMMENT_GROUP: { | 431 case BEGIN_COMMENT_GROUP: { |
440 const char* desc = reader.readString(); | 432 const char* desc = reader->readString(); |
441 canvas->beginCommentGroup(desc); | 433 canvas->beginCommentGroup(desc); |
442 } break; | 434 } break; |
443 case COMMENT: { | 435 case COMMENT: { |
444 const char* kywd = reader.readString(); | 436 const char* kywd = reader->readString(); |
445 const char* value = reader.readString(); | 437 const char* value = reader->readString(); |
446 canvas->addComment(kywd, value); | 438 canvas->addComment(kywd, value); |
447 } break; | 439 } break; |
448 case END_COMMENT_GROUP: { | 440 case END_COMMENT_GROUP: { |
449 canvas->endCommentGroup(); | 441 canvas->endCommentGroup(); |
450 } break; | 442 } break; |
451 case DRAW_OVAL: { | 443 case DRAW_OVAL: { |
452 const SkPaint& paint = *fPictureData->getPaint(reader); | 444 const SkPaint& paint = *fPictureData->getPaint(reader); |
453 canvas->drawOval(reader.skipT<SkRect>(), paint); | 445 canvas->drawOval(reader->skipT<SkRect>(), paint); |
454 } break; | 446 } break; |
455 case DRAW_PAINT: | 447 case DRAW_PAINT: |
456 canvas->drawPaint(*fPictureData->getPaint(reader)); | 448 canvas->drawPaint(*fPictureData->getPaint(reader)); |
457 break; | 449 break; |
458 case DRAW_PATH: { | 450 case DRAW_PATH: { |
459 const SkPaint& paint = *fPictureData->getPaint(reader); | 451 const SkPaint& paint = *fPictureData->getPaint(reader); |
460 canvas->drawPath(fPictureData->getPath(reader), paint); | 452 canvas->drawPath(fPictureData->getPath(reader), paint); |
461 } break; | 453 } break; |
462 case DRAW_PICTURE: | 454 case DRAW_PICTURE: |
463 canvas->drawPicture(fPictureData->getPicture(reader)); | 455 canvas->drawPicture(fPictureData->getPicture(reader)); |
464 break; | 456 break; |
465 case DRAW_POINTS: { | 457 case DRAW_POINTS: { |
466 const SkPaint& paint = *fPictureData->getPaint(reader); | 458 const SkPaint& paint = *fPictureData->getPaint(reader); |
467 SkCanvas::PointMode mode = (SkCanvas::PointMode)reader.readInt(); | 459 SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt(); |
468 size_t count = reader.readInt(); | 460 size_t count = reader->readInt(); |
469 const SkPoint* pts = (const SkPoint*)reader.skip(sizeof(SkPoint)* co unt); | 461 const SkPoint* pts = (const SkPoint*)reader->skip(sizeof(SkPoint)* c ount); |
470 canvas->drawPoints(mode, count, pts, paint); | 462 canvas->drawPoints(mode, count, pts, paint); |
471 } break; | 463 } break; |
472 case DRAW_POS_TEXT: { | 464 case DRAW_POS_TEXT: { |
473 const SkPaint& paint = *fPictureData->getPaint(reader); | 465 const SkPaint& paint = *fPictureData->getPaint(reader); |
474 get_text(&reader, &text); | 466 TextContainer text; |
475 size_t points = reader.readInt(); | 467 get_text(reader, &text); |
476 const SkPoint* pos = (const SkPoint*)reader.skip(points * sizeof(SkP oint)); | 468 size_t points = reader->readInt(); |
469 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point)); | |
477 canvas->drawPosText(text.text(), text.length(), pos, paint); | 470 canvas->drawPosText(text.text(), text.length(), pos, paint); |
478 } break; | 471 } break; |
479 case DRAW_POS_TEXT_TOP_BOTTOM: { | 472 case DRAW_POS_TEXT_TOP_BOTTOM: { |
480 const SkPaint& paint = *fPictureData->getPaint(reader); | 473 const SkPaint& paint = *fPictureData->getPaint(reader); |
481 get_text(&reader, &text); | 474 TextContainer text; |
482 size_t points = reader.readInt(); | 475 get_text(reader, &text); |
483 const SkPoint* pos = (const SkPoint*)reader.skip(points * sizeof(SkP oint)); | 476 size_t points = reader->readInt(); |
484 const SkScalar top = reader.readScalar(); | 477 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point)); |
485 const SkScalar bottom = reader.readScalar(); | 478 const SkScalar top = reader->readScalar(); |
479 const SkScalar bottom = reader->readScalar(); | |
486 if (!canvas->quickRejectY(top, bottom)) { | 480 if (!canvas->quickRejectY(top, bottom)) { |
487 canvas->drawPosText(text.text(), text.length(), pos, paint); | 481 canvas->drawPosText(text.text(), text.length(), pos, paint); |
488 } | 482 } |
489 } break; | 483 } break; |
490 case DRAW_POS_TEXT_H: { | 484 case DRAW_POS_TEXT_H: { |
491 const SkPaint& paint = *fPictureData->getPaint(reader); | 485 const SkPaint& paint = *fPictureData->getPaint(reader); |
492 get_text(&reader, &text); | 486 TextContainer text; |
493 size_t xCount = reader.readInt(); | 487 get_text(reader, &text); |
494 const SkScalar constY = reader.readScalar(); | 488 size_t xCount = reader->readInt(); |
495 const SkScalar* xpos = (const SkScalar*)reader.skip(xCount * sizeof( SkScalar)); | 489 const SkScalar constY = reader->readScalar(); |
490 const SkScalar* xpos = (const SkScalar*)reader->skip(xCount * sizeof (SkScalar)); | |
496 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, paint ); | 491 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, paint ); |
497 } break; | 492 } break; |
498 case DRAW_POS_TEXT_H_TOP_BOTTOM: { | 493 case DRAW_POS_TEXT_H_TOP_BOTTOM: { |
499 const SkPaint& paint = *fPictureData->getPaint(reader); | 494 const SkPaint& paint = *fPictureData->getPaint(reader); |
500 get_text(&reader, &text); | 495 TextContainer text; |
501 size_t xCount = reader.readInt(); | 496 get_text(reader, &text); |
502 const SkScalar* xpos = (const SkScalar*)reader.skip((3 + xCount) * s izeof(SkScalar)); | 497 size_t xCount = reader->readInt(); |
498 const SkScalar* xpos = (const SkScalar*)reader->skip((3 + xCount) * sizeof(SkScalar)); | |
503 const SkScalar top = *xpos++; | 499 const SkScalar top = *xpos++; |
504 const SkScalar bottom = *xpos++; | 500 const SkScalar bottom = *xpos++; |
505 const SkScalar constY = *xpos++; | 501 const SkScalar constY = *xpos++; |
506 if (!canvas->quickRejectY(top, bottom)) { | 502 if (!canvas->quickRejectY(top, bottom)) { |
507 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, p aint); | 503 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, p aint); |
508 } | 504 } |
509 } break; | 505 } break; |
510 case DRAW_RECT: { | 506 case DRAW_RECT: { |
511 const SkPaint& paint = *fPictureData->getPaint(reader); | 507 const SkPaint& paint = *fPictureData->getPaint(reader); |
512 canvas->drawRect(reader.skipT<SkRect>(), paint); | 508 canvas->drawRect(reader->skipT<SkRect>(), paint); |
513 } break; | 509 } break; |
514 case DRAW_RRECT: { | 510 case DRAW_RRECT: { |
515 const SkPaint& paint = *fPictureData->getPaint(reader); | 511 const SkPaint& paint = *fPictureData->getPaint(reader); |
516 SkRRect rrect; | 512 SkRRect rrect; |
517 reader.readRRect(&rrect); | 513 reader->readRRect(&rrect); |
518 canvas->drawRRect(rrect, paint); | 514 canvas->drawRRect(rrect, paint); |
519 } break; | 515 } break; |
520 case DRAW_SPRITE: { | 516 case DRAW_SPRITE: { |
521 const SkPaint* paint = fPictureData->getPaint(reader); | 517 const SkPaint* paint = fPictureData->getPaint(reader); |
522 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); | 518 const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader) ); |
523 int left = reader.readInt(); | 519 int left = reader->readInt(); |
524 int top = reader.readInt(); | 520 int top = reader->readInt(); |
525 canvas->drawSprite(bitmap, left, top, paint); | 521 canvas->drawSprite(bitmap, left, top, paint); |
526 } break; | 522 } break; |
527 case DRAW_TEXT: { | 523 case DRAW_TEXT: { |
528 const SkPaint& paint = *fPictureData->getPaint(reader); | 524 const SkPaint& paint = *fPictureData->getPaint(reader); |
529 get_text(&reader, &text); | 525 TextContainer text; |
530 SkScalar x = reader.readScalar(); | 526 get_text(reader, &text); |
531 SkScalar y = reader.readScalar(); | 527 SkScalar x = reader->readScalar(); |
528 SkScalar y = reader->readScalar(); | |
532 canvas->drawText(text.text(), text.length(), x, y, paint); | 529 canvas->drawText(text.text(), text.length(), x, y, paint); |
533 } break; | 530 } break; |
534 case DRAW_TEXT_TOP_BOTTOM: { | 531 case DRAW_TEXT_TOP_BOTTOM: { |
535 const SkPaint& paint = *fPictureData->getPaint(reader); | 532 const SkPaint& paint = *fPictureData->getPaint(reader); |
536 get_text(&reader, &text); | 533 TextContainer text; |
537 const SkScalar* ptr = (const SkScalar*)reader.skip(4 * sizeof(SkScal ar)); | 534 get_text(reader, &text); |
535 const SkScalar* ptr = (const SkScalar*)reader->skip(4 * sizeof(SkSca lar)); | |
538 // ptr[0] == x | 536 // ptr[0] == x |
539 // ptr[1] == y | 537 // ptr[1] == y |
540 // ptr[2] == top | 538 // ptr[2] == top |
541 // ptr[3] == bottom | 539 // ptr[3] == bottom |
542 if (!canvas->quickRejectY(ptr[2], ptr[3])) { | 540 if (!canvas->quickRejectY(ptr[2], ptr[3])) { |
543 canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], pai nt); | 541 canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], pai nt); |
544 } | 542 } |
545 } break; | 543 } break; |
546 case DRAW_TEXT_ON_PATH: { | 544 case DRAW_TEXT_ON_PATH: { |
547 const SkPaint& paint = *fPictureData->getPaint(reader); | 545 const SkPaint& paint = *fPictureData->getPaint(reader); |
548 get_text(&reader, &text); | 546 TextContainer text; |
547 get_text(reader, &text); | |
549 const SkPath& path = fPictureData->getPath(reader); | 548 const SkPath& path = fPictureData->getPath(reader); |
550 SkMatrix matrix; | 549 SkMatrix matrix; |
551 reader.readMatrix(&matrix); | 550 reader->readMatrix(&matrix); |
552 canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, pa int); | 551 canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, pa int); |
553 } break; | 552 } break; |
554 case DRAW_VERTICES: { | 553 case DRAW_VERTICES: { |
555 SkAutoTUnref<SkXfermode> xfer; | 554 SkAutoTUnref<SkXfermode> xfer; |
556 const SkPaint& paint = *fPictureData->getPaint(reader); | 555 const SkPaint& paint = *fPictureData->getPaint(reader); |
557 DrawVertexFlags flags = (DrawVertexFlags)reader.readInt(); | 556 DrawVertexFlags flags = (DrawVertexFlags)reader->readInt(); |
558 SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader.readInt(); | 557 SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt() ; |
559 int vCount = reader.readInt(); | 558 int vCount = reader->readInt(); |
560 const SkPoint* verts = (const SkPoint*)reader.skip(vCount * sizeof(S kPoint)); | 559 const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof( SkPoint)); |
561 const SkPoint* texs = NULL; | 560 const SkPoint* texs = NULL; |
562 const SkColor* colors = NULL; | 561 const SkColor* colors = NULL; |
563 const uint16_t* indices = NULL; | 562 const uint16_t* indices = NULL; |
564 int iCount = 0; | 563 int iCount = 0; |
565 if (flags & DRAW_VERTICES_HAS_TEXS) { | 564 if (flags & DRAW_VERTICES_HAS_TEXS) { |
566 texs = (const SkPoint*)reader.skip(vCount * sizeof(SkPoint)); | 565 texs = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint)); |
567 } | 566 } |
568 if (flags & DRAW_VERTICES_HAS_COLORS) { | 567 if (flags & DRAW_VERTICES_HAS_COLORS) { |
569 colors = (const SkColor*)reader.skip(vCount * sizeof(SkColor)); | 568 colors = (const SkColor*)reader->skip(vCount * sizeof(SkColor)); |
570 } | 569 } |
571 if (flags & DRAW_VERTICES_HAS_INDICES) { | 570 if (flags & DRAW_VERTICES_HAS_INDICES) { |
572 iCount = reader.readInt(); | 571 iCount = reader->readInt(); |
573 indices = (const uint16_t*)reader.skip(iCount * sizeof(uint16_t) ); | 572 indices = (const uint16_t*)reader->skip(iCount * sizeof(uint16_t )); |
574 } | 573 } |
575 if (flags & DRAW_VERTICES_HAS_XFER) { | 574 if (flags & DRAW_VERTICES_HAS_XFER) { |
576 int mode = reader.readInt(); | 575 int mode = reader->readInt(); |
577 if (mode < 0 || mode > SkXfermode::kLastMode) { | 576 if (mode < 0 || mode > SkXfermode::kLastMode) { |
578 mode = SkXfermode::kModulate_Mode; | 577 mode = SkXfermode::kModulate_Mode; |
579 } | 578 } |
580 xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode)); | 579 xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode)); |
581 } | 580 } |
582 canvas->drawVertices(vmode, vCount, verts, texs, colors, xfer, indic es, iCount, paint); | 581 canvas->drawVertices(vmode, vCount, verts, texs, colors, xfer, indic es, iCount, paint); |
583 } break; | 582 } break; |
584 case RESTORE: | 583 case RESTORE: |
585 canvas->restore(); | 584 canvas->restore(); |
586 break; | 585 break; |
587 case ROTATE: | 586 case ROTATE: |
588 canvas->rotate(reader.readScalar()); | 587 canvas->rotate(reader->readScalar()); |
589 break; | 588 break; |
590 case SAVE: | 589 case SAVE: |
591 // SKPs with version < 29 also store a SaveFlags param. | 590 // SKPs with version < 29 also store a SaveFlags param. |
592 if (size > 4) { | 591 if (size > 4) { |
593 SkASSERT(8 == size); | 592 SkASSERT(8 == size); |
594 reader.readInt(); | 593 reader->readInt(); |
595 } | 594 } |
596 canvas->save(); | 595 canvas->save(); |
597 break; | 596 break; |
598 case SAVE_LAYER: { | 597 case SAVE_LAYER: { |
599 const SkRect* boundsPtr = get_rect_ptr(reader); | 598 const SkRect* boundsPtr = get_rect_ptr(reader); |
600 const SkPaint* paint = fPictureData->getPaint(reader); | 599 const SkPaint* paint = fPictureData->getPaint(reader); |
601 canvas->saveLayer(boundsPtr, paint, (SkCanvas::SaveFlags) reader.rea dInt()); | 600 canvas->saveLayer(boundsPtr, paint, (SkCanvas::SaveFlags) reader->re adInt()); |
602 } break; | 601 } break; |
603 case SCALE: { | 602 case SCALE: { |
604 SkScalar sx = reader.readScalar(); | 603 SkScalar sx = reader->readScalar(); |
605 SkScalar sy = reader.readScalar(); | 604 SkScalar sy = reader->readScalar(); |
606 canvas->scale(sx, sy); | 605 canvas->scale(sx, sy); |
607 } break; | 606 } break; |
608 case SET_MATRIX: { | 607 case SET_MATRIX: { |
609 SkMatrix matrix; | 608 SkMatrix matrix; |
610 reader.readMatrix(&matrix); | 609 reader->readMatrix(&matrix); |
611 matrix.postConcat(initialMatrix); | 610 matrix.postConcat(initialMatrix); |
612 canvas->setMatrix(matrix); | 611 canvas->setMatrix(matrix); |
613 } break; | 612 } break; |
614 case SKEW: { | 613 case SKEW: { |
615 SkScalar sx = reader.readScalar(); | 614 SkScalar sx = reader->readScalar(); |
616 SkScalar sy = reader.readScalar(); | 615 SkScalar sy = reader->readScalar(); |
617 canvas->skew(sx, sy); | 616 canvas->skew(sx, sy); |
618 } break; | 617 } break; |
619 case TRANSLATE: { | 618 case TRANSLATE: { |
620 SkScalar dx = reader.readScalar(); | 619 SkScalar dx = reader->readScalar(); |
621 SkScalar dy = reader.readScalar(); | 620 SkScalar dy = reader->readScalar(); |
622 canvas->translate(dx, dy); | 621 canvas->translate(dx, dy); |
623 } break; | 622 } break; |
624 default: | 623 default: |
625 SkASSERT(0); | 624 SkASSERT(0); |
626 } | |
627 | |
628 #ifdef SK_DEVELOPER | |
629 this->postDraw(opIndex); | |
630 #endif | |
631 | |
632 if (it.isValid()) { | |
633 uint32_t skipTo = it.nextDraw(); | |
634 if (kDrawComplete == skipTo) { | |
635 break; | |
636 } | |
637 reader.setOffset(skipTo); | |
638 } | |
639 } | 625 } |
640 | |
641 #ifdef SPEW_CLIP_SKIPPING | |
642 { | |
643 size_t size = skipRect.fSize + skipRRect.fSize + skipPath.fSize + skipRe gion.fSize + | |
644 skipCull.fSize; | |
645 SkDebugf("--- Clip skips %d%% rect:%d rrect:%d path:%d rgn:%d cull:%d\n" , | |
646 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, | |
647 skipPath.fCount, skipRegion.fCount, skipCull.fCount); | |
648 SkDebugf("--- Total ops: %d\n", opCount); | |
649 } | |
650 #endif | |
651 // this->dumpSize(); | |
652 } | 626 } |
653 | 627 |
OLD | NEW |