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  */
16 #ifndef DEVICEINFO_H
17 #define DEVICEINFO_H
18 
19 #include <apex/display.h>
20 #include <SkImageInfo.h>
21 
22 #include "utils/Macros.h"
23 
24 namespace android {
25 namespace uirenderer {
26 
27 namespace renderthread {
28     class RenderThread;
29 }
30 
31 class DeviceInfo {
32     PREVENT_COPY_AND_ASSIGN(DeviceInfo);
33 
34 public:
35     static DeviceInfo* get();
getMaxRefreshRate()36     static float getMaxRefreshRate() { return get()->mMaxRefreshRate; }
getWidth()37     static int32_t getWidth() { return get()->mWidth; }
getHeight()38     static int32_t getHeight() { return get()->mHeight; }
getDensity()39     static float getDensity() { return get()->mDensity; }
getVsyncPeriod()40     static int64_t getVsyncPeriod() { return get()->mVsyncPeriod; }
getCompositorOffset()41     static int64_t getCompositorOffset() { return get()->mCompositorOffset; }
getAppOffset()42     static int64_t getAppOffset() { return get()->mAppOffset; }
43 
44     // this value is only valid after the GPU has been initialized and there is a valid graphics
45     // context or if you are using the HWUI_NULL_GPU
46     int maxTextureSize() const;
getWideColorSpace()47     sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; }
getWideColorType()48     SkColorType getWideColorType() const { return mWideColorType; }
49 
50     // This method should be called whenever the display refresh rate changes.
51     void onRefreshRateChanged(int64_t vsyncPeriod);
52 
53 private:
54     friend class renderthread::RenderThread;
55     static void setMaxTextureSize(int maxTextureSize);
56     void updateDisplayInfo();
57 
58     DeviceInfo();
59     ~DeviceInfo();
60 
61     int mMaxTextureSize;
62     sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB();
63     SkColorType mWideColorType = SkColorType::kN32_SkColorType;
64     ADisplayConfig* mCurrentConfig = nullptr;
65     ADisplay** mDisplays = nullptr;
66     int mDisplaysSize = 0;
67     int mPhysicalDisplayIndex = -1;
68     float mMaxRefreshRate = 60.0;
69     int32_t mWidth = 1080;
70     int32_t mHeight = 1920;
71     float mDensity = 2.0;
72     int64_t mVsyncPeriod = 16666666;
73     int64_t mCompositorOffset = 0;
74     int64_t mAppOffset = 0;
75 };
76 
77 } /* namespace uirenderer */
78 } /* namespace android */
79 
80 #endif /* DEVICEINFO_H */
81