#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <drm_fourcc.h>
#include <overlay-prioritizer-client-protocol.h>
#include <cstdint>
#include <memory>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/mock_callback.h"
#include "build/chromeos_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/rrect_f.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/linux/drm_util_linux.h"
#include "ui/gfx/overlay_priority_hint.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/ozone/platform/wayland/common/wayland_overlay_config.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_factory.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_frame_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_subsurface.h"
#include "ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h"
#include "ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h"
#include "ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
#include "ui/platform_window/platform_window_init_properties.h"
_;
Truly;
Values;
namespace ui {
namespace {
MockTerminateGpuCallback;
constexpr gfx::Size kDefaultSize(1024, 768);
constexpr uint32_t kAugmentedSurfaceNotSupportedVersion = …;
constexpr float kDefaultScale = …;
struct InputData { … };
class MockSurfaceGpu : public WaylandSurfaceGpu { … };
}
class WaylandBufferManagerTest : public WaylandTest { … };
TEST_P(WaylandBufferManagerTest, CreateDmabufBasedBuffers) { … }
TEST_P(WaylandBufferManagerTest, VerifyModifiers) { … }
TEST_P(WaylandBufferManagerTest, CreateShmBasedBuffers) { … }
TEST_P(WaylandBufferManagerTest, ValidateDataFromGpu) { … }
TEST_P(WaylandBufferManagerTest, CreateAndDestroyBuffer) { … }
TEST_P(WaylandBufferManagerTest, CommitBufferNonExistingBufferId) { … }
TEST_P(WaylandBufferManagerTest, CommitOverlaysNonExistingBufferId) { … }
TEST_P(WaylandBufferManagerTest, CommitOverlaysWithSameBufferId) { … }
TEST_P(WaylandBufferManagerTest, CommitBufferNullWidget) { … }
TEST_P(WaylandBufferManagerTest, CommitOverlaysNonsensicalBoundsRect) { … }
TEST_P(WaylandBufferManagerTest,
CommitOverlaysNonsensicalBoundsRectSingleOverlay) { … }
TEST_P(WaylandBufferManagerTest, EnsureCorrectOrderOfCallbacks) { … }
TEST_P(WaylandBufferManagerTest,
DestroyedBuffersGeneratePresentationFeedbackFailure) { … }
TEST_P(WaylandBufferManagerTest,
EnsureDiscardedPresentationDoesNotMakePreviousFeedbacksFailed) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_P(WaylandBufferManagerTest, EnsureFailedPresentationIsSent) {
constexpr uint32_t kBufferId1 = 1;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
ASSERT_TRUE(mock_wp_presentation);
});
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false , kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u ,
false );
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
constexpr uint32_t kNumberOfCommits = 1;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
EXPECT_EQ(
1u,
server->EnsureAndGetWpPresentation()->num_of_presentation_callbacks());
server->GetObject<wl::MockSurface>(id)->SendFrameCallback();
});
EXPECT_CALL(
mock_surface_gpu,
OnPresentation(
kBufferId1,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kFailure))))
.Times(1);
wl::MockWpPresentation::PresentationFeedbackParams params{
.tv_sec_hi = 1,
.tv_sec_lo = 1,
.tv_nsec = 1,
.refresh = 1,
.seq_hi = 1,
.seq_lo = 1,
.flags = gfx::PresentationFeedback::kFailure};
PostToServerAndWait([params](wl::TestWaylandServerThread* server) {
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->SendPresentationFeedbackToClient(false,
params);
});
task_environment_.FastForwardBy(
WaylandFrameManager::GetPresentationFlushTimerDurationForTesting());
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false );
}
#endif
TEST_P(WaylandBufferManagerTest, TestCommitBufferConditions) { … }
TEST_P(WaylandBufferManagerTest, TestCommitBufferConditionsAckConfigured) { … }
TEST_P(WaylandBufferManagerTest,
CommitBufferConditionsWithDeferredAckConfigure) { … }
TEST_P(WaylandBufferManagerTest, AnonymousBufferAttachedAndReleased) { … }
TEST_P(WaylandBufferManagerTest, DestroyBufferForDestroyedWindow) { … }
TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionSingleBuffer) { … }
TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionMultipleBuffers) { … }
TEST_P(WaylandBufferManagerTest, DestroyBufferCommittedTwiceInARow) { … }
TEST_P(WaylandBufferManagerTest, ReleaseBufferCommittedTwiceInARow) { … }
TEST_P(WaylandBufferManagerTest, ReleaseOrderDifferentToCommitOrder) { … }
TEST_P(WaylandBufferManagerTest,
OnSubmissionCalledForBufferCommitedTwiceInARow) { … }
TEST_P(WaylandBufferManagerTest, OnSubmissionCalledForSingleBuffer) { … }
TEST_P(WaylandBufferManagerTest, RootSurfaceIsCommittedLast) { … }
TEST_P(WaylandBufferManagerTest, FencedRelease) { … }
TEST_P(WaylandBufferManagerTest,
CanSubmitBufferAfterChannelDestroyedAndInitialized) { … }
TEST_P(WaylandBufferManagerTest, HidesSubsurfacesOnChannelDestroyed) { … }
TEST_P(WaylandBufferManagerTest,
DoesNotAttachAndCommitOnHideIfNoBuffersAttached) { … }
TEST_P(WaylandBufferManagerTest, HasOverlayPrioritizer) { … }
TEST_P(WaylandBufferManagerTest, CanSubmitOverlayPriority) { … }
TEST_P(WaylandBufferManagerTest, HasSurfaceAugmenter) { … }
TEST_P(WaylandBufferManagerTest, CanSetRoundedCorners) { … }
TEST_P(WaylandBufferManagerTest, FeedbacksAreDiscardedIfClientMisbehaves) { … }
TEST_P(WaylandBufferManagerTest, ExecutesTasksAfterInitialization) { … }
TEST_P(WaylandBufferManagerTest, DoesNotRequestReleaseForSolidColorBuffers) { … }
class WaylandBufferManagerViewportTest : public WaylandBufferManagerTest { … };
TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationNonInteger) { … }
TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationInteger) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}