Home | History | Annotate | Download | only in compositor
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/compositor/dip_util.h"
      6 
      7 #include "base/command_line.h"
      8 #include "ui/compositor/compositor.h"
      9 #include "ui/compositor/compositor_switches.h"
     10 #include "ui/compositor/layer.h"
     11 #include "ui/gfx/display.h"
     12 #include "ui/gfx/point.h"
     13 #include "ui/gfx/point_conversions.h"
     14 #include "ui/gfx/rect.h"
     15 #include "ui/gfx/rect_conversions.h"
     16 #include "ui/gfx/size.h"
     17 #include "ui/gfx/size_conversions.h"
     18 
     19 namespace ui {
     20 
     21 float GetDeviceScaleFactor(const Layer* layer) {
     22   return layer->device_scale_factor();
     23 }
     24 
     25 gfx::Point ConvertPointToDIP(const Layer* layer,
     26                              const gfx::Point& point_in_pixel) {
     27   return gfx::ToFlooredPoint(
     28       gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
     29 }
     30 
     31 gfx::PointF ConvertPointToDIP(const Layer* layer,
     32                               const gfx::PointF& point_in_pixel) {
     33   return gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer));
     34 }
     35 
     36 gfx::Size ConvertSizeToDIP(const Layer* layer,
     37                            const gfx::Size& size_in_pixel) {
     38   return gfx::ToFlooredSize(
     39       gfx::ScaleSize(size_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
     40 }
     41 
     42 gfx::Rect ConvertRectToDIP(const Layer* layer,
     43                            const gfx::Rect& rect_in_pixel) {
     44   float scale = 1.0f / GetDeviceScaleFactor(layer);
     45   return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
     46 }
     47 
     48 gfx::Point ConvertPointToPixel(const Layer* layer,
     49                                const gfx::Point& point_in_dip) {
     50   return gfx::ToFlooredPoint(
     51       gfx::ScalePoint(point_in_dip, GetDeviceScaleFactor(layer)));
     52 }
     53 
     54 gfx::Size ConvertSizeToPixel(const Layer* layer,
     55                              const gfx::Size& size_in_dip) {
     56   return gfx::ToFlooredSize(
     57       gfx::ScaleSize(size_in_dip, GetDeviceScaleFactor(layer)));
     58 }
     59 
     60 gfx::Rect ConvertRectToPixel(const Layer* layer,
     61                              const gfx::Rect& rect_in_dip) {
     62   float scale = GetDeviceScaleFactor(layer);
     63   return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale));
     64 }
     65 }  // namespace ui
     66