| OLD | NEW |
| (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 | |
| 96 display.set_device_scale_factor(dipScale); | |
| 97 display.SetRotationAsDegree(rotationDegrees); | |
| 98 display.set_color_depth(bitsPerPixel); | |
| 99 display.set_depth_per_component(bitsPerComponent); | |
| 100 display.set_is_monochrome(bitsPerComponent == 0); | |
| 101 | |
| 102 ProcessDisplayChanged(display, sdkDisplayId == primary_display_id_); | |
| 103 } | |
| 104 | |
| 105 void DisplayAndroidManager::RemoveDisplay( | |
| 106 JNIEnv* env, | |
| 107 const base::android::JavaParamRef<jobject>& jobject, | |
| 108 jint sdkDisplayId) { | |
| 109 display_list().RemoveDisplay(sdkDisplayId); | |
| 110 } | |
| 111 | |
| 112 void DisplayAndroidManager::SetPrimaryDisplayId( | |
| 113 JNIEnv* env, | |
| 114 const base::android::JavaParamRef<jobject>& jobject, | |
| 115 jint sdkDisplayId) { | |
| 116 primary_display_id_ = sdkDisplayId; | |
| 117 } | |
| 118 | |
| 119 } // namespace ui | |
| OLD | NEW |