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 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 19 | #include <SkColor.h> |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 20 | #include <vector> |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 21 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 22 | #include <ftl/flags.h> |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 23 | #include <ftl/small_map.h> |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 24 | #include <gui/SurfaceComposerClient.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; |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 37 | class SurfaceControl; |
Ady Abraham | 3649ea8 | 2022-07-08 16:04:02 -0700 | [diff] [blame] | 38 | class SurfaceFlinger; |
| 39 | |
| 40 | // Helper class to delete the SurfaceControl on a helper thread as |
| 41 | // SurfaceControl assumes its destruction happens without SurfaceFlinger::mStateLock held. |
| 42 | class SurfaceControlHolder { |
| 43 | public: |
| 44 | explicit SurfaceControlHolder(sp<SurfaceControl> sc) : mSurfaceControl(std::move(sc)){}; |
| 45 | ~SurfaceControlHolder(); |
| 46 | |
| 47 | const sp<SurfaceControl>& get() const { return mSurfaceControl; } |
| 48 | |
| 49 | private: |
| 50 | sp<SurfaceControl> mSurfaceControl; |
| 51 | }; |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 52 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 53 | class RefreshRateOverlay { |
| 54 | public: |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 55 | enum class Features { |
| 56 | Spinner = 1 << 0, |
| 57 | RenderRate = 1 << 1, |
Yifei Zhang | cfb7bb3 | 2023-01-12 16:17:14 -0800 | [diff] [blame] | 58 | ShowInMiddle = 1 << 2, |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 59 | SetByHwc = 1 << 3, |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | RefreshRateOverlay(FpsRange, ftl::Flags<Features>); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 63 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 64 | void setLayerStack(ui::LayerStack); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 65 | void setViewport(ui::Size); |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 66 | void changeRefreshRate(Fps, Fps); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 67 | void animate(); |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 68 | bool isSetByHwc() const { return mFeatures.test(RefreshRateOverlay::Features::SetByHwc); } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 69 | |
| 70 | private: |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 71 | using Buffers = std::vector<sp<GraphicBuffer>>; |
| 72 | |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 73 | class SevenSegmentDrawer { |
| 74 | public: |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 75 | static Buffers draw(int displayFps, int renderFps, SkColor, ui::Transform::RotationFlags, |
| 76 | ftl::Flags<Features>); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 77 | |
| 78 | private: |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 79 | enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom }; |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 80 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 81 | static void drawSegment(Segment, int left, SkColor, SkCanvas&); |
| 82 | static void drawDigit(int digit, int left, SkColor, SkCanvas&); |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 83 | static void drawNumber(int number, int left, SkColor, SkCanvas&); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 86 | const Buffers& getOrCreateBuffers(Fps, Fps); |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 87 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 88 | SurfaceComposerClient::Transaction createTransaction() const; |
| 89 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 90 | struct Key { |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 91 | int displayFps; |
| 92 | int renderFps; |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 93 | ui::Transform::RotationFlags flags; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 94 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 95 | bool operator==(Key other) const { |
| 96 | return displayFps == other.displayFps && renderFps == other.renderFps && |
| 97 | flags == other.flags; |
| 98 | } |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 99 | }; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 100 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 101 | using BufferCache = ftl::SmallMap<Key, Buffers, 9>; |
| 102 | BufferCache mBufferCache; |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 103 | |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 104 | std::optional<Fps> mDisplayFps; |
| 105 | std::optional<Fps> mRenderFps; |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 106 | size_t mFrame = 0; |
| 107 | |
| 108 | const FpsRange mFpsRange; // For color interpolation. |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 109 | const ftl::Flags<Features> mFeatures; |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 110 | |
Ady Abraham | 3649ea8 | 2022-07-08 16:04:02 -0700 | [diff] [blame] | 111 | const std::unique_ptr<SurfaceControlHolder> mSurfaceControl; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 114 | } // namespace android |