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

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..ae2dd320a8f75217f621df0c78a726017f11e30b
--- /dev/null
+++ b/ui/gfx/android/shared_device_display_info.cc
@@ -0,0 +1,109 @@
+// 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;
+using base::android::ScopedJavaLocalRef;
+
+namespace gfx {
+
+base::LazyInstance<SharedDeviceDisplayInfo> g_instance_;
+
+int SharedDeviceDisplayInfo::GetDisplayHeight() {
+ SharedDeviceDisplayInfo* instance = Instance();
+ base::AutoLock(instance->lock_);
+ return instance->display_height_;
+}
+
+int SharedDeviceDisplayInfo::GetDisplayWidth() {
+ SharedDeviceDisplayInfo* instance = Instance();
+ base::AutoLock(instance->lock_);
+ return instance->display_width_;
+}
+
+int SharedDeviceDisplayInfo::GetBitsPerPixel() {
+ SharedDeviceDisplayInfo* instance = Instance();
+ base::AutoLock(instance->lock_);
+ return instance->bits_per_pixel_;
+}
+
+int SharedDeviceDisplayInfo::GetBitsPerComponent() {
+ SharedDeviceDisplayInfo* instance = Instance();
+ base::AutoLock(instance->lock_);
+ return instance->bits_per_component_;
+}
+
+double SharedDeviceDisplayInfo::GetDIPScale() {
+ SharedDeviceDisplayInfo* instance = Instance();
+ base::AutoLock(instance->lock_);
+ return instance->dip_scale_;
+}
+
+void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
Alexei Svitkine (slow) 2013/10/11 14:13:06 This should be in anon namespace at the top of the
+ jobject obj,
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale) {
+ SharedDeviceDisplayInfo::InvokeUpdate(env, obj, display_height,
+ display_width, bits_per_pixel, bits_per_component, dip_scale);
Alexei Svitkine (slow) 2013/10/11 14:13:06 Nit: Indent 2 more. Please fix throughout.
+}
+
+void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
+ jobject obj,
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale) {
+ SharedDeviceDisplayInfo* instance = SharedDeviceDisplayInfo::Instance();
+ base::AutoLock(instance->lock());
+
+ instance->UpdateDisplayInfo(env, obj, display_height,
+ display_width, bits_per_pixel, bits_per_component, dip_scale);
+}
+
+void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv*,
+ jobject,
+ jint display_height,
+ jint display_width,
+ jint bits_per_pixel,
+ jint bits_per_component,
+ jdouble dip_scale) {
+ 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);
+}
+
+SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::Instance() {
+ return g_instance_.Pointer();
+}
+
+SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() {
+ JNIEnv* env = 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()));
+}
+
+bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698