blob: 40cc73a82846a9c95bab25000aebead67e785097 [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 Reck56428472018-03-16 17:27:17 -070034static constexpr android::DisplayInfo sDummyDisplay {
35 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
45};
46
John Reck704bed02015-11-05 09:22:17 -080047static DeviceInfo* sDeviceInfo = nullptr;
48static std::once_flag sInitializedFlag;
49
50const DeviceInfo* DeviceInfo::get() {
Chris Craik8ecf41c2015-11-16 10:27:59 -080051 LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized.");
John Reck704bed02015-11-05 09:22:17 -080052 return sDeviceInfo;
53}
54
55void DeviceInfo::initialize() {
56 std::call_once(sInitializedFlag, []() {
57 sDeviceInfo = new DeviceInfo();
58 sDeviceInfo->load();
59 });
60}
61
Stan Iliev500a0c32016-10-26 10:30:09 -040062void DeviceInfo::initialize(int maxTextureSize) {
63 std::call_once(sInitializedFlag, [maxTextureSize]() {
64 sDeviceInfo = new DeviceInfo();
John Reck56428472018-03-16 17:27:17 -070065 sDeviceInfo->mDisplayInfo = DeviceInfo::queryDisplayInfo();
Stan Iliev500a0c32016-10-26 10:30:09 -040066 sDeviceInfo->mMaxTextureSize = maxTextureSize;
67 });
68}
69
John Reck704bed02015-11-05 09:22:17 -080070void DeviceInfo::load() {
John Reck56428472018-03-16 17:27:17 -070071 mDisplayInfo = queryDisplayInfo();
John Reck704bed02015-11-05 09:22:17 -080072 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
73}
74
John Reck56428472018-03-16 17:27:17 -070075DisplayInfo DeviceInfo::queryDisplayInfo() {
76 if (Properties::isolatedProcess) {
77 return sDummyDisplay;
78 }
79
80 DisplayInfo displayInfo;
John Reck1bcacfd2017-11-03 10:12:19 -070081 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
John Reck56428472018-03-16 17:27:17 -070082 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo);
John Reck8dc02f92017-07-17 09:55:02 -070083 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
John Reck56428472018-03-16 17:27:17 -070084 return displayInfo;
John Reck8dc02f92017-07-17 09:55:02 -070085}
86
John Reck704bed02015-11-05 09:22:17 -080087} /* namespace uirenderer */
88} /* namespace android */