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

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 namespace gfx {
16
17 base::LazyInstance<SharedDeviceDisplayInfo> g_instance_;
18
19 int SharedDeviceDisplayInfo::GetDisplayHeight() {
20 SharedDeviceDisplayInfo* instance = Instance();
21 base::AutoLock(instance->lock_);
22 return instance->display_height_;
23 }
24
25 int SharedDeviceDisplayInfo::GetDisplayWidth() {
26 SharedDeviceDisplayInfo* instance = Instance();
27 base::AutoLock(instance->lock_);
28 return instance->display_width_;
29 }
30
31 int SharedDeviceDisplayInfo::GetBitsPerPixel() {
32 SharedDeviceDisplayInfo* instance = Instance();
33 base::AutoLock(instance->lock_);
34 return instance->bits_per_pixel_;
35 }
36
37 int SharedDeviceDisplayInfo::GetBitsPerComponent() {
38 SharedDeviceDisplayInfo* instance = Instance();
39 base::AutoLock(instance->lock_);
40 return instance->bits_per_component_;
41 }
42
43 double SharedDeviceDisplayInfo::GetDIPScale() {
44 SharedDeviceDisplayInfo* instance = Instance();
45 base::AutoLock(instance->lock_);
46 return instance->dip_scale_;
47 }
48
49 void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
Alexei Svitkine (slow) 2013/10/11 14:13:06 This should be in anon namespace at the top of the
50 jobject obj,
51 jint display_height,
52 jint display_width,
53 jint bits_per_pixel,
54 jint bits_per_component,
55 jdouble dip_scale) {
56 SharedDeviceDisplayInfo::InvokeUpdate(env, obj, display_height,
57 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.
58 }
59
60 void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
61 jobject obj,
62 jint display_height,
63 jint display_width,
64 jint bits_per_pixel,
65 jint bits_per_component,
66 jdouble dip_scale) {
67 SharedDeviceDisplayInfo* instance = SharedDeviceDisplayInfo::Instance();
68 base::AutoLock(instance->lock());
69
70 instance->UpdateDisplayInfo(env, obj, display_height,
71 display_width, bits_per_pixel, bits_per_component, dip_scale);
72 }
73
74 void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv*,
75 jobject,
76 jint display_height,
77 jint display_width,
78 jint bits_per_pixel,
79 jint bits_per_component,
80 jdouble dip_scale) {
81 display_height_ = static_cast<int>(display_height);
82 display_width_ = static_cast<int>(display_width);
83 bits_per_pixel_ = static_cast<int>(bits_per_pixel);
84 bits_per_component_ = static_cast<int>(bits_per_component);
85 dip_scale_ = static_cast<double>(dip_scale);
86 }
87
88 SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::Instance() {
89 return g_instance_.Pointer();
90 }
91
92 SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() {
93 JNIEnv* env = AttachCurrentThread();
94 j_device_info_.Reset(
95 Java_DeviceDisplayInfo_createWithListener(env,
96 base::android::GetApplicationContext()));
97 UpdateDisplayInfo(env, j_device_info_.obj(),
98 Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
99 Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
100 Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
101 Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
102 Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()));
103 }
104
105 bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
106 return RegisterNativesImpl(env);
107 }
108
109 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698