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

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

Issue 13957009: First pass at Comment API (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Addressed code review issues Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/pipe/SkGPipeWrite.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 1, // DRAW_VERTICES - right after op code 99 1, // DRAW_VERTICES - right after op code
100 0, // RESTORE - no paint 100 0, // RESTORE - no paint
101 0, // ROTATE - no paint 101 0, // ROTATE - no paint
102 0, // SAVE - no paint 102 0, // SAVE - no paint
103 0, // SAVE_LAYER - see below - this paint's location varies 103 0, // SAVE_LAYER - see below - this paint's location varies
104 0, // SCALE - no paint 104 0, // SCALE - no paint
105 0, // SET_MATRIX - no paint 105 0, // SET_MATRIX - no paint
106 0, // SKEW - no paint 106 0, // SKEW - no paint
107 0, // TRANSLATE - no paint 107 0, // TRANSLATE - no paint
108 0, // NOOP - no paint 108 0, // NOOP - no paint
109 0, // BEGIN_GROUP - no paint
110 0, // COMMENT - no paint
111 0, // END_GROUP - no paint
109 }; 112 };
110 113
111 SkASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1); 114 SkASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1);
112 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); 115 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM);
113 116
114 int overflow = 0; 117 int overflow = 0;
115 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { 118 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) {
116 // This op's size overflows so an extra uint32_t will be written 119 // This op's size overflows so an extra uint32_t will be written
117 // after the op code 120 // after the op code
118 overflow = sizeof(uint32_t); 121 overflow = sizeof(uint32_t);
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1272
1270 void SkPictureRecord::drawData(const void* data, size_t length) { 1273 void SkPictureRecord::drawData(const void* data, size_t length) {
1271 // op + length + 'length' worth of data 1274 // op + length + 'length' worth of data
1272 uint32_t size = 2 * kUInt32Size + SkAlign4(length); 1275 uint32_t size = 2 * kUInt32Size + SkAlign4(length);
1273 uint32_t initialOffset = this->addDraw(DRAW_DATA, &size); 1276 uint32_t initialOffset = this->addDraw(DRAW_DATA, &size);
1274 addInt(length); 1277 addInt(length);
1275 fWriter.writePad(data, length); 1278 fWriter.writePad(data, length);
1276 validate(initialOffset, size); 1279 validate(initialOffset, size);
1277 } 1280 }
1278 1281
1282 void SkPictureRecord::beginCommentGroup(const char* description) {
1283 // op/size + length of string + \0 terminated chars
1284 int length = strlen(description);
1285 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1);
1286 uint32_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size);
1287 fWriter.writeString(description, length);
1288 validate(initialOffset, size);
1289 }
1290
1291 void SkPictureRecord::addComment(const char* kywd, const char* value) {
1292 // op/size + 2x length of string + 2x \0 terminated chars
1293 int kywdLen = strlen(kywd);
1294 int valueLen = strlen(value);
1295 uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1);
1296 uint32_t initialOffset = this->addDraw(COMMENT, &size);
1297 fWriter.writeString(kywd, kywdLen);
1298 fWriter.writeString(value, valueLen);
1299 validate(initialOffset, size);
1300 }
1301
1302 void SkPictureRecord::endCommentGroup() {
1303 // op/size
1304 uint32_t size = 1 * kUInt32Size;
1305 uint32_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size);
1306 validate(initialOffset, size);
1307 }
1308
1279 /////////////////////////////////////////////////////////////////////////////// 1309 ///////////////////////////////////////////////////////////////////////////////
1280 1310
1281 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { 1311 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
1282 const int index = fBitmapHeap->insert(bitmap); 1312 const int index = fBitmapHeap->insert(bitmap);
1283 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In 1313 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In
1284 // release builds, the invalid value will be recorded so that the reader wil l know that there 1314 // release builds, the invalid value will be recorded so that the reader wil l know that there
1285 // was a problem. 1315 // was a problem.
1286 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); 1316 SkASSERT(index != SkBitmapHeap::INVALID_SLOT);
1287 addInt(index); 1317 addInt(index);
1288 } 1318 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 void SkPictureRecord::validateRegions() const { 1542 void SkPictureRecord::validateRegions() const {
1513 int count = fRegions.count(); 1543 int count = fRegions.count();
1514 SkASSERT((unsigned) count < 0x1000); 1544 SkASSERT((unsigned) count < 0x1000);
1515 for (int index = 0; index < count; index++) { 1545 for (int index = 0; index < count; index++) {
1516 const SkFlatData* region = fRegions[index]; 1546 const SkFlatData* region = fRegions[index];
1517 SkASSERT(region); 1547 SkASSERT(region);
1518 // region->validate(); 1548 // region->validate();
1519 } 1549 }
1520 } 1550 }
1521 #endif 1551 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/pipe/SkGPipeWrite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698