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::onDrawPaint(const SkPaint& paint) { | 454 void SkPictureRecord::drawPaint(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::onDrawPoints(PointMode mode, size_t count, const SkPoint p
ts[], | 463 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
[], |
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::onDrawOval(const SkRect& oval, const SkPaint& paint) { | 479 void SkPictureRecord::drawOval(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::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 489 void SkPictureRecord::drawRect(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::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { | 499 void SkPictureRecord::drawRRect(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::onDrawPath(const SkPath& path, const SkPaint& paint) { | 521 void SkPictureRecord::drawPath(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::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScal
ar top, | 533 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, |
534 const SkPaint* paint) { | 534 const SkPaint* paint = NULL) { |
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::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src
, const SkRect& dst, | 546 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, |
547 const SkPaint* paint, DrawBitmapRectFlags
flags) { | 547 const SkRect& dst, const SkPaint* pai
nt, |
| 548 DrawBitmapRectFlags flags) { |
548 // id + paint index + bitmap index + bool for 'src' + flags | 549 // id + paint index + bitmap index + bool for 'src' + flags |
549 size_t size = 5 * kUInt32Size; | 550 size_t size = 5 * kUInt32Size; |
550 if (src) { | 551 if (src) { |
551 size += sizeof(*src); // + rect | 552 size += sizeof(*src); // + rect |
552 } | 553 } |
553 size += sizeof(dst); // + rect | 554 size += sizeof(dst); // + rect |
554 | 555 |
555 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); | 556 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
556 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size) | 557 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size) |
557 == fWriter.bytesWritten()); | 558 == fWriter.bytesWritten()); |
558 this->addPaintPtr(paint); | 559 this->addPaintPtr(paint); |
559 this->addBitmap(bitmap); | 560 this->addBitmap(bitmap); |
560 this->addRectPtr(src); // may be null | 561 this->addRectPtr(src); // may be null |
561 this->addRect(dst); | 562 this->addRect(dst); |
562 this->addInt(flags); | 563 this->addInt(flags); |
563 this->validate(initialOffset, size); | 564 this->validate(initialOffset, size); |
564 } | 565 } |
565 | 566 |
566 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce
nter, | 567 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, |
567 const SkRect& dst, const SkPaint* paint)
{ | 568 const SkRect& dst, const SkPaint* paint) { |
568 // op + paint index + bitmap id + center + dst rect | 569 // op + paint index + bitmap id + center + dst rect |
569 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); | 570 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
570 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); | 571 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
571 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b
ytesWritten()); | 572 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b
ytesWritten()); |
572 this->addPaintPtr(paint); | 573 this->addPaintPtr(paint); |
573 this->addBitmap(bitmap); | 574 this->addBitmap(bitmap); |
574 this->addIRect(center); | 575 this->addIRect(center); |
575 this->addRect(dst); | 576 this->addRect(dst); |
576 this->validate(initialOffset, size); | 577 this->validate(initialOffset, size); |
577 } | 578 } |
578 | 579 |
579 void SkPictureRecord::onDrawSprite(const SkBitmap& bitmap, int left, int top, | 580 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
580 const SkPaint* paint) { | 581 const SkPaint* paint = NULL) { |
581 // op + paint index + bitmap index + left + top | 582 // op + paint index + bitmap index + left + top |
582 size_t size = 5 * kUInt32Size; | 583 size_t size = 5 * kUInt32Size; |
583 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); | 584 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
584 SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesW
ritten()); | 585 SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesW
ritten()); |
585 this->addPaintPtr(paint); | 586 this->addPaintPtr(paint); |
586 this->addBitmap(bitmap); | 587 this->addBitmap(bitmap); |
587 this->addInt(left); | 588 this->addInt(left); |
588 this->addInt(top); | 589 this->addInt(top); |
589 this->validate(initialOffset, size); | 590 this->validate(initialOffset, size); |
590 } | 591 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); | 686 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
686 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz
e) | 687 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz
e) |
687 == fWriter.bytesWritten()); | 688 == fWriter.bytesWritten()); |
688 this->addPaintPtr(paint); | 689 this->addPaintPtr(paint); |
689 this->addMatrix(m); | 690 this->addMatrix(m); |
690 this->addPicture(picture); | 691 this->addPicture(picture); |
691 } | 692 } |
692 this->validate(initialOffset, size); | 693 this->validate(initialOffset, size); |
693 } | 694 } |
694 | 695 |
695 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, | 696 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, |
696 const SkPoint vertices[], const SkPoint tex
s[], | 697 const SkPoint vertices[], const SkPoint texs[], |
697 const SkColor colors[], SkXfermode* xfer, | 698 const SkColor colors[], SkXfermode* xfer, |
698 const uint16_t indices[], int indexCount, | 699 const uint16_t indices[], int indexCount, |
699 const SkPaint& paint) { | 700 const SkPaint& paint) { |
700 uint32_t flags = 0; | 701 uint32_t flags = 0; |
701 if (texs) { | 702 if (texs) { |
702 flags |= DRAW_VERTICES_HAS_TEXS; | 703 flags |= DRAW_VERTICES_HAS_TEXS; |
703 } | 704 } |
704 if (colors) { | 705 if (colors) { |
705 flags |= DRAW_VERTICES_HAS_COLORS; | 706 flags |= DRAW_VERTICES_HAS_COLORS; |
706 } | 707 } |
707 if (indexCount > 0) { | 708 if (indexCount > 0) { |
708 flags |= DRAW_VERTICES_HAS_INDICES; | 709 flags |= DRAW_VERTICES_HAS_INDICES; |
709 } | 710 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 992 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
992 int index = fTextBlobRefs.count(); | 993 int index = fTextBlobRefs.count(); |
993 *fTextBlobRefs.append() = blob; | 994 *fTextBlobRefs.append() = blob; |
994 blob->ref(); | 995 blob->ref(); |
995 // follow the convention of recording a 1-based index | 996 // follow the convention of recording a 1-based index |
996 this->addInt(index + 1); | 997 this->addInt(index + 1); |
997 } | 998 } |
998 | 999 |
999 /////////////////////////////////////////////////////////////////////////////// | 1000 /////////////////////////////////////////////////////////////////////////////// |
1000 | 1001 |
OLD | NEW |