Loading services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp +19 −28 Original line number Diff line number Diff line Loading @@ -191,29 +191,20 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, return false; } Factory mFactory; sp<MockSurfaceFlinger> flinger = sp<MockSurfaceFlinger>::make(mFactory); TestableSurfaceFlinger mFlinger(flinger); mFlinger.setupRenderEngine( Factory factory; sp<MockSurfaceFlinger> flingerPtr = sp<MockSurfaceFlinger>::make(factory); TestableSurfaceFlinger flinger(flingerPtr); flinger.setupRenderEngine( std::make_unique<testing::NiceMock<renderengine::mock::RenderEngine>>()); mock::VsyncController* mVsyncController = new testing::NiceMock<mock::VsyncController>(); mock::VSyncTracker* mVSyncTracker = new testing::NiceMock<mock::VSyncTracker>(); mock::EventThread* mEventThread = new testing::NiceMock<mock::EventThread>(); mock::EventThread* mSFEventThread = new testing::NiceMock<mock::EventThread>(); mFlinger.setupScheduler(std::unique_ptr<scheduler::VsyncController>(mVsyncController), std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker), std::unique_ptr<EventThread>(mEventThread), std::unique_ptr<EventThread>(mSFEventThread), TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp, TestableSurfaceFlinger::kOneDisplayMode, true /* useNiceMock */); Hwc2::mock::Composer* mComposer = new testing::NiceMock<Hwc2::mock::Composer>(); mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); mFlinger.mutableMaxRenderTargetSize() = 16384; flinger->setLayerTracingFlags(LayerTracing::TRACE_INPUT | LayerTracing::TRACE_BUFFERS); flinger->setLayerTraceSize(512 * 1024); // 512MB buffer size flinger->startLayerTracing(traceFile.entry(0).elapsed_realtime_nanos()); flinger.setupMockScheduler({.useNiceMock = true}); Hwc2::mock::Composer* composerPtr = new testing::NiceMock<Hwc2::mock::Composer>(); flinger.setupComposer(std::unique_ptr<Hwc2::Composer>(composerPtr)); flinger.mutableMaxRenderTargetSize() = 16384; flingerPtr->setLayerTracingFlags(LayerTracing::TRACE_INPUT | LayerTracing::TRACE_BUFFERS); flingerPtr->setLayerTraceSize(512 * 1024); // 512MB buffer size flingerPtr->startLayerTracing(traceFile.entry(0).elapsed_realtime_nanos()); std::unique_ptr<TraceGenFlingerDataMapper> mapper = std::make_unique<TraceGenFlingerDataMapper>(); TraceGenFlingerDataMapper* dataMapper = mapper.get(); Loading @@ -234,7 +225,7 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, parser.fromProto(entry.added_layers(j), tracingArgs); gui::CreateSurfaceResult outResult; LayerCreationArgs args(mFlinger.flinger(), nullptr /* client */, tracingArgs.name, LayerCreationArgs args(flinger.flinger(), nullptr /* client */, tracingArgs.name, tracingArgs.flags, LayerMetadata(), std::make_optional<int32_t>(tracingArgs.layerId)); Loading @@ -247,10 +238,10 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, } else if (tracingArgs.parentId != -1) { parentHandle = dataMapper->getLayerHandle(tracingArgs.parentId); } mFlinger.createLayer(args, parentHandle, outResult); flinger.createLayer(args, parentHandle, outResult); } else { sp<IBinder> mirrorFromHandle = dataMapper->getLayerHandle(tracingArgs.mirrorFromId); mFlinger.mirrorLayer(args, mirrorFromHandle, outResult); flinger.mirrorLayer(args, mirrorFromHandle, outResult); } LOG_ALWAYS_FATAL_IF(outResult.layerId != tracingArgs.layerId, "Could not create layer expected:%d actual:%d", tracingArgs.layerId, Loading @@ -261,19 +252,19 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, for (int j = 0; j < entry.transactions_size(); j++) { // apply transactions TransactionState transaction = parser.fromProto(entry.transactions(j)); mFlinger.setTransactionStateInternal(transaction); flinger.setTransactionStateInternal(transaction); } const auto frameTime = TimePoint::fromNs(entry.elapsed_realtime_nanos()); const auto vsyncId = VsyncId{entry.vsync_id()}; mFlinger.commit(frameTime, vsyncId); flinger.commit(frameTime, vsyncId); for (int j = 0; j < entry.removed_layer_handles_size(); j++) { dataMapper->mLayerHandles.erase(entry.removed_layer_handles(j)); } } flinger->stopLayerTracing(outputLayersTracePath); flingerPtr->stopLayerTracing(outputLayersTracePath); ALOGD("End of generating trace file. File written to %s", outputLayersTracePath); dataMapper->mLayerHandles.clear(); return true; Loading services/surfaceflinger/tests/unittests/CompositionTest.cpp +1 −32 Original line number Diff line number Diff line Loading @@ -99,7 +99,7 @@ public: ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID}); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); Loading @@ -122,36 +122,6 @@ public: ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } void setupScheduler() { auto eventThread = std::make_unique<mock::EventThread>(); auto sfEventThread = std::make_unique<mock::EventThread>(); EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*eventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); auto vsyncController = std::make_unique<mock::VsyncController>(); auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); EXPECT_CALL(*vsyncTracker, currentPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), std::move(eventThread), std::move(sfEventThread), TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp, TestableSurfaceFlinger::kTwoDisplayModes); } void setupForceGeometryDirty() { // TODO: This requires the visible region and other related // state to be set, and is problematic for BufferLayers since they are Loading @@ -176,7 +146,6 @@ public: bool mDisplayOff = false; TestableSurfaceFlinger mFlinger; sp<DisplayDevice> mDisplay; sp<DisplayDevice> mExternalDisplay; sp<compositionengine::mock::DisplaySurface> mDisplaySurface = sp<compositionengine::mock::DisplaySurface>::make(); sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make(); Loading services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -29,9 +29,7 @@ using testing::SetArgPointee; using android::hardware::graphics::composer::hal::HWDisplayId; using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; DisplayTransactionTest::DisplayTransactionTest() { DisplayTransactionTest::DisplayTransactionTest(bool withMockScheduler) { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); Loading @@ -48,7 +46,10 @@ DisplayTransactionTest::DisplayTransactionTest() { return nullptr; }); injectMockScheduler(); if (withMockScheduler) { injectMockScheduler(PhysicalDisplayId::fromPort(0)); } mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); injectMockComposer(0); Loading @@ -61,7 +62,9 @@ DisplayTransactionTest::~DisplayTransactionTest() { mFlinger.resetScheduler(nullptr); } void DisplayTransactionTest::injectMockScheduler() { void DisplayTransactionTest::injectMockScheduler(PhysicalDisplayId displayId) { LOG_ALWAYS_FATAL_IF(mFlinger.scheduler()); EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*mEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(mEventThread, Loading @@ -78,6 +81,7 @@ void DisplayTransactionTest::injectMockScheduler() { std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker), std::unique_ptr<EventThread>(mEventThread), std::unique_ptr<EventThread>(mSFEventThread), TestableSurfaceFlinger::DefaultDisplayMode{displayId}, TestableSurfaceFlinger::SchedulerCallbackImpl::kMock); } Loading services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h +29 −44 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public: // -------------------------------------------------------------------- // Mock/Fake injection void injectMockScheduler(); void injectMockScheduler(PhysicalDisplayId); void injectMockComposer(int virtualDisplayCount); void injectFakeBufferQueueFactory(); void injectFakeNativeWindowSurfaceFactory(); Loading Loading @@ -139,7 +139,7 @@ public: surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; protected: DisplayTransactionTest(); DisplayTransactionTest(bool withMockScheduler = true); }; constexpr int32_t DEFAULT_VSYNC_PERIOD = 16'666'667; Loading @@ -158,7 +158,6 @@ constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; BOOL_SUBSTITUTE(Async); BOOL_SUBSTITUTE(Critical); BOOL_SUBSTITUTE(Primary); BOOL_SUBSTITUTE(Secure); BOOL_SUBSTITUTE(Virtual); Loading Loading @@ -238,8 +237,8 @@ struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> { // 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC. // 2) HalVirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC. // 3) GpuVirtualDisplayIdType for virtual display without HWC backing. template <typename DisplayIdType, int width, int height, Critical critical, Async async, Secure secure, Primary primary, int grallocUsage, int displayFlags> template <typename DisplayIdType, int width, int height, Async async, Secure secure, Primary primary, int grallocUsage, int displayFlags> struct DisplayVariant { using DISPLAY_ID = DisplayIdGetter<DisplayIdType>; using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>; Loading @@ -255,9 +254,6 @@ struct DisplayVariant { static constexpr Virtual VIRTUAL = IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE; // When creating native window surfaces for the framebuffer, whether those should be critical static constexpr Critical CRITICAL = critical; // When creating native window surfaces for the framebuffer, whether those should be async static constexpr Async ASYNC = async; Loading Loading @@ -486,14 +482,13 @@ constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = constexpr int PHYSICAL_DISPLAY_FLAGS = 0x1; template <typename PhysicalDisplay, int width, int height, Critical critical> template <typename PhysicalDisplay, int width, int height> struct PhysicalDisplayVariant : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, HwcDisplayVariant< PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL, DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical, : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL, DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, PhysicalDisplay> {}; Loading Loading @@ -525,15 +520,9 @@ struct TertiaryDisplay { static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; }; // A primary display is a physical display that is critical using PrimaryDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>; // An external display is physical display that is not critical. using ExternalDisplayVariant = PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>; using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>; using PrimaryDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160>; using ExternalDisplayVariant = PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280>; using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200>; // A virtual display not supported by the HWC. constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; Loading @@ -542,12 +531,11 @@ constexpr int VIRTUAL_DISPLAY_FLAGS = 0x0; template <int width, int height, Secure secure> struct NonHwcVirtualDisplayVariant : DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure, : DisplayVariant<GpuVirtualDisplayIdType, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS> { using Base = DisplayVariant<GpuVirtualDisplayIdType, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS> { using Base = DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>; VIRTUAL_DISPLAY_FLAGS>; static void injectHwcDisplay(DisplayTransactionTest*) {} Loading Loading @@ -589,17 +577,14 @@ constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER template <int width, int height, Secure secure> struct HwcVirtualDisplayVariant : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>, HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>, HwcDisplayVariant< HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>> { using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER, VIRTUAL_DISPLAY_FLAGS>; VIRTUAL_DISPLAY_FLAGS>> { using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER, VIRTUAL_DISPLAY_FLAGS>; using Self = HwcVirtualDisplayVariant<width, height, secure>; static std::shared_ptr<compositionengine::Display> injectCompositionDisplay( Loading services/surfaceflinger/tests/unittests/FpsReporterTest.cpp +1 −32 Original line number Diff line number Diff line Loading @@ -29,9 +29,7 @@ #include "TestableSurfaceFlinger.h" #include "fake/FakeClock.h" #include "mock/DisplayHardware/MockComposer.h" #include "mock/MockEventThread.h" #include "mock/MockFrameTimeline.h" #include "mock/MockVsyncController.h" namespace android { Loading @@ -47,7 +45,6 @@ using testing::UnorderedElementsAre; using android::Hwc2::IComposer; using android::Hwc2::IComposerClient; using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; using gui::LayerMetadata; struct TestableFpsListener : public gui::BnFpsListener { Loading Loading @@ -77,7 +74,6 @@ protected: static constexpr uint32_t LAYER_FLAGS = 0; static constexpr int32_t PRIORITY_UNSET = -1; void setupScheduler(); sp<Layer> createBufferStateLayer(LayerMetadata metadata); TestableSurfaceFlinger mFlinger; Loading @@ -102,7 +98,7 @@ FpsReporterTest::FpsReporterTest() { ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); mFlinger.setupMockScheduler(); mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); mFpsListener = sp<TestableFpsListener>::make(); Loading @@ -120,33 +116,6 @@ sp<Layer> FpsReporterTest::createBufferStateLayer(LayerMetadata metadata = {}) { return sp<Layer>::make(args); } void FpsReporterTest::setupScheduler() { auto eventThread = std::make_unique<mock::EventThread>(); auto sfEventThread = std::make_unique<mock::EventThread>(); EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*eventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); auto vsyncController = std::make_unique<mock::VsyncController>(); auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); EXPECT_CALL(*vsyncTracker, currentPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), std::move(eventThread), std::move(sfEventThread)); } namespace { TEST_F(FpsReporterTest, callsListeners) { Loading Loading
services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp +19 −28 Original line number Diff line number Diff line Loading @@ -191,29 +191,20 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, return false; } Factory mFactory; sp<MockSurfaceFlinger> flinger = sp<MockSurfaceFlinger>::make(mFactory); TestableSurfaceFlinger mFlinger(flinger); mFlinger.setupRenderEngine( Factory factory; sp<MockSurfaceFlinger> flingerPtr = sp<MockSurfaceFlinger>::make(factory); TestableSurfaceFlinger flinger(flingerPtr); flinger.setupRenderEngine( std::make_unique<testing::NiceMock<renderengine::mock::RenderEngine>>()); mock::VsyncController* mVsyncController = new testing::NiceMock<mock::VsyncController>(); mock::VSyncTracker* mVSyncTracker = new testing::NiceMock<mock::VSyncTracker>(); mock::EventThread* mEventThread = new testing::NiceMock<mock::EventThread>(); mock::EventThread* mSFEventThread = new testing::NiceMock<mock::EventThread>(); mFlinger.setupScheduler(std::unique_ptr<scheduler::VsyncController>(mVsyncController), std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker), std::unique_ptr<EventThread>(mEventThread), std::unique_ptr<EventThread>(mSFEventThread), TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp, TestableSurfaceFlinger::kOneDisplayMode, true /* useNiceMock */); Hwc2::mock::Composer* mComposer = new testing::NiceMock<Hwc2::mock::Composer>(); mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); mFlinger.mutableMaxRenderTargetSize() = 16384; flinger->setLayerTracingFlags(LayerTracing::TRACE_INPUT | LayerTracing::TRACE_BUFFERS); flinger->setLayerTraceSize(512 * 1024); // 512MB buffer size flinger->startLayerTracing(traceFile.entry(0).elapsed_realtime_nanos()); flinger.setupMockScheduler({.useNiceMock = true}); Hwc2::mock::Composer* composerPtr = new testing::NiceMock<Hwc2::mock::Composer>(); flinger.setupComposer(std::unique_ptr<Hwc2::Composer>(composerPtr)); flinger.mutableMaxRenderTargetSize() = 16384; flingerPtr->setLayerTracingFlags(LayerTracing::TRACE_INPUT | LayerTracing::TRACE_BUFFERS); flingerPtr->setLayerTraceSize(512 * 1024); // 512MB buffer size flingerPtr->startLayerTracing(traceFile.entry(0).elapsed_realtime_nanos()); std::unique_ptr<TraceGenFlingerDataMapper> mapper = std::make_unique<TraceGenFlingerDataMapper>(); TraceGenFlingerDataMapper* dataMapper = mapper.get(); Loading @@ -234,7 +225,7 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, parser.fromProto(entry.added_layers(j), tracingArgs); gui::CreateSurfaceResult outResult; LayerCreationArgs args(mFlinger.flinger(), nullptr /* client */, tracingArgs.name, LayerCreationArgs args(flinger.flinger(), nullptr /* client */, tracingArgs.name, tracingArgs.flags, LayerMetadata(), std::make_optional<int32_t>(tracingArgs.layerId)); Loading @@ -247,10 +238,10 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, } else if (tracingArgs.parentId != -1) { parentHandle = dataMapper->getLayerHandle(tracingArgs.parentId); } mFlinger.createLayer(args, parentHandle, outResult); flinger.createLayer(args, parentHandle, outResult); } else { sp<IBinder> mirrorFromHandle = dataMapper->getLayerHandle(tracingArgs.mirrorFromId); mFlinger.mirrorLayer(args, mirrorFromHandle, outResult); flinger.mirrorLayer(args, mirrorFromHandle, outResult); } LOG_ALWAYS_FATAL_IF(outResult.layerId != tracingArgs.layerId, "Could not create layer expected:%d actual:%d", tracingArgs.layerId, Loading @@ -261,19 +252,19 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile, for (int j = 0; j < entry.transactions_size(); j++) { // apply transactions TransactionState transaction = parser.fromProto(entry.transactions(j)); mFlinger.setTransactionStateInternal(transaction); flinger.setTransactionStateInternal(transaction); } const auto frameTime = TimePoint::fromNs(entry.elapsed_realtime_nanos()); const auto vsyncId = VsyncId{entry.vsync_id()}; mFlinger.commit(frameTime, vsyncId); flinger.commit(frameTime, vsyncId); for (int j = 0; j < entry.removed_layer_handles_size(); j++) { dataMapper->mLayerHandles.erase(entry.removed_layer_handles(j)); } } flinger->stopLayerTracing(outputLayersTracePath); flingerPtr->stopLayerTracing(outputLayersTracePath); ALOGD("End of generating trace file. File written to %s", outputLayersTracePath); dataMapper->mLayerHandles.clear(); return true; Loading
services/surfaceflinger/tests/unittests/CompositionTest.cpp +1 −32 Original line number Diff line number Diff line Loading @@ -99,7 +99,7 @@ public: ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID}); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); Loading @@ -122,36 +122,6 @@ public: ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } void setupScheduler() { auto eventThread = std::make_unique<mock::EventThread>(); auto sfEventThread = std::make_unique<mock::EventThread>(); EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*eventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); auto vsyncController = std::make_unique<mock::VsyncController>(); auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); EXPECT_CALL(*vsyncTracker, currentPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), std::move(eventThread), std::move(sfEventThread), TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp, TestableSurfaceFlinger::kTwoDisplayModes); } void setupForceGeometryDirty() { // TODO: This requires the visible region and other related // state to be set, and is problematic for BufferLayers since they are Loading @@ -176,7 +146,6 @@ public: bool mDisplayOff = false; TestableSurfaceFlinger mFlinger; sp<DisplayDevice> mDisplay; sp<DisplayDevice> mExternalDisplay; sp<compositionengine::mock::DisplaySurface> mDisplaySurface = sp<compositionengine::mock::DisplaySurface>::make(); sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make(); Loading
services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -29,9 +29,7 @@ using testing::SetArgPointee; using android::hardware::graphics::composer::hal::HWDisplayId; using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; DisplayTransactionTest::DisplayTransactionTest() { DisplayTransactionTest::DisplayTransactionTest(bool withMockScheduler) { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); Loading @@ -48,7 +46,10 @@ DisplayTransactionTest::DisplayTransactionTest() { return nullptr; }); injectMockScheduler(); if (withMockScheduler) { injectMockScheduler(PhysicalDisplayId::fromPort(0)); } mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); injectMockComposer(0); Loading @@ -61,7 +62,9 @@ DisplayTransactionTest::~DisplayTransactionTest() { mFlinger.resetScheduler(nullptr); } void DisplayTransactionTest::injectMockScheduler() { void DisplayTransactionTest::injectMockScheduler(PhysicalDisplayId displayId) { LOG_ALWAYS_FATAL_IF(mFlinger.scheduler()); EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*mEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(mEventThread, Loading @@ -78,6 +81,7 @@ void DisplayTransactionTest::injectMockScheduler() { std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker), std::unique_ptr<EventThread>(mEventThread), std::unique_ptr<EventThread>(mSFEventThread), TestableSurfaceFlinger::DefaultDisplayMode{displayId}, TestableSurfaceFlinger::SchedulerCallbackImpl::kMock); } Loading
services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h +29 −44 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public: // -------------------------------------------------------------------- // Mock/Fake injection void injectMockScheduler(); void injectMockScheduler(PhysicalDisplayId); void injectMockComposer(int virtualDisplayCount); void injectFakeBufferQueueFactory(); void injectFakeNativeWindowSurfaceFactory(); Loading Loading @@ -139,7 +139,7 @@ public: surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; protected: DisplayTransactionTest(); DisplayTransactionTest(bool withMockScheduler = true); }; constexpr int32_t DEFAULT_VSYNC_PERIOD = 16'666'667; Loading @@ -158,7 +158,6 @@ constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; BOOL_SUBSTITUTE(Async); BOOL_SUBSTITUTE(Critical); BOOL_SUBSTITUTE(Primary); BOOL_SUBSTITUTE(Secure); BOOL_SUBSTITUTE(Virtual); Loading Loading @@ -238,8 +237,8 @@ struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> { // 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC. // 2) HalVirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC. // 3) GpuVirtualDisplayIdType for virtual display without HWC backing. template <typename DisplayIdType, int width, int height, Critical critical, Async async, Secure secure, Primary primary, int grallocUsage, int displayFlags> template <typename DisplayIdType, int width, int height, Async async, Secure secure, Primary primary, int grallocUsage, int displayFlags> struct DisplayVariant { using DISPLAY_ID = DisplayIdGetter<DisplayIdType>; using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>; Loading @@ -255,9 +254,6 @@ struct DisplayVariant { static constexpr Virtual VIRTUAL = IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE; // When creating native window surfaces for the framebuffer, whether those should be critical static constexpr Critical CRITICAL = critical; // When creating native window surfaces for the framebuffer, whether those should be async static constexpr Async ASYNC = async; Loading Loading @@ -486,14 +482,13 @@ constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = constexpr int PHYSICAL_DISPLAY_FLAGS = 0x1; template <typename PhysicalDisplay, int width, int height, Critical critical> template <typename PhysicalDisplay, int width, int height> struct PhysicalDisplayVariant : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, HwcDisplayVariant< PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL, DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical, : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL, DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>, PhysicalDisplay> {}; Loading Loading @@ -525,15 +520,9 @@ struct TertiaryDisplay { static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; }; // A primary display is a physical display that is critical using PrimaryDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>; // An external display is physical display that is not critical. using ExternalDisplayVariant = PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>; using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>; using PrimaryDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160>; using ExternalDisplayVariant = PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280>; using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200>; // A virtual display not supported by the HWC. constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; Loading @@ -542,12 +531,11 @@ constexpr int VIRTUAL_DISPLAY_FLAGS = 0x0; template <int width, int height, Secure secure> struct NonHwcVirtualDisplayVariant : DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure, : DisplayVariant<GpuVirtualDisplayIdType, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS> { using Base = DisplayVariant<GpuVirtualDisplayIdType, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS> { using Base = DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>; VIRTUAL_DISPLAY_FLAGS>; static void injectHwcDisplay(DisplayTransactionTest*) {} Loading Loading @@ -589,17 +577,14 @@ constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER template <int width, int height, Secure secure> struct HwcVirtualDisplayVariant : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>, HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>, HwcDisplayVariant< HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY, VIRTUAL_DISPLAY_FLAGS>> { using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER, VIRTUAL_DISPLAY_FLAGS>; VIRTUAL_DISPLAY_FLAGS>> { using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER, VIRTUAL_DISPLAY_FLAGS>; using Self = HwcVirtualDisplayVariant<width, height, secure>; static std::shared_ptr<compositionengine::Display> injectCompositionDisplay( Loading
services/surfaceflinger/tests/unittests/FpsReporterTest.cpp +1 −32 Original line number Diff line number Diff line Loading @@ -29,9 +29,7 @@ #include "TestableSurfaceFlinger.h" #include "fake/FakeClock.h" #include "mock/DisplayHardware/MockComposer.h" #include "mock/MockEventThread.h" #include "mock/MockFrameTimeline.h" #include "mock/MockVsyncController.h" namespace android { Loading @@ -47,7 +45,6 @@ using testing::UnorderedElementsAre; using android::Hwc2::IComposer; using android::Hwc2::IComposerClient; using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; using gui::LayerMetadata; struct TestableFpsListener : public gui::BnFpsListener { Loading Loading @@ -77,7 +74,6 @@ protected: static constexpr uint32_t LAYER_FLAGS = 0; static constexpr int32_t PRIORITY_UNSET = -1; void setupScheduler(); sp<Layer> createBufferStateLayer(LayerMetadata metadata); TestableSurfaceFlinger mFlinger; Loading @@ -102,7 +98,7 @@ FpsReporterTest::FpsReporterTest() { ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); mFlinger.setupMockScheduler(); mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); mFpsListener = sp<TestableFpsListener>::make(); Loading @@ -120,33 +116,6 @@ sp<Layer> FpsReporterTest::createBufferStateLayer(LayerMetadata metadata = {}) { return sp<Layer>::make(args); } void FpsReporterTest::setupScheduler() { auto eventThread = std::make_unique<mock::EventThread>(); auto sfEventThread = std::make_unique<mock::EventThread>(); EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*eventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(), mock::EventThread::kCallingUid, ResyncCallback()))); auto vsyncController = std::make_unique<mock::VsyncController>(); auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); EXPECT_CALL(*vsyncTracker, currentPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), std::move(eventThread), std::move(sfEventThread)); } namespace { TEST_F(FpsReporterTest, callsListeners) { Loading