Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 "DisplayDevice.h" |
| 20 | #include "SurfaceFlinger.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 24 | class EventThread; |
| 25 | |
| 26 | namespace RE { |
| 27 | class RenderEngine; |
| 28 | } |
| 29 | |
| 30 | namespace Hwc2 { |
| 31 | class Composer; |
| 32 | } |
| 33 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 34 | class TestableSurfaceFlinger { |
| 35 | public: |
| 36 | // Extend this as needed for accessing SurfaceFlinger private (and public) |
| 37 | // functions. |
| 38 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 39 | void setupRenderEngine(std::unique_ptr<RE::RenderEngine> renderEngine) { |
| 40 | mFlinger->getBE().mRenderEngine = std::move(renderEngine); |
| 41 | } |
| 42 | |
| 43 | void setupComposer(std::unique_ptr<Hwc2::Composer> composer) { |
| 44 | mFlinger->getBE().mHwc.reset(new HWComposer(std::move(composer))); |
| 45 | } |
| 46 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 47 | using CreateBufferQueueFunction = SurfaceFlinger::CreateBufferQueueFunction; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 48 | void setCreateBufferQueueFunction(CreateBufferQueueFunction f) { |
| 49 | mFlinger->mCreateBufferQueue = f; |
| 50 | } |
| 51 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 52 | using CreateNativeWindowSurfaceFunction = SurfaceFlinger::CreateNativeWindowSurfaceFunction; |
| 53 | void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) { |
| 54 | mFlinger->mCreateNativeWindowSurface = f; |
| 55 | } |
| 56 | |
| 57 | using HotplugEvent = SurfaceFlinger::HotplugEvent; |
| 58 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 59 | /* ------------------------------------------------------------------------ |
| 60 | * Forwarding for functions being tested |
| 61 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 62 | |
| 63 | auto handleTransactionLocked(uint32_t transactionFlags) { |
| 64 | return mFlinger->handleTransactionLocked(transactionFlags); |
| 65 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 66 | |
| 67 | /* ------------------------------------------------------------------------ |
| 68 | * Read-write access to private data to set up preconditions and assert |
| 69 | * post-conditions. |
| 70 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 71 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 72 | auto& mutableBuiltinDisplays() { return mFlinger->mBuiltinDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 73 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 74 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 75 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 76 | auto& mutableEventControlThread() { return mFlinger->mEventControlThread; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 77 | auto& mutableEventQueue() { return mFlinger->mEventQueue; } |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 78 | auto& mutableEventThread() { return mFlinger->mEventThread; } |
| 79 | auto& mutableInterceptor() { return mFlinger->mInterceptor; } |
| 80 | auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; } |
| 81 | auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 82 | |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 83 | auto& mutableHwcDisplayData() { return mFlinger->getBE().mHwc->mDisplayData; } |
| 84 | auto& mutableHwcDisplaySlots() { return mFlinger->getBE().mHwc->mHwcDisplaySlots; } |
| 85 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 86 | ~TestableSurfaceFlinger() { |
| 87 | // All these pointer and container clears help ensure that GMock does |
| 88 | // not report a leaked object, since the SurfaceFlinger instance may |
| 89 | // still be referenced by something despite our best efforts to destroy |
| 90 | // it after each test is done. |
| 91 | mutableDisplays().clear(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 92 | mutableEventControlThread().reset(); |
| 93 | mutableEventQueue().reset(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 94 | mutableEventThread().reset(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame^] | 95 | mutableInterceptor().reset(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 96 | mFlinger->getBE().mHwc.reset(); |
| 97 | mFlinger->getBE().mRenderEngine.reset(); |
| 98 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 99 | |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 100 | /* ------------------------------------------------------------------------ |
| 101 | * Wrapper classes for Read-write access to private data to set up |
| 102 | * preconditions and assert post-conditions. |
| 103 | */ |
| 104 | struct HWC2Display : public HWC2::Display { |
| 105 | HWC2Display(Hwc2::Composer& composer, |
| 106 | const std::unordered_set<HWC2::Capability>& capabilities, hwc2_display_t id, |
| 107 | HWC2::DisplayType type) |
| 108 | : HWC2::Display(composer, capabilities, id, type) {} |
| 109 | ~HWC2Display() { |
| 110 | // Prevents a call to disable vsyncs. |
| 111 | mType = HWC2::DisplayType::Invalid; |
| 112 | } |
| 113 | |
| 114 | auto& mutableIsConnected() { return this->mIsConnected; } |
| 115 | auto& mutableConfigs() { return this->mConfigs; } |
| 116 | }; |
| 117 | |
Lloyd Pique | 2d3ee6d | 2018-01-17 13:42:24 -0800 | [diff] [blame] | 118 | sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(SurfaceFlinger::SkipInitialization); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace android |