diff options
author | sl.ostapenko@samsung.com <sl.ostapenko@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 18:18:14 +0000 |
---|---|---|
committer | sl.ostapenko@samsung.com <sl.ostapenko@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 18:18:14 +0000 |
commit | ae95af6eb848a131072b19bed599a63c3167cd8e (patch) | |
tree | 2269d7eff0447ee8ffca8af16c496ed9d9305b82 /ui/gfx | |
parent | e5b112169653322eaf6d7e8a7816753f919bf0f9 (diff) | |
download | chromium_src-ae95af6eb848a131072b19bed599a63c3167cd8e.zip chromium_src-ae95af6eb848a131072b19bed599a63c3167cd8e.tar.gz chromium_src-ae95af6eb848a131072b19bed599a63c3167cd8e.tar.bz2 |
Cache DeviceDisplayInfo data in shared structure on native side to avoid frequent JNI calls.
BUG=265008
Partial fix for bug 265008.
GetDisplayWidth and GetDisplayHeight are called for tile creation.
Review URL: https://codereview.chromium.org/26129009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230472 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/android/device_display_info.cc | 45 | ||||
-rw-r--r-- | ui/gfx/android/device_display_info.h | 6 | ||||
-rw-r--r-- | ui/gfx/android/gfx_jni_registrar.cc | 7 | ||||
-rw-r--r-- | ui/gfx/android/shared_device_display_info.cc | 128 | ||||
-rw-r--r-- | ui/gfx/android/shared_device_display_info.h | 68 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 2 |
6 files changed, 209 insertions, 47 deletions
diff --git a/ui/gfx/android/device_display_info.cc b/ui/gfx/android/device_display_info.cc index 23c6c2e..2de8440 100644 --- a/ui/gfx/android/device_display_info.cc +++ b/ui/gfx/android/device_display_info.cc @@ -4,70 +4,39 @@ #include "ui/gfx/android/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; +#include "ui/gfx/android/shared_device_display_info.h" namespace gfx { DeviceDisplayInfo::DeviceDisplayInfo() { - JNIEnv* env = AttachCurrentThread(); - j_device_info_.Reset(Java_DeviceDisplayInfo_create(env, - base::android::GetApplicationContext())); } DeviceDisplayInfo::~DeviceDisplayInfo() { } int DeviceDisplayInfo::GetDisplayHeight() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()); - return static_cast<int>(result); + return SharedDeviceDisplayInfo::GetInstance()->GetDisplayHeight(); } int DeviceDisplayInfo::GetDisplayWidth() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()); - return static_cast<int>(result); + return SharedDeviceDisplayInfo::GetInstance()->GetDisplayWidth(); } int DeviceDisplayInfo::GetBitsPerPixel() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()); - return static_cast<int>(result); + return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerPixel(); } int DeviceDisplayInfo::GetBitsPerComponent() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()); - return static_cast<int>(result); + return SharedDeviceDisplayInfo::GetInstance()->GetBitsPerComponent(); } double DeviceDisplayInfo::GetDIPScale() { - JNIEnv* env = AttachCurrentThread(); - jdouble result = - Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()); - return static_cast<double>(result); + return SharedDeviceDisplayInfo::GetInstance()->GetDIPScale(); } int DeviceDisplayInfo::GetSmallestDIPWidth() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()); - return static_cast<int>(result); -} - -// static -bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { - return RegisterNativesImpl(env); + return SharedDeviceDisplayInfo::GetInstance()->GetSmallestDIPWidth(); } } // namespace gfx diff --git a/ui/gfx/android/device_display_info.h b/ui/gfx/android/device_display_info.h index ace8569..83968e9 100644 --- a/ui/gfx/android/device_display_info.h +++ b/ui/gfx/android/device_display_info.h @@ -8,7 +8,6 @@ #include <jni.h> #include <string> -#include "base/android/scoped_java_ref.h" #include "base/basictypes.h" #include "ui/gfx/gfx_export.h" @@ -40,12 +39,7 @@ class GFX_EXPORT DeviceDisplayInfo { // Smallest possible screen size in density-independent pixels. int GetSmallestDIPWidth(); - // Registers methods with JNI and returns true if succeeded. - static bool RegisterDeviceDisplayInfo(JNIEnv* env); - private: - base::android::ScopedJavaGlobalRef<jobject> j_device_info_; - DISALLOW_COPY_AND_ASSIGN(DeviceDisplayInfo); }; diff --git a/ui/gfx/android/gfx_jni_registrar.cc b/ui/gfx/android/gfx_jni_registrar.cc index 8aa8551..be60a33 100644 --- a/ui/gfx/android/gfx_jni_registrar.cc +++ b/ui/gfx/android/gfx_jni_registrar.cc @@ -6,15 +6,16 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" -#include "ui/gfx/android/device_display_info.h" #include "ui/gfx/android/java_bitmap.h" +#include "ui/gfx/android/shared_device_display_info.h" namespace gfx { namespace android { static base::android::RegistrationMethod kGfxRegisteredMethods[] = { - { "DeviceDisplayInfo", gfx::DeviceDisplayInfo::RegisterDeviceDisplayInfo }, - { "JavaBitmap", gfx::JavaBitmap::RegisterJavaBitmap }, + { "SharedDeviceDisplayInfo", + SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo }, + { "JavaBitmap", JavaBitmap::RegisterJavaBitmap }, }; bool RegisterJni(JNIEnv* env) { 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 0000000..9ac18d0 --- /dev/null +++ b/ui/gfx/android/shared_device_display_info.cc @@ -0,0 +1,128 @@ +// Copyright 2013 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" + +namespace gfx { + +// static JNI call +static void UpdateSharedDeviceDisplayInfo(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) { + SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, + display_height, display_width, bits_per_pixel, bits_per_component, + dip_scale, smallest_dip_width); +} + +// static +SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { + return Singleton<SharedDeviceDisplayInfo>::get(); +} + +int SharedDeviceDisplayInfo::GetDisplayHeight() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, display_height_); + return display_height_; +} + +int SharedDeviceDisplayInfo::GetDisplayWidth() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, display_width_); + return display_width_; +} + +int SharedDeviceDisplayInfo::GetBitsPerPixel() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, bits_per_pixel_); + return bits_per_pixel_; +} + +int SharedDeviceDisplayInfo::GetBitsPerComponent() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, bits_per_component_); + return bits_per_component_; +} + +double SharedDeviceDisplayInfo::GetDIPScale() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, dip_scale_); + return dip_scale_; +} + +int SharedDeviceDisplayInfo::GetSmallestDIPWidth() { + base::AutoLock autolock(lock_); + DCHECK_NE(0, smallest_dip_width_); + return smallest_dip_width_; +} + +// static +bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { + 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) { + 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())); +} + +SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() { +} + +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 diff --git a/ui/gfx/android/shared_device_display_info.h b/ui/gfx/android/shared_device_display_info.h new file mode 100644 index 0000000..1e1fc0c --- /dev/null +++ b/ui/gfx/android/shared_device_display_info.h @@ -0,0 +1,68 @@ +// Copyright 2013 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. + +#ifndef UI_GFX_ANDROID_SHARED_DEVICE_DISPLAY_INFO_H_ +#define UI_GFX_ANDROID_SHARED_DEVICE_DISPLAY_INFO_H_ + +#include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" +#include "base/memory/singleton.h" +#include "base/synchronization/lock.h" + +namespace gfx { + +// Facilitates access to device information typically only +// available using the Android SDK, including Display properties. +class SharedDeviceDisplayInfo { + public: + static SharedDeviceDisplayInfo* GetInstance(); + + int GetDisplayHeight(); + int GetDisplayWidth(); + int GetBitsPerPixel(); + int GetBitsPerComponent(); + double GetDIPScale(); + int GetSmallestDIPWidth(); + + // Registers methods with JNI and returns true if succeeded. + static bool RegisterSharedDeviceDisplayInfo(JNIEnv* env); + + void InvokeUpdate(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); + private: + friend struct DefaultSingletonTraits<SharedDeviceDisplayInfo>; + + SharedDeviceDisplayInfo(); + ~SharedDeviceDisplayInfo(); + void 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); + + base::Lock lock_; + base::android::ScopedJavaGlobalRef<jobject> j_device_info_; + + int display_height_; + int display_width_; + int bits_per_pixel_; + int bits_per_component_; + double dip_scale_; + int smallest_dip_width_; + + DISALLOW_COPY_AND_ASSIGN(SharedDeviceDisplayInfo); +}; + +} // namespace gfx + +#endif // UI_GFX_ANDROID_SHARED_DEVICE_DISPLAY_INFO_H_ diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index 09a4a53..7364276 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -33,6 +33,8 @@ 'android/gfx_jni_registrar.h', 'android/java_bitmap.cc', 'android/java_bitmap.h', + 'android/shared_device_display_info.cc', + 'android/shared_device_display_info.h', 'animation/animation.cc', 'animation/animation.h', 'animation/animation_container.cc', |