| 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 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 void SkPictureRecord::endCommentGroup() { | 1552 void SkPictureRecord::endCommentGroup() { |
| 1553 // op/size | 1553 // op/size |
| 1554 uint32_t size = 1 * kUInt32Size; | 1554 uint32_t size = 1 * kUInt32Size; |
| 1555 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); | 1555 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); |
| 1556 this->validate(initialOffset, size); | 1556 this->validate(initialOffset, size); |
| 1557 } | 1557 } |
| 1558 | 1558 |
| 1559 // [op/size] [rect] [skip offset] | 1559 // [op/size] [rect] [skip offset] |
| 1560 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); | 1560 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); |
| 1561 void SkPictureRecord::onPushCull(const SkRect& cullRect) { | 1561 void SkPictureRecord::onPushCull(const SkRect& cullRect) { |
| 1562 // Skip identical cull rects. | |
| 1563 if (!fCullOffsetStack.isEmpty()) { | |
| 1564 const SkRect& prevCull = fWriter.readTAt<SkRect>(fCullOffsetStack.top()
- sizeof(SkRect)); | |
| 1565 if (prevCull == cullRect) { | |
| 1566 // Skipped culls are tracked on the stack, but they point to the pre
vious offset. | |
| 1567 fCullOffsetStack.push(fCullOffsetStack.top()); | |
| 1568 return; | |
| 1569 } | |
| 1570 | |
| 1571 SkASSERT(prevCull.contains(cullRect)); | |
| 1572 } | |
| 1573 | |
| 1574 uint32_t size = kPushCullOpSize; | 1562 uint32_t size = kPushCullOpSize; |
| 1575 size_t initialOffset = this->addDraw(PUSH_CULL, &size); | 1563 size_t initialOffset = this->addDraw(PUSH_CULL, &size); |
| 1576 // PUSH_CULL's size should stay constant (used to rewind). | 1564 // PUSH_CULL's size should stay constant (used to rewind). |
| 1577 SkASSERT(size == kPushCullOpSize); | 1565 SkASSERT(size == kPushCullOpSize); |
| 1578 | 1566 |
| 1579 this->addRect(cullRect); | 1567 this->addRect(cullRect); |
| 1580 fCullOffsetStack.push(fWriter.bytesWritten()); | 1568 fCullOffsetStack.push(fWriter.bytesWritten()); |
| 1581 this->addInt(0); | 1569 this->addInt(0); |
| 1582 this->validate(initialOffset, size); | 1570 this->validate(initialOffset, size); |
| 1583 } | 1571 } |
| 1584 | 1572 |
| 1585 void SkPictureRecord::onPopCull() { | 1573 void SkPictureRecord::onPopCull() { |
| 1586 SkASSERT(!fCullOffsetStack.isEmpty()); | 1574 SkASSERT(!fCullOffsetStack.isEmpty()); |
| 1587 | 1575 |
| 1588 uint32_t cullSkipOffset = fCullOffsetStack.top(); | 1576 uint32_t cullSkipOffset = fCullOffsetStack.top(); |
| 1589 fCullOffsetStack.pop(); | 1577 fCullOffsetStack.pop(); |
| 1590 | 1578 |
| 1591 // Skipped push, do the same for pop. | |
| 1592 if (!fCullOffsetStack.isEmpty() && cullSkipOffset == fCullOffsetStack.top())
{ | |
| 1593 return; | |
| 1594 } | |
| 1595 | |
| 1596 // Collapse empty push/pop pairs. | 1579 // Collapse empty push/pop pairs. |
| 1597 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { | 1580 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { |
| 1598 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); | 1581 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); |
| 1599 SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCu
llOpSize)); | 1582 SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCu
llOpSize)); |
| 1600 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); | 1583 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); |
| 1601 return; | 1584 return; |
| 1602 } | 1585 } |
| 1603 | 1586 |
| 1604 // op only | 1587 // op only |
| 1605 uint32_t size = kUInt32Size; | 1588 uint32_t size = kUInt32Size; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 void SkPictureRecord::validateRegions() const { | 1867 void SkPictureRecord::validateRegions() const { |
| 1885 int count = fRegions.count(); | 1868 int count = fRegions.count(); |
| 1886 SkASSERT((unsigned) count < 0x1000); | 1869 SkASSERT((unsigned) count < 0x1000); |
| 1887 for (int index = 0; index < count; index++) { | 1870 for (int index = 0; index < count; index++) { |
| 1888 const SkFlatData* region = fRegions[index]; | 1871 const SkFlatData* region = fRegions[index]; |
| 1889 SkASSERT(region); | 1872 SkASSERT(region); |
| 1890 // region->validate(); | 1873 // region->validate(); |
| 1891 } | 1874 } |
| 1892 } | 1875 } |
| 1893 #endif | 1876 #endif |
| OLD | NEW |