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

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

Issue 2416403002: Reland of Android: support multiple displays on C++ side (Closed)
Patch Set: JNI generated and registered in ui/android; ensure primary DisplayAndroid by going to app context 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
(Empty)
1 // Copyright 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/display/android/display_android_manager.h"
6
7 #include <jni.h>
8 #include <map>
9
10 #include "base/logging.h"
11 #include "jni/DisplayAndroidManager_jni.h"
12 #include "ui/android/window_android.h"
13 #include "ui/display/display.h"
14 #include "ui/display/display_export.h"
15 #include "ui/display/screen.h"
16
17 namespace display {
18
19 class DisplayAndroidManager : public Screen {
20 public:
21 DisplayAndroidManager() {}
22 ~DisplayAndroidManager() {}
23
24 // Disallow copy and assign.
boliu 2016/11/01 17:11:05 https://cs.chromium.org/chromium/src/base/macros.h
Tima Vaisburd 2016/11/01 23:04:36 Done.
25 DisplayAndroidManager(const DisplayAndroidManager& rhs) = delete;
26 DisplayAndroidManager& operator=(const DisplayAndroidManager& rhs) = delete;
27
28 // Screen interface.
boliu 2016/11/01 17:11:05 where are the overrides?
Tima Vaisburd 2016/11/01 23:04:36 Done.
29
30 gfx::Point GetCursorScreenPoint() { return gfx::Point(); }
boliu 2016/11/01 17:11:05 this one is NOTIMPLEMENTED as well
Tima Vaisburd 2016/11/01 23:04:36 Done.
31
32 bool IsWindowUnderCursor(gfx::NativeWindow window) {
33 NOTIMPLEMENTED();
34 return false;
35 }
36
37 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) {
38 NOTIMPLEMENTED();
39 return NULL;
40 }
41
42 int GetNumDisplays() const {
43 DCHECK_GE(displays_.size(), 1U);
44 return displays_.size();
45 }
46
47 std::vector<Display> GetAllDisplays() const {
48 DCHECK_GE(displays_.size(), 1U);
49
50 std::vector<Display> result;
51 for (const auto& display : displays_)
52 result.push_back(display.second);
53
54 return result;
55 }
56
57 Display GetDisplayNearestWindow(gfx::NativeView view) const {
58 DCHECK(view);
59 ui::WindowAndroid* window = view->GetWindowAndroid();
60
61 if (window && displays_.count(window->display_id()))
62 return GetFromMap(window->display_id());
63 else
64 return GetPrimaryDisplay();
65 }
66
67 Display GetDisplayNearestPoint(const gfx::Point& point) const {
68 NOTIMPLEMENTED();
69 return Display();
boliu 2016/11/01 17:11:05 old code returns primary display, so keep doing th
Tima Vaisburd 2016/11/01 23:04:36 Done.
70 }
71
72 Display GetDisplayMatching(const gfx::Rect& match_rect) const {
73 NOTIMPLEMENTED();
74 return Display();
boliu 2016/11/01 17:11:05 ditto
Tima Vaisburd 2016/11/01 23:04:36 Done.
75 }
76
77 Display GetPrimaryDisplay() const {
78 // Primary display must be set before the first call to this method.
79 CHECK_EQ(displays_.count(primary_display_id_), 1U);
boliu 2016/11/01 17:11:04 since this is a release check, avoid looking up th
Tima Vaisburd 2016/11/01 23:04:36 Done.
80 return GetFromMap(primary_display_id_);
81 }
82
83 // Native side observers are not implemented for Android.
84 void AddObserver(DisplayObserver* observer) {}
boliu 2016/11/01 17:11:05 add NOTIMPLEMENTED
Tima Vaisburd 2016/11/01 23:04:36 Done.
85
86 void RemoveObserver(DisplayObserver* observer) {}
87
88 // Helper methods that respond to Java calls.
89
90 void UpdateDisplay(int display_id, const Display& display) {
91 displays_[display_id] = display;
92 }
93
94 void RemoveDisplay(int display_id) { displays_.erase(display_id); }
boliu 2016/11/01 17:11:04 DCHECK key already exists
Tima Vaisburd 2016/11/01 23:04:36 Done.
95
96 void SetPrimaryDisplayId(int display_id) { primary_display_id_ = display_id; }
97
98 private:
99 Display GetFromMap(int id) const {
boliu 2016/11/01 17:11:05 in both places, having this helper is actually for
Tima Vaisburd 2016/11/01 23:04:36 Done.
100 DCHECK_EQ(displays_.count(id), 1U);
boliu 2016/11/01 17:11:05 fyi there's base::ContainsKey
Tima Vaisburd 2016/11/01 23:04:36 This method is gone, but using in RemoveDisplay().
101 return displays_.find(id)->second;
102 }
103
104 std::map<int, Display> displays_;
105 int primary_display_id_ = 0;
106 };
107
108 Screen* CreateNativeScreen() {
109 return new DisplayAndroidManager;
110 }
111
112 bool RegisterDisplayAndroidManager(JNIEnv* env) {
113 return RegisterNativesImpl(env);
114 }
115
116 // Called from Java
117
118 static void UpdateDisplay(JNIEnv* env,
119 const base::android::JavaParamRef<jclass>& jcaller,
120 jint sdkDisplayId,
121 jint physicalWidth,
122 jint physicalHeight,
123 jint width,
124 jint height,
125 jfloat dipScale,
126 jint rotationDegrees,
127 jint bitsPerPixel,
128 jint bitsPerComponent) {
129 gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight);
130
131 // Physical width and height might be not supported.
132 if (bounds_in_pixels.IsEmpty())
133 bounds_in_pixels = gfx::Rect(width, height);
134
135 const gfx::Rect bounds_in_dip = gfx::Rect(
136 gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale));
137
138 display::Display display = display::Display(0, bounds_in_dip);
boliu 2016/11/01 17:11:05 use id here also I think declaration syntax might
Tima Vaisburd 2016/11/01 23:04:36 Done.
139
140 display.set_device_scale_factor(dipScale);
141 display.SetRotationAsDegree(rotationDegrees);
142 display.set_color_depth(bitsPerPixel);
143 display.set_depth_per_component(bitsPerComponent);
144 display.set_is_monochrome(bitsPerComponent == 0);
145
146 static_cast<DisplayAndroidManager*>(Screen::GetScreen())
147 ->UpdateDisplay(sdkDisplayId, display);
148 }
149
150 static void RemoveDisplay(JNIEnv* env,
151 const base::android::JavaParamRef<jclass>& jcaller,
152 jint sdkDisplayId) {
153 static_cast<DisplayAndroidManager*>(Screen::GetScreen())
154 ->RemoveDisplay(sdkDisplayId);
155 }
156
157 static void SetPrimaryDisplayId(
158 JNIEnv* env,
159 const base::android::JavaParamRef<jclass>& jcaller,
160 jint sdkDisplayId) {
161 static_cast<DisplayAndroidManager*>(Screen::GetScreen())
162 ->SetPrimaryDisplayId(sdkDisplayId);
163 }
164
165 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698