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

Side by Side Diff: ui/display/android/screen_android.cc

Issue 2416403002: Reland of Android: support multiple displays on C++ side (Closed)
Patch Set: Update a map of Displays from Java Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/display/screen.h" 5 #include "ui/display/android/screen_android.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "ui/android/window_android.h"
9 #include "ui/display/display.h"
10 #include "ui/gfx/android/device_display_info.h"
11 #include "ui/gfx/geometry/size_conversions.h"
12 9
13 namespace display { 10 namespace display {
14 11
15 class ScreenAndroid : public Screen {
16 public:
17 ScreenAndroid() {}
18
19 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
20
21 bool IsWindowUnderCursor(gfx::NativeWindow window) override {
22 NOTIMPLEMENTED();
23 return false;
24 }
25
26 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
27 NOTIMPLEMENTED();
28 return NULL;
29 }
30
31 Display GetPrimaryDisplay() const override {
32 gfx::DeviceDisplayInfo device_info;
33 const float device_scale_factor = device_info.GetDIPScale();
34 // Note: GetPhysicalDisplayWidth/Height() does not subtract window
35 // decorations etc. Use it instead of GetDisplayWidth/Height() when
36 // available.
37 const gfx::Rect bounds_in_pixels =
38 gfx::Rect(device_info.GetPhysicalDisplayWidth()
39 ? device_info.GetPhysicalDisplayWidth()
40 : device_info.GetDisplayWidth(),
41 device_info.GetPhysicalDisplayHeight()
42 ? device_info.GetPhysicalDisplayHeight()
43 : device_info.GetDisplayHeight());
44 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize(
45 bounds_in_pixels.size(), 1.0f / device_scale_factor));
46 Display display(0, bounds_in_dip);
47 if (!Display::HasForceDeviceScaleFactor())
48 display.set_device_scale_factor(device_scale_factor);
49 display.SetRotationAsDegree(device_info.GetRotationDegrees());
50 display.set_color_depth(device_info.GetBitsPerPixel());
51 display.set_depth_per_component(device_info.GetBitsPerComponent());
52 display.set_is_monochrome(device_info.GetBitsPerComponent() == 0);
53 return display;
54 }
55
56 Display GetDisplayNearestWindow(gfx::NativeView view) const override {
57 return GetPrimaryDisplay();
58 }
59
60 Display GetDisplayNearestPoint(const gfx::Point& point) const override {
61 return GetPrimaryDisplay();
62 }
63
64 int GetNumDisplays() const override { return 1; }
65
66 std::vector<Display> GetAllDisplays() const override {
67 return std::vector<Display>(1, GetPrimaryDisplay());
68 }
69
70 Display GetDisplayMatching(const gfx::Rect& match_rect) const override {
71 return GetPrimaryDisplay();
72 }
73
74 void AddObserver(DisplayObserver* observer) override {
75 // no display change on Android.
76 }
77
78 void RemoveObserver(DisplayObserver* observer) override {
79 // no display change on Android.
80 }
81
82 private:
83 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid);
84 };
85
86 Screen* CreateNativeScreen() { 12 Screen* CreateNativeScreen() {
87 return new ScreenAndroid; 13 return new ScreenAndroid;
88 } 14 }
89 15
16 ScreenAndroid::ScreenAndroid() {}
17
18 ScreenAndroid::~ScreenAndroid() {}
19
20 gfx::Point ScreenAndroid::GetCursorScreenPoint() {
21 return gfx::Point();
22 }
23
24 bool ScreenAndroid::IsWindowUnderCursor(gfx::NativeWindow window) {
25 NOTIMPLEMENTED();
26 return false;
27 }
28
29 gfx::NativeWindow ScreenAndroid::GetWindowAtScreenPoint(
30 const gfx::Point& point) {
31 NOTIMPLEMENTED();
32 return NULL;
33 }
34
35 int ScreenAndroid::GetNumDisplays() const {
36 DCHECK_GE(displays_.size(), 1U);
37 return displays_.size();
38 }
39
40 std::vector<Display> ScreenAndroid::GetAllDisplays() const {
41 DCHECK_GE(displays_.size(), 1U);
42
43 std::vector<Display> result;
44 for (const auto& display : displays_)
45 result.push_back(display.second);
46
47 return result;
48 }
49
50 Display ScreenAndroid::GetDisplayNearestWindow(gfx::NativeView view) const {
51 DCHECK(view);
52 ui::WindowAndroid* window = view->GetWindowAndroid();
53
54 DCHECK(window);
boliu 2016/10/26 17:24:20 this may not hold either
55 int display_id = window->display_id();
56
57 DCHECK_EQ(displays_.count(display_id), 1U);
Tima Vaisburd 2016/10/26 02:02:18 This DCHECK will succeed because DisplayAndroid is
boliu 2016/10/26 17:24:20 It's more subtle than that. In theory, it's possib
Tima Vaisburd 2016/10/26 17:58:10 I was asking whether in GetPrimaryDisplay() and ma
boliu 2016/10/26 18:24:44 Primary display should be pushed down as well. And
58 return displays_.find(display_id)->second;
mthiesse 2016/10/26 14:49:49 I think we need to guarantee always returning a di
boliu 2016/10/26 17:24:20 +1 looks like most desktop implementations fallbac
Tima Vaisburd 2016/10/27 07:55:58 Following the offline conversation I add the prima
59 }
60
61 Display ScreenAndroid::GetDisplayNearestPoint(const gfx::Point& point) const {
62 NOTIMPLEMENTED();
63 return Display();
64 }
65
66 Display ScreenAndroid::GetDisplayMatching(const gfx::Rect& match_rect) const {
67 NOTIMPLEMENTED();
68 return Display();
69 }
70
71 Display ScreenAndroid::GetPrimaryDisplay() const {
72 const int kPrimaryDisplayId = 0;
boliu 2016/10/26 18:24:44 where did we decide 0 is the primary one?
Tima Vaisburd 2016/10/27 07:55:58 Display.DEFAULT_DISPLAY is defined as 0, I added t
73 DCHECK_EQ(displays_.count(kPrimaryDisplayId), 1U);
74 return displays_.find(kPrimaryDisplayId)->second;
75 }
76
77 // Native side observers are not implemenetd for Android.
78 void ScreenAndroid::AddObserver(DisplayObserver* observer) {}
79
80 void ScreenAndroid::RemoveObserver(DisplayObserver* observer) {}
81
82 void ScreenAndroid::UpdateDisplay(int display_id, const Display& display) {
83 displays_[display_id] = display;
84 }
85
86 void ScreenAndroid::RemoveDisplay(int display_id) {
87 displays_.erase(display_id);
88 }
89
90 } // namespace display 90 } // namespace display
OLDNEW
« ui/display/android/screen_android.h ('K') | « ui/display/android/screen_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698