Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: src/core/SkPictureRecord.cpp

Issue 618303002: Remove DEPRECATED_beginRecording(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix up benches Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkPixelRef.h" 11 #include "SkPixelRef.h"
12 #include "SkRRect.h" 12 #include "SkRRect.h"
13 #include "SkTextBlob.h" 13 #include "SkTextBlob.h"
14 #include "SkTSearch.h" 14 #include "SkTSearch.h"
15 15
16 #define HEAP_BLOCK_SIZE 4096 16 #define HEAP_BLOCK_SIZE 4096
17 17
18 enum { 18 enum {
19 // just need a value that save or getSaveCount would never return 19 // just need a value that save or getSaveCount would never return
20 kNoInitialSave = -1, 20 kNoInitialSave = -1,
21 }; 21 };
22 22
23 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c. 23 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c.
24 static int const kUInt32Size = 4; 24 static int const kUInt32Size = 4;
25 25
26 static const uint32_t kSaveSize = kUInt32Size; 26 static const uint32_t kSaveSize = kUInt32Size;
27 #ifdef SK_DEBUG
27 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; 28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
28 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect ); 29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect );
30 #endif//SK_DEBUG
29 31
30 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) 32 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
31 : INHERITED(dimensions.width(), dimensions.height()) 33 : INHERITED(dimensions.width(), dimensions.height())
32 , fFlattenableHeap(HEAP_BLOCK_SIZE) 34 , fFlattenableHeap(HEAP_BLOCK_SIZE)
33 , fPaints(&fFlattenableHeap) 35 , fPaints(&fFlattenableHeap)
34 , fRecordFlags(flags) { 36 , fRecordFlags(flags) {
35 37
36 fBitmapHeap = SkNEW(SkBitmapHeap); 38 fBitmapHeap = SkNEW(SkBitmapHeap);
37 fFlattenableHeap.setBitmapStorage(fBitmapHeap); 39 fFlattenableHeap.setBitmapStorage(fBitmapHeap);
38 40
39 fFirstSavedLayerIndex = kNoSavedLayerIndex; 41 fFirstSavedLayerIndex = kNoSavedLayerIndex;
40 fInitialSaveCount = kNoInitialSave; 42 fInitialSaveCount = kNoInitialSave;
41 } 43 }
42 44
43 SkPictureRecord::~SkPictureRecord() { 45 SkPictureRecord::~SkPictureRecord() {
44 SkSafeUnref(fBitmapHeap); 46 SkSafeUnref(fBitmapHeap);
45 fFlattenableHeap.setBitmapStorage(NULL); 47 fFlattenableHeap.setBitmapStorage(NULL);
46 fPictureRefs.unrefAll(); 48 fPictureRefs.unrefAll();
47 fTextBlobRefs.unrefAll(); 49 fTextBlobRefs.unrefAll();
48 } 50 }
49 51
50 /////////////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////////////
51 53
54 #ifdef SK_DEBUG
52 // Return the offset of the paint inside a given op's byte stream. A zero 55 // Return the offset of the paint inside a given op's byte stream. A zero
53 // return value means there is no paint (and you really shouldn't be calling 56 // return value means there is no paint (and you really shouldn't be calling
54 // this method) 57 // this method)
55 static inline size_t getPaintOffset(DrawType op, size_t opSize) { 58 static inline size_t get_paint_offset(DrawType op, size_t opSize) {
56 // These offsets are where the paint would be if the op size doesn't overflo w 59 // These offsets are where the paint would be if the op size doesn't overflo w
57 static const uint8_t gPaintOffsets[] = { 60 static const uint8_t gPaintOffsets[] = {
58 0, // UNUSED - no paint 61 0, // UNUSED - no paint
59 0, // CLIP_PATH - no paint 62 0, // CLIP_PATH - no paint
60 0, // CLIP_REGION - no paint 63 0, // CLIP_REGION - no paint
61 0, // CLIP_RECT - no paint 64 0, // CLIP_RECT - no paint
62 0, // CLIP_RRECT - no paint 65 0, // CLIP_RRECT - no paint
63 0, // CONCAT - no paint 66 0, // CONCAT - no paint
64 1, // DRAW_BITMAP - right after op code 67 1, // DRAW_BITMAP - right after op code
65 1, // DRAW_BITMAP_MATRIX - right after op code 68 1, // DRAW_BITMAP_MATRIX - right after op code
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return kSaveLayerNoBoundsPaintOffset + overflow; 125 return kSaveLayerNoBoundsPaintOffset + overflow;
123 } else { 126 } else {
124 SkASSERT(kSaveLayerWithBoundsSize == opSize); 127 SkASSERT(kSaveLayerWithBoundsSize == opSize);
125 return kSaveLayerWithBoundsPaintOffset + overflow; 128 return kSaveLayerWithBoundsPaintOffset + overflow;
126 } 129 }
127 } 130 }
128 131
129 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth od 132 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth od
130 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; 133 return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
131 } 134 }
135 #endif//SK_DEBUG
132 136
133 void SkPictureRecord::willSave() { 137 void SkPictureRecord::willSave() {
134 // record the offset to us, making it non-positive to distinguish a save 138 // record the offset to us, making it non-positive to distinguish a save
135 // from a clip entry. 139 // from a clip entry.
136 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 140 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
137 this->recordSave(); 141 this->recordSave();
138 142
139 this->INHERITED::willSave(); 143 this->INHERITED::willSave();
140 } 144 }
141 145
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (bounds) { 181 if (bounds) {
178 size += sizeof(*bounds); // + rect 182 size += sizeof(*bounds); // + rect
179 } 183 }
180 // + paint index + flags 184 // + paint index + flags
181 size += 2 * kUInt32Size; 185 size += 2 * kUInt32Size;
182 186
183 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ; 187 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
184 188
185 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); 189 size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
186 this->addRectPtr(bounds); 190 this->addRectPtr(bounds);
187 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten()); 191 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWr itten());
188 this->addPaintPtr(paint); 192 this->addPaintPtr(paint);
189 this->addInt(flags); 193 this->addInt(flags);
190 194
191 this->validate(initialOffset, size); 195 this->validate(initialOffset, size);
192 } 196 }
193 197
194 bool SkPictureRecord::isDrawingToLayer() const { 198 bool SkPictureRecord::isDrawingToLayer() const {
195 return fFirstSavedLayerIndex != kNoSavedLayerIndex; 199 return fFirstSavedLayerIndex != kNoSavedLayerIndex;
196 } 200 }
197 201
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 size_t size = 2 * kUInt32Size; 473 size_t size = 2 * kUInt32Size;
470 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); 474 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size);
471 this->addInt(color); 475 this->addInt(color);
472 this->validate(initialOffset, size); 476 this->validate(initialOffset, size);
473 } 477 }
474 478
475 void SkPictureRecord::drawPaint(const SkPaint& paint) { 479 void SkPictureRecord::drawPaint(const SkPaint& paint) {
476 // op + paint index 480 // op + paint index
477 size_t size = 2 * kUInt32Size; 481 size_t size = 2 * kUInt32Size;
478 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); 482 size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
479 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten()); 483 SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWr itten());
480 this->addPaint(paint); 484 this->addPaint(paint);
481 this->validate(initialOffset, size); 485 this->validate(initialOffset, size);
482 } 486 }
483 487
484 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [], 488 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [],
485 const SkPaint& paint) { 489 const SkPaint& paint) {
486 fContentInfo.onDrawPoints(count, paint); 490 fContentInfo.onDrawPoints(count, paint);
487 491
488 // op + paint index + mode + count + point data 492 // op + paint index + mode + count + point data
489 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); 493 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
490 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); 494 size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
491 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten()); 495 SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesW ritten());
492 this->addPaint(paint); 496 this->addPaint(paint);
493 497
494 this->addInt(mode); 498 this->addInt(mode);
495 this->addInt(SkToInt(count)); 499 this->addInt(SkToInt(count));
496 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 500 fWriter.writeMul4(pts, count * sizeof(SkPoint));
497 this->validate(initialOffset, size); 501 this->validate(initialOffset, size);
498 } 502 }
499 503
500 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { 504 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) {
501 // op + paint index + rect 505 // op + paint index + rect
502 size_t size = 2 * kUInt32Size + sizeof(oval); 506 size_t size = 2 * kUInt32Size + sizeof(oval);
503 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); 507 size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
504 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en()); 508 SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWri tten());
505 this->addPaint(paint); 509 this->addPaint(paint);
506 this->addRect(oval); 510 this->addRect(oval);
507 this->validate(initialOffset, size); 511 this->validate(initialOffset, size);
508 } 512 }
509 513
510 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { 514 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
511 // op + paint index + rect 515 // op + paint index + rect
512 size_t size = 2 * kUInt32Size + sizeof(rect); 516 size_t size = 2 * kUInt32Size + sizeof(rect);
513 size_t initialOffset = this->addDraw(DRAW_RECT, &size); 517 size_t initialOffset = this->addDraw(DRAW_RECT, &size);
514 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en()); 518 SkASSERT(initialOffset+get_paint_offset(DRAW_RECT, size) == fWriter.bytesWri tten());
515 this->addPaint(paint); 519 this->addPaint(paint);
516 this->addRect(rect); 520 this->addRect(rect);
517 this->validate(initialOffset, size); 521 this->validate(initialOffset, size);
518 } 522 }
519 523
520 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 524 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
521 // op + paint index + rrect 525 // op + paint index + rrect
522 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; 526 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
523 size_t initialOffset = this->addDraw(DRAW_RRECT, &size); 527 size_t initialOffset = this->addDraw(DRAW_RRECT, &size);
524 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytesWrit ten()); 528 SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWr itten());
525 this->addPaint(paint); 529 this->addPaint(paint);
526 this->addRRect(rrect); 530 this->addRRect(rrect);
527 this->validate(initialOffset, size); 531 this->validate(initialOffset, size);
528 } 532 }
529 533
530 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 534 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
531 const SkPaint& paint) { 535 const SkPaint& paint) {
532 // op + paint index + rrects 536 // op + paint index + rrects
533 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; 537 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2;
534 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); 538 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size);
535 SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWri tten()); 539 SkASSERT(initialOffset+get_paint_offset(DRAW_DRRECT, size) == fWriter.bytesW ritten());
536 this->addPaint(paint); 540 this->addPaint(paint);
537 this->addRRect(outer); 541 this->addRRect(outer);
538 this->addRRect(inner); 542 this->addRRect(inner);
539 this->validate(initialOffset, size); 543 this->validate(initialOffset, size);
540 } 544 }
541 545
542 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { 546 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
543 fContentInfo.onDrawPath(path, paint); 547 fContentInfo.onDrawPath(path, paint);
544 548
545 // op + paint index + path index 549 // op + paint index + path index
546 size_t size = 3 * kUInt32Size; 550 size_t size = 3 * kUInt32Size;
547 size_t initialOffset = this->addDraw(DRAW_PATH, &size); 551 size_t initialOffset = this->addDraw(DRAW_PATH, &size);
548 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en()); 552 SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWri tten());
549 this->addPaint(paint); 553 this->addPaint(paint);
550 this->addPath(path); 554 this->addPath(path);
551 this->validate(initialOffset, size); 555 this->validate(initialOffset, size);
552 } 556 }
553 557
554 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 558 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
555 const SkPaint* paint = NULL) { 559 const SkPaint* paint = NULL) {
556 // op + paint index + bitmap index + left + top 560 // op + paint index + bitmap index + left + top
557 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 561 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
558 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 562 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
559 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten()); 563 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesW ritten());
560 this->addPaintPtr(paint); 564 this->addPaintPtr(paint);
561 this->addBitmap(bitmap); 565 this->addBitmap(bitmap);
562 this->addScalar(left); 566 this->addScalar(left);
563 this->addScalar(top); 567 this->addScalar(top);
564 this->validate(initialOffset, size); 568 this->validate(initialOffset, size);
565 } 569 }
566 570
567 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 571 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
568 const SkRect& dst, const SkPaint* pai nt, 572 const SkRect& dst, const SkPaint* pai nt,
569 DrawBitmapRectFlags flags) { 573 DrawBitmapRectFlags flags) {
570 // id + paint index + bitmap index + bool for 'src' + flags 574 // id + paint index + bitmap index + bool for 'src' + flags
571 size_t size = 5 * kUInt32Size; 575 size_t size = 5 * kUInt32Size;
572 if (src) { 576 if (src) {
573 size += sizeof(*src); // + rect 577 size += sizeof(*src); // + rect
574 } 578 }
575 size += sizeof(dst); // + rect 579 size += sizeof(dst); // + rect
576 580
577 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 581 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
578 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) 582 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size)
579 == fWriter.bytesWritten()); 583 == fWriter.bytesWritten());
580 this->addPaintPtr(paint); 584 this->addPaintPtr(paint);
581 this->addBitmap(bitmap); 585 this->addBitmap(bitmap);
582 this->addRectPtr(src); // may be null 586 this->addRectPtr(src); // may be null
583 this->addRect(dst); 587 this->addRect(dst);
584 this->addInt(flags); 588 this->addInt(flags);
585 this->validate(initialOffset, size); 589 this->validate(initialOffset, size);
586 } 590 }
587 591
588 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix, 592 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix,
589 const SkPaint* paint) { 593 const SkPaint* paint) {
590 // id + paint index + bitmap index + matrix 594 // id + paint index + bitmap index + matrix
591 size_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); 595 size_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
592 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); 596 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
593 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten()); 597 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_MATRIX, size) == fWriter .bytesWritten());
594 this->addPaintPtr(paint); 598 this->addPaintPtr(paint);
595 this->addBitmap(bitmap); 599 this->addBitmap(bitmap);
596 this->addMatrix(matrix); 600 this->addMatrix(matrix);
597 this->validate(initialOffset, size); 601 this->validate(initialOffset, size);
598 } 602 }
599 603
600 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er, 604 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er,
601 const SkRect& dst, const SkPaint* paint) { 605 const SkRect& dst, const SkPaint* paint) {
602 // op + paint index + bitmap id + center + dst rect 606 // op + paint index + bitmap id + center + dst rect
603 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 607 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
604 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 608 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
605 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten()); 609 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b ytesWritten());
606 this->addPaintPtr(paint); 610 this->addPaintPtr(paint);
607 this->addBitmap(bitmap); 611 this->addBitmap(bitmap);
608 this->addIRect(center); 612 this->addIRect(center);
609 this->addRect(dst); 613 this->addRect(dst);
610 this->validate(initialOffset, size); 614 this->validate(initialOffset, size);
611 } 615 }
612 616
613 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 617 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
614 const SkPaint* paint = NULL) { 618 const SkPaint* paint = NULL) {
615 // op + paint index + bitmap index + left + top 619 // op + paint index + bitmap index + left + top
616 size_t size = 5 * kUInt32Size; 620 size_t size = 5 * kUInt32Size;
617 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 621 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
618 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten()); 622 SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesW ritten());
619 this->addPaintPtr(paint); 623 this->addPaintPtr(paint);
620 this->addBitmap(bitmap); 624 this->addBitmap(bitmap);
621 this->addInt(left); 625 this->addInt(left);
622 this->addInt(top); 626 this->addInt(top);
623 this->validate(initialOffset, size); 627 this->validate(initialOffset, size);
624 } 628 }
625 629
626 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y, 630 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y,
627 const SkPaint& paint) { 631 const SkPaint& paint) {
628 // op + paint index + length + 'length' worth of chars + x + y 632 // op + paint index + length + 'length' worth of chars + x + y
629 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); 633 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar);
630 634
631 DrawType op = DRAW_TEXT; 635 DrawType op = DRAW_TEXT;
632 size_t initialOffset = this->addDraw(op, &size); 636 size_t initialOffset = this->addDraw(op, &size);
633 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 637 SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()) ;
634 this->addPaint(paint); 638 this->addPaint(paint);
635 this->addText(text, byteLength); 639 this->addText(text, byteLength);
636 this->addScalar(x); 640 this->addScalar(x);
637 this->addScalar(y); 641 this->addScalar(y);
638 this->validate(initialOffset, size); 642 this->validate(initialOffset, size);
639 } 643 }
640 644
641 void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S kPoint pos[], 645 void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S kPoint pos[],
642 const SkPaint& paint) { 646 const SkPaint& paint) {
643 int points = paint.countText(text, byteLength); 647 int points = paint.countText(text, byteLength);
644 648
645 // op + paint index + length + 'length' worth of data + num points + x&y poi nt data 649 // op + paint index + length + 'length' worth of data + num points + x&y poi nt data
646 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint); 650 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint);
647 651
648 DrawType op = DRAW_POS_TEXT; 652 DrawType op = DRAW_POS_TEXT;
649 653
650 size_t initialOffset = this->addDraw(op, &size); 654 size_t initialOffset = this->addDraw(op, &size);
651 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 655 SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()) ;
652 this->addPaint(paint); 656 this->addPaint(paint);
653 this->addText(text, byteLength); 657 this->addText(text, byteLength);
654 this->addInt(points); 658 this->addInt(points);
655 fWriter.writeMul4(pos, points * sizeof(SkPoint)); 659 fWriter.writeMul4(pos, points * sizeof(SkPoint));
656 this->validate(initialOffset, size); 660 this->validate(initialOffset, size);
657 } 661 }
658 662
659 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], 663 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
660 SkScalar constY, const SkPaint& paint) { 664 SkScalar constY, const SkPaint& paint) {
661 int points = paint.countText(text, byteLength); 665 int points = paint.countText(text, byteLength);
(...skipping 11 matching lines...) Expand all
673 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); 677 fWriter.writeMul4(xpos, points * sizeof(SkScalar));
674 this->validate(initialOffset, size); 678 this->validate(initialOffset, size);
675 } 679 }
676 680
677 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons t SkPath& path, 681 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons t SkPath& path,
678 const SkMatrix* matrix, const SkPaint& pa int) { 682 const SkMatrix* matrix, const SkPaint& pa int) {
679 // op + paint index + length + 'length' worth of data + path index + matrix 683 // op + paint index + length + 'length' worth of data + path index + matrix
680 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 684 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
681 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(NULL); 685 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(NULL);
682 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 686 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
683 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten()); 687 SkASSERT(initialOffset+get_paint_offset(DRAW_TEXT_ON_PATH, size) == fWriter. bytesWritten());
684 this->addPaint(paint); 688 this->addPaint(paint);
685 this->addText(text, byteLength); 689 this->addText(text, byteLength);
686 this->addPath(path); 690 this->addPath(path);
687 this->addMatrix(m); 691 this->addMatrix(m);
688 this->validate(initialOffset, size); 692 this->validate(initialOffset, size);
689 } 693 }
690 694
691 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala r y, 695 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala r y,
692 const SkPaint& paint) { 696 const SkPaint& paint) {
693 697
694 // op + paint index + blob index + x/y 698 // op + paint index + blob index + x/y
695 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 699 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
696 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); 700 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size);
697 SkASSERT(initialOffset + getPaintOffset(DRAW_TEXT_BLOB, size) == fWriter.byt esWritten()); 701 SkASSERT(initialOffset + get_paint_offset(DRAW_TEXT_BLOB, size) == fWriter.b ytesWritten());
698 702
699 this->addPaint(paint); 703 this->addPaint(paint);
700 this->addTextBlob(blob); 704 this->addTextBlob(blob);
701 this->addScalar(x); 705 this->addScalar(x);
702 this->addScalar(y); 706 this->addScalar(y);
703 707
704 this->validate(initialOffset, size); 708 this->validate(initialOffset, size);
705 } 709 }
706 710
707 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix, 711 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix,
708 const SkPaint* paint) { 712 const SkPaint* paint) {
709 // op + picture index 713 // op + picture index
710 size_t size = 2 * kUInt32Size; 714 size_t size = 2 * kUInt32Size;
711 size_t initialOffset; 715 size_t initialOffset;
712 716
713 if (NULL == matrix && NULL == paint) { 717 if (NULL == matrix && NULL == paint) {
714 initialOffset = this->addDraw(DRAW_PICTURE, &size); 718 initialOffset = this->addDraw(DRAW_PICTURE, &size);
715 this->addPicture(picture); 719 this->addPicture(picture);
716 } else { 720 } else {
717 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 721 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
718 size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint 722 size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint
719 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); 723 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size);
720 SkASSERT(initialOffset + getPaintOffset(DRAW_PICTURE_MATRIX_PAINT, size) 724 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz e)
721 == fWriter.bytesWritten()); 725 == fWriter.bytesWritten());
722 this->addPaintPtr(paint); 726 this->addPaintPtr(paint);
723 this->addMatrix(m); 727 this->addMatrix(m);
724 this->addPicture(picture); 728 this->addPicture(picture);
725 } 729 }
726 this->validate(initialOffset, size); 730 this->validate(initialOffset, size);
727 } 731 }
728 732
729 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, 733 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
730 const SkPoint vertices[], const SkPoint texs[], 734 const SkPoint vertices[], const SkPoint texs[],
(...skipping 27 matching lines...) Expand all
758 } 762 }
759 if (flags & DRAW_VERTICES_HAS_INDICES) { 763 if (flags & DRAW_VERTICES_HAS_INDICES) {
760 // + num indices + indices 764 // + num indices + indices
761 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); 765 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t));
762 } 766 }
763 if (flags & DRAW_VERTICES_HAS_XFER) { 767 if (flags & DRAW_VERTICES_HAS_XFER) {
764 size += kUInt32Size; // mode enum 768 size += kUInt32Size; // mode enum
765 } 769 }
766 770
767 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); 771 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size);
768 SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesW ritten()); 772 SkASSERT(initialOffset+get_paint_offset(DRAW_VERTICES, size) == fWriter.byte sWritten());
769 this->addPaint(paint); 773 this->addPaint(paint);
770 this->addInt(flags); 774 this->addInt(flags);
771 this->addInt(vmode); 775 this->addInt(vmode);
772 this->addInt(vertexCount); 776 this->addInt(vertexCount);
773 this->addPoints(vertices, vertexCount); 777 this->addPoints(vertices, vertexCount);
774 if (flags & DRAW_VERTICES_HAS_TEXS) { 778 if (flags & DRAW_VERTICES_HAS_TEXS) {
775 this->addPoints(texs, vertexCount); 779 this->addPoints(texs, vertexCount);
776 } 780 }
777 if (flags & DRAW_VERTICES_HAS_COLORS) { 781 if (flags & DRAW_VERTICES_HAS_COLORS) {
778 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); 782 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor));
(...skipping 26 matching lines...) Expand all
805 } 809 }
806 if (xmode) { 810 if (xmode) {
807 SkXfermode::Mode mode; 811 SkXfermode::Mode mode;
808 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { 812 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
809 flag |= DRAW_VERTICES_HAS_XFER; 813 flag |= DRAW_VERTICES_HAS_XFER;
810 size += kUInt32Size; 814 size += kUInt32Size;
811 } 815 }
812 } 816 }
813 817
814 size_t initialOffset = this->addDraw(DRAW_PATCH, &size); 818 size_t initialOffset = this->addDraw(DRAW_PATCH, &size);
815 SkASSERT(initialOffset+getPaintOffset(DRAW_PATCH, size) == fWriter.bytesWrit ten()); 819 SkASSERT(initialOffset+get_paint_offset(DRAW_PATCH, size) == fWriter.bytesWr itten());
816 this->addPaint(paint); 820 this->addPaint(paint);
817 this->addPatch(cubics); 821 this->addPatch(cubics);
818 this->addInt(flag); 822 this->addInt(flag);
819 823
820 // write optional parameters 824 // write optional parameters
821 if (colors) { 825 if (colors) {
822 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); 826 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
823 } 827 }
824 if (texCoords) { 828 if (texCoords) {
825 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); 829 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 1014 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
1011 int index = fTextBlobRefs.count(); 1015 int index = fTextBlobRefs.count();
1012 *fTextBlobRefs.append() = blob; 1016 *fTextBlobRefs.append() = blob;
1013 blob->ref(); 1017 blob->ref();
1014 // follow the convention of recording a 1-based index 1018 // follow the convention of recording a 1-based index
1015 this->addInt(index + 1); 1019 this->addInt(index + 1);
1016 } 1020 }
1017 1021
1018 /////////////////////////////////////////////////////////////////////////////// 1022 ///////////////////////////////////////////////////////////////////////////////
1019 1023
OLDNEW
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698