1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/android/shared_device_display_info.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/logging.h"
#include "jni/DeviceDisplayInfo_jni.h"
namespace gfx {
// static JNI call
static void UpdateSharedDeviceDisplayInfo(JNIEnv* env,
jobject obj,
jint display_height,
jint display_width,
jint physical_display_height,
jint physical_display_width,
jint bits_per_pixel,
jint bits_per_component,
jdouble dip_scale,
jint smallest_dip_width,
jint rotation_degrees) {
SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj,
display_height, display_width,
physical_display_height, physical_display_width,
bits_per_pixel, bits_per_component,
dip_scale, smallest_dip_width, rotation_degrees);
}
// static
SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() {
return Singleton<SharedDeviceDisplayInfo>::get();
}
int SharedDeviceDisplayInfo::GetDisplayHeight() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, display_height_);
return display_height_;
}
int SharedDeviceDisplayInfo::GetDisplayWidth() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, display_width_);
return display_width_;
}
int SharedDeviceDisplayInfo::GetPhysicalDisplayHeight() {
base::AutoLock autolock(lock_);
return physical_display_height_;
}
int SharedDeviceDisplayInfo::GetPhysicalDisplayWidth() {
base::AutoLock autolock(lock_);
return physical_display_width_;
}
int SharedDeviceDisplayInfo::GetBitsPerPixel() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, bits_per_pixel_);
return bits_per_pixel_;
}
int SharedDeviceDisplayInfo::GetBitsPerComponent() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, bits_per_component_);
return bits_per_component_;
}
double SharedDeviceDisplayInfo::GetDIPScale() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, dip_scale_);
return dip_scale_;
}
int SharedDeviceDisplayInfo::GetSmallestDIPWidth() {
base::AutoLock autolock(lock_);
DCHECK_NE(0, smallest_dip_width_);
return smallest_dip_width_;
}
int SharedDeviceDisplayInfo::GetRotationDegrees() {
base::AutoLock autolock(lock_);
return rotation_degrees_;
}
// static
bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) {
return RegisterNativesImpl(env);
}
void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env,
jobject obj,
jint display_height,
jint display_width,
jint physical_display_height,
jint physical_display_width,
jint bits_per_pixel,
jint bits_per_component,
jdouble dip_scale,
jint smallest_dip_width,
jint rotation_degrees) {
base::AutoLock autolock(lock_);
UpdateDisplayInfo(env, obj,
display_height, display_width,
physical_display_height, physical_display_width,
bits_per_pixel, bits_per_component, dip_scale,
smallest_dip_width, rotation_degrees);
}
SharedDeviceDisplayInfo::SharedDeviceDisplayInfo()
: display_height_(0),
display_width_(0),
bits_per_pixel_(0),
bits_per_component_(0),
dip_scale_(0),
smallest_dip_width_(0) {
JNIEnv* env = base::android::AttachCurrentThread();
j_device_info_.Reset(
Java_DeviceDisplayInfo_create(
env, base::android::GetApplicationContext()));
UpdateDisplayInfo(env, j_device_info_.obj(),
Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getPhysicalDisplayHeight(env,
j_device_info_.obj()),
Java_DeviceDisplayInfo_getPhysicalDisplayWidth(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj()),
Java_DeviceDisplayInfo_getRotationDegrees(env, j_device_info_.obj()));
}
SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() {
}
void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env,
jobject jobj,
jint display_height,
jint display_width,
jint physical_display_height,
jint physical_display_width,
jint bits_per_pixel,
jint bits_per_component,
jdouble dip_scale,
jint smallest_dip_width,
jint rotation_degrees) {
display_height_ = static_cast<int>(display_height);
display_width_ = static_cast<int>(display_width);
physical_display_height_ = static_cast<int>(physical_display_height);
physical_display_width_ = static_cast<int>(physical_display_width);
bits_per_pixel_ = static_cast<int>(bits_per_pixel);
bits_per_component_ = static_cast<int>(bits_per_component);
dip_scale_ = static_cast<double>(dip_scale);
smallest_dip_width_ = static_cast<int>(smallest_dip_width);
rotation_degrees_ = static_cast<int>(rotation_degrees);
}
} // namespace gfx
|