Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 20 | #include <gui/ISurfaceComposer.h> |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 21 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 22 | #include "Scheduler/DispSync.h" |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 23 | #include "Scheduler/EventThread.h" |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 24 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 25 | #include "Scheduler/Scheduler.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 29 | class TestableScheduler : public Scheduler, private ISchedulerCallback { |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 30 | public: |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 31 | TestableScheduler(const scheduler::RefreshRateConfigs& configs, bool useContentDetectionV2) |
Ana Krulec | 8dc3dd2 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 32 | : Scheduler([](bool) {}, configs, *this, useContentDetectionV2, true) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 33 | if (mUseContentDetectionV2) { |
| 34 | mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>(); |
| 35 | } else { |
| 36 | mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>(); |
| 37 | } |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 38 | } |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 39 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 40 | TestableScheduler(std::unique_ptr<DispSync> primaryDispSync, |
| 41 | std::unique_ptr<EventControlThread> eventControlThread, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 42 | const scheduler::RefreshRateConfigs& configs, bool useContentDetectionV2) |
| 43 | : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs, *this, |
Ana Krulec | 8dc3dd2 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 44 | useContentDetectionV2, true) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 45 | if (mUseContentDetectionV2) { |
| 46 | mLayerHistory = std::make_unique<scheduler::impl::LayerHistoryV2>(); |
| 47 | } else { |
| 48 | mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>(); |
| 49 | } |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 50 | } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 51 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 52 | // Used to inject mock event thread. |
| 53 | ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 54 | return Scheduler::createConnection(std::move(eventThread)); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 57 | size_t layerHistorySize() const NO_THREAD_SAFETY_ANALYSIS { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 58 | 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 Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 67 | /* ------------------------------------------------------------------------ |
| 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; } |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame^] | 75 | |
Ady Abraham | e3ed2f9 | 2020-01-06 17:01:28 -0800 | [diff] [blame] | 76 | auto mutableLayerHistory() { |
| 77 | return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get()); |
| 78 | } |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame^] | 79 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 80 | auto mutableLayerHistoryV2() { |
| 81 | return static_cast<scheduler::impl::LayerHistoryV2*>(mLayerHistory.get()); |
| 82 | } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 83 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame^] | 84 | void replaceTouchTimer(int64_t millis) { |
| 85 | if (mTouchTimer) { |
| 86 | mTouchTimer.reset(); |
| 87 | } |
| 88 | mTouchTimer.emplace( |
| 89 | std::chrono::milliseconds(millis), |
| 90 | [this] { touchTimerCallback(TimerState::Reset); }, |
| 91 | [this] { touchTimerCallback(TimerState::Expired); }); |
| 92 | mTouchTimer->start(); |
| 93 | } |
| 94 | |
| 95 | bool isTouchActive() { |
| 96 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
| 97 | return mFeatures.touch == Scheduler::TouchState::Active; |
| 98 | } |
| 99 | |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 100 | ~TestableScheduler() { |
| 101 | // All these pointer and container clears help ensure that GMock does |
| 102 | // not report a leaked object, since the Scheduler instance may |
| 103 | // still be referenced by something despite our best efforts to destroy |
| 104 | // it after each test is done. |
| 105 | mutableEventControlThread().reset(); |
| 106 | mutablePrimaryDispSync().reset(); |
| 107 | mConnections.clear(); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 108 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 109 | |
| 110 | private: |
| 111 | void changeRefreshRate(const RefreshRate&, ConfigEvent) override {} |
| 112 | void repaintEverythingForHWC() override {} |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 113 | void kernelTimerChanged(bool /*expired*/) override {} |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace android |