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

Unified Diff: ui/gfx/canvas.cc

Issue 12257016: (Not ready for review!) Toolbar and views high dpi support. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleaned up more useless diffs. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/gfx/canvas_paint_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas.cc
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index 4b4a0f47e3bdc7a3b8a49b00cc85facf19bebb89..437c8f5e0723c51c90a04f9a5e64dad92104d475 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
+#include "ui/base/win/dpi.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
#include "ui/gfx/rect.h"
@@ -57,8 +58,19 @@ Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque)
DrawImageInt(gfx::ImageSkia(image_rep), 0, 0);
}
+ui::ScaleFactor GetScaleFactor() {
+#if defined(ENABLE_HIDPI)
+ float scale = ui::GetDPIScale();
+ if (scale > 1.6)
+ return ui::SCALE_FACTOR_180P;
+ else if (scale > 1.2)
+ return ui::SCALE_FACTOR_140P;
+#endif
+ return ui::SCALE_FACTOR_100P;
+}
+
Canvas::Canvas()
- : scale_factor_(ui::SCALE_FACTOR_100P),
+ : scale_factor_(GetScaleFactor()),
owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))),
canvas_(owned_canvas_.get()) {
}
@@ -83,6 +95,7 @@ void Canvas::RecreateBackingCanvas(const gfx::Size& size,
is_opaque));
canvas_ = owned_canvas_.get();
SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
+ scale = 1;
canvas_->scale(scale, scale);
}
@@ -194,9 +207,17 @@ void Canvas::Translate(const gfx::Vector2d& offset) {
canvas_->translate(SkIntToScalar(offset.x()), SkIntToScalar(offset.y()));
}
+#include "/gtools.h"
+#if defined(ENABLE_HIDPI)
+void Canvas::Scale(double x_scale, double y_scale) {
+ canvas_->scale(x_scale, y_scale);
+// Debug(L"Scaling %p to %f", this, x_scale);
+}
+#else
void Canvas::Scale(int x_scale, int y_scale) {
canvas_->scale(SkIntToScalar(x_scale), SkIntToScalar(y_scale));
}
+#endif
void Canvas::DrawColor(SkColor color) {
DrawColor(color, SkXfermode::kSrcOver_Mode);
@@ -306,11 +327,11 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image,
float bitmap_scale = image_rep.GetScale();
canvas_->save();
- canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
- SkFloatToScalar(1.0f / bitmap_scale));
+// canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
+// SkFloatToScalar(1.0f / bitmap_scale));
canvas_->drawBitmap(bitmap,
- SkFloatToScalar(x * bitmap_scale),
- SkFloatToScalar(y * bitmap_scale),
+ SkFloatToScalar(x),// * bitmap_scale),
+ SkFloatToScalar(y),// * bitmap_scale),
&paint);
canvas_->restore();
}
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/gfx/canvas_paint_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698