OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 444 } |
445 size_t initialOffset = this->addDraw(CLIP_REGION, &size); | 445 size_t initialOffset = this->addDraw(CLIP_REGION, &size); |
446 this->addRegion(region); | 446 this->addRegion(region); |
447 this->addInt(ClipParams_pack(op, false)); | 447 this->addInt(ClipParams_pack(op, false)); |
448 size_t offset = this->recordRestoreOffsetPlaceholder(op); | 448 size_t offset = this->recordRestoreOffsetPlaceholder(op); |
449 | 449 |
450 this->validate(initialOffset, size); | 450 this->validate(initialOffset, size); |
451 return offset; | 451 return offset; |
452 } | 452 } |
453 | 453 |
454 void SkPictureRecord::drawPaint(const SkPaint& paint) { | 454 void SkPictureRecord::onDrawPaint(const SkPaint& paint) { |
455 // op + paint index | 455 // op + paint index |
456 size_t size = 2 * kUInt32Size; | 456 size_t size = 2 * kUInt32Size; |
457 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); | 457 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); |
458 SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWr
itten()); | 458 SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWr
itten()); |
459 this->addPaint(paint); | 459 this->addPaint(paint); |
460 this->validate(initialOffset, size); | 460 this->validate(initialOffset, size); |
461 } | 461 } |
462 | 462 |
463 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
[], | 463 void SkPictureRecord::onDrawPoints(PointMode mode, size_t count, const SkPoint p
ts[], |
464 const SkPaint& paint) { | 464 const SkPaint& paint) { |
465 fContentInfo.onDrawPoints(count, paint); | 465 fContentInfo.onDrawPoints(count, paint); |
466 | 466 |
467 // op + paint index + mode + count + point data | 467 // op + paint index + mode + count + point data |
468 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); | 468 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); |
469 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); | 469 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); |
470 SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesW
ritten()); | 470 SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesW
ritten()); |
471 this->addPaint(paint); | 471 this->addPaint(paint); |
472 | 472 |
473 this->addInt(mode); | 473 this->addInt(mode); |
474 this->addInt(SkToInt(count)); | 474 this->addInt(SkToInt(count)); |
475 fWriter.writeMul4(pts, count * sizeof(SkPoint)); | 475 fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
476 this->validate(initialOffset, size); | 476 this->validate(initialOffset, size); |
477 } | 477 } |
478 | 478 |
479 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { | 479 void SkPictureRecord::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
480 // op + paint index + rect | 480 // op + paint index + rect |
481 size_t size = 2 * kUInt32Size + sizeof(oval); | 481 size_t size = 2 * kUInt32Size + sizeof(oval); |
482 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); | 482 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); |
483 SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWri
tten()); | 483 SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWri
tten()); |
484 this->addPaint(paint); | 484 this->addPaint(paint); |
485 this->addRect(oval); | 485 this->addRect(oval); |
486 this->validate(initialOffset, size); | 486 this->validate(initialOffset, size); |
487 } | 487 } |
488 | 488 |
489 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { | 489 void SkPictureRecord::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
490 // op + paint index + rect | 490 // op + paint index + rect |
491 size_t size = 2 * kUInt32Size + sizeof(rect); | 491 size_t size = 2 * kUInt32Size + sizeof(rect); |
492 size_t initialOffset = this->addDraw(DRAW_RECT, &size); | 492 size_t initialOffset = this->addDraw(DRAW_RECT, &size); |
493 SkASSERT(initialOffset+get_paint_offset(DRAW_RECT, size) == fWriter.bytesWri
tten()); | 493 SkASSERT(initialOffset+get_paint_offset(DRAW_RECT, size) == fWriter.bytesWri
tten()); |
494 this->addPaint(paint); | 494 this->addPaint(paint); |
495 this->addRect(rect); | 495 this->addRect(rect); |
496 this->validate(initialOffset, size); | 496 this->validate(initialOffset, size); |
497 } | 497 } |
498 | 498 |
499 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 499 void SkPictureRecord::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
500 // op + paint index + rrect | 500 // op + paint index + rrect |
501 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; | 501 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; |
502 size_t initialOffset = this->addDraw(DRAW_RRECT, &size); | 502 size_t initialOffset = this->addDraw(DRAW_RRECT, &size); |
503 SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWr
itten()); | 503 SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWr
itten()); |
504 this->addPaint(paint); | 504 this->addPaint(paint); |
505 this->addRRect(rrect); | 505 this->addRRect(rrect); |
506 this->validate(initialOffset, size); | 506 this->validate(initialOffset, size); |
507 } | 507 } |
508 | 508 |
509 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, | 509 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
510 const SkPaint& paint) { | 510 const SkPaint& paint) { |
511 // op + paint index + rrects | 511 // op + paint index + rrects |
512 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; | 512 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; |
513 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); | 513 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); |
514 SkASSERT(initialOffset+get_paint_offset(DRAW_DRRECT, size) == fWriter.bytesW
ritten()); | 514 SkASSERT(initialOffset+get_paint_offset(DRAW_DRRECT, size) == fWriter.bytesW
ritten()); |
515 this->addPaint(paint); | 515 this->addPaint(paint); |
516 this->addRRect(outer); | 516 this->addRRect(outer); |
517 this->addRRect(inner); | 517 this->addRRect(inner); |
518 this->validate(initialOffset, size); | 518 this->validate(initialOffset, size); |
519 } | 519 } |
520 | 520 |
521 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { | 521 void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) { |
522 fContentInfo.onDrawPath(path, paint); | 522 fContentInfo.onDrawPath(path, paint); |
523 | 523 |
524 // op + paint index + path index | 524 // op + paint index + path index |
525 size_t size = 3 * kUInt32Size; | 525 size_t size = 3 * kUInt32Size; |
526 size_t initialOffset = this->addDraw(DRAW_PATH, &size); | 526 size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
527 SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWri
tten()); | 527 SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWri
tten()); |
528 this->addPaint(paint); | 528 this->addPaint(paint); |
529 this->addPath(path); | 529 this->addPath(path); |
530 this->validate(initialOffset, size); | 530 this->validate(initialOffset, size); |
531 } | 531 } |
532 | 532 |
533 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, | 533 void SkPictureRecord::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScal
ar top, |
534 const SkPaint* paint = NULL) { | 534 const SkPaint* paint) { |
535 // op + paint index + bitmap index + left + top | 535 // op + paint index + bitmap index + left + top |
536 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); | 536 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
537 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); | 537 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); |
538 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesW
ritten()); | 538 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesW
ritten()); |
539 this->addPaintPtr(paint); | 539 this->addPaintPtr(paint); |
540 this->addBitmap(bitmap); | 540 this->addBitmap(bitmap); |
541 this->addScalar(left); | 541 this->addScalar(left); |
542 this->addScalar(top); | 542 this->addScalar(top); |
543 this->validate(initialOffset, size); | 543 this->validate(initialOffset, size); |
544 } | 544 } |
545 | 545 |
546 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, | 546 void SkPictureRecord::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src
, const SkRect& dst, |
547 const SkRect& dst, const SkPaint* pai
nt, | 547 const SkPaint* paint, DrawBitmapRectFlags
flags) { |
548 DrawBitmapRectFlags flags) { | |
549 // id + paint index + bitmap index + bool for 'src' + flags | 548 // id + paint index + bitmap index + bool for 'src' + flags |
550 size_t size = 5 * kUInt32Size; | 549 size_t size = 5 * kUInt32Size; |
551 if (src) { | 550 if (src) { |
552 size += sizeof(*src); // + rect | 551 size += sizeof(*src); // + rect |
553 } | 552 } |
554 size += sizeof(dst); // + rect | 553 size += sizeof(dst); // + rect |
555 | 554 |
556 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); | 555 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
557 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size) | 556 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size) |
558 == fWriter.bytesWritten()); | 557 == fWriter.bytesWritten()); |
559 this->addPaintPtr(paint); | 558 this->addPaintPtr(paint); |
560 this->addBitmap(bitmap); | 559 this->addBitmap(bitmap); |
561 this->addRectPtr(src); // may be null | 560 this->addRectPtr(src); // may be null |
562 this->addRect(dst); | 561 this->addRect(dst); |
563 this->addInt(flags); | 562 this->addInt(flags); |
564 this->validate(initialOffset, size); | 563 this->validate(initialOffset, size); |
565 } | 564 } |
566 | 565 |
567 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, | 566 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce
nter, |
568 const SkRect& dst, const SkPaint* paint) { | 567 const SkRect& dst, const SkPaint* paint)
{ |
569 // op + paint index + bitmap id + center + dst rect | 568 // op + paint index + bitmap id + center + dst rect |
570 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); | 569 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
571 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); | 570 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
572 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b
ytesWritten()); | 571 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b
ytesWritten()); |
573 this->addPaintPtr(paint); | 572 this->addPaintPtr(paint); |
574 this->addBitmap(bitmap); | 573 this->addBitmap(bitmap); |
575 this->addIRect(center); | 574 this->addIRect(center); |
576 this->addRect(dst); | 575 this->addRect(dst); |
577 this->validate(initialOffset, size); | 576 this->validate(initialOffset, size); |
578 } | 577 } |
579 | 578 |
580 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, | 579 void SkPictureRecord::onDrawSprite(const SkBitmap& bitmap, int left, int top, |
581 const SkPaint* paint = NULL) { | 580 const SkPaint* paint) { |
582 // op + paint index + bitmap index + left + top | 581 // op + paint index + bitmap index + left + top |
583 size_t size = 5 * kUInt32Size; | 582 size_t size = 5 * kUInt32Size; |
584 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); | 583 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
585 SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesW
ritten()); | 584 SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesW
ritten()); |
586 this->addPaintPtr(paint); | 585 this->addPaintPtr(paint); |
587 this->addBitmap(bitmap); | 586 this->addBitmap(bitmap); |
588 this->addInt(left); | 587 this->addInt(left); |
589 this->addInt(top); | 588 this->addInt(top); |
590 this->validate(initialOffset, size); | 589 this->validate(initialOffset, size); |
591 } | 590 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); | 685 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
687 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz
e) | 686 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz
e) |
688 == fWriter.bytesWritten()); | 687 == fWriter.bytesWritten()); |
689 this->addPaintPtr(paint); | 688 this->addPaintPtr(paint); |
690 this->addMatrix(m); | 689 this->addMatrix(m); |
691 this->addPicture(picture); | 690 this->addPicture(picture); |
692 } | 691 } |
693 this->validate(initialOffset, size); | 692 this->validate(initialOffset, size); |
694 } | 693 } |
695 | 694 |
696 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, | 695 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, |
697 const SkPoint vertices[], const SkPoint texs[], | 696 const SkPoint vertices[], const SkPoint tex
s[], |
698 const SkColor colors[], SkXfermode* xfer, | 697 const SkColor colors[], SkXfermode* xfer, |
699 const uint16_t indices[], int indexCount, | 698 const uint16_t indices[], int indexCount, |
700 const SkPaint& paint) { | 699 const SkPaint& paint) { |
701 uint32_t flags = 0; | 700 uint32_t flags = 0; |
702 if (texs) { | 701 if (texs) { |
703 flags |= DRAW_VERTICES_HAS_TEXS; | 702 flags |= DRAW_VERTICES_HAS_TEXS; |
704 } | 703 } |
705 if (colors) { | 704 if (colors) { |
706 flags |= DRAW_VERTICES_HAS_COLORS; | 705 flags |= DRAW_VERTICES_HAS_COLORS; |
707 } | 706 } |
708 if (indexCount > 0) { | 707 if (indexCount > 0) { |
709 flags |= DRAW_VERTICES_HAS_INDICES; | 708 flags |= DRAW_VERTICES_HAS_INDICES; |
710 } | 709 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 991 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
993 int index = fTextBlobRefs.count(); | 992 int index = fTextBlobRefs.count(); |
994 *fTextBlobRefs.append() = blob; | 993 *fTextBlobRefs.append() = blob; |
995 blob->ref(); | 994 blob->ref(); |
996 // follow the convention of recording a 1-based index | 995 // follow the convention of recording a 1-based index |
997 this->addInt(index + 1); | 996 this->addInt(index + 1); |
998 } | 997 } |
999 | 998 |
1000 /////////////////////////////////////////////////////////////////////////////// | 999 /////////////////////////////////////////////////////////////////////////////// |
1001 | 1000 |
OLD | NEW |