blob: ae334e54ef3b05cd4d2cc2a805231b8d53e7dfd8 [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 {
40public:
Ady Abraham0aa373a2022-11-22 13:56:50 -080041 enum class Features {
42 Spinner = 1 << 0,
43 RenderRate = 1 << 1,
Yifei Zhangcfb7bb32023-01-12 16:17:14 -080044 ShowInMiddle = 1 << 2,
ramindanib2158ee2023-02-13 20:29:59 -080045 SetByHwc = 1 << 3,
Ady Abraham0aa373a2022-11-22 13:56:50 -080046 };
47
48 RefreshRateOverlay(FpsRange, ftl::Flags<Features>);
Ady Abraham03b02dd2019-03-21 15:40:11 -070049
Dominik Laskowski29fa1462021-04-27 15:51:50 -070050 void setLayerStack(ui::LayerStack);
Dominik Laskowski20134642020-04-20 22:36:44 -070051 void setViewport(ui::Size);
Ady Abraham0aa373a2022-11-22 13:56:50 -080052 void changeRefreshRate(Fps, Fps);
ramindani3faf5742023-09-21 13:45:12 -070053 void changeRenderRate(Fps);
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -070054 void animate();
ramindanib2158ee2023-02-13 20:29:59 -080055 bool isSetByHwc() const { return mFeatures.test(RefreshRateOverlay::Features::SetByHwc); }
Ady Abraham03b02dd2019-03-21 15:40:11 -070056
57private:
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070058 using Buffers = std::vector<sp<GraphicBuffer>>;
59
ramindania04b8a52023-08-07 18:49:47 -070060 static Buffers draw(int vsyncRate, int renderFps, SkColor, ui::Transform::RotationFlags,
Sally Qi147581b2023-06-27 11:55:34 -070061 ftl::Flags<Features>);
62 static void drawNumber(int number, int left, SkColor, SkCanvas&);
Ady Abraham2cb8b622019-12-02 18:55:33 -080063
Ady Abraham0aa373a2022-11-22 13:56:50 -080064 const Buffers& getOrCreateBuffers(Fps, Fps);
chaviw70aa7572021-09-22 12:27:57 -050065
ramindanib2158ee2023-02-13 20:29:59 -080066 SurfaceComposerClient::Transaction createTransaction() const;
67
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070068 struct Key {
ramindania04b8a52023-08-07 18:49:47 -070069 int vsyncRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080070 int renderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070071 ui::Transform::RotationFlags flags;
Ady Abraham03b02dd2019-03-21 15:40:11 -070072
Ady Abraham0aa373a2022-11-22 13:56:50 -080073 bool operator==(Key other) const {
ramindania04b8a52023-08-07 18:49:47 -070074 return vsyncRate == other.vsyncRate && renderFps == other.renderFps &&
Ady Abraham0aa373a2022-11-22 13:56:50 -080075 flags == other.flags;
76 }
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070077 };
Ady Abraham03b02dd2019-03-21 15:40:11 -070078
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070079 using BufferCache = ftl::SmallMap<Key, Buffers, 9>;
80 BufferCache mBufferCache;
Ady Abraham29d0da32020-07-16 18:39:33 -070081
ramindania04b8a52023-08-07 18:49:47 -070082 std::optional<Fps> mVsyncRate;
Ady Abraham0aa373a2022-11-22 13:56:50 -080083 std::optional<Fps> mRenderFps;
Dominik Laskowski8c4356c2022-03-21 08:19:54 -070084 size_t mFrame = 0;
85
86 const FpsRange mFpsRange; // For color interpolation.
Ady Abraham0aa373a2022-11-22 13:56:50 -080087 const ftl::Flags<Features> mFeatures;
Marin Shalamanovf7f6b3c2020-12-09 13:19:38 +010088
Ady Abraham3649ea82022-07-08 16:04:02 -070089 const std::unique_ptr<SurfaceControlHolder> mSurfaceControl;
Ady Abraham03b02dd2019-03-21 15:40:11 -070090};
91
Dominik Laskowski20134642020-04-20 22:36:44 -070092} // namespace android