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

Side by Side Diff: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java

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, 1 month 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 package org.chromium.ui.gfx; 5 package org.chromium.ui.gfx;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.ComponentCallbacks;
9 import android.content.res.Configuration;
8 import android.graphics.PixelFormat; 10 import android.graphics.PixelFormat;
9 import android.os.Build; 11 import android.os.Build;
10 import android.util.DisplayMetrics; 12 import android.util.DisplayMetrics;
11 import android.view.Display; 13 import android.view.Display;
12 import android.view.WindowManager; 14 import android.view.WindowManager;
13 15
14 import org.chromium.base.CalledByNative; 16 import org.chromium.base.CalledByNative;
15 import org.chromium.base.JNINamespace; 17 import org.chromium.base.JNINamespace;
16 18
17 /** 19 /**
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 119
118 /** 120 /**
119 * @return Smallest screen size in density-independent pixels that the 121 * @return Smallest screen size in density-independent pixels that the
120 * application will see, regardless of orientation. 122 * application will see, regardless of orientation.
121 */ 123 */
122 @CalledByNative 124 @CalledByNative
123 private int getSmallestDIPWidth() { 125 private int getSmallestDIPWidth() {
124 return mAppContext.getResources().getConfiguration().smallestScreenWidthDp ; 126 return mAppContext.getResources().getConfiguration().smallestScreenWidthDp ;
125 } 127 }
126 128
129 private void registerListener() {
130 mAppContext.registerComponentCallbacks(
131 new ComponentCallbacks() {
132 @Override
133 public void onConfigurationChanged(Configuration configuration) {
134 updateNativeSharedDisplayInfo();
135 }
136
137 @Override
138 public void onLowMemory() {
139 }
140 });
141 }
142
143 private void updateNativeSharedDisplayInfo() {
144 nativeUpdateSharedDeviceDisplayInfo(getDisplayHeight(),
145 getDisplayWidth(), getBitsPerPixel(), getBitsPerComponent(),
146 getDIPScale(), getSmallestDIPWidth());
147 }
148
127 private Display getDisplay() { 149 private Display getDisplay() {
128 return mWinManager.getDefaultDisplay(); 150 return mWinManager.getDefaultDisplay();
129 } 151 }
130 152
131 private DisplayMetrics getMetrics() { 153 private DisplayMetrics getMetrics() {
132 return mAppContext.getResources().getDisplayMetrics(); 154 return mAppContext.getResources().getDisplayMetrics();
133 } 155 }
134 156
135 /** 157 /**
136 * Creates DeviceDisplayInfo for a given Context. 158 * Creates DeviceDisplayInfo for a given Context.
137 * @param context A context to use. 159 * @param context A context to use.
138 * @return DeviceDisplayInfo associated with a given Context. 160 * @return DeviceDisplayInfo associated with a given Context.
139 */ 161 */
140 @CalledByNative
141 public static DeviceDisplayInfo create(Context context) { 162 public static DeviceDisplayInfo create(Context context) {
142 return new DeviceDisplayInfo(context); 163 return new DeviceDisplayInfo(context);
143 } 164 }
165
166 @CalledByNative
167 private static DeviceDisplayInfo createWithListener(Context context) {
168 DeviceDisplayInfo deviceDisplayInfo = new DeviceDisplayInfo(context);
169 deviceDisplayInfo.registerListener();
170 return deviceDisplayInfo;
171 }
172
173 private native void nativeUpdateSharedDeviceDisplayInfo(int displayHeight,
174 int displayWidth, int bitsPerPixel,
175 int bitsPerComponent, double dipScale,
176 int smallestDIPWidth);
177
144 } 178 }
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/android/device_display_info.h » ('j') | ui/gfx/android/gfx_jni_registrar.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698