summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-08 19:16:59 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-08 19:16:59 +0000
commitcd9a61c70012ba2d7062f861d9ae3fe4b831f277 (patch)
tree36ec4f771194c94f290fb433e462fce602ffcb8d
parent9bdadea89eed1e2b85b0b89df4b5a744ee933920 (diff)
downloadchromium_src-cd9a61c70012ba2d7062f861d9ae3fe4b831f277.zip
chromium_src-cd9a61c70012ba2d7062f861d9ae3fe4b831f277.tar.gz
chromium_src-cd9a61c70012ba2d7062f861d9ae3fe4b831f277.tar.bz2
Move DIP translation from ui/aura to ui/compositor.
Layer's coordinate system is now in DIP. Added support of dynamic density switching. Removed ENABLE_DIP gyp/macro and added runtime flag "--ui-enable-dip" BUG=105165, 114666 TEST=enabled monitor test. added new tests to compositor_unittests Review URL: https://chromiumcodereview.appspot.com/10221028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135888 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/accelerators/accelerator_controller.cc7
-rw-r--r--ash/accelerators/accelerator_table.cc5
-rw-r--r--ash/accelerators/accelerator_table.h5
-rw-r--r--ash/dip_unittest.cc65
-rw-r--r--ash/monitor/multi_monitor_manager.cc22
-rw-r--r--ash/monitor/multi_monitor_manager.h2
-rw-r--r--ash/wm/image_grid.cc35
-rw-r--r--ash/wm/image_grid.h11
-rw-r--r--ash/wm/image_grid_unittest.cc12
-rw-r--r--ash/wm/resize_shadow.cc2
-rw-r--r--ash/wm/shadow.cc4
-rw-r--r--ash/wm/shadow.h10
-rw-r--r--ash/wm/shadow_controller.cc3
-rw-r--r--ash/wm/shelf_layout_manager.cc11
-rw-r--r--ash/wm/window_animations.cc14
-rw-r--r--build/common.gypi9
-rw-r--r--chrome/browser/ui/views/ash/window_positioner.cc8
-rw-r--r--chrome/browser/ui/window_snapshot/window_snapshot_aura.cc3
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/dip_util.cc84
-rw-r--r--ui/aura/dip_util.h41
-rw-r--r--ui/aura/root_window.cc103
-rw-r--r--ui/aura/root_window.h7
-rw-r--r--ui/aura/window.cc37
-rw-r--r--ui/aura/window.h6
-rw-r--r--ui/compositor/compositor.cc45
-rw-r--r--ui/compositor/compositor.gyp2
-rw-r--r--ui/compositor/compositor.h26
-rw-r--r--ui/compositor/compositor_switches.cc3
-rw-r--r--ui/compositor/compositor_switches.h1
-rw-r--r--ui/compositor/dip_util.cc101
-rw-r--r--ui/compositor/dip_util.h64
-rw-r--r--ui/compositor/layer.cc74
-rw-r--r--ui/compositor/layer.h23
-rw-r--r--ui/compositor/layer_unittest.cc168
-rw-r--r--ui/compositor/test/test_compositor_host_linux.cc3
-rw-r--r--ui/compositor/test/test_compositor_host_win.cc3
-rw-r--r--ui/gfx/insets_f.h4
-rw-r--r--ui/gfx/monitor.cc4
-rw-r--r--ui/gfx/monitor.h7
-rw-r--r--ui/gfx/monitor_unittest.cc2
-rw-r--r--ui/gfx/path.cc2
-rw-r--r--ui/gfx/path.h4
-rw-r--r--ui/gfx/point_f.h4
-rw-r--r--ui/gfx/rect_f.h4
-rw-r--r--ui/gfx/size_f.h4
-rw-r--r--ui/ui.gyp12
-rw-r--r--ui/views/view.cc43
48 files changed, 631 insertions, 480 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index f8782ea..b6ce065 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -513,12 +513,15 @@ bool AcceleratorController::AcceleratorPressed(
return HandlePrintLayerHierarchy();
case PRINT_WINDOW_HIERARCHY:
return HandlePrintWindowHierarchy();
- case ADD_REMOVE_MONITOR:
+ case MONITOR_ADD_REMOVE:
internal::MultiMonitorManager::AddRemoveMonitor();
return true;
- case CYCLE_MONITOR:
+ case MONITOR_CYCLE:
internal::MultiMonitorManager::CycleMonitor();
return true;
+ case MONITOR_TOGGLE_SCALE:
+ internal::MultiMonitorManager::ToggleMonitorScale();
+ return true;
#endif
default:
NOTREACHED() << "Unhandled action " << it->second;
diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc
index 0b7093a..08d47f2 100644
--- a/ash/accelerators/accelerator_table.cc
+++ b/ash/accelerators/accelerator_table.cc
@@ -104,8 +104,9 @@ const AcceleratorData kAcceleratorData[] = {
// For testing on systems where Alt-Tab is already mapped.
{ true, ui::VKEY_W, false, false, true, CYCLE_FORWARD_MRU },
{ true, ui::VKEY_W, true, false, true, CYCLE_BACKWARD_MRU },
- { true, ui::VKEY_F4, false, true, false, ADD_REMOVE_MONITOR },
- { true, ui::VKEY_F4, true, true, false, CYCLE_MONITOR },
+ { true, ui::VKEY_F4, false, true, false, MONITOR_ADD_REMOVE },
+ { true, ui::VKEY_F4, true, true, false, MONITOR_CYCLE },
+ { true, ui::VKEY_HOME, true, true, false, MONITOR_TOGGLE_SCALE },
#endif
// trigger_on_press, KeyboardCode, shift, control, alt, AcceleratorAction
};
diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h
index 12d94c1..08ef43a 100644
--- a/ash/accelerators/accelerator_table.h
+++ b/ash/accelerators/accelerator_table.h
@@ -59,8 +59,9 @@ enum AcceleratorAction {
OPEN_FILE_MANAGER,
#endif
#if !defined(NDEBUG)
- ADD_REMOVE_MONITOR,
- CYCLE_MONITOR,
+ MONITOR_ADD_REMOVE,
+ MONITOR_CYCLE,
+ MONITOR_TOGGLE_SCALE,
PRINT_LAYER_HIERARCHY,
PRINT_WINDOW_HIERARCHY,
ROTATE_SCREEN,
diff --git a/ash/dip_unittest.cc b/ash/dip_unittest.cc
index 7d57a0e..16335b3 100644
--- a/ash/dip_unittest.cc
+++ b/ash/dip_unittest.cc
@@ -17,80 +17,55 @@
#include "ui/aura/client/activation_client.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/monitor.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
-#if defined(ENABLE_DIP)
-#define MAYBE_Shadow FAILS_Shadow
-#define MAYBE_WorkArea FAILS_WorkArea
-#else
-#define MAYBE_Shadow DISABLED_Shadow
-#define MAYBE_WorkArea DISABLED_WorkArea
-#endif
-
namespace ash {
typedef ash::test::AshTestBase DIPTest;
-// Test if the shadow works correctly under different density
-TEST_F(DIPTest, MAYBE_Shadow) {
- const gfx::Rect kBoundsInDIP(20, 30, 400, 300);
-
- scoped_ptr<aura::Window> window(new aura::Window(NULL));
- window->SetType(aura::client::WINDOW_TYPE_NORMAL);
- window->Init(ui::LAYER_TEXTURED);
- window->SetParent(NULL);
- window->SetBounds(kBoundsInDIP);
-
- internal::ShadowController::TestApi api(
- Shell::GetInstance()->shadow_controller());
- const internal::Shadow* shadow = api.GetShadowForWindow(window.get());
- window->Show();
-
- const gfx::Rect layer_bounds_copy = shadow->layer()->bounds();
- window.reset();
-
- ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 1000, 1000));
-
- window.reset(new aura::Window(NULL));
- window->SetType(aura::client::WINDOW_TYPE_NORMAL);
- window->Init(ui::LAYER_TEXTURED);
- window->SetParent(NULL);
- window->SetBounds(kBoundsInDIP);
- shadow = api.GetShadowForWindow(window.get());
- window->Show();
- EXPECT_EQ("40,60 800x600", window->GetBoundsInPixel().ToString());
- EXPECT_EQ(layer_bounds_copy.Scale(2.0f).ToString(),
- shadow->layer()->bounds().ToString());
-}
+#if defined(OS_WIN)
+// Windows/Aura doesn't have DIP support in monitor yet.
+#define MAYBE_WorkArea DISABLED_WorkArea
+#else
+#define MAYBE_WorkArea WorkArea
+#endif
// Test if the WM sets correct work area under different density.
TEST_F(DIPTest, MAYBE_WorkArea) {
+ ui::test::ScopedDIPEnablerForTest enable;
ChangeMonitorConfig(1.0f, gfx::Rect(0, 0, 1000, 900));
aura::RootWindow* root = Shell::GetRootWindow();
const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(root);
EXPECT_EQ("0,0 1000x900", monitor.bounds().ToString());
- const gfx::Rect work_area = monitor.work_area();
- const gfx::Insets insets = monitor.bounds().InsetsFrom(work_area);
- EXPECT_EQ("0,0,48,0", insets.ToString());
+ gfx::Rect work_area = monitor.work_area();
+ EXPECT_EQ("0,0 1000x852", work_area.ToString());
+ EXPECT_EQ("0,0,48,0", monitor.bounds().InsetsFrom(work_area).ToString());
ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 2000, 1800));
const gfx::Monitor monitor_2x = gfx::Screen::GetMonitorNearestWindow(root);
+ // The |bounds_in_pixel()| should report bounds in pixel coordinate.
EXPECT_EQ("0,0 2000x1800", monitor_2x.bounds_in_pixel().ToString());
- EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString());
- EXPECT_EQ(work_area.ToString(), monitor_2x.work_area().ToString());
+ // Aura and views coordinates are in DIP, so they their bounds do not change.
+ EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString());
+ work_area = monitor_2x.work_area();
+ EXPECT_EQ("0,0 1000x852", work_area.ToString());
+ EXPECT_EQ("0,0,48,0", monitor_2x.bounds().InsetsFrom(work_area).ToString());
+ // Sanity check if the workarea's inset hight is same as
+ // the launcher's height.
Launcher* launcher = Shell::GetInstance()->launcher();
EXPECT_EQ(
- monitor_2x.bounds().InsetsFrom(work_area).height() * 2,
+ monitor_2x.bounds().InsetsFrom(work_area).height(),
launcher->widget()->GetNativeView()->layer()->bounds().height());
}
diff --git a/ash/monitor/multi_monitor_manager.cc b/ash/monitor/multi_monitor_manager.cc
index 874f224..e7ace37 100644
--- a/ash/monitor/multi_monitor_manager.cc
+++ b/ash/monitor/multi_monitor_manager.cc
@@ -57,6 +57,12 @@ void MultiMonitorManager::CycleMonitor() {
manager->CycleMonitorImpl();
}
+ void MultiMonitorManager::ToggleMonitorScale() {
+ MultiMonitorManager* manager = static_cast<MultiMonitorManager*>(
+ aura::Env::GetInstance()->monitor_manager());
+ manager->ScaleMonitorImpl();
+}
+
void MultiMonitorManager::OnNativeMonitorsChanged(
const std::vector<Monitor>& new_monitors) {
size_t min = std::min(monitors_.size(), new_monitors.size());
@@ -204,6 +210,22 @@ void MultiMonitorManager::CycleMonitorImpl() {
}
}
+void MultiMonitorManager::ScaleMonitorImpl() {
+ if (monitors_.size() > 0) {
+ std::vector<Monitor> new_monitors;
+ for (Monitors::const_iterator iter = monitors_.begin();
+ iter != monitors_.end(); ++iter) {
+ gfx::Monitor monitor = *iter;
+ float factor = monitor.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
+ monitor.SetScaleAndBounds(
+ factor, gfx::Rect(monitor.bounds_in_pixel().origin(),
+ monitor.size().Scale(factor)));
+ new_monitors.push_back(monitor);
+ }
+ OnNativeMonitorsChanged(new_monitors);
+ }
+}
+
gfx::Monitor& MultiMonitorManager::FindMonitorById(int id) {
for (Monitors::iterator iter = monitors_.begin();
iter != monitors_.end(); ++iter) {
diff --git a/ash/monitor/multi_monitor_manager.h b/ash/monitor/multi_monitor_manager.h
index 6ecd8a7..3d8a76b 100644
--- a/ash/monitor/multi_monitor_manager.h
+++ b/ash/monitor/multi_monitor_manager.h
@@ -37,6 +37,7 @@ class ASH_EXPORT MultiMonitorManager : public aura::MonitorManager,
// of on a device.
static void AddRemoveMonitor();
static void CycleMonitor();
+ static void ToggleMonitorScale();
bool UpdateWorkAreaOfMonitorNearestWindow(const aura::Window* window,
const gfx::Insets& insets);
@@ -64,6 +65,7 @@ class ASH_EXPORT MultiMonitorManager : public aura::MonitorManager,
void Init();
void AddRemoveMonitorImpl();
void CycleMonitorImpl();
+ void ScaleMonitorImpl();
gfx::Monitor& FindMonitorById(int id);
Monitors monitors_;
diff --git a/ash/wm/image_grid.cc b/ash/wm/image_grid.cc
index 2edb3f5..c9c982f 100644
--- a/ash/wm/image_grid.cc
+++ b/ash/wm/image_grid.cc
@@ -6,7 +6,6 @@
#include <algorithm>
-#include "ui/aura/dip_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
@@ -27,9 +26,8 @@ gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds(
return bounds;
}
-ImageGrid::ImageGrid(aura::Window* window)
- : window_(window),
- layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
+ImageGrid::ImageGrid()
+ : layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
top_image_height_(0),
bottom_image_height_(0),
left_image_width_(0),
@@ -130,7 +128,7 @@ void ImageGrid::SetSize(const gfx::Size& size) {
if (center_height > 0) {
ui::Transform transform;
transform.SetScaleY(
- static_cast<float>(center_height) / left_layer_->bounds().height());
+ (static_cast<float>(center_height) / left_layer_->bounds().height()));
transform.ConcatTranslate(0, top);
left_layer_->SetTransform(transform);
}
@@ -206,21 +204,16 @@ void ImageGrid::SetSize(const gfx::Size& size) {
}
}
-void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds_in_dip) {
-#if defined(ENABLE_DIP)
- // TODO(oshma): Scale the size of the shadow.
- const gfx::Rect content_bounds =
- aura::ConvertRectToPixel(window_, content_bounds_in_dip);
-#else
- const gfx::Rect& content_bounds = content_bounds_in_dip;
-#endif
+void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds) {
SetSize(gfx::Size(
content_bounds.width() + left_image_width_ + right_image_width_,
- content_bounds.height() + top_image_height_ + bottom_image_height_));
- layer_->SetBounds(gfx::Rect(content_bounds.x() - left_image_width_,
- content_bounds.y() - top_image_height_,
- layer_->bounds().width(),
- layer_->bounds().height()));
+ content_bounds.height() + top_image_height_ +
+ bottom_image_height_));
+ layer_->SetBounds(
+ gfx::Rect(content_bounds.x() - left_image_width_,
+ content_bounds.y() - top_image_height_,
+ layer_->bounds().width(),
+ layer_->bounds().height()));
}
void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect,
@@ -267,13 +260,7 @@ void ImageGrid::SetImage(const gfx::Image* image,
// Set up the new layer and painter.
layer_ptr->reset(new ui::Layer(ui::LAYER_TEXTURED));
-#if defined(ENABLE_DIP)
- const gfx::Size size =
- aura::ConvertSizeToPixel(window_, GetImageSize(image));
-#else
const gfx::Size size = GetImageSize(image);
-#endif
-
layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height()));
painter_ptr->reset(new ImagePainter(image));
diff --git a/ash/wm/image_grid.h b/ash/wm/image_grid.h
index 7b53f88..37fc37c 100644
--- a/ash/wm/image_grid.h
+++ b/ash/wm/image_grid.h
@@ -15,10 +15,6 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
-namespace aura {
-class Window;
-} // namespace aura
-
namespace gfx {
class Image;
} // namespace gfx
@@ -91,7 +87,7 @@ class ASH_EXPORT ImageGrid {
DISALLOW_COPY_AND_ASSIGN(TestAPI);
};
- explicit ImageGrid(aura::Window* window);
+ ImageGrid();
~ImageGrid();
ui::Layer* layer() { return layer_.get(); }
@@ -167,11 +163,6 @@ class ASH_EXPORT ImageGrid {
scoped_ptr<ui::Layer>* layer_ptr,
scoped_ptr<ImagePainter>* painter_ptr);
- // A possibly-arbitrary window that is drawn at the same DPI
- // (i.e. on the same monitor) as this grid.
- // TODO(oshima): move scale factor to ui/compositor/ and remove this.
- aura::Window* window_;
-
// Layer that contains all of the image layers.
scoped_ptr<ui::Layer> layer_;
diff --git a/ash/wm/image_grid_unittest.cc b/ash/wm/image_grid_unittest.cc
index bb31c31..715ddb9 100644
--- a/ash/wm/image_grid_unittest.cc
+++ b/ash/wm/image_grid_unittest.cc
@@ -37,7 +37,7 @@ TEST_F(ImageGridTest, Basic) {
scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1)));
scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(),
image_Bx1.get(), image_1x1.get(), image_Bx1.get(),
image_BxB.get(), image_1xB.get(), image_BxB.get());
@@ -129,7 +129,7 @@ TEST_F(ImageGridTest, SetContentBounds) {
scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1)));
scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(image_BxB.get(), image_1xB.get(), image_BxB.get(),
image_Bx1.get(), image_1x1.get(), image_Bx1.get(),
image_BxB.get(), image_1xB.get(), image_BxB.get());
@@ -154,7 +154,7 @@ TEST_F(ImageGridTest, SingleImage) {
const int kBorder = 1;
scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(NULL, image.get(), NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
@@ -186,7 +186,7 @@ TEST_F(ImageGridTest, ResetImages) {
const int kBorder = 1;
scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(NULL, image.get(), NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
@@ -234,7 +234,7 @@ TEST_F(ImageGridTest, SmallerSides) {
scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge)));
scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(top_left_image.get(), top_image.get(), top_right_image.get(),
left_image.get(), NULL, right_image.get(),
NULL, NULL, NULL);
@@ -287,7 +287,7 @@ TEST_F(ImageGridTest, TooSmall) {
scoped_ptr<gfx::Image> bottom_right_image(
CreateImage(gfx::Size(kCorner, kCorner)));
- ImageGrid grid(NULL);
+ ImageGrid grid;
grid.SetImages(
top_left_image.get(), top_image.get(), top_right_image.get(),
left_image.get(), center_image.get(), right_image.get(),
diff --git a/ash/wm/resize_shadow.cc b/ash/wm/resize_shadow.cc
index a9e0298..805783f 100644
--- a/ash/wm/resize_shadow.cc
+++ b/ash/wm/resize_shadow.cc
@@ -49,7 +49,7 @@ ResizeShadow::~ResizeShadow() {}
void ResizeShadow::Init(aura::Window* window) {
// Set up our image grid and images.
ResourceBundle& res = ResourceBundle::GetSharedInstance();
- image_grid_.reset(new ImageGrid(window));
+ image_grid_.reset(new ImageGrid);
image_grid_->SetImages(
&res.GetImageNamed(IDR_AURA_RESIZE_SHADOW_TOP_LEFT),
&res.GetImageNamed(IDR_AURA_RESIZE_SHADOW_TOP),
diff --git a/ash/wm/shadow.cc b/ash/wm/shadow.cc
index 49e9788..7cd2fea 100644
--- a/ash/wm/shadow.cc
+++ b/ash/wm/shadow.cc
@@ -44,9 +44,9 @@ Shadow::Shadow() : style_(STYLE_ACTIVE) {
Shadow::~Shadow() {
}
-void Shadow::Init(aura::Window* window, Style style) {
+void Shadow::Init(Style style) {
style_ = style;
- image_grid_.reset(new ImageGrid(window));
+ image_grid_.reset(new ImageGrid);
UpdateImagesForStyle();
image_grid_->layer()->set_name("Shadow");
image_grid_->layer()->SetOpacity(GetOpacityForStyle(style_));
diff --git a/ash/wm/shadow.h b/ash/wm/shadow.h
index a137085..11ac6f3 100644
--- a/ash/wm/shadow.h
+++ b/ash/wm/shadow.h
@@ -12,10 +12,6 @@
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/rect.h"
-namespace aura {
-class Window;
-} // namespace aura
-
namespace ui {
class Layer;
} // namespace ui
@@ -44,11 +40,7 @@ class ASH_EXPORT Shadow : public ui::ImplicitAnimationObserver {
Shadow();
virtual ~Shadow();
- // |window| is a possibly-arbitrary window that is drawn at the same DPI
- // (i.e. on the same monitor) as this shadow. The actual bounds for the
- // shadow still has to be provided through |SetContentBounds()|.
- // TODO(oshima): move scale factor to ui/compositor/ and remove this.
- void Init(aura::Window* window, Style style);
+ void Init(Style style);
// Returns |image_grid_|'s ui::Layer. This is exposed so it can be added to
// the same layer as the content and stacked below it. SetContentBounds()
diff --git a/ash/wm/shadow_controller.cc b/ash/wm/shadow_controller.cc
index 04aa99f..2538630 100644
--- a/ash/wm/shadow_controller.cc
+++ b/ash/wm/shadow_controller.cc
@@ -162,8 +162,7 @@ void ShadowController::CreateShadowForWindow(aura::Window* window) {
linked_ptr<Shadow> shadow(new Shadow());
window_shadows_.insert(make_pair(window, shadow));
- shadow->Init(window,
- ShouldUseSmallShadowForWindow(window) ?
+ shadow->Init(ShouldUseSmallShadowForWindow(window) ?
Shadow::STYLE_SMALL : Shadow::STYLE_ACTIVE);
shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc
index 188449a..0d344fe 100644
--- a/ash/wm/shelf_layout_manager.cc
+++ b/ash/wm/shelf_layout_manager.cc
@@ -14,7 +14,6 @@
#include "base/auto_reset.h"
#include "base/i18n/rtl.h"
#include "ui/aura/client/activation_client.h"
-#include "ui/aura/dip_util.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/root_window.h"
@@ -37,11 +36,6 @@ ui::Layer* GetLayer(views::Widget* widget) {
return widget->GetNativeView()->layer();
}
-void SetLayerBounds(views::Widget* widget, const gfx::Rect& bounds) {
- aura::Window* window = widget->GetNativeView();
- window->layer()->SetBounds(aura::ConvertRectToPixel(window, bounds));
-}
-
} // namespace
// static
@@ -195,6 +189,7 @@ void ShelfLayoutManager::LayoutShelf() {
CalculateTargetBounds(state_, &target_bounds);
if (launcher_widget()) {
GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity);
+
launcher_widget()->SetBounds(target_bounds.launcher_bounds);
launcher_->SetStatusWidth(
target_bounds.status_bounds.width());
@@ -334,7 +329,7 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) {
launcher_animation_setter.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(130));
launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT);
- SetLayerBounds(launcher_widget(), target_bounds.launcher_bounds);
+ GetLayer(launcher_widget())->SetBounds(target_bounds.launcher_bounds);
GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity);
}
ui::ScopedLayerAnimationSettings status_animation_setter(
@@ -342,7 +337,7 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) {
status_animation_setter.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(130));
status_animation_setter.SetTweenType(ui::Tween::EASE_OUT);
- SetLayerBounds(status_, target_bounds.status_bounds);
+ GetLayer(status_)->SetBounds(target_bounds.status_bounds);
GetLayer(status_)->SetOpacity(target_bounds.opacity);
Shell::GetInstance()->SetMonitorWorkAreaInsets(
Shell::GetRootWindow(),
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index 15394ff..692af31 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -14,7 +14,6 @@
#include "base/stl_util.h"
#include "base/time.h"
#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/dip_util.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_property.h"
@@ -236,7 +235,7 @@ void AnimateShowWindow_Drop(aura::Window* window) {
ui::Transform transform;
transform.ConcatScale(kWindowAnimation_ScaleFactor,
kWindowAnimation_ScaleFactor);
- gfx::Rect bounds = window->GetBoundsInPixel();
+ gfx::Rect bounds = window->bounds();
transform.ConcatTranslate(
kWindowAnimation_TranslateFactor * bounds.width(),
kWindowAnimation_TranslateFactor * bounds.height());
@@ -247,7 +246,7 @@ void AnimateHideWindow_Drop(aura::Window* window) {
ui::Transform transform;
transform.ConcatScale(kWindowAnimation_ScaleFactor,
kWindowAnimation_ScaleFactor);
- gfx::Rect bounds = window->GetBoundsInPixel();
+ gfx::Rect bounds = window->bounds();
transform.ConcatTranslate(
kWindowAnimation_TranslateFactor * bounds.width(),
kWindowAnimation_TranslateFactor * bounds.height());
@@ -281,8 +280,8 @@ void AnimateHideWindow_Fade(aura::Window* window) {
ui::Transform BuildWorkspaceSwitchTransform(aura::Window* window) {
// Animations for transitioning workspaces scale all windows. To give the
// effect of scaling from the center of the screen the windows are translated.
- gfx::Rect bounds = window->GetBoundsInPixel();
- gfx::Rect parent_bounds(window->parent()->GetBoundsInPixel());
+ gfx::Rect bounds = window->bounds();
+ gfx::Rect parent_bounds(window->parent()->bounds());
float mid_x = static_cast<float>(parent_bounds.width()) / 2.0f;
float initial_x =
@@ -366,9 +365,8 @@ gfx::Rect GetMinimizeRectForWindow(aura::Window* window) {
void AddLayerAnimationsForMinimize(aura::Window* window, bool show) {
// Recalculate the transform at restore time since the launcher item may have
// moved while the window was minimized.
- gfx::Rect bounds = window->GetBoundsInPixel();
- gfx::Rect target_bounds =
- aura::ConvertRectToPixel(window, GetMinimizeRectForWindow(window));
+ gfx::Rect bounds = window->bounds();
+ gfx::Rect target_bounds = GetMinimizeRectForWindow(window);
float scale_x = static_cast<float>(target_bounds.height()) / bounds.width();
float scale_y = static_cast<float>(target_bounds.width()) / bounds.height();
diff --git a/build/common.gypi b/build/common.gypi
index 3bcdeef..398d0fd 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -29,9 +29,6 @@
# Whether or not we are building the Ash shell.
'use_ash%': 0,
- # Enable DIP (Density Independent Pixels) support.
- 'enable_dip%': 0,
-
# Use OpenSSL instead of NSS. Under development: see http://crbug.com/62803
'use_openssl%': 0,
@@ -55,7 +52,6 @@
'chromeos%': '<(chromeos)',
'use_aura%': '<(use_aura)',
'use_ash%': '<(use_ash)',
- 'enable_dip%': '<(enable_dip)',
'use_openssl%': '<(use_openssl)',
'use_virtual_keyboard%': '<(use_virtual_keyboard)',
'enable_viewport%': '<(enable_viewport)',
@@ -117,7 +113,6 @@
'toolkit_views%': '<(toolkit_views)',
'use_aura%': '<(use_aura)',
'use_ash%': '<(use_ash)',
- 'enable_dip%': '<(enable_dip)',
'use_openssl%': '<(use_openssl)',
'use_virtual_keyboard%': '<(use_virtual_keyboard)',
'enable_viewport%': '<(enable_viewport)',
@@ -503,7 +498,6 @@
'ui_compositor_image_transport%': '<(ui_compositor_image_transport)',
'use_aura%': '<(use_aura)',
'use_ash%': '<(use_ash)',
- 'enable_dip%': '<(enable_dip)',
'use_openssl%': '<(use_openssl)',
'use_nss%': '<(use_nss)',
'os_bsd%': '<(os_bsd)',
@@ -1256,9 +1250,6 @@
['use_ash==1', {
'defines': ['USE_ASH=1'],
}],
- ['enable_dip==1', {
- 'defines': ['ENABLE_DIP'],
- }],
['use_nss==1', {
'defines': ['USE_NSS=1'],
}],
diff --git a/chrome/browser/ui/views/ash/window_positioner.cc b/chrome/browser/ui/views/ash/window_positioner.cc
index ad6c4c6..f84dfe3 100644
--- a/chrome/browser/ui/views/ash/window_positioner.cc
+++ b/chrome/browser/ui/views/ash/window_positioner.cc
@@ -103,7 +103,7 @@ gfx::Rect WindowPositioner::SmartPopupPosition(
const std::vector<aura::Window*> windows =
ash::WindowCycleController::BuildWindowList();
- std::vector<gfx::Rect> regions;
+ std::vector<const gfx::Rect*> regions;
// Process the window list and check if we can bail immediately.
for (size_t i = 0; i < windows.size(); i++) {
// We only include opaque and visible windows.
@@ -115,7 +115,7 @@ gfx::Rect WindowPositioner::SmartPopupPosition(
ash::wm::IsWindowFullscreen(windows[i]))
return gfx::Rect(0, 0, 0, 0);
if (ash::wm::IsWindowNormal(windows[i]))
- regions.push_back(windows[i]->bounds());
+ regions.push_back(&windows[i]->bounds());
}
}
@@ -150,9 +150,9 @@ gfx::Rect WindowPositioner::SmartPopupPosition(
while (y + h <= work_area.height()) {
size_t i;
for (i = 0; i < regions.size(); i++) {
- if (regions[i].Intersects(gfx::Rect(x + work_area.x(),
+ if (regions[i]->Intersects(gfx::Rect(x + work_area.x(),
y + work_area.y(), w, h))) {
- y = regions[i].bottom() - work_area.y();
+ y = regions[i]->bottom() - work_area.y();
if (grid > 1) {
// Align to the (next) grid step.
y = ash::WindowResizer::AlignToGridRoundUp(y, grid);
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc
index aa84adc..fcc5f58 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc
@@ -8,6 +8,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/aura/window.h"
#include "ui/compositor/compositor.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/rect.h"
@@ -25,6 +26,8 @@ bool GrabWindowSnapshot(gfx::NativeWindow window,
// the desktop.
read_pixels_bounds.set_origin(
snapshot_bounds.origin().Add(window->bounds().origin()));
+ read_pixels_bounds =
+ ui::ConvertRectToPixel(window->layer(), read_pixels_bounds);
DCHECK_GE(compositor->size().width(), read_pixels_bounds.right());
DCHECK_GE(compositor->size().height(), read_pixels_bounds.bottom());
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index f7b3f8f..00e8054 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -63,8 +63,6 @@
'desktop/desktop_screen_x11.cc',
'desktop/desktop_stacking_client.cc',
'desktop/desktop_stacking_client.h',
- 'dip_util.cc',
- 'dip_util.h',
'dispatcher_linux.cc',
'dispatcher_linux.h',
'dispatcher_win.cc',
diff --git a/ui/aura/dip_util.cc b/ui/aura/dip_util.cc
deleted file mode 100644
index c17e0ed..0000000
--- a/ui/aura/dip_util.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/aura/dip_util.h"
-
-#include "ui/aura/env.h"
-#include "ui/aura/window.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/size.h"
-#include "ui/gfx/rect.h"
-
-#if defined(ENABLE_DIP)
-#include "ui/aura/monitor_manager.h"
-#include "ui/gfx/monitor.h"
-#endif
-
-namespace aura {
-#if defined(ENABLE_DIP)
-float GetMonitorScaleFactor(const Window* window) {
- gfx::Monitor monitor = aura::Env::GetInstance()->monitor_manager()->
- GetMonitorNearestWindow(window);
- return monitor.device_scale_factor();
-} // namespace
-#endif
-
-gfx::Point ConvertPointToDIP(const Window* window,
- const gfx::Point& point_in_pixel) {
-#if defined(ENABLE_DIP)
- return point_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
-#else
- return point_in_pixel;
-#endif
-}
-
-gfx::Size ConvertSizeToDIP(const Window* window,
- const gfx::Size& size_in_pixel) {
-#if defined(ENABLE_DIP)
- return size_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
-#else
- return size_in_pixel;
-#endif
-}
-
-gfx::Rect ConvertRectToDIP(const Window* window,
- const gfx::Rect& rect_in_pixel) {
-#if defined(ENABLE_DIP)
- float scale = 1.0f / GetMonitorScaleFactor(window);
- return gfx::Rect(rect_in_pixel.origin().Scale(scale),
- rect_in_pixel.size().Scale(scale));
-#else
- return rect_in_pixel;
-#endif
-}
-
-gfx::Point ConvertPointToPixel(const Window* window,
- const gfx::Point& point_in_dip) {
-#if defined(ENABLE_DIP)
- return point_in_dip.Scale(GetMonitorScaleFactor(window));
-#else
- return point_in_dip;
-#endif
-}
-
-gfx::Size ConvertSizeToPixel(const Window* window,
- const gfx::Size& size_in_dip) {
-#if defined(ENABLE_DIP)
- return size_in_dip.Scale(GetMonitorScaleFactor(window));
-#else
- return size_in_dip;
-#endif
-}
-
-gfx::Rect ConvertRectToPixel(const Window* window,
- const gfx::Rect& rect_in_dip) {
-#if defined(ENABLE_DIP)
- float scale = GetMonitorScaleFactor(window);
- return gfx::Rect(rect_in_dip.origin().Scale(scale),
- rect_in_dip.size().Scale(scale));
-#else
- return rect_in_dip;
-#endif
-}
-} // namespace aura
diff --git a/ui/aura/dip_util.h b/ui/aura/dip_util.h
deleted file mode 100644
index 4a5bfef..0000000
--- a/ui/aura/dip_util.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_AURA_DIP_UTIL_H_
-#define UI_AURA_DIP_UTIL_H_
-#pragma once
-
-#include "ui/aura/aura_export.h"
-
-namespace gfx {
-class Point;
-class Size;
-class Rect;
-} // namespace gfx
-
-namespace aura {
-class Window;
-
-#if defined(ENABLE_DIP)
-AURA_EXPORT float GetMonitorScaleFactor(const Window* window);
-#endif
-
-// Utility functions that convert point/size/rect between
-// DIP and pixel coordinates system.
-AURA_EXPORT gfx::Point ConvertPointToDIP(const Window* window,
- const gfx::Point& point_in_pixel);
-AURA_EXPORT gfx::Size ConvertSizeToDIP(const Window* window,
- const gfx::Size& size_in_pixel);
-AURA_EXPORT gfx::Rect ConvertRectToDIP(const Window* window,
- const gfx::Rect& rect_in_pixel);
-AURA_EXPORT gfx::Point ConvertPointToPixel(const Window* window,
- const gfx::Point& point_in_dip);
-AURA_EXPORT gfx::Size ConvertSizeToPixel(const Window* window,
- const gfx::Size& size_in_dip);
-AURA_EXPORT gfx::Rect ConvertRectToPixel(const Window* window,
- const gfx::Rect& rect_in_dip);
-
-} // namespace aura
-
-#endif // UI_AURA_DIP_UTIL_H_
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 3c67f34..4dfdc97 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -18,6 +18,7 @@
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
+#include "ui/aura/monitor_manager.h"
#include "ui/aura/root_window_host.h"
#include "ui/aura/root_window_observer.h"
#include "ui/aura/window.h"
@@ -26,8 +27,11 @@
#include "ui/base/gestures/gesture_types.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
+#include "ui/gfx/monitor.h"
+#include "ui/gfx/screen.h"
using std::vector;
@@ -54,6 +58,11 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) {
}
}
+float GetDeviceScaleFactorFromMonitor(const aura::Window* window) {
+ MonitorManager* monitor_manager = Env::GetInstance()->monitor_manager();
+ return monitor_manager->GetMonitorNearestWindow(window).device_scale_factor();
+}
+
const int kCompositorLockTimeoutMs = 67;
} // namespace
@@ -110,8 +119,7 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds)
should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAuraDisableHoldMouseMoves);
- compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(),
- host_->GetBounds().size()));
+ compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget()));
DCHECK(compositor_.get());
compositor_->AddObserver(this);
}
@@ -136,11 +144,15 @@ RootWindow::~RootWindow() {
}
void RootWindow::Init() {
+ compositor()->SetScaleAndSize(GetDeviceScaleFactorFromMonitor(this),
+ host_->GetBounds().size());
Window::Init(ui::LAYER_NOT_DRAWN);
- last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
- SetBounds(ConvertRectToDIP(this, gfx::Rect(host_->GetBounds().size())));
- Show();
+ last_mouse_location_ =
+ ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
compositor()->SetRootLayer(layer());
+ SetBounds(
+ ui::ConvertRectToDIP(layer(), gfx::Rect(host_->GetBounds().size())));
+ Show();
host_->SetRootWindow(this);
}
@@ -148,13 +160,14 @@ void RootWindow::ShowRootWindow() {
host_->Show();
}
-void RootWindow::SetHostSize(const gfx::Size& size) {
+void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) {
DispatchHeldMouseMove();
gfx::Rect bounds = host_->GetBounds();
- bounds.set_size(size);
+ bounds.set_size(size_in_pixel);
host_->SetBounds(bounds);
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
+ last_mouse_location_ =
+ ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
synthesize_mouse_move_ = false;
}
@@ -162,11 +175,12 @@ gfx::Size RootWindow::GetHostSize() const {
return host_->GetBounds().size();
}
-void RootWindow::SetHostBounds(const gfx::Rect& bounds) {
+void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) {
DispatchHeldMouseMove();
- host_->SetBounds(bounds);
+ host_->SetBounds(bounds_in_pixel);
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
+ last_mouse_location_ =
+ ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
synthesize_mouse_move_ = false;
}
@@ -187,7 +201,7 @@ void RootWindow::ShowCursor(bool show) {
}
void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
- host_->MoveCursorTo(ConvertPointToPixel(this, location_in_dip));
+ host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location_in_dip));
}
bool RootWindow::ConfineCursorToWindow() {
@@ -249,15 +263,14 @@ bool RootWindow::DispatchKeyEvent(KeyEvent* event) {
bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
DispatchHeldMouseMove();
-#if defined(ENABLE_DIP)
- float scale = GetMonitorScaleFactor(this);
- ui::Transform transform;
- transform.SetScale(scale, scale);
- transform.ConcatTransform(layer()->transform());
- event->UpdateForRootTransform(transform);
-#else
- event->UpdateForRootTransform(layer()->transform());
-#endif
+ if (ui::IsDIPEnabled()) {
+ float scale = ui::GetDeviceScaleFactor(layer());
+ ui::Transform transform = layer()->transform();
+ transform.ConcatScale(scale, scale);
+ event->UpdateForRootTransform(transform);
+ } else {
+ event->UpdateForRootTransform(layer()->transform());
+ }
last_mouse_location_ = event->location();
synthesize_mouse_move_ = false;
@@ -281,15 +294,14 @@ bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
DispatchHeldMouseMove();
-#if defined(ENABLE_DIP)
- float scale = GetMonitorScaleFactor(this);
- ui::Transform transform;
- transform.SetScale(scale, scale);
- transform.ConcatTransform(layer()->transform());
- event->UpdateForRootTransform(transform);
-#else
- event->UpdateForRootTransform(layer()->transform());
-#endif
+ if (ui::IsDIPEnabled()) {
+ float scale = ui::GetDeviceScaleFactor(layer());
+ ui::Transform transform = layer()->transform();
+ transform.ConcatScale(scale, scale);
+ event->UpdateForRootTransform(transform);
+ } else {
+ event->UpdateForRootTransform(layer()->transform());
+ }
bool handled = false;
GestureConsumer* consumer = gesture_recognizer_->GetTouchLockedTarget(event);
@@ -361,16 +373,18 @@ bool RootWindow::DispatchGestureEvent(GestureEvent* event) {
return false;
}
-void RootWindow::OnHostResized(const gfx::Size& size) {
+void RootWindow::OnHostResized(const gfx::Size& size_in_pixel) {
DispatchHeldMouseMove();
// The compositor should have the same size as the native root window host.
- compositor_->WidgetSizeChanged(size);
- gfx::Size old(ConvertSizeToDIP(this, bounds().size()));
+ // Get the latest scale from monitor because it might have been changed.
+ compositor_->SetScaleAndSize(GetDeviceScaleFactorFromMonitor(this),
+ size_in_pixel);
+ gfx::Size old(bounds().size());
// The layer, and all the observers should be notified of the
// transformed size of the root window.
- gfx::Rect bounds(ConvertSizeToDIP(this, size));
+ gfx::Rect bounds(ui::ConvertSizeToDIP(layer(), size_in_pixel));
layer()->transform().TransformRect(&bounds);
- SetBounds(gfx::Rect(bounds.size()));
+ SetBounds(bounds);
FOR_EACH_OBSERVER(RootWindowObserver, observers_,
OnRootWindowResized(this, old));
}
@@ -901,15 +915,14 @@ bool RootWindow::DispatchMouseEventImpl(MouseEvent* event) {
ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON;
-#if defined(ENABLE_DIP)
- float scale = GetMonitorScaleFactor(this);
- ui::Transform transform;
- transform.SetScale(scale, scale);
- transform.ConcatTransform(layer()->transform());
- event->UpdateForRootTransform(transform);
-#else
- event->UpdateForRootTransform(layer()->transform());
-#endif
+ if (ui::IsDIPEnabled()) {
+ float scale = ui::GetDeviceScaleFactor(layer());
+ ui::Transform transform = layer()->transform();
+ transform.ConcatScale(scale, scale);
+ event->UpdateForRootTransform(transform);
+ } else {
+ event->UpdateForRootTransform(layer()->transform());
+ }
last_mouse_location_ = event->location();
synthesize_mouse_move_ = false;
@@ -976,9 +989,7 @@ void RootWindow::SynthesizeMouseMoveEvent() {
#if !defined(OS_WIN)
// Temporarily disabled for windows. See crbug.com/112222.
gfx::Point orig_mouse_location = last_mouse_location_;
- orig_mouse_location = ConvertPointToPixel(this, orig_mouse_location);
layer()->transform().TransformPoint(orig_mouse_location);
- orig_mouse_location = ConvertPointToDIP(this,orig_mouse_location);
// TODO(derat|oshima): Don't use mouse_button_flags_ as it's
// currently broken. See/ crbug.com/107931.
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 9298bb4..708fa6c 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -12,7 +12,6 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "ui/aura/aura_export.h"
-#include "ui/aura/dip_util.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/window.h"
#include "ui/base/cursor/cursor.h"
@@ -105,11 +104,11 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
void ShowRootWindow();
// Sets the size of the root window.
- void SetHostSize(const gfx::Size& size);
+ void SetHostSize(const gfx::Size& size_in_pixel);
gfx::Size GetHostSize() const;
// Sets the bounds of the host window.
- void SetHostBounds(const gfx::Rect& size);
+ void SetHostBounds(const gfx::Rect& size_in_pixel);
// Returns where the RootWindow is on screen.
gfx::Point GetHostOrigin() const;
@@ -155,7 +154,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
bool DispatchGestureEvent(GestureEvent* event);
// Called when the host changes size.
- void OnHostResized(const gfx::Size& size);
+ void OnHostResized(const gfx::Size& size_in_pixel);
// Invoked when |window| is being destroyed.
void OnWindowDestroying(Window* window);
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 43e8e08ba..c059ee5 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -13,7 +13,6 @@
#include "ui/aura/client/event_client.h"
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/client/visibility_client.h"
-#include "ui/aura/dip_util.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
@@ -212,10 +211,6 @@ gfx::Rect Window::GetBoundsInRootWindow() const {
return gfx::Rect(origin, bounds().size());
}
-const gfx::Rect& Window::GetBoundsInPixel() const {
- return layer_->bounds();
-}
-
void Window::SetTransform(const ui::Transform& transform) {
RootWindow* root_window = GetRootWindow();
bool contained_mouse = IsVisible() && root_window &&
@@ -247,22 +242,17 @@ void Window::SetBounds(const gfx::Rect& new_bounds) {
}
gfx::Rect Window::GetTargetBounds() const {
- return ConvertRectToDIP(this, layer_->GetTargetBounds());
+ return layer_->GetTargetBounds();
}
-gfx::Rect Window::bounds() const {
-#if defined(ENABLE_DIP)
- return ConvertRectToDIP(this, layer_->bounds());
-#else
+const gfx::Rect& Window::bounds() const {
return layer_->bounds();
-#endif
}
-void Window::SchedulePaintInRect(const gfx::Rect& rect_in_dip) {
- gfx::Rect rect = ConvertRectToPixel(this, rect_in_dip);
+void Window::SchedulePaintInRect(const gfx::Rect& rect) {
if (layer_->SchedulePaint(rect)) {
FOR_EACH_OBSERVER(
- WindowObserver, observers_, OnWindowPaintScheduled(this, rect_in_dip));
+ WindowObserver, observers_, OnWindowPaintScheduled(this, rect));
}
}
@@ -384,14 +374,7 @@ void Window::ConvertPointToWindow(const Window* source,
gfx::Point* point) {
if (!source)
return;
- // TODO(oshima): We probably need to handle source's root != target's root
- // case under multi monitor environment.
- *point = ConvertPointToPixel(source, *point);
ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
- if (target)
- *point = ConvertPointToDIP(target, *point);
- else
- *point = ConvertPointToDIP(source, *point);
}
gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
@@ -595,7 +578,7 @@ void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
// Always need to set the layer's bounds -- even if it is to the same thing.
// This may cause important side effects such as stopping animation.
- layer_->SetBounds(ConvertRectToPixel(this, actual_new_bounds));
+ layer_->SetBounds(actual_new_bounds);
// If we're not changing the effective bounds, then we can bail early and skip
// notifying our listeners.
@@ -809,16 +792,8 @@ void Window::NotifyAddedToRootWindow() {
}
void Window::OnPaintLayer(gfx::Canvas* canvas) {
- if (delegate_) {
-#if defined(ENABLE_DIP)
- float scale = GetMonitorScaleFactor(this);
- canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale));
-#endif
+ if (delegate_)
delegate_->OnPaint(canvas);
-#if defined(ENABLE_DIP)
- canvas->Restore();
-#endif
- }
}
void Window::UpdateLayerName(const std::string& name) {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index f3e8528..796142c 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -112,8 +112,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
WindowDelegate* delegate() { return delegate_; }
- // TODO(oshima): Rename this to GetBounds().
- gfx::Rect bounds() const;
+ const gfx::Rect& bounds() const;
Window* parent() { return parent_; }
const Window* parent() const { return parent_; }
@@ -144,9 +143,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// support.
gfx::Rect GetBoundsInRootWindow() const;
- // Returns the bounds in pixel coordinates.
- const gfx::Rect& GetBoundsInPixel() const;
-
virtual void SetTransform(const ui::Transform& transform);
// Assigns a LayoutManager to size and place child windows.
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 8c9b1bd..18da91c 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -14,6 +14,7 @@
#include "third_party/skia/include/images/SkImageEncoder.h"
#include "ui/compositor/compositor_observer.h"
#include "ui/compositor/compositor_switches.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/test_web_graphics_context_3d.h"
#include "ui/gfx/gl/gl_context.h"
@@ -119,14 +120,13 @@ Texture::~Texture() {
}
Compositor::Compositor(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size)
+ gfx::AcceleratedWidget widget)
: delegate_(delegate),
- size_(size),
root_layer_(NULL),
widget_(widget),
root_web_layer_(WebKit::WebLayer::create()),
- swap_posted_(false) {
+ swap_posted_(false),
+ device_scale_factor_(0.0f) {
WebKit::WebLayerTreeView::Settings settings;
CommandLine* command_line = CommandLine::ForCurrentProcess();
settings.showFPSCounter =
@@ -142,7 +142,6 @@ Compositor::Compositor(CompositorDelegate* delegate,
host_.initialize(this, root_web_layer_, settings);
root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
- WidgetSizeChanged(size_);
}
Compositor::~Compositor() {
@@ -210,32 +209,42 @@ void Compositor::ScheduleFullDraw() {
host_.setNeedsRedraw();
}
-bool Compositor::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) {
- if (bounds.right() > size().width() || bounds.bottom() > size().height())
+bool Compositor::ReadPixels(SkBitmap* bitmap,
+ const gfx::Rect& bounds_in_pixel) {
+ if (bounds_in_pixel.right() > size().width() ||
+ bounds_in_pixel.bottom() > size().height())
return false;
// Convert to OpenGL coordinates.
- gfx::Point new_origin(bounds.x(),
- size().height() - bounds.height() - bounds.y());
+ gfx::Point new_origin(
+ bounds_in_pixel.x(),
+ size().height() - bounds_in_pixel.height() - bounds_in_pixel.y());
bitmap->setConfig(SkBitmap::kARGB_8888_Config,
- bounds.width(), bounds.height());
+ bounds_in_pixel.width(), bounds_in_pixel.height());
bitmap->allocPixels();
SkAutoLockPixels lock_image(*bitmap);
unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels());
- if (host_.compositeAndReadback(pixels,
- gfx::Rect(new_origin, bounds.size()))) {
- SwizzleRGBAToBGRAAndFlip(pixels, bounds.size());
+ if (host_.compositeAndReadback(
+ pixels, gfx::Rect(new_origin, bounds_in_pixel.size()))) {
+ SwizzleRGBAToBGRAAndFlip(pixels, bounds_in_pixel.size());
return true;
}
return false;
}
-void Compositor::WidgetSizeChanged(const gfx::Size& size) {
- if (size.IsEmpty())
+void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) {
+ DCHECK(scale > 0);
+ if (size_in_pixel.IsEmpty() || scale <= 0)
return;
- size_ = size;
- host_.setViewportSize(size_);
- root_web_layer_.setBounds(size_);
+ size_ = size_in_pixel;
+ host_.setViewportSize(size_in_pixel);
+ root_web_layer_.setBounds(size_in_pixel);
+
+ if (device_scale_factor_ != scale && IsDIPEnabled()) {
+ device_scale_factor_ = scale;
+ if (root_layer_)
+ root_layer_->OnDeviceScaleFactorChanged(scale);
+ }
}
void Compositor::AddObserver(CompositorObserver* observer) {
diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp
index d53f1f2..4640b4d0 100644
--- a/ui/compositor/compositor.gyp
+++ b/ui/compositor/compositor.gyp
@@ -34,6 +34,8 @@
'compositor_switches.h',
'debug_utils.cc',
'debug_utils.h',
+ 'dip_util.cc',
+ 'dip_util.h',
'layer.cc',
'layer.h',
'layer_animation_delegate.h',
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
index 2bb4083..ef72de0 100644
--- a/ui/compositor/compositor.h
+++ b/ui/compositor/compositor.h
@@ -111,7 +111,7 @@ class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> {
unsigned int texture_id_;
bool flipped_;
- gfx::Size size_;
+ gfx::Size size_; // in pixel
DISALLOW_COPY_AND_ASSIGN(Texture);
};
@@ -135,8 +135,7 @@ class COMPOSITOR_EXPORT Compositor
: NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) {
public:
Compositor(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size);
+ gfx::AcceleratedWidget widget);
virtual ~Compositor();
static void Initialize(bool useThread);
@@ -154,6 +153,10 @@ class COMPOSITOR_EXPORT Compositor
Layer* root_layer() { return root_layer_; }
void SetRootLayer(Layer* root_layer);
+ // The scale factor of the device that this compositor is
+ // compositing layers on.
+ float device_scale_factor() const { return device_scale_factor_; }
+
// Draws the scene created by the layer tree and any visual effects. If
// |force_clear| is true, this will cause the compositor to clear before
// compositing.
@@ -164,16 +167,15 @@ class COMPOSITOR_EXPORT Compositor
// the whole frame needs to be drawn.
void ScheduleFullDraw();
- // Reads the region |bounds| of the contents of the last rendered frame
- // into the given bitmap.
+ // Reads the region |bounds_in_pixel| of the contents of the last rendered
+ // frame into the given bitmap.
// Returns false if the pixels could not be read.
- bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds);
+ bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds_in_pixel);
- // Notifies the compositor that the size of the widget that it is
- // drawing to has changed.
- void WidgetSizeChanged(const gfx::Size& size);
+ // Sets the compositor's device scale factor and size.
+ void SetScaleAndSize(float scale, const gfx::Size& size_in_pixel);
- // Returns the size of the widget that is being drawn to.
+ // Returns the size of the widget that is being drawn to in pixel coordinates.
const gfx::Size& size() const { return size_; }
// Returns the widget for this compositor.
@@ -238,6 +240,10 @@ class COMPOSITOR_EXPORT Compositor
// This is set to true when the swap buffers has been posted and we're waiting
// for completion.
bool swap_posted_;
+
+ // The device scale factor of the monitor that this compositor is compositing
+ // layers on.
+ float device_scale_factor_;
};
} // namespace ui
diff --git a/ui/compositor/compositor_switches.cc b/ui/compositor/compositor_switches.cc
index b3dbb2d..8f339a5 100644
--- a/ui/compositor/compositor_switches.cc
+++ b/ui/compositor/compositor_switches.cc
@@ -10,6 +10,9 @@ const char kDisableTestCompositor[] = "disable-test-compositor";
const char kDisableUIVsync[] = "disable-ui-vsync";
+// Enable Density Independent Pixel coordinates.
+const char kUIEnableDIP[] = "ui-enable-dip";
+
const char kUIEnablePartialSwap[] = "ui-enable-partial-swap";
// Show FPS counter.
diff --git a/ui/compositor/compositor_switches.h b/ui/compositor/compositor_switches.h
index a8f9c8f..aec358d 100644
--- a/ui/compositor/compositor_switches.h
+++ b/ui/compositor/compositor_switches.h
@@ -12,6 +12,7 @@ namespace switches {
COMPOSITOR_EXPORT extern const char kDisableTestCompositor[];
COMPOSITOR_EXPORT extern const char kDisableUIVsync[];
+COMPOSITOR_EXPORT extern const char kUIEnableDIP[];
COMPOSITOR_EXPORT extern const char kUIEnablePartialSwap[];
COMPOSITOR_EXPORT extern const char kUIShowFPSCounter[];
COMPOSITOR_EXPORT extern const char kUIShowLayerBorders[];
diff --git a/ui/compositor/dip_util.cc b/ui/compositor/dip_util.cc
new file mode 100644
index 0000000..e13c750
--- /dev/null
+++ b/ui/compositor/dip_util.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/compositor/dip_util.h"
+
+#include "base/command_line.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/compositor_switches.h"
+#include "ui/compositor/layer.h"
+#include "ui/gfx/monitor.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/rect.h"
+
+namespace ui {
+namespace {
+bool dip_enabled_for_test = false;
+} // namespace
+
+namespace test {
+
+ScopedDIPEnablerForTest::ScopedDIPEnablerForTest() {
+ CHECK(!dip_enabled_for_test);
+ dip_enabled_for_test = true;
+}
+
+ScopedDIPEnablerForTest::~ScopedDIPEnablerForTest() {
+ dip_enabled_for_test = false;
+}
+
+} // namespace test
+
+bool IsDIPEnabled() {
+ static const bool dip_enabled =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kUIEnableDIP);
+ return dip_enabled || dip_enabled_for_test;
+}
+
+float GetDeviceScaleFactor(const Layer* layer) {
+ if (!IsDIPEnabled())
+ return 1.0f;
+ return layer->device_scale_factor();
+}
+
+gfx::Point ConvertPointToDIP(const Layer* layer,
+ const gfx::Point& point_in_pixel) {
+ if (IsDIPEnabled())
+ return point_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
+ else
+ return point_in_pixel;
+}
+
+gfx::Size ConvertSizeToDIP(const Layer* layer,
+ const gfx::Size& size_in_pixel) {
+ if (IsDIPEnabled())
+ return size_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer));
+ else
+ return size_in_pixel;
+}
+
+gfx::Rect ConvertRectToDIP(const Layer* layer,
+ const gfx::Rect& rect_in_pixel) {
+ if (IsDIPEnabled()) {
+ float scale = 1.0f / GetDeviceScaleFactor(layer);
+ return gfx::Rect(rect_in_pixel.origin().Scale(scale),
+ rect_in_pixel.size().Scale(scale));
+ } else {
+ return rect_in_pixel;
+ }
+}
+
+gfx::Point ConvertPointToPixel(const Layer* layer,
+ const gfx::Point& point_in_dip) {
+ if (IsDIPEnabled()) {
+ return point_in_dip.Scale(GetDeviceScaleFactor(layer));
+ } else {
+ return point_in_dip;
+ }
+}
+
+gfx::Size ConvertSizeToPixel(const Layer* layer,
+ const gfx::Size& size_in_dip) {
+ if (IsDIPEnabled()) {
+ return size_in_dip.Scale(GetDeviceScaleFactor(layer));
+ } else {
+ return size_in_dip;
+ }
+}
+
+gfx::Rect ConvertRectToPixel(const Layer* layer,
+ const gfx::Rect& rect_in_dip) {
+ if (IsDIPEnabled()) {
+ float scale = GetDeviceScaleFactor(layer);
+ return gfx::Rect(rect_in_dip.origin().Scale(scale),
+ rect_in_dip.size().Scale(scale));
+ } else {
+ return rect_in_dip;
+ }
+}
+} // namespace ui
diff --git a/ui/compositor/dip_util.h b/ui/compositor/dip_util.h
new file mode 100644
index 0000000..0667052
--- /dev/null
+++ b/ui/compositor/dip_util.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_COMPOSITOR_DIP_UTIL_H_
+#define UI_COMPOSITOR_DIP_UTIL_H_
+#pragma once
+
+#include "ui/compositor/compositor_export.h"
+#include "base/basictypes.h"
+
+namespace gfx {
+class Point;
+class Size;
+class Rect;
+} // namespace gfx
+
+namespace ui {
+namespace test {
+
+// A scoped object allows you to temporarily enable DIP
+// in the unit tests.
+class COMPOSITOR_EXPORT ScopedDIPEnablerForTest {
+ public:
+ ScopedDIPEnablerForTest();
+ ~ScopedDIPEnablerForTest();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedDIPEnablerForTest);
+};
+
+} // namespace test
+
+class Layer;
+
+// True if DIP is enabled.
+COMPOSITOR_EXPORT bool IsDIPEnabled();
+
+COMPOSITOR_EXPORT float GetDeviceScaleFactor(const Layer* layer);
+
+// Utility functions that convert point/size/rect between
+// DIP and pixel coordinates system.
+COMPOSITOR_EXPORT gfx::Point ConvertPointToDIP(
+ const Layer* layer,
+ const gfx::Point& point_in_pixel);
+COMPOSITOR_EXPORT gfx::Size ConvertSizeToDIP(
+ const Layer* layer,
+ const gfx::Size& size_in_pixel);
+COMPOSITOR_EXPORT gfx::Rect ConvertRectToDIP(
+ const Layer* layer,
+ const gfx::Rect& rect_in_pixel);
+COMPOSITOR_EXPORT gfx::Point ConvertPointToPixel(
+ const Layer* layer,
+ const gfx::Point& point_in_dip);
+COMPOSITOR_EXPORT gfx::Size ConvertSizeToPixel(
+ const Layer* layer,
+ const gfx::Size& size_in_dip);
+COMPOSITOR_EXPORT gfx::Rect ConvertRectToPixel(
+ const Layer* layer,
+ const gfx::Rect& rect_in_dip);
+
+} // namespace ui
+
+#endif // UI_COMPOSITOR_DIP_UTIL_H_
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 204b1b0..6ba3211 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -20,10 +20,12 @@
#include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.h"
#include "ui/base/animation/animation.h"
#include "ui/compositor/compositor_switches.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer_animator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/point3.h"
+#include "ui/gfx/monitor.h"
namespace {
@@ -50,7 +52,9 @@ Layer::Layer()
fills_bounds_opaquely_(true),
layer_updated_externally_(false),
opacity_(1.0f),
- delegate_(NULL) {
+ delegate_(NULL),
+ scale_canvas_(true),
+ device_scale_factor_(1.0f) {
CreateWebLayer();
}
@@ -62,7 +66,9 @@ Layer::Layer(LayerType type)
fills_bounds_opaquely_(true),
layer_updated_externally_(false),
opacity_(1.0f),
- delegate_(NULL) {
+ delegate_(NULL),
+ scale_canvas_(true),
+ device_scale_factor_(1.0f) {
CreateWebLayer();
}
@@ -91,6 +97,8 @@ void Layer::SetCompositor(Compositor* compositor) {
DCHECK(!compositor || compositor->root_layer() == this);
DCHECK(!parent_);
compositor_ = compositor;
+ if (IsDIPEnabled() && compositor)
+ OnDeviceScaleFactorChanged(compositor->device_scale_factor());
}
void Layer::Add(Layer* child) {
@@ -100,6 +108,8 @@ void Layer::Add(Layer* child) {
child->parent_ = this;
children_.push_back(child);
web_layer_.addChild(child->web_layer_);
+ if (IsDIPEnabled())
+ child->OnDeviceScaleFactorChanged(device_scale_factor_);
}
void Layer::Remove(Layer* child) {
@@ -234,6 +244,8 @@ void Layer::ConvertPointToLayer(const Layer* source,
const Layer* root_layer = GetRoot(source);
CHECK_EQ(root_layer, GetRoot(target));
+ // TODO(oshima): We probably need to handle source's root != target's root
+ // case under multi monitor environment.
if (source != root_layer)
source->ConvertPointForAncestor(root_layer, point);
if (target != root_layer)
@@ -297,10 +309,11 @@ void Layer::SetColor(SkColor color) {
bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
if (type_ == LAYER_SOLID_COLOR || !delegate_)
return false;
- damaged_region_.op(invalid_rect.x(),
- invalid_rect.y(),
- invalid_rect.right(),
- invalid_rect.bottom(),
+ gfx::Rect invalid_rect_in_pixel = ConvertRectToPixel(this, invalid_rect);
+ damaged_region_.op(invalid_rect_in_pixel.x(),
+ invalid_rect_in_pixel.y(),
+ invalid_rect_in_pixel.right(),
+ invalid_rect_in_pixel.bottom(),
SkRegion::kUnion_Op);
ScheduleDraw();
return true;
@@ -342,12 +355,30 @@ void Layer::SuppressPaint() {
children_[i]->SuppressPaint();
}
+void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) {
+ CHECK(IsDIPEnabled());
+ if (device_scale_factor_ == device_scale_factor)
+ return;
+ device_scale_factor_ = device_scale_factor;
+ RecomputeTransform();
+ RecomputeDrawsContentAndUVRect();
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->OnDeviceScaleFactorChanged(device_scale_factor);
+}
+
void Layer::paintContents(WebKit::WebCanvas* web_canvas,
const WebKit::WebRect& clip) {
TRACE_EVENT0("ui", "Layer::paintContents");
gfx::Canvas canvas(web_canvas);
+ bool scale_canvas = IsDIPEnabled() && scale_canvas_;
+ if (scale_canvas) {
+ canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_),
+ SkFloatToScalar(device_scale_factor_));
+ }
if (delegate_)
delegate_->OnPaintLayer(&canvas);
+ if (scale_canvas)
+ canvas.Restore();
}
float Layer::GetCombinedOpacity() const {
@@ -508,14 +539,28 @@ void Layer::CreateWebLayer() {
show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUIShowLayerBorders);
web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0);
- RecomputeDrawsContentAndUVRect();
- RecomputeDebugBorderColor();
}
void Layer::RecomputeTransform() {
- ui::Transform transform = transform_;
- transform.ConcatTranslate(bounds_.x(), bounds_.y());
- web_layer_.setTransform(transform.matrix());
+ if (IsDIPEnabled()) {
+ ui::Transform scale_translate;
+ scale_translate.matrix().set3x3(device_scale_factor_, 0, 0,
+ 0, device_scale_factor_, 0,
+ 0, 0, 1);
+ // Start with the inverse matrix of above.
+ Transform transform;
+ transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0,
+ 0, 1.0f / device_scale_factor_, 0,
+ 0, 0, 1);
+ transform.ConcatTransform(transform_);
+ transform.ConcatTranslate(bounds_.x(), bounds_.y());
+ transform.ConcatTransform(scale_translate);
+ web_layer_.setTransform(transform.matrix());
+ } else {
+ Transform t = transform_;
+ t.ConcatTranslate(bounds_.x(), bounds_.y());
+ web_layer_.setTransform(t.matrix());
+ }
}
void Layer::RecomputeDrawsContentAndUVRect() {
@@ -524,16 +569,17 @@ void Layer::RecomputeDrawsContentAndUVRect() {
if (!web_layer_is_accelerated_) {
if (type_ != LAYER_SOLID_COLOR)
web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw);
- web_layer_.setBounds(bounds_.size());
+ web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size()));
} else {
DCHECK(texture_);
unsigned int texture_id = texture_->texture_id();
WebKit::WebExternalTextureLayer texture_layer =
web_layer_.to<WebKit::WebExternalTextureLayer>();
texture_layer.setTextureId(should_draw ? texture_id : 0);
+ gfx::Rect bounds_in_pixel = ConvertRectToPixel(this, bounds());
gfx::Size texture_size = texture_->size();
- gfx::Size size(std::min(bounds_.width(), texture_size.width()),
- std::min(bounds_.height(), texture_size.height()));
+ gfx::Size size(std::min(bounds_in_pixel.width(), texture_size.width()),
+ std::min(bounds_in_pixel.height(), texture_size.height()));
WebKit::WebFloatRect rect(
0,
0,
diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h
index e74d553..e523fdc 100644
--- a/ui/compositor/layer.h
+++ b/ui/compositor/layer.h
@@ -36,6 +36,8 @@ class Texture;
// has enabled layers ends up creating a Layer to manage the texture.
// A Layer can also be created without a texture, in which case it renders
// nothing and is simply used as a node in a hierarchy of layers.
+// Coordinate system used in layers is DIP (Density Independent Pixel)
+// coordinates unless explicitly mentioned as pixel coordinates.
//
// NOTE: unlike Views, each Layer does *not* own its children views. If you
// delete a Layer and it has children, the parent of each child layer is set to
@@ -193,6 +195,14 @@ class COMPOSITOR_EXPORT Layer :
// new paint requests.
void SuppressPaint();
+ // Notifies the layer that the device scale factor has changed.
+ void OnDeviceScaleFactorChanged(float device_scale_factor);
+
+ // Sets if the layer should scale the canvas before passing to
+ // |LayerDelegate::OnLayerPaint|. Set to false if the delegate
+ // handles scaling.
+ void set_scale_canvas(bool scale_canvas) { scale_canvas_ = scale_canvas; }
+
// Sometimes the Layer is being updated by something other than SetCanvas
// (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT).
bool layer_updated_externally() const { return layer_updated_externally_; }
@@ -202,6 +212,8 @@ class COMPOSITOR_EXPORT Layer :
WebKit::WebLayer web_layer() { return web_layer_; }
+ float device_scale_factor() const { return device_scale_factor_; }
+
private:
struct LayerProperties {
public:
@@ -276,8 +288,8 @@ class COMPOSITOR_EXPORT Layer :
// If true the layer is always up to date.
bool layer_updated_externally_;
- // Union of damaged rects to be used when compositor is ready to
- // paint the content.
+ // Union of damaged rects, in pixel coordinates, to be used when
+ // compositor is ready to paint the content.
SkRegion damaged_region_;
float opacity_;
@@ -293,6 +305,13 @@ class COMPOSITOR_EXPORT Layer :
bool web_layer_is_accelerated_;
bool show_debug_borders_;
+ // If true, the layer scales the canvas using device scale factor
+ // before passing to LayerDelegate::OnLayerPaint.
+ bool scale_canvas_;
+
+ // A cached copy of |Compositor::device_scale_factor()|.
+ float device_scale_factor_;
+
DISALLOW_COPY_AND_ASSIGN(Layer);
};
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index 3af990d..6143ebb 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -9,8 +9,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/stringprintf.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "ui/compositor/compositor_observer.h"
+#include "ui/compositor/compositor_setup.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/test/test_compositor_host.h"
@@ -19,8 +23,6 @@
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/skia_util.h"
-#include "ui/compositor/compositor_setup.h"
-
namespace ui {
namespace {
@@ -220,18 +222,27 @@ class TestLayerDelegate : public LayerDelegate {
const gfx::Size& paint_size() const { return paint_size_; }
int color_index() const { return color_index_; }
+ std::string ToScaleString() const {
+ return StringPrintf("%.1f %.1f", scale_x_, scale_y_);
+ }
+
// Overridden from LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
SkBitmap contents = canvas->ExtractBitmap();
paint_size_ = gfx::Size(contents.width(), contents.height());
canvas->FillRect(gfx::Rect(paint_size_), colors_[color_index_]);
color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
+ const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix();
+ scale_x_ = matrix.getScaleX();
+ scale_y_ = matrix.getScaleY();
}
private:
std::vector<SkColor> colors_;
int color_index_;
gfx::Size paint_size_;
+ float scale_x_;
+ float scale_y_;
DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
};
@@ -315,6 +326,9 @@ class TestCompositorObserver : public CompositorObserver {
#define MAYBE_CompositorObservers DISABLED_CompositorObservers
#define MAYBE_ModifyHierarchy DISABLED_ModifyHierarchy
#define MAYBE_Opacity DISABLED_Opacity
+#define MAYBE_ScaleUpDown DISABLED_ScaleUpDown
+#define MAYBE_ScaleReparent DISABLED_ScaleReparent
+#define MAYBE_NoScaleCanvas DISABLED_NoScaleCanvas
#else
#define MAYBE_Delegate DISABLED_Delegate
#define MAYBE_Draw Draw
@@ -326,6 +340,9 @@ class TestCompositorObserver : public CompositorObserver {
#define MAYBE_CompositorObservers DISABLED_CompositorObservers
#define MAYBE_ModifyHierarchy ModifyHierarchy
#define MAYBE_Opacity Opacity
+#define MAYBE_ScaleUpDown ScaleUpDown
+#define MAYBE_ScaleReparent ScaleReparent
+#define MAYBE_NoScaleCanvas NoScaleCanvas
#endif
TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) {
@@ -366,7 +383,8 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
virtual void SetUp() OVERRIDE {
ui::SetupTestCompositor();
compositor_.reset(new Compositor(
- this, gfx::kNullAcceleratedWidget, gfx::Size(1000, 1000)));
+ this, gfx::kNullAcceleratedWidget));
+ compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000));
}
virtual void TearDown() OVERRIDE {
@@ -857,7 +875,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) {
// Checks that modifying the hierarchy correctly affects final composite.
TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) {
- GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50));
+ GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
// l0
// +-l11
@@ -917,7 +935,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) {
// Opacity is rendered correctly.
// Checks that modifying the hierarchy correctly affects final composite.
TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) {
- GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50));
+ GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
// l0
// +-l11
@@ -1021,4 +1039,144 @@ TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) {
gfx::Rect(10, 10, 30, 30)));
}
+TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) {
+ test::ScopedDIPEnablerForTest enable;
+
+ scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 200, 220)));
+ TestLayerDelegate root_delegate;
+ root_delegate.AddColor(SK_ColorWHITE);
+ root->set_delegate(&root_delegate);
+
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 140, 180)));
+ TestLayerDelegate l1_delegate;
+ l1_delegate.AddColor(SK_ColorWHITE);
+ l1->set_delegate(&l1_delegate);
+
+ GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
+ GetCompositor()->SetRootLayer(root.get());
+ root->Add(l1.get());
+ RunPendingMessages();
+
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ gfx::Size size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("200x220", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+
+ EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
+ EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
+
+ // Scale up to 2.0. Changing scale doesn't change the bounds in DIP.
+ GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ // Pixel size must have been scaled up.
+ size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("400x440", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("280x360", size_in_pixel.ToString());
+
+ // Canvas size must have been scaled down up.
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("400x440", root_delegate.paint_size().ToString());
+ EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString());
+ EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
+ EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
+
+ // Scale down back to 1.0f.
+ GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ // Pixel size must have been scaled down.
+ size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("200x220", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ // Canvas size must have been scaled down too.
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
+ EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString());
+ EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
+ EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
+}
+
+TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) {
+ test::ScopedDIPEnablerForTest enable;
+ scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 200, 220)));
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 140, 180)));
+ TestLayerDelegate l1_delegate;
+ l1_delegate.AddColor(SK_ColorWHITE);
+ l1->set_delegate(&l1_delegate);
+
+ GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
+ GetCompositor()->SetRootLayer(root.get());
+ RunPendingMessages();
+
+ root->Add(l1.get());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ gfx::Size size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
+ EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
+
+ // Remove l1 from root and change the scale.
+ root->Remove(l1.get());
+ EXPECT_EQ(NULL, l1->parent());
+ EXPECT_EQ(NULL, l1->GetCompositor());
+ GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
+ // Sanity check on root and l1.
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+
+ root->Add(l1.get());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("280x360", size_in_pixel.ToString());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
+ EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
+}
+
+// Tests layer::set_scale_canvas(false).
+TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) {
+ test::ScopedDIPEnablerForTest enable;
+ scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 200, 220)));
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 140, 180)));
+ l1->set_scale_canvas(false);
+ root->Add(l1.get());
+ TestLayerDelegate l1_delegate;
+ l1_delegate.AddColor(SK_ColorWHITE);
+ l1->set_delegate(&l1_delegate);
+
+ GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
+ GetCompositor()->SetRootLayer(root.get());
+
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
+ EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
+}
+
} // namespace ui
diff --git a/ui/compositor/test/test_compositor_host_linux.cc b/ui/compositor/test/test_compositor_host_linux.cc
index 0359723..b6c64a4 100644
--- a/ui/compositor/test/test_compositor_host_linux.cc
+++ b/ui/compositor/test/test_compositor_host_linux.cc
@@ -75,7 +75,8 @@ void TestCompositorHostLinux::Show() {
if (event.type == MapNotify && event.xmap.window == window_)
break;
}
- compositor_.reset(new ui::Compositor(this, window_, bounds_.size()));
+ compositor_.reset(new ui::Compositor(this, window_));
+ compositor_->SetScaleAndSize(1.0f, bounds_.size());
}
ui::Compositor* TestCompositorHostLinux::GetCompositor() {
diff --git a/ui/compositor/test/test_compositor_host_win.cc b/ui/compositor/test/test_compositor_host_win.cc
index 8e0c4f2..a6d712bcb 100644
--- a/ui/compositor/test/test_compositor_host_win.cc
+++ b/ui/compositor/test/test_compositor_host_win.cc
@@ -17,7 +17,8 @@ class TestCompositorHostWin : public TestCompositorHost,
public:
TestCompositorHostWin(const gfx::Rect& bounds) {
Init(NULL, bounds);
- compositor_.reset(new ui::Compositor(this, hwnd(), GetSize()));
+ compositor_.reset(new ui::Compositor(this, hwnd()));
+ compositor_->SetScaleAndSize(1.0f, GetSize());
}
virtual ~TestCompositorHostWin() {
diff --git a/ui/gfx/insets_f.h b/ui/gfx/insets_f.h
index 8e1ccee..20fb968 100644
--- a/ui/gfx/insets_f.h
+++ b/ui/gfx/insets_f.h
@@ -11,10 +11,6 @@
#include "build/build_config.h"
#include "ui/base/ui_export.h"
-#if !defined(ENABLE_DIP)
-#error "This class should be used only when DIP feature is enabled"
-#endif
-
namespace gfx {
// A floating versino of gfx::Insets. This is copied, instead of using
diff --git a/ui/gfx/monitor.cc b/ui/gfx/monitor.cc
index 5783a92..36dde84 100644
--- a/ui/gfx/monitor.cc
+++ b/ui/gfx/monitor.cc
@@ -69,12 +69,8 @@ void Monitor::SetScaleAndBounds(
// TODO(oshima): For m19, work area/monitor bounds that chrome/webapps sees
// has (0, 0) origin because it's simpler and enough. Fix this when
// real multi monitor support is implemented.
-#if defined(ENABLE_DIP)
bounds_ = gfx::Rect(
bounds_in_pixel.size().Scale(1.0f / device_scale_factor_));
-#else
- bounds_ = gfx::Rect(bounds_in_pixel.size());
-#endif
UpdateWorkAreaFromInsets(insets);
}
diff --git a/ui/gfx/monitor.h b/ui/gfx/monitor.h
index ab6677a..03d757f 100644
--- a/ui/gfx/monitor.h
+++ b/ui/gfx/monitor.h
@@ -14,10 +14,9 @@
namespace gfx {
// Note: The screen and monitor currently uses pixel coordinate
-// system. With ENABLE_DIP macro (which is enabled with enable_dip=1
-// gyp flag), |bounds()| and |work_area| will return values in DIP
-// coordinate system, not in backing pixels.
-// TODO(oshima): Update the comment when ENABLE_DIP macro is removed.
+// system. For platforms that support DIP (density independent pixel),
+// |bounds()| and |work_area| will return values in DIP coordinate
+// system, not in backing pixels.
class UI_EXPORT Monitor {
public:
// Returns the default value for the device scale factor, which is
diff --git a/ui/gfx/monitor_unittest.cc b/ui/gfx/monitor_unittest.cc
index a6f8c05..ae129d4 100644
--- a/ui/gfx/monitor_unittest.cc
+++ b/ui/gfx/monitor_unittest.cc
@@ -29,7 +29,6 @@ TEST(MonitorTest, WorkArea) {
EXPECT_EQ("4,3 190x192", monitor.work_area().ToString());
}
-#if defined(ENABLE_DIP)
TEST(MonitorTest, Scale) {
gfx::Monitor monitor(0, gfx::Rect(0, 0, 100, 100));
monitor.set_work_area(gfx::Rect(10, 10, 80, 80));
@@ -46,6 +45,5 @@ TEST(MonitorTest, Scale) {
EXPECT_EQ("0,0 100x100", monitor.bounds().ToString());
EXPECT_EQ("10,10 80x80", monitor.work_area().ToString());
}
-#endif
}
diff --git a/ui/gfx/path.cc b/ui/gfx/path.cc
index db355e8..70ed739 100644
--- a/ui/gfx/path.cc
+++ b/ui/gfx/path.cc
@@ -19,14 +19,12 @@ Path::Path(const Point* points, size_t count) {
lineTo(SkIntToScalar(points[i].x), SkIntToScalar(points[i].y));
}
-#if defined(ENABLE_DIP)
Path::Path(const PointF* points, size_t count) {
DCHECK(count > 1);
moveTo(SkFloatToScalar(points[0].x), SkFloatToScalar(points[0].y));
for (size_t i = 1; i < count; ++i)
lineTo(SkFloatToScalar(points[i].x), SkFloatToScalar(points[i].y));
}
-#endif
Path::~Path() {
}
diff --git a/ui/gfx/path.h b/ui/gfx/path.h
index 1b576bd..847b749 100644
--- a/ui/gfx/path.h
+++ b/ui/gfx/path.h
@@ -20,20 +20,16 @@ class UI_EXPORT Path : public SkPath {
int x;
int y;
};
-#if defined(ENABLE_DIP)
struct PointF {
float x;
float y;
};
-#endif
Path();
// Creates a path populated with the specified points.
Path(const Point* points, size_t count);
-#if defined(ENABLE_DIP)
Path(const PointF* points, size_t count);
-#endif
~Path();
diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h
index a1fc4c9..c1bf5fb 100644
--- a/ui/gfx/point_f.h
+++ b/ui/gfx/point_f.h
@@ -11,10 +11,6 @@
#include "ui/base/ui_export.h"
#include "ui/gfx/point_base.h"
-#if !defined(ENABLE_DIP)
-#error "This class should be used only when DIP feature is enabled"
-#endif
-
namespace gfx {
class Point;
diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h
index 1c92153..401070d 100644
--- a/ui/gfx/rect_f.h
+++ b/ui/gfx/rect_f.h
@@ -13,10 +13,6 @@
#include "ui/gfx/rect_base.h"
#include "ui/gfx/size_f.h"
-#if !defined(ENABLE_DIP)
-#error "This class should be used only when DIP feature is enabled"
-#endif
-
namespace gfx {
class InsetsF;
diff --git a/ui/gfx/size_f.h b/ui/gfx/size_f.h
index 1e49660..b522da8 100644
--- a/ui/gfx/size_f.h
+++ b/ui/gfx/size_f.h
@@ -12,10 +12,6 @@
#include "ui/gfx/size.h"
#include "ui/gfx/size_base.h"
-#if !defined(ENABLE_DIP)
-#error "This class should be used only when DIP feature is enabled"
-#endif
-
namespace gfx {
// A floating version of gfx::Size.
diff --git a/ui/ui.gyp b/ui/ui.gyp
index 6541bf4..25b8765 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -517,18 +517,6 @@
}],
],
}],
- ['enable_dip==1', {
- 'sources': [
- 'gfx/insets_f.cc',
- 'gfx/insets_f.h',
- 'gfx/point_f.cc',
- 'gfx/point_f.h',
- 'gfx/rect_f.cc',
- 'gfx/rect_f.h',
- 'gfx/size_f.cc',
- 'gfx/size_f.h',
- ],
- }],
['toolkit_uses_gtk == 1', {
'dependencies': [
'../build/linux/system.gyp:gtk',
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 1b35ab7..f1e3365 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -38,11 +38,6 @@
#include "ui/views/accessibility/native_view_accessibility_win.h"
#endif
-#if defined(ENABLE_DIP)
-#include "ui/gfx/monitor.h"
-#include "ui/gfx/screen.h"
-#endif
-
namespace {
// Whether to use accelerated compositing when necessary (e.g. when a view has a
@@ -85,23 +80,6 @@ const views::View* GetHierarchyRoot(const views::View* view) {
return root;
}
-// Converts the rect in DIP coordinates in DIP to pixel coordinates.
-gfx::Rect ConvertRectToPixel(const views::View* view,
- const gfx::Rect& rect_in_dip) {
-#if defined(ENABLE_DIP)
- // If we don't know in which monitor the window is in, just assume
- // it's in normal density for now.
- // TODO(oshima): Re-compute layer_'s bounds when the window is
- // attached to root window.
- if (view->GetWidget() && view->GetWidget()->GetNativeView()) {
- gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
- view->GetWidget()->GetNativeView());
- return gfx::Rect(rect_in_dip.Scale(monitor.device_scale_factor()));
- }
-#endif
- return rect_in_dip;
-}
-
} // namespace
namespace views {
@@ -710,16 +688,16 @@ void View::SchedulePaint() {
SchedulePaintInRect(GetLocalBounds());
}
-void View::SchedulePaintInRect(const gfx::Rect& rect_in_dip) {
+void View::SchedulePaintInRect(const gfx::Rect& rect) {
if (!visible_ || !painting_enabled_)
return;
if (layer()) {
- layer()->SchedulePaint(ConvertRectToPixel(this, rect_in_dip));
+ layer()->SchedulePaint(rect);
} else if (parent_) {
// Translate the requested paint rect to the parent's coordinate system
// then pass this notification up to the parent.
- parent_->SchedulePaintInRect(ConvertRectToParent(rect_in_dip));
+ parent_->SchedulePaintInRect(ConvertRectToParent(rect));
}
}
@@ -1257,17 +1235,6 @@ void View::UpdateChildLayerBounds(const gfx::Point& offset) {
}
void View::OnPaintLayer(gfx::Canvas* canvas) {
-#if defined(ENABLE_DIP)
- scoped_ptr<ScopedCanvas> scoped_canvas;
- if (layer() && GetWidget() && GetWidget()->GetNativeView()) {
- scoped_canvas.reset(new ScopedCanvas(canvas));
- float scale =
- gfx::Screen::GetMonitorNearestWindow(GetWidget()->GetNativeView()).
- device_scale_factor();
- canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale));
- }
-#endif
-
if (!layer() || !layer()->fills_bounds_opaquely())
canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
PaintCommon(canvas);
@@ -1768,8 +1735,8 @@ void View::RemoveDescendantToNotify(View* view) {
descendants_to_notify_.reset();
}
-void View::SetLayerBounds(const gfx::Rect& bounds_in_dip) {
- layer()->SetBounds(ConvertRectToPixel(this, bounds_in_dip));
+void View::SetLayerBounds(const gfx::Rect& bounds) {
+ layer()->SetBounds(bounds);
}
// Transformations -------------------------------------------------------------