Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 // 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 |
| 69 // 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 |
| 70 // this method) | 70 // this method) |
| 71 static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) { | 71 static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) { |
| 72 // 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 |
| 73 static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = { | 73 static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = { |
| 74 0, // UNUSED - no paint | 74 0, // UNUSED - no paint |
| 75 0, // CLIP_PATH - no paint | 75 0, // CLIP_PATH - no paint |
| 76 0, // CLIP_REGION - no paint | 76 0, // CLIP_REGION - no paint |
| 77 0, // CLIP_RECT - no paint | 77 0, // CLIP_RECT - no paint |
| 78 0, // CLIP_RRECT - no paint | 78 0, // CLIP_RRECT - no paint |
|
robertphillips
2014/02/25 15:58:41
move to match other moves?
f(malita)
2014/02/25 16:50:28
Will do.
| |
| 79 0, // PUSH_CULL - no paint | |
| 80 0, // POP_CULL - no paint | |
| 79 0, // CONCAT - no paint | 81 0, // CONCAT - no paint |
| 80 1, // DRAW_BITMAP - right after op code | 82 1, // DRAW_BITMAP - right after op code |
| 81 1, // DRAW_BITMAP_MATRIX - right after op code | 83 1, // DRAW_BITMAP_MATRIX - right after op code |
| 82 1, // DRAW_BITMAP_NINE - right after op code | 84 1, // DRAW_BITMAP_NINE - right after op code |
| 83 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code | 85 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code |
| 84 0, // DRAW_CLEAR - no paint | 86 0, // DRAW_CLEAR - no paint |
| 85 0, // DRAW_DATA - no paint | 87 0, // DRAW_DATA - no paint |
| 86 1, // DRAW_OVAL - right after op code | 88 1, // DRAW_OVAL - right after op code |
| 87 1, // DRAW_PAINT - right after op code | 89 1, // DRAW_PAINT - right after op code |
| 88 1, // DRAW_PATH - right after op code | 90 1, // DRAW_PATH - right after op code |
| (...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1541 this->validate(initialOffset, size); | 1543 this->validate(initialOffset, size); |
| 1542 } | 1544 } |
| 1543 | 1545 |
| 1544 void SkPictureRecord::endCommentGroup() { | 1546 void SkPictureRecord::endCommentGroup() { |
| 1545 // op/size | 1547 // op/size |
| 1546 uint32_t size = 1 * kUInt32Size; | 1548 uint32_t size = 1 * kUInt32Size; |
| 1547 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); | 1549 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); |
| 1548 this->validate(initialOffset, size); | 1550 this->validate(initialOffset, size); |
| 1549 } | 1551 } |
| 1550 | 1552 |
| 1553 // [op/size] [rect] [skip offset] | |
| 1554 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); | |
| 1555 void SkPictureRecord::onPushCull(const SkRect& cullRect) { | |
|
robertphillips
2014/02/25 15:58:41
Don't we also want to assert that the current cull
f(malita)
2014/02/25 16:50:28
At a high level it surely makes sense (and my init
| |
| 1556 // Skip identical cull rects. | |
| 1557 if (!fCullOffsetStack.isEmpty()) { | |
| 1558 const SkRect& prevCull = fWriter.readTAt<SkRect>(fCullOffsetStack.top() - sizeof(SkRect)); | |
| 1559 if (prevCull == cullRect) { | |
| 1560 // Skipped culls are tracked on the stack, but they point to the pre vious offset. | |
| 1561 fCullOffsetStack.push(fCullOffsetStack.top()); | |
| 1562 return; | |
| 1563 } | |
| 1564 } | |
| 1565 | |
| 1566 uint32_t size = kPushCullOpSize; | |
| 1567 size_t initialOffset = this->addDraw(PUSH_CULL, &size); | |
| 1568 // PUSH_CULL's size should stay constant (used to rewind). | |
| 1569 SkASSERT(size == kPushCullOpSize); | |
| 1570 | |
|
robertphillips
2014/02/25 15:58:41
this->
| |
| 1571 addRect(cullRect); | |
| 1572 fCullOffsetStack.push(fWriter.bytesWritten()); | |
|
robertphillips
2014/02/25 15:58:41
this->
| |
| 1573 addInt(0); | |
| 1574 this->validate(initialOffset, size); | |
| 1575 } | |
| 1576 | |
| 1577 void SkPictureRecord::onPopCull() { | |
| 1578 SkASSERT(!fCullOffsetStack.isEmpty()); | |
| 1579 | |
| 1580 uint32_t cullSkipOffset = fCullOffsetStack.top(); | |
| 1581 fCullOffsetStack.pop(); | |
| 1582 | |
| 1583 // Skipped push, do the same for pop. | |
| 1584 if (!fCullOffsetStack.isEmpty() && cullSkipOffset == fCullOffsetStack.top()) { | |
| 1585 return; | |
| 1586 } | |
| 1587 | |
| 1588 // Collapse empty push/pop pairs. | |
| 1589 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { | |
| 1590 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); | |
|
robertphillips
2014/02/25 15:58:41
can we have a peek_op static function for this?
| |
| 1591 SkASSERT(fWriter.readTAt<uint32_t>( | |
| 1592 fWriter.bytesWritten() - kPushCullOpSize) >> 24 == PUSH_CUL L); | |
| 1593 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); | |
| 1594 return; | |
| 1595 } | |
| 1596 | |
| 1597 // op only | |
| 1598 uint32_t size = kUInt32Size; | |
| 1599 size_t initialOffset = this->addDraw(POP_CULL, &size); | |
| 1600 | |
| 1601 // update the cull skip offset to point past this op. | |
| 1602 fWriter.overwriteTAt<uint32_t>(cullSkipOffset, fWriter.bytesWritten()); | |
| 1603 | |
| 1604 this->validate(initialOffset, size); | |
| 1605 } | |
| 1606 | |
| 1551 /////////////////////////////////////////////////////////////////////////////// | 1607 /////////////////////////////////////////////////////////////////////////////// |
| 1552 | 1608 |
| 1553 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { | 1609 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { |
| 1554 return SkSurface::NewPicture(info.fWidth, info.fHeight); | 1610 return SkSurface::NewPicture(info.fWidth, info.fHeight); |
| 1555 } | 1611 } |
| 1556 | 1612 |
| 1557 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | 1613 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
| 1558 const int index = fBitmapHeap->insert(bitmap); | 1614 const int index = fBitmapHeap->insert(bitmap); |
| 1559 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In | 1615 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In |
| 1560 // release builds, the invalid value will be recorded so that the reader wil l know that there | 1616 // release builds, the invalid value will be recorded so that the reader wil l know that there |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1796 void SkPictureRecord::validateRegions() const { | 1852 void SkPictureRecord::validateRegions() const { |
| 1797 int count = fRegions.count(); | 1853 int count = fRegions.count(); |
| 1798 SkASSERT((unsigned) count < 0x1000); | 1854 SkASSERT((unsigned) count < 0x1000); |
| 1799 for (int index = 0; index < count; index++) { | 1855 for (int index = 0; index < count; index++) { |
| 1800 const SkFlatData* region = fRegions[index]; | 1856 const SkFlatData* region = fRegions[index]; |
| 1801 SkASSERT(region); | 1857 SkASSERT(region); |
| 1802 // region->validate(); | 1858 // region->validate(); |
| 1803 } | 1859 } |
| 1804 } | 1860 } |
| 1805 #endif | 1861 #endif |
| OLD | NEW |