Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/core/SkCanvas.cpp

Issue 1128133005: Revert of Implement support for non-scale/translate CTM in image filters. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 values: they reflect the top of the save stack, but translated and clipped 108 values: they reflect the top of the save stack, but translated and clipped
109 by the device's XY offset and bitmap-bounds. 109 by the device's XY offset and bitmap-bounds.
110 */ 110 */
111 struct DeviceCM { 111 struct DeviceCM {
112 DeviceCM* fNext; 112 DeviceCM* fNext;
113 SkBaseDevice* fDevice; 113 SkBaseDevice* fDevice;
114 SkRasterClip fClip; 114 SkRasterClip fClip;
115 SkPaint* fPaint; // may be null (in the future) 115 SkPaint* fPaint; // may be null (in the future)
116 const SkMatrix* fMatrix; 116 const SkMatrix* fMatrix;
117 SkMatrix fMatrixStorage; 117 SkMatrix fMatrixStorage;
118 SkMatrix fStashedMatrix; // Original CTM; used by imageFilter at saveLayer time
119 const bool fDeviceIsBitmapDevice; 118 const bool fDeviceIsBitmapDevice;
120 119
121 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, 120 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
122 bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMat rix& stashed) 121 bool conservativeRasterClip, bool deviceIsBitmapDevice)
123 : fNext(NULL) 122 : fNext(NULL)
124 , fClip(conservativeRasterClip) 123 , fClip(conservativeRasterClip)
125 , fStashedMatrix(stashed)
126 , fDeviceIsBitmapDevice(deviceIsBitmapDevice) 124 , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
127 { 125 {
128 if (NULL != device) { 126 if (NULL != device) {
129 device->ref(); 127 device->ref();
130 device->onAttachToCanvas(canvas); 128 device->onAttachToCanvas(canvas);
131 } 129 }
132 fDevice = device; 130 fDevice = device;
133 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; 131 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL;
134 } 132 }
135 133
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 fSaveCount = 1; 521 fSaveCount = 1;
524 fMetaData = NULL; 522 fMetaData = NULL;
525 523
526 fClipStack.reset(SkNEW(SkClipStack)); 524 fClipStack.reset(SkNEW(SkClipStack));
527 525
528 fMCRec = (MCRec*)fMCStack.push_back(); 526 fMCRec = (MCRec*)fMCStack.push_back();
529 new (fMCRec) MCRec(fConservativeRasterClip); 527 new (fMCRec) MCRec(fConservativeRasterClip);
530 528
531 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 529 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
532 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 530 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
533 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse, 531 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse);
534 fMCRec->fMatrix);
535 532
536 fMCRec->fTopLayer = fMCRec->fLayer; 533 fMCRec->fTopLayer = fMCRec->fLayer;
537 534
538 fSurfaceBase = NULL; 535 fSurfaceBase = NULL;
539 536
540 if (device) { 537 if (device) {
541 device->initForRootLayer(fProps.pixelGeometry()); 538 device->initForRootLayer(fProps.pixelGeometry());
542 if (device->forceConservativeRasterClip()) { 539 if (device->forceConservativeRasterClip()) {
543 fConservativeRasterClip = true; 540 fConservativeRasterClip = true;
544 } 541 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 fSaveCount += 1; 984 fSaveCount += 1;
988 this->internalSaveLayer(bounds, paint, flags, strategy); 985 this->internalSaveLayer(bounds, paint, flags, strategy);
989 return this->getSaveCount() - 1; 986 return this->getSaveCount() - 1;
990 } 987 }
991 988
992 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, 989 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags,
993 SaveLayerStrategy strategy) { 990 SaveLayerStrategy strategy) {
994 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 991 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
995 flags |= kClipToLayer_SaveFlag; 992 flags |= kClipToLayer_SaveFlag;
996 #endif 993 #endif
997 SkLazyPaint lazyP;
998 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL;
999 SkMatrix stashedMatrix = fMCRec->fMatrix;
1000 SkMatrix remainder;
1001 SkSize scale;
1002 if (imageFilter &&
1003 !stashedMatrix.isScaleTranslate() && stashedMatrix.decomposeScale(&scale , &remainder)) {
1004 // We will restore the matrix (which we are overwriting here) in restore via fStashedMatrix
1005 this->internalSetMatrix(SkMatrix::MakeScale(scale.width(), scale.height( )));
1006 SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilt er(
1007 remainder, SkFilterQuality::kLow_SkFilterQua lity, imageFilter));
1008 imageFilter = matrixFilter.get();
1009 SkPaint* p = lazyP.set(*paint);
1010 p->setImageFilter(imageFilter);
1011 paint = p;
1012 }
1013 994
1014 // do this before we create the layer. We don't call the public save() since 995 // do this before we create the layer. We don't call the public save() since
1015 // that would invoke a possibly overridden virtual 996 // that would invoke a possibly overridden virtual
1016 this->internalSave(); 997 this->internalSave();
1017 998
1018 fDeviceCMDirty = true; 999 fDeviceCMDirty = true;
1019 1000
1020 SkIRect ir; 1001 SkIRect ir;
1021 if (!this->clipRectBounds(bounds, flags, &ir, imageFilter)) { 1002 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) {
1022 return; 1003 return;
1023 } 1004 }
1024 1005
1025 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about 1006 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
1026 // the clipRectBounds() call above? 1007 // the clipRectBounds() call above?
1027 if (kNoLayer_SaveLayerStrategy == strategy) { 1008 if (kNoLayer_SaveLayerStrategy == strategy) {
1028 return; 1009 return;
1029 } 1010 }
1030 1011
1031 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); 1012 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
(...skipping 27 matching lines...) Expand all
1059 "Unable to create device for layer.") ; 1040 "Unable to create device for layer.") ;
1060 return; 1041 return;
1061 } 1042 }
1062 forceSpriteOnRestore = true; 1043 forceSpriteOnRestore = true;
1063 } 1044 }
1064 device = newDev; 1045 device = newDev;
1065 } 1046 }
1066 1047
1067 device->setOrigin(ir.fLeft, ir.fTop); 1048 device->setOrigin(ir.fLeft, ir.fTop);
1068 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip, 1049 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip,
1069 forceSpriteOnRestore, stashedMatrix) ); 1050 forceSpriteOnRestore));
1070 device->unref(); 1051 device->unref();
1071 1052
1072 layer->fNext = fMCRec->fTopLayer; 1053 layer->fNext = fMCRec->fTopLayer;
1073 fMCRec->fLayer = layer; 1054 fMCRec->fLayer = layer;
1074 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1055 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1075 } 1056 }
1076 1057
1077 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1058 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
1078 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); 1059 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag);
1079 } 1060 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), 1098 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
1118 layer->fPaint, layer->fDeviceIsBitmapDevice ); 1099 layer->fPaint, layer->fDeviceIsBitmapDevice );
1119 // reset this, since internalDrawDevice will have set it to true 1100 // reset this, since internalDrawDevice will have set it to true
1120 fDeviceCMDirty = true; 1101 fDeviceCMDirty = true;
1121 SkDELETE(layer); 1102 SkDELETE(layer);
1122 } else { 1103 } else {
1123 // we're at the root 1104 // we're at the root
1124 SkASSERT(layer == (void*)fDeviceCMStorage); 1105 SkASSERT(layer == (void*)fDeviceCMStorage);
1125 layer->~DeviceCM(); 1106 layer->~DeviceCM();
1126 } 1107 }
1127 if (fMCRec) {
1128 // restore what we smashed in internalSaveLayer
1129 fMCRec->fMatrix = layer->fStashedMatrix;
1130 }
1131 } 1108 }
1132 } 1109 }
1133 1110
1134 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 1111 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
1135 if (NULL == props) { 1112 if (NULL == props) {
1136 props = &fProps; 1113 props = &fProps;
1137 } 1114 }
1138 return this->onNewSurface(info, *props); 1115 return this->onNewSurface(info, *props);
1139 } 1116 }
1140 1117
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 } 1325 }
1349 1326
1350 this->checkForDeferredSave(); 1327 this->checkForDeferredSave();
1351 fDeviceCMDirty = true; 1328 fDeviceCMDirty = true;
1352 fCachedLocalClipBoundsDirty = true; 1329 fCachedLocalClipBoundsDirty = true;
1353 fMCRec->fMatrix.preConcat(matrix); 1330 fMCRec->fMatrix.preConcat(matrix);
1354 1331
1355 this->didConcat(matrix); 1332 this->didConcat(matrix);
1356 } 1333 }
1357 1334
1358 void SkCanvas::internalSetMatrix(const SkMatrix& matrix) {
1359 fDeviceCMDirty = true;
1360 fCachedLocalClipBoundsDirty = true;
1361 fMCRec->fMatrix = matrix;
1362 }
1363
1364 void SkCanvas::setMatrix(const SkMatrix& matrix) { 1335 void SkCanvas::setMatrix(const SkMatrix& matrix) {
1365 this->checkForDeferredSave(); 1336 this->checkForDeferredSave();
1366 this->internalSetMatrix(matrix); 1337 fDeviceCMDirty = true;
1338 fCachedLocalClipBoundsDirty = true;
1339 fMCRec->fMatrix = matrix;
1367 this->didSetMatrix(matrix); 1340 this->didSetMatrix(matrix);
1368 } 1341 }
1369 1342
1370 void SkCanvas::resetMatrix() { 1343 void SkCanvas::resetMatrix() {
1371 SkMatrix matrix; 1344 SkMatrix matrix;
1372 1345
1373 matrix.reset(); 1346 matrix.reset();
1374 this->setMatrix(matrix); 1347 this->setMatrix(matrix);
1375 } 1348 }
1376 1349
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 } 2687 }
2715 2688
2716 if (matrix) { 2689 if (matrix) {
2717 canvas->concat(*matrix); 2690 canvas->concat(*matrix);
2718 } 2691 }
2719 } 2692 }
2720 2693
2721 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2694 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2722 fCanvas->restoreToCount(fSaveCount); 2695 fCanvas->restoreToCount(fSaveCount);
2723 } 2696 }
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698