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

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

Issue 1144333004: Make WebView work for external displays (over Presentations). Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor naming/comment fixes Created 5 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.PixelFormat; 9 import android.graphics.PixelFormat;
10 import android.graphics.Point; 10 import android.graphics.Point;
11 import android.os.Build; 11 import android.os.Build;
12 import android.util.DisplayMetrics; 12 import android.util.DisplayMetrics;
13 import android.view.Display; 13 import android.view.Display;
14 import android.view.Surface; 14 import android.view.Surface;
15 import android.view.WindowManager; 15 import android.view.WindowManager;
16 16
17 import org.chromium.base.CalledByNative; 17 import org.chromium.base.CalledByNative;
18 import org.chromium.base.JNINamespace; 18 import org.chromium.base.JNINamespace;
19 19
20 import java.lang.ref.WeakReference;
21
20 /** 22 /**
21 * This class facilitates access to android information typically only 23 * This class facilitates access to android information typically only
22 * available using the Java SDK, including {@link Display} properties. 24 * available using the Java SDK, including {@link Display} properties.
23 * 25 *
24 * Currently the information consists of very raw display information (height, w idth, DPI scale) 26 * Currently the information consists of very raw display information (height, w idth, DPI scale)
25 * regarding the main display. 27 * regarding the main display.
26 */ 28 */
27 @JNINamespace("gfx") 29 @JNINamespace("gfx")
28 public class DeviceDisplayInfo { 30 public class DeviceDisplayInfo {
29 31 private final WeakReference<Context> mContextRef;
30 private final Context mAppContext;
31 private final WindowManager mWinManager; 32 private final WindowManager mWinManager;
32 private Point mTempPoint = new Point(); 33 private Point mTempPoint = new Point();
33 private DisplayMetrics mTempMetrics = new DisplayMetrics(); 34 private DisplayMetrics mTempMetrics = new DisplayMetrics();
34 35
35 private DeviceDisplayInfo(Context context) { 36 private DeviceDisplayInfo(WeakReference<Context> contextRef) {
36 mAppContext = context.getApplicationContext(); 37 mContextRef = contextRef;
37 mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDO W_SERVICE); 38 Context context = mContextRef.get();
39 if (context == null)
boliu 2015/07/15 06:38:47 Pass a strong ref in constructor, then this can't
gsennton 2015/07/15 19:26:21 Unless the incoming context is null because we ret
boliu 2015/07/16 14:36:56 You can check for null before passing it into Devi
gsennton 2015/10/20 13:27:12 Right, will check this in WindowAndroid::UpdateDev
boliu 2015/10/20 15:07:22 "use the default DeviceDisplayInfo" sounds wrong,
40 throw new RuntimeException("got null Context in DeviceDisplayInfo co nstructor");
41 mWinManager = (WindowManager) context.getSystemService(Context.WINDOW_SE RVICE);
38 } 42 }
39 43
40 /** 44 /**
41 * @return Display height in physical pixels. 45 * @return Display height in physical pixels.
42 */ 46 */
43 @CalledByNative 47 @CalledByNative
44 public int getDisplayHeight() { 48 public int getDisplayHeight() {
45 getDisplay().getSize(mTempPoint); 49 getDisplay().getSize(mTempPoint);
46 return mTempPoint.y; 50 return mTempPoint.y;
47 } 51 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 getDisplay().getMetrics(mTempMetrics); 151 getDisplay().getMetrics(mTempMetrics);
148 return mTempMetrics.density; 152 return mTempMetrics.density;
149 } 153 }
150 154
151 /** 155 /**
152 * @return Smallest screen size in density-independent pixels that the 156 * @return Smallest screen size in density-independent pixels that the
153 * application will see, regardless of orientation. 157 * application will see, regardless of orientation.
154 */ 158 */
155 @CalledByNative 159 @CalledByNative
156 private int getSmallestDIPWidth() { 160 private int getSmallestDIPWidth() {
157 return mAppContext.getResources().getConfiguration().smallestScreenWidth Dp; 161 Context context = mContextRef.get();
162 if (context == null) throw new RuntimeException("null context in getSmal lestDIPWidth!!!");
163 return context.getResources().getConfiguration().smallestScreenWidthDp;
boliu 2015/07/15 06:38:47 I wonder if this can ever change. Maybe it's ok to
jdduke (slow) 2015/07/15 16:03:07 +1. It might also be worth investigating why this
gsennton 2015/07/15 19:26:21 Right, going ahead and storing the value in the co
boliu 2015/07/16 14:36:56 You no longer need to keep mContextRef in this cla
gsennton 2015/10/20 13:27:12 will remove mContextRef Regarding getSmallestDIPW
158 } 164 }
159 165
160 /** 166 /**
161 * @return the screen's rotation angle from its 'natural' orientation. 167 * @return the screen's rotation angle from its 'natural' orientation.
162 * Expected values are one of { 0, 90, 180, 270 }. 168 * Expected values are one of { 0, 90, 180, 270 }.
163 * See http://developer.android.com/reference/android/view/Display.html#getR otation() 169 * See http://developer.android.com/reference/android/view/Display.html#getR otation()
164 * for more information about Display.getRotation() behavior. 170 * for more information about Display.getRotation() behavior.
165 */ 171 */
166 @CalledByNative 172 @CalledByNative
167 public int getRotationDegrees() { 173 public int getRotationDegrees() {
168 switch (getDisplay().getRotation()) { 174 switch (getDisplay().getRotation()) {
169 case Surface.ROTATION_0: 175 case Surface.ROTATION_0:
170 return 0; 176 return 0;
171 case Surface.ROTATION_90: 177 case Surface.ROTATION_90:
172 return 90; 178 return 90;
173 case Surface.ROTATION_180: 179 case Surface.ROTATION_180:
174 return 180; 180 return 180;
175 case Surface.ROTATION_270: 181 case Surface.ROTATION_270:
176 return 270; 182 return 270;
177 } 183 }
178 184
179 // This should not happen. 185 // This should not happen.
180 assert false; 186 assert false;
181 return 0; 187 return 0;
182 } 188 }
183 189
184 /**
185 * Inform the native implementation to update its cached representation of
186 * the DeviceDisplayInfo values.
187 */
188 public void updateNativeSharedDisplayInfo() {
189 nativeUpdateSharedDeviceDisplayInfo(
190 getDisplayHeight(), getDisplayWidth(),
191 getPhysicalDisplayHeight(), getPhysicalDisplayWidth(),
192 getBitsPerPixel(), getBitsPerComponent(),
193 getDIPScale(), getSmallestDIPWidth(), getRotationDegrees());
194 }
195
196 private Display getDisplay() { 190 private Display getDisplay() {
197 return mWinManager.getDefaultDisplay(); 191 return mWinManager.getDefaultDisplay();
198 } 192 }
199 193
200 /** 194 /**
201 * Creates DeviceDisplayInfo for a given Context. 195 * Creates DeviceDisplayInfo for a given Context.
202 * 196 *
203 * @param context A context to use. 197 * @param context A context to use.
204 * @return DeviceDisplayInfo associated with a given Context. 198 * @return DeviceDisplayInfo associated with a given Context.
205 */ 199 */
206 @CalledByNative 200 @CalledByNative
207 public static DeviceDisplayInfo create(Context context) { 201 public static DeviceDisplayInfo create(Context context) {
208 return new DeviceDisplayInfo(context); 202 return new DeviceDisplayInfo(new WeakReference<Context>(context));
209 } 203 }
210
211 private native void nativeUpdateSharedDeviceDisplayInfo(
212 int displayHeight, int displayWidth,
213 int physicalDisplayHeight, int physicalDisplayWidth,
214 int bitsPerPixel, int bitsPerComponent, double dipScale,
215 int smallestDIPWidth, int rotationDegrees);
216
217 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698