blob: b5b87d516ff70f0a70c448cf0229bda7372fd844 [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>
John Reck704bed02015-11-05 09:22:17 -080023
John Reck704bed02015-11-05 09:22:17 -080024#include <mutex>
John Reck1bcacfd2017-11-03 10:12:19 -070025#include <thread>
John Reck704bed02015-11-05 09:22:17 -080026
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070027#include <log/log.h>
28
29#include <GLES2/gl2.h>
30
John Reck704bed02015-11-05 09:22:17 -080031namespace android {
32namespace uirenderer {
33
John Recke170fb62018-05-07 08:12:07 -070034static constexpr android::DisplayInfo sDummyDisplay{
John Reck56428472018-03-16 17:27:17 -070035 1080, // w
36 1920, // h
37 320.0, // xdpi
38 320.0, // ydpi
39 60.0, // fps
40 2.0, // density
41 0, // orientation
42 false, // secure?
43 0, // appVsyncOffset
44 0, // presentationDeadline
Yiwei Zhang2c2bfc32018-08-23 17:24:55 -070045 1080, // viewportW
46 1920, // viewportH
John Reck56428472018-03-16 17:27:17 -070047};
48
John Reck704bed02015-11-05 09:22:17 -080049static DeviceInfo* sDeviceInfo = nullptr;
50static std::once_flag sInitializedFlag;
51
52const DeviceInfo* DeviceInfo::get() {
Chris Craik8ecf41c2015-11-16 10:27:59 -080053 LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized.");
John Reck704bed02015-11-05 09:22:17 -080054 return sDeviceInfo;
55}
56
57void DeviceInfo::initialize() {
58 std::call_once(sInitializedFlag, []() {
59 sDeviceInfo = new DeviceInfo();
60 sDeviceInfo->load();
61 });
62}
63
Stan Iliev500a0c32016-10-26 10:30:09 -040064void DeviceInfo::initialize(int maxTextureSize) {
65 std::call_once(sInitializedFlag, [maxTextureSize]() {
66 sDeviceInfo = new DeviceInfo();
John Reck56428472018-03-16 17:27:17 -070067 sDeviceInfo->mDisplayInfo = DeviceInfo::queryDisplayInfo();
Stan Iliev500a0c32016-10-26 10:30:09 -040068 sDeviceInfo->mMaxTextureSize = maxTextureSize;
Peiyong Lin1f6aa122018-09-10 16:28:08 -070069 sDeviceInfo->queryCompositionPreference(&sDeviceInfo->mTargetDataSpace,
70 &sDeviceInfo->mTargetPixelFormat);
Stan Iliev500a0c32016-10-26 10:30:09 -040071 });
72}
73
John Reck704bed02015-11-05 09:22:17 -080074void DeviceInfo::load() {
John Reck56428472018-03-16 17:27:17 -070075 mDisplayInfo = queryDisplayInfo();
John Reck704bed02015-11-05 09:22:17 -080076 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Peiyong Lin1f6aa122018-09-10 16:28:08 -070077 sDeviceInfo->queryCompositionPreference(&sDeviceInfo->mTargetDataSpace,
78 &sDeviceInfo->mTargetPixelFormat);
John Reck704bed02015-11-05 09:22:17 -080079}
80
John Reck56428472018-03-16 17:27:17 -070081DisplayInfo DeviceInfo::queryDisplayInfo() {
82 if (Properties::isolatedProcess) {
83 return sDummyDisplay;
84 }
85
86 DisplayInfo displayInfo;
John Reck1bcacfd2017-11-03 10:12:19 -070087 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
John Reck56428472018-03-16 17:27:17 -070088 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo);
John Reck8dc02f92017-07-17 09:55:02 -070089 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
John Reck56428472018-03-16 17:27:17 -070090 return displayInfo;
John Reck8dc02f92017-07-17 09:55:02 -070091}
92
Peiyong Lin1f6aa122018-09-10 16:28:08 -070093void DeviceInfo::queryCompositionPreference(ui::Dataspace* dataSpace,
94 ui::PixelFormat* pixelFormat) {
95 if (Properties::isolatedProcess) {
96 *dataSpace = ui::Dataspace::V0_SRGB;
97 *pixelFormat = ui::PixelFormat::RGBA_8888;
98 }
99
100 status_t status =
101 SurfaceComposerClient::getCompositionPreference(dataSpace, pixelFormat);
102 LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
103}
104
John Reck704bed02015-11-05 09:22:17 -0800105} /* namespace uirenderer */
106} /* namespace android */