Chromium Code Reviews| Index: src/core/SkCanvas.cpp |
| diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
| index 62d60da178bd790582acdf5aba3c7db92791e0bb..1e2bab777bef81c29e2fc8c99595bd527b608f8c 100644 |
| --- a/src/core/SkCanvas.cpp |
| +++ b/src/core/SkCanvas.cpp |
| @@ -67,6 +67,36 @@ void SkCanvas::predrawNotify() { |
| /////////////////////////////////////////////////////////////////////////////// |
| +static bool disable_lcd(const SkSurfaceProps& props) { |
| + return kUnknown_SkPixelGeometry == props.fPixelGeometry; |
| +} |
| + |
| +static bool disable_lcd(const SkPaint& paint) { |
| + return paint.getRasterizer() || paint.getPathEffect() || paint.isFakeBoldText() || |
|
robertphillips
2014/09/16 14:15:18
Tab these two lines over?
reed1
2014/09/16 18:16:01
Done.
|
| + paint.getStyle() != SkPaint::kFill_Style || |
| + !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode); |
| +} |
| + |
| +void apply_props_to_paint(const SkSurfaceProps& props, SkPaint* paint) { |
| + uint32_t clearMask = 0; |
| + |
| + if (paint->isDither() && (props.fDisallowFlags & SkSurfaceProps::kDither_DisallowFlag)) { |
| + clearMask |= SkPaint::kDither_Flag; |
| + } |
| + if (paint->isAntiAlias()) { |
| + if (props.fDisallowFlags & SkSurfaceProps::kAntiAlias_DisallowFlag) { |
| + clearMask |= SkPaint::kAntiAlias_Flag; |
| + } else if (paint->isLCDRenderText() && (disable_lcd(props) || disable_lcd(*paint))) { |
| + clearMask |= SkPaint::kLCDRenderText_Flag; |
| + } |
| + } |
| + if (clearMask) { |
| + paint->setFlags(paint->getFlags() & ~clearMask); |
| + } |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
| /* This is the record we keep for each SkBaseDevice that the user installs. |
| The clip/matrix/proc are fields that reflect the top of the save/restore |
| stack. Whenever the canvas changes, it marks a dirty flag, and then before |
| @@ -250,9 +280,9 @@ private: |
| class AutoDrawLooper { |
| public: |
| - AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, |
| + AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint, |
| bool skipLayerForImageFilter = false, |
| - const SkRect* bounds = NULL) : fOrigPaint(paint) { |
| + const SkRect* bounds = NULL) : fProps(props), fOrigPaint(paint) { |
| fCanvas = canvas; |
| fFilter = canvas->getDrawFilter(); |
| fPaint = NULL; |
| @@ -309,6 +339,7 @@ public: |
| private: |
| SkLazyPaint fLazyPaint; |
| SkCanvas* fCanvas; |
| + const SkSurfaceProps& fProps; |
| const SkPaint& fOrigPaint; |
| SkDrawFilter* fFilter; |
| const SkPaint* fPaint; |
| @@ -332,6 +363,7 @@ bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
| if (fDoClearImageFilter) { |
| paint->setImageFilter(NULL); |
| } |
| + apply_props_to_paint(fProps, paint); |
| if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
| fDone = true; |
| @@ -368,13 +400,13 @@ bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
| #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
| this->predrawNotify(); \ |
| - AutoDrawLooper looper(this, paint, true); \ |
| + AutoDrawLooper looper(this, fProps, paint, true); \ |
| while (looper.next(type)) { \ |
| SkDrawIter iter(this); |
| #define LOOPER_BEGIN(paint, type, bounds) \ |
| this->predrawNotify(); \ |
| - AutoDrawLooper looper(this, paint, false, bounds); \ |
| + AutoDrawLooper looper(this, fProps, paint, false, bounds); \ |
| while (looper.next(type)) { \ |
| SkDrawIter iter(this); |
| @@ -468,12 +500,14 @@ SkCanvas::SkCanvas(SkBaseDevice* device) |
| this->init(device, kDefault_InitFlags); |
| } |
| -SkCanvas::SkCanvas(const SkBitmap& bitmap) |
| +SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps* props) |
| : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
| + , fProps(props ? *props : SkSurfaceProps()) |
| { |
| inc_canvas(); |
| - this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)), kDefault_InitFlags)->unref(); |
| + SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); |
| + this->init(device, kDefault_InitFlags); |
| } |
| SkCanvas::~SkCanvas() { |