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
19 #include "Properties.h"
20
21 #include <gui/ISurfaceComposer.h>
22 #include <gui/SurfaceComposerClient.h>
23
24 #include <mutex>
25 #include <thread>
26
27 #include <log/log.h>
28
29 #include <GLES2/gl2.h>
30
31 namespace android {
32 namespace uirenderer {
33
34 static 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
47 static DeviceInfo* sDeviceInfo = nullptr;
48 static std::once_flag sInitializedFlag;
49
get()50 const DeviceInfo* DeviceInfo::get() {
51 LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized.");
52 return sDeviceInfo;
53 }
54
initialize()55 void DeviceInfo::initialize() {
56 std::call_once(sInitializedFlag, []() {
57 sDeviceInfo = new DeviceInfo();
58 sDeviceInfo->load();
59 });
60 }
61
initialize(int maxTextureSize)62 void DeviceInfo::initialize(int maxTextureSize) {
63 std::call_once(sInitializedFlag, [maxTextureSize]() {
64 sDeviceInfo = new DeviceInfo();
65 sDeviceInfo->mDisplayInfo = DeviceInfo::queryDisplayInfo();
66 sDeviceInfo->mMaxTextureSize = maxTextureSize;
67 });
68 }
69
load()70 void DeviceInfo::load() {
71 mDisplayInfo = queryDisplayInfo();
72 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
73 }
74
queryDisplayInfo()75 DisplayInfo DeviceInfo::queryDisplayInfo() {
76 if (Properties::isolatedProcess) {
77 return sDummyDisplay;
78 }
79
80 DisplayInfo displayInfo;
81 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
82 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo);
83 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
84 return displayInfo;
85 }
86
87 } /* namespace uirenderer */
88 } /* namespace android */
89