John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 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 | */ |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 16 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 17 | #include <DeviceInfo.h> |
| 18 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 19 | #include <gui/ISurfaceComposer.h> |
| 20 | #include <gui/SurfaceComposerClient.h> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 21 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 22 | #include <mutex> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 23 | #include <thread> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 24 | |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 25 | #include <log/log.h> |
| 26 | |
| 27 | #include <GLES2/gl2.h> |
| 28 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
| 32 | static DeviceInfo* sDeviceInfo = nullptr; |
| 33 | static std::once_flag sInitializedFlag; |
| 34 | |
| 35 | const DeviceInfo* DeviceInfo::get() { |
Chris Craik | 8ecf41c | 2015-11-16 10:27:59 -0800 | [diff] [blame] | 36 | LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized."); |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 37 | return sDeviceInfo; |
| 38 | } |
| 39 | |
| 40 | void DeviceInfo::initialize() { |
| 41 | std::call_once(sInitializedFlag, []() { |
| 42 | sDeviceInfo = new DeviceInfo(); |
| 43 | sDeviceInfo->load(); |
| 44 | }); |
| 45 | } |
| 46 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 47 | void DeviceInfo::initialize(int maxTextureSize) { |
| 48 | std::call_once(sInitializedFlag, [maxTextureSize]() { |
| 49 | sDeviceInfo = new DeviceInfo(); |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 50 | sDeviceInfo->loadDisplayInfo(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 51 | sDeviceInfo->mMaxTextureSize = maxTextureSize; |
| 52 | }); |
| 53 | } |
| 54 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 55 | void DeviceInfo::load() { |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 56 | loadDisplayInfo(); |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 57 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); |
| 58 | } |
| 59 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 60 | void DeviceInfo::loadDisplayInfo() { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 61 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 62 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &mDisplayInfo); |
| 63 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status); |
| 64 | } |
| 65 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 66 | } /* namespace uirenderer */ |
| 67 | } /* namespace android */ |