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

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

Issue 2416403002: Reland of Android: support multiple displays on C++ side (Closed)
Patch Set: Addressed comments 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/android/display_android_manager.h"
6
7 #include <jni.h>
8 #include <map>
9
10 #include "base/android/jni_android.h"
11 #include "base/stl_util.h"
12 #include "jni/DisplayAndroidManager_jni.h"
13 #include "ui/android/screen_android.h"
14 #include "ui/android/window_android.h"
15 #include "ui/display/display.h"
16
17 namespace ui {
18
19 using base::android::AttachCurrentThread;
20 using display::Display;
21 using display::DisplayObserver;
22
23 void SetScreenAndroid() {
24 // Do not override existing Screen.
25 if (display::Screen::GetScreen())
boliu 2016/11/14 15:48:53 this should be a DCHECK (or if you feel unsafe, a
Tima Vaisburd 2016/11/14 20:11:08 I think DCHECK is better. Replaced with DCHECK.
26 return;
27
28 DisplayAndroidManager* manager = new DisplayAndroidManager();
29 display::Screen::SetScreenInstance(manager);
30
31 JNIEnv* env = AttachCurrentThread();
32 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)manager);
33 }
34
35 bool RegisterScreenAndroid(JNIEnv* env) {
36 return RegisterNativesImpl(env);
37 }
38
39 DisplayAndroidManager::DisplayAndroidManager() {}
40
41 DisplayAndroidManager::~DisplayAndroidManager() {}
42
43 // Screen interface.
44
45 gfx::Point DisplayAndroidManager::GetCursorScreenPoint() {
46 NOTIMPLEMENTED();
47 return gfx::Point();
48 }
49
50 bool DisplayAndroidManager::IsWindowUnderCursor(gfx::NativeWindow window) {
51 NOTIMPLEMENTED();
52 return false;
53 }
54
55 gfx::NativeWindow DisplayAndroidManager::GetWindowAtScreenPoint(
56 const gfx::Point& point) {
57 NOTIMPLEMENTED();
58 return NULL;
59 }
60
61 int DisplayAndroidManager::GetNumDisplays() const {
62 DCHECK_GE(displays_.size(), 1U);
63 return displays_.size();
64 }
65
66 std::vector<Display> DisplayAndroidManager::GetAllDisplays() const {
67 DCHECK_GE(displays_.size(), 1U);
68
69 std::vector<Display> result;
70 for (const auto& display : displays_)
71 result.push_back(display.second);
72
73 return result;
74 }
75
76 Display DisplayAndroidManager::GetDisplayNearestWindow(
77 gfx::NativeView view) const {
78 ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr;
79 if (window) {
80 DisplayMap::const_iterator it = displays_.find(window->display_id());
81 if (it != displays_.end()) {
82 return it->second;
83 }
84 }
85 return GetPrimaryDisplay();
86 }
87
88 Display DisplayAndroidManager::GetDisplayNearestPoint(
89 const gfx::Point& point) const {
90 NOTIMPLEMENTED();
91 return GetPrimaryDisplay();
92 }
93
94 Display DisplayAndroidManager::GetDisplayMatching(
95 const gfx::Rect& match_rect) const {
96 NOTIMPLEMENTED();
97 return GetPrimaryDisplay();
98 }
99
100 Display DisplayAndroidManager::GetPrimaryDisplay() const {
101 DisplayMap::const_iterator it = displays_.find(primary_display_id_);
102 // Primary display must be set before the first call to this method.
103 CHECK(it != displays_.end());
104 return it->second;
105 }
106
107 void DisplayAndroidManager::AddObserver(DisplayObserver* observer) {
108 NOTIMPLEMENTED();
109 }
110
111 void DisplayAndroidManager::RemoveObserver(DisplayObserver* observer) {
112 NOTIMPLEMENTED();
113 }
114
115 // Methods called from Java
116
117 void DisplayAndroidManager::UpdateDisplay(
118 JNIEnv* env,
119 const base::android::JavaParamRef<jobject>& jobject,
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(sdkDisplayId, bounds_in_dip);
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 displays_[sdkDisplayId] = display;
147 }
148
149 void DisplayAndroidManager::RemoveDisplay(
150 JNIEnv* env,
151 const base::android::JavaParamRef<jobject>& jobject,
152 jint sdkDisplayId) {
153 displays_.erase(sdkDisplayId);
154 }
155
156 void DisplayAndroidManager::SetPrimaryDisplayId(
157 JNIEnv* env,
158 const base::android::JavaParamRef<jobject>& jobject,
159 jint sdkDisplayId) {
160 primary_display_id_ = sdkDisplayId;
161 }
162
163 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698