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 | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 18 | #include <android/hardware_buffer.h> |
| 19 | #include <apex/display.h> |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 20 | #include <log/log.h> |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 21 | #include <utils/Errors.h> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 22 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 23 | #include "Properties.h" |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 24 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 28 | DeviceInfo* DeviceInfo::get() { |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 29 | static DeviceInfo sDeviceInfo; |
| 30 | return &sDeviceInfo; |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 33 | DeviceInfo::DeviceInfo() { |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 34 | #if HWUI_NULL_GPU |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 35 | mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 36 | #else |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 37 | mMaxTextureSize = -1; |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 38 | #endif |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 39 | } |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 40 | |
| 41 | void DeviceInfo::updateDisplayInfo() { |
| 42 | if (Properties::isolatedProcess) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | ADisplay** displays; |
| 47 | int size = ADisplay_acquirePhysicalDisplays(&displays); |
| 48 | |
| 49 | if (size <= 0) { |
| 50 | LOG_ALWAYS_FATAL("Failed to acquire physical displays for WCG support!"); |
| 51 | } |
| 52 | |
| 53 | for (int i = 0; i < size; ++i) { |
| 54 | // Pick the first internal display for querying the display type |
| 55 | // In practice this is controlled by a sysprop so it doesn't really |
| 56 | // matter which display we use. |
| 57 | if (ADisplay_getDisplayType(displays[i]) == DISPLAY_TYPE_INTERNAL) { |
| 58 | // We get the dataspace from DisplayManager already. Allocate space |
| 59 | // for the result here but we don't actually care about using it. |
| 60 | ADataSpace dataspace; |
| 61 | AHardwareBuffer_Format pixelFormat; |
| 62 | ADisplay_getPreferredWideColorFormat(displays[i], &dataspace, &pixelFormat); |
| 63 | |
| 64 | if (pixelFormat == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) { |
| 65 | mWideColorType = SkColorType::kN32_SkColorType; |
| 66 | } else if (pixelFormat == AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT) { |
| 67 | mWideColorType = SkColorType::kRGBA_F16_SkColorType; |
| 68 | } else { |
| 69 | LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format: %d", pixelFormat); |
| 70 | } |
| 71 | ADisplay_release(displays); |
| 72 | return; |
| 73 | } |
| 74 | } |
| 75 | LOG_ALWAYS_FATAL("Failed to find a valid physical display for WCG support!"); |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | int DeviceInfo::maxTextureSize() const { |
| 79 | LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); |
| 80 | return mMaxTextureSize; |
| 81 | } |
| 82 | |
| 83 | void DeviceInfo::setMaxTextureSize(int maxTextureSize) { |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 84 | DeviceInfo::get()->mMaxTextureSize = maxTextureSize; |
| 85 | } |
| 86 | |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 87 | void DeviceInfo::setWideColorDataspace(ADataSpace dataspace) { |
| 88 | switch (dataspace) { |
| 89 | case ADATASPACE_DISPLAY_P3: |
| 90 | get()->mWideColorSpace = |
Mike Reed | 7ac1af3 | 2020-05-26 10:50:21 -0400 | [diff] [blame] | 91 | SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3); |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 92 | break; |
| 93 | case ADATASPACE_SCRGB: |
| 94 | get()->mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 95 | break; |
John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 96 | default: |
| 97 | ALOGW("Unknown dataspace %d", dataspace); |
| 98 | // Treat unknown dataspaces as sRGB, so fall through |
| 99 | [[fallthrough]]; |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 100 | case ADATASPACE_SRGB: |
| 101 | // when sRGB is returned, it means wide color gamut is not supported. |
| 102 | get()->mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 103 | break; |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 104 | } |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Sally Qi | 02068d5 | 2022-08-30 16:29:14 -0700 | [diff] [blame] | 107 | void DeviceInfo::setSupportFp16ForHdr(bool supportFp16ForHdr) { |
| 108 | get()->mSupportFp16ForHdr = supportFp16ForHdr; |
| 109 | } |
| 110 | |
Alec Mouri | 4a3035e | 2024-03-04 23:12:42 +0000 | [diff] [blame] | 111 | void DeviceInfo::setSupportRgba10101010ForHdr(bool supportRgba10101010ForHdr) { |
| 112 | get()->mSupportRgba10101010ForHdr = supportRgba10101010ForHdr; |
| 113 | } |
| 114 | |
Sally Qi | 830b041 | 2022-12-14 16:26:49 -0800 | [diff] [blame] | 115 | void DeviceInfo::setSupportMixedColorSpaces(bool supportMixedColorSpaces) { |
| 116 | get()->mSupportMixedColorSpaces = supportMixedColorSpaces; |
| 117 | } |
| 118 | |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 119 | void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) { |
| 120 | mVsyncPeriod = vsyncPeriod; |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Alec Mouri | d5fa1dc | 2020-04-06 13:15:28 -0700 | [diff] [blame] | 123 | std::atomic<float> DeviceInfo::sDensity = 2.0; |
| 124 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 125 | } /* namespace uirenderer */ |
| 126 | } /* namespace android */ |