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

Unified Diff: src/core/SkCanvas.cpp

Issue 551463004: introduce Props to surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: un-plumb props into device (not needed) Created 6 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 side-by-side diff with in-line comments
Download patch
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() {

Powered by Google App Engine
This is Rietveld 408576698