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 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "SurfaceFlinger.h" |
| 19 | |
| 20 | namespace android { |
| 21 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 22 | using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate; |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 23 | |
| 24 | class RefreshRateOverlay { |
| 25 | public: |
| 26 | RefreshRateOverlay(SurfaceFlinger& flinger); |
| 27 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 28 | void changeRefreshRate(const RefreshRate& refreshRate); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 29 | |
| 30 | private: |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame^] | 31 | class SevenSegmentDrawer { |
| 32 | public: |
| 33 | static sp<GraphicBuffer> drawNumber(int number, const half4& color); |
| 34 | static uint32_t getHeight() { return BUFFER_HEIGHT; } |
| 35 | static uint32_t getWidth() { return BUFFER_WIDTH; } |
| 36 | |
| 37 | private: |
| 38 | enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Buttom }; |
| 39 | |
| 40 | static void drawRect(const Rect& r, const half4& color, const sp<GraphicBuffer>& buffer, |
| 41 | uint8_t* pixels); |
| 42 | static void drawSegment(Segment segment, int left, const half4& color, |
| 43 | const sp<GraphicBuffer>& buffer, uint8_t* pixels); |
| 44 | static void drawDigit(int digit, int left, const half4& color, |
| 45 | const sp<GraphicBuffer>& buffer, uint8_t* pixels); |
| 46 | |
| 47 | static constexpr uint32_t DIGIT_HEIGHT = 100; |
| 48 | static constexpr uint32_t DIGIT_WIDTH = 64; |
| 49 | static constexpr uint32_t DIGIT_SPACE = 16; |
| 50 | static constexpr uint32_t BUFFER_HEIGHT = DIGIT_HEIGHT; |
| 51 | static constexpr uint32_t BUFFER_WIDTH = |
| 52 | 3 * DIGIT_WIDTH + 2 * DIGIT_SPACE; // Digit|Space|Digit|Space|Digit |
| 53 | }; |
| 54 | |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 55 | bool createLayer(); |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame^] | 56 | void primeCache(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 57 | |
| 58 | SurfaceFlinger& mFlinger; |
| 59 | sp<Client> mClient; |
| 60 | sp<Layer> mLayer; |
| 61 | sp<IBinder> mIBinder; |
| 62 | sp<IGraphicBufferProducer> mGbp; |
| 63 | |
Ady Abraham | 2cb8b62 | 2019-12-02 18:55:33 -0800 | [diff] [blame^] | 64 | std::unordered_map<int, sp<GraphicBuffer>> mBufferCache; |
| 65 | |
| 66 | static constexpr float ALPHA = 0.8f; |
| 67 | const half3 LOW_FPS_COLOR = half3(1.0f, 0.0f, 0.0f); |
| 68 | const half3 HIGH_FPS_COLOR = half3(0.0f, 1.0f, 0.0f); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | }; // namespace android |