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

Unified Diff: ui/gfx/android/shared_device_display_info.cc

Issue 26129009: Cache DeviceDisplayInfo data in shared structure on native side to avoid frequent JNI calls. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Updated by review comments. Created 7 years, 2 months 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/gfx/android/shared_device_display_info.cc
diff --git a/ui/gfx/android/shared_device_display_info.cc b/ui/gfx/android/shared_device_display_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d35686f0db63d7927ed4cbc0f796a5a2a13ac19
--- /dev/null
+++ b/ui/gfx/android/shared_device_display_info.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 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/gfx/android/shared_device_display_info.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/logging.h"
+#include "jni/DeviceDisplayInfo_jni.h"
+
+using base::android::AttachCurrentThread;
+
+namespace gfx {
+
+// static JNI call
+static void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
+ jobject obj,
Alexei Svitkine (slow) 2013/10/22 21:01:54 Nit: Align params.
ostap 2013/10/22 21:40:42 Done.
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale,
+ jint smallest_dip_width) {
+ SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj,
+ display_height, display_width, bits_per_pixel, bits_per_component,
+ dip_scale, smallest_dip_width);
+}
+
+SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() {
Alexei Svitkine (slow) 2013/10/22 21:01:54 Nit: Add "// static" above this.
ostap 2013/10/22 21:40:42 Done.
+ return Singleton<SharedDeviceDisplayInfo>::get();
+}
+
+int SharedDeviceDisplayInfo::GetDisplayHeight() {
+ base::AutoLock autolock(lock_);
+ return display_height_;
+}
+
+int SharedDeviceDisplayInfo::GetDisplayWidth() {
+ base::AutoLock autolock(lock_);
+ return display_width_;
+}
+
+int SharedDeviceDisplayInfo::GetBitsPerPixel() {
+ base::AutoLock autolock(lock_);
+ return bits_per_pixel_;
+}
+
+int SharedDeviceDisplayInfo::GetBitsPerComponent() {
+ base::AutoLock autolock(lock_);
+ return bits_per_component_;
+}
+
+double SharedDeviceDisplayInfo::GetDIPScale() {
+ base::AutoLock autolock(lock_);
+ return dip_scale_;
+}
+
+int SharedDeviceDisplayInfo::GetSmallestDIPWidth() {
+ base::AutoLock autolock(lock_);
+ return smallest_dip_width_;
Alexei Svitkine (slow) 2013/10/22 21:01:54 Can you add a DCHECK_NE(0, smallest_dip_width_); h
ostap 2013/10/22 21:40:42 Done.
+}
+
+bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
Alexei Svitkine (slow) 2013/10/22 21:01:54 Nit: Add "// static" above this.
ostap 2013/10/22 21:40:42 Done.
+ return RegisterNativesImpl(env);
+}
+
+void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
+ jobject obj,
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale,
+ jint smallest_dip_width) {
+ base::AutoLock autolock(lock_);
+
+ UpdateDisplayInfo(env, obj, display_height,
+ display_width, bits_per_pixel, bits_per_component, dip_scale,
+ smallest_dip_width);
+}
+
+SharedDeviceDisplayInfo::SharedDeviceDisplayInfo()
+ : display_height_(0),
+ display_width_(0),
+ bits_per_pixel_(0),
+ bits_per_component_(0),
+ dip_scale_(0),
+ smallest_dip_width_(0)
+
Alexei Svitkine (slow) 2013/10/22 21:01:54 Nit: Remove empty line.
ostap 2013/10/22 21:40:42 Done.
+{
+ JNIEnv* env = base::android::AttachCurrentThread();
+ j_device_info_.Reset(
+ Java_DeviceDisplayInfo_createWithListener(env,
+ base::android::GetApplicationContext()));
+ UpdateDisplayInfo(env, j_device_info_.obj(),
+ Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
+ Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
+ Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
+ Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
+ Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()),
+ Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()));
+}
+
+void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env,
+ jobject jobj,
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale,
+ jint smallest_dip_width) {
+ display_height_ = static_cast<int>(display_height);
+ display_width_ = static_cast<int>(display_width);
+ bits_per_pixel_ = static_cast<int>(bits_per_pixel);
+ bits_per_component_ = static_cast<int>(bits_per_component);
+ dip_scale_ = static_cast<double>(dip_scale);
+ smallest_dip_width_ = static_cast<int>(smallest_dip_width);
+}
+
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698