| OLD | NEW |
| 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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 fMatrixClipStackStorage, | 103 fMatrixClipStackStorage, |
| 104 sizeof(fMatrixClipStackStorage)) | 104 sizeof(fMatrixClipStackStorage)) |
| 105 , fCurOpenStateID(kIdentityWideOpenStateID) { | 105 , fCurOpenStateID(kIdentityWideOpenStateID) { |
| 106 | 106 |
| 107 fSkipOffsets = SkNEW(SkTDArray<int>); | 107 fSkipOffsets = SkNEW(SkTDArray<int>); |
| 108 | 108 |
| 109 // The first slot in the matrix dictionary is reserved for the identity matr
ix | 109 // The first slot in the matrix dictionary is reserved for the identity matr
ix |
| 110 fMatrixDict.append()->reset(); | 110 fMatrixDict.append()->reset(); |
| 111 | 111 |
| 112 fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back(); | 112 fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back(); |
| 113 new (fCurMCState) MatrixClipState(NULL, 0); // balanced in restore() | 113 new (fCurMCState) MatrixClipState(NULL); // balanced in restore() |
| 114 | 114 |
| 115 #ifdef SK_DEBUG | 115 #ifdef SK_DEBUG |
| 116 fActualDepth = 0; | 116 fActualDepth = 0; |
| 117 #endif | 117 #endif |
| 118 } | 118 } |
| 119 | 119 |
| 120 SkMatrixClipStateMgr::~SkMatrixClipStateMgr() { | 120 SkMatrixClipStateMgr::~SkMatrixClipStateMgr() { |
| 121 for (int i = 0; i < fRegionDict.count(); ++i) { | 121 for (int i = 0; i < fRegionDict.count(); ++i) { |
| 122 SkDELETE(fRegionDict[i]); | 122 SkDELETE(fRegionDict[i]); |
| 123 } | 123 } |
| 124 | 124 |
| 125 SkDELETE(fSkipOffsets); | 125 SkDELETE(fSkipOffsets); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 int SkMatrixClipStateMgr::MCStackPush(SkCanvas::SaveFlags flags) { | 129 int SkMatrixClipStateMgr::MCStackPush() { |
| 130 MatrixClipState* newTop = (MatrixClipState*)fMatrixClipStack.push_back(); | 130 MatrixClipState* newTop = (MatrixClipState*)fMatrixClipStack.push_back(); |
| 131 new (newTop) MatrixClipState(fCurMCState, flags); // balanced in restore() | 131 new (newTop) MatrixClipState(fCurMCState); // balanced in restore() |
| 132 fCurMCState = newTop; | 132 fCurMCState = newTop; |
| 133 | 133 |
| 134 SkDEBUGCODE(this->validate();) | 134 SkDEBUGCODE(this->validate();) |
| 135 | 135 |
| 136 return fMatrixClipStack.count(); | 136 return fMatrixClipStack.count(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 int SkMatrixClipStateMgr::save(SkCanvas::SaveFlags flags) { | 139 int SkMatrixClipStateMgr::save() { |
| 140 SkDEBUGCODE(this->validate();) | 140 SkDEBUGCODE(this->validate();) |
| 141 | 141 |
| 142 return this->MCStackPush(flags); | 142 return this->MCStackPush(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 int SkMatrixClipStateMgr::saveLayer(const SkRect* bounds, const SkPaint* paint, | 145 int SkMatrixClipStateMgr::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 146 SkCanvas::SaveFlags flags) { | 146 SkCanvas::SaveFlags flags) { |
| 147 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
| 148 if (fCurMCState->fIsSaveLayer) { | 148 if (fCurMCState->fIsSaveLayer) { |
| 149 SkASSERT(0 == fSkipOffsets->count()); | 149 SkASSERT(0 == fSkipOffsets->count()); |
| 150 } | 150 } |
| 151 #endif | 151 #endif |
| 152 | 152 |
| 153 // Since the saveLayer call draws something we need to potentially dump | 153 // Since the saveLayer call draws something we need to potentially dump |
| 154 // out the MC state | 154 // out the MC state |
| 155 SkDEBUGCODE(bool saved =) this->call(kOther_CallType); | 155 SkDEBUGCODE(bool saved =) this->call(kOther_CallType); |
| 156 | 156 |
| 157 int result = this->MCStackPush(flags); | 157 int result = this->MCStackPush(); |
| 158 ++fCurMCState->fLayerID; | 158 ++fCurMCState->fLayerID; |
| 159 fCurMCState->fIsSaveLayer = true; | 159 fCurMCState->fIsSaveLayer = true; |
| 160 | 160 |
| 161 #ifdef SK_DEBUG | 161 #ifdef SK_DEBUG |
| 162 if (saved) { | 162 if (saved) { |
| 163 fCurMCState->fExpectedDepth++; // 1 for nesting save | 163 fCurMCState->fExpectedDepth++; // 1 for nesting save |
| 164 } | 164 } |
| 165 fCurMCState->fExpectedDepth++; // 1 for saveLayer | 165 fCurMCState->fExpectedDepth++; // 1 for saveLayer |
| 166 #endif | 166 #endif |
| 167 | 167 |
| 168 *fStateIDStack.append() = fCurOpenStateID; | 168 *fStateIDStack.append() = fCurOpenStateID; |
| 169 fCurMCState->fSavedSkipOffsets = fSkipOffsets; | 169 fCurMCState->fSavedSkipOffsets = fSkipOffsets; |
| 170 | 170 |
| 171 // TODO: recycle these rather then new & deleting them on every saveLayer/ | 171 // TODO: recycle these rather then new & deleting them on every saveLayer/ |
| 172 // restore | 172 // restore |
| 173 fSkipOffsets = SkNEW(SkTDArray<int>); | 173 fSkipOffsets = SkNEW(SkTDArray<int>); |
| 174 | 174 |
| 175 fPicRecord->recordSaveLayer(bounds, paint, flags | SkCanvas::kMatrixClip_Sav
eFlag); | 175 fPicRecord->recordSaveLayer(bounds, paint, flags); |
| 176 #ifdef SK_DEBUG | 176 #ifdef SK_DEBUG |
| 177 fActualDepth++; | 177 fActualDepth++; |
| 178 #endif | 178 #endif |
| 179 return result; | 179 return result; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void SkMatrixClipStateMgr::restore() { | 182 void SkMatrixClipStateMgr::restore() { |
| 183 SkDEBUGCODE(this->validate();) | 183 SkDEBUGCODE(this->validate();) |
| 184 | 184 |
| 185 if (fCurMCState->fIsSaveLayer) { | 185 if (fCurMCState->fIsSaveLayer) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (kIdentityWideOpenStateID == fCurOpenStateID) { | 282 if (kIdentityWideOpenStateID == fCurOpenStateID) { |
| 283 SkASSERT(0 == fActualDepth); | 283 SkASSERT(0 == fActualDepth); |
| 284 SkASSERT(!fCurMCState->fHasOpen); | 284 SkASSERT(!fCurMCState->fHasOpen); |
| 285 SkASSERT(0 == fSkipOffsets->count()); | 285 SkASSERT(0 == fSkipOffsets->count()); |
| 286 return false; | 286 return false; |
| 287 } | 287 } |
| 288 | 288 |
| 289 SkASSERT(!fCurMCState->fHasOpen); | 289 SkASSERT(!fCurMCState->fHasOpen); |
| 290 SkASSERT(0 == fSkipOffsets->count()); | 290 SkASSERT(0 == fSkipOffsets->count()); |
| 291 fCurMCState->fHasOpen = true; | 291 fCurMCState->fHasOpen = true; |
| 292 fPicRecord->recordSave(SkCanvas::kMatrixClip_SaveFlag); | 292 fPicRecord->recordSave(); |
| 293 #ifdef SK_DEBUG | 293 #ifdef SK_DEBUG |
| 294 fActualDepth++; | 294 fActualDepth++; |
| 295 SkASSERT(fActualDepth == fCurMCState->fExpectedDepth); | 295 SkASSERT(fActualDepth == fCurMCState->fExpectedDepth); |
| 296 #endif | 296 #endif |
| 297 | 297 |
| 298 // write out clips | 298 // write out clips |
| 299 SkDeque::Iter iter(fMatrixClipStack, SkDeque::Iter::kBack_IterStart); | 299 SkDeque::Iter iter(fMatrixClipStack, SkDeque::Iter::kBack_IterStart); |
| 300 const MatrixClipState* state; | 300 const MatrixClipState* state; |
| 301 // Loop back across the MC states until the last saveLayer. The MC | 301 // Loop back across the MC states until the last saveLayer. The MC |
| 302 // state in front of the saveLayer has already been written out. | 302 // state in front of the saveLayer has already been written out. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 410 } |
| 411 | 411 |
| 412 int SkMatrixClipStateMgr::addMatToDict(const SkMatrix& mat) { | 412 int SkMatrixClipStateMgr::addMatToDict(const SkMatrix& mat) { |
| 413 if (mat.isIdentity()) { | 413 if (mat.isIdentity()) { |
| 414 return kIdentityMatID; | 414 return kIdentityMatID; |
| 415 } | 415 } |
| 416 | 416 |
| 417 *fMatrixDict.append() = mat; | 417 *fMatrixDict.append() = mat; |
| 418 return fMatrixDict.count()-1; | 418 return fMatrixDict.count()-1; |
| 419 } | 419 } |
| OLD | NEW |