blob: bcc930107a8b499687ef3f84c6d95adb95b5f52f [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 */
16#ifndef DEVICEINFO_H
17#define DEVICEINFO_H
18
Alec Mouri22d753f2019-09-05 17:11:45 -070019#include <apex/display.h>
Peiyong Lin3bff1352018-12-11 07:56:07 -080020#include <SkImageInfo.h>
John Reck8dc02f92017-07-17 09:55:02 -070021
John Reck1bcacfd2017-11-03 10:12:19 -070022#include "utils/Macros.h"
John Reck704bed02015-11-05 09:22:17 -080023
24namespace android {
25namespace uirenderer {
26
Derek Sollenberger17662382018-09-13 14:14:00 -040027namespace renderthread {
28 class RenderThread;
29}
30
John Reck704bed02015-11-05 09:22:17 -080031class DeviceInfo {
32 PREVENT_COPY_AND_ASSIGN(DeviceInfo);
John Reck1bcacfd2017-11-03 10:12:19 -070033
John Reck704bed02015-11-05 09:22:17 -080034public:
John Reckcf185f52019-04-11 16:11:24 -070035 static DeviceInfo* get();
Alec Mouri22d753f2019-09-05 17:11:45 -070036 static float getMaxRefreshRate() { return get()->mMaxRefreshRate; }
37 static int32_t getWidth() { return get()->mWidth; }
38 static int32_t getHeight() { return get()->mHeight; }
Alec Mourid5fa1dc2020-04-06 13:15:28 -070039 // Gets the density in density-independent pixels
40 static float getDensity() { return sDensity.load(); }
Alec Mouri4a818f12019-11-19 16:17:53 -080041 static int64_t getVsyncPeriod() { return get()->mVsyncPeriod; }
Alec Mouri22d753f2019-09-05 17:11:45 -070042 static int64_t getCompositorOffset() { return get()->mCompositorOffset; }
43 static int64_t getAppOffset() { return get()->mAppOffset; }
Alec Mourid5fa1dc2020-04-06 13:15:28 -070044 // Sets the density in density-independent pixels
45 static void setDensity(float density) { sDensity.store(density); }
John Reck704bed02015-11-05 09:22:17 -080046
Derek Sollenberger17662382018-09-13 14:14:00 -040047 // this value is only valid after the GPU has been initialized and there is a valid graphics
48 // context or if you are using the HWUI_NULL_GPU
49 int maxTextureSize() const;
Peiyong Lin3bff1352018-12-11 07:56:07 -080050 sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; }
51 SkColorType getWideColorType() const { return mWideColorType; }
John Reckcf185f52019-04-11 16:11:24 -070052
Alec Mouri4a818f12019-11-19 16:17:53 -080053 // This method should be called whenever the display refresh rate changes.
54 void onRefreshRateChanged(int64_t vsyncPeriod);
John Reck56428472018-03-16 17:27:17 -070055
John Reck704bed02015-11-05 09:22:17 -080056private:
Derek Sollenberger17662382018-09-13 14:14:00 -040057 friend class renderthread::RenderThread;
58 static void setMaxTextureSize(int maxTextureSize);
Alec Mouri22d753f2019-09-05 17:11:45 -070059 void updateDisplayInfo();
Peiyong Lin1f6aa122018-09-10 16:28:08 -070060
Derek Sollenberger17662382018-09-13 14:14:00 -040061 DeviceInfo();
Alec Mouri22d753f2019-09-05 17:11:45 -070062 ~DeviceInfo();
John Reck704bed02015-11-05 09:22:17 -080063
John Reck704bed02015-11-05 09:22:17 -080064 int mMaxTextureSize;
Alec Mouri70f2a922019-11-20 11:10:29 -080065 sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB();
66 SkColorType mWideColorType = SkColorType::kN32_SkColorType;
Alec Mouri22d753f2019-09-05 17:11:45 -070067 ADisplayConfig* mCurrentConfig = nullptr;
68 ADisplay** mDisplays = nullptr;
69 int mDisplaysSize = 0;
70 int mPhysicalDisplayIndex = -1;
71 float mMaxRefreshRate = 60.0;
72 int32_t mWidth = 1080;
73 int32_t mHeight = 1920;
Alec Mouri4a818f12019-11-19 16:17:53 -080074 int64_t mVsyncPeriod = 16666666;
Alec Mouri22d753f2019-09-05 17:11:45 -070075 int64_t mCompositorOffset = 0;
76 int64_t mAppOffset = 0;
Alec Mourid5fa1dc2020-04-06 13:15:28 -070077
78 // Density is not retrieved from the ADisplay apis, so this may potentially
79 // be called on multiple threads.
80 // Unit is density-independent pixels
81 static std::atomic<float> sDensity;
John Reck704bed02015-11-05 09:22:17 -080082};
83
84} /* namespace uirenderer */
85} /* namespace android */
86
87#endif /* DEVICEINFO_H */