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::DisplayObserver; |
| 22 |
| 23 display::Screen* CreateScreenAndroid() { |
| 24 // DisplayAndroidManager should be created only once. |
| 25 DCHECK(!display::Screen::GetScreen()) << "CreateScreenAndroid called twice"; |
| 26 |
| 27 DisplayAndroidManager* result = new DisplayAndroidManager(); |
| 28 |
| 29 JNIEnv* env = AttachCurrentThread(); |
| 30 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)result); |
| 31 return result; |
| 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 gfx::Point DisplayAndroidManager::GetCursorScreenPoint() { |
| 45 NOTIMPLEMENTED(); |
| 46 return gfx::Point(); |
| 47 } |
| 48 |
| 49 bool DisplayAndroidManager::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 50 NOTIMPLEMENTED(); |
| 51 return false; |
| 52 } |
| 53 |
| 54 gfx::NativeWindow DisplayAndroidManager::GetWindowAtScreenPoint( |
| 55 const gfx::Point& point) { |
| 56 NOTIMPLEMENTED(); |
| 57 return NULL; |
| 58 } |
| 59 |
| 60 int DisplayAndroidManager::GetNumDisplays() const { |
| 61 DCHECK_GE(displays_.size(), 1U); |
| 62 return displays_.size(); |
| 63 } |
| 64 |
| 65 std::vector<Display> DisplayAndroidManager::GetAllDisplays() const { |
| 66 DCHECK_GE(displays_.size(), 1U); |
| 67 |
| 68 std::vector<Display> result; |
| 69 for (const auto& display : displays_) |
| 70 result.push_back(display.second); |
| 71 |
| 72 return result; |
| 73 } |
| 74 |
| 75 Display DisplayAndroidManager::GetDisplayNearestWindow( |
| 76 gfx::NativeView view) const { |
| 77 ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr; |
| 78 if (window) { |
| 79 DisplayMap::const_iterator it = displays_.find(window->display_id()); |
| 80 if (it != displays_.end()) { |
| 81 return it->second; |
| 82 } |
| 83 } |
| 84 return GetPrimaryDisplay(); |
| 85 } |
| 86 |
| 87 Display DisplayAndroidManager::GetDisplayNearestPoint( |
| 88 const gfx::Point& point) const { |
| 89 NOTIMPLEMENTED(); |
| 90 return GetPrimaryDisplay(); |
| 91 } |
| 92 |
| 93 Display DisplayAndroidManager::GetDisplayMatching( |
| 94 const gfx::Rect& match_rect) const { |
| 95 NOTIMPLEMENTED(); |
| 96 return GetPrimaryDisplay(); |
| 97 } |
| 98 |
| 99 Display DisplayAndroidManager::GetPrimaryDisplay() const { |
| 100 DisplayMap::const_iterator it = displays_.find(primary_display_id_); |
| 101 // Primary display must be set before the first call to this method. |
| 102 CHECK(it != displays_.end()); |
| 103 return it->second; |
| 104 } |
| 105 |
| 106 void DisplayAndroidManager::AddObserver(DisplayObserver* observer) { |
| 107 NOTIMPLEMENTED(); |
| 108 } |
| 109 |
| 110 void DisplayAndroidManager::RemoveObserver(DisplayObserver* observer) { |
| 111 NOTIMPLEMENTED(); |
| 112 } |
| 113 |
| 114 // Methods called from Java |
| 115 |
| 116 void DisplayAndroidManager::UpdateDisplay( |
| 117 JNIEnv* env, |
| 118 const base::android::JavaParamRef<jobject>& jobject, |
| 119 jint sdkDisplayId, |
| 120 jint physicalWidth, |
| 121 jint physicalHeight, |
| 122 jint width, |
| 123 jint height, |
| 124 jfloat dipScale, |
| 125 jint rotationDegrees, |
| 126 jint bitsPerPixel, |
| 127 jint bitsPerComponent) { |
| 128 gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight); |
| 129 |
| 130 // Physical width and height might be not supported. |
| 131 if (bounds_in_pixels.IsEmpty()) |
| 132 bounds_in_pixels = gfx::Rect(width, height); |
| 133 |
| 134 const gfx::Rect bounds_in_dip = gfx::Rect( |
| 135 gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale)); |
| 136 |
| 137 display::Display display(sdkDisplayId, bounds_in_dip); |
| 138 |
| 139 display.set_device_scale_factor(dipScale); |
| 140 display.SetRotationAsDegree(rotationDegrees); |
| 141 display.set_color_depth(bitsPerPixel); |
| 142 display.set_depth_per_component(bitsPerComponent); |
| 143 display.set_is_monochrome(bitsPerComponent == 0); |
| 144 |
| 145 displays_[sdkDisplayId] = display; |
| 146 } |
| 147 |
| 148 void DisplayAndroidManager::RemoveDisplay( |
| 149 JNIEnv* env, |
| 150 const base::android::JavaParamRef<jobject>& jobject, |
| 151 jint sdkDisplayId) { |
| 152 displays_.erase(sdkDisplayId); |
| 153 } |
| 154 |
| 155 void DisplayAndroidManager::SetPrimaryDisplayId( |
| 156 JNIEnv* env, |
| 157 const base::android::JavaParamRef<jobject>& jobject, |
| 158 jint sdkDisplayId) { |
| 159 primary_display_id_ = sdkDisplayId; |
| 160 } |
| 161 |
| 162 } // namespace ui |
OLD | NEW |