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 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 22 | #include <ftl/small_map.h> |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 23 | #include <ui/LayerStack.h> |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 24 | #include <ui/Size.h> |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 25 | #include <ui/Transform.h> |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 26 | #include <utils/StrongPointer.h> |
| 27 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 28 | #include <scheduler/Fps.h> |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 29 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 30 | class SkCanvas; |
| 31 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 34 | class GraphicBuffer; |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 35 | class SurfaceControl; |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 36 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 37 | class RefreshRateOverlay { |
| 38 | public: |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 39 | RefreshRateOverlay(FpsRange, bool showSpinner); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 40 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 41 | void setLayerStack(ui::LayerStack); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 42 | void setViewport(ui::Size); |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 43 | void changeRefreshRate(Fps); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 44 | void animate(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 45 | |
| 46 | private: |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 47 | using Buffers = std::vector<sp<GraphicBuffer>>; |
| 48 | |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 49 | class SevenSegmentDrawer { |
| 50 | public: |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 51 | static Buffers draw(int number, SkColor, ui::Transform::RotationFlags, bool showSpinner); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 52 | |
| 53 | private: |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 54 | enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom }; |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 55 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 56 | static void drawSegment(Segment, int left, SkColor, SkCanvas&); |
| 57 | static void drawDigit(int digit, int left, SkColor, SkCanvas&); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 60 | const Buffers& getOrCreateBuffers(Fps); |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 61 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 62 | struct Key { |
| 63 | int fps; |
| 64 | ui::Transform::RotationFlags flags; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 65 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 66 | bool operator==(Key other) const { return fps == other.fps && flags == other.flags; } |
| 67 | }; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 68 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 69 | using BufferCache = ftl::SmallMap<Key, Buffers, 9>; |
| 70 | BufferCache mBufferCache; |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 71 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 72 | std::optional<Fps> mCurrentFps; |
| 73 | size_t mFrame = 0; |
| 74 | |
| 75 | const FpsRange mFpsRange; // For color interpolation. |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 76 | const bool mShowSpinner; |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 77 | |
Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame^] | 78 | const sp<SurfaceControl> mSurfaceControl; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 81 | } // namespace android |