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

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

Issue 151033004: Add matrix dictionary to SkMatrixClipStateMgr (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: updated to Tot 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
« no previous file with comments | « src/core/SkMatrixClipStateMgr.h ('k') | no next file » | 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkMatrixClipStateMgr.h" 8 #include "SkMatrixClipStateMgr.h"
9 #include "SkPictureRecord.h" 9 #include "SkPictureRecord.h"
10 10
11 bool SkMatrixClipStateMgr::MatrixClipState::ClipInfo::clipPath(SkPictureRecord* picRecord, 11 bool SkMatrixClipStateMgr::MatrixClipState::ClipInfo::clipPath(SkPictureRecord* picRecord,
12 const SkPath& pat h, 12 const SkPath& pat h,
13 SkRegion::Op op, 13 SkRegion::Op op,
14 bool doAA, 14 bool doAA,
15 const SkMatrix& m atrix) { 15 int matrixID) {
16 int pathID = picRecord->addPathToHeap(path); 16 int pathID = picRecord->addPathToHeap(path);
17 17
18 ClipOp& newClip = fClips.push_back(); 18 ClipOp& newClip = fClips.push_back();
19 newClip.fClipType = kPath_ClipType; 19 newClip.fClipType = kPath_ClipType;
20 newClip.fGeom.fPathID = pathID; 20 newClip.fGeom.fPathID = pathID;
21 newClip.fOp = op; 21 newClip.fOp = op;
22 newClip.fDoAA = doAA; 22 newClip.fDoAA = doAA;
23 newClip.fMatrix = matrix; 23 newClip.fMatrixID = matrixID;
24 newClip.fOffset = kInvalidJumpOffset; 24 newClip.fOffset = kInvalidJumpOffset;
25 return false; 25 return false;
26 } 26 }
27 27
28 bool SkMatrixClipStateMgr::MatrixClipState::ClipInfo::clipRegion(SkPictureRecord * picRecord, 28 bool SkMatrixClipStateMgr::MatrixClipState::ClipInfo::clipRegion(SkPictureRecord * picRecord,
29 const SkRegion& region, 29 const SkRegion& region,
30 SkRegion::Op op , 30 SkRegion::Op op ,
31 const SkMatrix& matrix) { 31 int matrixID) {
32 // TODO: add a region dictionary so we don't have to copy the region in here 32 // TODO: add a region dictionary so we don't have to copy the region in here
33 ClipOp& newClip = fClips.push_back(); 33 ClipOp& newClip = fClips.push_back();
34 newClip.fClipType = kRegion_ClipType; 34 newClip.fClipType = kRegion_ClipType;
35 newClip.fGeom.fRegion = SkNEW(SkRegion(region)); 35 newClip.fGeom.fRegion = SkNEW(SkRegion(region));
36 newClip.fOp = op; 36 newClip.fOp = op;
37 newClip.fDoAA = true; // not necessary but sanity preserving 37 newClip.fDoAA = true; // not necessary but sanity preserving
38 newClip.fMatrix = matrix; 38 newClip.fMatrixID = matrixID;
39 newClip.fOffset = kInvalidJumpOffset; 39 newClip.fOffset = kInvalidJumpOffset;
40 return false; 40 return false;
41 } 41 }
42 42
43 void SkMatrixClipStateMgr::WriteDeltaMat(SkPictureRecord* picRecord, 43 void SkMatrixClipStateMgr::writeDeltaMat(int currentMatID, int desiredMatID) {
44 const SkMatrix& current, 44 const SkMatrix& current = this->lookupMat(currentMatID);
45 const SkMatrix& desired) { 45 const SkMatrix& desired = this->lookupMat(desiredMatID);
46
46 SkMatrix delta; 47 SkMatrix delta;
47 bool result = current.invert(&delta); 48 bool result = current.invert(&delta);
48 if (result) { 49 if (result) {
49 delta.preConcat(desired); 50 delta.preConcat(desired);
50 } 51 }
51 picRecord->recordConcat(delta); 52 fPicRecord->recordConcat(delta);
52 } 53 }
53 54
54 // Note: this only writes out the clips for the current save state. To get the 55 // Note: this only writes out the clips for the current save state. To get the
55 // entire clip stack requires iterating of the entire matrix/clip stack. 56 // entire clip stack requires iterating of the entire matrix/clip stack.
56 void SkMatrixClipStateMgr::MatrixClipState::ClipInfo::writeClip(SkMatrix* curMat , 57 void SkMatrixClipStateMgr::MatrixClipState::ClipInfo::writeClip(int* curMatID,
57 SkPictureRecord* picRecord, 58 SkMatrixClipStat eMgr* mgr,
58 bool* overrideFi rstOp) { 59 bool* overrideFi rstOp) {
59 for (int i = 0; i < fClips.count(); ++i) { 60 for (int i = 0; i < fClips.count(); ++i) {
60 ClipOp& curClip = fClips[i]; 61 ClipOp& curClip = fClips[i];
61 62
62 SkRegion::Op op = curClip.fOp; 63 SkRegion::Op op = curClip.fOp;
63 if (*overrideFirstOp) { 64 if (*overrideFirstOp) {
64 op = SkRegion::kReplace_Op; 65 op = SkRegion::kReplace_Op;
65 *overrideFirstOp = false; 66 *overrideFirstOp = false;
66 } 67 }
67 68
68 // TODO: re-add an internal matrix dictionary to not write out 69 // TODO: use the matrix ID to skip writing the identity matrix
69 // redundant matrices. 70 // over and over, i.e.:
71 // if (*curMatID != curClip.fMatrixID) {
72 // mgr->writeDeltaMat...
73 // *curMatID...
74 // }
75 // Right now this optimization would throw off the testing harness.
70 // TODO: right now we're writing out the delta matrix from the prior 76 // TODO: right now we're writing out the delta matrix from the prior
71 // matrix state. This is a side-effect of writing out the entire 77 // matrix state. This is a side-effect of writing out the entire
72 // clip stack and should be resolved when that is fixed. 78 // clip stack and should be resolved when that is fixed.
73 SkMatrixClipStateMgr::WriteDeltaMat(picRecord, *curMat, curClip.fMatrix) ; 79 mgr->writeDeltaMat(*curMatID, curClip.fMatrixID);
74 *curMat = curClip.fMatrix; 80 *curMatID = curClip.fMatrixID;
75 81
76 switch (curClip.fClipType) { 82 switch (curClip.fClipType) {
77 case kRect_ClipType: 83 case kRect_ClipType:
78 curClip.fOffset = picRecord->recordClipRect(curClip.fGeom.fRRect.rec t(), 84 curClip.fOffset = mgr->getPicRecord()->recordClipRect(curClip.fGeom. fRRect.rect(),
79 op, curClip.fDoAA); 85 op, curClip.fD oAA);
80 break; 86 break;
81 case kRRect_ClipType: 87 case kRRect_ClipType:
82 curClip.fOffset = picRecord->recordClipRRect(curClip.fGeom.fRRect, o p, 88 curClip.fOffset = mgr->getPicRecord()->recordClipRRect(curClip.fGeom .fRRect, op,
83 curClip.fDoAA); 89 curClip.fDoAA );
84 break; 90 break;
85 case kPath_ClipType: 91 case kPath_ClipType:
86 curClip.fOffset = picRecord->recordClipPath(curClip.fGeom.fPathID, o p, 92 curClip.fOffset = mgr->getPicRecord()->recordClipPath(curClip.fGeom. fPathID, op,
87 curClip.fDoAA); 93 curClip.fDoAA) ;
88 break; 94 break;
89 case kRegion_ClipType: 95 case kRegion_ClipType:
90 curClip.fOffset = picRecord->recordClipRegion(*curClip.fGeom.fRegion , op); 96 curClip.fOffset = mgr->getPicRecord()->recordClipRegion(*curClip.fGe om.fRegion, op);
91 break; 97 break;
92 default: 98 default:
93 SkASSERT(0); 99 SkASSERT(0);
94 } 100 }
95 } 101 }
96 } 102 }
97 103
98 // Fill in the skip offsets for all the clips written in the current block 104 // Fill in the skip offsets for all the clips written in the current block
99 void SkMatrixClipStateMgr::MatrixClipState::ClipInfo::fillInSkips(SkWriter32* wr iter, 105 void SkMatrixClipStateMgr::MatrixClipState::ClipInfo::fillInSkips(SkWriter32* wr iter,
100 int32_t restor eOffset) { 106 int32_t restor eOffset) {
101 for (int i = 0; i < fClips.count(); ++i) { 107 for (int i = 0; i < fClips.count(); ++i) {
102 ClipOp& curClip = fClips[i]; 108 ClipOp& curClip = fClips[i];
103 109
104 if (-1 == curClip.fOffset) { 110 if (-1 == curClip.fOffset) {
105 continue; 111 continue;
106 } 112 }
107 // SkDEBUGCODE(uint32_t peek = writer->read32At(curClip.fOffset);) 113 // SkDEBUGCODE(uint32_t peek = writer->read32At(curClip.fOffset);)
108 // SkASSERT(-1 == peek); 114 // SkASSERT(-1 == peek);
109 writer->overwriteTAt(curClip.fOffset, restoreOffset); 115 writer->overwriteTAt(curClip.fOffset, restoreOffset);
110 SkDEBUGCODE(curClip.fOffset = -1;) 116 SkDEBUGCODE(curClip.fOffset = -1;)
111 } 117 }
112 } 118 }
113 119
114 SkMatrixClipStateMgr::SkMatrixClipStateMgr() 120 SkMatrixClipStateMgr::SkMatrixClipStateMgr()
115 : fPicRecord(NULL) 121 : fPicRecord(NULL)
116 , fMatrixClipStack(sizeof(MatrixClipState), 122 , fMatrixClipStack(sizeof(MatrixClipState),
117 fMatrixClipStackStorage, 123 fMatrixClipStackStorage,
118 sizeof(fMatrixClipStackStorage)) 124 sizeof(fMatrixClipStackStorage))
119 , fCurOpenStateID(kIdentityWideOpenStateID) { 125 , fCurOpenStateID(kIdentityWideOpenStateID) {
126
127 // The first slot in the matrix dictionary is reserved for the identity matr ix
128 fMatrixDict.append()->reset();
129
120 fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back(); 130 fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back();
121 new (fCurMCState) MatrixClipState(NULL, 0); // balanced in restore() 131 new (fCurMCState) MatrixClipState(NULL, 0); // balanced in restore()
122 } 132 }
123 133
124 134
125 int SkMatrixClipStateMgr::save(SkCanvas::SaveFlags flags) { 135 int SkMatrixClipStateMgr::save(SkCanvas::SaveFlags flags) {
126 SkDEBUGCODE(this->validate();) 136 SkDEBUGCODE(this->validate();)
127 137
128 MatrixClipState* newTop = (MatrixClipState*)fMatrixClipStack.push_back(); 138 MatrixClipState* newTop = (MatrixClipState*)fMatrixClipStack.push_back();
129 new (newTop) MatrixClipState(fCurMCState, flags); // balanced in restore() 139 new (newTop) MatrixClipState(fCurMCState, flags); // balanced in restore()
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 218
209 // Install the required MC state as the active one 219 // Install the required MC state as the active one
210 fCurOpenStateID = fCurMCState->fMCStateID; 220 fCurOpenStateID = fCurMCState->fMCStateID;
211 221
212 fPicRecord->recordSave(SkCanvas::kMatrixClip_SaveFlag); 222 fPicRecord->recordSave(SkCanvas::kMatrixClip_SaveFlag);
213 223
214 // write out clips 224 // write out clips
215 SkDeque::F2BIter iter(fMatrixClipStack); 225 SkDeque::F2BIter iter(fMatrixClipStack);
216 bool firstClip = true; 226 bool firstClip = true;
217 227
218 SkMatrix curMat = SkMatrix::I(); 228 int curMatID = kIdentityMatID;
219 for (const MatrixClipState* state = (const MatrixClipState*) iter.next(); 229 for (const MatrixClipState* state = (const MatrixClipState*) iter.next();
220 state != NULL; 230 state != NULL;
221 state = (const MatrixClipState*) iter.next()) { 231 state = (const MatrixClipState*) iter.next()) {
222 state->fClipInfo->writeClip(&curMat, fPicRecord, &firstClip); 232 state->fClipInfo->writeClip(&curMatID, this, &firstClip);
223 } 233 }
224 234
225 // write out matrix 235 // write out matrix
226 if (!fCurMCState->fMatrixInfo->fMatrix.isIdentity()) { 236 if (kIdentityMatID != fCurMCState->fMatrixInfo->getID(this)) {
227 // TODO: writing out the delta matrix here is an artifact of the writing 237 // TODO: writing out the delta matrix here is an artifact of the writing
228 // out of the entire clip stack (with its matrices). Ultimately we will 238 // out of the entire clip stack (with its matrices). Ultimately we will
229 // write out the CTM here when the clip state is collapsed to a single p ath. 239 // write out the CTM here when the clip state is collapsed to a single p ath.
230 WriteDeltaMat(fPicRecord, curMat, fCurMCState->fMatrixInfo->fMatrix); 240 this->writeDeltaMat(curMatID, fCurMCState->fMatrixInfo->getID(this));
231 } 241 }
232 242
233 SkDEBUGCODE(this->validate();) 243 SkDEBUGCODE(this->validate();)
234 244
235 return true; 245 return true;
236 } 246 }
237 247
238 void SkMatrixClipStateMgr::finish() { 248 void SkMatrixClipStateMgr::finish() {
239 if (kIdentityWideOpenStateID != fCurOpenStateID) { 249 if (kIdentityWideOpenStateID != fCurOpenStateID) {
240 fPicRecord->recordRestore(); // Close the open block 250 fPicRecord->recordRestore(); // Close the open block
241 fCurOpenStateID = kIdentityWideOpenStateID; 251 fCurOpenStateID = kIdentityWideOpenStateID;
242 } 252 }
243 } 253 }
244 254
245 #ifdef SK_DEBUG 255 #ifdef SK_DEBUG
246 void SkMatrixClipStateMgr::validate() { 256 void SkMatrixClipStateMgr::validate() {
247 if (fCurOpenStateID == fCurMCState->fMCStateID) { 257 if (fCurOpenStateID == fCurMCState->fMCStateID) {
248 // The current state is the active one so all its skip offsets should 258 // The current state is the active one so all its skip offsets should
249 // still be -1 259 // still be -1
250 SkDeque::F2BIter iter(fMatrixClipStack); 260 SkDeque::F2BIter iter(fMatrixClipStack);
251 261
252 for (const MatrixClipState* state = (const MatrixClipState*) iter.next() ; 262 for (const MatrixClipState* state = (const MatrixClipState*) iter.next() ;
253 state != NULL; 263 state != NULL;
254 state = (const MatrixClipState*) iter.next()) { 264 state = (const MatrixClipState*) iter.next()) {
255 state->fClipInfo->checkOffsetNotEqual(-1); 265 state->fClipInfo->checkOffsetNotEqual(-1);
256 } 266 }
257 } 267 }
258 } 268 }
259 #endif 269 #endif
270
271 int SkMatrixClipStateMgr::addMatToDict(const SkMatrix& mat) {
272 if (mat.isIdentity()) {
273 return kIdentityMatID;
274 }
275
276 *fMatrixDict.append() = mat;
277 return fMatrixDict.count()-1;
278 }
OLDNEW
« no previous file with comments | « src/core/SkMatrixClipStateMgr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698