blob: 2dd8e5f50fb983d31e2a2dab7fdf9813baac844b [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;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -080048 void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
49 mFlinger->mCreateBufferQueue = f;
50 }
51
Lloyd Pique1fa4d462018-01-22 18:03:16 -080052 using CreateNativeWindowSurfaceFunction = SurfaceFlinger::CreateNativeWindowSurfaceFunction;
53 void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) {
54 mFlinger->mCreateNativeWindowSurface = f;
55 }
56
57 using HotplugEvent = SurfaceFlinger::HotplugEvent;
58
Lloyd Piquef58625d2017-12-19 13:22:33 -080059 /* ------------------------------------------------------------------------
60 * Forwarding for functions being tested
61 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080062
63 auto handleTransactionLocked(uint32_t transactionFlags) {
64 return mFlinger->handleTransactionLocked(transactionFlags);
65 }
Lloyd Piquef58625d2017-12-19 13:22:33 -080066
67 /* ------------------------------------------------------------------------
68 * Read-write access to private data to set up preconditions and assert
69 * post-conditions.
70 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080071
Lloyd Piquef58625d2017-12-19 13:22:33 -080072 auto& mutableBuiltinDisplays() { return mFlinger->mBuiltinDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -080073 auto& mutableCurrentState() { return mFlinger->mCurrentState; }
Lloyd Pique1fa4d462018-01-22 18:03:16 -080074 auto& mutableDisplays() { return mFlinger->mDisplays; }
Lloyd Piquee39cad22017-12-20 17:01:29 -080075 auto& mutableDrawingState() { return mFlinger->mDrawingState; }
Lloyd Pique1fa4d462018-01-22 18:03:16 -080076 auto& mutableEventControlThread() { return mFlinger->mEventControlThread; }
Lloyd Piquee39cad22017-12-20 17:01:29 -080077 auto& mutableEventQueue() { return mFlinger->mEventQueue; }
Lloyd Pique1fa4d462018-01-22 18:03:16 -080078 auto& mutableEventThread() { return mFlinger->mEventThread; }
79 auto& mutableInterceptor() { return mFlinger->mInterceptor; }
80 auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; }
81 auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; }
Lloyd Piquee39cad22017-12-20 17:01:29 -080082
Lloyd Piquebc792092018-01-17 11:52:30 -080083 auto& mutableHwcDisplayData() { return mFlinger->getBE().mHwc->mDisplayData; }
84 auto& mutableHwcDisplaySlots() { return mFlinger->getBE().mHwc->mHwcDisplaySlots; }
85
Lloyd Piquee39cad22017-12-20 17:01:29 -080086 ~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 Pique1fa4d462018-01-22 18:03:16 -080092 mutableEventControlThread().reset();
93 mutableEventQueue().reset();
Lloyd Piquee39cad22017-12-20 17:01:29 -080094 mutableEventThread().reset();
Lloyd Pique1fa4d462018-01-22 18:03:16 -080095 mutableInterceptor().reset();
Lloyd Piquee39cad22017-12-20 17:01:29 -080096 mFlinger->getBE().mHwc.reset();
97 mFlinger->getBE().mRenderEngine.reset();
98 }
Lloyd Piquef58625d2017-12-19 13:22:33 -080099
Lloyd Piquebc792092018-01-17 11:52:30 -0800100 /* ------------------------------------------------------------------------
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 Pique2d3ee6d2018-01-17 13:42:24 -0800118 sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(SurfaceFlinger::SkipInitialization);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800119};
120
121} // namespace android