blob: 4895e16d31aa99ad6c4689ce77fb5c72917685c3 [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
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
22namespace android {
23
Lloyd Piquee39cad22017-12-20 17:01:29 -080024class EventThread;
25
26namespace RE {
27class RenderEngine;
28}
29
30namespace Hwc2 {
31class Composer;
32}
33
Lloyd Piquef58625d2017-12-19 13:22:33 -080034class TestableSurfaceFlinger {
35public:
36 // Extend this as needed for accessing SurfaceFlinger private (and public)
37 // functions.
38
Lloyd Piquee39cad22017-12-20 17:01:29 -080039 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 Pique5b36f3f2018-01-17 11:57:07 -080053 using CreateBufferQueueFunction = SurfaceFlinger::CreateBufferQueueFunction;
54
55 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
56 mFlinger->mCreateBufferQueue = f;
57 }
58
Lloyd Piquef58625d2017-12-19 13:22:33 -080059 /* ------------------------------------------------------------------------
60 * Forwarding for functions being tested
61 */
Lloyd Piquef58625d2017-12-19 13:22:33 -080062 auto processDisplayChangesLocked() { return mFlinger->processDisplayChangesLocked(); }
63
64 /* ------------------------------------------------------------------------
65 * Read-write access to private data to set up preconditions and assert
66 * post-conditions.
67 */
68 auto& mutableBuiltinDisplays() { return mFlinger->mBuiltinDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -080069 auto& mutableDisplays() { return mFlinger->mDisplays; }
70 auto& mutableCurrentState() { return mFlinger->mCurrentState; }
71 auto& mutableDrawingState() { return mFlinger->mDrawingState; }
72 auto& mutableEventThread() { return mFlinger->mEventThread; }
73 auto& mutableEventQueue() { return mFlinger->mEventQueue; }
74
75 ~TestableSurfaceFlinger() {
76 // All these pointer and container clears help ensure that GMock does
77 // not report a leaked object, since the SurfaceFlinger instance may
78 // still be referenced by something despite our best efforts to destroy
79 // it after each test is done.
80 mutableDisplays().clear();
81 mutableEventThread().reset();
82 mFlinger->getBE().mHwc.reset();
83 mFlinger->getBE().mRenderEngine.reset();
84 }
Lloyd Piquef58625d2017-12-19 13:22:33 -080085
86 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger();
87};
88
89} // namespace android