| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/win/screen_win_display.h" | 5 #include "ui/gfx/win/screen_win_display.h" |
| 6 | 6 |
| 7 #include "ui/gfx/geometry/insets.h" | 7 #include "ui/gfx/geometry/insets.h" |
| 8 #include "ui/gfx/win/display_info.h" | 8 #include "ui/gfx/win/display_info.h" |
| 9 #include "ui/gfx/win/dpi.h" | 9 #include "ui/gfx/win/dpi.h" |
| 10 #include "ui/gfx/win/rect_util.h" | 10 #include "ui/gfx/win/scaling_util.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 gfx::Display CreateDisplayFromDisplayInfo( | 14 gfx::Display CreateDisplayFromDisplayInfo( |
| 15 const gfx::win::DisplayInfo& display_info) { | 15 const gfx::win::DisplayInfo& display_info) { |
| 16 gfx::Display display(display_info.id()); | 16 gfx::Display display(display_info.id()); |
| 17 float scale_factor = display_info.device_scale_factor(); | 17 float scale_factor = display_info.device_scale_factor(); |
| 18 display.set_device_scale_factor(scale_factor); | 18 display.set_device_scale_factor(scale_factor); |
| 19 display.set_work_area( | 19 display.set_work_area( |
| 20 gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), | 20 gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), |
| 21 1.0f / scale_factor)); | 21 1.0f / scale_factor)); |
| 22 display.set_bounds(gfx::ScaleToEnclosingRect(display_info.screen_rect(), | 22 display.set_bounds(gfx::ScaleToEnclosingRect(display_info.screen_rect(), |
| 23 1.0f / scale_factor)); | 23 1.0f / scale_factor)); |
| 24 display.set_rotation(display_info.rotation()); | 24 display.set_rotation(display_info.rotation()); |
| 25 return display; | 25 return display; |
| 26 } | 26 } |
| 27 | 27 |
| 28 gfx::Display CreateDisplayWithReferenceFromDisplayInfo( | |
| 29 const gfx::win::ScreenWinDisplay& reference, | |
| 30 const gfx::win::DisplayInfo& display_info) { | |
| 31 gfx::Display display(display_info.id()); | |
| 32 float scale_factor = display_info.device_scale_factor(); | |
| 33 display.set_device_scale_factor(scale_factor); | |
| 34 const gfx::Insets pixel_insets = | |
| 35 display_info.screen_rect().InsetsFrom(display_info.screen_work_rect()); | |
| 36 const gfx::Insets scaled_insets = pixel_insets.Scale(1.0f / scale_factor, | |
| 37 1.0f / scale_factor); | |
| 38 const gfx::Rect scaled_bounds = | |
| 39 gfx::win::ScaleAndPositionRect(reference.display().bounds(), | |
| 40 reference.pixel_bounds(), | |
| 41 display_info.screen_rect(), | |
| 42 scale_factor); | |
| 43 display.set_bounds(scaled_bounds); | |
| 44 gfx::Rect scaled_work_area(scaled_bounds); | |
| 45 scaled_work_area.Inset(scaled_insets); | |
| 46 display.set_work_area(scaled_work_area); | |
| 47 display.set_rotation(display_info.rotation()); | |
| 48 return display; | |
| 49 } | |
| 50 | |
| 51 } // namespace | 28 } // namespace |
| 52 | 29 |
| 53 namespace gfx { | 30 namespace gfx { |
| 54 namespace win { | 31 namespace win { |
| 55 | 32 |
| 56 ScreenWinDisplay::ScreenWinDisplay() = default; | 33 ScreenWinDisplay::ScreenWinDisplay() = default; |
| 57 | 34 |
| 58 ScreenWinDisplay::ScreenWinDisplay(const DisplayInfo& display_info) | 35 ScreenWinDisplay::ScreenWinDisplay(const DisplayInfo& display_info) |
| 59 : display_(CreateDisplayFromDisplayInfo(display_info)), | 36 : ScreenWinDisplay(CreateDisplayFromDisplayInfo(display_info), |
| 60 pixel_bounds_(display_info.screen_rect()) {} | 37 display_info) {} |
| 61 | 38 |
| 62 ScreenWinDisplay::ScreenWinDisplay(const ScreenWinDisplay& reference, | 39 ScreenWinDisplay::ScreenWinDisplay(const gfx::Display& display, |
| 63 const DisplayInfo& display_info) | 40 const DisplayInfo& display_info) |
| 64 : display_(CreateDisplayWithReferenceFromDisplayInfo(reference, | 41 : display_(display), |
| 65 display_info)), | |
| 66 pixel_bounds_(display_info.screen_rect()) {} | 42 pixel_bounds_(display_info.screen_rect()) {} |
| 67 | 43 |
| 68 } // namespace win | 44 } // namespace win |
| 69 } // namespace gfx | 45 } // namespace gfx |
| OLD | NEW |