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 | 8 |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 typedef SkTLazy<SkPaint> SkLazyPaint; | 60 typedef SkTLazy<SkPaint> SkLazyPaint; |
| 61 | 61 |
| 62 void SkCanvas::predrawNotify() { | 62 void SkCanvas::predrawNotify() { |
| 63 if (fSurfaceBase) { | 63 if (fSurfaceBase) { |
| 64 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); | 64 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 69 | 69 |
| 70 static uint32_t filter_paint_flags(const SkSurfaceProps& props, uint32_t flags) { | |
| 71 const uint32_t propFlags = props.flags(); | |
| 72 if (propFlags & SkSurfaceProps::kDisallowDither_Flag) { | |
| 73 flags &= ~SkPaint::kDither_Flag; | |
| 74 } | |
| 75 if (propFlags & SkSurfaceProps::kDisallowAntiAlias_Flag) { | |
| 76 flags &= ~SkPaint::kAntiAlias_Flag; | |
| 77 } | |
| 78 return flags; | |
| 79 } | |
| 80 | |
| 81 /////////////////////////////////////////////////////////////////////////////// | |
| 82 | |
| 70 /* This is the record we keep for each SkBaseDevice that the user installs. | 83 /* This is the record we keep for each SkBaseDevice that the user installs. |
| 71 The clip/matrix/proc are fields that reflect the top of the save/restore | 84 The clip/matrix/proc are fields that reflect the top of the save/restore |
| 72 stack. Whenever the canvas changes, it marks a dirty flag, and then before | 85 stack. Whenever the canvas changes, it marks a dirty flag, and then before |
| 73 these are used (assuming we're not on a layer) we rebuild these cache | 86 these are used (assuming we're not on a layer) we rebuild these cache |
| 74 values: they reflect the top of the save stack, but translated and clipped | 87 values: they reflect the top of the save stack, but translated and clipped |
| 75 by the device's XY offset and bitmap-bounds. | 88 by the device's XY offset and bitmap-bounds. |
| 76 */ | 89 */ |
| 77 struct DeviceCM { | 90 struct DeviceCM { |
| 78 DeviceCM* fNext; | 91 DeviceCM* fNext; |
| 79 SkBaseDevice* fDevice; | 92 SkBaseDevice* fDevice; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 const SkPaint* fPaint; // May be null. | 256 const SkPaint* fPaint; // May be null. |
| 244 SkBool8 fSkipEmptyClips; | 257 SkBool8 fSkipEmptyClips; |
| 245 | 258 |
| 246 typedef SkDraw INHERITED; | 259 typedef SkDraw INHERITED; |
| 247 }; | 260 }; |
| 248 | 261 |
| 249 ///////////////////////////////////////////////////////////////////////////// | 262 ///////////////////////////////////////////////////////////////////////////// |
| 250 | 263 |
| 251 class AutoDrawLooper { | 264 class AutoDrawLooper { |
| 252 public: | 265 public: |
| 253 AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, | 266 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint, |
| 254 bool skipLayerForImageFilter = false, | 267 bool skipLayerForImageFilter = false, |
| 255 const SkRect* bounds = NULL) : fOrigPaint(paint) { | 268 const SkRect* bounds = NULL) : fOrigPaint(paint) { |
| 256 fCanvas = canvas; | 269 fCanvas = canvas; |
| 257 fFilter = canvas->getDrawFilter(); | 270 fFilter = canvas->getDrawFilter(); |
| 258 fPaint = NULL; | 271 fPaint = &fOrigPaint; |
|
bsalomon
2014/09/18 18:43:33
SkTCopyOnFirstWrite?
reed1
2014/09/18 21:03:12
? fPaint is a pointer, so this line is free.
bsalomon
2014/09/18 21:20:24
Init'ing a SkTCopyOnFirstWrite isn't costly and it
| |
| 259 fSaveCount = canvas->getSaveCount(); | 272 fSaveCount = canvas->getSaveCount(); |
| 260 fDoClearImageFilter = false; | 273 fDoClearImageFilter = false; |
| 261 fDone = false; | 274 fDone = false; |
| 262 | 275 |
| 263 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { | 276 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { |
| 264 SkPaint tmp; | 277 SkPaint tmp; |
| 265 tmp.setImageFilter(fOrigPaint.getImageFilter()); | 278 tmp.setImageFilter(fOrigPaint.getImageFilter()); |
| 266 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag, | 279 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag, |
| 267 true, SkCanvas::kFullLayer_SaveLayer Strategy); | 280 true, SkCanvas::kFullLayer_SaveLayer Strategy); |
| 268 // we'll clear the imageFilter for the actual draws in next(), so | 281 // we'll clear the imageFilter for the actual draws in next(), so |
| 269 // it will only be applied during the restore(). | 282 // it will only be applied during the restore(). |
| 270 fDoClearImageFilter = true; | 283 fDoClearImageFilter = true; |
| 271 } | 284 } |
| 272 | 285 |
| 273 if (SkDrawLooper* looper = paint.getLooper()) { | 286 if (SkDrawLooper* looper = paint.getLooper()) { |
| 274 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( | 287 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( |
| 275 looper->contextSize()); | 288 looper->contextSize()); |
| 276 fLooperContext = looper->createContext(canvas, buffer); | 289 fLooperContext = looper->createContext(canvas, buffer); |
| 277 fIsSimple = false; | 290 fIsSimple = false; |
| 278 } else { | 291 } else { |
| 279 fLooperContext = NULL; | 292 fLooperContext = NULL; |
| 280 // can we be marked as simple? | 293 // can we be marked as simple? |
| 281 fIsSimple = !fFilter && !fDoClearImageFilter; | 294 fIsSimple = !fFilter && !fDoClearImageFilter; |
| 282 } | 295 } |
| 296 | |
| 297 uint32_t oldFlags = paint.getFlags(); | |
| 298 fNewPaintFlags = filter_paint_flags(props, oldFlags); | |
| 299 if (fIsSimple && (fNewPaintFlags != oldFlags)) { | |
| 300 SkPaint* paint = fLazyPaint.set(fOrigPaint); | |
|
bsalomon
2014/09/18 18:43:33
fPaint->writable()->setFlags(fNewPaintFlags);
| |
| 301 paint->setFlags(fNewPaintFlags); | |
| 302 fPaint = paint; | |
| 303 // if we're not simple, doNext() will take care of calling setFlags( ) | |
| 304 } | |
| 283 } | 305 } |
| 284 | 306 |
| 285 ~AutoDrawLooper() { | 307 ~AutoDrawLooper() { |
| 286 if (fDoClearImageFilter) { | 308 if (fDoClearImageFilter) { |
| 287 fCanvas->internalRestore(); | 309 fCanvas->internalRestore(); |
| 288 } | 310 } |
| 289 SkASSERT(fCanvas->getSaveCount() == fSaveCount); | 311 SkASSERT(fCanvas->getSaveCount() == fSaveCount); |
| 290 } | 312 } |
| 291 | 313 |
| 292 const SkPaint& paint() const { | 314 const SkPaint& paint() const { |
| 293 SkASSERT(fPaint); | 315 SkASSERT(fPaint); |
| 294 return *fPaint; | 316 return *fPaint; |
| 295 } | 317 } |
| 296 | 318 |
| 297 bool next(SkDrawFilter::Type drawType) { | 319 bool next(SkDrawFilter::Type drawType) { |
| 298 if (fDone) { | 320 if (fDone) { |
| 299 return false; | 321 return false; |
| 300 } else if (fIsSimple) { | 322 } else if (fIsSimple) { |
| 301 fDone = true; | 323 fDone = true; |
| 302 fPaint = &fOrigPaint; | |
| 303 return !fPaint->nothingToDraw(); | 324 return !fPaint->nothingToDraw(); |
| 304 } else { | 325 } else { |
| 305 return this->doNext(drawType); | 326 return this->doNext(drawType); |
| 306 } | 327 } |
| 307 } | 328 } |
| 308 | 329 |
| 309 private: | 330 private: |
| 310 SkLazyPaint fLazyPaint; | 331 SkLazyPaint fLazyPaint; |
| 311 SkCanvas* fCanvas; | 332 SkCanvas* fCanvas; |
| 312 const SkPaint& fOrigPaint; | 333 const SkPaint& fOrigPaint; |
| 313 SkDrawFilter* fFilter; | 334 SkDrawFilter* fFilter; |
| 314 const SkPaint* fPaint; | 335 const SkPaint* fPaint; |
| 315 int fSaveCount; | 336 int fSaveCount; |
| 337 uint32_t fNewPaintFlags; | |
| 316 bool fDoClearImageFilter; | 338 bool fDoClearImageFilter; |
| 317 bool fDone; | 339 bool fDone; |
| 318 bool fIsSimple; | 340 bool fIsSimple; |
| 319 SkDrawLooper::Context* fLooperContext; | 341 SkDrawLooper::Context* fLooperContext; |
| 320 SkSmallAllocator<1, 32> fLooperContextAllocator; | 342 SkSmallAllocator<1, 32> fLooperContextAllocator; |
| 321 | 343 |
| 322 bool doNext(SkDrawFilter::Type drawType); | 344 bool doNext(SkDrawFilter::Type drawType); |
| 323 }; | 345 }; |
| 324 | 346 |
| 325 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { | 347 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
| 326 fPaint = NULL; | 348 fPaint = NULL; |
| 327 SkASSERT(!fIsSimple); | 349 SkASSERT(!fIsSimple); |
| 328 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter); | 350 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter); |
| 329 | 351 |
| 330 SkPaint* paint = fLazyPaint.set(fOrigPaint); | 352 SkPaint* paint = fLazyPaint.set(fOrigPaint); |
| 353 paint->setFlags(fNewPaintFlags); | |
| 331 | 354 |
| 332 if (fDoClearImageFilter) { | 355 if (fDoClearImageFilter) { |
| 333 paint->setImageFilter(NULL); | 356 paint->setImageFilter(NULL); |
| 334 } | 357 } |
| 335 | 358 |
| 336 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { | 359 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
| 337 fDone = true; | 360 fDone = true; |
| 338 return false; | 361 return false; |
| 339 } | 362 } |
| 340 if (fFilter) { | 363 if (fFilter) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 356 | 379 |
| 357 // call this after any possible paint modifiers | 380 // call this after any possible paint modifiers |
| 358 if (fPaint->nothingToDraw()) { | 381 if (fPaint->nothingToDraw()) { |
| 359 fPaint = NULL; | 382 fPaint = NULL; |
| 360 return false; | 383 return false; |
| 361 } | 384 } |
| 362 return true; | 385 return true; |
| 363 } | 386 } |
| 364 | 387 |
| 365 #include "SkColorPriv.h" | 388 #include "SkColorPriv.h" |
| 389 #include "SkDeviceProperties.h" | |
| 366 | 390 |
| 367 ////////// macros to place around the internal draw calls ////////////////// | 391 ////////// macros to place around the internal draw calls ////////////////// |
| 368 | 392 |
| 369 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ | 393 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
| 370 this->predrawNotify(); \ | 394 this->predrawNotify(); \ |
| 371 AutoDrawLooper looper(this, paint, true); \ | 395 AutoDrawLooper looper(this, fProps, paint, true); \ |
| 372 while (looper.next(type)) { \ | 396 while (looper.next(type)) { \ |
| 373 SkDrawIter iter(this); | 397 SkDrawIter iter(this); |
| 374 | 398 |
| 375 #define LOOPER_BEGIN(paint, type, bounds) \ | 399 #define LOOPER_BEGIN(paint, type, bounds) \ |
| 376 this->predrawNotify(); \ | 400 this->predrawNotify(); \ |
| 377 AutoDrawLooper looper(this, paint, false, bounds); \ | 401 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ |
| 378 while (looper.next(type)) { \ | 402 while (looper.next(type)) { \ |
| 379 SkDrawIter iter(this); | 403 SkDrawIter iter(this); |
| 380 | 404 |
| 381 #define LOOPER_END } | 405 #define LOOPER_END } |
| 382 | 406 |
| 383 //////////////////////////////////////////////////////////////////////////// | 407 //////////////////////////////////////////////////////////////////////////// |
| 384 | 408 |
| 409 void SkCanvas::setupDevice(SkBaseDevice* device) { | |
| 410 device->setPixelGeometry(fProps.pixelGeometry()); | |
| 411 } | |
| 412 | |
| 385 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { | 413 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
| 386 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; | 414 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; |
| 387 fCachedLocalClipBounds.setEmpty(); | 415 fCachedLocalClipBounds.setEmpty(); |
| 388 fCachedLocalClipBoundsDirty = true; | 416 fCachedLocalClipBoundsDirty = true; |
| 389 fAllowSoftClip = true; | 417 fAllowSoftClip = true; |
| 390 fAllowSimplifyClip = false; | 418 fAllowSimplifyClip = false; |
| 391 fDeviceCMDirty = true; | 419 fDeviceCMDirty = true; |
| 392 fSaveLayerCount = 0; | 420 fSaveLayerCount = 0; |
| 393 fCullCount = 0; | 421 fCullCount = 0; |
| 394 fMetaData = NULL; | 422 fMetaData = NULL; |
| 395 | 423 |
| 396 if (device && device->forceConservativeRasterClip()) { | |
| 397 fConservativeRasterClip = true; | |
| 398 } | |
| 399 | |
| 400 fMCRec = (MCRec*)fMCStack.push_back(); | 424 fMCRec = (MCRec*)fMCStack.push_back(); |
| 401 new (fMCRec) MCRec(fConservativeRasterClip); | 425 new (fMCRec) MCRec(fConservativeRasterClip); |
| 402 | 426 |
| 403 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); | 427 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); |
| 404 fMCRec->fTopLayer = fMCRec->fLayer; | 428 fMCRec->fTopLayer = fMCRec->fLayer; |
| 405 | 429 |
| 406 fSurfaceBase = NULL; | 430 fSurfaceBase = NULL; |
| 407 | 431 |
| 408 if (device) { | 432 if (device) { |
| 433 this->setupDevice(device); | |
| 434 if (device->forceConservativeRasterClip()) { | |
| 435 fConservativeRasterClip = true; | |
| 436 } | |
| 409 device->onAttachToCanvas(this); | 437 device->onAttachToCanvas(this); |
| 410 fMCRec->fLayer->fDevice = SkRef(device); | 438 fMCRec->fLayer->fDevice = SkRef(device); |
| 411 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei ght())); | 439 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei ght())); |
| 412 } | 440 } |
| 413 return device; | 441 return device; |
| 414 } | 442 } |
| 415 | 443 |
| 416 SkCanvas::SkCanvas() | 444 SkCanvas::SkCanvas() |
| 417 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 445 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 446 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
| 418 { | 447 { |
| 419 inc_canvas(); | 448 inc_canvas(); |
| 420 | 449 |
| 421 this->init(NULL, kDefault_InitFlags); | 450 this->init(NULL, kDefault_InitFlags); |
| 422 } | 451 } |
| 423 | 452 |
| 424 static SkBitmap make_nopixels(int width, int height) { | 453 static SkBitmap make_nopixels(int width, int height) { |
| 425 SkBitmap bitmap; | 454 SkBitmap bitmap; |
| 426 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); | 455 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
| 427 return bitmap; | 456 return bitmap; |
| 428 } | 457 } |
| 429 | 458 |
| 430 class SkNoPixelsBitmapDevice : public SkBitmapDevice { | 459 class SkNoPixelsBitmapDevice : public SkBitmapDevice { |
| 431 public: | 460 public: |
| 432 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt h, height)) {} | 461 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt h, height)) {} |
| 433 | 462 |
| 434 private: | 463 private: |
| 435 | 464 |
| 436 typedef SkBitmapDevice INHERITED; | 465 typedef SkBitmapDevice INHERITED; |
| 437 }; | 466 }; |
| 438 | 467 |
| 468 static SkSurfaceProps props_or_default(const SkSurfaceProps* props) { | |
| 469 if (props) { | |
| 470 return *props; | |
| 471 } else { | |
| 472 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 473 } | |
| 474 } | |
| 475 | |
| 439 SkCanvas::SkCanvas(int width, int height) | 476 SkCanvas::SkCanvas(int width, int height) |
| 440 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 477 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 478 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
| 441 { | 479 { |
| 442 inc_canvas(); | 480 inc_canvas(); |
| 443 | 481 |
| 444 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini tFlags)->unref(); | 482 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini tFlags)->unref(); |
| 445 } | 483 } |
| 446 | 484 |
| 447 SkCanvas::SkCanvas(int width, int height, InitFlags flags) | 485 SkCanvas::SkCanvas(int width, int height, InitFlags flags) |
| 448 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 486 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 487 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
| 449 { | 488 { |
| 450 inc_canvas(); | 489 inc_canvas(); |
| 451 | 490 |
| 452 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre f(); | 491 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre f(); |
| 453 } | 492 } |
| 454 | 493 |
| 455 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) | 494 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags) |
| 456 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 495 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 496 , fProps(props_or_default(props)) | |
| 457 { | 497 { |
| 458 inc_canvas(); | 498 inc_canvas(); |
| 459 | 499 |
| 460 this->init(device, flags); | 500 this->init(device, flags); |
| 461 } | 501 } |
| 462 | 502 |
| 463 SkCanvas::SkCanvas(SkBaseDevice* device) | 503 SkCanvas::SkCanvas(SkBaseDevice* device) |
| 464 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 504 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 505 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
| 465 { | 506 { |
| 466 inc_canvas(); | 507 inc_canvas(); |
| 467 | 508 |
| 468 this->init(device, kDefault_InitFlags); | 509 this->init(device, kDefault_InitFlags); |
| 469 } | 510 } |
| 470 | 511 |
| 512 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) | |
| 513 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | |
| 514 , fProps(props) | |
| 515 { | |
| 516 inc_canvas(); | |
| 517 | |
| 518 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); | |
| 519 this->init(device, kDefault_InitFlags); | |
| 520 } | |
| 521 | |
| 471 SkCanvas::SkCanvas(const SkBitmap& bitmap) | 522 SkCanvas::SkCanvas(const SkBitmap& bitmap) |
| 472 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 523 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| 524 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
| 473 { | 525 { |
| 474 inc_canvas(); | 526 inc_canvas(); |
| 475 | 527 |
| 476 this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)), kDefault_InitFlags)->unref( ); | 528 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); |
| 529 this->init(device, kDefault_InitFlags); | |
| 477 } | 530 } |
| 478 | 531 |
| 479 SkCanvas::~SkCanvas() { | 532 SkCanvas::~SkCanvas() { |
| 480 // free up the contents of our deque | 533 // free up the contents of our deque |
| 481 this->restoreToCount(1); // restore everything but the last | 534 this->restoreToCount(1); // restore everything but the last |
| 482 SkASSERT(0 == fSaveLayerCount); | 535 SkASSERT(0 == fSaveLayerCount); |
| 483 | 536 |
| 484 this->internalRestore(); // restore the last, since we're going away | 537 this->internalRestore(); // restore the last, since we're going away |
| 485 | 538 |
| 486 SkDELETE(fMetaData); | 539 SkDELETE(fMetaData); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 | 610 |
| 558 if (device) { | 611 if (device) { |
| 559 device->onAttachToCanvas(this); | 612 device->onAttachToCanvas(this); |
| 560 } | 613 } |
| 561 if (rootDevice) { | 614 if (rootDevice) { |
| 562 rootDevice->onDetachFromCanvas(); | 615 rootDevice->onDetachFromCanvas(); |
| 563 } | 616 } |
| 564 | 617 |
| 565 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); | 618 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); |
| 566 rootDevice = device; | 619 rootDevice = device; |
| 620 this->setupDevice(device); | |
| 567 | 621 |
| 568 fDeviceCMDirty = true; | 622 fDeviceCMDirty = true; |
| 569 | 623 |
| 570 /* Now we update our initial region to have the bounds of the new device, | 624 /* Now we update our initial region to have the bounds of the new device, |
| 571 and then intersect all of the clips in our stack with these bounds, | 625 and then intersect all of the clips in our stack with these bounds, |
| 572 to ensure that we can't draw outside of the device's bounds (and trash | 626 to ensure that we can't draw outside of the device's bounds (and trash |
| 573 memory). | 627 memory). |
| 574 | 628 |
| 575 NOTE: this is only a partial-fix, since if the new device is larger than | 629 NOTE: this is only a partial-fix, since if the new device is larger than |
| 576 the previous one, we don't know how to "enlarge" the clips in our stack, | 630 the previous one, we don't know how to "enlarge" the clips in our stack, |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 if (device) { | 946 if (device) { |
| 893 device = device->createCompatibleDevice(info); | 947 device = device->createCompatibleDevice(info); |
| 894 } | 948 } |
| 895 } else { | 949 } else { |
| 896 device = this->createLayerDevice(info); | 950 device = this->createLayerDevice(info); |
| 897 } | 951 } |
| 898 if (NULL == device) { | 952 if (NULL == device) { |
| 899 SkDebugf("Unable to create device for layer."); | 953 SkDebugf("Unable to create device for layer."); |
| 900 return count; | 954 return count; |
| 901 } | 955 } |
| 956 this->setupDevice(device); | |
| 902 | 957 |
| 903 device->setOrigin(ir.fLeft, ir.fTop); | 958 device->setOrigin(ir.fLeft, ir.fTop); |
| 904 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 959 DeviceCM* layer = SkNEW_ARGS(DeviceCM, |
| 905 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip)); | 960 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip)); |
| 906 device->unref(); | 961 device->unref(); |
| 907 | 962 |
| 908 layer->fNext = fMCRec->fTopLayer; | 963 layer->fNext = fMCRec->fTopLayer; |
| 909 fMCRec->fLayer = layer; | 964 fMCRec->fLayer = layer; |
| 910 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 965 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
| 911 | 966 |
| (...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2490 } | 2545 } |
| 2491 | 2546 |
| 2492 if (matrix) { | 2547 if (matrix) { |
| 2493 canvas->concat(*matrix); | 2548 canvas->concat(*matrix); |
| 2494 } | 2549 } |
| 2495 } | 2550 } |
| 2496 | 2551 |
| 2497 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2552 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2498 fCanvas->restoreToCount(fSaveCount); | 2553 fCanvas->restoreToCount(fSaveCount); |
| 2499 } | 2554 } |
| OLD | NEW |