blob: b0b51bdd8a330f937d54564fee85aa1e5a1d426d [file] [log] [blame]
Ana Krulecafb45842019-02-13 13:33:03 -08001/*
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 */
16
17#pragma once
18
19#include <gmock/gmock.h>
Ady Abraham0f4a1b12019-06-04 16:04:04 -070020#include <gui/ISurfaceComposer.h>
Ana Krulecafb45842019-02-13 13:33:03 -080021
Dominik Laskowski98041832019-08-01 18:35:59 -070022#include "Scheduler/DispSync.h"
Ana Krulecafb45842019-02-13 13:33:03 -080023#include "Scheduler/EventThread.h"
Dominik Laskowski49cea512019-11-12 14:13:23 -080024#include "Scheduler/LayerHistory.h"
Ana Krulecafb45842019-02-13 13:33:03 -080025#include "Scheduler/Scheduler.h"
26
27namespace android {
28
Ady Abraham3a77a7b2019-12-02 18:46:59 -080029class TestableScheduler : public Scheduler, private ISchedulerCallback {
Ana Krulecafb45842019-02-13 13:33:03 -080030public:
Ady Abraham8a82ba62020-01-17 12:43:17 -080031 TestableScheduler(const scheduler::RefreshRateConfigs& configs, bool useContentDetectionV2)
32 : Scheduler([](bool) {}, configs, *this, useContentDetectionV2) {
33 if (mUseContentDetectionV2) {
34 mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>();
35 } else {
36 mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
37 }
Dominik Laskowski49cea512019-11-12 14:13:23 -080038 }
Dominik Laskowski98041832019-08-01 18:35:59 -070039
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070040 TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
41 std::unique_ptr<EventControlThread> eventControlThread,
Ady Abraham8a82ba62020-01-17 12:43:17 -080042 const scheduler::RefreshRateConfigs& configs, bool useContentDetectionV2)
43 : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs, *this,
44 useContentDetectionV2) {
45 if (mUseContentDetectionV2) {
46 mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>();
47 } else {
48 mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
49 }
Dominik Laskowski49cea512019-11-12 14:13:23 -080050 }
Ana Krulecafb45842019-02-13 13:33:03 -080051
Dominik Laskowski98041832019-08-01 18:35:59 -070052 // Used to inject mock event thread.
53 ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -070054 return Scheduler::createConnection(std::move(eventThread));
Ana Krulecafb45842019-02-13 13:33:03 -080055 }
56
Dominik Laskowski49cea512019-11-12 14:13:23 -080057 size_t layerHistorySize() const NO_THREAD_SAFETY_ANALYSIS {
Ady Abraham8a82ba62020-01-17 12:43:17 -080058 if (mUseContentDetectionV2) {
59 return static_cast<scheduler::impl::LayerHistoryV2*>(mLayerHistory.get())
60 ->mLayerInfos.size();
61 } else {
62 return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get())
63 ->mLayerInfos.size();
64 }
Dominik Laskowski49cea512019-11-12 14:13:23 -080065 }
66
Ana Krulecafb45842019-02-13 13:33:03 -080067 /* ------------------------------------------------------------------------
68 * Read-write access to private data to set up preconditions and assert
69 * post-conditions.
70 */
71 auto& mutablePrimaryHWVsyncEnabled() { return mPrimaryHWVsyncEnabled; }
72 auto& mutableEventControlThread() { return mEventControlThread; }
73 auto& mutablePrimaryDispSync() { return mPrimaryDispSync; }
74 auto& mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
Ady Abrahame3ed2f92020-01-06 17:01:28 -080075 auto mutableLayerHistory() {
76 return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get());
77 }
Ady Abraham8a82ba62020-01-17 12:43:17 -080078 auto mutableLayerHistoryV2() {
79 return static_cast<scheduler::impl::LayerHistoryV2*>(mLayerHistory.get());
80 }
Ana Krulecafb45842019-02-13 13:33:03 -080081
82 ~TestableScheduler() {
83 // All these pointer and container clears help ensure that GMock does
84 // not report a leaked object, since the Scheduler instance may
85 // still be referenced by something despite our best efforts to destroy
86 // it after each test is done.
87 mutableEventControlThread().reset();
88 mutablePrimaryDispSync().reset();
89 mConnections.clear();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070090 }
Ady Abraham3a77a7b2019-12-02 18:46:59 -080091
92private:
93 void changeRefreshRate(const RefreshRate&, ConfigEvent) override {}
94 void repaintEverythingForHWC() override {}
Ady Abrahama09852a2020-02-20 14:23:42 -080095 void kernelTimerChanged(bool /*expired*/) override {}
Ana Krulecafb45842019-02-13 13:33:03 -080096};
97
98} // namespace android