device_display_info.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/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
12using base::android::AttachCurrentThread;
13using base::android::ScopedJavaLocalRef;
14
15namespace gfx {
16
17DeviceDisplayInfo::DeviceDisplayInfo() {
18  JNIEnv* env = AttachCurrentThread();
19  j_device_info_.Reset(Java_DeviceDisplayInfo_create(env,
20      base::android::GetApplicationContext()));
21}
22
23DeviceDisplayInfo::~DeviceDisplayInfo() {
24}
25
26int DeviceDisplayInfo::GetDisplayHeight() {
27  JNIEnv* env = AttachCurrentThread();
28  jint result =
29      Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj());
30  return static_cast<int>(result);
31}
32
33int DeviceDisplayInfo::GetDisplayWidth() {
34  JNIEnv* env = AttachCurrentThread();
35  jint result =
36      Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj());
37  return static_cast<int>(result);
38}
39
40int DeviceDisplayInfo::GetBitsPerPixel() {
41  JNIEnv* env = AttachCurrentThread();
42  jint result =
43      Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj());
44  return static_cast<int>(result);
45}
46
47int DeviceDisplayInfo::GetBitsPerComponent() {
48  JNIEnv* env = AttachCurrentThread();
49  jint result =
50      Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj());
51  return static_cast<int>(result);
52}
53
54double DeviceDisplayInfo::GetDIPScale() {
55  JNIEnv* env = AttachCurrentThread();
56  jdouble result =
57      Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj());
58  return static_cast<double>(result);
59}
60
61double DeviceDisplayInfo::GetRefreshRate() {
62  JNIEnv* env = AttachCurrentThread();
63  jdouble result =
64      Java_DeviceDisplayInfo_getRefreshRate(env, j_device_info_.obj());
65  return static_cast<double>(result);
66}
67
68// static
69bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) {
70  return RegisterNativesImpl(env);
71}
72
73}  // namespace gfx
74