blob: e4162875279c909beb6c4e315debdb96ca7a5df7 [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 Reck8dc02f92017-07-17 09:55:02 -070019#include <gui/ISurfaceComposer.h>
20#include <gui/SurfaceComposerClient.h>
John Reck704bed02015-11-05 09:22:17 -080021
John Reck704bed02015-11-05 09:22:17 -080022#include <mutex>
John Reck1bcacfd2017-11-03 10:12:19 -070023#include <thread>
John Reck704bed02015-11-05 09:22:17 -080024
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070025#include <log/log.h>
26
27#include <GLES2/gl2.h>
28
John Reck704bed02015-11-05 09:22:17 -080029namespace android {
30namespace uirenderer {
31
32static DeviceInfo* sDeviceInfo = nullptr;
33static std::once_flag sInitializedFlag;
34
35const DeviceInfo* DeviceInfo::get() {
Chris Craik8ecf41c2015-11-16 10:27:59 -080036 LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized.");
John Reck704bed02015-11-05 09:22:17 -080037 return sDeviceInfo;
38}
39
40void DeviceInfo::initialize() {
41 std::call_once(sInitializedFlag, []() {
42 sDeviceInfo = new DeviceInfo();
43 sDeviceInfo->load();
44 });
45}
46
Stan Iliev500a0c32016-10-26 10:30:09 -040047void DeviceInfo::initialize(int maxTextureSize) {
48 std::call_once(sInitializedFlag, [maxTextureSize]() {
49 sDeviceInfo = new DeviceInfo();
John Reck8dc02f92017-07-17 09:55:02 -070050 sDeviceInfo->loadDisplayInfo();
Stan Iliev500a0c32016-10-26 10:30:09 -040051 sDeviceInfo->mMaxTextureSize = maxTextureSize;
52 });
53}
54
John Reck704bed02015-11-05 09:22:17 -080055void DeviceInfo::load() {
John Reck8dc02f92017-07-17 09:55:02 -070056 loadDisplayInfo();
John Reck704bed02015-11-05 09:22:17 -080057 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
58}
59
John Reck8dc02f92017-07-17 09:55:02 -070060void DeviceInfo::loadDisplayInfo() {
John Reck1bcacfd2017-11-03 10:12:19 -070061 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
John Reck8dc02f92017-07-17 09:55:02 -070062 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &mDisplayInfo);
63 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
64}
65
John Reck704bed02015-11-05 09:22:17 -080066} /* namespace uirenderer */
67} /* namespace android */