blob: af7a49653829ebfee41b2a07cb5f83efdefebb6a [file] [log] [blame]
John Reck704bed02015-11-05 09:22:17 -08001/*
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 Salyzyn52eb4e02016-09-28 16:15:30 -070016
John Reck704bed02015-11-05 09:22:17 -080017#include <DeviceInfo.h>
Alec Mourie55aa632020-04-15 19:46:05 -070018#include <android/hardware_buffer.h>
19#include <apex/display.h>
Alec Mouri22d753f2019-09-05 17:11:45 -070020#include <log/log.h>
Alec Mouri70f2a922019-11-20 11:10:29 -080021#include <utils/Errors.h>
John Reck704bed02015-11-05 09:22:17 -080022
Alec Mouri22d753f2019-09-05 17:11:45 -070023#include "Properties.h"
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070024
John Reck704bed02015-11-05 09:22:17 -080025namespace android {
26namespace uirenderer {
27
John Reckcf185f52019-04-11 16:11:24 -070028DeviceInfo* DeviceInfo::get() {
Alec Mouri22d753f2019-09-05 17:11:45 -070029 static DeviceInfo sDeviceInfo;
30 return &sDeviceInfo;
John Reckcf185f52019-04-11 16:11:24 -070031}
32
Alec Mouri22d753f2019-09-05 17:11:45 -070033DeviceInfo::DeviceInfo() {
Derek Sollenberger17662382018-09-13 14:14:00 -040034#if HWUI_NULL_GPU
Alec Mourie55aa632020-04-15 19:46:05 -070035 mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
Derek Sollenberger17662382018-09-13 14:14:00 -040036#else
Alec Mourie55aa632020-04-15 19:46:05 -070037 mMaxTextureSize = -1;
Derek Sollenberger17662382018-09-13 14:14:00 -040038#endif
Alec Mouri22d753f2019-09-05 17:11:45 -070039}
Alec Mourie55aa632020-04-15 19:46:05 -070040
41void 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 Sollenberger17662382018-09-13 14:14:00 -040076}
77
78int DeviceInfo::maxTextureSize() const {
79 LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet.");
80 return mMaxTextureSize;
81}
82
83void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
John Reckcf185f52019-04-11 16:11:24 -070084 DeviceInfo::get()->mMaxTextureSize = maxTextureSize;
85}
86
Alec Mourie55aa632020-04-15 19:46:05 -070087void DeviceInfo::setWideColorDataspace(ADataSpace dataspace) {
88 switch (dataspace) {
89 case ADATASPACE_DISPLAY_P3:
90 get()->mWideColorSpace =
Mike Reed7ac1af32020-05-26 10:50:21 -040091 SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
Alec Mourie55aa632020-04-15 19:46:05 -070092 break;
93 case ADATASPACE_SCRGB:
94 get()->mWideColorSpace = SkColorSpace::MakeSRGB();
95 break;
John Reck5f66fb82022-09-23 17:49:23 -040096 default:
97 ALOGW("Unknown dataspace %d", dataspace);
98 // Treat unknown dataspaces as sRGB, so fall through
99 [[fallthrough]];
Alec Mourie55aa632020-04-15 19:46:05 -0700100 case ADATASPACE_SRGB:
101 // when sRGB is returned, it means wide color gamut is not supported.
102 get()->mWideColorSpace = SkColorSpace::MakeSRGB();
103 break;
Alec Mourie55aa632020-04-15 19:46:05 -0700104 }
Alec Mouri22d753f2019-09-05 17:11:45 -0700105}
106
Sally Qi02068d52022-08-30 16:29:14 -0700107void DeviceInfo::setSupportFp16ForHdr(bool supportFp16ForHdr) {
108 get()->mSupportFp16ForHdr = supportFp16ForHdr;
109}
110
Alec Mouri4a3035e2024-03-04 23:12:42 +0000111void DeviceInfo::setSupportRgba10101010ForHdr(bool supportRgba10101010ForHdr) {
112 get()->mSupportRgba10101010ForHdr = supportRgba10101010ForHdr;
113}
114
Sally Qi830b0412022-12-14 16:26:49 -0800115void DeviceInfo::setSupportMixedColorSpaces(bool supportMixedColorSpaces) {
116 get()->mSupportMixedColorSpaces = supportMixedColorSpaces;
117}
118
Alec Mourie55aa632020-04-15 19:46:05 -0700119void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) {
120 mVsyncPeriod = vsyncPeriod;
Derek Sollenberger17662382018-09-13 14:14:00 -0400121}
122
Alec Mourid5fa1dc2020-04-06 13:15:28 -0700123std::atomic<float> DeviceInfo::sDensity = 2.0;
124
John Reck704bed02015-11-05 09:22:17 -0800125} /* namespace uirenderer */
126} /* namespace android */