blob: a2966e654eaf14a85c2d9ae1fccc13a44720dfdc [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;
Ady Abraham3649ea82022-07-08 16:04:02 -070036class SurfaceFlinger;
37
38// Helper class to delete the SurfaceControl on a helper thread as
39// SurfaceControl assumes its destruction happens without SurfaceFlinger::mStateLock held.
40class SurfaceControlHolder {
41public:
42 explicit SurfaceControlHolder(sp<SurfaceControl> sc) : mSurfaceControl(std::move(sc)){};
43 ~SurfaceControlHolder();
44
45 const sp<SurfaceControl>& get() const { return mSurfaceControl; }
46
47private:
48 sp<SurfaceControl> mSurfaceControl;
49};
Dominik Laskowski20134642020-04-20 22:36:44 -070050
Ady Abraham03b02dd2019-03-21 15:40:11 -070051class RefreshRateOverlay {
52public:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070053 RefreshRateOverlay(FpsRange, bool showSpinner);
Ady Abraham03b02dd2019-03-21 15:40:11 -070054
Dominik Laskowski29fa1462021-04-27 15:51:50 -070055 void setLayerStack(ui::LayerStack);
Dominik Laskowski20134642020-04-20 22:36:44 -070056 void setViewport(ui::Size);
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080057 void changeRefreshRate(Fps);
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070058 void animate();
Ady Abraham03b02dd2019-03-21 15:40:11 -070059
60private:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070061 using Buffers = std::vector<sp<GraphicBuffer>>;
62
Ady Abraham2cb8b622019-12-02 18:55:33 -080063 class SevenSegmentDrawer {
64 public:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070065 static Buffers draw(int number, SkColor, ui::Transform::RotationFlags, bool showSpinner);
Ady Abraham2cb8b622019-12-02 18:55:33 -080066
67 private:
rnlee756005b2021-05-27 10:46:36 -070068 enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom };
Ady Abraham2cb8b622019-12-02 18:55:33 -080069
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070070 static void drawSegment(Segment, int left, SkColor, SkCanvas&);
71 static void drawDigit(int digit, int left, SkColor, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080072 };
73
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070074 const Buffers& getOrCreateBuffers(Fps);
chaviw70aa7572021-09-22 12:27:57 -050075
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070076 struct Key {
77 int fps;
78 ui::Transform::RotationFlags flags;
Ady Abraham03b02dd2019-03-21 15:40:11 -070079
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070080 bool operator==(Key other) const { return fps == other.fps && flags == other.flags; }
81 };
Ady Abraham03b02dd2019-03-21 15:40:11 -070082
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070083 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
84 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -070085
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070086 std::optional<Fps> mCurrentFps;
87 size_t mFrame = 0;
88
89 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham29d0da32020-07-16 18:39:33 -070090 const bool mShowSpinner;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +010091
Ady Abraham3649ea82022-07-08 16:04:02 -070092 const std::unique_ptr<SurfaceControlHolder> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -070093};
94
Dominik Laskowski20134642020-04-20 22:36:44 -070095} // namespace android