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

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

Issue 499413002: SkTextBlob plumbing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: review comments Created 6 years, 3 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/SkPictureRecord.h ('k') | src/core/SkRecorder.h » ('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 "SkBBoxHierarchy.h" 9 #include "SkBBoxHierarchy.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkPatchUtils.h" 11 #include "SkPatchUtils.h"
12 #include "SkPictureStateTree.h" 12 #include "SkPictureStateTree.h"
13 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 #include "SkRRect.h" 14 #include "SkRRect.h"
15 #include "SkTextBlob.h"
15 #include "SkTSearch.h" 16 #include "SkTSearch.h"
16 17
17 #define HEAP_BLOCK_SIZE 4096 18 #define HEAP_BLOCK_SIZE 4096
18 19
19 // If SK_RECORD_LITERAL_PICTURES is defined, record our inputs as literally as p ossible. 20 // If SK_RECORD_LITERAL_PICTURES is defined, record our inputs as literally as p ossible.
20 // Otherwise, we can be clever and record faster equivalents. kBeClever is norm ally true. 21 // Otherwise, we can be clever and record faster equivalents. kBeClever is norm ally true.
21 static const bool kBeClever = 22 static const bool kBeClever =
22 #ifdef SK_RECORD_LITERAL_PICTURES 23 #ifdef SK_RECORD_LITERAL_PICTURES
23 false; 24 false;
24 #else 25 #else
(...skipping 27 matching lines...) Expand all
52 fFirstSavedLayerIndex = kNoSavedLayerIndex; 53 fFirstSavedLayerIndex = kNoSavedLayerIndex;
53 fInitialSaveCount = kNoInitialSave; 54 fInitialSaveCount = kNoInitialSave;
54 } 55 }
55 56
56 SkPictureRecord::~SkPictureRecord() { 57 SkPictureRecord::~SkPictureRecord() {
57 SkSafeUnref(fBitmapHeap); 58 SkSafeUnref(fBitmapHeap);
58 SkSafeUnref(fBoundingHierarchy); 59 SkSafeUnref(fBoundingHierarchy);
59 SkSafeUnref(fStateTree); 60 SkSafeUnref(fStateTree);
60 fFlattenableHeap.setBitmapStorage(NULL); 61 fFlattenableHeap.setBitmapStorage(NULL);
61 fPictureRefs.unrefAll(); 62 fPictureRefs.unrefAll();
63 fTextBlobRefs.unrefAll();
62 } 64 }
63 65
64 /////////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////////
65 67
66 // Return the offset of the paint inside a given op's byte stream. A zero 68 // Return the offset of the paint inside a given op's byte stream. A zero
67 // return value means there is no paint (and you really shouldn't be calling 69 // return value means there is no paint (and you really shouldn't be calling
68 // this method) 70 // this method)
69 static inline size_t getPaintOffset(DrawType op, size_t opSize) { 71 static inline size_t getPaintOffset(DrawType op, size_t opSize) {
70 // These offsets are where the paint would be if the op size doesn't overflo w 72 // These offsets are where the paint would be if the op size doesn't overflo w
71 static const uint8_t gPaintOffsets[] = { 73 static const uint8_t gPaintOffsets[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 0, // TRANSLATE - no paint 109 0, // TRANSLATE - no paint
108 0, // NOOP - no paint 110 0, // NOOP - no paint
109 0, // BEGIN_GROUP - no paint 111 0, // BEGIN_GROUP - no paint
110 0, // COMMENT - no paint 112 0, // COMMENT - no paint
111 0, // END_GROUP - no paint 113 0, // END_GROUP - no paint
112 1, // DRAWDRRECT - right after op code 114 1, // DRAWDRRECT - right after op code
113 0, // PUSH_CULL - no paint 115 0, // PUSH_CULL - no paint
114 0, // POP_CULL - no paint 116 0, // POP_CULL - no paint
115 1, // DRAW_PATCH - right after op code 117 1, // DRAW_PATCH - right after op code
116 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code 118 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code
119 1, // DRAW_TEXT_BLOB- right after op code
117 }; 120 };
118 121
119 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, 122 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1,
120 need_to_be_in_sync); 123 need_to_be_in_sync);
121 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); 124 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM);
122 125
123 int overflow = 0; 126 int overflow = 0;
124 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { 127 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) {
125 // This op's size overflows so an extra uint32_t will be written 128 // This op's size overflows so an extra uint32_t will be written
126 // after the op code 129 // after the op code
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return merge_savelayer_paint_into_drawbitmp(writer, paintDict, 458 return merge_savelayer_paint_into_drawbitmp(writer, paintDict,
456 result[0], result[3]); 459 result[0], result[3]);
457 } 460 }
458 461
459 static bool is_drawing_op(DrawType op) { 462 static bool is_drawing_op(DrawType op) {
460 463
461 // FIXME: yuck. convert to a lookup table? 464 // FIXME: yuck. convert to a lookup table?
462 return (op > CONCAT && op < ROTATE) 465 return (op > CONCAT && op < ROTATE)
463 || DRAW_DRRECT == op 466 || DRAW_DRRECT == op
464 || DRAW_PATCH == op 467 || DRAW_PATCH == op
465 || DRAW_PICTURE_MATRIX_PAINT == op; 468 || DRAW_PICTURE_MATRIX_PAINT == op
469 || DRAW_TEXT_BLOB == op;
466 } 470 }
467 471
468 /* 472 /*
469 * Restore has just been called (but not recorded), so look back at the 473 * Restore has just been called (but not recorded), so look back at the
470 * matching save(), and see if we can eliminate the pair of them, due to no 474 * matching save(), and see if we can eliminate the pair of them, due to no
471 * intervening matrix/clip calls. 475 * intervening matrix/clip calls.
472 * 476 *
473 * If so, update the writer and return true, in which case we won't even record 477 * If so, update the writer and return true, in which case we won't even record
474 * the restore() call. If we still need the restore(), return false. 478 * the restore() call. If we still need the restore(), return false.
475 */ 479 */
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(NULL); 1204 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(NULL);
1201 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 1205 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
1202 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten()); 1206 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten());
1203 this->addPaint(paint); 1207 this->addPaint(paint);
1204 this->addText(text, byteLength); 1208 this->addText(text, byteLength);
1205 this->addPath(path); 1209 this->addPath(path);
1206 this->addMatrix(m); 1210 this->addMatrix(m);
1207 this->validate(initialOffset, size); 1211 this->validate(initialOffset, size);
1208 } 1212 }
1209 1213
1214 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala r y,
1215 const SkPaint& paint) {
1216
1217 // op + paint index + blob index + x/y
1218 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
1219 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size);
1220 SkASSERT(initialOffset + getPaintOffset(DRAW_TEXT_BLOB, size) == fWriter.byt esWritten());
1221
1222 this->addPaint(paint);
1223 this->addTextBlob(blob);
1224 this->addScalar(x);
1225 this->addScalar(y);
1226
1227 this->validate(initialOffset, size);
1228 }
1229
1210 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix, 1230 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma trix,
1211 const SkPaint* paint) { 1231 const SkPaint* paint) {
1212 // op + picture index 1232 // op + picture index
1213 size_t size = 2 * kUInt32Size; 1233 size_t size = 2 * kUInt32Size;
1214 size_t initialOffset; 1234 size_t initialOffset;
1215 1235
1216 if (NULL == matrix && NULL == paint) { 1236 if (NULL == matrix && NULL == paint) {
1217 initialOffset = this->addDraw(DRAW_PICTURE, &size); 1237 initialOffset = this->addDraw(DRAW_PICTURE, &size);
1218 this->addPicture(picture); 1238 this->addPicture(picture);
1219 } else { 1239 } else {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 void SkPictureRecord::addRegion(const SkRegion& region) { 1536 void SkPictureRecord::addRegion(const SkRegion& region) {
1517 fWriter.writeRegion(region); 1537 fWriter.writeRegion(region);
1518 } 1538 }
1519 1539
1520 void SkPictureRecord::addText(const void* text, size_t byteLength) { 1540 void SkPictureRecord::addText(const void* text, size_t byteLength) {
1521 fContentInfo.onDrawText(); 1541 fContentInfo.onDrawText();
1522 addInt(SkToInt(byteLength)); 1542 addInt(SkToInt(byteLength));
1523 fWriter.writePad(text, byteLength); 1543 fWriter.writePad(text, byteLength);
1524 } 1544 }
1525 1545
1546 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
1547 int index = fTextBlobRefs.find(blob);
1548 if (index < 0) { // not found
1549 index = fTextBlobRefs.count();
1550 *fTextBlobRefs.append() = blob;
1551 blob->ref();
1552 }
1553 // follow the convention of recording a 1-based index
1554 this->addInt(index + 1);
1555 }
1556
1526 /////////////////////////////////////////////////////////////////////////////// 1557 ///////////////////////////////////////////////////////////////////////////////
1527 1558
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/core/SkRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698