| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef DEVICEINFO_H |
| 17 |
#define DEVICEINFO_H |
| 18 |
|
| 19 |
#include <SkImageInfo.h> |
| 20 |
#include <android/data_space.h> |
| 21 |
|
| 22 |
#include <mutex> |
| 23 |
|
| 24 |
#include "utils/Macros.h" |
| 25 |
|
| 26 |
namespace android { |
| 27 |
namespace uirenderer { |
| 28 |
|
| 29 |
namespace renderthread { |
| 30 |
class RenderThread; |
| 31 |
} |
| 32 |
|
| 33 |
class DeviceInfo { |
| 34 |
PREVENT_COPY_AND_ASSIGN(DeviceInfo); |
| 35 |
|
| 36 |
public: |
| 37 |
static DeviceInfo* get(); |
| 38 |
static int32_t getWidth() { return get()->mWidth; } |
| 39 |
static int32_t getHeight() { return get()->mHeight; } |
| 40 |
|
| 41 |
static float getDensity() { return sDensity.load(); } |
| 42 |
static int64_t getVsyncPeriod() { return get()->mVsyncPeriod; } |
| 43 |
static int64_t getCompositorOffset() { return get()->getCompositorOffsetInternal(); } |
| 44 |
static int64_t getAppOffset() { return get()->mAppVsyncOffsetNanos; } |
| 45 |
|
| 46 |
static void setDensity(float density) { sDensity.store(density); } |
| 47 |
static void setWidth(int32_t width) { get()->mWidth = width; } |
| 48 |
static void setHeight(int32_t height) { get()->mHeight = height; } |
| 49 |
static void setRefreshRate(float refreshRate) { |
| 50 |
get()->mVsyncPeriod = static_cast<int64_t>(1000000000 / refreshRate); |
| 51 |
} |
| 52 |
static void setPresentationDeadlineNanos(int64_t deadlineNanos) { |
| 53 |
get()->mPresentationDeadlineNanos = deadlineNanos; |
| 54 |
} |
| 55 |
static void setAppVsyncOffsetNanos(int64_t offsetNanos) { |
| 56 |
get()->mAppVsyncOffsetNanos = offsetNanos; |
| 57 |
} |
| 58 |
static void setWideColorDataspace(ADataSpace dataspace); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
int maxTextureSize() const; |
| 63 |
sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; } |
| 64 |
SkColorType getWideColorType() { |
| 65 |
static std::once_flag kFlag; |
| 66 |
|
| 67 |
std::call_once(kFlag, [&, this]() { updateDisplayInfo(); }); |
| 68 |
return mWideColorType; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
void onRefreshRateChanged(int64_t vsyncPeriod); |
| 73 |
|
| 74 |
private: |
| 75 |
friend class renderthread::RenderThread; |
| 76 |
static void setMaxTextureSize(int maxTextureSize); |
| 77 |
void updateDisplayInfo(); |
| 78 |
int64_t getCompositorOffsetInternal() const { |
| 79 |
|
| 80 |
|
| 81 |
return mVsyncPeriod - (mPresentationDeadlineNanos - 1000000); |
| 82 |
} |
| 83 |
|
| 84 |
DeviceInfo(); |
| 85 |
~DeviceInfo() = default; |
| 86 |
|
| 87 |
int mMaxTextureSize; |
| 88 |
sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB(); |
| 89 |
SkColorType mWideColorType = SkColorType::kN32_SkColorType; |
| 90 |
int mDisplaysSize = 0; |
| 91 |
int mPhysicalDisplayIndex = -1; |
| 92 |
int32_t mWidth = 1080; |
| 93 |
int32_t mHeight = 1920; |
| 94 |
int64_t mVsyncPeriod = 16666666; |
| 95 |
|
| 96 |
int64_t mPresentationDeadlineNanos = 17666666; |
| 97 |
int64_t mAppVsyncOffsetNanos = 0; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
static std::atomic<float> sDensity; |
| 103 |
}; |
| 104 |
|
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
#endif |