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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/display/android/display_android_manager.cc
diff --git a/ui/display/android/display_android_manager.cc b/ui/display/android/display_android_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..393e01168124997a9f883203226b1c60a50aa4cb
--- /dev/null
+++ b/ui/display/android/display_android_manager.cc
@@ -0,0 +1,165 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/display/android/display_android_manager.h"
+
+#include <jni.h>
+#include <map>
+
+#include "base/logging.h"
+#include "jni/DisplayAndroidManager_jni.h"
+#include "ui/android/window_android.h"
+#include "ui/display/display.h"
+#include "ui/display/display_export.h"
+#include "ui/display/screen.h"
+
+namespace display {
+
+class DisplayAndroidManager : public Screen {
+ public:
+ DisplayAndroidManager() {}
+ ~DisplayAndroidManager() {}
+
+ // 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.
+ DisplayAndroidManager(const DisplayAndroidManager& rhs) = delete;
+ DisplayAndroidManager& operator=(const DisplayAndroidManager& rhs) = delete;
+
+ // Screen interface.
boliu 2016/11/01 17:11:05 where are the overrides?
Tima Vaisburd 2016/11/01 23:04:36 Done.
+
+ 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.
+
+ bool IsWindowUnderCursor(gfx::NativeWindow window) {
+ NOTIMPLEMENTED();
+ return false;
+ }
+
+ gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) {
+ NOTIMPLEMENTED();
+ return NULL;
+ }
+
+ int GetNumDisplays() const {
+ DCHECK_GE(displays_.size(), 1U);
+ return displays_.size();
+ }
+
+ std::vector<Display> GetAllDisplays() const {
+ DCHECK_GE(displays_.size(), 1U);
+
+ std::vector<Display> result;
+ for (const auto& display : displays_)
+ result.push_back(display.second);
+
+ return result;
+ }
+
+ Display GetDisplayNearestWindow(gfx::NativeView view) const {
+ DCHECK(view);
+ ui::WindowAndroid* window = view->GetWindowAndroid();
+
+ if (window && displays_.count(window->display_id()))
+ return GetFromMap(window->display_id());
+ else
+ return GetPrimaryDisplay();
+ }
+
+ Display GetDisplayNearestPoint(const gfx::Point& point) const {
+ NOTIMPLEMENTED();
+ 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.
+ }
+
+ Display GetDisplayMatching(const gfx::Rect& match_rect) const {
+ NOTIMPLEMENTED();
+ return Display();
boliu 2016/11/01 17:11:05 ditto
Tima Vaisburd 2016/11/01 23:04:36 Done.
+ }
+
+ Display GetPrimaryDisplay() const {
+ // Primary display must be set before the first call to this method.
+ 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.
+ return GetFromMap(primary_display_id_);
+ }
+
+ // Native side observers are not implemented for Android.
+ void AddObserver(DisplayObserver* observer) {}
boliu 2016/11/01 17:11:05 add NOTIMPLEMENTED
Tima Vaisburd 2016/11/01 23:04:36 Done.
+
+ void RemoveObserver(DisplayObserver* observer) {}
+
+ // Helper methods that respond to Java calls.
+
+ void UpdateDisplay(int display_id, const Display& display) {
+ displays_[display_id] = display;
+ }
+
+ 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.
+
+ void SetPrimaryDisplayId(int display_id) { primary_display_id_ = display_id; }
+
+ private:
+ 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.
+ 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().
+ return displays_.find(id)->second;
+ }
+
+ std::map<int, Display> displays_;
+ int primary_display_id_ = 0;
+};
+
+Screen* CreateNativeScreen() {
+ return new DisplayAndroidManager;
+}
+
+bool RegisterDisplayAndroidManager(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+// Called from Java
+
+static void UpdateDisplay(JNIEnv* env,
+ const base::android::JavaParamRef<jclass>& jcaller,
+ jint sdkDisplayId,
+ jint physicalWidth,
+ jint physicalHeight,
+ jint width,
+ jint height,
+ jfloat dipScale,
+ jint rotationDegrees,
+ jint bitsPerPixel,
+ jint bitsPerComponent) {
+ gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight);
+
+ // Physical width and height might be not supported.
+ if (bounds_in_pixels.IsEmpty())
+ bounds_in_pixels = gfx::Rect(width, height);
+
+ const gfx::Rect bounds_in_dip = gfx::Rect(
+ gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale));
+
+ 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.
+
+ display.set_device_scale_factor(dipScale);
+ display.SetRotationAsDegree(rotationDegrees);
+ display.set_color_depth(bitsPerPixel);
+ display.set_depth_per_component(bitsPerComponent);
+ display.set_is_monochrome(bitsPerComponent == 0);
+
+ static_cast<DisplayAndroidManager*>(Screen::GetScreen())
+ ->UpdateDisplay(sdkDisplayId, display);
+}
+
+static void RemoveDisplay(JNIEnv* env,
+ const base::android::JavaParamRef<jclass>& jcaller,
+ jint sdkDisplayId) {
+ static_cast<DisplayAndroidManager*>(Screen::GetScreen())
+ ->RemoveDisplay(sdkDisplayId);
+}
+
+static void SetPrimaryDisplayId(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jclass>& jcaller,
+ jint sdkDisplayId) {
+ static_cast<DisplayAndroidManager*>(Screen::GetScreen())
+ ->SetPrimaryDisplayId(sdkDisplayId);
+}
+
+} // namespace display

Powered by Google App Engine
This is Rietveld 408576698