| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 | 8 |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 /* This is the record we keep for each save/restore level in the stack. | 183 /* This is the record we keep for each save/restore level in the stack. |
| 184 Since a level optionally copies the matrix and/or stack, we have pointers | 184 Since a level optionally copies the matrix and/or stack, we have pointers |
| 185 for these fields. If the value is copied for this level, the copy is | 185 for these fields. If the value is copied for this level, the copy is |
| 186 stored in the ...Storage field, and the pointer points to that. If the | 186 stored in the ...Storage field, and the pointer points to that. If the |
| 187 value is not copied for this level, we ignore ...Storage, and just point | 187 value is not copied for this level, we ignore ...Storage, and just point |
| 188 at the corresponding value in the previous level in the stack. | 188 at the corresponding value in the previous level in the stack. |
| 189 */ | 189 */ |
| 190 class SkCanvas::MCRec { | 190 class SkCanvas::MCRec { |
| 191 public: | 191 public: |
| 192 int fFlags; | |
| 193 SkMatrix* fMatrix; // points to either fMatrixStorage or prev M
CRec | 192 SkMatrix* fMatrix; // points to either fMatrixStorage or prev M
CRec |
| 194 SkRasterClip* fRasterClip; // points to either fRegionStorage or prev M
CRec | 193 SkRasterClip* fRasterClip; // points to either fRegionStorage or prev M
CRec |
| 195 SkDrawFilter* fFilter; // the current filter (or null) | 194 SkDrawFilter* fFilter; // the current filter (or null) |
| 196 | 195 |
| 197 DeviceCM* fLayer; | 196 DeviceCM* fLayer; |
| 198 /* If there are any layers in the stack, this points to the top-most | 197 /* If there are any layers in the stack, this points to the top-most |
| 199 one that is at or below this level in the stack (so we know what | 198 one that is at or below this level in the stack (so we know what |
| 200 bitmap/device to draw into from this level. This value is NOT | 199 bitmap/device to draw into from this level. This value is NOT |
| 201 reference counted, since the real owner is either our fLayer field, | 200 reference counted, since the real owner is either our fLayer field, |
| 202 or a previous one in a lower level.) | 201 or a previous one in a lower level.) |
| 203 */ | 202 */ |
| 204 DeviceCM* fTopLayer; | 203 DeviceCM* fTopLayer; |
| 205 | 204 |
| 206 MCRec(const MCRec* prev, int flags) : fFlags(flags) { | 205 MCRec(const MCRec* prev) { |
| 207 if (NULL != prev) { | 206 if (NULL != prev) { |
| 208 if (flags & SkCanvas::kMatrix_SaveFlag) { | 207 fMatrixStorage = *prev->fMatrix; |
| 209 fMatrixStorage = *prev->fMatrix; | 208 fMatrix = &fMatrixStorage; |
| 210 fMatrix = &fMatrixStorage; | |
| 211 } else { | |
| 212 fMatrix = prev->fMatrix; | |
| 213 } | |
| 214 | 209 |
| 215 if (flags & SkCanvas::kClip_SaveFlag) { | 210 fRasterClipStorage = *prev->fRasterClip; |
| 216 fRasterClipStorage = *prev->fRasterClip; | 211 fRasterClip = &fRasterClipStorage; |
| 217 fRasterClip = &fRasterClipStorage; | |
| 218 } else { | |
| 219 fRasterClip = prev->fRasterClip; | |
| 220 } | |
| 221 | 212 |
| 222 fFilter = prev->fFilter; | 213 fFilter = prev->fFilter; |
| 223 SkSafeRef(fFilter); | 214 SkSafeRef(fFilter); |
| 224 | 215 |
| 225 fTopLayer = prev->fTopLayer; | 216 fTopLayer = prev->fTopLayer; |
| 226 } else { // no prev | 217 } else { // no prev |
| 227 fMatrixStorage.reset(); | 218 fMatrixStorage.reset(); |
| 228 | 219 |
| 229 fMatrix = &fMatrixStorage; | 220 fMatrix = &fMatrixStorage; |
| 230 fRasterClip = &fRasterClipStorage; | 221 fRasterClip = &fRasterClipStorage; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 fCachedLocalClipBounds.setEmpty(); | 433 fCachedLocalClipBounds.setEmpty(); |
| 443 fCachedLocalClipBoundsDirty = true; | 434 fCachedLocalClipBoundsDirty = true; |
| 444 fAllowSoftClip = true; | 435 fAllowSoftClip = true; |
| 445 fAllowSimplifyClip = false; | 436 fAllowSimplifyClip = false; |
| 446 fDeviceCMDirty = false; | 437 fDeviceCMDirty = false; |
| 447 fSaveLayerCount = 0; | 438 fSaveLayerCount = 0; |
| 448 fCullCount = 0; | 439 fCullCount = 0; |
| 449 fMetaData = NULL; | 440 fMetaData = NULL; |
| 450 | 441 |
| 451 fMCRec = (MCRec*)fMCStack.push_back(); | 442 fMCRec = (MCRec*)fMCStack.push_back(); |
| 452 new (fMCRec) MCRec(NULL, 0); | 443 new (fMCRec) MCRec(NULL); |
| 453 | 444 |
| 454 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL)); | 445 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL)); |
| 455 fMCRec->fTopLayer = fMCRec->fLayer; | 446 fMCRec->fTopLayer = fMCRec->fLayer; |
| 456 | 447 |
| 457 fSurfaceBase = NULL; | 448 fSurfaceBase = NULL; |
| 458 | 449 |
| 459 return this->setRootDevice(device); | 450 return this->setRootDevice(device); |
| 460 } | 451 } |
| 461 | 452 |
| 462 SkCanvas::SkCanvas() | 453 SkCanvas::SkCanvas() |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 do { | 770 do { |
| 780 layer->updateMC(totalMatrix, clip, fClipStack, &clip); | 771 layer->updateMC(totalMatrix, clip, fClipStack, &clip); |
| 781 } while ((layer = layer->fNext) != NULL); | 772 } while ((layer = layer->fNext) != NULL); |
| 782 } | 773 } |
| 783 fDeviceCMDirty = false; | 774 fDeviceCMDirty = false; |
| 784 } | 775 } |
| 785 } | 776 } |
| 786 | 777 |
| 787 /////////////////////////////////////////////////////////////////////////////// | 778 /////////////////////////////////////////////////////////////////////////////// |
| 788 | 779 |
| 789 int SkCanvas::internalSave(SaveFlags flags) { | 780 int SkCanvas::internalSave() { |
| 790 int saveCount = this->getSaveCount(); // record this before the actual save | 781 int saveCount = this->getSaveCount(); // record this before the actual save |
| 791 | 782 |
| 792 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 783 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
| 793 new (newTop) MCRec(fMCRec, flags); // balanced in restore() | 784 new (newTop) MCRec(fMCRec); // balanced in restore() |
| 794 | |
| 795 fMCRec = newTop; | 785 fMCRec = newTop; |
| 796 | 786 |
| 797 if (SkCanvas::kClip_SaveFlag & flags) { | 787 fClipStack.save(); |
| 798 fClipStack.save(); | |
| 799 } | |
| 800 | 788 |
| 801 return saveCount; | 789 return saveCount; |
| 802 } | 790 } |
| 803 | 791 |
| 804 int SkCanvas::save() { | 792 int SkCanvas::save() { |
| 805 this->willSave(kMatrixClip_SaveFlag); | 793 this->willSave(); |
| 806 return this->internalSave(kMatrixClip_SaveFlag); | 794 return this->internalSave(); |
| 807 } | |
| 808 | |
| 809 int SkCanvas::save(SaveFlags flags) { | |
| 810 this->willSave(flags); | |
| 811 // call shared impl | |
| 812 return this->internalSave(flags); | |
| 813 } | 795 } |
| 814 | 796 |
| 815 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 797 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
| 816 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 798 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 817 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 799 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
| 818 #else | 800 #else |
| 819 return true; | 801 return true; |
| 820 #endif | 802 #endif |
| 821 } | 803 } |
| 822 | 804 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 864 } |
| 883 | 865 |
| 884 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save
Flags flags, | 866 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save
Flags flags, |
| 885 bool justForImageFilter, SaveLayerStrategy strat
egy) { | 867 bool justForImageFilter, SaveLayerStrategy strat
egy) { |
| 886 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 868 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 887 flags |= kClipToLayer_SaveFlag; | 869 flags |= kClipToLayer_SaveFlag; |
| 888 #endif | 870 #endif |
| 889 | 871 |
| 890 // do this before we create the layer. We don't call the public save() since | 872 // do this before we create the layer. We don't call the public save() since |
| 891 // that would invoke a possibly overridden virtual | 873 // that would invoke a possibly overridden virtual |
| 892 int count = this->internalSave(flags); | 874 int count = this->internalSave(); |
| 893 | 875 |
| 894 fDeviceCMDirty = true; | 876 fDeviceCMDirty = true; |
| 895 | 877 |
| 896 SkIRect ir; | 878 SkIRect ir; |
| 897 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 879 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { |
| 898 return count; | 880 return count; |
| 899 } | 881 } |
| 900 | 882 |
| 901 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about | 883 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about |
| 902 // the clipRectBounds() call above? | 884 // the clipRectBounds() call above? |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 this->internalRestore(); | 949 this->internalRestore(); |
| 968 } | 950 } |
| 969 } | 951 } |
| 970 | 952 |
| 971 void SkCanvas::internalRestore() { | 953 void SkCanvas::internalRestore() { |
| 972 SkASSERT(fMCStack.count() != 0); | 954 SkASSERT(fMCStack.count() != 0); |
| 973 | 955 |
| 974 fDeviceCMDirty = true; | 956 fDeviceCMDirty = true; |
| 975 fCachedLocalClipBoundsDirty = true; | 957 fCachedLocalClipBoundsDirty = true; |
| 976 | 958 |
| 977 if (SkCanvas::kClip_SaveFlag & fMCRec->fFlags) { | 959 fClipStack.restore(); |
| 978 fClipStack.restore(); | |
| 979 } | |
| 980 | 960 |
| 981 // reserve our layer (if any) | 961 // reserve our layer (if any) |
| 982 DeviceCM* layer = fMCRec->fLayer; // may be null | 962 DeviceCM* layer = fMCRec->fLayer; // may be null |
| 983 // now detach it from fMCRec so we can pop(). Gets freed after its drawn | 963 // now detach it from fMCRec so we can pop(). Gets freed after its drawn |
| 984 fMCRec->fLayer = NULL; | 964 fMCRec->fLayer = NULL; |
| 985 | 965 |
| 986 // now do the normal restore() | 966 // now do the normal restore() |
| 987 fMCRec->~MCRec(); // balanced in save() | 967 fMCRec->~MCRec(); // balanced in save() |
| 988 fMCStack.pop_back(); | 968 fMCStack.pop_back(); |
| 989 fMCRec = (MCRec*)fMCStack.back(); | 969 fMCRec = (MCRec*)fMCStack.back(); |
| (...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2585 if (!supported_for_raster_canvas(info)) { | 2565 if (!supported_for_raster_canvas(info)) { |
| 2586 return NULL; | 2566 return NULL; |
| 2587 } | 2567 } |
| 2588 | 2568 |
| 2589 SkBitmap bitmap; | 2569 SkBitmap bitmap; |
| 2590 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2570 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
| 2591 return NULL; | 2571 return NULL; |
| 2592 } | 2572 } |
| 2593 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2573 return SkNEW_ARGS(SkCanvas, (bitmap)); |
| 2594 } | 2574 } |
| OLD | NEW |