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 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 21 | #include <mutex> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include <thread> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 23 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 24 | #include "Properties.h" |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 25 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 29 | DeviceInfo* DeviceInfo::get() { |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 30 | static DeviceInfo sDeviceInfo; |
| 31 | return &sDeviceInfo; |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 34 | DeviceInfo::DeviceInfo() { |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 35 | #if HWUI_NULL_GPU |
| 36 | mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; |
| 37 | #else |
| 38 | mMaxTextureSize = -1; |
| 39 | #endif |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 40 | updateDisplayInfo(); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 41 | } |
| 42 | DeviceInfo::~DeviceInfo() { |
| 43 | ADisplay_release(mDisplays); |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | int DeviceInfo::maxTextureSize() const { |
| 47 | LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); |
| 48 | return mMaxTextureSize; |
| 49 | } |
| 50 | |
| 51 | void DeviceInfo::setMaxTextureSize(int maxTextureSize) { |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 52 | DeviceInfo::get()->mMaxTextureSize = maxTextureSize; |
| 53 | } |
| 54 | |
| 55 | void DeviceInfo::onDisplayConfigChanged() { |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 56 | updateDisplayInfo(); |
| 57 | } |
| 58 | |
| 59 | void DeviceInfo::updateDisplayInfo() { |
| 60 | if (Properties::isolatedProcess) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (mCurrentConfig == nullptr) { |
| 65 | mDisplaysSize = ADisplay_acquirePhysicalDisplays(&mDisplays); |
| 66 | LOG_ALWAYS_FATAL_IF(mDisplays == nullptr || mDisplaysSize <= 0, |
| 67 | "Failed to get physical displays: no connected display: %d!", mDisplaysSize); |
| 68 | for (size_t i = 0; i < mDisplaysSize; i++) { |
| 69 | ADisplayType type = ADisplay_getDisplayType(mDisplays[i]); |
| 70 | if (type == ADisplayType::DISPLAY_TYPE_INTERNAL) { |
| 71 | mPhysicalDisplayIndex = i; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | 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^] | 76 | |
| 77 | |
| 78 | // Since we now just got the primary display for the first time, then |
| 79 | // store the primary display metadata here. |
| 80 | ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex]; |
| 81 | mMaxRefreshRate = ADisplay_getMaxSupportedFps(primaryDisplay); |
| 82 | ADataSpace dataspace; |
| 83 | AHardwareBuffer_Format format; |
| 84 | ADisplay_getPreferredWideColorFormat(primaryDisplay, &dataspace, &format); |
| 85 | switch (dataspace) { |
| 86 | case ADATASPACE_DISPLAY_P3: |
| 87 | mWideColorSpace = |
| 88 | SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3); |
| 89 | break; |
| 90 | case ADATASPACE_SCRGB: |
| 91 | mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 92 | break; |
| 93 | case ADATASPACE_SRGB: |
| 94 | // when sRGB is returned, it means wide color gamut is not supported. |
| 95 | mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 96 | break; |
| 97 | default: |
| 98 | LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space."); |
| 99 | } |
| 100 | switch (format) { |
| 101 | case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: |
| 102 | mWideColorType = SkColorType::kN32_SkColorType; |
| 103 | break; |
| 104 | case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: |
| 105 | mWideColorType = SkColorType::kRGBA_F16_SkColorType; |
| 106 | break; |
| 107 | default: |
| 108 | LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format."); |
| 109 | } |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 110 | } |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame^] | 111 | // This method may have been called when the display config changed, so |
| 112 | // sync with the current configuration. |
| 113 | ADisplay* primaryDisplay = mDisplays[mPhysicalDisplayIndex]; |
| 114 | status_t status = ADisplay_getCurrentConfig(primaryDisplay, &mCurrentConfig); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 115 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display config, error %d", status); |
| 116 | mWidth = ADisplayConfig_getWidth(mCurrentConfig); |
| 117 | mHeight = ADisplayConfig_getHeight(mCurrentConfig); |
| 118 | mDensity = ADisplayConfig_getDensity(mCurrentConfig); |
| 119 | mRefreshRate = ADisplayConfig_getFps(mCurrentConfig); |
| 120 | mCompositorOffset = ADisplayConfig_getCompositorOffsetNanos(mCurrentConfig); |
| 121 | mAppOffset = ADisplayConfig_getAppVsyncOffsetNanos(mCurrentConfig); |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 122 | } |
| 123 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 124 | } /* namespace uirenderer */ |
| 125 | } /* namespace android */ |