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

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

Issue 926843003: Move canvas->surface association to the device subclasses (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-03-sksurface-set-root-device-simple
Patch Set: Created 5 years, 10 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 | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkPictureRecord.h » ('j') | 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #define inc_layer() 71 #define inc_layer()
72 #define dec_layer() 72 #define dec_layer()
73 #define inc_rec() 73 #define inc_rec()
74 #define dec_rec() 74 #define dec_rec()
75 #define inc_canvas() 75 #define inc_canvas()
76 #define dec_canvas() 76 #define dec_canvas()
77 #endif 77 #endif
78 78
79 typedef SkTLazy<SkPaint> SkLazyPaint; 79 typedef SkTLazy<SkPaint> SkLazyPaint;
80 80
81 void SkCanvas::predrawNotify() {
82 if (fSurfaceBase) {
83 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode);
84 }
85 }
86
87 /////////////////////////////////////////////////////////////////////////////// 81 ///////////////////////////////////////////////////////////////////////////////
88 82
89 static uint32_t filter_paint_flags(const SkSurfaceProps& props, uint32_t flags) { 83 static uint32_t filter_paint_flags(const SkSurfaceProps& props, uint32_t flags) {
90 const uint32_t propFlags = props.flags(); 84 const uint32_t propFlags = props.flags();
91 if (propFlags & SkSurfaceProps::kDisallowDither_Flag) { 85 if (propFlags & SkSurfaceProps::kDisallowDither_Flag) {
92 flags &= ~SkPaint::kDither_Flag; 86 flags &= ~SkPaint::kDither_Flag;
93 } 87 }
94 if (propFlags & SkSurfaceProps::kDisallowAntiAlias_Flag) { 88 if (propFlags & SkSurfaceProps::kDisallowAntiAlias_Flag) {
95 flags &= ~SkPaint::kAntiAlias_Flag; 89 flags &= ~SkPaint::kAntiAlias_Flag;
96 } 90 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (fPaint->nothingToDraw()) { 396 if (fPaint->nothingToDraw()) {
403 fPaint = NULL; 397 fPaint = NULL;
404 return false; 398 return false;
405 } 399 }
406 return true; 400 return true;
407 } 401 }
408 402
409 ////////// macros to place around the internal draw calls ////////////////// 403 ////////// macros to place around the internal draw calls //////////////////
410 404
411 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ 405 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \
412 this->predrawNotify(); \
413 AutoDrawLooper looper(this, fProps, paint, true); \ 406 AutoDrawLooper looper(this, fProps, paint, true); \
414 while (looper.next(type)) { \ 407 while (looper.next(type)) { \
415 SkDrawIter iter(this); 408 SkDrawIter iter(this);
416 409
417 #define LOOPER_BEGIN(paint, type, bounds) \ 410 #define LOOPER_BEGIN(paint, type, bounds) \
418 this->predrawNotify(); \
419 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ 411 AutoDrawLooper looper(this, fProps, paint, false, bounds); \
420 while (looper.next(type)) { \ 412 while (looper.next(type)) { \
421 SkDrawIter iter(this); 413 SkDrawIter iter(this);
422 414
423 #define LOOPER_END } 415 #define LOOPER_END }
424 416
425 //////////////////////////////////////////////////////////////////////////// 417 ////////////////////////////////////////////////////////////////////////////
426 418
427 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 419 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
428 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; 420 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ;
429 fCachedLocalClipBounds.setEmpty(); 421 fCachedLocalClipBounds.setEmpty();
430 fCachedLocalClipBoundsDirty = true; 422 fCachedLocalClipBoundsDirty = true;
431 fAllowSoftClip = true; 423 fAllowSoftClip = true;
432 fAllowSimplifyClip = false; 424 fAllowSimplifyClip = false;
433 fDeviceCMDirty = true; 425 fDeviceCMDirty = true;
434 fSaveCount = 1; 426 fSaveCount = 1;
435 fMetaData = NULL; 427 fMetaData = NULL;
436 428
437 fMCRec = (MCRec*)fMCStack.push_back(); 429 fMCRec = (MCRec*)fMCStack.push_back();
438 new (fMCRec) MCRec(fConservativeRasterClip); 430 new (fMCRec) MCRec(fConservativeRasterClip);
439 431
440 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); 432 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip));
441 fMCRec->fTopLayer = fMCRec->fLayer; 433 fMCRec->fTopLayer = fMCRec->fLayer;
442 434
443 fSurfaceBase = NULL;
444
445 fClipStack.reset(SkNEW(SkClipStack)); 435 fClipStack.reset(SkNEW(SkClipStack));
446 436
447 if (device) { 437 if (device) {
448 device->initForRootLayer(fProps.pixelGeometry()); 438 device->initForRootLayer(fProps.pixelGeometry());
449 if (device->forceConservativeRasterClip()) { 439 if (device->forceConservativeRasterClip()) {
450 fConservativeRasterClip = true; 440 fConservativeRasterClip = true;
451 } 441 }
452 device->onAttachToCanvas(this); 442 device->onAttachToCanvas(this);
453 fMCRec->fLayer->fDevice = SkRef(device); 443 fMCRec->fLayer->fDevice = SkRef(device);
454 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); 444 fMCRec->fRasterClip.setRect(device->getGlobalBounds());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // if x or y are negative, then we have to adjust pixels 700 // if x or y are negative, then we have to adjust pixels
711 if (x > 0) { 701 if (x > 0) {
712 x = 0; 702 x = 0;
713 } 703 }
714 if (y > 0) { 704 if (y > 0) {
715 y = 0; 705 y = 0;
716 } 706 }
717 // here x,y are either 0 or negative 707 // here x,y are either 0 or negative
718 pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel()); 708 pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel());
719 709
720 // Tell our owning surface to bump its generation ID
721 this->predrawNotify();
722
723 // The device can assert that the requested area is always contained in its bounds 710 // The device can assert that the requested area is always contained in its bounds
724 return device->writePixels(info, pixels, rowBytes, target.x(), target.y()); 711 return device->writePixels(info, pixels, rowBytes, target.x(), target.y());
725 } 712 }
726 713
727 SkCanvas* SkCanvas::canvasForDrawIter() { 714 SkCanvas* SkCanvas::canvasForDrawIter() {
728 return this; 715 return this;
729 } 716 }
730 717
731 ////////////////////////////////////////////////////////////////////////////// 718 //////////////////////////////////////////////////////////////////////////////
732 719
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 1645
1659 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai nt* paint) { 1646 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai nt* paint) {
1660 this->onDrawSprite(bitmap, left, top, paint); 1647 this->onDrawSprite(bitmap, left, top, paint);
1661 } 1648 }
1662 1649
1663 ////////////////////////////////////////////////////////////////////////////// 1650 //////////////////////////////////////////////////////////////////////////////
1664 // These are the virtual drawing methods 1651 // These are the virtual drawing methods
1665 ////////////////////////////////////////////////////////////////////////////// 1652 //////////////////////////////////////////////////////////////////////////////
1666 1653
1667 void SkCanvas::onDiscard() { 1654 void SkCanvas::onDiscard() {
1668 if (fSurfaceBase) { 1655 if (this->getDevice()) {
1669 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); 1656 this->getDevice()->discard();
1670 } 1657 }
1671 } 1658 }
1672 1659
1673 void SkCanvas::onDrawPaint(const SkPaint& paint) { 1660 void SkCanvas::onDrawPaint(const SkPaint& paint) {
1674 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPaint()"); 1661 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPaint()");
1675 this->internalDrawPaint(paint); 1662 this->internalDrawPaint(paint);
1676 } 1663 }
1677 1664
1678 void SkCanvas::internalDrawPaint(const SkPaint& paint) { 1665 void SkCanvas::internalDrawPaint(const SkPaint& paint) {
1679 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) 1666 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL)
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 } 2498 }
2512 2499
2513 if (matrix) { 2500 if (matrix) {
2514 canvas->concat(*matrix); 2501 canvas->concat(*matrix);
2515 } 2502 }
2516 } 2503 }
2517 2504
2518 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2505 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2519 fCanvas->restoreToCount(fSaveCount); 2506 fCanvas->restoreToCount(fSaveCount);
2520 } 2507 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkPictureRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698