Home | History | Annotate | Download | only in android
      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 
     12 using base::android::AttachCurrentThread;
     13 using base::android::ScopedJavaLocalRef;
     14 
     15 namespace gfx {
     16 
     17 DeviceDisplayInfo::DeviceDisplayInfo() {
     18   JNIEnv* env = AttachCurrentThread();
     19   j_device_info_.Reset(Java_DeviceDisplayInfo_create(env,
     20       base::android::GetApplicationContext()));
     21 }
     22 
     23 DeviceDisplayInfo::~DeviceDisplayInfo() {
     24 }
     25 
     26 int 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 
     33 int 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 
     40 int 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 
     47 int 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 
     54 double 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 
     61 // static
     62 bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) {
     63   return RegisterNativesImpl(env);
     64 }
     65 
     66 }  // namespace gfx
     67