shared_device_display_info.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gfx/android/shared_device_display_info.h" 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/android/jni_android.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/android/jni_string.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/logging.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "jni/DeviceDisplayInfo_jni.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace gfx { 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// static JNI call 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)static void UpdateSharedDeviceDisplayInfo(JNIEnv* env, 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jobject obj, 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_height, 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_width, 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_pixel, 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_component, 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jdouble dip_scale, 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint smallest_dip_width) { 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SharedDeviceDisplayInfo::GetInstance()->InvokeUpdate(env, obj, 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) display_height, display_width, bits_per_pixel, bits_per_component, 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dip_scale, smallest_dip_width); 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// static 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)SharedDeviceDisplayInfo* SharedDeviceDisplayInfo::GetInstance() { 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return Singleton<SharedDeviceDisplayInfo>::get(); 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int SharedDeviceDisplayInfo::GetDisplayHeight() { 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, display_height_); 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return display_height_; 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int SharedDeviceDisplayInfo::GetDisplayWidth() { 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, display_width_); 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return display_width_; 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int SharedDeviceDisplayInfo::GetBitsPerPixel() { 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, bits_per_pixel_); 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return bits_per_pixel_; 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int SharedDeviceDisplayInfo::GetBitsPerComponent() { 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, bits_per_component_); 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return bits_per_component_; 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)double SharedDeviceDisplayInfo::GetDIPScale() { 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, dip_scale_); 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return dip_scale_; 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int SharedDeviceDisplayInfo::GetSmallestDIPWidth() { 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK_NE(0, smallest_dip_width_); 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return smallest_dip_width_; 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// static 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool SharedDeviceDisplayInfo::RegisterSharedDeviceDisplayInfo(JNIEnv* env) { 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return RegisterNativesImpl(env); 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void SharedDeviceDisplayInfo::InvokeUpdate(JNIEnv* env, 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jobject obj, 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_height, 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_width, 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_pixel, 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_component, 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jdouble dip_scale, 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint smallest_dip_width) { 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::AutoLock autolock(lock_); 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UpdateDisplayInfo(env, obj, display_height, 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) display_width, bits_per_pixel, bits_per_component, dip_scale, 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) smallest_dip_width); 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : display_height_(0), 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) display_width_(0), 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bits_per_pixel_(0), 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bits_per_component_(0), 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dip_scale_(0), 951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) smallest_dip_width_(0) { 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) j_device_info_.Reset( 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_createWithListener(env, 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::android::GetApplicationContext())); 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UpdateDisplayInfo(env, j_device_info_.obj(), 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), 1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()), 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()), 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()), 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Java_DeviceDisplayInfo_getSmallestDIPWidth(env, j_device_info_.obj())); 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)SharedDeviceDisplayInfo::~SharedDeviceDisplayInfo() { 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void SharedDeviceDisplayInfo::UpdateDisplayInfo(JNIEnv* env, 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jobject jobj, 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_height, 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint display_width, 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_pixel, 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint bits_per_component, 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jdouble dip_scale, 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) jint smallest_dip_width) { 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) display_height_ = static_cast<int>(display_height); 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) display_width_ = static_cast<int>(display_width); 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bits_per_pixel_ = static_cast<int>(bits_per_pixel); 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bits_per_component_ = static_cast<int>(bits_per_component); 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dip_scale_ = static_cast<double>(dip_scale); 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) smallest_dip_width_ = static_cast<int>(smallest_dip_width); 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace gfx 129