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 | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 19 | #include "Properties.h" |
| 20 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 21 | #include <gui/ISurfaceComposer.h> |
| 22 | #include <gui/SurfaceComposerClient.h> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 23 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 24 | #include <mutex> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #include <thread> |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 26 | |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 27 | #include <log/log.h> |
| 28 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 32 | static constexpr android::DisplayInfo sDummyDisplay{ |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 33 | 1080, // w |
| 34 | 1920, // h |
| 35 | 320.0, // xdpi |
| 36 | 320.0, // ydpi |
| 37 | 60.0, // fps |
| 38 | 2.0, // density |
| 39 | 0, // orientation |
| 40 | false, // secure? |
| 41 | 0, // appVsyncOffset |
| 42 | 0, // presentationDeadline |
Yiwei Zhang | 2c2bfc3 | 2018-08-23 17:24:55 -0700 | [diff] [blame] | 43 | 1080, // viewportW |
| 44 | 1920, // viewportH |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 47 | const DeviceInfo* DeviceInfo::get() { |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame^] | 48 | static DeviceInfo sDeviceInfo; |
| 49 | return &sDeviceInfo; |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame^] | 52 | DisplayInfo QueryDisplayInfo() { |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 53 | if (Properties::isolatedProcess) { |
| 54 | return sDummyDisplay; |
| 55 | } |
| 56 | |
| 57 | DisplayInfo displayInfo; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 58 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 59 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo); |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 60 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status); |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 61 | return displayInfo; |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame^] | 64 | void QueryCompositionPreference(ui::Dataspace* dataSpace, |
| 65 | ui::PixelFormat* pixelFormat) { |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 66 | if (Properties::isolatedProcess) { |
| 67 | *dataSpace = ui::Dataspace::V0_SRGB; |
| 68 | *pixelFormat = ui::PixelFormat::RGBA_8888; |
| 69 | } |
| 70 | |
| 71 | status_t status = |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame^] | 72 | SurfaceComposerClient::getCompositionPreference(dataSpace, pixelFormat); |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 73 | LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status); |
| 74 | } |
| 75 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame^] | 76 | DeviceInfo::DeviceInfo() { |
| 77 | #if HWUI_NULL_GPU |
| 78 | mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; |
| 79 | #else |
| 80 | mMaxTextureSize = -1; |
| 81 | #endif |
| 82 | mDisplayInfo = QueryDisplayInfo(); |
| 83 | QueryCompositionPreference(&mTargetDataSpace, &mTargetPixelFormat); |
| 84 | } |
| 85 | |
| 86 | int DeviceInfo::maxTextureSize() const { |
| 87 | LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); |
| 88 | return mMaxTextureSize; |
| 89 | } |
| 90 | |
| 91 | void DeviceInfo::setMaxTextureSize(int maxTextureSize) { |
| 92 | const_cast<DeviceInfo*>(DeviceInfo::get())->mMaxTextureSize = maxTextureSize; |
| 93 | } |
| 94 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 95 | } /* namespace uirenderer */ |
| 96 | } /* namespace android */ |