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

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

Issue 2416403002: Reland of Android: support multiple displays on C++ side (Closed)
Patch Set: Rebased and fixed webkit_tests Created 4 years 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
« no previous file with comments | « ui/android/display_android_manager.h ('k') | ui/android/dummy_screen_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::DisplayList;
22
23 void SetScreenAndroid() {
24 // Do not override existing Screen.
25 DCHECK_EQ(display::Screen::GetScreen(), nullptr);
26
27 DisplayAndroidManager* manager = new DisplayAndroidManager();
28 display::Screen::SetScreenInstance(manager);
29
30 JNIEnv* env = AttachCurrentThread();
31 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)manager);
32 }
33
34 bool RegisterScreenAndroid(JNIEnv* env) {
35 return RegisterNativesImpl(env);
36 }
37
38 DisplayAndroidManager::DisplayAndroidManager() {}
39
40 DisplayAndroidManager::~DisplayAndroidManager() {}
41
42 // Screen interface.
43
44 Display DisplayAndroidManager::GetDisplayNearestWindow(
45 gfx::NativeView view) const {
46 ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr;
47 if (window) {
48 DisplayList::Displays::const_iterator it =
49 display_list().FindDisplayById(window->display_id());
50 if (it != display_list().displays().end()) {
51 return *it;
52 }
53 }
54 return GetPrimaryDisplay();
55 }
56
57 // There is no notion of relative display positions on Android.
58 Display DisplayAndroidManager::GetDisplayNearestPoint(
59 const gfx::Point& point) const {
60 NOTIMPLEMENTED();
61 return GetPrimaryDisplay();
62 }
63
64 // There is no notion of relative display positions on Android.
65 Display DisplayAndroidManager::GetDisplayMatching(
66 const gfx::Rect& match_rect) const {
67 NOTIMPLEMENTED();
68 return GetPrimaryDisplay();
69 }
70
71 // Methods called from Java
72
73 void DisplayAndroidManager::UpdateDisplay(
74 JNIEnv* env,
75 const base::android::JavaParamRef<jobject>& jobject,
76 jint sdkDisplayId,
77 jint physicalWidth,
78 jint physicalHeight,
79 jint width,
80 jint height,
81 jfloat dipScale,
82 jint rotationDegrees,
83 jint bitsPerPixel,
84 jint bitsPerComponent) {
85 gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight);
86
87 // Physical width and height might be not supported.
88 if (bounds_in_pixels.IsEmpty())
89 bounds_in_pixels = gfx::Rect(width, height);
90
91 const gfx::Rect bounds_in_dip = gfx::Rect(
92 gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale));
93
94 display::Display display(sdkDisplayId, bounds_in_dip);
95 if (!Display::HasForceDeviceScaleFactor())
96 display.set_device_scale_factor(dipScale);
97
98 display.SetRotationAsDegree(rotationDegrees);
99 display.set_color_depth(bitsPerPixel);
100 display.set_depth_per_component(bitsPerComponent);
101 display.set_is_monochrome(bitsPerComponent == 0);
102
103 ProcessDisplayChanged(display, sdkDisplayId == primary_display_id_);
104 }
105
106 void DisplayAndroidManager::RemoveDisplay(
107 JNIEnv* env,
108 const base::android::JavaParamRef<jobject>& jobject,
109 jint sdkDisplayId) {
110 display_list().RemoveDisplay(sdkDisplayId);
111 }
112
113 void DisplayAndroidManager::SetPrimaryDisplayId(
114 JNIEnv* env,
115 const base::android::JavaParamRef<jobject>& jobject,
116 jint sdkDisplayId) {
117 primary_display_id_ = sdkDisplayId;
118 }
119
120 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/display_android_manager.h ('k') | ui/android/dummy_screen_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698