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

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

Issue 1120043002: 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
118 const bool fDeviceIsBitmapDevice; 119 const bool fDeviceIsBitmapDevice;
119 120
120 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, 121 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
121 bool conservativeRasterClip, bool deviceIsBitmapDevice) 122 bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMat rix& stashed)
122 : fNext(NULL) 123 : fNext(NULL)
123 , fClip(conservativeRasterClip) 124 , fClip(conservativeRasterClip)
125 , fStashedMatrix(stashed)
124 , fDeviceIsBitmapDevice(deviceIsBitmapDevice) 126 , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
125 { 127 {
126 if (NULL != device) { 128 if (NULL != device) {
127 device->ref(); 129 device->ref();
128 device->onAttachToCanvas(canvas); 130 device->onAttachToCanvas(canvas);
129 } 131 }
130 fDevice = device; 132 fDevice = device;
131 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; 133 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL;
132 } 134 }
133 135
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 fSaveCount = 1; 527 fSaveCount = 1;
526 fMetaData = NULL; 528 fMetaData = NULL;
527 529
528 fClipStack.reset(SkNEW(SkClipStack)); 530 fClipStack.reset(SkNEW(SkClipStack));
529 531
530 fMCRec = (MCRec*)fMCStack.push_back(); 532 fMCRec = (MCRec*)fMCStack.push_back();
531 new (fMCRec) MCRec(fConservativeRasterClip); 533 new (fMCRec) MCRec(fConservativeRasterClip);
532 534
533 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 535 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
534 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 536 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
535 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse); 537 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse,
538 fMCRec->fMatrix);
536 539
537 fMCRec->fTopLayer = fMCRec->fLayer; 540 fMCRec->fTopLayer = fMCRec->fLayer;
538 541
539 fSurfaceBase = NULL; 542 fSurfaceBase = NULL;
540 543
541 if (device) { 544 if (device) {
542 device->initForRootLayer(fProps.pixelGeometry()); 545 device->initForRootLayer(fProps.pixelGeometry());
543 if (device->forceConservativeRasterClip()) { 546 if (device->forceConservativeRasterClip()) {
544 fConservativeRasterClip = true; 547 fConservativeRasterClip = true;
545 } 548 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 fSaveCount += 1; 991 fSaveCount += 1;
989 this->internalSaveLayer(bounds, paint, flags, strategy); 992 this->internalSaveLayer(bounds, paint, flags, strategy);
990 return this->getSaveCount() - 1; 993 return this->getSaveCount() - 1;
991 } 994 }
992 995
993 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, 996 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags,
994 SaveLayerStrategy strategy) { 997 SaveLayerStrategy strategy) {
995 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 998 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
996 flags |= kClipToLayer_SaveFlag; 999 flags |= kClipToLayer_SaveFlag;
997 #endif 1000 #endif
1001 SkLazyPaint lazyP;
1002 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL;
1003 SkMatrix matrix = fMCRec->fMatrix;
1004 SkMatrix remainder;
1005 SkSize scale;
1006 if (imageFilter && !matrix.isScaleTranslate() && matrix.decomposeScale(&scal e, &remainder)) {
1007 this->internalSetMatrix(SkMatrix::MakeScale(scale.width(), scale.height( )));
robertphillips 2015/05/04 14:12:38 \n somewhere ?
reed1 2015/05/13 19:53:15 Done.
1008 SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilt er(remainder, SkFilterQuality::kLow_SkFilterQuality, imageFilter));
1009 imageFilter = matrixFilter.get();
1010 SkPaint* p = lazyP.set(*paint);
1011 p->setImageFilter(imageFilter);
1012 paint = p;
1013 }
998 1014
999 // do this before we create the layer. We don't call the public save() since 1015 // do this before we create the layer. We don't call the public save() since
1000 // that would invoke a possibly overridden virtual 1016 // that would invoke a possibly overridden virtual
1001 this->internalSave(); 1017 this->internalSave();
1002 1018
1003 fDeviceCMDirty = true; 1019 fDeviceCMDirty = true;
1004 1020
1005 SkIRect ir; 1021 SkIRect ir;
1006 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 1022 if (!this->clipRectBounds(bounds, flags, &ir, imageFilter)) {
1007 return; 1023 return;
1008 } 1024 }
1009 1025
1010 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about 1026 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
1011 // the clipRectBounds() call above? 1027 // the clipRectBounds() call above?
1012 if (kNoLayer_SaveLayerStrategy == strategy) { 1028 if (kNoLayer_SaveLayerStrategy == strategy) {
1013 return; 1029 return;
1014 } 1030 }
1015 1031
1016 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); 1032 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
(...skipping 27 matching lines...) Expand all
1044 "Unable to create device for layer.") ; 1060 "Unable to create device for layer.") ;
1045 return; 1061 return;
1046 } 1062 }
1047 forceSpriteOnRestore = true; 1063 forceSpriteOnRestore = true;
1048 } 1064 }
1049 device = newDev; 1065 device = newDev;
1050 } 1066 }
1051 1067
1052 device->setOrigin(ir.fLeft, ir.fTop); 1068 device->setOrigin(ir.fLeft, ir.fTop);
1053 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip, 1069 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip,
1054 forceSpriteOnRestore)); 1070 forceSpriteOnRestore, matrix));
1055 device->unref(); 1071 device->unref();
1056 1072
1057 layer->fNext = fMCRec->fTopLayer; 1073 layer->fNext = fMCRec->fTopLayer;
1058 fMCRec->fLayer = layer; 1074 fMCRec->fLayer = layer;
1059 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1075 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1060 } 1076 }
1061 1077
1062 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1078 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
1063 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); 1079 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag);
1064 } 1080 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), 1118 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
1103 layer->fPaint, layer->fDeviceIsBitmapDevice ); 1119 layer->fPaint, layer->fDeviceIsBitmapDevice );
1104 // reset this, since internalDrawDevice will have set it to true 1120 // reset this, since internalDrawDevice will have set it to true
1105 fDeviceCMDirty = true; 1121 fDeviceCMDirty = true;
1106 SkDELETE(layer); 1122 SkDELETE(layer);
1107 } else { 1123 } else {
1108 // we're at the root 1124 // we're at the root
1109 SkASSERT(layer == (void*)fDeviceCMStorage); 1125 SkASSERT(layer == (void*)fDeviceCMStorage);
1110 layer->~DeviceCM(); 1126 layer->~DeviceCM();
1111 } 1127 }
1128 if (fMCRec) {
1129 fMCRec->fMatrix = layer->fStashedMatrix;
1130 }
1112 } 1131 }
1113 } 1132 }
1114 1133
1115 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 1134 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
1116 if (NULL == props) { 1135 if (NULL == props) {
1117 props = &fProps; 1136 props = &fProps;
1118 } 1137 }
1119 return this->onNewSurface(info, *props); 1138 return this->onNewSurface(info, *props);
1120 } 1139 }
1121 1140
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1348 }
1330 1349
1331 this->checkForDeferredSave(); 1350 this->checkForDeferredSave();
1332 fDeviceCMDirty = true; 1351 fDeviceCMDirty = true;
1333 fCachedLocalClipBoundsDirty = true; 1352 fCachedLocalClipBoundsDirty = true;
1334 fMCRec->fMatrix.preConcat(matrix); 1353 fMCRec->fMatrix.preConcat(matrix);
1335 1354
1336 this->didConcat(matrix); 1355 this->didConcat(matrix);
1337 } 1356 }
1338 1357
1358 void SkCanvas::internalSetMatrix(const SkMatrix& matrix) {
1359 fDeviceCMDirty = true;
1360 fCachedLocalClipBoundsDirty = true;
1361 fMCRec->fMatrix = matrix;
1362 }
1363
1339 void SkCanvas::setMatrix(const SkMatrix& matrix) { 1364 void SkCanvas::setMatrix(const SkMatrix& matrix) {
1340 this->checkForDeferredSave(); 1365 this->checkForDeferredSave();
1341 fDeviceCMDirty = true; 1366 this->internalSetMatrix(matrix);
1342 fCachedLocalClipBoundsDirty = true;
1343 fMCRec->fMatrix = matrix;
1344 this->didSetMatrix(matrix); 1367 this->didSetMatrix(matrix);
1345 } 1368 }
1346 1369
1347 void SkCanvas::resetMatrix() { 1370 void SkCanvas::resetMatrix() {
1348 SkMatrix matrix; 1371 SkMatrix matrix;
1349 1372
1350 matrix.reset(); 1373 matrix.reset();
1351 this->setMatrix(matrix); 1374 this->setMatrix(matrix);
1352 } 1375 }
1353 1376
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 } 2668 }
2646 2669
2647 if (matrix) { 2670 if (matrix) {
2648 canvas->concat(*matrix); 2671 canvas->concat(*matrix);
2649 } 2672 }
2650 } 2673 }
2651 2674
2652 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2675 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2653 fCanvas->restoreToCount(fSaveCount); 2676 fCanvas->restoreToCount(fSaveCount);
2654 } 2677 }
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