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 "SkTSearch.h" | 9 #include "SkTSearch.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 */ | 286 */ |
287 static bool match(SkWriter32* writer, uint32_t offset, | 287 static bool match(SkWriter32* writer, uint32_t offset, |
288 int* pattern, CommandInfo* result, int numCommands) { | 288 int* pattern, CommandInfo* result, int numCommands) { |
289 SkASSERT(offset < writer->bytesWritten()); | 289 SkASSERT(offset < writer->bytesWritten()); |
290 | 290 |
291 uint32_t curOffset = offset; | 291 uint32_t curOffset = offset; |
292 uint32_t curSize = 0; | 292 uint32_t curSize = 0; |
293 int numMatched; | 293 int numMatched; |
294 for (numMatched = 0; numMatched < numCommands && curOffset < writer->bytesWr
itten(); ++numMatched) { | 294 for (numMatched = 0; numMatched < numCommands && curOffset < writer->bytesWr
itten(); ++numMatched) { |
295 DrawType op = peek_op_and_size(writer, curOffset, &curSize); | 295 DrawType op = peek_op_and_size(writer, curOffset, &curSize); |
296 while (NOOP == op && curOffset < writer->bytesWritten()) { | 296 while (NOOP == op) { |
297 curOffset += curSize; | 297 curOffset += curSize; |
| 298 if (curOffset >= writer->bytesWritten()) { |
| 299 return false; |
| 300 } |
298 op = peek_op_and_size(writer, curOffset, &curSize); | 301 op = peek_op_and_size(writer, curOffset, &curSize); |
299 } | 302 } |
300 | 303 |
301 if (curOffset >= writer->bytesWritten()) { | |
302 return false; // ran out of byte stream | |
303 } | |
304 | |
305 if (kDRAW_BITMAP_FLAVOR == pattern[numMatched]) { | 304 if (kDRAW_BITMAP_FLAVOR == pattern[numMatched]) { |
306 if (DRAW_BITMAP != op && DRAW_BITMAP_MATRIX != op && | 305 if (DRAW_BITMAP != op && DRAW_BITMAP_MATRIX != op && |
307 DRAW_BITMAP_NINE != op && DRAW_BITMAP_RECT_TO_RECT != op) { | 306 DRAW_BITMAP_NINE != op && DRAW_BITMAP_RECT_TO_RECT != op) { |
308 return false; | 307 return false; |
309 } | 308 } |
310 } else if (op != pattern[numMatched]) { | 309 } else if (op != pattern[numMatched]) { |
311 return false; | 310 return false; |
312 } | 311 } |
313 | 312 |
314 result[numMatched].fActualOp = op; | 313 result[numMatched].fActualOp = op; |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 } | 1641 } |
1643 | 1642 |
1644 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { | 1643 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
1645 fWriter.writeMul4(pts, count * sizeof(SkPoint)); | 1644 fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
1646 #ifdef SK_DEBUG_SIZE | 1645 #ifdef SK_DEBUG_SIZE |
1647 fPointBytes += count * sizeof(SkPoint); | 1646 fPointBytes += count * sizeof(SkPoint); |
1648 fPointWrites++; | 1647 fPointWrites++; |
1649 #endif | 1648 #endif |
1650 } | 1649 } |
1651 | 1650 |
| 1651 void SkPictureRecord::addNoOp() { |
| 1652 size_t size = kUInt32Size; // op |
| 1653 this->addDraw(NOOP, &size); |
| 1654 } |
| 1655 |
1652 void SkPictureRecord::addRect(const SkRect& rect) { | 1656 void SkPictureRecord::addRect(const SkRect& rect) { |
1653 #ifdef SK_DEBUG_SIZE | 1657 #ifdef SK_DEBUG_SIZE |
1654 size_t start = fWriter.bytesWritten(); | 1658 size_t start = fWriter.bytesWritten(); |
1655 #endif | 1659 #endif |
1656 fWriter.writeRect(rect); | 1660 fWriter.writeRect(rect); |
1657 #ifdef SK_DEBUG_SIZE | 1661 #ifdef SK_DEBUG_SIZE |
1658 fRectBytes += fWriter.bytesWritten() - start; | 1662 fRectBytes += fWriter.bytesWritten() - start; |
1659 fRectWrites++; | 1663 fRectWrites++; |
1660 #endif | 1664 #endif |
1661 } | 1665 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 void SkPictureRecord::validateRegions() const { | 1826 void SkPictureRecord::validateRegions() const { |
1823 int count = fRegions.count(); | 1827 int count = fRegions.count(); |
1824 SkASSERT((unsigned) count < 0x1000); | 1828 SkASSERT((unsigned) count < 0x1000); |
1825 for (int index = 0; index < count; index++) { | 1829 for (int index = 0; index < count; index++) { |
1826 const SkFlatData* region = fRegions[index]; | 1830 const SkFlatData* region = fRegions[index]; |
1827 SkASSERT(region); | 1831 SkASSERT(region); |
1828 // region->validate(); | 1832 // region->validate(); |
1829 } | 1833 } |
1830 } | 1834 } |
1831 #endif | 1835 #endif |
OLD | NEW |