| 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 #ifndef SkMatrixClipStateMgr_DEFINED | 7 #ifndef SkMatrixClipStateMgr_DEFINED |
| 8 #define SkMatrixClipStateMgr_DEFINED | 8 #define SkMatrixClipStateMgr_DEFINED |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // The CTM in effect when this clip call was issued | 173 // The CTM in effect when this clip call was issued |
| 174 int fMatrixID; | 174 int fMatrixID; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 SkTDArray<ClipOp> fClips; | 177 SkTDArray<ClipOp> fClips; |
| 178 | 178 |
| 179 typedef SkNoncopyable INHERITED; | 179 typedef SkNoncopyable INHERITED; |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 MatrixClipState(MatrixClipState* prev, int flags) | 182 MatrixClipState(MatrixClipState* prev, int flags) |
| 183 #ifdef SK_DEBUG | |
| 184 : fPrev(prev) | 183 : fPrev(prev) |
| 185 #endif | |
| 186 { | 184 { |
| 185 fHasOpen = false; |
| 186 |
| 187 if (NULL == prev) { | 187 if (NULL == prev) { |
| 188 fLayerID = 0; | 188 fLayerID = 0; |
| 189 | 189 |
| 190 fMatrixInfoStorage.reset(); | 190 fMatrixInfoStorage.reset(); |
| 191 fMatrixInfo = &fMatrixInfoStorage; | 191 fMatrixInfo = &fMatrixInfoStorage; |
| 192 fClipInfo = &fClipInfoStorage; // ctor handles init of fClipInf
oStorage | 192 fClipInfo = &fClipInfoStorage; // ctor handles init of fClipInf
oStorage |
| 193 | 193 |
| 194 // The identity/wide-open-clip state is current by default | 194 // The identity/wide-open-clip state is current by default |
| 195 fMCStateID = kIdentityWideOpenStateID; | 195 fMCStateID = kIdentityWideOpenStateID; |
| 196 #ifdef SK_DEBUG |
| 197 fExpectedDepth = 1; |
| 198 #endif |
| 196 } | 199 } |
| 197 else { | 200 else { |
| 198 fLayerID = prev->fLayerID; | 201 fLayerID = prev->fLayerID; |
| 199 | 202 |
| 200 if (flags & SkCanvas::kMatrix_SaveFlag) { | 203 if (flags & SkCanvas::kMatrix_SaveFlag) { |
| 201 fMatrixInfoStorage = *prev->fMatrixInfo; | 204 fMatrixInfoStorage = *prev->fMatrixInfo; |
| 202 fMatrixInfo = &fMatrixInfoStorage; | 205 fMatrixInfo = &fMatrixInfoStorage; |
| 203 } else { | 206 } else { |
| 204 fMatrixInfo = prev->fMatrixInfo; | 207 fMatrixInfo = prev->fMatrixInfo; |
| 205 } | 208 } |
| 206 | 209 |
| 207 if (flags & SkCanvas::kClip_SaveFlag) { | 210 if (flags & SkCanvas::kClip_SaveFlag) { |
| 208 // We don't copy the ClipOps of the previous clip states | 211 // We don't copy the ClipOps of the previous clip states |
| 209 fClipInfo = &fClipInfoStorage; | 212 fClipInfo = &fClipInfoStorage; |
| 210 } else { | 213 } else { |
| 211 fClipInfo = prev->fClipInfo; | 214 fClipInfo = prev->fClipInfo; |
| 212 } | 215 } |
| 213 | 216 |
| 214 // Initially a new save/saveLayer represents the same MC state | 217 // Initially a new save/saveLayer represents the same MC state |
| 215 // as its predecessor. | 218 // as its predecessor. |
| 216 fMCStateID = prev->fMCStateID; | 219 fMCStateID = prev->fMCStateID; |
| 220 #ifdef SK_DEBUG |
| 221 fExpectedDepth = prev->fExpectedDepth; |
| 222 #endif |
| 217 } | 223 } |
| 218 | 224 |
| 219 fIsSaveLayer = false; | 225 fIsSaveLayer = false; |
| 220 } | 226 } |
| 221 | 227 |
| 222 MatrixInfo* fMatrixInfo; | 228 MatrixInfo* fMatrixInfo; |
| 223 MatrixInfo fMatrixInfoStorage; | 229 MatrixInfo fMatrixInfoStorage; |
| 224 | 230 |
| 225 ClipInfo* fClipInfo; | 231 ClipInfo* fClipInfo; |
| 226 ClipInfo fClipInfoStorage; | 232 ClipInfo fClipInfoStorage; |
| 227 | 233 |
| 228 // Tracks the current depth of saveLayers to support the isDrawingToLaye
r call | 234 // Tracks the current depth of saveLayers to support the isDrawingToLaye
r call |
| 229 int fLayerID; | 235 int fLayerID; |
| 230 // Does this MC state represent a saveLayer call? | 236 // Does this MC state represent a saveLayer call? |
| 231 bool fIsSaveLayer; | 237 bool fIsSaveLayer; |
| 232 | 238 |
| 233 // The next two fields are only valid when fIsSaveLayer is set. | 239 // The next two fields are only valid when fIsSaveLayer is set. |
| 234 int32_t fSaveLayerBaseStateID; | 240 int32_t fSaveLayerBaseStateID; |
| 235 SkTDArray<int>* fSavedSkipOffsets; | 241 SkTDArray<int>* fSavedSkipOffsets; |
| 236 | 242 |
| 243 // Does the MC state have an open block in the skp? |
| 244 bool fHasOpen; |
| 245 |
| 246 MatrixClipState* fPrev; |
| 247 |
| 237 #ifdef SK_DEBUG | 248 #ifdef SK_DEBUG |
| 238 MatrixClipState* fPrev; // debugging aid | 249 int fExpectedDepth; // debugging aid |
| 239 #endif | 250 #endif |
| 240 | 251 |
| 241 int32_t fMCStateID; | 252 int32_t fMCStateID; |
| 242 }; | 253 }; |
| 243 | 254 |
| 244 enum CallType { | 255 enum CallType { |
| 245 kMatrix_CallType, | 256 kMatrix_CallType, |
| 246 kClip_CallType, | 257 kClip_CallType, |
| 247 kOther_CallType | 258 kOther_CallType |
| 248 }; | 259 }; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // can cause MC states to be nested. | 369 // can cause MC states to be nested. |
| 359 SkTDArray<int32_t> *fSkipOffsets; | 370 SkTDArray<int32_t> *fSkipOffsets; |
| 360 | 371 |
| 361 SkDEBUGCODE(void validate();) | 372 SkDEBUGCODE(void validate();) |
| 362 | 373 |
| 363 int MCStackPush(SkCanvas::SaveFlags flags); | 374 int MCStackPush(SkCanvas::SaveFlags flags); |
| 364 | 375 |
| 365 void addClipOffset(int offset) { | 376 void addClipOffset(int offset) { |
| 366 SkASSERT(NULL != fSkipOffsets); | 377 SkASSERT(NULL != fSkipOffsets); |
| 367 SkASSERT(kIdentityWideOpenStateID != fCurOpenStateID); | 378 SkASSERT(kIdentityWideOpenStateID != fCurOpenStateID); |
| 379 SkASSERT(fCurMCState->fHasOpen); |
| 380 SkASSERT(!fCurMCState->fIsSaveLayer); |
| 368 | 381 |
| 369 *fSkipOffsets->append() = offset; | 382 *fSkipOffsets->append() = offset; |
| 370 } | 383 } |
| 371 | 384 |
| 372 void writeDeltaMat(int currentMatID, int desiredMatID); | 385 void writeDeltaMat(int currentMatID, int desiredMatID); |
| 373 static int32_t NewMCStateID(); | 386 static int32_t NewMCStateID(); |
| 374 | 387 |
| 375 int addRegionToDict(const SkRegion& region); | 388 int addRegionToDict(const SkRegion& region); |
| 376 const SkRegion* lookupRegion(int index) { | 389 const SkRegion* lookupRegion(int index) { |
| 377 SkASSERT(index >= 0 && index < fRegionDict.count()); | 390 SkASSERT(index >= 0 && index < fRegionDict.count()); |
| 378 return fRegionDict[index]; | 391 return fRegionDict[index]; |
| 379 } | 392 } |
| 380 | 393 |
| 381 // TODO: add stats to check if the dictionary really does | 394 // TODO: add stats to check if the dictionary really does |
| 382 // reduce the size of the SkPicture. | 395 // reduce the size of the SkPicture. |
| 383 int addMatToDict(const SkMatrix& mat); | 396 int addMatToDict(const SkMatrix& mat); |
| 384 const SkMatrix& lookupMat(int index) { | 397 const SkMatrix& lookupMat(int index) { |
| 385 SkASSERT(index >= 0 && index < fMatrixDict.count()); | 398 SkASSERT(index >= 0 && index < fMatrixDict.count()); |
| 386 return fMatrixDict[index]; | 399 return fMatrixDict[index]; |
| 387 } | 400 } |
| 401 |
| 402 bool isCurrentlyOpen(int32_t stateID); |
| 403 |
| 404 #ifdef SK_DEBUG |
| 405 int fActualDepth; |
| 406 #endif |
| 388 }; | 407 }; |
| 389 | 408 |
| 390 #endif | 409 #endif |
| OLD | NEW |