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 138013009: Culling API (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Comments, formatting. Created 6 years, 10 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
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 "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 this->validate(initialOffset, size); 1525 this->validate(initialOffset, size);
1524 } 1526 }
1525 1527
1526 void SkPictureRecord::endCommentGroup() { 1528 void SkPictureRecord::endCommentGroup() {
1527 // op/size 1529 // op/size
1528 uint32_t size = 1 * kUInt32Size; 1530 uint32_t size = 1 * kUInt32Size;
1529 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); 1531 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size);
1530 this->validate(initialOffset, size); 1532 this->validate(initialOffset, size);
1531 } 1533 }
1532 1534
1535 // [op/size] [rect] [skip offset]
1536 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect);
1537 void SkPictureRecord::onPushCull(const SkRect& cullRect) {
1538 // Skip identical cull rects.
1539 if (!fCullOffsetStack.isEmpty()) {
1540 const SkRect& prevCull = fWriter.readTAt<SkRect>(fCullOffsetStack.top() - sizeof(SkRect));
1541 if (prevCull == cullRect) {
1542 // Skipped culls are tracked on the stack, but they point to the pre vious offset.
1543 fCullOffsetStack.push(fCullOffsetStack.top());
1544 return;
1545 }
1546 }
1547
1548 uint32_t size = kPushCullOpSize;
1549 size_t initialOffset = this->addDraw(PUSH_CULL, &size);
1550 // PUSH_CULL's size should stay constant (used to rewind).
1551 SkASSERT(size == kPushCullOpSize);
1552
1553 addRect(cullRect);
1554 fCullOffsetStack.push(fWriter.bytesWritten());
1555 addInt(0);
1556 this->validate(initialOffset, size);
1557 }
1558
1559 void SkPictureRecord::onPopCull() {
1560 SkASSERT(!fCullOffsetStack.isEmpty());
1561
1562 uint32_t cullSkipOffset = fCullOffsetStack.top();
1563 fCullOffsetStack.pop();
1564
1565 // Skipped push, do the same for pop.
1566 if (!fCullOffsetStack.isEmpty() && cullSkipOffset == fCullOffsetStack.top()) {
1567 return;
1568 }
1569
1570 // Collapse empty push/pop pairs.
1571 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) {
1572 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize);
1573 SkASSERT(fWriter.readTAt<uint32_t>(
1574 fWriter.bytesWritten() - kPushCullOpSize) >> 24 == PUSH_CUL L);
1575 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize);
1576 return;
1577 }
1578
1579 // op only
1580 uint32_t size = kUInt32Size;
1581 size_t initialOffset = this->addDraw(POP_CULL, &size);
1582
1583 // update the cull skip offset to point past this op.
1584 fWriter.overwriteTAt<uint32_t>(cullSkipOffset, fWriter.bytesWritten());
1585
1586 this->validate(initialOffset, size);
1587 }
1588
1533 /////////////////////////////////////////////////////////////////////////////// 1589 ///////////////////////////////////////////////////////////////////////////////
1534 1590
1535 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { 1591 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) {
1536 return SkSurface::NewPicture(info.fWidth, info.fHeight); 1592 return SkSurface::NewPicture(info.fWidth, info.fHeight);
1537 } 1593 }
1538 1594
1539 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { 1595 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
1540 const int index = fBitmapHeap->insert(bitmap); 1596 const int index = fBitmapHeap->insert(bitmap);
1541 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In 1597 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In
1542 // release builds, the invalid value will be recorded so that the reader wil l know that there 1598 // 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
1778 void SkPictureRecord::validateRegions() const { 1834 void SkPictureRecord::validateRegions() const {
1779 int count = fRegions.count(); 1835 int count = fRegions.count();
1780 SkASSERT((unsigned) count < 0x1000); 1836 SkASSERT((unsigned) count < 0x1000);
1781 for (int index = 0; index < count; index++) { 1837 for (int index = 0; index < count; index++) {
1782 const SkFlatData* region = fRegions[index]; 1838 const SkFlatData* region = fRegions[index];
1783 SkASSERT(region); 1839 SkASSERT(region);
1784 // region->validate(); 1840 // region->validate();
1785 } 1841 }
1786 } 1842 }
1787 #endif 1843 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698