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 | |
| 47 | void setupPrimaryDisplay() { |
| 48 | mFlinger->getBE().mHwc->mHwcDevice->onHotplug(0, HWC2::Connection::Connected); |
| 49 | mFlinger->getBE().mHwc->onHotplug(0, DisplayDevice::DISPLAY_PRIMARY, |
| 50 | HWC2::Connection::Connected); |
| 51 | } |
| 52 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 53 | /* ------------------------------------------------------------------------ |
| 54 | * Forwarding for functions being tested |
| 55 | */ |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 56 | auto processDisplayChangesLocked() { return mFlinger->processDisplayChangesLocked(); } |
| 57 | |
| 58 | /* ------------------------------------------------------------------------ |
| 59 | * Read-write access to private data to set up preconditions and assert |
| 60 | * post-conditions. |
| 61 | */ |
| 62 | auto& mutableBuiltinDisplays() { return mFlinger->mBuiltinDisplays; } |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame^] | 63 | auto& mutableDisplays() { return mFlinger->mDisplays; } |
| 64 | auto& mutableCurrentState() { return mFlinger->mCurrentState; } |
| 65 | auto& mutableDrawingState() { return mFlinger->mDrawingState; } |
| 66 | auto& mutableEventThread() { return mFlinger->mEventThread; } |
| 67 | auto& mutableEventQueue() { return mFlinger->mEventQueue; } |
| 68 | |
| 69 | ~TestableSurfaceFlinger() { |
| 70 | // All these pointer and container clears help ensure that GMock does |
| 71 | // not report a leaked object, since the SurfaceFlinger instance may |
| 72 | // still be referenced by something despite our best efforts to destroy |
| 73 | // it after each test is done. |
| 74 | mutableDisplays().clear(); |
| 75 | mutableEventThread().reset(); |
| 76 | mFlinger->getBE().mHwc.reset(); |
| 77 | mFlinger->getBE().mRenderEngine.reset(); |
| 78 | } |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 79 | |
| 80 | sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(); |
| 81 | }; |
| 82 | |
| 83 | } // namespace android |