blob: 0fec470edcb020a75a8749ec3bedd183dd4b6814 [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 Abraham03b02dd2019-03-21 15:40:11 -070060
Ady Abrahamddba9342023-10-02 16:28:03 -070061 RefreshRateOverlay(ConstructorTag, FpsRange, ftl::Flags<Features>);
62
Ady Abraham03b02dd2019-03-21 15:40:11 -070063private:
Ady Abrahamddba9342023-10-02 16:28:03 -070064 bool initCheck() const;
65
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070066 using Buffers = std::vector<sp<GraphicBuffer>>;
67
ramindania04b8a52023-08-07 18:49:47 -070068 static Buffers draw(int vsyncRate, int renderFps, SkColor, ui::Transform::RotationFlags,
Sally Qi147581b2023-06-27 11:55:34 -070069 ftl::Flags<Features>);
70 static void drawNumber(int number, int left, SkColor, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080071
Ady Abraham0aa373a2022-11-22 13:56:50 -080072 const Buffers& getOrCreateBuffers(Fps, Fps);
chaviw70aa7572021-09-22 12:27:57 -050073
ramindanib2158ee2023-02-13 20:29:59 -080074 SurfaceComposerClient::Transaction createTransaction() const;
75
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070076 struct Key {
ramindania04b8a52023-08-07 18:49:47 -070077 int vsyncRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080078 int renderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070079 ui::Transform::RotationFlags flags;
Ady Abraham03b02dd2019-03-21 15:40:11 -070080
Ady Abraham0aa373a2022-11-22 13:56:50 -080081 bool operator==(Key other) const {
ramindania04b8a52023-08-07 18:49:47 -070082 return vsyncRate == other.vsyncRate && renderFps == other.renderFps &&
Ady Abraham0aa373a2022-11-22 13:56:50 -080083 flags == other.flags;
84 }
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070085 };
Ady Abraham03b02dd2019-03-21 15:40:11 -070086
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070087 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
88 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -070089
ramindania04b8a52023-08-07 18:49:47 -070090 std::optional<Fps> mVsyncRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080091 std::optional<Fps> mRenderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070092 size_t mFrame = 0;
93
94 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham0aa373a2022-11-22 13:56:50 -080095 const ftl::Flags<Features> mFeatures;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +010096
Ady Abraham3649ea82022-07-08 16:04:02 -070097 const std::unique_ptr<SurfaceControlHolder> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -070098};
99
Dominik Laskowski20134642020-04-20 22:36:44 -0700100} // namespace android