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