blob: a43f58cd1e56145a850816259e2adf1bc4d5479d [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;
69 });
70}
71
John Reck704bed02015-11-05 09:22:17 -080072void DeviceInfo::load() {
John Reck56428472018-03-16 17:27:17 -070073 mDisplayInfo = queryDisplayInfo();
John Reck704bed02015-11-05 09:22:17 -080074 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
75}
76
John Reck56428472018-03-16 17:27:17 -070077DisplayInfo DeviceInfo::queryDisplayInfo() {
78 if (Properties::isolatedProcess) {
79 return sDummyDisplay;
80 }
81
82 DisplayInfo displayInfo;
John Reck1bcacfd2017-11-03 10:12:19 -070083 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
John Reck56428472018-03-16 17:27:17 -070084 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo);
John Reck8dc02f92017-07-17 09:55:02 -070085 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
John Reck56428472018-03-16 17:27:17 -070086 return displayInfo;
John Reck8dc02f92017-07-17 09:55:02 -070087}
88
John Reck704bed02015-11-05 09:22:17 -080089} /* namespace uirenderer */
90} /* namespace android */