John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 16 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 17 | #include <DeviceInfo.h> |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 18 | #include <log/log.h> |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 19 | #include <utils/Errors.h> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 20 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 21 | #include "Properties.h" |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 22 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 26 | DeviceInfo* DeviceInfo::get() { |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 27 | static DeviceInfo sDeviceInfo; |
| 28 | return &sDeviceInfo; |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 31 | DeviceInfo::DeviceInfo() { |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 32 | #if HWUI_NULL_GPU |
| 33 | mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; |
| 34 | #else |
| 35 | mMaxTextureSize = -1; |
| 36 | #endif |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 37 | updateDisplayInfo(); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 38 | } |
| 39 | DeviceInfo::~DeviceInfo() { |
| 40 | ADisplay_release(mDisplays); |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int DeviceInfo::maxTextureSize() const { |
| 44 | LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); |
| 45 | return mMaxTextureSize; |
| 46 | } |
| 47 | |
| 48 | void DeviceInfo::setMaxTextureSize(int maxTextureSize) { |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 49 | DeviceInfo::get()->mMaxTextureSize = maxTextureSize; |
| 50 | } |
| 51 | |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 52 | void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) { |
| 53 | mVsyncPeriod = vsyncPeriod; |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void DeviceInfo::updateDisplayInfo() { |
| 57 | if (Properties::isolatedProcess) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if (mCurrentConfig == nullptr) { |
| 62 | mDisplaysSize = ADisplay_acquirePhysicalDisplays(&mDisplays); |
| 63 | LOG_ALWAYS_FATAL_IF(mDisplays == nullptr || mDisplaysSize <= 0, |
| 64 | "Failed to get physical displays: no connected display: %d!", mDisplaysSize); |
| 65 | for (size_t i = 0; i < mDisplaysSize; i++) { |
| 66 | ADisplayType type = ADisplay_getDisplayType(mDisplays[i]); |
| 67 | if (type == ADisplayType::DISPLAY_TYPE_INTERNAL) { |
| 68 | mPhysicalDisplayIndex = i; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | LOG_ALWAYS_FATAL_IF(mPhysicalDisplayIndex < 0, "Failed to find a connected physical display!"); |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 73 | |
| 74 | |
| 75 | // Since we now just got the primary display for the first time, then |
| 76 | // store the primary display metadata here. |
| 77 | ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex]; |
| 78 | mMaxRefreshRate = ADisplay_getMaxSupportedFps(primaryDisplay); |
| 79 | ADataSpace dataspace; |
| 80 | AHardwareBuffer_Format format; |
| 81 | ADisplay_getPreferredWideColorFormat(primaryDisplay, &dataspace, &format); |
| 82 | switch (dataspace) { |
| 83 | case ADATASPACE_DISPLAY_P3: |
| 84 | mWideColorSpace = |
| 85 | SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3); |
| 86 | break; |
| 87 | case ADATASPACE_SCRGB: |
| 88 | mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 89 | break; |
| 90 | case ADATASPACE_SRGB: |
| 91 | // when sRGB is returned, it means wide color gamut is not supported. |
| 92 | mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 93 | break; |
| 94 | default: |
| 95 | LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space."); |
| 96 | } |
| 97 | switch (format) { |
| 98 | case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: |
| 99 | mWideColorType = SkColorType::kN32_SkColorType; |
| 100 | break; |
| 101 | case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: |
| 102 | mWideColorType = SkColorType::kRGBA_F16_SkColorType; |
| 103 | break; |
| 104 | default: |
| 105 | LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format."); |
| 106 | } |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 107 | } |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 108 | // This method may have been called when the display config changed, so |
| 109 | // sync with the current configuration. |
| 110 | ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex]; |
| 111 | status_t status = ADisplay_getCurrentConfig(primaryDisplay, &mCurrentConfig); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 112 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display config, error %d", status); |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 113 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 114 | mWidth = ADisplayConfig_getWidth(mCurrentConfig); |
| 115 | mHeight = ADisplayConfig_getHeight(mCurrentConfig); |
| 116 | mDensity = ADisplayConfig_getDensity(mCurrentConfig); |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 117 | mVsyncPeriod = static_cast<int64_t>(1000000000 / ADisplayConfig_getFps(mCurrentConfig)); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 118 | mCompositorOffset = ADisplayConfig_getCompositorOffsetNanos(mCurrentConfig); |
| 119 | mAppOffset = ADisplayConfig_getAppVsyncOffsetNanos(mCurrentConfig); |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 120 | } |
| 121 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 122 | } /* namespace uirenderer */ |
| 123 | } /* namespace android */ |