blob: 9d00366daffeeb9da8c47bc7e6e5cc4c018feabe [file] [log] [blame]
John Reck94c40fe2014-10-08 09:28:43 -07001/*
2 * Copyright (C) 2014 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#ifndef TESTCONTEXT_H
18#define TESTCONTEXT_H
19
John Reck1bcacfd2017-11-03 10:12:19 -070020#include <gui/BufferItemConsumer.h>
John Reck84e390c2015-01-05 09:42:52 -080021#include <gui/DisplayEventReceiver.h>
22#include <gui/ISurfaceComposer.h>
John Reck1bcacfd2017-11-03 10:12:19 -070023#include <gui/Surface.h>
John Reck84e390c2015-01-05 09:42:52 -080024#include <gui/SurfaceComposerClient.h>
John Reck94c40fe2014-10-08 09:28:43 -070025#include <gui/SurfaceControl.h>
Marin Shalamanovcb783ca2021-01-29 21:26:07 +010026#include <ui/DisplayMode.h>
Marin Shalamanov463ad8e2021-01-28 22:58:37 +010027#include <ui/StaticDisplayInfo.h>
John Reck84e390c2015-01-05 09:42:52 -080028#include <utils/Looper.h>
John Reck94c40fe2014-10-08 09:28:43 -070029
John Reckf1480762016-07-03 18:28:25 -070030#include <atomic>
John Reck1bcacfd2017-11-03 10:12:19 -070031#include <thread>
John Reckf1480762016-07-03 18:28:25 -070032
Dominik Laskowski69b281d2019-11-22 14:13:12 -080033#define dp(x) ((x) * android::uirenderer::test::getDisplayInfo().density)
34
John Reck84e390c2015-01-05 09:42:52 -080035namespace android {
36namespace uirenderer {
37namespace test {
John Reck94c40fe2014-10-08 09:28:43 -070038
Marin Shalamanov463ad8e2021-01-28 22:58:37 +010039const ui::StaticDisplayInfo& getDisplayInfo();
Marin Shalamanovcb783ca2021-01-29 21:26:07 +010040const ui::DisplayMode& getActiveDisplayMode();
John Reck94c40fe2014-10-08 09:28:43 -070041
Dominik Laskowski69b281d2019-11-22 14:13:12 -080042inline const ui::Size& getActiveDisplayResolution() {
Marin Shalamanovcb783ca2021-01-29 21:26:07 +010043 return getActiveDisplayMode().resolution;
Dominik Laskowski69b281d2019-11-22 14:13:12 -080044}
John Recke702c9c2015-10-07 10:26:02 -070045
John Reck84e390c2015-01-05 09:42:52 -080046class TestContext {
47public:
48 TestContext();
49 ~TestContext();
50
John Reckf1480762016-07-03 18:28:25 -070051 // Must be called before surface();
52 void setRenderOffscreen(bool renderOffscreen) {
John Reck1bcacfd2017-11-03 10:12:19 -070053 LOG_ALWAYS_FATAL_IF(mSurface.get(), "Must be called before surface is created");
John Reckf1480762016-07-03 18:28:25 -070054 mRenderOffscreen = renderOffscreen;
55 }
56
John Reck84e390c2015-01-05 09:42:52 -080057 sp<Surface> surface();
58
59 void waitForVsync();
60
61private:
John Reckf1480762016-07-03 18:28:25 -070062 void createSurface();
63 void createWindowSurface();
64 void createOffscreenSurface();
65
John Reck84e390c2015-01-05 09:42:52 -080066 sp<SurfaceComposerClient> mSurfaceComposerClient;
67 sp<SurfaceControl> mSurfaceControl;
John Reckf1480762016-07-03 18:28:25 -070068 sp<BufferItemConsumer> mConsumer;
John Reck84e390c2015-01-05 09:42:52 -080069 DisplayEventReceiver mDisplayEventReceiver;
70 sp<Looper> mLooper;
John Reckf1480762016-07-03 18:28:25 -070071 sp<Surface> mSurface;
72 bool mRenderOffscreen;
John Reck84e390c2015-01-05 09:42:52 -080073};
74
John Reck1bcacfd2017-11-03 10:12:19 -070075} // namespace test
76} // namespace uirenderer
77} // namespace android
John Reck94c40fe2014-10-08 09:28:43 -070078
79#endif