Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | */ |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 16 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 17 | #pragma once |
| 18 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 19 | #include "Utils/OverlayUtils.h" |
| 20 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 21 | #include <vector> |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 22 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 23 | #include <ftl/flags.h> |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 24 | #include <ftl/small_map.h> |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 25 | #include <ui/LayerStack.h> |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 26 | #include <ui/Size.h> |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 27 | #include <ui/Transform.h> |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 28 | #include <utils/StrongPointer.h> |
| 29 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 30 | #include <scheduler/Fps.h> |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 31 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 32 | class SkCanvas; |
| 33 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 36 | class GraphicBuffer; |
Ady Abraham | 3649ea8 | 2022-07-08 16:04:02 -0700 | [diff] [blame] | 37 | class SurfaceFlinger; |
| 38 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 39 | class RefreshRateOverlay { |
Ady Abraham | ddba934 | 2023-10-02 16:28:03 -0700 | [diff] [blame] | 40 | private: |
| 41 | // Effectively making the constructor private, while keeping std::make_unique work |
| 42 | struct ConstructorTag {}; |
| 43 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 44 | public: |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 45 | enum class Features { |
| 46 | Spinner = 1 << 0, |
| 47 | RenderRate = 1 << 1, |
Yifei Zhang | cfb7bb3 | 2023-01-12 16:17:14 -0800 | [diff] [blame] | 48 | ShowInMiddle = 1 << 2, |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 49 | SetByHwc = 1 << 3, |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
Ady Abraham | ddba934 | 2023-10-02 16:28:03 -0700 | [diff] [blame] | 52 | static std::unique_ptr<RefreshRateOverlay> create(FpsRange, ftl::Flags<Features>); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 53 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 54 | void setLayerStack(ui::LayerStack); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 55 | void setViewport(ui::Size); |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 56 | void changeRefreshRate(Fps, Fps); |
ramindani | 3faf574 | 2023-09-21 13:45:12 -0700 | [diff] [blame] | 57 | void changeRenderRate(Fps); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 58 | void animate(); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 59 | bool isSetByHwc() const { return mFeatures.test(RefreshRateOverlay::Features::SetByHwc); } |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 60 | void onVrrIdle(bool idle); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 61 | |
Ady Abraham | ddba934 | 2023-10-02 16:28:03 -0700 | [diff] [blame] | 62 | RefreshRateOverlay(ConstructorTag, FpsRange, ftl::Flags<Features>); |
| 63 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 64 | private: |
Ady Abraham | ddba934 | 2023-10-02 16:28:03 -0700 | [diff] [blame] | 65 | bool initCheck() const; |
| 66 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 67 | using Buffers = std::vector<sp<GraphicBuffer>>; |
| 68 | |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 69 | static Buffers draw(int refreshRate, int renderFps, bool idle, SkColor, |
| 70 | ui::Transform::RotationFlags, ftl::Flags<Features>); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 71 | static void drawNumber(int number, int left, SkColor, SkCanvas&); |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 72 | static void drawDash(int left, SkCanvas&); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 73 | |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 74 | const Buffers& getOrCreateBuffers(Fps, Fps, bool); |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 75 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 76 | SurfaceComposerClient::Transaction createTransaction() const; |
| 77 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 78 | struct Key { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 79 | int refreshRate; |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 80 | int renderFps; |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 81 | ui::Transform::RotationFlags flags; |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 82 | bool idle; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 83 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 84 | bool operator==(Key other) const { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 85 | return refreshRate == other.refreshRate && renderFps == other.renderFps && |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 86 | flags == other.flags && idle == other.idle; |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 87 | } |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 88 | }; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 89 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 90 | using BufferCache = ftl::SmallMap<Key, Buffers, 9>; |
| 91 | BufferCache mBufferCache; |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 92 | |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 93 | std::optional<Fps> mRefreshRate; |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 94 | std::optional<Fps> mRenderFps; |
Ady Abraham | e294632 | 2024-07-10 17:45:29 -0700 | [diff] [blame] | 95 | bool mIsVrrIdle = false; |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 96 | size_t mFrame = 0; |
| 97 | |
| 98 | const FpsRange mFpsRange; // For color interpolation. |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 99 | const ftl::Flags<Features> mFeatures; |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 100 | |
Ady Abraham | 3649ea8 | 2022-07-08 16:04:02 -0700 | [diff] [blame] | 101 | const std::unique_ptr<SurfaceControlHolder> mSurfaceControl; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 104 | } // namespace android |