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

Side by Side Diff: ui/gfx/android/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 patch 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/android/device_display_info.h" 5 #include "ui/gfx/android/device_display_info.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "ui/gfx/android/shared_device_display_info.h"
8 #include "base/android/jni_string.h"
9 #include "base/logging.h"
10 #include "jni/DeviceDisplayInfo_jni.h"
11
12 using base::android::AttachCurrentThread;
13 using base::android::ScopedJavaLocalRef;
14 8
15 namespace gfx { 9 namespace gfx {
16 10
17 DeviceDisplayInfo::DeviceDisplayInfo() { 11 DeviceDisplayInfo::DeviceDisplayInfo() {
18 JNIEnv* env = AttachCurrentThread();
19 j_device_info_.Reset(Java_DeviceDisplayInfo_create(env,
20 base::android::GetApplicationContext()));
21 } 12 }
22 13
23 DeviceDisplayInfo::~DeviceDisplayInfo() { 14 DeviceDisplayInfo::~DeviceDisplayInfo() {
24 } 15 }
25 16
26 int DeviceDisplayInfo::GetDisplayHeight() { 17 int DeviceDisplayInfo::GetDisplayHeight() {
27 JNIEnv* env = AttachCurrentThread(); 18 return SharedDeviceDisplayInfo::GetDisplayHeight();
28 jint result =
29 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj());
30 return static_cast<int>(result);
31 } 19 }
32 20
33 int DeviceDisplayInfo::GetDisplayWidth() { 21 int DeviceDisplayInfo::GetDisplayWidth() {
34 JNIEnv* env = AttachCurrentThread(); 22 return SharedDeviceDisplayInfo::GetDisplayWidth();
35 jint result =
36 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj());
37 return static_cast<int>(result);
38 } 23 }
39 24
40 int DeviceDisplayInfo::GetBitsPerPixel() { 25 int DeviceDisplayInfo::GetBitsPerPixel() {
41 JNIEnv* env = AttachCurrentThread(); 26 return SharedDeviceDisplayInfo::GetBitsPerPixel();
42 jint result =
43 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj());
44 return static_cast<int>(result);
45 } 27 }
46 28
47 int DeviceDisplayInfo::GetBitsPerComponent() { 29 int DeviceDisplayInfo::GetBitsPerComponent() {
48 JNIEnv* env = AttachCurrentThread(); 30 return SharedDeviceDisplayInfo::GetBitsPerComponent();
49 jint result =
50 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj());
51 return static_cast<int>(result);
52 } 31 }
53 32
54 double DeviceDisplayInfo::GetDIPScale() { 33 double DeviceDisplayInfo::GetDIPScale() {
55 JNIEnv* env = AttachCurrentThread(); 34 return SharedDeviceDisplayInfo::GetDIPScale();
56 jdouble result =
57 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj());
58 return static_cast<double>(result);
59 }
60
61 // static
62 bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) {
63 return RegisterNativesImpl(env);
64 } 35 }
65 36
66 } // namespace gfx 37 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698