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

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

Issue 2296703003: test dont-clip-layer (Closed)
Patch Set: allow feature to be tested all the time Created 4 years, 3 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
« gm/aaclip.cpp ('K') | « gm/aaclip.cpp ('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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 209
210 void reset(const SkIRect& bounds) { 210 void reset(const SkIRect& bounds) {
211 SkASSERT(!fPaint); 211 SkASSERT(!fPaint);
212 SkASSERT(!fNext); 212 SkASSERT(!fNext);
213 SkASSERT(fDevice); 213 SkASSERT(fDevice);
214 fClip.setRect(bounds); 214 fClip.setRect(bounds);
215 } 215 }
216 216
217 void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip, 217 void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip,
218 const SkClipStack& clipStack, SkRasterClip* updateClip) { 218 SkRasterClip* updateClip) {
219 int x = fDevice->getOrigin().x(); 219 int x = fDevice->getOrigin().x();
220 int y = fDevice->getOrigin().y(); 220 int y = fDevice->getOrigin().y();
221 int width = fDevice->width(); 221 int width = fDevice->width();
222 int height = fDevice->height(); 222 int height = fDevice->height();
223 223
224 if ((x | y) == 0) { 224 if ((x | y) == 0) {
225 fMatrix = &totalMatrix; 225 fMatrix = &totalMatrix;
226 fClip = totalClip; 226 fClip = totalClip;
227 } else { 227 } else {
228 fMatrixStorage = totalMatrix; 228 fMatrixStorage = totalMatrix;
229 fMatrixStorage.postTranslate(SkIntToScalar(-x), 229 fMatrixStorage.postTranslate(SkIntToScalar(-x),
230 SkIntToScalar(-y)); 230 SkIntToScalar(-y));
231 fMatrix = &fMatrixStorage; 231 fMatrix = &fMatrixStorage;
232 232
233 totalClip.translate(-x, -y, &fClip); 233 totalClip.translate(-x, -y, &fClip);
234 } 234 }
235 235
236 fClip.op(SkIRect::MakeWH(width, height), SkRegion::kIntersect_Op); 236 fClip.op(SkIRect::MakeWH(width, height), SkRegion::kIntersect_Op);
237 237
238 // intersect clip, but don't translate it (yet) 238 // intersect clip, but don't translate it (yet)
239 239
240 if (updateClip) { 240 if (updateClip) {
241 updateClip->op(SkIRect::MakeXYWH(x, y, width, height), 241 updateClip->op(SkIRect::MakeXYWH(x, y, width, height),
242 SkRegion::kDifference_Op); 242 SkRegion::kDifference_Op);
243 } 243 }
244 244
245 fDevice->setMatrixClip(*fMatrix, fClip.forceGetBW(), clipStack);
246
247 #ifdef SK_DEBUG 245 #ifdef SK_DEBUG
248 if (!fClip.isEmpty()) { 246 if (!fClip.isEmpty()) {
249 SkIRect deviceR; 247 SkIRect deviceR;
250 deviceR.set(0, 0, width, height); 248 deviceR.set(0, 0, width, height);
251 SkASSERT(deviceR.contains(fClip.getBounds())); 249 SkASSERT(deviceR.contains(fClip.getBounds()));
252 } 250 }
253 #endif 251 #endif
254 } 252 }
255 }; 253 };
256 254
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 void reset(const SkIRect& bounds) { 307 void reset(const SkIRect& bounds) {
310 SkASSERT(fLayer); 308 SkASSERT(fLayer);
311 SkASSERT(fDeferredSaveCount == 0); 309 SkASSERT(fDeferredSaveCount == 0);
312 310
313 fMatrix.reset(); 311 fMatrix.reset();
314 fRasterClip.setRect(bounds); 312 fRasterClip.setRect(bounds);
315 fLayer->reset(bounds); 313 fLayer->reset(bounds);
316 } 314 }
317 }; 315 };
318 316
317 static SkIRect compute_device_bounds(SkBaseDevice* device) {
318 return SkIRect::MakeXYWH(device->getOrigin().x(), device->getOrigin().y(),
319 device->width(), device->height());
320 }
321
319 class SkDrawIter : public SkDraw { 322 class SkDrawIter : public SkDraw {
320 public: 323 public:
321 SkDrawIter(SkCanvas* canvas) { 324 SkDrawIter(SkCanvas* canvas) {
322 canvas = canvas->canvasForDrawIter(); 325 canvas = canvas->canvasForDrawIter();
323 canvas->updateDeviceCMCache(); 326 canvas->updateDeviceCMCache();
324 327
325 fClipStack = canvas->fClipStack; 328 fClipStack = canvas->fClipStack;
326 fCurrLayer = canvas->fMCRec->fTopLayer; 329 fCurrLayer = canvas->fMCRec->fTopLayer;
330
331 fMultiDeviceCS = nullptr;
332 if (fCurrLayer->fNext) {
333 fMultiDeviceCS = canvas->fClipStack;
334 fMultiDeviceCS->save();
335 }
336 }
337
338 ~SkDrawIter() {
339 if (fMultiDeviceCS) {
340 fMultiDeviceCS->restore();
341 }
327 } 342 }
328 343
329 bool next() { 344 bool next() {
345 if (fMultiDeviceCS && fDevice) {
346 // remove the previous device's bounds
347 fMultiDeviceCS->clipDevRect(compute_device_bounds(fDevice),
348 SkRegion::kDifference_Op);
349 }
350
330 // skip over recs with empty clips 351 // skip over recs with empty clips
331 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { 352 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) {
332 fCurrLayer = fCurrLayer->fNext; 353 fCurrLayer = fCurrLayer->fNext;
333 } 354 }
334 355
335 const DeviceCM* rec = fCurrLayer; 356 const DeviceCM* rec = fCurrLayer;
336 if (rec && rec->fDevice) { 357 if (rec && rec->fDevice) {
337 358
338 fMatrix = rec->fMatrix; 359 fMatrix = rec->fMatrix;
339 fRC = &rec->fClip; 360 fRC = &rec->fClip;
(...skipping 15 matching lines...) Expand all
355 SkBaseDevice* getDevice() const { return fDevice; } 376 SkBaseDevice* getDevice() const { return fDevice; }
356 const SkRasterClip& getClip() const { return *fRC; } 377 const SkRasterClip& getClip() const { return *fRC; }
357 int getX() const { return fDevice->getOrigin().x(); } 378 int getX() const { return fDevice->getOrigin().x(); }
358 int getY() const { return fDevice->getOrigin().y(); } 379 int getY() const { return fDevice->getOrigin().y(); }
359 const SkMatrix& getMatrix() const { return *fMatrix; } 380 const SkMatrix& getMatrix() const { return *fMatrix; }
360 const SkPaint* getPaint() const { return fPaint; } 381 const SkPaint* getPaint() const { return fPaint; }
361 382
362 private: 383 private:
363 const DeviceCM* fCurrLayer; 384 const DeviceCM* fCurrLayer;
364 const SkPaint* fPaint; // May be null. 385 const SkPaint* fPaint; // May be null.
386 SkClipStack* fMultiDeviceCS;
365 387
366 typedef SkDraw INHERITED; 388 typedef SkDraw INHERITED;
367 }; 389 };
368 390
369 ///////////////////////////////////////////////////////////////////////////// 391 /////////////////////////////////////////////////////////////////////////////
370 392
371 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { 393 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) {
372 return lazy->isValid() ? lazy->get() : lazy->set(orig); 394 return lazy->isValid() ? lazy->get() : lazy->set(orig);
373 } 395 }
374 396
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 977
956 ////////////////////////////////////////////////////////////////////////////// 978 //////////////////////////////////////////////////////////////////////////////
957 979
958 void SkCanvas::updateDeviceCMCache() { 980 void SkCanvas::updateDeviceCMCache() {
959 if (fDeviceCMDirty) { 981 if (fDeviceCMDirty) {
960 const SkMatrix& totalMatrix = this->getTotalMatrix(); 982 const SkMatrix& totalMatrix = this->getTotalMatrix();
961 const SkRasterClip& totalClip = fMCRec->fRasterClip; 983 const SkRasterClip& totalClip = fMCRec->fRasterClip;
962 DeviceCM* layer = fMCRec->fTopLayer; 984 DeviceCM* layer = fMCRec->fTopLayer;
963 985
964 if (nullptr == layer->fNext) { // only one layer 986 if (nullptr == layer->fNext) { // only one layer
965 layer->updateMC(totalMatrix, totalClip, *fClipStack, nullptr); 987 layer->updateMC(totalMatrix, totalClip, nullptr);
966 } else { 988 } else {
967 SkRasterClip clip(totalClip); 989 SkRasterClip clip(totalClip);
968 do { 990 do {
969 layer->updateMC(totalMatrix, clip, *fClipStack, &clip); 991 layer->updateMC(totalMatrix, clip, &clip);
970 } while ((layer = layer->fNext) != nullptr); 992 } while ((layer = layer->fNext) != nullptr);
971 } 993 }
972 fDeviceCMDirty = false; 994 fDeviceCMDirty = false;
973 } 995 }
974 } 996 }
975 997
976 /////////////////////////////////////////////////////////////////////////////// 998 ///////////////////////////////////////////////////////////////////////////////
977 999
978 void SkCanvas::checkForDeferredSave() { 1000 void SkCanvas::checkForDeferredSave() {
979 if (fMCRec->fDeferredSaveCount > 0) { 1001 if (fMCRec->fDeferredSaveCount > 0) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1064
1043 void SkCanvas::internalSave() { 1065 void SkCanvas::internalSave() {
1044 MCRec* newTop = (MCRec*)fMCStack.push_back(); 1066 MCRec* newTop = (MCRec*)fMCStack.push_back();
1045 new (newTop) MCRec(*fMCRec); // balanced in restore() 1067 new (newTop) MCRec(*fMCRec); // balanced in restore()
1046 fMCRec = newTop; 1068 fMCRec = newTop;
1047 1069
1048 fClipStack->save(); 1070 fClipStack->save();
1049 } 1071 }
1050 1072
1051 bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) { 1073 bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) {
1052 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1053 return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag); 1074 return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag);
1054 #else
1055 return true;
1056 #endif
1057 } 1075 }
1058 1076
1059 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlag s, 1077 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlag s,
1060 SkIRect* intersection, const SkImageFilter* imageF ilter) { 1078 SkIRect* intersection, const SkImageFilter* imageF ilter) {
1061 SkIRect clipBounds; 1079 SkIRect clipBounds;
1062 if (!this->getClipDeviceBounds(&clipBounds)) { 1080 if (!this->getClipDeviceBounds(&clipBounds)) {
1063 return false; 1081 return false;
1064 } 1082 }
1065 1083
1066 const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix() 1084 const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix()
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 // keep the same characteristics as the prev 1181 // keep the same characteristics as the prev
1164 return SkImageInfo::Make(w, h, prev.colorType(), alphaType, sk_ref_sp(pr ev.colorSpace())); 1182 return SkImageInfo::Make(w, h, prev.colorType(), alphaType, sk_ref_sp(pr ev.colorSpace()));
1165 } 1183 }
1166 } 1184 }
1167 1185
1168 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) { 1186 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) {
1169 const SkRect* bounds = rec.fBounds; 1187 const SkRect* bounds = rec.fBounds;
1170 const SkPaint* paint = rec.fPaint; 1188 const SkPaint* paint = rec.fPaint;
1171 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; 1189 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags;
1172 1190
1173 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1174 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag;
1175 #endif
1176
1177 SkLazyPaint lazyP; 1191 SkLazyPaint lazyP;
1178 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; 1192 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL;
1179 SkMatrix stashedMatrix = fMCRec->fMatrix; 1193 SkMatrix stashedMatrix = fMCRec->fMatrix;
1180 SkMatrix remainder; 1194 SkMatrix remainder;
1181 SkSize scale; 1195 SkSize scale;
1182 /* 1196 /*
1183 * ImageFilters (so far) do not correctly handle matrices (CTM) that contai n rotation/skew/etc. 1197 * ImageFilters (so far) do not correctly handle matrices (CTM) that contai n rotation/skew/etc.
1184 * but they do handle scaling. To accommodate this, we do the following: 1198 * but they do handle scaling. To accommodate this, we do the following:
1185 * 1199 *
1186 * 1. Stash off the current CTM 1200 * 1. Stash off the current CTM
(...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 3460
3447 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3461 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3448 fCanvas->restoreToCount(fSaveCount); 3462 fCanvas->restoreToCount(fSaveCount);
3449 } 3463 }
3450 3464
3451 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API 3465 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
3452 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 3466 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
3453 return this->makeSurface(info, props).release(); 3467 return this->makeSurface(info, props).release();
3454 } 3468 }
3455 #endif 3469 #endif
OLDNEW
« gm/aaclip.cpp ('K') | « gm/aaclip.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698