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 | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 19 | #include <unordered_map> |
| 20 | |
| 21 | #include <math/vec4.h> |
| 22 | #include <ui/Rect.h> |
| 23 | #include <ui/Size.h> |
| 24 | #include <utils/StrongPointer.h> |
| 25 | |
| 26 | #include "Scheduler/RefreshRateConfigs.h" |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 30 | class Client; |
| 31 | class GraphicBuffer; |
| 32 | class IBinder; |
| 33 | class IGraphicBufferProducer; |
| 34 | class Layer; |
| 35 | class SurfaceFlinger; |
| 36 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 37 | using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 38 | |
| 39 | class RefreshRateOverlay { |
| 40 | public: |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame^] | 41 | RefreshRateOverlay(SurfaceFlinger&, bool showSpinner); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 42 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 43 | void setViewport(ui::Size); |
| 44 | void changeRefreshRate(const RefreshRate&); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame^] | 45 | void onInvalidate(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 48 | class SevenSegmentDrawer { |
| 49 | public: |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame^] | 50 | static std::vector<sp<GraphicBuffer>> drawNumber(int number, const half4& color, |
| 51 | bool showSpinner); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 52 | static uint32_t getHeight() { return BUFFER_HEIGHT; } |
| 53 | static uint32_t getWidth() { return BUFFER_WIDTH; } |
| 54 | |
| 55 | private: |
| 56 | enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Buttom }; |
| 57 | |
| 58 | static void drawRect(const Rect& r, const half4& color, const sp<GraphicBuffer>& buffer, |
| 59 | uint8_t* pixels); |
| 60 | static void drawSegment(Segment segment, int left, const half4& color, |
| 61 | const sp<GraphicBuffer>& buffer, uint8_t* pixels); |
| 62 | static void drawDigit(int digit, int left, const half4& color, |
| 63 | const sp<GraphicBuffer>& buffer, uint8_t* pixels); |
| 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(); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 74 | void primeCache(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 75 | |
| 76 | SurfaceFlinger& mFlinger; |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 77 | const sp<Client> mClient; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 78 | sp<Layer> mLayer; |
| 79 | sp<IBinder> mIBinder; |
| 80 | sp<IGraphicBufferProducer> mGbp; |
| 81 | |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame^] | 82 | std::unordered_map<int, std::vector<sp<GraphicBuffer>>> mBufferCache; |
| 83 | std::optional<int> mCurrentFps; |
| 84 | int mFrame = 0; |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame] | 85 | static constexpr float ALPHA = 0.8f; |
| 86 | const half3 LOW_FPS_COLOR = half3(1.0f, 0.0f, 0.0f); |
| 87 | const half3 HIGH_FPS_COLOR = half3(0.0f, 1.0f, 0.0f); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame^] | 88 | |
| 89 | const bool mShowSpinner; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 92 | } // namespace android |