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 | |
| 29 | class TestableScheduler : public Scheduler { |
| 30 | public: |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 31 | explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs) |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame^] | 32 | : Scheduler([](bool) {}, configs) { |
| 33 | mLayerHistory.emplace(); |
| 34 | } |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 35 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 36 | TestableScheduler(std::unique_ptr<DispSync> primaryDispSync, |
| 37 | std::unique_ptr<EventControlThread> eventControlThread, |
| 38 | const scheduler::RefreshRateConfigs& configs) |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame^] | 39 | : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs) { |
| 40 | mLayerHistory.emplace(); |
| 41 | } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 42 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 43 | // Used to inject mock event thread. |
| 44 | ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 45 | return Scheduler::createConnection(std::move(eventThread)); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame^] | 48 | size_t layerHistorySize() const NO_THREAD_SAFETY_ANALYSIS { |
| 49 | return mLayerHistory->mLayerInfos.size(); |
| 50 | } |
| 51 | |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 52 | /* ------------------------------------------------------------------------ |
| 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; } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 60 | auto& mutableLayerHistory() { return mLayerHistory; } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 61 | |
| 62 | ~TestableScheduler() { |
| 63 | // All these pointer and container clears help ensure that GMock does |
| 64 | // not report a leaked object, since the Scheduler instance may |
| 65 | // still be referenced by something despite our best efforts to destroy |
| 66 | // it after each test is done. |
| 67 | mutableEventControlThread().reset(); |
| 68 | mutablePrimaryDispSync().reset(); |
| 69 | mConnections.clear(); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 70 | } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace android |