blob: 0b9d82b105a322b4650b15dbad3cf821264e6e53 [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
John Reck704bed02015-11-05 09:22:17 -080029namespace android {
30namespace uirenderer {
31
John Recke170fb62018-05-07 08:12:07 -070032static constexpr android::DisplayInfo sDummyDisplay{
John Reck56428472018-03-16 17:27:17 -070033 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 Zhang2c2bfc32018-08-23 17:24:55 -070043 1080, // viewportW
44 1920, // viewportH
John Reck56428472018-03-16 17:27:17 -070045};
46
John Reck704bed02015-11-05 09:22:17 -080047const DeviceInfo* DeviceInfo::get() {
Derek Sollenberger17662382018-09-13 14:14:00 -040048 static DeviceInfo sDeviceInfo;
49 return &sDeviceInfo;
John Reck704bed02015-11-05 09:22:17 -080050}
51
Derek Sollenberger17662382018-09-13 14:14:00 -040052DisplayInfo QueryDisplayInfo() {
John Reck56428472018-03-16 17:27:17 -070053 if (Properties::isolatedProcess) {
54 return sDummyDisplay;
55 }
56
57 DisplayInfo displayInfo;
John Reck1bcacfd2017-11-03 10:12:19 -070058 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
John Reck56428472018-03-16 17:27:17 -070059 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &displayInfo);
John Reck8dc02f92017-07-17 09:55:02 -070060 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status);
John Reck56428472018-03-16 17:27:17 -070061 return displayInfo;
John Reck8dc02f92017-07-17 09:55:02 -070062}
63
Derek Sollenberger17662382018-09-13 14:14:00 -040064DeviceInfo::DeviceInfo() {
65#if HWUI_NULL_GPU
66 mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
67#else
68 mMaxTextureSize = -1;
69#endif
70 mDisplayInfo = QueryDisplayInfo();
Derek Sollenberger17662382018-09-13 14:14:00 -040071}
72
73int DeviceInfo::maxTextureSize() const {
74 LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet.");
75 return mMaxTextureSize;
76}
77
78void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
79 const_cast<DeviceInfo*>(DeviceInfo::get())->mMaxTextureSize = maxTextureSize;
80}
81
John Reck704bed02015-11-05 09:22:17 -080082} /* namespace uirenderer */
83} /* namespace android */