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 <SkCanvas.h> |
| 20 | #include <SkColor.h> |
| 21 | #include <unordered_map> |
| 22 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 23 | #include <math/vec4.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 24 | #include <renderengine/RenderEngine.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/Rect.h> |
| 27 | #include <ui/Size.h> |
| 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 | |
| 32 | namespace android { |
| 33 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 34 | class Client; |
| 35 | class GraphicBuffer; |
| 36 | class IBinder; |
| 37 | class IGraphicBufferProducer; |
| 38 | class Layer; |
| 39 | class SurfaceFlinger; |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 40 | class SurfaceControl; |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 41 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 42 | class RefreshRateOverlay { |
| 43 | public: |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 44 | RefreshRateOverlay(SurfaceFlinger&, uint32_t lowFps, uint32_t highFps, bool showSpinner); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 45 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 46 | void setLayerStack(ui::LayerStack); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 47 | void setViewport(ui::Size); |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame^] | 48 | void changeRefreshRate(Fps); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 49 | void animate(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 50 | |
| 51 | private: |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 52 | class SevenSegmentDrawer { |
| 53 | public: |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 54 | static std::vector<sp<GraphicBuffer>> draw(int number, SkColor& color, |
| 55 | ui::Transform::RotationFlags, bool showSpinner); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 56 | static uint32_t getHeight() { return BUFFER_HEIGHT; } |
| 57 | static uint32_t getWidth() { return BUFFER_WIDTH; } |
| 58 | |
| 59 | private: |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 60 | enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom }; |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 61 | |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 62 | static void drawSegment(Segment segment, int left, SkColor& color, SkCanvas& canvas); |
| 63 | static void drawDigit(int digit, int left, SkColor& color, SkCanvas& canvas); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 64 | |
| 65 | static constexpr uint32_t DIGIT_HEIGHT = 100; |
| 66 | static constexpr uint32_t DIGIT_WIDTH = 64; |
| 67 | static constexpr uint32_t DIGIT_SPACE = 16; |
| 68 | static constexpr uint32_t BUFFER_HEIGHT = DIGIT_HEIGHT; |
| 69 | static constexpr uint32_t BUFFER_WIDTH = |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 70 | 4 * DIGIT_WIDTH + 3 * DIGIT_SPACE; // Digit|Space|Digit|Space|Digit|Space|Spinner |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 73 | bool createLayer(); |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 74 | |
| 75 | const std::vector<sp<GraphicBuffer>>& getOrCreateBuffers(uint32_t fps); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 76 | |
| 77 | SurfaceFlinger& mFlinger; |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 78 | const sp<Client> mClient; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 79 | sp<IBinder> mIBinder; |
| 80 | sp<IGraphicBufferProducer> mGbp; |
| 81 | |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 82 | std::unordered_map<ui::Transform::RotationFlags, |
| 83 | std::unordered_map<int, std::vector<sp<GraphicBuffer>>>> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 84 | mBufferCache; |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 85 | std::optional<int> mCurrentFps; |
| 86 | int mFrame = 0; |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 87 | static constexpr float ALPHA = 0.8f; |
rnlee | 756005b | 2021-05-27 10:46:36 -0700 | [diff] [blame] | 88 | const SkColor LOW_FPS_COLOR = SK_ColorRED; |
| 89 | const SkColor HIGH_FPS_COLOR = SK_ColorGREEN; |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 90 | |
| 91 | const bool mShowSpinner; |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 92 | |
| 93 | // Interpolate the colors between these values. |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 94 | const uint32_t mLowFps; |
| 95 | const uint32_t mHighFps; |
chaviw | 70aa757 | 2021-09-22 12:27:57 -0500 | [diff] [blame] | 96 | |
| 97 | sp<SurfaceControl> mSurfaceControl; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 100 | } // namespace android |