blob: a67c24c2d6e40f9eafd23ff3f9388c9a9ab58a99 [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:
Dominik Laskowski98041832019-08-01 18:35:59 -070031 explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs)
Ady Abraham3a77a7b2019-12-02 18:46:59 -080032 : Scheduler([](bool) {}, configs, *this) {
Ady Abrahame3ed2f92020-01-06 17:01:28 -080033 mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
Dominik Laskowski49cea512019-11-12 14:13:23 -080034 }
Dominik Laskowski98041832019-08-01 18:35:59 -070035
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070036 TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
37 std::unique_ptr<EventControlThread> eventControlThread,
38 const scheduler::RefreshRateConfigs& configs)
Ady Abraham3a77a7b2019-12-02 18:46:59 -080039 : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs, *this) {
Ady Abrahame3ed2f92020-01-06 17:01:28 -080040 mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
Dominik Laskowski49cea512019-11-12 14:13:23 -080041 }
Ana Krulecafb45842019-02-13 13:33:03 -080042
Dominik Laskowski98041832019-08-01 18:35:59 -070043 // Used to inject mock event thread.
44 ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -070045 return Scheduler::createConnection(std::move(eventThread));
Ana Krulecafb45842019-02-13 13:33:03 -080046 }
47
Dominik Laskowski49cea512019-11-12 14:13:23 -080048 size_t layerHistorySize() const NO_THREAD_SAFETY_ANALYSIS {
Ady Abrahame3ed2f92020-01-06 17:01:28 -080049 return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get())->mLayerInfos.size();
Dominik Laskowski49cea512019-11-12 14:13:23 -080050 }
51
Ana Krulecafb45842019-02-13 13:33:03 -080052 /* ------------------------------------------------------------------------
53 * Read-write access to private data to set up preconditions and assert
54 * post-conditions.
55 */
56 auto& mutablePrimaryHWVsyncEnabled() { return mPrimaryHWVsyncEnabled; }
57 auto& mutableEventControlThread() { return mEventControlThread; }
58 auto& mutablePrimaryDispSync() { return mPrimaryDispSync; }
59 auto& mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
Ady Abrahame3ed2f92020-01-06 17:01:28 -080060 auto mutableLayerHistory() {
61 return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get());
62 }
Ana Krulecafb45842019-02-13 13:33:03 -080063
64 ~TestableScheduler() {
65 // All these pointer and container clears help ensure that GMock does
66 // not report a leaked object, since the Scheduler instance may
67 // still be referenced by something despite our best efforts to destroy
68 // it after each test is done.
69 mutableEventControlThread().reset();
70 mutablePrimaryDispSync().reset();
71 mConnections.clear();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070072 }
Ady Abraham3a77a7b2019-12-02 18:46:59 -080073
74private:
75 void changeRefreshRate(const RefreshRate&, ConfigEvent) override {}
76 void repaintEverythingForHWC() override {}
Ana Krulecafb45842019-02-13 13:33:03 -080077};
78
79} // namespace android