• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 
17 #include <DeviceInfo.h>
18 #include <android/hardware_buffer.h>
19 #include <apex/display.h>
20 #include <log/log.h>
21 #include <utils/Errors.h>
22 
23 #include "Properties.h"
24 
25 namespace android {
26 namespace uirenderer {
27 
get()28 DeviceInfo* DeviceInfo::get() {
29     static DeviceInfo sDeviceInfo;
30     return &sDeviceInfo;
31 }
32 
DeviceInfo()33 DeviceInfo::DeviceInfo() {
34 #if HWUI_NULL_GPU
35     mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
36 #else
37     mMaxTextureSize = -1;
38 #endif
39 }
40 
updateDisplayInfo()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!");
76 }
77 
maxTextureSize() const78 int DeviceInfo::maxTextureSize() const {
79     LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet.");
80     return mMaxTextureSize;
81 }
82 
setMaxTextureSize(int maxTextureSize)83 void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
84     DeviceInfo::get()->mMaxTextureSize = maxTextureSize;
85 }
86 
setWideColorDataspace(ADataSpace dataspace)87 void DeviceInfo::setWideColorDataspace(ADataSpace dataspace) {
88     switch (dataspace) {
89         case ADATASPACE_DISPLAY_P3:
90             get()->mWideColorSpace =
91                     SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
92             break;
93         case ADATASPACE_SCRGB:
94             get()->mWideColorSpace = SkColorSpace::MakeSRGB();
95             break;
96         case ADATASPACE_SRGB:
97             // when sRGB is returned, it means wide color gamut is not supported.
98             get()->mWideColorSpace = SkColorSpace::MakeSRGB();
99             break;
100         default:
101             LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
102     }
103 }
104 
onRefreshRateChanged(int64_t vsyncPeriod)105 void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) {
106     mVsyncPeriod = vsyncPeriod;
107 }
108 
109 std::atomic<float> DeviceInfo::sDensity = 2.0;
110 
111 } /* namespace uirenderer */
112 } /* namespace android */
113