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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void reset(const SkIRect& bounds) { | 307 void reset(const SkIRect& bounds) { |
308 SkASSERT(fLayer); | 308 SkASSERT(fLayer); |
309 SkASSERT(fDeferredSaveCount == 0); | 309 SkASSERT(fDeferredSaveCount == 0); |
310 | 310 |
311 fMatrix.reset(); | 311 fMatrix.reset(); |
312 fRasterClip.setRect(bounds); | 312 fRasterClip.setRect(bounds); |
313 fLayer->reset(bounds); | 313 fLayer->reset(bounds); |
314 } | 314 } |
315 }; | 315 }; |
316 | 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 |
317 class SkDrawIter : public SkDraw { | 322 class SkDrawIter : public SkDraw { |
318 public: | 323 public: |
319 SkDrawIter(SkCanvas* canvas) { | 324 SkDrawIter(SkCanvas* canvas) { |
320 canvas = canvas->canvasForDrawIter(); | 325 canvas = canvas->canvasForDrawIter(); |
321 canvas->updateDeviceCMCache(); | 326 canvas->updateDeviceCMCache(); |
322 | 327 |
323 fClipStack = canvas->fClipStack; | 328 fClipStack = canvas->fClipStack; |
324 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 } |
325 } | 342 } |
326 | 343 |
327 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 |
328 // skip over recs with empty clips | 351 // skip over recs with empty clips |
329 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { | 352 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { |
330 fCurrLayer = fCurrLayer->fNext; | 353 fCurrLayer = fCurrLayer->fNext; |
331 } | 354 } |
332 | 355 |
333 const DeviceCM* rec = fCurrLayer; | 356 const DeviceCM* rec = fCurrLayer; |
334 if (rec && rec->fDevice) { | 357 if (rec && rec->fDevice) { |
335 | 358 |
336 fMatrix = rec->fMatrix; | 359 fMatrix = rec->fMatrix; |
337 fRC = &rec->fClip; | 360 fRC = &rec->fClip; |
(...skipping 15 matching lines...) Expand all Loading... |
353 SkBaseDevice* getDevice() const { return fDevice; } | 376 SkBaseDevice* getDevice() const { return fDevice; } |
354 const SkRasterClip& getClip() const { return *fRC; } | 377 const SkRasterClip& getClip() const { return *fRC; } |
355 int getX() const { return fDevice->getOrigin().x(); } | 378 int getX() const { return fDevice->getOrigin().x(); } |
356 int getY() const { return fDevice->getOrigin().y(); } | 379 int getY() const { return fDevice->getOrigin().y(); } |
357 const SkMatrix& getMatrix() const { return *fMatrix; } | 380 const SkMatrix& getMatrix() const { return *fMatrix; } |
358 const SkPaint* getPaint() const { return fPaint; } | 381 const SkPaint* getPaint() const { return fPaint; } |
359 | 382 |
360 private: | 383 private: |
361 const DeviceCM* fCurrLayer; | 384 const DeviceCM* fCurrLayer; |
362 const SkPaint* fPaint; // May be null. | 385 const SkPaint* fPaint; // May be null. |
| 386 SkClipStack* fMultiDeviceCS; |
363 | 387 |
364 typedef SkDraw INHERITED; | 388 typedef SkDraw INHERITED; |
365 }; | 389 }; |
366 | 390 |
367 ///////////////////////////////////////////////////////////////////////////// | 391 ///////////////////////////////////////////////////////////////////////////// |
368 | 392 |
369 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { | 393 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { |
370 return lazy->isValid() ? lazy->get() : lazy->set(orig); | 394 return lazy->isValid() ? lazy->get() : lazy->set(orig); |
371 } | 395 } |
372 | 396 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 | 1064 |
1041 void SkCanvas::internalSave() { | 1065 void SkCanvas::internalSave() { |
1042 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 1066 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
1043 new (newTop) MCRec(*fMCRec); // balanced in restore() | 1067 new (newTop) MCRec(*fMCRec); // balanced in restore() |
1044 fMCRec = newTop; | 1068 fMCRec = newTop; |
1045 | 1069 |
1046 fClipStack->save(); | 1070 fClipStack->save(); |
1047 } | 1071 } |
1048 | 1072 |
1049 bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) { | 1073 bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) { |
1050 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | |
1051 return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag); | 1074 return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag); |
1052 #else | |
1053 return true; | |
1054 #endif | |
1055 } | 1075 } |
1056 | 1076 |
1057 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlag
s, | 1077 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlag
s, |
1058 SkIRect* intersection, const SkImageFilter* imageF
ilter) { | 1078 SkIRect* intersection, const SkImageFilter* imageF
ilter) { |
1059 SkIRect clipBounds; | 1079 SkIRect clipBounds; |
1060 if (!this->getClipDeviceBounds(&clipBounds)) { | 1080 if (!this->getClipDeviceBounds(&clipBounds)) { |
1061 return false; | 1081 return false; |
1062 } | 1082 } |
1063 | 1083 |
1064 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 Loading... |
1161 // keep the same characteristics as the prev | 1181 // keep the same characteristics as the prev |
1162 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())); |
1163 } | 1183 } |
1164 } | 1184 } |
1165 | 1185 |
1166 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
tegy) { | 1186 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
tegy) { |
1167 const SkRect* bounds = rec.fBounds; | 1187 const SkRect* bounds = rec.fBounds; |
1168 const SkPaint* paint = rec.fPaint; | 1188 const SkPaint* paint = rec.fPaint; |
1169 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; | 1189 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; |
1170 | 1190 |
1171 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | |
1172 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; | |
1173 #endif | |
1174 | |
1175 SkLazyPaint lazyP; | 1191 SkLazyPaint lazyP; |
1176 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; | 1192 SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; |
1177 SkMatrix stashedMatrix = fMCRec->fMatrix; | 1193 SkMatrix stashedMatrix = fMCRec->fMatrix; |
1178 SkMatrix remainder; | 1194 SkMatrix remainder; |
1179 SkSize scale; | 1195 SkSize scale; |
1180 /* | 1196 /* |
1181 * 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. |
1182 * 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: |
1183 * | 1199 * |
1184 * 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 Loading... |
3444 | 3460 |
3445 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3461 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3446 fCanvas->restoreToCount(fSaveCount); | 3462 fCanvas->restoreToCount(fSaveCount); |
3447 } | 3463 } |
3448 | 3464 |
3449 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3465 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3450 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3466 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
3451 return this->makeSurface(info, props).release(); | 3467 return this->makeSurface(info, props).release(); |
3452 } | 3468 } |
3453 #endif | 3469 #endif |
OLD | NEW |