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 | */ |
| 16 | #ifndef DEVICEINFO_H |
| 17 | #define DEVICEINFO_H |
| 18 | |
Kevin Lubick | 07d6aae | 2022-04-01 14:03:11 -0400 | [diff] [blame] | 19 | #include <SkColorSpace.h> |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 20 | #include <SkImageInfo.h> |
Kevin Lubick | 07d6aae | 2022-04-01 14:03:11 -0400 | [diff] [blame] | 21 | #include <SkRefCnt.h> |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 22 | #include <android/data_space.h> |
| 23 | |
| 24 | #include <mutex> |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 25 | |
Alec Mouri | 22ab7f3 | 2023-09-06 02:11:56 +0000 | [diff] [blame^] | 26 | #include "Properties.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 27 | #include "utils/Macros.h" |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 32 | namespace renderthread { |
| 33 | class RenderThread; |
| 34 | } |
| 35 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 36 | class DeviceInfo { |
| 37 | PREVENT_COPY_AND_ASSIGN(DeviceInfo); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 38 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 39 | public: |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 40 | static DeviceInfo* get(); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 41 | static int32_t getWidth() { return get()->mWidth; } |
| 42 | static int32_t getHeight() { return get()->mHeight; } |
Alec Mouri | d5fa1dc | 2020-04-06 13:15:28 -0700 | [diff] [blame] | 43 | // Gets the density in density-independent pixels |
| 44 | static float getDensity() { return sDensity.load(); } |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 45 | static int64_t getVsyncPeriod() { return get()->mVsyncPeriod; } |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 46 | static int64_t getCompositorOffset() { return get()->getCompositorOffsetInternal(); } |
| 47 | static int64_t getAppOffset() { return get()->mAppVsyncOffsetNanos; } |
Alec Mouri | d5fa1dc | 2020-04-06 13:15:28 -0700 | [diff] [blame] | 48 | // Sets the density in density-independent pixels |
| 49 | static void setDensity(float density) { sDensity.store(density); } |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 50 | static void setWidth(int32_t width) { get()->mWidth = width; } |
| 51 | static void setHeight(int32_t height) { get()->mHeight = height; } |
| 52 | static void setRefreshRate(float refreshRate) { |
| 53 | get()->mVsyncPeriod = static_cast<int64_t>(1000000000 / refreshRate); |
| 54 | } |
| 55 | static void setPresentationDeadlineNanos(int64_t deadlineNanos) { |
| 56 | get()->mPresentationDeadlineNanos = deadlineNanos; |
| 57 | } |
| 58 | static void setAppVsyncOffsetNanos(int64_t offsetNanos) { |
| 59 | get()->mAppVsyncOffsetNanos = offsetNanos; |
| 60 | } |
| 61 | static void setWideColorDataspace(ADataSpace dataspace); |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 62 | |
Sally Qi | 02068d5 | 2022-08-30 16:29:14 -0700 | [diff] [blame] | 63 | static void setSupportFp16ForHdr(bool supportFp16ForHdr); |
Alec Mouri | 22ab7f3 | 2023-09-06 02:11:56 +0000 | [diff] [blame^] | 64 | static bool isSupportFp16ForHdr() { |
| 65 | if (!Properties::hdr10bitPlus) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return get()->mSupportFp16ForHdr; |
| 70 | }; |
Sally Qi | 02068d5 | 2022-08-30 16:29:14 -0700 | [diff] [blame] | 71 | |
Sally Qi | 830b041 | 2022-12-14 16:26:49 -0800 | [diff] [blame] | 72 | static void setSupportMixedColorSpaces(bool supportMixedColorSpaces); |
| 73 | static bool isSupportMixedColorSpaces() { return get()->mSupportMixedColorSpaces; }; |
| 74 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 75 | // this value is only valid after the GPU has been initialized and there is a valid graphics |
| 76 | // context or if you are using the HWUI_NULL_GPU |
| 77 | int maxTextureSize() const; |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 78 | sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; } |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 79 | SkColorType getWideColorType() { |
| 80 | static std::once_flag kFlag; |
| 81 | // lazily update display info from SF here, so that the call is performed by RenderThread. |
| 82 | std::call_once(kFlag, [&, this]() { updateDisplayInfo(); }); |
| 83 | return mWideColorType; |
| 84 | } |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 85 | |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 86 | // This method should be called whenever the display refresh rate changes. |
| 87 | void onRefreshRateChanged(int64_t vsyncPeriod); |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 88 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 89 | private: |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 90 | friend class renderthread::RenderThread; |
| 91 | static void setMaxTextureSize(int maxTextureSize); |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 92 | void updateDisplayInfo(); |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 93 | int64_t getCompositorOffsetInternal() const { |
| 94 | // Assume that SF takes around a millisecond to latch buffers after |
| 95 | // waking up |
| 96 | return mVsyncPeriod - (mPresentationDeadlineNanos - 1000000); |
| 97 | } |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 98 | |
Derek Sollenberger | 1766238 | 2018-09-13 14:14:00 -0400 | [diff] [blame] | 99 | DeviceInfo(); |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 100 | ~DeviceInfo() = default; |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 101 | |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 102 | int mMaxTextureSize; |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 103 | sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB(); |
Sally Qi | 02068d5 | 2022-08-30 16:29:14 -0700 | [diff] [blame] | 104 | bool mSupportFp16ForHdr = false; |
Sally Qi | 830b041 | 2022-12-14 16:26:49 -0800 | [diff] [blame] | 105 | bool mSupportMixedColorSpaces = false; |
Alec Mouri | 70f2a92 | 2019-11-20 11:10:29 -0800 | [diff] [blame] | 106 | SkColorType mWideColorType = SkColorType::kN32_SkColorType; |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 107 | int mDisplaysSize = 0; |
| 108 | int mPhysicalDisplayIndex = -1; |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 109 | int32_t mWidth = 1080; |
| 110 | int32_t mHeight = 1920; |
Alec Mouri | 4a818f1 | 2019-11-19 16:17:53 -0800 | [diff] [blame] | 111 | int64_t mVsyncPeriod = 16666666; |
Alec Mouri | 978a2cc | 2020-05-12 22:51:15 -0700 | [diff] [blame] | 112 | // Magically corresponds with an sf offset of 0 for a sane default. |
| 113 | int64_t mPresentationDeadlineNanos = 17666666; |
Alec Mouri | e55aa63 | 2020-04-15 19:46:05 -0700 | [diff] [blame] | 114 | int64_t mAppVsyncOffsetNanos = 0; |
Alec Mouri | d5fa1dc | 2020-04-06 13:15:28 -0700 | [diff] [blame] | 115 | |
| 116 | // Density is not retrieved from the ADisplay apis, so this may potentially |
| 117 | // be called on multiple threads. |
| 118 | // Unit is density-independent pixels |
| 119 | static std::atomic<float> sDensity; |
John Reck | 704bed0 | 2015-11-05 09:22:17 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | } /* namespace uirenderer */ |
| 123 | } /* namespace android */ |
| 124 | |
| 125 | #endif /* DEVICEINFO_H */ |