blob: d8aa048747c5ea47d81075072f59e7f2fd956044 [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
Sally Qi147581b2023-06-27 11:55:34 -070019#include "Utils/OverlayUtils.h"
20
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070021#include <vector>
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080022
Ady Abraham0aa373a2022-11-22 13:56:50 -080023#include <ftl/flags.h>
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070024#include <ftl/small_map.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;
Ady Abraham3649ea82022-07-08 16:04:02 -070037class SurfaceFlinger;
38
Ady Abraham03b02dd2019-03-21 15:40:11 -070039class RefreshRateOverlay {
Ady Abrahamddba9342023-10-02 16:28:03 -070040private:
41 // Effectively making the constructor private, while keeping std::make_unique work
42 struct ConstructorTag {};
43
Ady Abraham03b02dd2019-03-21 15:40:11 -070044public:
Ady Abraham0aa373a2022-11-22 13:56:50 -080045 enum class Features {
46 Spinner = 1 << 0,
47 RenderRate = 1 << 1,
Yifei Zhangcfb7bb32023-01-12 16:17:14 -080048 ShowInMiddle = 1 << 2,
ramindanib2158ee2023-02-13 20:29:59 -080049 SetByHwc = 1 << 3,
Ady Abraham0aa373a2022-11-22 13:56:50 -080050 };
51
Ady Abrahamddba9342023-10-02 16:28:03 -070052 static std::unique_ptr<RefreshRateOverlay> create(FpsRange, ftl::Flags<Features>);
Ady Abraham03b02dd2019-03-21 15:40:11 -070053
Dominik Laskowski29fa1462021-04-27 15:51:50 -070054 void setLayerStack(ui::LayerStack);
Dominik Laskowski20134642020-04-20 22:36:44 -070055 void setViewport(ui::Size);
Ady Abraham0aa373a2022-11-22 13:56:50 -080056 void changeRefreshRate(Fps, Fps);
ramindani3faf5742023-09-21 13:45:12 -070057 void changeRenderRate(Fps);
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070058 void animate();
ramindanib2158ee2023-02-13 20:29:59 -080059 bool isSetByHwc() const { return mFeatures.test(RefreshRateOverlay::Features::SetByHwc); }
Ady Abrahame2946322024-07-10 17:45:29 -070060 void onVrrIdle(bool idle);
Ady Abraham03b02dd2019-03-21 15:40:11 -070061
Ady Abrahamddba9342023-10-02 16:28:03 -070062 RefreshRateOverlay(ConstructorTag, FpsRange, ftl::Flags<Features>);
63
Ady Abraham03b02dd2019-03-21 15:40:11 -070064private:
Ady Abrahamddba9342023-10-02 16:28:03 -070065 bool initCheck() const;
66
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070067 using Buffers = std::vector<sp<GraphicBuffer>>;
68
Ady Abrahame2946322024-07-10 17:45:29 -070069 static Buffers draw(int refreshRate, int renderFps, bool idle, SkColor,
70 ui::Transform::RotationFlags, ftl::Flags<Features>);
Sally Qi147581b2023-06-27 11:55:34 -070071 static void drawNumber(int number, int left, SkColor, SkCanvas&);
Ady Abrahame2946322024-07-10 17:45:29 -070072 static void drawDash(int left, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080073
Ady Abrahame2946322024-07-10 17:45:29 -070074 const Buffers& getOrCreateBuffers(Fps, Fps, bool);
chaviw70aa7572021-09-22 12:27:57 -050075
ramindanib2158ee2023-02-13 20:29:59 -080076 SurfaceComposerClient::Transaction createTransaction() const;
77
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070078 struct Key {
Ying Wei22d59cc2024-05-11 02:41:08 +000079 int refreshRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080080 int renderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070081 ui::Transform::RotationFlags flags;
Ady Abrahame2946322024-07-10 17:45:29 -070082 bool idle;
Ady Abraham03b02dd2019-03-21 15:40:11 -070083
Ady Abraham0aa373a2022-11-22 13:56:50 -080084 bool operator==(Key other) const {
Ying Wei22d59cc2024-05-11 02:41:08 +000085 return refreshRate == other.refreshRate && renderFps == other.renderFps &&
Ady Abrahame2946322024-07-10 17:45:29 -070086 flags == other.flags && idle == other.idle;
Ady Abraham0aa373a2022-11-22 13:56:50 -080087 }
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070088 };
Ady Abraham03b02dd2019-03-21 15:40:11 -070089
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070090 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
91 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -070092
Ying Wei22d59cc2024-05-11 02:41:08 +000093 std::optional<Fps> mRefreshRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080094 std::optional<Fps> mRenderFps;
Ady Abrahame2946322024-07-10 17:45:29 -070095 bool mIsVrrIdle = false;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070096 size_t mFrame = 0;
97
98 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham0aa373a2022-11-22 13:56:50 -080099 const ftl::Flags<Features> mFeatures;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +0100100
Ady Abraham3649ea82022-07-08 16:04:02 -0700101 const std::unique_ptr<SurfaceControlHolder> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -0700102};
103
Dominik Laskowski20134642020-04-20 22:36:44 -0700104} // namespace android