blob: 0b89b8e3a1270cbaa6a6980abb7a2b2699fa157b [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
Ady Abraham0aa373a2022-11-22 13:56:50 -080022#include <ftl/flags.h>
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070023#include <ftl/small_map.h>
ramindanib2158ee2023-02-13 20:29:59 -080024#include <gui/SurfaceComposerClient.h>
Dominik Laskowski29fa1462021-04-27 15:51:50 -070025#include <ui/LayerStack.h>
Dominik Laskowski20134642020-04-20 22:36:44 -070026#include <ui/Size.h>
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070027#include <ui/Transform.h>
Dominik Laskowski20134642020-04-20 22:36:44 -070028#include <utils/StrongPointer.h>
29
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080030#include <scheduler/Fps.h>
Ady Abraham03b02dd2019-03-21 15:40:11 -070031
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070032class SkCanvas;
33
Ady Abraham03b02dd2019-03-21 15:40:11 -070034namespace android {
35
Dominik Laskowski20134642020-04-20 22:36:44 -070036class GraphicBuffer;
chaviw70aa7572021-09-22 12:27:57 -050037class SurfaceControl;
Ady Abraham3649ea82022-07-08 16:04:02 -070038class SurfaceFlinger;
39
40// Helper class to delete the SurfaceControl on a helper thread as
41// SurfaceControl assumes its destruction happens without SurfaceFlinger::mStateLock held.
42class SurfaceControlHolder {
43public:
44 explicit SurfaceControlHolder(sp<SurfaceControl> sc) : mSurfaceControl(std::move(sc)){};
45 ~SurfaceControlHolder();
46
47 const sp<SurfaceControl>& get() const { return mSurfaceControl; }
48
49private:
50 sp<SurfaceControl> mSurfaceControl;
51};
Dominik Laskowski20134642020-04-20 22:36:44 -070052
Ady Abraham03b02dd2019-03-21 15:40:11 -070053class RefreshRateOverlay {
54public:
Ady Abraham0aa373a2022-11-22 13:56:50 -080055 enum class Features {
56 Spinner = 1 << 0,
57 RenderRate = 1 << 1,
Yifei Zhangcfb7bb32023-01-12 16:17:14 -080058 ShowInMiddle = 1 << 2,
ramindanib2158ee2023-02-13 20:29:59 -080059 SetByHwc = 1 << 3,
Ady Abraham0aa373a2022-11-22 13:56:50 -080060 };
61
62 RefreshRateOverlay(FpsRange, ftl::Flags<Features>);
Ady Abraham03b02dd2019-03-21 15:40:11 -070063
Dominik Laskowski29fa1462021-04-27 15:51:50 -070064 void setLayerStack(ui::LayerStack);
Dominik Laskowski20134642020-04-20 22:36:44 -070065 void setViewport(ui::Size);
Ady Abraham0aa373a2022-11-22 13:56:50 -080066 void changeRefreshRate(Fps, Fps);
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070067 void animate();
ramindanib2158ee2023-02-13 20:29:59 -080068 bool isSetByHwc() const { return mFeatures.test(RefreshRateOverlay::Features::SetByHwc); }
Ady Abraham03b02dd2019-03-21 15:40:11 -070069
70private:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070071 using Buffers = std::vector<sp<GraphicBuffer>>;
72
Ady Abraham2cb8b622019-12-02 18:55:33 -080073 class SevenSegmentDrawer {
74 public:
Ady Abraham0aa373a2022-11-22 13:56:50 -080075 static Buffers draw(int displayFps, int renderFps, SkColor, ui::Transform::RotationFlags,
76 ftl::Flags<Features>);
Ady Abraham2cb8b622019-12-02 18:55:33 -080077
78 private:
rnlee756005b2021-05-27 10:46:36 -070079 enum class Segment { Upper, UpperLeft, UpperRight, Middle, LowerLeft, LowerRight, Bottom };
Ady Abraham2cb8b622019-12-02 18:55:33 -080080
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070081 static void drawSegment(Segment, int left, SkColor, SkCanvas&);
82 static void drawDigit(int digit, int left, SkColor, SkCanvas&);
Ady Abraham0aa373a2022-11-22 13:56:50 -080083 static void drawNumber(int number, int left, SkColor, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080084 };
85
Ady Abraham0aa373a2022-11-22 13:56:50 -080086 const Buffers& getOrCreateBuffers(Fps, Fps);
chaviw70aa7572021-09-22 12:27:57 -050087
ramindanib2158ee2023-02-13 20:29:59 -080088 SurfaceComposerClient::Transaction createTransaction() const;
89
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070090 struct Key {
Ady Abraham0aa373a2022-11-22 13:56:50 -080091 int displayFps;
92 int renderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070093 ui::Transform::RotationFlags flags;
Ady Abraham03b02dd2019-03-21 15:40:11 -070094
Ady Abraham0aa373a2022-11-22 13:56:50 -080095 bool operator==(Key other) const {
96 return displayFps == other.displayFps && renderFps == other.renderFps &&
97 flags == other.flags;
98 }
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070099 };
Ady Abraham03b02dd2019-03-21 15:40:11 -0700100
Dominik Laskowski8c4356c2022-03-21 08:19:54 -0700101 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
102 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -0700103
Ady Abraham0aa373a2022-11-22 13:56:50 -0800104 std::optional<Fps> mDisplayFps;
105 std::optional<Fps> mRenderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -0700106 size_t mFrame = 0;
107
108 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham0aa373a2022-11-22 13:56:50 -0800109 const ftl::Flags<Features> mFeatures;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +0100110
Ady Abraham3649ea82022-07-08 16:04:02 -0700111 const std::unique_ptr<SurfaceControlHolder> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -0700112};
113
Dominik Laskowski20134642020-04-20 22:36:44 -0700114} // namespace android