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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/android/shared_device_display_info.h"
6
7 #include "base/android/jni_android.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
15 void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
Alexei Svitkine (slow) 2013/10/15 15:13:07 Surround this with the anon namespace (it can stil
ostap 2013/10/15 19:41:27 If I do so it is not visible from JNI. I get this
Alexei Svitkine (slow) 2013/10/22 19:15:24 Got it. Then, please re-add the static keyword to
16 jobject obj,
17 jint display_height,
18 jint display_width,
19 jint bits_per_pixel,
20 jint bits_per_component,
21 jdouble dip_scale) {
22 gfx::SharedDeviceDisplayInfo::InvokeUpdate(env, obj, display_height,
23 display_width, bits_per_pixel, bits_per_component, dip_scale);
24 }
25
26 namespace gfx {
27
28 int SharedDeviceDisplayInfo::GetDisplayHeight() {
Alexei Svitkine (slow) 2013/10/15 18:46:47 How about making these non-static and to be used t
29 SharedDeviceDisplayInfo* instance = GetInstance();
30 base::AutoLock(instance->lock_);
31 return instance->display_height_;
32 }
33
34 int SharedDeviceDisplayInfo::GetDisplayWidth() {
35 SharedDeviceDisplayInfo* instance = GetInstance();
36 base::AutoLock(instance->lock_);
37 return instance->display_width_;
38 }
39
40 int SharedDeviceDisplayInfo::GetBitsPerPixel() {
41 SharedDeviceDisplayInfo* instance = GetInstance();
42 base::AutoLock(instance->lock_);
43 return instance->bits_per_pixel_;
44 }
45
46 int SharedDeviceDisplayInfo::GetBitsPerComponent() {
47 SharedDeviceDisplayInfo* instance = GetInstance();
48 base::AutoLock(instance->lock_);
49 return instance->bits_per_component_;
50 }
51
52 double SharedDeviceDisplayInfo::GetDIPScale() {
53 SharedDeviceDisplayInfo* instance = GetInstance();
54 base::AutoLock(instance->lock_);
55 return instance->dip_scale_;
56 }
57
58 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
59 jobject obj,
60 jint display_height,
61 jint display_width,
62 jint bits_per_pixel,
63 jint bits_per_component,
64 jdouble dip_scale) {
65 SharedDeviceDisplayInfo* instance = SharedDeviceDisplayInfo::GetInstance();
66 base::AutoLock(instance->lock());
67
68 instance->UpdateDisplayInfo(env, obj, display_height,
69 display_width, bits_per_pixel, bits_per_component, dip_scale);
70 }
71
72 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env,
73 jobject jobj,
74 jint display_height,
75 jint display_width,
76 jint bits_per_pixel,
77 jint bits_per_component,
78 jdouble dip_scale) {
79 display_height_ = static_cast<int>(display_height);
80 display_width_ = static_cast<int>(display_width);
81 bits_per_pixel_ = static_cast<int>(bits_per_pixel);
82 bits_per_component_ = static_cast<int>(bits_per_component);
83 dip_scale_ = static_cast<double>(dip_scale);
84 }
85
86 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() {
87 return Singleton<SharedDeviceDisplayInfo>::get();
88 }
89
90 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() {
91 JNIEnv* env = AttachCurrentThread();
92 j_device_info_.Reset(
93 Java_DeviceDisplayInfo_createWithListener(env,
94 base::android::GetApplicationContext()));
95 UpdateDisplayInfo(env, j_device_info_.obj(),
96 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
97 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
98 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
99 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
100 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()));
101 }
102
103 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
104 return RegisterNativesImpl(env);
105 }
106
107 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698