Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 11 matching lines...) Expand all Loading... | |
| 29 private final WindowManager mWinManager; | 31 private final WindowManager mWinManager; |
| 30 | 32 |
| 31 private DeviceDisplayInfo(Context context) { | 33 private DeviceDisplayInfo(Context context) { |
| 32 mAppContext = context.getApplicationContext(); | 34 mAppContext = context.getApplicationContext(); |
| 33 mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_ SERVICE); | 35 mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_ SERVICE); |
| 34 } | 36 } |
| 35 | 37 |
| 36 /** | 38 /** |
| 37 * @return Display height in physical pixels. | 39 * @return Display height in physical pixels. |
| 38 */ | 40 */ |
| 39 @CalledByNative | |
| 40 public int getDisplayHeight() { | 41 public int getDisplayHeight() { |
| 41 return getMetrics().heightPixels; | 42 return getMetrics().heightPixels; |
| 42 } | 43 } |
| 43 | 44 |
| 44 /** | 45 /** |
| 45 * @return Display width in physical pixels. | 46 * @return Display width in physical pixels. |
| 46 */ | 47 */ |
| 47 @CalledByNative | |
| 48 public int getDisplayWidth() { | 48 public int getDisplayWidth() { |
| 49 return getMetrics().widthPixels; | 49 return getMetrics().widthPixels; |
| 50 } | 50 } |
| 51 | 51 |
| 52 @SuppressWarnings("deprecation") | 52 @SuppressWarnings("deprecation") |
| 53 private int getPixelFormat() { | 53 private int getPixelFormat() { |
| 54 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { | 54 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 55 return getDisplay().getPixelFormat(); | 55 return getDisplay().getPixelFormat(); |
| 56 } | 56 } |
| 57 // JellyBean MR1 and later always uses RGBA_8888. | 57 // JellyBean MR1 and later always uses RGBA_8888. |
| 58 return PixelFormat.RGBA_8888; | 58 return PixelFormat.RGBA_8888; |
| 59 } | 59 } |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * @return Bits per pixel. | 62 * @return Bits per pixel. |
| 63 */ | 63 */ |
| 64 @CalledByNative | |
| 65 public int getBitsPerPixel() { | 64 public int getBitsPerPixel() { |
| 66 int format = getPixelFormat(); | 65 int format = getPixelFormat(); |
| 67 PixelFormat info = new PixelFormat(); | 66 PixelFormat info = new PixelFormat(); |
| 68 PixelFormat.getPixelFormatInfo(format, info); | 67 PixelFormat.getPixelFormatInfo(format, info); |
| 69 return info.bitsPerPixel; | 68 return info.bitsPerPixel; |
| 70 } | 69 } |
| 71 | 70 |
| 72 /** | 71 /** |
| 73 * @return Bits per component. | 72 * @return Bits per component. |
| 74 */ | 73 */ |
| 75 @SuppressWarnings("deprecation") | 74 @SuppressWarnings("deprecation") |
| 76 @CalledByNative | |
| 77 public int getBitsPerComponent() { | 75 public int getBitsPerComponent() { |
| 78 int format = getPixelFormat(); | 76 int format = getPixelFormat(); |
| 79 switch (format) { | 77 switch (format) { |
| 80 case PixelFormat.RGBA_4444: | 78 case PixelFormat.RGBA_4444: |
| 81 return 4; | 79 return 4; |
| 82 | 80 |
| 83 case PixelFormat.RGBA_5551: | 81 case PixelFormat.RGBA_5551: |
| 84 return 5; | 82 return 5; |
| 85 | 83 |
| 86 case PixelFormat.RGBA_8888: | 84 case PixelFormat.RGBA_8888: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 103 // Unknown format. Use 8 as a sensible default. | 101 // Unknown format. Use 8 as a sensible default. |
| 104 default: | 102 default: |
| 105 return 8; | 103 return 8; |
| 106 } | 104 } |
| 107 } | 105 } |
| 108 | 106 |
| 109 /** | 107 /** |
| 110 * @return A scaling factor for the Density Independent Pixel unit. | 108 * @return A scaling factor for the Density Independent Pixel unit. |
| 111 * 1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi. | 109 * 1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi. |
| 112 */ | 110 */ |
| 113 @CalledByNative | |
| 114 public double getDIPScale() { | 111 public double getDIPScale() { |
| 115 return getMetrics().density; | 112 return getMetrics().density; |
| 116 } | 113 } |
| 117 | 114 |
| 115 @CalledByNative | |
| 116 public void registerListener() { | |
| 117 mAppContext.registerComponentCallbacks( | |
|
Yaron
2013/10/10 11:52:46
nit: indent 4 (also below)
| |
| 118 new ComponentCallbacks() { | |
| 119 @Override | |
| 120 public void onConfigurationChanged(Configuration configuration) { | |
| 121 updateNativeSharedDisplayInfo(); | |
| 122 } | |
|
Yaron
2013/10/10 11:52:46
nit: add linebreak below
| |
| 123 @Override | |
| 124 public void onLowMemory() { | |
| 125 } | |
| 126 }); | |
| 127 | |
| 128 updateNativeSharedDisplayInfo(); | |
| 129 } | |
| 130 | |
| 131 private void updateNativeSharedDisplayInfo() { | |
| 132 nativeUpdateSharedDisplayInfo(getDisplayHeight(), getDisplayWidth(), | |
| 133 getBitsPerPixel(), getBitsPerComponent(), getDIPScale()); | |
| 134 } | |
| 135 | |
| 118 private Display getDisplay() { | 136 private Display getDisplay() { |
| 119 return mWinManager.getDefaultDisplay(); | 137 return mWinManager.getDefaultDisplay(); |
| 120 } | 138 } |
| 121 | 139 |
| 122 private DisplayMetrics getMetrics() { | 140 private DisplayMetrics getMetrics() { |
| 123 return mAppContext.getResources().getDisplayMetrics(); | 141 return mAppContext.getResources().getDisplayMetrics(); |
| 124 } | 142 } |
| 125 | 143 |
| 144 | |
| 126 /** | 145 /** |
| 127 * Creates DeviceDisplayInfo for a given Context. | 146 * Creates DeviceDisplayInfo for a given Context. |
| 128 * @param context A context to use. | 147 * @param context A context to use. |
| 129 * @return DeviceDisplayInfo associated with a given Context. | 148 * @return DeviceDisplayInfo associated with a given Context. |
| 130 */ | 149 */ |
| 131 @CalledByNative | 150 @CalledByNative |
| 132 public static DeviceDisplayInfo create(Context context) { | 151 public static DeviceDisplayInfo create(Context context) { |
| 133 return new DeviceDisplayInfo(context); | 152 return new DeviceDisplayInfo(context); |
| 134 } | 153 } |
| 154 | |
| 155 private native void nativeUpdateSharedDisplayInfo(int display_height, | |
|
Yaron
2013/10/10 11:52:46
java style should be displayHeight. Please update
| |
| 156 int display_width, int bits_per_pixel, | |
| 157 int bits_per_component, double dip_scale); | |
| 158 | |
| 135 } | 159 } |
| OLD | NEW |