John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 1 | /* |
| 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 Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 20 | #include <gui/BufferItemConsumer.h> |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 21 | #include <gui/DisplayEventReceiver.h> |
| 22 | #include <gui/ISurfaceComposer.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 23 | #include <gui/Surface.h> |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 24 | #include <gui/SurfaceComposerClient.h> |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 25 | #include <gui/SurfaceControl.h> |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 26 | #include <ui/DisplayMode.h> |
Marin Shalamanov | 463ad8e | 2021-01-28 22:58:37 +0100 | [diff] [blame^] | 27 | #include <ui/StaticDisplayInfo.h> |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 28 | #include <utils/Looper.h> |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 29 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 30 | #include <atomic> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 31 | #include <thread> |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 32 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 33 | #define dp(x) ((x) * android::uirenderer::test::getDisplayInfo().density) |
| 34 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | namespace test { |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 38 | |
Marin Shalamanov | 463ad8e | 2021-01-28 22:58:37 +0100 | [diff] [blame^] | 39 | const ui::StaticDisplayInfo& getDisplayInfo(); |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 40 | const ui::DisplayMode& getActiveDisplayMode(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 41 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 42 | inline const ui::Size& getActiveDisplayResolution() { |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 43 | return getActiveDisplayMode().resolution; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 44 | } |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 45 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 46 | class TestContext { |
| 47 | public: |
| 48 | TestContext(); |
| 49 | ~TestContext(); |
| 50 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 51 | // Must be called before surface(); |
| 52 | void setRenderOffscreen(bool renderOffscreen) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | LOG_ALWAYS_FATAL_IF(mSurface.get(), "Must be called before surface is created"); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 54 | mRenderOffscreen = renderOffscreen; |
| 55 | } |
| 56 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 57 | sp<Surface> surface(); |
| 58 | |
| 59 | void waitForVsync(); |
| 60 | |
| 61 | private: |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 62 | void createSurface(); |
| 63 | void createWindowSurface(); |
| 64 | void createOffscreenSurface(); |
| 65 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 66 | sp<SurfaceComposerClient> mSurfaceComposerClient; |
| 67 | sp<SurfaceControl> mSurfaceControl; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 68 | sp<BufferItemConsumer> mConsumer; |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 69 | DisplayEventReceiver mDisplayEventReceiver; |
| 70 | sp<Looper> mLooper; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 71 | sp<Surface> mSurface; |
| 72 | bool mRenderOffscreen; |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 75 | } // namespace test |
| 76 | } // namespace uirenderer |
| 77 | } // namespace android |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 78 | |
| 79 | #endif |