blob: cf5d7ce3f738090730fc4f98a4258962ce7422f4 [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>
18
John Reck56428472018-03-16 17:27:17 -070019#include "Properties.h"
20
John Reck8dc02f92017-07-17 09:55:02 -070021#include <gui/ISurfaceComposer.h>
22#include <gui/SurfaceComposerClient.h>
Peiyong Lin3bff1352018-12-11 07:56:07 -080023#include <ui/GraphicTypes.h>
John Reck704bed02015-11-05 09:22:17 -080024
John Reck704bed02015-11-05 09:22:17 -080025#include <mutex>
John Reck1bcacfd2017-11-03 10:12:19 -070026#include <thread>
John Reck704bed02015-11-05 09:22:17 -080027
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070028#include <log/log.h>
29
John Reck704bed02015-11-05 09:22:17 -080030namespace android {
31namespace uirenderer {
32
John Recke170fb62018-05-07 08:12:07 -070033static constexpr android::DisplayInfo sDummyDisplay{
John Reck56428472018-03-16 17:27:17 -070034 1080, // w
35 1920, // h
36 320.0, // xdpi
37 320.0, // ydpi
38 60.0, // fps
39 2.0, // density
40 0, // orientation
41 false, // secure?
42 0, // appVsyncOffset
43 0, // presentationDeadline
Yiwei Zhang2c2bfc32018-08-23 17:24:55 -070044 1080, // viewportW
45 1920, // viewportH
John Reck56428472018-03-16 17:27:17 -070046};
47
John Reck704bed02015-11-05 09:22:17 -080048const DeviceInfo* DeviceInfo::get() {
Derek Sollenberger17662382018-09-13 14:14:00 -040049 static DeviceInfo sDeviceInfo;
50 return &sDeviceInfo;
John Reck704bed02015-11-05 09:22:17 -080051}
52
Derek Sollenberger17662382018-09-13 14:14:00 -040053DisplayInfo QueryDisplayInfo() {
John Reck56428472018-03-16 17:27:17 -070054 if (Properties::isolatedProcess) {
55 return sDummyDisplay;
56 }
57
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080058 const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken();
59 LOG_ALWAYS_FATAL_IF(token == nullptr,
60 "Failed to get display info because internal display is disconnected");
61
John Reck56428472018-03-16 17:27:17 -070062 DisplayInfo displayInfo;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -080063 status_t status = SurfaceComposerClient::getDisplayInfo(token, &displayInfo);
John Reck8dc02f92017-07-17 09:55:02 -070064 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
John Reck56428472018-03-16 17:27:17 -070065 return displayInfo;
John Reck8dc02f92017-07-17 09:55:02 -070066}
67
Brian Osmane0cf5972019-01-23 10:41:20 -050068static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) {
Peiyong Lin3bff1352018-12-11 07:56:07 -080069 if (Properties::isolatedProcess) {
Peiyong Lin3bff1352018-12-11 07:56:07 -080070 *colorSpace = SkColorSpace::MakeSRGB();
71 *colorType = SkColorType::kN32_SkColorType;
72 return;
73 }
74 ui::Dataspace defaultDataspace, wcgDataspace;
75 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
76 status_t status =
77 SurfaceComposerClient::getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
78 &wcgDataspace, &wcgPixelFormat);
79 LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
80 switch (wcgDataspace) {
81 case ui::Dataspace::DISPLAY_P3:
Brian Osmanbe8fac262019-01-14 17:02:23 -050082 *colorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
Peiyong Lin3bff1352018-12-11 07:56:07 -080083 break;
84 case ui::Dataspace::V0_SCRGB:
Peiyong Lin3bff1352018-12-11 07:56:07 -080085 *colorSpace = SkColorSpace::MakeSRGB();
86 break;
87 case ui::Dataspace::V0_SRGB:
88 // when sRGB is returned, it means wide color gamut is not supported.
Peiyong Lin3bff1352018-12-11 07:56:07 -080089 *colorSpace = SkColorSpace::MakeSRGB();
90 break;
91 default:
92 LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
93 }
94 switch (wcgPixelFormat) {
95 case ui::PixelFormat::RGBA_8888:
96 *colorType = SkColorType::kN32_SkColorType;
97 break;
98 case ui::PixelFormat::RGBA_FP16:
99 *colorType = SkColorType::kRGBA_F16_SkColorType;
100 break;
101 default:
102 LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format.");
103 }
104}
105
Derek Sollenberger17662382018-09-13 14:14:00 -0400106DeviceInfo::DeviceInfo() {
107#if HWUI_NULL_GPU
108 mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
109#else
110 mMaxTextureSize = -1;
111#endif
112 mDisplayInfo = QueryDisplayInfo();
Brian Osmane0cf5972019-01-23 10:41:20 -0500113 queryWideColorGamutPreference(&mWideColorSpace, &mWideColorType);
Derek Sollenberger17662382018-09-13 14:14:00 -0400114}
115
116int DeviceInfo::maxTextureSize() const {
117 LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet.");
118 return mMaxTextureSize;
119}
120
121void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
122 const_cast<DeviceInfo*>(DeviceInfo::get())->mMaxTextureSize = maxTextureSize;
123}
124
John Reck704bed02015-11-05 09:22:17 -0800125} /* namespace uirenderer */
126} /* namespace android */