blob: 067b09ad027f493d17dc33cb4ed80c688f4fc3eb [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
Lloyd Pique5b36f3f2018-01-17 11:57:07 -080047 using CreateBufferQueueFunction = SurfaceFlinger::CreateBufferQueueFunction;
48
49 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
50 mFlinger->mCreateBufferQueue = f;
51 }
52
Lloyd Piquef58625d2017-12-19 13:22:33 -080053 /* ------------------------------------------------------------------------
54 * Forwarding for functions being tested
55 */
Lloyd Piquef58625d2017-12-19 13:22:33 -080056 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 Piquee39cad22017-12-20 17:01:29 -080063 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
Lloyd Piquebc792092018-01-17 11:52:30 -080069 auto& mutableHwcDisplayData() { return mFlinger->getBE().mHwc->mDisplayData; }
70 auto& mutableHwcDisplaySlots() { return mFlinger->getBE().mHwc->mHwcDisplaySlots; }
71
Lloyd Piquee39cad22017-12-20 17:01:29 -080072 ~TestableSurfaceFlinger() {
73 // All these pointer and container clears help ensure that GMock does
74 // not report a leaked object, since the SurfaceFlinger instance may
75 // still be referenced by something despite our best efforts to destroy
76 // it after each test is done.
77 mutableDisplays().clear();
78 mutableEventThread().reset();
79 mFlinger->getBE().mHwc.reset();
80 mFlinger->getBE().mRenderEngine.reset();
81 }
Lloyd Piquef58625d2017-12-19 13:22:33 -080082
Lloyd Piquebc792092018-01-17 11:52:30 -080083 /* ------------------------------------------------------------------------
84 * Wrapper classes for Read-write access to private data to set up
85 * preconditions and assert post-conditions.
86 */
87 struct HWC2Display : public HWC2::Display {
88 HWC2Display(Hwc2::Composer& composer,
89 const std::unordered_set<HWC2::Capability>& capabilities, hwc2_display_t id,
90 HWC2::DisplayType type)
91 : HWC2::Display(composer, capabilities, id, type) {}
92 ~HWC2Display() {
93 // Prevents a call to disable vsyncs.
94 mType = HWC2::DisplayType::Invalid;
95 }
96
97 auto& mutableIsConnected() { return this->mIsConnected; }
98 auto& mutableConfigs() { return this->mConfigs; }
99 };
100
Lloyd Piquef58625d2017-12-19 13:22:33 -0800101 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger();
102};
103
104} // namespace android