Chromium Code Reviews| 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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 these are used (assuming we're not on a layer) we rebuild these cache | 106 these are used (assuming we're not on a layer) we rebuild these cache |
| 107 values: they reflect the top of the save stack, but translated and clipped | 107 values: they reflect the top of the save stack, but translated and clipped |
| 108 by the device's XY offset and bitmap-bounds. | 108 by the device's XY offset and bitmap-bounds. |
| 109 */ | 109 */ |
| 110 struct DeviceCM { | 110 struct DeviceCM { |
| 111 DeviceCM* fNext; | 111 DeviceCM* fNext; |
| 112 SkBaseDevice* fDevice; | 112 SkBaseDevice* fDevice; |
| 113 SkRasterClip fClip; | 113 SkRasterClip fClip; |
| 114 const SkMatrix* fMatrix; | 114 const SkMatrix* fMatrix; |
| 115 SkPaint* fPaint; // may be null (in the future) | 115 SkPaint* fPaint; // may be null (in the future) |
| 116 SkMatrix fStashedMatrix; // Original CTM; used by imageFilter at saveLayer time | |
| 116 | 117 |
| 117 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, | 118 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, |
| 118 bool conservativeRasterClip) | 119 bool conservativeRasterClip, const SkMatrix& stashedMatrix) |
| 119 : fNext(NULL) | 120 : fNext(NULL) |
| 120 , fClip(conservativeRasterClip) | 121 , fClip(conservativeRasterClip) |
| 122 , fStashedMatrix(stashedMatrix) | |
| 121 { | 123 { |
| 122 if (NULL != device) { | 124 if (NULL != device) { |
| 123 device->ref(); | 125 device->ref(); |
| 124 device->onAttachToCanvas(canvas); | 126 device->onAttachToCanvas(canvas); |
| 125 } | 127 } |
| 126 fDevice = device; | 128 fDevice = device; |
| 127 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; | 129 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; |
| 128 } | 130 } |
| 129 | 131 |
| 130 ~DeviceCM() { | 132 ~DeviceCM() { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 fCachedLocalClipBoundsDirty = true; | 433 fCachedLocalClipBoundsDirty = true; |
| 432 fAllowSoftClip = true; | 434 fAllowSoftClip = true; |
| 433 fAllowSimplifyClip = false; | 435 fAllowSimplifyClip = false; |
| 434 fDeviceCMDirty = true; | 436 fDeviceCMDirty = true; |
| 435 fSaveCount = 1; | 437 fSaveCount = 1; |
| 436 fMetaData = NULL; | 438 fMetaData = NULL; |
| 437 | 439 |
| 438 fMCRec = (MCRec*)fMCStack.push_back(); | 440 fMCRec = (MCRec*)fMCStack.push_back(); |
| 439 new (fMCRec) MCRec(fConservativeRasterClip); | 441 new (fMCRec) MCRec(fConservativeRasterClip); |
| 440 | 442 |
| 441 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, NULL, NULL, fConservativeRaster Clip)); | 443 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, NULL, NULL, fConservativeRaster Clip, |
| 444 fMCRec->fMatrix)); | |
| 442 fMCRec->fTopLayer = fMCRec->fLayer; | 445 fMCRec->fTopLayer = fMCRec->fLayer; |
| 443 | 446 |
| 444 fSurfaceBase = NULL; | 447 fSurfaceBase = NULL; |
| 445 | 448 |
| 446 fClipStack.reset(SkNEW(SkClipStack)); | 449 fClipStack.reset(SkNEW(SkClipStack)); |
| 447 | 450 |
| 448 if (device) { | 451 if (device) { |
| 449 device->initForRootLayer(fProps.pixelGeometry()); | 452 device->initForRootLayer(fProps.pixelGeometry()); |
| 450 if (device->forceConservativeRasterClip()) { | 453 if (device->forceConservativeRasterClip()) { |
| 451 fConservativeRasterClip = true; | 454 fConservativeRasterClip = true; |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 fSaveCount += 1; | 895 fSaveCount += 1; |
| 893 this->internalSaveLayer(bounds, paint, flags, strategy); | 896 this->internalSaveLayer(bounds, paint, flags, strategy); |
| 894 return this->getSaveCount() - 1; | 897 return this->getSaveCount() - 1; |
| 895 } | 898 } |
| 896 | 899 |
| 897 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, | 900 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, |
| 898 SaveLayerStrategy strategy) { | 901 SaveLayerStrategy strategy) { |
| 899 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 902 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 900 flags |= kClipToLayer_SaveFlag; | 903 flags |= kClipToLayer_SaveFlag; |
| 901 #endif | 904 #endif |
| 905 SkLazyPaint lazyP; | |
| 906 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; | |
| 907 SkMatrix matrix = fMCRec->fMatrix; | |
| 908 SkMatrix remainder; | |
| 909 SkSize scale; | |
| 910 if (imageFilter && !matrix.isScaleTranslate() && matrix.decomposeScale(&scal e, &remainder)) { | |
| 911 this->resetMatrix(); | |
|
reed1
2015/03/26 15:54:03
these two calls for matrix changes are virtual, wh
Stephen White
2015/03/26 16:18:34
Hmm -- they don't seem to be virtual on SkCanvas?
| |
| 912 this->scale(scale.width(), scale.height()); | |
| 913 SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilt er(remainder, SkFilterQuality::kHigh_SkFilterQuality, imageFilter)); | |
|
reed1
2015/03/26 15:54:03
kLow might be more honest, since by definition rem
Stephen White
2015/03/26 16:18:34
Done.
| |
| 914 imageFilter = matrixFilter.get(); | |
| 915 SkPaint* p = lazyP.set(*paint); | |
| 916 p->setImageFilter(imageFilter); | |
| 917 paint = p; | |
| 918 } | |
| 902 | 919 |
| 903 // do this before we create the layer. We don't call the public save() since | 920 // do this before we create the layer. We don't call the public save() since |
| 904 // that would invoke a possibly overridden virtual | 921 // that would invoke a possibly overridden virtual |
| 905 this->internalSave(); | 922 this->internalSave(); |
| 906 | 923 |
| 907 fDeviceCMDirty = true; | 924 fDeviceCMDirty = true; |
| 908 | 925 |
| 909 SkIRect ir; | 926 SkIRect ir; |
| 910 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { | 927 if (!this->clipRectBounds(bounds, flags, &ir, imageFilter)) { |
| 911 return; | 928 return; |
| 912 } | 929 } |
| 913 | 930 |
| 914 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about | 931 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about |
| 915 // the clipRectBounds() call above? | 932 // the clipRectBounds() call above? |
| 916 if (kNoLayer_SaveLayerStrategy == strategy) { | 933 if (kNoLayer_SaveLayerStrategy == strategy) { |
| 917 return; | 934 return; |
| 918 } | 935 } |
| 919 | 936 |
| 920 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 937 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 945 } | 962 } |
| 946 #endif | 963 #endif |
| 947 device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, geo), paint); | 964 device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, geo), paint); |
| 948 if (NULL == device) { | 965 if (NULL == device) { |
| 949 SkErrorInternals::SetError( kInternalError_SkError, | 966 SkErrorInternals::SetError( kInternalError_SkError, |
| 950 "Unable to create device for layer."); | 967 "Unable to create device for layer."); |
| 951 return; | 968 return; |
| 952 } | 969 } |
| 953 | 970 |
| 954 device->setOrigin(ir.fLeft, ir.fTop); | 971 device->setOrigin(ir.fLeft, ir.fTop); |
| 955 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip)); | 972 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip, matrix)); |
| 956 device->unref(); | 973 device->unref(); |
| 957 | 974 |
| 958 layer->fNext = fMCRec->fTopLayer; | 975 layer->fNext = fMCRec->fTopLayer; |
| 959 fMCRec->fLayer = layer; | 976 fMCRec->fLayer = layer; |
| 960 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 977 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
| 961 } | 978 } |
| 962 | 979 |
| 963 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 980 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
| 964 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); | 981 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); |
| 965 } | 982 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 recorder will have already recorded the restore). | 1015 recorder will have already recorded the restore). |
| 999 */ | 1016 */ |
| 1000 if (layer) { | 1017 if (layer) { |
| 1001 if (layer->fNext) { | 1018 if (layer->fNext) { |
| 1002 const SkIPoint& origin = layer->fDevice->getOrigin(); | 1019 const SkIPoint& origin = layer->fDevice->getOrigin(); |
| 1003 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), | 1020 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), |
| 1004 layer->fPaint); | 1021 layer->fPaint); |
| 1005 // reset this, since internalDrawDevice will have set it to true | 1022 // reset this, since internalDrawDevice will have set it to true |
| 1006 fDeviceCMDirty = true; | 1023 fDeviceCMDirty = true; |
| 1007 } | 1024 } |
| 1025 if (layer->fPaint && layer->fPaint->fImageFilter) { | |
|
reed1
2015/03/26 15:54:03
the check seems a little fragile, since it somehow
Stephen White
2015/03/26 16:18:34
Done.
| |
| 1026 fMCRec->fMatrix = layer->fStashedMatrix; | |
| 1027 } | |
| 1008 SkDELETE(layer); | 1028 SkDELETE(layer); |
| 1009 } | 1029 } |
| 1010 } | 1030 } |
| 1011 | 1031 |
| 1012 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 1032 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
| 1013 if (NULL == props) { | 1033 if (NULL == props) { |
| 1014 props = &fProps; | 1034 props = &fProps; |
| 1015 } | 1035 } |
| 1016 return this->onNewSurface(info, *props); | 1036 return this->onNewSurface(info, *props); |
| 1017 } | 1037 } |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2520 } | 2540 } |
| 2521 | 2541 |
| 2522 if (matrix) { | 2542 if (matrix) { |
| 2523 canvas->concat(*matrix); | 2543 canvas->concat(*matrix); |
| 2524 } | 2544 } |
| 2525 } | 2545 } |
| 2526 | 2546 |
| 2527 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2547 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2528 fCanvas->restoreToCount(fSaveCount); | 2548 fCanvas->restoreToCount(fSaveCount); |
| 2529 } | 2549 } |
| OLD | NEW |