blob: a465a367478e83c13e5d8d562686acb2f05c6d7b [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 Laskowskif6b4ba62021-11-09 12:46:10 -080019#include <SkColor.h>
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070020#include <vector>
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080021
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070022#include <ftl/small_map.h>
Dominik Laskowski29fa1462021-04-27 15:51:50 -070023#include <ui/LayerStack.h>
Dominik Laskowski20134642020-04-20 22:36:44 -070024#include <ui/Size.h>
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070025#include <ui/Transform.h>
Dominik Laskowski20134642020-04-20 22:36:44 -070026#include <utils/StrongPointer.h>
27
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080028#include <scheduler/Fps.h>
Ady Abraham03b02dd2019-03-21 15:40:11 -070029
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070030class SkCanvas;
31
Ady Abraham03b02dd2019-03-21 15:40:11 -070032namespace android {
33
Dominik Laskowski20134642020-04-20 22:36:44 -070034class GraphicBuffer;
chaviw70aa7572021-09-22 12:27:57 -050035class SurfaceControl;
Dominik Laskowski20134642020-04-20 22:36:44 -070036
Ady Abraham03b02dd2019-03-21 15:40:11 -070037class RefreshRateOverlay {
38public:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070039 RefreshRateOverlay(FpsRange, bool showSpinner);
Ady Abraham03b02dd2019-03-21 15:40:11 -070040
Dominik Laskowski29fa1462021-04-27 15:51:50 -070041 void setLayerStack(ui::LayerStack);
Dominik Laskowski20134642020-04-20 22:36:44 -070042 void setViewport(ui::Size);
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080043 void changeRefreshRate(Fps);
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070044 void animate();
Ady Abraham03b02dd2019-03-21 15:40:11 -070045
46private:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070047 using Buffers = std::vector<sp<GraphicBuffer>>;
48
Ady Abraham2cb8b622019-12-02 18:55:33 -080049 class SevenSegmentDrawer {
50 public:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070051 static Buffers draw(int number, SkColor, ui::Transform::RotationFlags, bool showSpinner);
Ady Abraham2cb8b622019-12-02 18:55:33 -080052
53 private:
rnlee756005b2021-05-27 10:46:36 -070054 enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom };
Ady Abraham2cb8b622019-12-02 18:55:33 -080055
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070056 static void drawSegment(Segment, int left, SkColor, SkCanvas&);
57 static void drawDigit(int digit, int left, SkColor, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080058 };
59
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070060 const Buffers& getOrCreateBuffers(Fps);
chaviw70aa7572021-09-22 12:27:57 -050061
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070062 struct Key {
63 int fps;
64 ui::Transform::RotationFlags flags;
Ady Abraham03b02dd2019-03-21 15:40:11 -070065
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070066 bool operator==(Key other) const { return fps == other.fps && flags == other.flags; }
67 };
Ady Abraham03b02dd2019-03-21 15:40:11 -070068
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070069 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
70 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -070071
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070072 std::optional<Fps> mCurrentFps;
73 size_t mFrame = 0;
74
75 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham29d0da32020-07-16 18:39:33 -070076 const bool mShowSpinner;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +010077
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070078 const sp<SurfaceControl> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -070079};
80
Dominik Laskowski20134642020-04-20 22:36:44 -070081} // namespace android