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

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

Issue 1557123002: remove now defunct get_paint_offset (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | 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 "SkImage_Base.h" 10 #include "SkImage_Base.h"
11 #include "SkPatchUtils.h" 11 #include "SkPatchUtils.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 #include "SkRRect.h" 13 #include "SkRRect.h"
14 #include "SkRSXform.h" 14 #include "SkRSXform.h"
15 #include "SkTextBlob.h" 15 #include "SkTextBlob.h"
16 #include "SkTSearch.h" 16 #include "SkTSearch.h"
17 17
18 #define HEAP_BLOCK_SIZE 4096 18 #define HEAP_BLOCK_SIZE 4096
19 19
20 enum { 20 enum {
21 // just need a value that save or getSaveCount would never return 21 // just need a value that save or getSaveCount would never return
22 kNoInitialSave = -1, 22 kNoInitialSave = -1,
23 }; 23 };
24 24
25 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c. 25 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c.
26 static int const kUInt32Size = 4; 26 static int const kUInt32Size = 4;
27 27
28 static const uint32_t kSaveSize = kUInt32Size;
29 #ifdef SK_DEBUG
30 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
31 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect );
32 #endif//SK_DEBUG
33
34 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) 28 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
35 : INHERITED(dimensions.width(), dimensions.height()) 29 : INHERITED(dimensions.width(), dimensions.height())
36 , fRecordFlags(flags) 30 , fRecordFlags(flags)
37 , fInitialSaveCount(kNoInitialSave) { 31 , fInitialSaveCount(kNoInitialSave) {
38 } 32 }
39 33
40 SkPictureRecord::~SkPictureRecord() { 34 SkPictureRecord::~SkPictureRecord() {
41 fImageRefs.unrefAll(); 35 fImageRefs.unrefAll();
42 fPictureRefs.unrefAll(); 36 fPictureRefs.unrefAll();
43 fTextBlobRefs.unrefAll(); 37 fTextBlobRefs.unrefAll();
44 } 38 }
45 39
46 /////////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////////
47 41
48 #ifdef SK_DEBUG
49 // Return the offset of the paint inside a given op's byte stream. A zero
50 // return value means there is no paint (and you really shouldn't be calling
51 // this method)
52 static inline size_t get_paint_offset(DrawType op, size_t opSize) {
53 // These offsets are where the paint would be if the op size doesn't overflo w
54 static const uint8_t gPaintOffsets[] = {
55 0, // UNUSED - no paint
56 0, // CLIP_PATH - no paint
57 0, // CLIP_REGION - no paint
58 0, // CLIP_RECT - no paint
59 0, // CLIP_RRECT - no paint
60 0, // CONCAT - no paint
61 1, // DRAW_BITMAP - right after op code
62 1, // DRAW_BITMAP_MATRIX - right after op code, deprecated
63 1, // DRAW_BITMAP_NINE - right after op code
64 1, // DRAW_BITMAP_RECT - right after op code
65 0, // DRAW_CLEAR - no paint
66 0, // DRAW_DATA - no paint
67 1, // DRAW_OVAL - right after op code
68 1, // DRAW_PAINT - right after op code
69 1, // DRAW_PATH - right after op code
70 0, // DRAW_PICTURE - no paint
71 1, // DRAW_POINTS - right after op code
72 1, // DRAW_POS_TEXT - right after op code
73 1, // DRAW_POS_TEXT_TOP_BOTTOM - right after op code
74 1, // DRAW_POS_TEXT_H - right after op code
75 1, // DRAW_POS_TEXT_H_TOP_BOTTOM - right after op code
76 1, // DRAW_RECT - right after op code
77 1, // DRAW_RRECT - right after op code
78 1, // DRAW_SPRITE - right after op code
79 1, // DRAW_TEXT - right after op code
80 1, // DRAW_TEXT_ON_PATH - right after op code
81 1, // DRAW_TEXT_TOP_BOTTOM - right after op code
82 1, // DRAW_VERTICES - right after op code
83 0, // RESTORE - no paint
84 0, // ROTATE - no paint
85 0, // SAVE - no paint
86 0, // SAVE_LAYER_SAVEFLAGS_DEPRECATED - see below - this paint's locati on varies
87 0, // SCALE - no paint
88 0, // SET_MATRIX - no paint
89 0, // SKEW - no paint
90 0, // TRANSLATE - no paint
91 0, // NOOP - no paint
92 0, // BEGIN_GROUP - no paint
93 0, // COMMENT - no paint
94 0, // END_GROUP - no paint
95 1, // DRAWDRRECT - right after op code
96 0, // PUSH_CULL - no paint
97 0, // POP_CULL - no paint
98 1, // DRAW_PATCH - right after op code
99 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code
100 1, // DRAW_TEXT_BLOB- right after op code
101 1, // DRAW_IMAGE - right after op code
102 1, // DRAW_IMAGE_RECT_STRICT - right after op code
103 1, // DRAW_ATLAS - right after op code
104 1, // DRAW_IMAGE_NINE - right after op code
105 1, // DRAW_IMAGE_RECT - right after op code
106 0, // SAVE_LAYER_SAVELAYERFLAGS - see below - this paint's location var ies
107 };
108
109 static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_i n_sync");
110 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM);
111
112 int overflow = 0;
113 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) {
114 // This op's size overflows so an extra uint32_t will be written
115 // after the op code
116 overflow = sizeof(uint32_t);
117 }
118
119 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != op);
120 if (SAVE_LAYER_SAVELAYERFLAGS == op) {
121 static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size;
122 static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size + sizeof(SkRect);
123
124 if (kSaveLayerNoBoundsSize == opSize) {
125 return kSaveLayerNoBoundsPaintOffset + overflow;
126 } else {
127 SkASSERT(kSaveLayerWithBoundsSize == opSize);
128 return kSaveLayerWithBoundsPaintOffset + overflow;
129 }
130 }
131
132 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth od
133 return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
134 }
135 #endif//SK_DEBUG
136
137 void SkPictureRecord::willSave() { 42 void SkPictureRecord::willSave() {
138 // record the offset to us, making it non-positive to distinguish a save 43 // record the offset to us, making it non-positive to distinguish a save
139 // from a clip entry. 44 // from a clip entry.
140 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 45 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
141 this->recordSave(); 46 this->recordSave();
142 47
143 this->INHERITED::willSave(); 48 this->INHERITED::willSave();
144 } 49 }
145 50
146 void SkPictureRecord::recordSave() { 51 void SkPictureRecord::recordSave() {
147 fContentInfo.onSave(); 52 fContentInfo.onSave();
148 53
149 // op only 54 // op only
150 size_t size = kSaveSize; 55 size_t size = sizeof(kUInt32Size);
151 size_t initialOffset = this->addDraw(SAVE, &size); 56 size_t initialOffset = this->addDraw(SAVE, &size);
152 57
153 this->validate(initialOffset, size); 58 this->validate(initialOffset, size);
154 } 59 }
155 60
156 SkCanvas::SaveLayerStrategy SkPictureRecord::getSaveLayerStrategy(const SaveLaye rRec& rec) { 61 SkCanvas::SaveLayerStrategy SkPictureRecord::getSaveLayerStrategy(const SaveLaye rRec& rec) {
157 // record the offset to us, making it non-positive to distinguish a save 62 // record the offset to us, making it non-positive to distinguish a save
158 // from a clip entry. 63 // from a clip entry.
159 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 64 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
160 this->recordSaveLayer(rec); 65 this->recordSaveLayer(rec);
(...skipping 11 matching lines...) Expand all
172 fContentInfo.onSaveLayer(); 77 fContentInfo.onSaveLayer();
173 78
174 // op + bool for 'bounds' 79 // op + bool for 'bounds'
175 size_t size = 2 * kUInt32Size; 80 size_t size = 2 * kUInt32Size;
176 if (rec.fBounds) { 81 if (rec.fBounds) {
177 size += sizeof(*rec.fBounds); // + rect 82 size += sizeof(*rec.fBounds); // + rect
178 } 83 }
179 // + paint index + flags 84 // + paint index + flags
180 size += 2 * kUInt32Size; 85 size += 2 * kUInt32Size;
181 86
182 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
183
184 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); 87 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size);
185 this->addRectPtr(rec.fBounds); 88 this->addRectPtr(rec.fBounds);
186 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER_SAVELAYERFLAGS, size) == fWriter.bytesWritten());
187 this->addPaintPtr(rec.fPaint); 89 this->addPaintPtr(rec.fPaint);
188 this->addInt(rec.fSaveLayerFlags); 90 this->addInt(rec.fSaveLayerFlags);
189 91
190 this->validate(initialOffset, size); 92 this->validate(initialOffset, size);
191 } 93 }
192 94
193 #ifdef SK_DEBUG 95 #ifdef SK_DEBUG
194 /* 96 /*
195 * Read the op code from 'offset' in 'writer' and extract the size too. 97 * Read the op code from 'offset' in 'writer' and extract the size too.
196 */ 98 */
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 size_t offset = this->recordRestoreOffsetPlaceholder(op); 355 size_t offset = this->recordRestoreOffsetPlaceholder(op);
454 356
455 this->validate(initialOffset, size); 357 this->validate(initialOffset, size);
456 return offset; 358 return offset;
457 } 359 }
458 360
459 void SkPictureRecord::onDrawPaint(const SkPaint& paint) { 361 void SkPictureRecord::onDrawPaint(const SkPaint& paint) {
460 // op + paint index 362 // op + paint index
461 size_t size = 2 * kUInt32Size; 363 size_t size = 2 * kUInt32Size;
462 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); 364 size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
463 SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWr itten());
464 this->addPaint(paint); 365 this->addPaint(paint);
465 this->validate(initialOffset, size); 366 this->validate(initialOffset, size);
466 } 367 }
467 368
468 void SkPictureRecord::onDrawPoints(PointMode mode, size_t count, const SkPoint p ts[], 369 void SkPictureRecord::onDrawPoints(PointMode mode, size_t count, const SkPoint p ts[],
469 const SkPaint& paint) { 370 const SkPaint& paint) {
470 fContentInfo.onDrawPoints(count, paint); 371 fContentInfo.onDrawPoints(count, paint);
471 372
472 // op + paint index + mode + count + point data 373 // op + paint index + mode + count + point data
473 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); 374 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
474 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); 375 size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
475 SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesW ritten());
476 this->addPaint(paint); 376 this->addPaint(paint);
477 377
478 this->addInt(mode); 378 this->addInt(mode);
479 this->addInt(SkToInt(count)); 379 this->addInt(SkToInt(count));
480 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 380 fWriter.writeMul4(pts, count * sizeof(SkPoint));
481 this->validate(initialOffset, size); 381 this->validate(initialOffset, size);
482 } 382 }
483 383
484 void SkPictureRecord::onDrawOval(const SkRect& oval, const SkPaint& paint) { 384 void SkPictureRecord::onDrawOval(const SkRect& oval, const SkPaint& paint) {
485 // op + paint index + rect 385 // op + paint index + rect
486 size_t size = 2 * kUInt32Size + sizeof(oval); 386 size_t size = 2 * kUInt32Size + sizeof(oval);
487 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); 387 size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
488 SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWri tten());
489 this->addPaint(paint); 388 this->addPaint(paint);
490 this->addRect(oval); 389 this->addRect(oval);
491 this->validate(initialOffset, size); 390 this->validate(initialOffset, size);
492 } 391 }
493 392
494 void SkPictureRecord::onDrawRect(const SkRect& rect, const SkPaint& paint) { 393 void SkPictureRecord::onDrawRect(const SkRect& rect, const SkPaint& paint) {
495 // op + paint index + rect 394 // op + paint index + rect
496 size_t size = 2 * kUInt32Size + sizeof(rect); 395 size_t size = 2 * kUInt32Size + sizeof(rect);
497 size_t initialOffset = this->addDraw(DRAW_RECT, &size); 396 size_t initialOffset = this->addDraw(DRAW_RECT, &size);
498 SkASSERT(initialOffset+get_paint_offset(DRAW_RECT, size) == fWriter.bytesWri tten());
499 this->addPaint(paint); 397 this->addPaint(paint);
500 this->addRect(rect); 398 this->addRect(rect);
501 this->validate(initialOffset, size); 399 this->validate(initialOffset, size);
502 } 400 }
503 401
504 void SkPictureRecord::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 402 void SkPictureRecord::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
505 // op + paint index + rrect 403 // op + paint index + rrect
506 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; 404 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
507 size_t initialOffset = this->addDraw(DRAW_RRECT, &size); 405 size_t initialOffset = this->addDraw(DRAW_RRECT, &size);
508 SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWr itten());
509 this->addPaint(paint); 406 this->addPaint(paint);
510 this->addRRect(rrect); 407 this->addRRect(rrect);
511 this->validate(initialOffset, size); 408 this->validate(initialOffset, size);
512 } 409 }
513 410
514 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 411 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
515 const SkPaint& paint) { 412 const SkPaint& paint) {
516 // op + paint index + rrects 413 // op + paint index + rrects
517 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; 414 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2;
518 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); 415 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size);
519 SkASSERT(initialOffset+get_paint_offset(DRAW_DRRECT, size) == fWriter.bytesW ritten());
520 this->addPaint(paint); 416 this->addPaint(paint);
521 this->addRRect(outer); 417 this->addRRect(outer);
522 this->addRRect(inner); 418 this->addRRect(inner);
523 this->validate(initialOffset, size); 419 this->validate(initialOffset, size);
524 } 420 }
525 421
526 void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) { 422 void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) {
527 fContentInfo.onDrawPath(path, paint); 423 fContentInfo.onDrawPath(path, paint);
528 424
529 // op + paint index + path index 425 // op + paint index + path index
530 size_t size = 3 * kUInt32Size; 426 size_t size = 3 * kUInt32Size;
531 size_t initialOffset = this->addDraw(DRAW_PATH, &size); 427 size_t initialOffset = this->addDraw(DRAW_PATH, &size);
532 SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWri tten());
533 this->addPaint(paint); 428 this->addPaint(paint);
534 this->addPath(path); 429 this->addPath(path);
535 this->validate(initialOffset, size); 430 this->validate(initialOffset, size);
536 } 431 }
537 432
538 void SkPictureRecord::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScal ar top, 433 void SkPictureRecord::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScal ar top,
539 const SkPaint* paint) { 434 const SkPaint* paint) {
540 // op + paint index + bitmap index + left + top 435 // op + paint index + bitmap index + left + top
541 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 436 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
542 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 437 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
543 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesW ritten());
544 this->addPaintPtr(paint); 438 this->addPaintPtr(paint);
545 this->addBitmap(bitmap); 439 this->addBitmap(bitmap);
546 this->addScalar(left); 440 this->addScalar(left);
547 this->addScalar(top); 441 this->addScalar(top);
548 this->validate(initialOffset, size); 442 this->validate(initialOffset, size);
549 } 443 }
550 444
551 void SkPictureRecord::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src , const SkRect& dst, 445 void SkPictureRecord::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src , const SkRect& dst,
552 const SkPaint* paint, SrcRectConstraint c onstraint) { 446 const SkPaint* paint, SrcRectConstraint c onstraint) {
553 // id + paint index + bitmap index + bool for 'src' + flags 447 // id + paint index + bitmap index + bool for 'src' + flags
554 size_t size = 5 * kUInt32Size; 448 size_t size = 5 * kUInt32Size;
555 if (src) { 449 if (src) {
556 size += sizeof(*src); // + rect 450 size += sizeof(*src); // + rect
557 } 451 }
558 size += sizeof(dst); // + rect 452 size += sizeof(dst); // + rect
559 453
560 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT, &size); 454 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT, &size);
561 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT, size) == fWriter.b ytesWritten());
562 this->addPaintPtr(paint); 455 this->addPaintPtr(paint);
563 this->addBitmap(bitmap); 456 this->addBitmap(bitmap);
564 this->addRectPtr(src); // may be null 457 this->addRectPtr(src); // may be null
565 this->addRect(dst); 458 this->addRect(dst);
566 this->addInt(constraint); 459 this->addInt(constraint);
567 this->validate(initialOffset, size); 460 this->validate(initialOffset, size);
568 } 461 }
569 462
570 void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, 463 void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
571 const SkPaint* paint) { 464 const SkPaint* paint) {
572 // op + paint_index + image_index + x + y 465 // op + paint_index + image_index + x + y
573 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 466 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
574 size_t initialOffset = this->addDraw(DRAW_IMAGE, &size); 467 size_t initialOffset = this->addDraw(DRAW_IMAGE, &size);
575 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE, size) == fWriter.bytesWr itten());
576 this->addPaintPtr(paint); 468 this->addPaintPtr(paint);
577 this->addImage(image); 469 this->addImage(image);
578 this->addScalar(x); 470 this->addScalar(x);
579 this->addScalar(y); 471 this->addScalar(y);
580 this->validate(initialOffset, size); 472 this->validate(initialOffset, size);
581 } 473 }
582 474
583 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst, 475 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst,
584 const SkPaint* paint, SrcRectConstraint co nstraint) { 476 const SkPaint* paint, SrcRectConstraint co nstraint) {
585 // id + paint_index + image_index + bool_for_src + constraint 477 // id + paint_index + image_index + bool_for_src + constraint
586 size_t size = 5 * kUInt32Size; 478 size_t size = 5 * kUInt32Size;
587 if (src) { 479 if (src) {
588 size += sizeof(*src); // + rect 480 size += sizeof(*src); // + rect
589 } 481 }
590 size += sizeof(dst); // + rect 482 size += sizeof(dst); // + rect
591 483
592 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); 484 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size);
593 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size)
594 == fWriter.bytesWritten());
595 this->addPaintPtr(paint); 485 this->addPaintPtr(paint);
596 this->addImage(image); 486 this->addImage(image);
597 this->addRectPtr(src); // may be null 487 this->addRectPtr(src); // may be null
598 this->addRect(dst); 488 this->addRect(dst);
599 this->addInt(constraint); 489 this->addInt(constraint);
600 this->validate(initialOffset, size); 490 this->validate(initialOffset, size);
601 } 491 }
602 492
603 void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst, 493 void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst,
604 const SkPaint* paint) { 494 const SkPaint* paint) {
605 // id + paint_index + image_index + center + dst 495 // id + paint_index + image_index + center + dst
606 size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect); 496 size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect);
607 497
608 size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size); 498 size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size);
609 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_NINE, size) == fWriter.by tesWritten());
610 this->addPaintPtr(paint); 499 this->addPaintPtr(paint);
611 this->addImage(img); 500 this->addImage(img);
612 this->addIRect(center); 501 this->addIRect(center);
613 this->addRect(dst); 502 this->addRect(dst);
614 this->validate(initialOffset, size); 503 this->validate(initialOffset, size);
615 } 504 }
616 505
617 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce nter, 506 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce nter,
618 const SkRect& dst, const SkPaint* paint) { 507 const SkRect& dst, const SkPaint* paint) {
619 // op + paint index + bitmap id + center + dst rect 508 // op + paint index + bitmap id + center + dst rect
620 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 509 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
621 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 510 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
622 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b ytesWritten());
623 this->addPaintPtr(paint); 511 this->addPaintPtr(paint);
624 this->addBitmap(bitmap); 512 this->addBitmap(bitmap);
625 this->addIRect(center); 513 this->addIRect(center);
626 this->addRect(dst); 514 this->addRect(dst);
627 this->validate(initialOffset, size); 515 this->validate(initialOffset, size);
628 } 516 }
629 517
630 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y, 518 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y,
631 const SkPaint& paint) { 519 const SkPaint& paint) {
632 // op + paint index + length + 'length' worth of chars + x + y 520 // op + paint index + length + 'length' worth of chars + x + y
633 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); 521 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar);
634 522
635 DrawType op = DRAW_TEXT; 523 DrawType op = DRAW_TEXT;
636 size_t initialOffset = this->addDraw(op, &size); 524 size_t initialOffset = this->addDraw(op, &size);
637 SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()) ;
638 this->addPaint(paint); 525 this->addPaint(paint);
639 this->addText(text, byteLength); 526 this->addText(text, byteLength);
640 this->addScalar(x); 527 this->addScalar(x);
641 this->addScalar(y); 528 this->addScalar(y);
642 this->validate(initialOffset, size); 529 this->validate(initialOffset, size);
643 } 530 }
644 531
645 void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S kPoint pos[], 532 void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S kPoint pos[],
646 const SkPaint& paint) { 533 const SkPaint& paint) {
647 int points = paint.countText(text, byteLength); 534 int points = paint.countText(text, byteLength);
648 535
649 // op + paint index + length + 'length' worth of data + num points + x&y poi nt data 536 // op + paint index + length + 'length' worth of data + num points + x&y poi nt data
650 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint); 537 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint);
651 538
652 DrawType op = DRAW_POS_TEXT; 539 DrawType op = DRAW_POS_TEXT;
653 540
654 size_t initialOffset = this->addDraw(op, &size); 541 size_t initialOffset = this->addDraw(op, &size);
655 SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten()) ;
656 this->addPaint(paint); 542 this->addPaint(paint);
657 this->addText(text, byteLength); 543 this->addText(text, byteLength);
658 this->addInt(points); 544 this->addInt(points);
659 fWriter.writeMul4(pos, points * sizeof(SkPoint)); 545 fWriter.writeMul4(pos, points * sizeof(SkPoint));
660 this->validate(initialOffset, size); 546 this->validate(initialOffset, size);
661 } 547 }
662 548
663 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], 549 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
664 SkScalar constY, const SkPaint& paint) { 550 SkScalar constY, const SkPaint& paint) {
665 int points = paint.countText(text, byteLength); 551 int points = paint.countText(text, byteLength);
(...skipping 11 matching lines...) Expand all
677 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); 563 fWriter.writeMul4(xpos, points * sizeof(SkScalar));
678 this->validate(initialOffset, size); 564 this->validate(initialOffset, size);
679 } 565 }
680 566
681 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons t SkPath& path, 567 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons t SkPath& path,
682 const SkMatrix* matrix, const SkPaint& pa int) { 568 const SkMatrix* matrix, const SkPaint& pa int) {
683 // op + paint index + length + 'length' worth of data + path index + matrix 569 // op + paint index + length + 'length' worth of data + path index + matrix
684 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 570 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
685 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(nullptr); 571 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(nullptr);
686 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 572 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
687 SkASSERT(initialOffset+get_paint_offset(DRAW_TEXT_ON_PATH, size) == fWriter. bytesWritten());
688 this->addPaint(paint); 573 this->addPaint(paint);
689 this->addText(text, byteLength); 574 this->addText(text, byteLength);
690 this->addPath(path); 575 this->addPath(path);
691 this->addMatrix(m); 576 this->addMatrix(m);
692 this->validate(initialOffset, size); 577 this->validate(initialOffset, size);
693 } 578 }
694 579
695 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala r y, 580 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala r y,
696 const SkPaint& paint) { 581 const SkPaint& paint) {
697 582
698 // op + paint index + blob index + x/y 583 // op + paint index + blob index + x/y
699 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 584 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
700 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); 585 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size);
701 SkASSERT(initialOffset + get_paint_offset(DRAW_TEXT_BLOB, size) == fWriter.b ytesWritten());
702 586
703 this->addPaint(paint); 587 this->addPaint(paint);
704 this->addTextBlob(blob); 588 this->addTextBlob(blob);
705 this->addScalar(x); 589 this->addScalar(x);
706 this->addScalar(y); 590 this->addScalar(y);
707 591
708 this->validate(initialOffset, size); 592 this->validate(initialOffset, size);
709 } 593 }
710 594
711 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix, 595 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix,
712 const SkPaint* paint) { 596 const SkPaint* paint) {
713 // op + picture index 597 // op + picture index
714 size_t size = 2 * kUInt32Size; 598 size_t size = 2 * kUInt32Size;
715 size_t initialOffset; 599 size_t initialOffset;
716 600
717 if (nullptr == matrix && nullptr == paint) { 601 if (nullptr == matrix && nullptr == paint) {
718 initialOffset = this->addDraw(DRAW_PICTURE, &size); 602 initialOffset = this->addDraw(DRAW_PICTURE, &size);
719 this->addPicture(picture); 603 this->addPicture(picture);
720 } else { 604 } else {
721 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 605 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
722 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint 606 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint
723 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); 607 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size);
724 SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, siz e)
725 == fWriter.bytesWritten());
726 this->addPaintPtr(paint); 608 this->addPaintPtr(paint);
727 this->addMatrix(m); 609 this->addMatrix(m);
728 this->addPicture(picture); 610 this->addPicture(picture);
729 } 611 }
730 this->validate(initialOffset, size); 612 this->validate(initialOffset, size);
731 } 613 }
732 614
733 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, 615 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount,
734 const SkPoint vertices[], const SkPoint tex s[], 616 const SkPoint vertices[], const SkPoint tex s[],
735 const SkColor colors[], SkXfermode* xfer, 617 const SkColor colors[], SkXfermode* xfer,
(...skipping 26 matching lines...) Expand all
762 } 644 }
763 if (flags & DRAW_VERTICES_HAS_INDICES) { 645 if (flags & DRAW_VERTICES_HAS_INDICES) {
764 // + num indices + indices 646 // + num indices + indices
765 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); 647 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t));
766 } 648 }
767 if (flags & DRAW_VERTICES_HAS_XFER) { 649 if (flags & DRAW_VERTICES_HAS_XFER) {
768 size += kUInt32Size; // mode enum 650 size += kUInt32Size; // mode enum
769 } 651 }
770 652
771 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); 653 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size);
772 SkASSERT(initialOffset+get_paint_offset(DRAW_VERTICES, size) == fWriter.byte sWritten());
773 this->addPaint(paint); 654 this->addPaint(paint);
774 this->addInt(flags); 655 this->addInt(flags);
775 this->addInt(vmode); 656 this->addInt(vmode);
776 this->addInt(vertexCount); 657 this->addInt(vertexCount);
777 this->addPoints(vertices, vertexCount); 658 this->addPoints(vertices, vertexCount);
778 if (flags & DRAW_VERTICES_HAS_TEXS) { 659 if (flags & DRAW_VERTICES_HAS_TEXS) {
779 this->addPoints(texs, vertexCount); 660 this->addPoints(texs, vertexCount);
780 } 661 }
781 if (flags & DRAW_VERTICES_HAS_COLORS) { 662 if (flags & DRAW_VERTICES_HAS_COLORS) {
782 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); 663 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor));
(...skipping 26 matching lines...) Expand all
809 } 690 }
810 if (xmode) { 691 if (xmode) {
811 SkXfermode::Mode mode; 692 SkXfermode::Mode mode;
812 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { 693 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
813 flag |= DRAW_VERTICES_HAS_XFER; 694 flag |= DRAW_VERTICES_HAS_XFER;
814 size += kUInt32Size; 695 size += kUInt32Size;
815 } 696 }
816 } 697 }
817 698
818 size_t initialOffset = this->addDraw(DRAW_PATCH, &size); 699 size_t initialOffset = this->addDraw(DRAW_PATCH, &size);
819 SkASSERT(initialOffset+get_paint_offset(DRAW_PATCH, size) == fWriter.bytesWr itten());
820 this->addPaint(paint); 700 this->addPaint(paint);
821 this->addPatch(cubics); 701 this->addPatch(cubics);
822 this->addInt(flag); 702 this->addInt(flag);
823 703
824 // write optional parameters 704 // write optional parameters
825 if (colors) { 705 if (colors) {
826 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); 706 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
827 } 707 }
828 if (texCoords) { 708 if (texCoords) {
829 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); 709 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
(...skipping 16 matching lines...) Expand all
846 flags |= DRAW_ATLAS_HAS_COLORS; 726 flags |= DRAW_ATLAS_HAS_COLORS;
847 size += count * sizeof(SkColor); 727 size += count * sizeof(SkColor);
848 size += sizeof(uint32_t); // xfermode::mode 728 size += sizeof(uint32_t); // xfermode::mode
849 } 729 }
850 if (cull) { 730 if (cull) {
851 flags |= DRAW_ATLAS_HAS_CULL; 731 flags |= DRAW_ATLAS_HAS_CULL;
852 size += sizeof(SkRect); 732 size += sizeof(SkRect);
853 } 733 }
854 734
855 size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); 735 size_t initialOffset = this->addDraw(DRAW_ATLAS, &size);
856 SkASSERT(initialOffset+get_paint_offset(DRAW_ATLAS, size) == fWriter.bytesWr itten());
857 this->addPaintPtr(paint); 736 this->addPaintPtr(paint);
858 this->addImage(atlas); 737 this->addImage(atlas);
859 this->addInt(flags); 738 this->addInt(flags);
860 this->addInt(count); 739 this->addInt(count);
861 fWriter.write(xform, count * sizeof(SkRSXform)); 740 fWriter.write(xform, count * sizeof(SkRSXform));
862 fWriter.write(tex, count * sizeof(SkRect)); 741 fWriter.write(tex, count * sizeof(SkRect));
863 742
864 // write optional parameters 743 // write optional parameters
865 if (colors) { 744 if (colors) {
866 fWriter.write(colors, count * sizeof(SkColor)); 745 fWriter.write(colors, count * sizeof(SkColor));
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 931 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
1053 int index = fTextBlobRefs.count(); 932 int index = fTextBlobRefs.count();
1054 *fTextBlobRefs.append() = blob; 933 *fTextBlobRefs.append() = blob;
1055 blob->ref(); 934 blob->ref();
1056 // follow the convention of recording a 1-based index 935 // follow the convention of recording a 1-based index
1057 this->addInt(index + 1); 936 this->addInt(index + 1);
1058 } 937 }
1059 938
1060 /////////////////////////////////////////////////////////////////////////////// 939 ///////////////////////////////////////////////////////////////////////////////
1061 940
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698