blob: 35c80201d7f867c1cc4308b409ffdf790271b786 [file] [log] [blame]
Ady Abraham03b02dd2019-03-21 15:40:11 -07001/*
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 Laskowski20134642020-04-20 22:36:44 -070016
Ady Abraham03b02dd2019-03-21 15:40:11 -070017#pragma once
18
Dominik Laskowski20134642020-04-20 22:36:44 -070019#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 Abraham03b02dd2019-03-21 15:40:11 -070027
28namespace android {
29
Dominik Laskowski20134642020-04-20 22:36:44 -070030class Client;
31class GraphicBuffer;
32class IBinder;
33class IGraphicBufferProducer;
34class Layer;
35class SurfaceFlinger;
36
Ady Abraham2139f732019-11-13 18:56:40 -080037using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate;
Ady Abraham03b02dd2019-03-21 15:40:11 -070038
39class RefreshRateOverlay {
40public:
Dominik Laskowski20134642020-04-20 22:36:44 -070041 explicit RefreshRateOverlay(SurfaceFlinger&);
Ady Abraham03b02dd2019-03-21 15:40:11 -070042
Dominik Laskowski20134642020-04-20 22:36:44 -070043 void setViewport(ui::Size);
44 void changeRefreshRate(const RefreshRate&);
Ady Abraham03b02dd2019-03-21 15:40:11 -070045
46private:
Ady Abraham2cb8b622019-12-02 18:55:33 -080047 class SevenSegmentDrawer {
48 public:
49 static sp<GraphicBuffer> drawNumber(int number, const half4& color);
50 static uint32_t getHeight() { return BUFFER_HEIGHT; }
51 static uint32_t getWidth() { return BUFFER_WIDTH; }
52
53 private:
54 enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Buttom };
55
56 static void drawRect(const Rect& r, const half4& color, const sp<GraphicBuffer>& buffer,
57 uint8_t* pixels);
58 static void drawSegment(Segment segment, int left, const half4& color,
59 const sp<GraphicBuffer>& buffer, uint8_t* pixels);
60 static void drawDigit(int digit, int left, const half4& color,
61 const sp<GraphicBuffer>& buffer, uint8_t* pixels);
62
63 static constexpr uint32_t DIGIT_HEIGHT = 100;
64 static constexpr uint32_t DIGIT_WIDTH = 64;
65 static constexpr uint32_t DIGIT_SPACE = 16;
66 static constexpr uint32_t BUFFER_HEIGHT = DIGIT_HEIGHT;
67 static constexpr uint32_t BUFFER_WIDTH =
68 3 * DIGIT_WIDTH + 2 * DIGIT_SPACE; // Digit|Space|Digit|Space|Digit
69 };
70
Ady Abraham03b02dd2019-03-21 15:40:11 -070071 bool createLayer();
Ady Abraham2cb8b622019-12-02 18:55:33 -080072 void primeCache();
Ady Abraham03b02dd2019-03-21 15:40:11 -070073
74 SurfaceFlinger& mFlinger;
Dominik Laskowski20134642020-04-20 22:36:44 -070075 const sp<Client> mClient;
Ady Abraham03b02dd2019-03-21 15:40:11 -070076 sp<Layer> mLayer;
77 sp<IBinder> mIBinder;
78 sp<IGraphicBufferProducer> mGbp;
79
Ady Abraham2cb8b622019-12-02 18:55:33 -080080 std::unordered_map<int, sp<GraphicBuffer>> mBufferCache;
81
82 static constexpr float ALPHA = 0.8f;
83 const half3 LOW_FPS_COLOR = half3(1.0f, 0.0f, 0.0f);
84 const half3 HIGH_FPS_COLOR = half3(0.0f, 1.0f, 0.0f);
Ady Abraham03b02dd2019-03-21 15:40:11 -070085};
86
Dominik Laskowski20134642020-04-20 22:36:44 -070087} // namespace android