EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.ui.gfx]

COVERAGE SUMMARY FOR SOURCE FILE [DeviceDisplayInfo.java]

nameclass, %method, %block, %line, %
DeviceDisplayInfo.java100% (1/1)100% (10/10)83%  (68/82)73%  (19/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DeviceDisplayInfo100% (1/1)100% (10/10)83%  (68/82)73%  (19/26)
getBitsPerComponent (): int 100% (1/1)37%  (7/19)33%  (3/9)
getPixelFormat (): int 100% (1/1)78%  (7/9)67%  (2/3)
DeviceDisplayInfo (Context): void 100% (1/1)100% (14/14)100% (4/4)
create (Context): DeviceDisplayInfo 100% (1/1)100% (5/5)100% (1/1)
getBitsPerPixel (): int 100% (1/1)100% (13/13)100% (4/4)
getDIPScale (): double 100% (1/1)100% (5/5)100% (1/1)
getDisplay (): Display 100% (1/1)100% (4/4)100% (1/1)
getDisplayHeight (): int 100% (1/1)100% (4/4)100% (1/1)
getDisplayWidth (): int 100% (1/1)100% (4/4)100% (1/1)
getMetrics (): DisplayMetrics 100% (1/1)100% (5/5)100% (1/1)

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 
5package org.chromium.ui.gfx;
6 
7import android.content.Context;
8import android.graphics.PixelFormat;
9import android.os.Build;
10import android.util.DisplayMetrics;
11import android.view.Display;
12import android.view.WindowManager;
13 
14import org.chromium.base.CalledByNative;
15import org.chromium.base.JNINamespace;
16 
17/**
18 * This class facilitates access to android information typically only
19 * available using the Java SDK, including {@link Display} properties.
20 *
21 * Currently the information consists of very raw display information (height, width, DPI scale)
22 * regarding the main display.
23 */
24@JNINamespace("gfx")
25public class DeviceDisplayInfo {
26 
27 
28  private final Context mAppContext;
29  private final WindowManager mWinManager;
30 
31  private DeviceDisplayInfo(Context context) {
32      mAppContext = context.getApplicationContext();
33      mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_SERVICE);
34  }
35 
36  /**
37   * @return Display height in physical pixels.
38   */
39  @CalledByNative
40  public int getDisplayHeight() {
41      return getMetrics().heightPixels;
42  }
43 
44  /**
45   * @return Display width in physical pixels.
46   */
47  @CalledByNative
48  public int getDisplayWidth() {
49      return getMetrics().widthPixels;
50  }
51 
52  @SuppressWarnings("deprecation")
53  private int getPixelFormat() {
54      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
55          return getDisplay().getPixelFormat();
56      }
57      // JellyBean MR1 and later always uses RGBA_8888.
58      return PixelFormat.RGBA_8888;
59  }
60 
61  /**
62   * @return Bits per pixel.
63   */
64  @CalledByNative
65  public int getBitsPerPixel() {
66      int format = getPixelFormat();
67      PixelFormat info = new PixelFormat();
68      PixelFormat.getPixelFormatInfo(format, info);
69      return info.bitsPerPixel;
70  }
71 
72  /**
73   * @return Bits per component.
74   */
75  @SuppressWarnings("deprecation")
76  @CalledByNative
77  public int getBitsPerComponent() {
78      int format = getPixelFormat();
79      switch (format) {
80      case PixelFormat.RGBA_4444:
81          return 4;
82 
83      case PixelFormat.RGBA_5551:
84          return 5;
85 
86      case PixelFormat.RGBA_8888:
87      case PixelFormat.RGBX_8888:
88      case PixelFormat.RGB_888:
89          return 8;
90 
91      case PixelFormat.RGB_332:
92          return 2;
93 
94      case PixelFormat.RGB_565:
95          return 5;
96 
97      // Non-RGB formats.
98      case PixelFormat.A_8:
99      case PixelFormat.LA_88:
100      case PixelFormat.L_8:
101          return 0;
102 
103      // Unknown format. Use 8 as a sensible default.
104      default:
105          return 8;
106      }
107  }
108 
109  /**
110   * @return A scaling factor for the Density Independent Pixel unit.
111   *         1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi.
112   */
113  @CalledByNative
114  public double getDIPScale() {
115      return getMetrics().density;
116  }
117 
118  private Display getDisplay() {
119      return mWinManager.getDefaultDisplay();
120  }
121 
122  private DisplayMetrics getMetrics() {
123      return mAppContext.getResources().getDisplayMetrics();
124  }
125 
126  /**
127   * Creates DeviceDisplayInfo for a given Context.
128   * @param context A context to use.
129   * @return DeviceDisplayInfo associated with a given Context.
130   */
131  @CalledByNative
132  public static DeviceDisplayInfo create(Context context) {
133      return new DeviceDisplayInfo(context);
134  }
135}

[all classes][org.chromium.ui.gfx]
EMMA 2.0.5312 (C) Vladimir Roubtsov