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) { |
robertphillips
2014/06/23 14:33:39
Can we get rid of the fMatrix/fMatrixStorage and f
f(malita)
2014/06/23 14:39:12
Yes, the plan is to follow up with a deferred save
| |
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 do { | 767 do { |
777 layer->updateMC(totalMatrix, clip, fClipStack, &clip); | 768 layer->updateMC(totalMatrix, clip, fClipStack, &clip); |
778 } while ((layer = layer->fNext) != NULL); | 769 } while ((layer = layer->fNext) != NULL); |
779 } | 770 } |
780 fDeviceCMDirty = false; | 771 fDeviceCMDirty = false; |
781 } | 772 } |
782 } | 773 } |
783 | 774 |
784 /////////////////////////////////////////////////////////////////////////////// | 775 /////////////////////////////////////////////////////////////////////////////// |
785 | 776 |
786 int SkCanvas::internalSave(SaveFlags flags) { | 777 int SkCanvas::internalSave() { |
787 int saveCount = this->getSaveCount(); // record this before the actual save | 778 int saveCount = this->getSaveCount(); // record this before the actual save |
788 | 779 |
789 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 780 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
790 new (newTop) MCRec(fMCRec, flags); // balanced in restore() | 781 new (newTop) MCRec(fMCRec); // balanced in restore() |
791 | |
792 fMCRec = newTop; | 782 fMCRec = newTop; |
793 | 783 |
794 if (SkCanvas::kClip_SaveFlag & flags) { | 784 fClipStack.save(); |
795 fClipStack.save(); | |
796 } | |
797 | 785 |
798 return saveCount; | 786 return saveCount; |
799 } | 787 } |
800 | 788 |
801 int SkCanvas::save() { | 789 int SkCanvas::save() { |
802 this->willSave(kMatrixClip_SaveFlag); | 790 this->willSave(); |
803 return this->internalSave(kMatrixClip_SaveFlag); | 791 return this->internalSave(); |
804 } | |
805 | |
806 int SkCanvas::save(SaveFlags flags) { | |
807 this->willSave(flags); | |
808 // call shared impl | |
809 return this->internalSave(flags); | |
810 } | 792 } |
811 | 793 |
812 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 794 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
813 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 795 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
814 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 796 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
815 #else | 797 #else |
816 return true; | 798 return true; |
817 #endif | 799 #endif |
818 } | 800 } |
819 | 801 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 } | 861 } |
880 | 862 |
881 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save Flags flags, | 863 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save Flags flags, |
882 bool justForImageFilter, SaveLayerStrategy strat egy) { | 864 bool justForImageFilter, SaveLayerStrategy strat egy) { |
883 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 865 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
884 flags |= kClipToLayer_SaveFlag; | 866 flags |= kClipToLayer_SaveFlag; |
885 #endif | 867 #endif |
886 | 868 |
887 // do this before we create the layer. We don't call the public save() since | 869 // do this before we create the layer. We don't call the public save() since |
888 // that would invoke a possibly overridden virtual | 870 // that would invoke a possibly overridden virtual |
889 int count = this->internalSave(flags); | 871 int count = this->internalSave(); |
890 | 872 |
891 fDeviceCMDirty = true; | 873 fDeviceCMDirty = true; |
892 | 874 |
893 SkIRect ir; | 875 SkIRect ir; |
894 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { | 876 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { |
895 return count; | 877 return count; |
896 } | 878 } |
897 | 879 |
898 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about | 880 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about |
899 // the clipRectBounds() call above? | 881 // the clipRectBounds() call above? |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 this->internalRestore(); | 946 this->internalRestore(); |
965 } | 947 } |
966 } | 948 } |
967 | 949 |
968 void SkCanvas::internalRestore() { | 950 void SkCanvas::internalRestore() { |
969 SkASSERT(fMCStack.count() != 0); | 951 SkASSERT(fMCStack.count() != 0); |
970 | 952 |
971 fDeviceCMDirty = true; | 953 fDeviceCMDirty = true; |
972 fCachedLocalClipBoundsDirty = true; | 954 fCachedLocalClipBoundsDirty = true; |
973 | 955 |
974 if (SkCanvas::kClip_SaveFlag & fMCRec->fFlags) { | 956 fClipStack.restore(); |
975 fClipStack.restore(); | |
976 } | |
977 | 957 |
978 // reserve our layer (if any) | 958 // reserve our layer (if any) |
979 DeviceCM* layer = fMCRec->fLayer; // may be null | 959 DeviceCM* layer = fMCRec->fLayer; // may be null |
980 // now detach it from fMCRec so we can pop(). Gets freed after its drawn | 960 // now detach it from fMCRec so we can pop(). Gets freed after its drawn |
981 fMCRec->fLayer = NULL; | 961 fMCRec->fLayer = NULL; |
982 | 962 |
983 // now do the normal restore() | 963 // now do the normal restore() |
984 fMCRec->~MCRec(); // balanced in save() | 964 fMCRec->~MCRec(); // balanced in save() |
985 fMCStack.pop_back(); | 965 fMCStack.pop_back(); |
986 fMCRec = (MCRec*)fMCStack.back(); | 966 fMCRec = (MCRec*)fMCStack.back(); |
(...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2588 if (!supported_for_raster_canvas(info)) { | 2568 if (!supported_for_raster_canvas(info)) { |
2589 return NULL; | 2569 return NULL; |
2590 } | 2570 } |
2591 | 2571 |
2592 SkBitmap bitmap; | 2572 SkBitmap bitmap; |
2593 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2573 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
2594 return NULL; | 2574 return NULL; |
2595 } | 2575 } |
2596 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2576 return SkNEW_ARGS(SkCanvas, (bitmap)); |
2597 } | 2577 } |
OLD | NEW |