Dominik Laskowski | 5caf9a9 | 2024-02-01 16:53:30 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 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 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include <compositionengine/Display.h> |
| 20 | #include <compositionengine/mock/DisplaySurface.h> |
| 21 | #include <renderengine/mock/RenderEngine.h> |
| 22 | |
| 23 | #include "TestableSurfaceFlinger.h" |
| 24 | #include "mock/DisplayHardware/MockComposer.h" |
| 25 | #include "mock/DisplayHardware/MockPowerAdvisor.h" |
| 26 | #include "mock/MockTimeStats.h" |
| 27 | #include "mock/system/window/MockNativeWindow.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | // Minimal setup to use TestableSurfaceFlinger::commitAndComposite. |
| 32 | struct CommitAndCompositeTest : testing::Test { |
| 33 | void SetUp() override { |
| 34 | mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID}); |
| 35 | mComposer = new Hwc2::mock::Composer(); |
| 36 | mPowerAdvisor = new Hwc2::mock::PowerAdvisor(); |
| 37 | mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); |
| 38 | mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats)); |
| 39 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
| 40 | mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor)); |
| 41 | |
| 42 | constexpr bool kIsPrimary = true; |
| 43 | FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, kIsPrimary) |
| 44 | .setPowerMode(hal::PowerMode::ON) |
| 45 | .inject(&mFlinger, mComposer); |
| 46 | auto compostionEngineDisplayArgs = |
| 47 | compositionengine::DisplayCreationArgsBuilder() |
| 48 | .setId(DEFAULT_DISPLAY_ID) |
| 49 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 50 | .setPowerAdvisor(mPowerAdvisor) |
| 51 | .setName("Internal display") |
| 52 | .build(); |
| 53 | auto compositionDisplay = |
| 54 | compositionengine::impl::createDisplay(mFlinger.getCompositionEngine(), |
| 55 | std::move(compostionEngineDisplayArgs)); |
| 56 | mDisplay = FakeDisplayDeviceInjector(mFlinger, compositionDisplay, |
| 57 | ui::DisplayConnectionType::Internal, HWC_DISPLAY, |
| 58 | kIsPrimary) |
| 59 | .setDisplaySurface(mDisplaySurface) |
| 60 | .setNativeWindow(mNativeWindow) |
| 61 | .setPowerMode(hal::PowerMode::ON) |
| 62 | .setRefreshRateSelector(mFlinger.scheduler()->refreshRateSelector()) |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 63 | .skipSchedulerRegistration() |
Dominik Laskowski | 5caf9a9 | 2024-02-01 16:53:30 -0500 | [diff] [blame] | 64 | .inject(); |
| 65 | } |
| 66 | |
| 67 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
| 68 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 69 | |
| 70 | static constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID; |
| 71 | static constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u); |
| 72 | static constexpr int DEFAULT_DISPLAY_WIDTH = 1920; |
| 73 | static constexpr int DEFAULT_DISPLAY_HEIGHT = 1024; |
| 74 | |
| 75 | TestableSurfaceFlinger mFlinger; |
| 76 | renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine(); |
| 77 | sp<DisplayDevice> mDisplay; |
| 78 | sp<compositionengine::mock::DisplaySurface> mDisplaySurface = |
| 79 | sp<compositionengine::mock::DisplaySurface>::make(); |
| 80 | sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make(); |
| 81 | mock::TimeStats* mTimeStats = new mock::TimeStats(); |
| 82 | Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr; |
| 83 | Hwc2::mock::Composer* mComposer = nullptr; |
| 84 | }; |
| 85 | |
| 86 | } // namespace android |