code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_SOURCE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_SOURCE_H_ #include <wayland-server-protocol.h> #include "base/memory/weak_ptr.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" struct wl_resource; namespace wl { extern const struct wl_data_source_interface kTestDataSourceImpl; class TestDataSource : public TestSelectionSource { public: explicit TestDataSource(wl_resource* resource); TestDataSource(const TestDataSource&) = delete; TestDataSource& operator=(const TestDataSource&) = delete; ~TestDataSource() override; void SetActions(uint32_t dnd_actions); uint32_t actions() const { return actions_; } private: uint32_t actions_ = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_SOURCE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_source.h
C++
unknown
1,018
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_gtk_primary_selection.h" #include <gtk-primary-selection-server-protocol.h> #include <wayland-server-core.h> #include <cstdint> #include <memory> #include "base/memory/raw_ptr.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" // GtkPrimarySelection* classes contain protocol-specific implementation of // TestSelection*::Delegate interfaces, such that primary selection test // cases may be set-up and run against test wayland compositor. namespace wl { namespace { void Destroy(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } struct GtkPrimarySelectionOffer final : public TestSelectionOffer::Delegate { void SendOffer(const std::string& mime_type) override { gtk_primary_selection_offer_send_offer(offer->resource(), mime_type.c_str()); } raw_ptr<TestSelectionOffer> offer = nullptr; }; struct GtkPrimarySelectionDevice final : public TestSelectionDevice::Delegate { TestSelectionOffer* CreateAndSendOffer() override { static const struct gtk_primary_selection_offer_interface kOfferImpl = { &TestSelectionOffer::Receive, &Destroy}; wl_resource* device_resource = device->resource(); const int version = wl_resource_get_version(device_resource); auto owned_delegate = std::make_unique<GtkPrimarySelectionOffer>(); auto* delegate = owned_delegate.get(); wl_resource* new_offer_resource = CreateResourceWithImpl<TestSelectionOffer>( wl_resource_get_client(device->resource()), &gtk_primary_selection_offer_interface, version, &kOfferImpl, 0, std::move(owned_delegate)); delegate->offer = GetUserDataAs<TestSelectionOffer>(new_offer_resource); gtk_primary_selection_device_send_data_offer(device_resource, new_offer_resource); return delegate->offer; } void SendSelection(TestSelectionOffer* offer) override { CHECK(offer); gtk_primary_selection_device_send_selection(device->resource(), offer->resource()); } void HandleSetSelection(TestSelectionSource* source, uint32_t serial) override { NOTIMPLEMENTED(); } raw_ptr<TestSelectionDevice> device = nullptr; }; struct GtkPrimarySelectionSource : public TestSelectionSource::Delegate { void SendSend(const std::string& mime_type, base::ScopedFD write_fd) override { gtk_primary_selection_source_send_send(source->resource(), mime_type.c_str(), write_fd.get()); wl_client_flush(wl_resource_get_client(source->resource())); } void SendFinished() override { NOTREACHED() << "The interface does not support this method."; } void SendCancelled() override { gtk_primary_selection_source_send_cancelled(source->resource()); } void SendDndAction(uint32_t action) override { NOTREACHED() << "The interface does not support this method."; } raw_ptr<TestSelectionSource> source = nullptr; }; struct GtkPrimarySelectionDeviceManager : public TestSelectionDeviceManager::Delegate { explicit GtkPrimarySelectionDeviceManager(uint32_t version) : version_(version) {} ~GtkPrimarySelectionDeviceManager() override = default; TestSelectionDevice* CreateDevice(wl_client* client, uint32_t id) override { static const struct gtk_primary_selection_device_interface kTestSelectionDeviceImpl = {&TestSelectionDevice::SetSelection, &Destroy}; auto owned_delegate = std::make_unique<GtkPrimarySelectionDevice>(); auto* delegate = owned_delegate.get(); wl_resource* resource = CreateResourceWithImpl<TestSelectionDevice>( client, &gtk_primary_selection_device_interface, version_, &kTestSelectionDeviceImpl, id, std::move(owned_delegate)); delegate->device = GetUserDataAs<TestSelectionDevice>(resource); return delegate->device; } TestSelectionSource* CreateSource(wl_client* client, uint32_t id) override { static const struct gtk_primary_selection_source_interface kTestSelectionSourceImpl = {&TestSelectionSource::Offer, &Destroy}; auto owned_delegate = std::make_unique<GtkPrimarySelectionSource>(); auto* delegate = owned_delegate.get(); wl_resource* resource = CreateResourceWithImpl<TestSelectionSource>( client, &gtk_primary_selection_source_interface, version_, &kTestSelectionSourceImpl, id, std::move(owned_delegate)); delegate->source = GetUserDataAs<TestSelectionSource>(resource); return delegate->source; } private: const uint32_t version_; }; } // namespace std::unique_ptr<TestSelectionDeviceManager> CreateTestSelectionManagerGtk() { constexpr uint32_t kVersion = 1; static const struct gtk_primary_selection_device_manager_interface kTestSelectionManagerImpl = {&TestSelectionDeviceManager::CreateSource, &TestSelectionDeviceManager::GetDevice, &Destroy}; static const TestSelectionDeviceManager::InterfaceInfo interface_info = { .interface = &gtk_primary_selection_device_manager_interface, .implementation = &kTestSelectionManagerImpl, .version = kVersion}; return std::make_unique<TestSelectionDeviceManager>( interface_info, std::make_unique<GtkPrimarySelectionDeviceManager>(kVersion)); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_gtk_primary_selection.cc
C++
unknown
5,787
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_GTK_PRIMARY_SELECTION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_GTK_PRIMARY_SELECTION_H_ #include <memory> #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" namespace wl { std::unique_ptr<TestSelectionDeviceManager> CreateTestSelectionManagerGtk(); } #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_GTK_PRIMARY_SELECTION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_gtk_primary_selection.h
C++
unknown
545
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_keyboard.h" namespace wl { const struct wl_pointer_interface kTestKeyboardImpl = { nullptr, // set_cursor &DestroyResource, // release }; TestKeyboard::TestKeyboard(wl_resource* resource) : ServerObject(resource) {} TestKeyboard::~TestKeyboard() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_keyboard.cc
C++
unknown
490
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_KEYBOARD_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_KEYBOARD_H_ #include <wayland-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct wl_pointer_interface kTestKeyboardImpl; class TestKeyboard : public ServerObject { public: explicit TestKeyboard(wl_resource* resource); TestKeyboard(const TestKeyboard&) = delete; TestKeyboard& operator=(const TestKeyboard&) = delete; ~TestKeyboard() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_KEYBOARD_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_keyboard.h
C++
unknown
768
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_output.h" #include <wayland-server-protocol.h> #include "base/check_op.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/display/types/display_constants.h" namespace wl { namespace { // TODO(tluk): Update this to the latest supported wl_output version. constexpr uint32_t kOutputVersion = 2; } TestOutput::TestOutput(FlushMetricsCallback flush_metrics_callback) : TestOutput(std::move(flush_metrics_callback), TestOutputMetrics()) {} TestOutput::TestOutput(FlushMetricsCallback flush_metrics_callback, TestOutputMetrics metrics) : GlobalObject(&wl_output_interface, nullptr, kOutputVersion), flush_metrics_callback_(std::move(flush_metrics_callback)), metrics_(std::move(metrics)) {} TestOutput::~TestOutput() = default; // static TestOutput* TestOutput::FromResource(wl_resource* resource) { return GetUserDataAs<TestOutput>(resource); } void TestOutput::SetPhysicalAndLogicalBounds(const gfx::Rect& bounds) { metrics_.wl_physical_size = bounds.size(); metrics_.wl_origin = bounds.origin(); metrics_.xdg_logical_size = bounds.size(); metrics_.xdg_logical_origin = bounds.origin(); } void TestOutput::ApplyLogicalTranspose() { metrics_.xdg_logical_size.Transpose(); } void TestOutput::SetOrigin(const gfx::Point& wl_origin) { metrics_.wl_origin = wl_origin; } void TestOutput::SetScale(int32_t wl_scale) { metrics_.wl_scale = wl_scale; } void TestOutput::SetLogicalSize(const gfx::Size& xdg_logical_size) { metrics_.xdg_logical_size = xdg_logical_size; } void TestOutput::SetLogicalOrigin(const gfx::Point& xdg_logical_origin) { metrics_.xdg_logical_origin = xdg_logical_origin; } void TestOutput::SetPanelTransform(wl_output_transform wl_panel_transform) { metrics_.wl_panel_transform = wl_panel_transform; } void TestOutput::SetLogicalInsets(const gfx::Insets& aura_logical_insets) { metrics_.aura_logical_insets = aura_logical_insets; } void TestOutput::SetDeviceScaleFactor(float aura_device_scale_factor) { metrics_.aura_device_scale_factor = aura_device_scale_factor; } void TestOutput::SetLogicalTransform( wl_output_transform aura_logical_transform) { metrics_.aura_logical_transform = aura_logical_transform; } const gfx::Size& TestOutput::GetPhysicalSize() const { return metrics_.wl_physical_size; } const gfx::Point& TestOutput::GetOrigin() const { return metrics_.wl_origin; } int32_t TestOutput::GetScale() const { return metrics_.wl_scale; } int64_t TestOutput::GetDisplayId() const { return metrics_.aura_display_id; } void TestOutput::Flush() { flush_metrics_callback_.Run(resource(), metrics_); constexpr char kUnknownMake[] = "unknown_make"; constexpr char kUnknownModel[] = "unknown_model"; wl_output_send_geometry( resource(), metrics_.wl_origin.x(), metrics_.wl_origin.y(), 0 /* physical_width */, 0 /* physical_height */, 0 /* subpixel */, kUnknownMake, kUnknownModel, metrics_.wl_panel_transform); wl_output_send_mode(resource(), WL_OUTPUT_MODE_CURRENT, metrics_.wl_physical_size.width(), metrics_.wl_physical_size.height(), 0); wl_output_send_scale(resource(), metrics_.wl_scale); if (xdg_output_) { xdg_output_->Flush(metrics_); } if (aura_output_) { aura_output_->Flush(metrics_); } wl_output_send_done(resource()); } // Notifies clients about the changes in the output configuration via server // events as soon as the output is bound (unless suppressed). Sending metrics at // bind time is the most common behavior among Wayland compositors and is the // case for the exo compositor. void TestOutput::OnBind() { if (!suppress_implicit_flush_) { Flush(); } } void TestOutput::SetAuraOutput(TestZAuraOutput* aura_output) { aura_output_ = aura_output; // Make sure to send the necessary information for a client that // relies on the xdg and aura output information. if (xdg_output_ && !suppress_implicit_flush_) { Flush(); } } void TestOutput::SetXdgOutput(TestZXdgOutput* xdg_output) { xdg_output_ = xdg_output; // Make sure to send the necessary information for a client that // relies on the xdg and aura output information. if (aura_output_ && !suppress_implicit_flush_) { Flush(); } } TestZAuraOutput* TestOutput::GetAuraOutput() { return aura_output_; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_output.cc
C++
unknown
4,564
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_H_ #include <wayland-server-protocol.h> #include <cstdint> #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/rect.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/test_output_metrics.h" #include "ui/ozone/platform/wayland/test/test_zaura_output.h" #include "ui/ozone/platform/wayland/test/test_zxdg_output.h" struct wl_resource; namespace wl { // Handles the server-side representation of the wl_output. Values stored in // `metrics_` are propagated to clients when `Flush()` is called. This occurs // when the client first binds the output and output extensions are set by // default. class TestOutput : public GlobalObject { public: // A callback that allows clients to respond to a Flush() of a given // TestOutput's metrics_. This is called immediately before Flush() sends // metrics events to clients. The output_resource is the wl_resource // associated with this output. using FlushMetricsCallback = base::RepeatingCallback<void(wl_resource* output_resource, const TestOutputMetrics& metrics)>; explicit TestOutput(FlushMetricsCallback flush_metrics_callback); TestOutput(FlushMetricsCallback flush_metrics_callback, TestOutputMetrics metrics); TestOutput(const TestOutput&) = delete; TestOutput& operator=(const TestOutput&) = delete; ~TestOutput() override; static TestOutput* FromResource(wl_resource* resource); // Useful only when zaura_shell is supported. void set_aura_shell_enabled() { aura_shell_enabled_ = true; } bool aura_shell_enabled() { return aura_shell_enabled_; } ////////////////////////////////////////////////////////////////////////////// // Output metrics helpers. // Sets the physical and logical bounds of the output to `bounds`. This is // helpful for the default case. void SetPhysicalAndLogicalBounds(const gfx::Rect& bounds); // Applies a transpose operation on the logical size. void ApplyLogicalTranspose(); void SetOrigin(const gfx::Point& wl_origin); void SetScale(int32_t wl_scale); void SetLogicalSize(const gfx::Size& xdg_logical_size); void SetLogicalOrigin(const gfx::Point& xdg_logical_origin); void SetPanelTransform(wl_output_transform wl_panel_transform); void SetLogicalInsets(const gfx::Insets& wl_logical_insets); void SetDeviceScaleFactor(float aura_device_scale_factor); void SetLogicalTransform(wl_output_transform aura_logical_transform); const gfx::Size& GetPhysicalSize() const; const gfx::Point& GetOrigin() const; int32_t GetScale() const; int64_t GetDisplayId() const; ////////////////////////////////////////////////////////////////////////////// // Flushes `metrics_` for this output and all available extensions. void Flush(); void SetAuraOutput(TestZAuraOutput* aura_output); TestZAuraOutput* GetAuraOutput(); void SetXdgOutput(TestZXdgOutput* aura_output); TestZXdgOutput* xdg_output() { return xdg_output_; } void set_suppress_implicit_flush(bool suppress_implicit_flush) { suppress_implicit_flush_ = suppress_implicit_flush; } protected: void OnBind() override; private: bool aura_shell_enabled_ = false; // Disable sending metrics to clients implicitly (i.e. when the output is // bound or when output extensions are created). If this is set `Flush()` must // be explicitly called to propagate pending metrics. bool suppress_implicit_flush_ = false; // Called immediately before Flush() sends metrics events to clients. FlushMetricsCallback flush_metrics_callback_; TestOutputMetrics metrics_; raw_ptr<TestZAuraOutput> aura_output_ = nullptr; raw_ptr<TestZXdgOutput> xdg_output_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_output.h
C++
unknown
4,136
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_output_metrics.h" namespace wl { namespace { int64_t display_id_counter = 10; } // namespace TestOutputMetrics::TestOutputMetrics() : aura_display_id(display_id_counter++) {} TestOutputMetrics::TestOutputMetrics(const gfx::Rect& bounds) : wl_physical_size(bounds.size()), wl_origin(bounds.origin()), xdg_logical_size(bounds.size()), xdg_logical_origin(bounds.origin()), aura_display_id(display_id_counter++) {} TestOutputMetrics::TestOutputMetrics(TestOutputMetrics&&) = default; TestOutputMetrics& TestOutputMetrics::operator=(TestOutputMetrics&&) = default; TestOutputMetrics::~TestOutputMetrics() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_output_metrics.cc
C++
unknown
860
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_METRICS_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_METRICS_H_ #include <wayland-server-protocol-core.h> #include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" namespace wl { // Metrics for testing wayland_output and its extensions. struct TestOutputMetrics { // Creates a test metrics object with reasonable defaults. TestOutputMetrics(); // Creates a test metrics object with physical and logical bounds set to // `bounds`. explicit TestOutputMetrics(const gfx::Rect& bounds); TestOutputMetrics(const TestOutputMetrics&) = delete; TestOutputMetrics& operator=(const TestOutputMetrics&) = delete; TestOutputMetrics(TestOutputMetrics&&); TestOutputMetrics& operator=(TestOutputMetrics&&); virtual ~TestOutputMetrics(); // Output metrics gfx::Size wl_physical_size = gfx::Size(800, 600); gfx::Point wl_origin; int32_t wl_scale = 1; wl_output_transform wl_panel_transform = WL_OUTPUT_TRANSFORM_NORMAL; // ZxdgOutput metrics gfx::Size xdg_logical_size = gfx::Size(800, 600); gfx::Point xdg_logical_origin; // AuraOutput metrics int64_t aura_display_id; gfx::Insets aura_logical_insets; float aura_device_scale_factor = 1; wl_output_transform aura_logical_transform = WL_OUTPUT_TRANSFORM_NORMAL; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_METRICS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_output_metrics.h
C++
unknown
1,623
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" namespace wl { namespace { void SetOverlayPriority(struct wl_client* client, struct wl_resource* resource, uint32_t priority) { GetUserDataAs<TestOverlayPrioritizedSurface>(resource)->set_overlay_priority( priority); } } // namespace const struct overlay_prioritized_surface_interface kTestOverlayPrioritizedSurfaceImpl = { DestroyResource, SetOverlayPriority, }; TestOverlayPrioritizedSurface::TestOverlayPrioritizedSurface( wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) { DCHECK(surface_); } TestOverlayPrioritizedSurface::~TestOverlayPrioritizedSurface() { auto* mock_prioritized_surface = GetUserDataAs<MockSurface>(surface_); if (mock_prioritized_surface) mock_prioritized_surface->set_overlay_prioritized_surface(nullptr); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.cc
C++
unknown
1,179
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZED_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZED_SURFACE_H_ #include <overlay-prioritizer-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct overlay_prioritized_surface_interface kTestOverlayPrioritizedSurfaceImpl; class TestOverlayPrioritizedSurface : public ServerObject { public: TestOverlayPrioritizedSurface(wl_resource* resource, wl_resource* surface); ~TestOverlayPrioritizedSurface() override; TestOverlayPrioritizedSurface(const TestOverlayPrioritizedSurface& rhs) = delete; TestOverlayPrioritizedSurface& operator=( const TestOverlayPrioritizedSurface& rhs) = delete; void set_overlay_priority(uint32_t priority) { overlay_priority_ = priority; } uint32_t overlay_priority() { return overlay_priority_; } private: // Surface resource that is the ground for this prioritized surface. raw_ptr<wl_resource> surface_ = nullptr; uint32_t overlay_priority_ = OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_NONE; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZED_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h
C++
unknown
1,415
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_overlay_prioritizer.h" #include <overlay-prioritizer-server-protocol.h> #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h" namespace wl { namespace { constexpr uint32_t kOverlayPriortizerProtocolVersion = 1; void GetOverlayPrioritizedSurface(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface) { auto* mock_surface = GetUserDataAs<MockSurface>(surface); if (mock_surface->prioritized_surface()) { wl_resource_post_error( resource, OVERLAY_PRIORITIZER_ERROR_OVERLAY_HINTED_SURFACE_EXISTS, "overlay_prioritizer exists"); return; } wl_resource* prioritized_surface_resource = CreateResourceWithImpl< ::testing::NiceMock<TestOverlayPrioritizedSurface>>( client, &overlay_prioritized_surface_interface, wl_resource_get_version(resource), &kTestOverlayPrioritizedSurfaceImpl, id, surface); DCHECK(prioritized_surface_resource); mock_surface->set_overlay_prioritized_surface( GetUserDataAs<TestOverlayPrioritizedSurface>( prioritized_surface_resource)); } } // namespace const struct overlay_prioritizer_interface kTestOverlayPrioritizerImpl = { DestroyResource, GetOverlayPrioritizedSurface, }; TestOverlayPrioritizer::TestOverlayPrioritizer() : GlobalObject(&overlay_prioritizer_interface, &kTestOverlayPrioritizerImpl, kOverlayPriortizerProtocolVersion) {} TestOverlayPrioritizer::~TestOverlayPrioritizer() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_overlay_prioritizer.cc
C++
unknown
1,951
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZER_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { // Manage overlay_prioritizer object. class TestOverlayPrioritizer : public GlobalObject { public: TestOverlayPrioritizer(); ~TestOverlayPrioritizer() override; TestOverlayPrioritizer(const TestOverlayPrioritizer& rhs) = delete; TestOverlayPrioritizer& operator=(const TestOverlayPrioritizer& rhs) = delete; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OVERLAY_PRIORITIZER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_overlay_prioritizer.h
C++
unknown
765
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_positioner.h" #include <wayland-server-core.h> namespace wl { namespace { void SetSize(struct wl_client* wl_client, struct wl_resource* resource, int32_t width, int32_t height) { if (width < 1 || height < 1) { wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "width and height must be positive and non-zero"); return; } GetUserDataAs<TestPositioner>(resource)->set_size(gfx::Size(width, height)); } void SetAnchorRect(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { if (width < 1 || height < 1) { wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "width and height must be positive and non-zero"); return; } GetUserDataAs<TestPositioner>(resource)->set_anchor_rect( gfx::Rect(x, y, width, height)); } void SetAnchor(struct wl_client* wl_client, struct wl_resource* resource, uint32_t anchor) { GetUserDataAs<TestPositioner>(resource)->set_anchor(anchor); } void SetGravity(struct wl_client* client, struct wl_resource* resource, uint32_t gravity) { GetUserDataAs<TestPositioner>(resource)->set_gravity(gravity); } void SetConstraintAdjustment(struct wl_client* client, struct wl_resource* resource, uint32_t constraint_adjustment) { GetUserDataAs<TestPositioner>(resource)->set_constraint_adjustment( constraint_adjustment); } } // namespace const struct xdg_positioner_interface kTestXdgPositionerImpl = { &DestroyResource, // destroy &SetSize, // set_size &SetAnchorRect, // set_anchor_rect &SetAnchor, // set_anchor &SetGravity, // set_gravity &SetConstraintAdjustment, // set_constraint_adjustment nullptr, // set_offset }; TestPositioner::TestPositioner(wl_resource* resource) : ServerObject(resource) {} TestPositioner::~TestPositioner() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_positioner.cc
C++
unknown
2,445
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_ #include <utility> #include <xdg-shell-server-protocol.h> #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct xdg_positioner_interface kTestXdgPositionerImpl; extern const struct zxdg_positioner_v6_interface kTestZxdgPositionerV6Impl; // A simple positioner object that provides a collection of rules of a child // surface relative to a parent surface. class TestPositioner : public ServerObject { public: struct PopupPosition { gfx::Rect anchor_rect; gfx::Size size; uint32_t anchor = 0; uint32_t gravity = 0; uint32_t constraint_adjustment = 0; }; explicit TestPositioner(wl_resource* resource); TestPositioner(const TestPositioner&) = delete; TestPositioner& operator=(const TestPositioner&) = delete; ~TestPositioner() override; PopupPosition position() { return std::move(position_); } void set_size(gfx::Size size) { position_.size = size; } void set_anchor_rect(gfx::Rect anchor_rect) { position_.anchor_rect = anchor_rect; } void set_anchor(uint32_t anchor) { position_.anchor = anchor; } void set_gravity(uint32_t gravity) { position_.gravity = gravity; } void set_constraint_adjustment(uint32_t constraint_adjustment) { position_.constraint_adjustment = constraint_adjustment; } private: PopupPosition position_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_positioner.h
C++
unknown
1,769
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_region.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { void Destroy(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } void Add(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<SkRegion>(resource)->op(SkIRect::MakeXYWH(x, y, width, height), SkRegion::kUnion_Op); } static void Subtract(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<SkRegion>(resource)->op(SkIRect::MakeXYWH(x, y, width, height), SkRegion::kDifference_Op); } } // namespace const struct wl_region_interface kTestWlRegionImpl = {Destroy, Add, Subtract}; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_region.cc
C++
unknown
1,201
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_ #include <wayland-server-protocol.h> #include "third_party/skia/include/core/SkRegion.h" namespace wl { extern const struct wl_region_interface kTestWlRegionImpl; using TestRegion = SkRegion; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_region.h
C++
unknown
527
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_seat.h" #include "ui/ozone/platform/wayland/test/mock_pointer.h" #include "ui/ozone/platform/wayland/test/test_keyboard.h" #include "ui/ozone/platform/wayland/test/test_touch.h" namespace wl { namespace { constexpr uint32_t kSeatVersion = 4; void GetPointer(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* pointer_resource = CreateResourceWithImpl<MockPointer>( client, &wl_pointer_interface, wl_resource_get_version(resource), &kMockPointerImpl, id); GetUserDataAs<TestSeat>(resource)->set_pointer( GetUserDataAs<MockPointer>(pointer_resource)); } void GetKeyboard(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* keyboard_resource = CreateResourceWithImpl<TestKeyboard>( client, &wl_keyboard_interface, wl_resource_get_version(resource), &kTestKeyboardImpl, id); GetUserDataAs<TestSeat>(resource)->set_keyboard( GetUserDataAs<TestKeyboard>(keyboard_resource)); } void GetTouch(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* touch_resource = CreateResourceWithImpl<TestTouch>( client, &wl_touch_interface, wl_resource_get_version(resource), &kTestTouchImpl, id); GetUserDataAs<TestSeat>(resource)->set_touch( GetUserDataAs<TestTouch>(touch_resource)); } } // namespace const struct wl_seat_interface kTestSeatImpl = { &GetPointer, // get_pointer &GetKeyboard, // get_keyboard &GetTouch, // get_touch, &DestroyResource, // release }; TestSeat::TestSeat() : GlobalObject(&wl_seat_interface, &kTestSeatImpl, kSeatVersion) {} TestSeat::~TestSeat() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_seat.cc
C++
unknown
1,842
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SEAT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SEAT_H_ #include <wayland-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct wl_seat_interface kTestSeatImpl; class MockPointer; class TestKeyboard; class TestTouch; // Manages a global wl_seat object. // A seat groups keyboard, pointer, and touch devices. This object is // published as a global during start up, or when such a device is hot plugged. // A seat typically has a pointer and maintains a keyboard focus and a pointer // focus. // https://people.freedesktop.org/~whot/wayland-doxygen/wayland/Server/structwl__seat__interface.html class TestSeat : public GlobalObject { public: TestSeat(); TestSeat(const TestSeat&) = delete; TestSeat& operator=(const TestSeat&) = delete; ~TestSeat() override; void set_pointer(MockPointer* pointer) { pointer_ = pointer; } MockPointer* pointer() const { return pointer_; } void set_keyboard(TestKeyboard* keyboard) { keyboard_ = keyboard; } TestKeyboard* keyboard() const { return keyboard_; } void set_touch(TestTouch* touch) { touch_ = touch; } TestTouch* touch() const { return touch_; } private: raw_ptr<MockPointer> pointer_; raw_ptr<TestKeyboard> keyboard_; raw_ptr<TestTouch> touch_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SEAT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_seat.h
C++
unknown
1,592
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" #include <wayland-server-core.h> #include <cstdint> #include <utility> #include <vector> #include "base/check.h" #include "base/files/file_util.h" #include "base/files/scoped_file.h" #include "base/functional/bind.h" #include "base/logging.h" #include "base/notreached.h" #include "base/task/sequenced_task_runner.h" #include "base/task/task_traits.h" #include "base/task/thread_pool.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { std::vector<uint8_t> ReadDataOnWorkerThread(base::ScopedFD fd) { constexpr size_t kChunkSize = 1024; std::vector<uint8_t> bytes; while (true) { uint8_t chunk[kChunkSize]; ssize_t bytes_read = HANDLE_EINTR(read(fd.get(), chunk, kChunkSize)); if (bytes_read > 0) { bytes.insert(bytes.end(), chunk, chunk + bytes_read); continue; } if (bytes_read < 0) { PLOG(ERROR) << "Failed to read data"; bytes.clear(); } break; } return bytes; } void WriteDataOnWorkerThread(base::ScopedFD fd, ui::PlatformClipboard::Data data) { if (!base::WriteFileDescriptor(fd.get(), data->data())) { LOG(ERROR) << "Failed to write selection data to clipboard."; } } } // namespace // TestSelectionOffer implementation. TestSelectionOffer::TestSelectionOffer(wl_resource* resource, std::unique_ptr<Delegate> delegate) : ServerObject(resource), delegate_(std::move(delegate)), task_runner_( base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})) {} TestSelectionOffer::~TestSelectionOffer() = default; void TestSelectionOffer::OnOffer(const std::string& mime_type, ui::PlatformClipboard::Data data) { data_to_offer_[mime_type] = data; delegate_->SendOffer(mime_type); } void TestSelectionOffer::Receive(wl_client* client, wl_resource* resource, const char* mime_type, int fd) { CHECK(GetUserDataAs<TestSelectionOffer>(resource)); auto* self = GetUserDataAs<TestSelectionOffer>(resource); self->task_runner_->PostTask( FROM_HERE, base::BindOnce(&WriteDataOnWorkerThread, base::ScopedFD(fd), self->data_to_offer_[mime_type])); } // TestSelectionSource implementation. TestSelectionSource::TestSelectionSource(wl_resource* resource, std::unique_ptr<Delegate> delegate) : ServerObject(resource), delegate_(std::move(delegate)), task_runner_( base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})) {} TestSelectionSource::~TestSelectionSource() = default; void TestSelectionSource::ReadData(const std::string& mime_type, ReadDataCallback callback) { base::ScopedFD read_fd; base::ScopedFD write_fd; PCHECK(base::CreatePipe(&read_fd, &write_fd)); // 1. Send the SEND event to notify client's DataSource that it's time // to send us the drag data thrhough the write_fd file descriptor. delegate_->SendSend(mime_type, std::move(write_fd)); // 2. Schedule the ReadDataOnWorkerThread task. The result of read // operation will be then passed in to the callback requested by the caller. task_runner_->PostTaskAndReplyWithResult( FROM_HERE, base::BindOnce(&ReadDataOnWorkerThread, std::move(read_fd)), std::move(callback)); } void TestSelectionSource::OnFinished() { delegate_->SendFinished(); mime_types_.clear(); } void TestSelectionSource::OnCancelled() { delegate_->SendCancelled(); mime_types_.clear(); } void TestSelectionSource::OnDndAction(uint32_t action) { delegate_->SendDndAction(action); } void TestSelectionSource::Offer(struct wl_client* client, struct wl_resource* resource, const char* mime_type) { CHECK(GetUserDataAs<TestSelectionSource>(resource)); auto* self = GetUserDataAs<TestSelectionSource>(resource); self->mime_types_.push_back(mime_type); } // TestSelectionDevice implementation. TestSelectionDevice::TestSelectionDevice(wl_resource* resource, std::unique_ptr<Delegate> delegate) : ServerObject(resource), delegate_(std::move(delegate)) {} TestSelectionDevice::~TestSelectionDevice() = default; TestSelectionOffer* TestSelectionDevice::OnDataOffer() { return delegate_->CreateAndSendOffer(); } void TestSelectionDevice::OnSelection(TestSelectionOffer* offer) { delegate_->SendSelection(offer); } void TestSelectionDevice::SetSelection(struct wl_client* client, struct wl_resource* resource, struct wl_resource* source, uint32_t serial) { CHECK(GetUserDataAs<TestSelectionDevice>(resource)); auto* self = GetUserDataAs<TestSelectionDevice>(resource); auto* src = source ? GetUserDataAs<TestSelectionSource>(source) : nullptr; self->selection_serial_ = serial; self->delegate_->HandleSetSelection(src, serial); if (self->manager_) self->manager_->set_source(src); } TestSelectionDeviceManager::TestSelectionDeviceManager( const InterfaceInfo& info, std::unique_ptr<Delegate> delegate) : GlobalObject(info.interface, info.implementation, info.version), delegate_(std::move(delegate)) {} TestSelectionDeviceManager::~TestSelectionDeviceManager() = default; void TestSelectionDeviceManager::CreateSource(wl_client* client, wl_resource* manager_resource, uint32_t id) { CHECK(GetUserDataAs<TestSelectionDeviceManager>(manager_resource)); auto* manager = GetUserDataAs<TestSelectionDeviceManager>(manager_resource); manager->delegate_->CreateSource(client, id); } void TestSelectionDeviceManager::GetDevice(wl_client* client, wl_resource* manager_resource, uint32_t id, wl_resource* seat_resource) { CHECK(GetUserDataAs<TestSelectionDeviceManager>(manager_resource)); auto* manager = GetUserDataAs<TestSelectionDeviceManager>(manager_resource); auto* new_device = manager->delegate_->CreateDevice(client, id); new_device->set_manager(manager); manager->device_ = new_device; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_selection_device_manager.cc
C++
unknown
6,713
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_ #include <cstdint> #include <memory> #include <string> #include <vector> #include "base/files/scoped_file.h" #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr_exclusion.h" #include "base/memory/scoped_refptr.h" #include "base/threading/thread.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/public/platform_clipboard.h" namespace base { class SequencedTaskRunner; } namespace wl { class TestSelectionSource; class TestSelectionDevice; // Base classes for data device implementations. Protocol specific derived // classes must bind request handlers and factory methods for data device and // source instances. E.g: Standard data device (wl_data_*), as well as zwp and // gtk primary selection protocols. class TestSelectionDeviceManager : public GlobalObject { public: struct Delegate { virtual ~Delegate() = default; virtual TestSelectionDevice* CreateDevice(wl_client* client, uint32_t id) = 0; virtual TestSelectionSource* CreateSource(wl_client* client, uint32_t id) = 0; }; struct InterfaceInfo { // This field is not a raw_ptr<> because it was filtered by the rewriter // for: #global-scope RAW_PTR_EXCLUSION const struct wl_interface* interface; // This field is not a raw_ptr<> because it was filtered by the rewriter // for: #global-scope RAW_PTR_EXCLUSION const void* implementation; uint32_t version; }; TestSelectionDeviceManager(const InterfaceInfo& info, std::unique_ptr<Delegate> delegate); ~TestSelectionDeviceManager() override; TestSelectionDeviceManager(const TestSelectionDeviceManager&) = delete; TestSelectionDeviceManager& operator=(const TestSelectionDeviceManager&) = delete; TestSelectionDevice* device() { return device_; } TestSelectionSource* source() { return source_; } void set_source(TestSelectionSource* source) { source_ = source; } // Protocol object requests: static void CreateSource(wl_client* client, wl_resource* manager_resource, uint32_t id); static void GetDevice(wl_client* client, wl_resource* manager_resource, uint32_t id, wl_resource* seat_resource); private: const std::unique_ptr<Delegate> delegate_; raw_ptr<TestSelectionDevice> device_ = nullptr; raw_ptr<TestSelectionSource> source_ = nullptr; }; class TestSelectionOffer : public ServerObject { public: struct Delegate { virtual ~Delegate() = default; virtual void SendOffer(const std::string& mime_type) = 0; }; TestSelectionOffer(wl_resource* resource, std::unique_ptr<Delegate> delegate); ~TestSelectionOffer() override; TestSelectionOffer(const TestSelectionOffer&) = delete; TestSelectionOffer& operator=(const TestSelectionOffer&) = delete; void OnOffer(const std::string& mime_type, ui::PlatformClipboard::Data data); // Protocol object requests: static void Receive(wl_client* client, wl_resource* resource, const char* mime_type, int fd); private: const std::unique_ptr<Delegate> delegate_; const scoped_refptr<base::SequencedTaskRunner> task_runner_; ui::PlatformClipboard::DataMap data_to_offer_; }; class TestSelectionSource : public ServerObject { public: struct Delegate { virtual ~Delegate() = default; virtual void SendSend(const std::string& mime_type, base::ScopedFD write_fd) = 0; virtual void SendFinished() = 0; virtual void SendCancelled() = 0; virtual void SendDndAction(uint32_t action) = 0; }; TestSelectionSource(wl_resource* resource, std::unique_ptr<Delegate> delegate); ~TestSelectionSource() override; using ReadDataCallback = base::OnceCallback<void(std::vector<uint8_t>&&)>; void ReadData(const std::string& mime_type, ReadDataCallback callback); void OnFinished(); void OnCancelled(); void OnDndAction(uint32_t action); const std::vector<std::string>& mime_types() const { return mime_types_; } // Protocol object requests: static void Offer(struct wl_client* client, struct wl_resource* resource, const char* mime_type); private: const std::unique_ptr<Delegate> delegate_; std::vector<std::string> mime_types_; const scoped_refptr<base::SequencedTaskRunner> task_runner_; }; class TestSelectionDevice : public ServerObject { public: struct Delegate { virtual ~Delegate() = default; virtual TestSelectionOffer* CreateAndSendOffer() = 0; virtual void SendSelection(TestSelectionOffer* offer) = 0; virtual void HandleSetSelection(TestSelectionSource* source, uint32_t serial) = 0; }; TestSelectionDevice(wl_resource* resource, std::unique_ptr<Delegate> delegate); ~TestSelectionDevice() override; TestSelectionDevice(const TestSelectionDevice&) = delete; TestSelectionDevice& operator=(const TestSelectionDevice&) = delete; TestSelectionOffer* OnDataOffer(); void OnSelection(TestSelectionOffer* offer); void set_manager(TestSelectionDeviceManager* manager) { manager_ = manager; } // Protocol object requests: static void SetSelection(struct wl_client* client, struct wl_resource* resource, struct wl_resource* source, uint32_t serial); uint32_t selection_serial() const { return selection_serial_; } private: const std::unique_ptr<Delegate> delegate_; uint32_t selection_serial_ = 0; raw_ptr<TestSelectionDeviceManager> manager_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_selection_device_manager.h
C++
unknown
6,309
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_subcompositor.h" #include <wayland-server-core.h> #include "base/check.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_subsurface.h" namespace wl { namespace { constexpr uint32_t kSubCompositorVersion = 1; void GetSubsurface(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface, struct wl_resource* parent) { auto* mock_surface = GetUserDataAs<MockSurface>(surface); auto* parent_surface = GetUserDataAs<MockSurface>(parent); if (mock_surface->has_role() || !parent_surface) { wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "invalid surface"); return; } wl_resource* subsurface_resource = CreateResourceWithImpl<::testing::NiceMock<TestSubSurface>>( client, &wl_subsurface_interface, wl_resource_get_version(resource), &kTestSubSurfaceImpl, id, surface, parent); DCHECK(subsurface_resource); mock_surface->set_sub_surface( GetUserDataAs<TestSubSurface>(subsurface_resource)); } } // namespace const struct wl_subcompositor_interface kTestSubCompositorImpl = { DestroyResource, GetSubsurface, }; TestSubCompositor::TestSubCompositor() : GlobalObject(&wl_subcompositor_interface, &kTestSubCompositorImpl, kSubCompositorVersion) {} TestSubCompositor::~TestSubCompositor() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_subcompositor.cc
C++
unknown
1,783
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBCOMPOSITOR_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBCOMPOSITOR_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { // Manage wl_compositor object. class TestSubCompositor : public GlobalObject { public: TestSubCompositor(); ~TestSubCompositor() override; TestSubCompositor(const TestSubCompositor& rhs) = delete; TestSubCompositor& operator=(const TestSubCompositor& rhs) = delete; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBCOMPOSITOR_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_subcompositor.h
C++
unknown
706
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/test_augmented_subsurface.h" namespace wl { namespace { void SetPosition(wl_client* client, wl_resource* resource, int32_t x, int32_t y) { GetUserDataAs<TestSubSurface>(resource)->SetPositionImpl(x, y); } void PlaceAbove(wl_client* client, wl_resource* resource, wl_resource* reference_resource) { GetUserDataAs<TestSubSurface>(resource)->PlaceAbove(reference_resource); } void PlaceBelow(wl_client* client, wl_resource* resource, wl_resource* sibling_resource) { GetUserDataAs<TestSubSurface>(resource)->PlaceBelow(sibling_resource); } void SetSync(wl_client* client, wl_resource* resource) { GetUserDataAs<TestSubSurface>(resource)->set_sync(true); } void SetDesync(wl_client* client, wl_resource* resource) { GetUserDataAs<TestSubSurface>(resource)->set_sync(false); } } // namespace const struct wl_subsurface_interface kTestSubSurfaceImpl = { DestroyResource, SetPosition, PlaceAbove, PlaceBelow, SetSync, SetDesync, }; TestSubSurface::TestSubSurface(wl_resource* resource, wl_resource* surface, wl_resource* parent_resource) : ServerObject(resource), surface_(surface), parent_resource_(parent_resource) { DCHECK(surface_); } TestSubSurface::~TestSubSurface() { auto* mock_surface = GetUserDataAs<MockSurface>(surface_); if (mock_surface) mock_surface->set_sub_surface(nullptr); if (augmented_subsurface_ && augmented_subsurface_->resource()) wl_resource_destroy(augmented_subsurface_->resource()); } void TestSubSurface::SetPositionImpl(float x, float y) { position_ = gfx::PointF(x, y); SetPosition(x, y); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_subsurface.cc
C++
unknown
2,048
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBSURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBSURFACE_H_ #include <wayland-server-protocol.h> #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/geometry/point_f.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { class TestAugmentedSubSurface; extern const struct wl_subsurface_interface kTestSubSurfaceImpl; class TestSubSurface : public ServerObject { public: explicit TestSubSurface(wl_resource* resource, wl_resource* surface, wl_resource* parent_resource); ~TestSubSurface() override; TestSubSurface(const TestSubSurface& rhs) = delete; TestSubSurface& operator=(const TestSubSurface& rhs) = delete; MOCK_METHOD1(PlaceAbove, void(wl_resource* reference_resource)); MOCK_METHOD1(PlaceBelow, void(wl_resource* sibling_resource)); MOCK_METHOD2(SetPosition, void(float x, float y)); void SetPositionImpl(float x, float y); gfx::PointF position() const { return position_; } void set_sync(bool sync) { sync_ = sync; } bool sync() const { return sync_; } wl_resource* parent_resource() const { return parent_resource_; } void set_augmented_subsurface(TestAugmentedSubSurface* augmented_subsurface) { augmented_subsurface_ = augmented_subsurface; } TestAugmentedSubSurface* augmented_subsurface() const { return augmented_subsurface_; } private: gfx::PointF position_; bool sync_ = false; // Surface resource that is the ground for this subsurface. raw_ptr<wl_resource> surface_ = nullptr; // Parent surface resource. raw_ptr<wl_resource> parent_resource_ = nullptr; raw_ptr<TestAugmentedSubSurface> augmented_subsurface_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SUBSURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_subsurface.h
C++
unknown
2,034
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_surface_augmenter.h" #include <surface-augmenter-server-protocol.h> #include "base/files/scoped_file.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_augmented_subsurface.h" #include "ui/ozone/platform/wayland/test/test_augmented_surface.h" #include "ui/ozone/platform/wayland/test/test_buffer.h" namespace wl { namespace { constexpr uint32_t kSurfaceAugmenterProtocolVersion = 2; void CreateSolidColorBuffer(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_array* color, int32_t width, int32_t height) { std::vector<base::ScopedFD> fds; CreateResourceWithImpl<::testing::NiceMock<TestBuffer>>( client, &wl_buffer_interface, wl_resource_get_version(resource), &kTestWlBufferImpl, id, std::move(fds)); } void GetGetAugmentedSurface(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface) { auto* mock_surface = GetUserDataAs<MockSurface>(surface); if (mock_surface->augmented_surface()) { wl_resource_post_error(resource, SURFACE_AUGMENTER_ERROR_AUGMENTED_SURFACE_EXISTS, "surface_augmenter exists"); return; } wl_resource* augmented_surface_resource = CreateResourceWithImpl<::testing::NiceMock<TestAugmentedSurface>>( client, &augmented_surface_interface, wl_resource_get_version(resource), &kTestAugmentedSurfaceImpl, id, surface); DCHECK(augmented_surface_resource); mock_surface->set_augmented_surface( GetUserDataAs<TestAugmentedSurface>(augmented_surface_resource)); } void GetAugmentedSubsurface(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* subsurface) { auto* test_subsurface = GetUserDataAs<TestSubSurface>(subsurface); if (test_subsurface->augmented_subsurface()) { wl_resource_post_error(resource, SURFACE_AUGMENTER_ERROR_AUGMENTED_SURFACE_EXISTS, "augmented_subsurface exists"); return; } wl_resource* augmented_subsurface_resource = CreateResourceWithImpl<::testing::NiceMock<TestAugmentedSubSurface>>( client, &augmented_sub_surface_interface, wl_resource_get_version(resource), &kTestAugmentedSubSurfaceImpl, id, subsurface); DCHECK(augmented_subsurface_resource); test_subsurface->set_augmented_subsurface( GetUserDataAs<TestAugmentedSubSurface>(augmented_subsurface_resource)); } } // namespace const struct surface_augmenter_interface kTestSurfaceAugmenterImpl = { DestroyResource, CreateSolidColorBuffer, GetGetAugmentedSurface, GetAugmentedSubsurface, }; TestSurfaceAugmenter::TestSurfaceAugmenter() : GlobalObject(&surface_augmenter_interface, &kTestSurfaceAugmenterImpl, kSurfaceAugmenterProtocolVersion) {} TestSurfaceAugmenter::~TestSurfaceAugmenter() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_surface_augmenter.cc
C++
unknown
3,586
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SURFACE_AUGMENTER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SURFACE_AUGMENTER_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { // Manage surface_augmenter object. class TestSurfaceAugmenter : public GlobalObject { public: TestSurfaceAugmenter(); ~TestSurfaceAugmenter() override; TestSurfaceAugmenter(const TestSurfaceAugmenter& rhs) = delete; TestSurfaceAugmenter& operator=(const TestSurfaceAugmenter& rhs) = delete; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SURFACE_AUGMENTER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_surface_augmenter.h
C++
unknown
743
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_touch.h" namespace wl { const struct wl_pointer_interface kTestTouchImpl = { nullptr, // set_cursor &DestroyResource, // release }; TestTouch::TestTouch(wl_resource* resource) : ServerObject(resource) {} TestTouch::~TestTouch() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_touch.cc
C++
unknown
472
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_TOUCH_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_TOUCH_H_ #include <wayland-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct wl_pointer_interface kTestTouchImpl; class TestZcrTouchStylus; class TestTouch : public ServerObject { public: explicit TestTouch(wl_resource* resource); TestTouch(const TestTouch&) = delete; TestTouch& operator=(const TestTouch&) = delete; ~TestTouch() override; void set_touch_stylus(TestZcrTouchStylus* touch_stylus) { touch_stylus_ = touch_stylus; } TestZcrTouchStylus* touch_stylus() const { return touch_stylus_; } private: raw_ptr<TestZcrTouchStylus> touch_stylus_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_TOUCH_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_touch.h
C++
unknown
1,029
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_util.h" #include <wayland-client-protocol.h> #include "base/run_loop.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace wl { void SyncDisplay(wl_display* display_proxy, wl_display& display) { base::RunLoop run_loop; wl::Object<wl_callback> sync_callback( wl_display_sync(display_proxy ? display_proxy : &display)); wl_callback_listener listener = { [](void* data, struct wl_callback* cb, uint32_t time) { static_cast<base::RunLoop*>(data)->Quit(); }}; wl_callback_add_listener(sync_callback.get(), &listener, &run_loop); wl_display_flush(&display); run_loop.Run(); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_util.cc
C++
unknown
842
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_UTIL_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_UTIL_H_ struct wl_display; namespace wl { // Sets up a sync callback via wl_display.sync and waits until it's received. // Requests are handled in-order and events are delivered in-order, thus sync // is used as a barrier to ensure all previous requests and the resulting // events have been handled. A client may choose whether it uses a proxy wrapper // or an original display object to create a sync object. If |display_proxy| is // null, a callback is created for the original display object. In other words, // a default event queue is used. void SyncDisplay(wl_display* display_proxy, wl_display& display); } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_UTIL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_util.h
C++
unknown
932
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_viewport.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" namespace wl { namespace { void SetSource(wl_client* client, wl_resource* resource, wl_fixed_t x, wl_fixed_t y, wl_fixed_t width, wl_fixed_t height) { auto* test_vp = GetUserDataAs<TestViewport>(resource); DCHECK(test_vp); test_vp->SetSource(wl_fixed_to_double(x), wl_fixed_to_double(y), wl_fixed_to_double(width), wl_fixed_to_double(height)); } void SetDestination(wl_client* client, wl_resource* resource, int32_t width, int32_t height) { auto* test_vp = GetUserDataAs<TestViewport>(resource); DCHECK(test_vp); test_vp->SetDestinationImpl(width, height); } } // namespace const struct wp_viewport_interface kTestViewportImpl = { DestroyResource, SetSource, SetDestination, }; TestViewport::TestViewport(wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) { DCHECK(surface_); } TestViewport::~TestViewport() { auto* mock_surface = GetUserDataAs<MockSurface>(surface_); if (mock_surface) mock_surface->set_viewport(nullptr); } void TestViewport::SetDestinationImpl(float width, float height) { destination_size_ = gfx::SizeF(width, height); SetDestination(width, height); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_viewport.cc
C++
unknown
1,628
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORT_H_ #include <viewporter-server-protocol.h> #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/geometry/size_f.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct wp_viewport_interface kTestViewportImpl; class TestViewport : public ServerObject { public: explicit TestViewport(wl_resource* resource, wl_resource* surface); ~TestViewport() override; TestViewport(const TestViewport& rhs) = delete; TestViewport& operator=(const TestViewport& rhs) = delete; MOCK_METHOD2(SetDestination, void(float x, float y)); MOCK_METHOD4(SetSource, void(float x, float y, float width, float height)); gfx::SizeF destination_size() const { return destination_size_; } void SetDestinationImpl(float x, float y); private: // Surface resource that is the ground for this Viewport. raw_ptr<wl_resource> surface_ = nullptr; gfx::SizeF destination_size_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_viewport.h
C++
unknown
1,312
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_viewporter.h" #include <viewporter-server-protocol.h> #include <wayland-server-core.h> #include "base/check.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/test_viewport.h" namespace wl { namespace { constexpr uint32_t kViewporterVersion = 1; void GetViewport(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface) { auto* mock_surface = GetUserDataAs<MockSurface>(surface); if (mock_surface->viewport()) { wl_resource_post_error(resource, WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, "viewport exists"); return; } wl_resource* viewport_resource = CreateResourceWithImpl<::testing::NiceMock<TestViewport>>( client, &wp_viewport_interface, wl_resource_get_version(resource), &kTestViewportImpl, id, surface); DCHECK(viewport_resource); mock_surface->set_viewport(GetUserDataAs<TestViewport>(viewport_resource)); } } // namespace const struct wp_viewporter_interface kTestViewporterImpl = { DestroyResource, GetViewport, }; TestViewporter::TestViewporter() : GlobalObject(&wp_viewporter_interface, &kTestViewporterImpl, kViewporterVersion) {} TestViewporter::~TestViewporter() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_viewporter.cc
C++
unknown
1,570
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORTER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORTER_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { // Manage wl_viewporter object. class TestViewporter : public GlobalObject { public: TestViewporter(); ~TestViewporter() override; TestViewporter(const TestViewporter& rhs) = delete; TestViewporter& operator=(const TestViewporter& rhs) = delete; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_VIEWPORTER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_viewporter.h
C++
unknown
676
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include <sys/socket.h> #include <wayland-server.h> #include <cstdlib> #include <memory> #include <utility> #include "base/files/file_util.h" #include "base/files/scoped_file.h" #include "base/functional/bind.h" #include "base/functional/callback_forward.h" #include "base/functional/callback_helpers.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/test/bind.h" #include "ui/ozone/platform/wayland/test/test_gtk_primary_selection.h" #include "ui/ozone/platform/wayland/test/test_zcr_text_input_extension.h" #include "ui/ozone/platform/wayland/test/test_zwp_primary_selection.h" namespace wl { namespace { void handle_client_destroyed(struct wl_listener* listener, void* data) { TestServerListener* destroy_listener = wl_container_of(listener, /*sample=*/destroy_listener, /*member=*/listener); DCHECK(destroy_listener); destroy_listener->test_server->OnClientDestroyed( static_cast<struct wl_client*>(data)); } } // namespace void DisplayDeleter::operator()(wl_display* display) { wl_display_destroy(display); } TestWaylandServerThread::TestWaylandServerThread() : TestWaylandServerThread(ServerConfig{}) {} TestWaylandServerThread::TestWaylandServerThread(const ServerConfig& config) : Thread("test_wayland_server"), client_destroy_listener_(this), config_(config), compositor_(config.compositor_version), output_(base::BindRepeating( &TestWaylandServerThread::OnTestOutputMetricsFlush, base::Unretained(this))), zcr_text_input_extension_v1_(config.text_input_extension_version), controller_(FROM_HERE) { DETACH_FROM_THREAD(thread_checker_); } TestWaylandServerThread::~TestWaylandServerThread() { // Stop watching the descriptor here to guarantee that no new events // will come during or after the destruction of the display. This must be // done on the correct thread to avoid data races. auto stop_controller_on_server_thread = [](wl::TestWaylandServerThread* server) { server->controller_.StopWatchingFileDescriptor(); }; RunAndWait( base::BindLambdaForTesting(std::move(stop_controller_on_server_thread))); Stop(); if (protocol_logger_) wl_protocol_logger_destroy(protocol_logger_); protocol_logger_ = nullptr; // Check if the client has been destroyed after the thread is stopped. This // most probably will happen if the real client has closed its fd resulting // in a closed socket. The server's event loop will then see that and destroy // the client automatically. This may or may not happen - depends on whether // the events will be processed after the real client closes its end or not. if (client_) wl_client_destroy(client_); client_ = nullptr; } bool TestWaylandServerThread::Start() { display_.reset(wl_display_create()); if (!display_) return false; event_loop_ = wl_display_get_event_loop(display_.get()); int fd[2]; if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) return false; base::ScopedFD server_fd(fd[0]); base::ScopedFD client_fd(fd[1]); if (wl_display_init_shm(display_.get()) < 0) return false; if (!compositor_.Initialize(display_.get())) { return false; } if (!sub_compositor_.Initialize(display_.get())) return false; if (!viewporter_.Initialize(display_.get())) return false; if (!alpha_compositing_.Initialize(display_.get())) return false; if (config_.enable_aura_shell == EnableAuraShellProtocol::kEnabled) { if (config_.use_aura_output_manager) { // zaura_output_manager should be initialized before any wl_output // globals. if (!zaura_output_manager_.Initialize(display_.get())) { return false; } } else { if (!zxdg_output_manager_.Initialize(display_.get())) { return false; } } output_.set_aura_shell_enabled(); if (!zaura_shell_.Initialize(display_.get())) { return false; } } if (!output_.Initialize(display_.get())) return false; if (!data_device_manager_.Initialize(display_.get())) return false; if (!SetupPrimarySelectionManager(config_.primary_selection_protocol)) { return false; } if (!seat_.Initialize(display_.get())) return false; if (!xdg_shell_.Initialize(display_.get())) return false; if (!zcr_stylus_.Initialize(display_.get())) return false; if (!zcr_text_input_extension_v1_.Initialize(display_.get())) { return false; } if (!zwp_text_input_manager_v1_.Initialize(display_.get())) return false; if (!SetupExplicitSynchronizationProtocol( config_.use_explicit_synchronization)) { return false; } if (!zwp_linux_dmabuf_v1_.Initialize(display_.get())) return false; if (!overlay_prioritizer_.Initialize(display_.get())) return false; if (!wp_pointer_gestures_.Initialize(display_.get())) return false; if (!zcr_color_manager_v1_.Initialize(display_.get())) { return false; } if (!xdg_activation_v1_.Initialize(display_.get())) { return false; } client_ = wl_client_create(display_.get(), server_fd.release()); if (!client_) return false; client_destroy_listener_.listener.notify = handle_client_destroyed; wl_client_add_destroy_listener(client_, &client_destroy_listener_.listener); protocol_logger_ = wl_display_add_protocol_logger( display_.get(), TestWaylandServerThread::ProtocolLogger, this); base::Thread::Options options; options.message_pump_factory = base::BindRepeating( &TestWaylandServerThread::CreateMessagePump, base::Unretained(this)); if (!base::Thread::StartWithOptions(std::move(options))) return false; setenv("WAYLAND_SOCKET", base::NumberToString(client_fd.release()).c_str(), 1); return true; } void TestWaylandServerThread::RunAndWait( base::OnceCallback<void(TestWaylandServerThread*)> callback) { base::OnceClosure closure = base::BindOnce(std::move(callback), base::Unretained(this)); RunAndWait(std::move(closure)); } void TestWaylandServerThread::RunAndWait(base::OnceClosure closure) { // Allow nestable tasks for dnd tests. base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); task_runner()->PostTaskAndReply( FROM_HERE, base::BindOnce(&TestWaylandServerThread::DoRun, base::Unretained(this), std::move(closure)), run_loop.QuitClosure()); run_loop.Run(); } MockWpPresentation* TestWaylandServerThread::EnsureAndGetWpPresentation() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); if (wp_presentation_.resource()) return &wp_presentation_; if (wp_presentation_.Initialize(display_.get())) return &wp_presentation_; return nullptr; } TestSurfaceAugmenter* TestWaylandServerThread::EnsureSurfaceAugmenter() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); if (surface_augmenter_.Initialize(display_.get())) return &surface_augmenter_; return nullptr; } void TestWaylandServerThread::OnTestOutputMetricsFlush( wl_resource* output_resource, const TestOutputMetrics& metrics) { if (zaura_output_manager_.resource()) { zaura_output_manager_.SendOutputMetrics(output_resource, metrics); } } void TestWaylandServerThread::OnClientDestroyed(wl_client* client) { if (!client_) return; DCHECK_EQ(client_, client); client_ = nullptr; } uint32_t TestWaylandServerThread::GetNextSerial() const { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); return wl_display_next_serial(display_.get()); } uint32_t TestWaylandServerThread::GetNextTime() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); static uint32_t timestamp = 0; return ++timestamp; } bool TestWaylandServerThread::SetupPrimarySelectionManager( PrimarySelectionProtocol protocol) { switch (protocol) { case PrimarySelectionProtocol::kNone: return true; case PrimarySelectionProtocol::kZwp: primary_selection_device_manager_ = CreateTestSelectionManagerZwp(); break; case PrimarySelectionProtocol::kGtk: primary_selection_device_manager_ = CreateTestSelectionManagerGtk(); break; } return primary_selection_device_manager_->Initialize(display_.get()); } bool TestWaylandServerThread::SetupExplicitSynchronizationProtocol( ShouldUseExplicitSynchronizationProtocol usage) { switch (usage) { case ShouldUseExplicitSynchronizationProtocol::kNone: return true; case ShouldUseExplicitSynchronizationProtocol::kUse: return zwp_linux_explicit_synchronization_v1_.Initialize(display_.get()); } NOTREACHED(); return false; } std::unique_ptr<base::MessagePump> TestWaylandServerThread::CreateMessagePump() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); auto pump = std::make_unique<base::MessagePumpLibevent>(); pump->WatchFileDescriptor(wl_event_loop_get_fd(event_loop_), true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); return std::move(pump); } void TestWaylandServerThread::DoRun(base::OnceClosure closure) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); std::move(closure).Run(); wl_display_flush_clients(display_.get()); } void TestWaylandServerThread::OnFileCanReadWithoutBlocking(int fd) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); wl_event_loop_dispatch(event_loop_, 0); if (display_) wl_display_flush_clients(display_.get()); } void TestWaylandServerThread::OnFileCanWriteWithoutBlocking(int fd) {} // static void TestWaylandServerThread::ProtocolLogger( void* user_data, enum wl_protocol_logger_type direction, const struct wl_protocol_logger_message* message) { auto* test_server = static_cast<TestWaylandServerThread*>(user_data); DCHECK(test_server); // All the protocol calls must be made on the correct thread. DCHECK_CALLED_ON_VALID_THREAD(test_server->thread_checker_); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_server_thread.cc
C++
unknown
10,176
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_SERVER_THREAD_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_SERVER_THREAD_H_ #include <wayland-server-core.h> #include <cstdint> #include <memory> #include <vector> #include "base/memory/raw_ptr.h" #include "base/message_loop/message_pump_libevent.h" #include "base/threading/thread.h" #include "base/threading/thread_checker.h" #include "ui/display/types/display_constants.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/test/mock_wp_presentation.h" #include "ui/ozone/platform/wayland/test/mock_xdg_activation_v1.h" #include "ui/ozone/platform/wayland/test/mock_xdg_shell.h" #include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h" #include "ui/ozone/platform/wayland/test/test_alpha_compositing.h" #include "ui/ozone/platform/wayland/test/test_compositor.h" #include "ui/ozone/platform/wayland/test/test_data_device_manager.h" #include "ui/ozone/platform/wayland/test/test_output.h" #include "ui/ozone/platform/wayland/test/test_overlay_prioritizer.h" #include "ui/ozone/platform/wayland/test/test_seat.h" #include "ui/ozone/platform/wayland/test/test_subcompositor.h" #include "ui/ozone/platform/wayland/test/test_surface_augmenter.h" #include "ui/ozone/platform/wayland/test/test_viewporter.h" #include "ui/ozone/platform/wayland/test/test_wp_pointer_gestures.h" #include "ui/ozone/platform/wayland/test/test_zaura_output_manager.h" #include "ui/ozone/platform/wayland/test/test_zaura_shell.h" #include "ui/ozone/platform/wayland/test/test_zcr_stylus.h" #include "ui/ozone/platform/wayland/test/test_zcr_text_input_extension.h" #include "ui/ozone/platform/wayland/test/test_zwp_linux_explicit_synchronization.h" #include "ui/ozone/platform/wayland/test/test_zwp_text_input_manager.h" #include "ui/ozone/platform/wayland/test/test_zxdg_output_manager.h" struct wl_client; struct wl_display; struct wl_event_loop; struct wl_resource; namespace wl { struct DisplayDeleter { void operator()(wl_display* display); }; // Server configuration related enums and structs. enum class PrimarySelectionProtocol { kNone, kGtk, kZwp }; enum class ShouldUseExplicitSynchronizationProtocol { kNone, kUse }; enum class EnableAuraShellProtocol { kEnabled, kDisabled }; struct ServerConfig { TestZcrTextInputExtensionV1::Version text_input_extension_version = TestZcrTextInputExtensionV1::Version::kV8; TestCompositor::Version compositor_version = TestCompositor::Version::kV4; PrimarySelectionProtocol primary_selection_protocol = PrimarySelectionProtocol::kNone; ShouldUseExplicitSynchronizationProtocol use_explicit_synchronization = ShouldUseExplicitSynchronizationProtocol::kUse; EnableAuraShellProtocol enable_aura_shell = EnableAuraShellProtocol::kDisabled; bool surface_submission_in_pixel_coordinates = true; bool supports_viewporter_surface_scaling = false; bool use_aura_output_manager = false; }; class TestWaylandServerThread; // A custom listener that holds wl_listener and the pointer to a test_server. struct TestServerListener { public: explicit TestServerListener(TestWaylandServerThread* server) : test_server(server) {} wl_listener listener; const raw_ptr<TestWaylandServerThread> test_server; }; class TestSelectionDeviceManager; class TestWaylandServerThread : public base::Thread, base::MessagePumpLibevent::FdWatcher { public: class OutputDelegate; TestWaylandServerThread(); explicit TestWaylandServerThread(const ServerConfig& config); TestWaylandServerThread(const TestWaylandServerThread&) = delete; TestWaylandServerThread& operator=(const TestWaylandServerThread&) = delete; ~TestWaylandServerThread() override; // Starts the test Wayland server thread. If this succeeds, the WAYLAND_SOCKET // environment variable will be set to the string representation of a file // descriptor that a client can connect to. The caller is responsible for // ensuring that this file descriptor gets closed (for example, by calling // wl_display_connect). bool Start(); // Runs 'callback' or 'closure' on the server thread; blocks until the // callable is run and all pending Wayland requests and events are delivered. void RunAndWait(base::OnceCallback<void(TestWaylandServerThread*)> callback); void RunAndWait(base::OnceClosure closure); // Returns WpPresentation. If it hasn't been initialized yet, initializes that // first and then returns. MockWpPresentation* EnsureAndGetWpPresentation(); // Initializes and returns SurfaceAugmenter. TestSurfaceAugmenter* EnsureSurfaceAugmenter(); template <typename T> T* GetObject(uint32_t id) { // All the protocol calls must be made on the correct thread. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); wl_resource* resource = wl_client_get_object(client_, id); return resource ? T::FromResource(resource) : nullptr; } TestOutput* CreateAndInitializeOutput(TestOutputMetrics metrics = {}) { auto output = std::make_unique<TestOutput>( base::BindRepeating(&TestWaylandServerThread::OnTestOutputMetricsFlush, base::Unretained(this)), std::move(metrics)); if (output_.aura_shell_enabled()) { output->set_aura_shell_enabled(); } output->Initialize(display()); TestOutput* output_ptr = output.get(); globals_.push_back(std::move(output)); return output_ptr; } // Called when the Flush() is called for a TestOutput associated with // `output_resource`. When called sends the corresponding events for the // `metrics` to clients of the zaura_output_manager. void OnTestOutputMetricsFlush(wl_resource* output_resource, const TestOutputMetrics& metrics); TestDataDeviceManager* data_device_manager() { return &data_device_manager_; } TestSeat* seat() { return &seat_; } MockXdgShell* xdg_shell() { return &xdg_shell_; } TestZAuraOutputManager* zaura_output_manager() { return &zaura_output_manager_; } TestZAuraShell* zaura_shell() { return &zaura_shell_; } TestOutput* output() { return &output_; } TestZcrTextInputExtensionV1* text_input_extension_v1() { return &zcr_text_input_extension_v1_; } TestZwpTextInputManagerV1* text_input_manager_v1() { return &zwp_text_input_manager_v1_; } TestZwpLinuxExplicitSynchronizationV1* zwp_linux_explicit_synchronization_v1() { return &zwp_linux_explicit_synchronization_v1_; } MockZwpLinuxDmabufV1* zwp_linux_dmabuf_v1() { return &zwp_linux_dmabuf_v1_; } wl_display* display() const { return display_.get(); } TestSelectionDeviceManager* primary_selection_device_manager() { return primary_selection_device_manager_.get(); } TestWpPointerGestures& wp_pointer_gestures() { return wp_pointer_gestures_; } MockZcrColorManagerV1* zcr_color_manager_v1() { return &zcr_color_manager_v1_; } MockXdgActivationV1* xdg_activation_v1() { return &xdg_activation_v1_; } void set_output_delegate(OutputDelegate* delegate) { output_delegate_ = delegate; } wl_client* client() const { return client_; } void OnClientDestroyed(wl_client* client); // Returns next available serial. Must be called on the server thread. uint32_t GetNextSerial() const; // Returns next available timestamp. Suitable for events sent from the server // the client. Must be called on the server thread. uint32_t GetNextTime(); private: void SetupOutputs(); bool SetupPrimarySelectionManager(PrimarySelectionProtocol protocol); bool SetupExplicitSynchronizationProtocol( ShouldUseExplicitSynchronizationProtocol usage); std::unique_ptr<base::MessagePump> CreateMessagePump(); // Executes the closure and flushes the server event queue. Must be run on // server's thread. void DoRun(base::OnceClosure closure); // base::MessagePumpLibevent::FdWatcher void OnFileCanReadWithoutBlocking(int fd) override; void OnFileCanWriteWithoutBlocking(int fd) override; // wl_protocol_logger. Whenever there is a call to a protocol from the server // side, the logger is invoked. This is handy as we can use this to verify all // the protocol calls happen only when the server thread is not running. This // helps to avoid thread races as the client runs on a different from the // server tread. static void ProtocolLogger(void* user_data, enum wl_protocol_logger_type direction, const struct wl_protocol_logger_message* message); std::unique_ptr<wl_display, DisplayDeleter> display_; TestServerListener client_destroy_listener_; raw_ptr<wl_client> client_ = nullptr; raw_ptr<wl_event_loop> event_loop_ = nullptr; raw_ptr<wl_protocol_logger> protocol_logger_ = nullptr; ServerConfig config_; // Represent Wayland global objects TestCompositor compositor_; TestSubCompositor sub_compositor_; TestViewporter viewporter_; TestAlphaCompositing alpha_compositing_; TestDataDeviceManager data_device_manager_; TestOutput output_; TestOverlayPrioritizer overlay_prioritizer_; TestSurfaceAugmenter surface_augmenter_; TestSeat seat_; TestZXdgOutputManager zxdg_output_manager_; MockXdgShell xdg_shell_; TestZAuraOutputManager zaura_output_manager_; TestZAuraShell zaura_shell_; MockZcrColorManagerV1 zcr_color_manager_v1_; TestZcrStylus zcr_stylus_; TestZcrTextInputExtensionV1 zcr_text_input_extension_v1_; TestZwpTextInputManagerV1 zwp_text_input_manager_v1_; TestZwpLinuxExplicitSynchronizationV1 zwp_linux_explicit_synchronization_v1_; MockZwpLinuxDmabufV1 zwp_linux_dmabuf_v1_; MockWpPresentation wp_presentation_; TestWpPointerGestures wp_pointer_gestures_; MockXdgActivationV1 xdg_activation_v1_; std::unique_ptr<TestSelectionDeviceManager> primary_selection_device_manager_; std::vector<std::unique_ptr<GlobalObject>> globals_; base::MessagePumpLibevent::FdWatchController controller_; raw_ptr<OutputDelegate> output_delegate_ = nullptr; THREAD_CHECKER(thread_checker_); }; class TestWaylandServerThread::OutputDelegate { public: // Tests may implement this such that it emulates different display/output // test scenarios. For example, multi-screen, lazy configuration, arbitrary // ordering of the outputs metadata events, etc. virtual void SetupOutputs(TestOutput* primary_output) = 0; protected: virtual ~OutputDelegate() = default; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_SERVER_THREAD_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_server_thread.h
C++
unknown
10,782
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_output.h" #include "base/notreached.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h" namespace wl { namespace { void GetColorSpace(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* color_space_resource = CreateResourceWithImpl<TestZcrColorSpaceV1>( client, &zcr_color_space_v1_interface, 1, &kTestZcrColorSpaceV1Impl, id); auto* color_management_output = GetUserDataAs<TestZcrColorManagementOutputV1>(resource); auto* zcr_color_space = GetUserDataAs<TestZcrColorSpaceV1>(color_space_resource); zcr_color_space->SetGfxColorSpace( color_management_output->GetGfxColorSpace()); color_management_output->StoreZcrColorSpace(zcr_color_space); } } // namespace const struct zcr_color_management_output_v1_interface kTestZcrColorManagementOutputV1Impl = {&GetColorSpace, &DestroyResource}; TestZcrColorManagementOutputV1::TestZcrColorManagementOutputV1( wl_resource* resource) : ServerObject(resource) {} TestZcrColorManagementOutputV1::~TestZcrColorManagementOutputV1() { DCHECK(zcr_color_manager_); zcr_color_manager_->OnZcrColorManagementOutputDestroyed(this); } void TestZcrColorManagementOutputV1::SetGfxColorSpace( gfx::ColorSpace gfx_color_space) { gfx_color_space_ = gfx_color_space; } void TestZcrColorManagementOutputV1::StoreZcrColorManager( MockZcrColorManagerV1* zcr_color_manager) { zcr_color_manager_ = zcr_color_manager; } void TestZcrColorManagementOutputV1::StoreZcrColorSpace( TestZcrColorSpaceV1* zcr_color_space) { zcr_color_space_ = zcr_color_space; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_output.cc
C++
unknown
2,015
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_OUTPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_OUTPUT_H_ #include <chrome-color-management-server-protocol.h> #include "base/files/scoped_file.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zcr_color_management_output_v1_interface kTestZcrColorManagementOutputV1Impl; class MockZcrColorManagerV1; class TestZcrColorSpaceV1; class TestZcrColorManagementOutputV1 : public ServerObject { public: explicit TestZcrColorManagementOutputV1(wl_resource* resource); TestZcrColorManagementOutputV1(const TestZcrColorManagementOutputV1&) = delete; TestZcrColorManagementOutputV1& operator=( const TestZcrColorManagementOutputV1&) = delete; ~TestZcrColorManagementOutputV1() override; void GetColorSpace(wl_client* client, wl_resource* resource, uint32_t id); void Destroy(wl_client* client, wl_resource* resource); gfx::ColorSpace GetGfxColorSpace() const { return gfx_color_space_; } void SetGfxColorSpace(gfx::ColorSpace gfx_color_space); void StoreZcrColorManager(MockZcrColorManagerV1* zcr_color_manager); TestZcrColorSpaceV1* GetZcrColorSpace() const { return zcr_color_space_; } void StoreZcrColorSpace(TestZcrColorSpaceV1* zcr_color_space); private: gfx::ColorSpace gfx_color_space_; raw_ptr<MockZcrColorManagerV1> zcr_color_manager_ = nullptr; raw_ptr<TestZcrColorSpaceV1> zcr_color_space_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_OUTPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_output.h
C++
unknown
1,918
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_surface.h" #include "base/notreached.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h" namespace wl { namespace { void SetAlphaMode(wl_client* client, wl_resource* resource, uint32_t alpha_mode) { auto* color_management_surface = GetUserDataAs<TestZcrColorManagementSurfaceV1>(resource); DCHECK(color_management_surface); } void SetExtendedDynamicRange(wl_client* client, wl_resource* resource, uint32_t value) { auto* color_management_surface = GetUserDataAs<TestZcrColorManagementSurfaceV1>(resource); DCHECK(color_management_surface); } void SetColorSpace(wl_client* client, wl_resource* resource, wl_resource* color_space_resource, uint32_t render_intent) { auto* color_management_surface = GetUserDataAs<TestZcrColorManagementSurfaceV1>(resource); DCHECK(color_space_resource); auto* zcr_color_space = GetUserDataAs<TestZcrColorSpaceV1>(color_space_resource); color_management_surface->SetGfxColorSpace( zcr_color_space->GetGfxColorSpace()); } void SetDefaultColorSpace(wl_client* client, wl_resource* resource) { auto* color_management_surface = GetUserDataAs<TestZcrColorManagementSurfaceV1>(resource); color_management_surface->SetGfxColorSpace(gfx::ColorSpace::CreateSRGB()); } } // namespace const struct zcr_color_management_surface_v1_interface kTestZcrColorManagementSurfaceV1Impl = { &SetAlphaMode, &SetExtendedDynamicRange, &SetColorSpace, &SetDefaultColorSpace, &DestroyResource}; TestZcrColorManagementSurfaceV1::TestZcrColorManagementSurfaceV1( wl_resource* resource) : ServerObject(resource) {} TestZcrColorManagementSurfaceV1::~TestZcrColorManagementSurfaceV1() { DCHECK(zcr_color_manager_); zcr_color_manager_->OnZcrColorManagementSurfaceDestroyed(this); } gfx::ColorSpace TestZcrColorManagementSurfaceV1::GetGfxColorSpace() { return gfx_color_space_; } void TestZcrColorManagementSurfaceV1::SetGfxColorSpace( gfx::ColorSpace gfx_color_space) { gfx_color_space_ = gfx_color_space; } void TestZcrColorManagementSurfaceV1::StoreZcrColorManager( MockZcrColorManagerV1* zcr_color_manager) { zcr_color_manager_ = zcr_color_manager; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_surface.cc
C++
unknown
2,747
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_ #include <chrome-color-management-server-protocol.h> #include "base/files/scoped_file.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zcr_color_management_surface_v1_interface kTestZcrColorManagementSurfaceV1Impl; class MockZcrColorManagerV1; class TestZcrColorManagementSurfaceV1 : public ServerObject { public: explicit TestZcrColorManagementSurfaceV1(wl_resource* resource); TestZcrColorManagementSurfaceV1(const TestZcrColorManagementSurfaceV1&) = delete; TestZcrColorManagementSurfaceV1& operator=( const TestZcrColorManagementSurfaceV1&) = delete; ~TestZcrColorManagementSurfaceV1() override; void SetAlphaMode(wl_client* client, wl_resource* resource, uint32_t alpha_mode); void SetExtendedDynamicRange(wl_client* client, wl_resource* resource, uint32_t value); void SetColorSpace(wl_client* client, wl_resource* resource, wl_resource* color_space_resource, uint32_t render_intent); void SetDefaultColorSpace(wl_client* client, wl_resource* resource); void Destroy(wl_client* client, wl_resource* resource); gfx::ColorSpace GetGfxColorSpace(); void SetGfxColorSpace(gfx::ColorSpace gfx_color_space); void StoreZcrColorManager(MockZcrColorManagerV1* zcr_color_manager); private: gfx::ColorSpace gfx_color_space_; raw_ptr<MockZcrColorManagerV1> zcr_color_manager_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_surface.h
C++
unknown
2,124
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h" #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { void GetInformation(wl_client* client, wl_resource* resource) { auto* zcr_color_space = GetUserDataAs<TestZcrColorSpaceV1>(resource); DCHECK(zcr_color_space); } } // namespace const struct zcr_color_space_v1_interface kTestZcrColorSpaceV1Impl = { &GetInformation, &DestroyResource}; TestZcrColorSpaceV1::TestZcrColorSpaceV1(wl_resource* resource) : ServerObject(resource) {} TestZcrColorSpaceV1::~TestZcrColorSpaceV1() { if (zcr_color_manager_) { zcr_color_manager_->OnZcrColorSpaceDestroyed(this); } } void TestZcrColorSpaceV1::SetGfxColorSpace(gfx::ColorSpace gfx_color_space) { gfx_color_space_ = gfx_color_space; } void TestZcrColorSpaceV1::SetZcrColorManager( MockZcrColorManagerV1* zcr_color_manager) { zcr_color_manager_ = zcr_color_manager; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.cc
C++
unknown
1,186
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_SPACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_SPACE_H_ #include <chrome-color-management-server-protocol.h> #include "base/files/scoped_file.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zcr_color_space_v1_interface kTestZcrColorSpaceV1Impl; class MockZcrColorManagerV1; // Manage zcr_color_space_v1_interface class TestZcrColorSpaceV1 : public ServerObject { public: explicit TestZcrColorSpaceV1(wl_resource* resource); TestZcrColorSpaceV1(const TestZcrColorSpaceV1&) = delete; TestZcrColorSpaceV1& operator=(const TestZcrColorSpaceV1&) = delete; ~TestZcrColorSpaceV1() override; void GetInformation(wl_client* client, wl_resource* resource); void Destroy(wl_client* client, wl_resource* resource); gfx::ColorSpace GetGfxColorSpace() const { return gfx_color_space_; } void SetGfxColorSpace(gfx::ColorSpace gfx_color_space); void SetZcrColorManager(MockZcrColorManagerV1* zcr_color_manager); private: gfx::ColorSpace gfx_color_space_; raw_ptr<MockZcrColorManagerV1> zcr_color_manager_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLANDS_ZCR_COLOR_SPACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h
C++
unknown
1,563
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space_creator.h" namespace wl { TestZcrColorSpaceCreatorV1::TestZcrColorSpaceCreatorV1(wl_resource* resource) : ServerObject(resource) {} TestZcrColorSpaceCreatorV1::~TestZcrColorSpaceCreatorV1() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_space_creator.cc
C++
unknown
441
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_ #include <chrome-color-management-server-protocol.h> #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { class TestZcrColorSpaceCreatorV1 : public ServerObject { public: explicit TestZcrColorSpaceCreatorV1(wl_resource* resource); TestZcrColorSpaceCreatorV1(const TestZcrColorSpaceCreatorV1&) = delete; TestZcrColorSpaceCreatorV1& operator=(const TestZcrColorSpaceCreatorV1&) = delete; ~TestZcrColorSpaceCreatorV1() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wayland_zcr_color_space_creator.h
C++
unknown
943
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_wp_pointer_gestures.h" #include <pointer-gestures-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include "base/logging.h" #include "base/notreached.h" namespace wl { namespace { const struct zwp_pointer_gesture_pinch_v1_interface kTestPinchImpl = { DestroyResource}; constexpr uint32_t kInterfaceVersion = 1; } // namespace const struct zwp_pointer_gestures_v1_interface kInterfaceImpl = { TestWpPointerGestures::GetSwipeGesture, TestWpPointerGestures::GetPinchGesture, DestroyResource, }; TestWpPointerGestures::TestWpPointerGestures() : GlobalObject(&zwp_pointer_gestures_v1_interface, &kInterfaceImpl, kInterfaceVersion) {} TestWpPointerGestures::~TestWpPointerGestures() = default; // static void TestWpPointerGestures::GetSwipeGesture(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* pointer) { NOTIMPLEMENTED_LOG_ONCE(); } // static void TestWpPointerGestures::GetPinchGesture( struct wl_client* client, struct wl_resource* pointer_gestures_resource, uint32_t id, struct wl_resource* pointer) { wl_resource* pinch_gesture_resource = CreateResourceWithImpl<TestPinchGesture>( client, &zwp_pointer_gesture_pinch_v1_interface, 1, &kTestPinchImpl, id); GetUserDataAs<TestWpPointerGestures>(pointer_gestures_resource)->pinch_ = GetUserDataAs<TestPinchGesture>(pinch_gesture_resource); } TestPinchGesture::TestPinchGesture(wl_resource* resource) : ServerObject(resource) {} TestPinchGesture::~TestPinchGesture() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wp_pointer_gestures.cc
C++
unknown
1,955
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WP_POINTER_GESTURES_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WP_POINTER_GESTURES_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_client; struct wl_resource; namespace wl { class TestPinchGesture : public ServerObject { public: explicit TestPinchGesture(wl_resource* resource); TestPinchGesture(const TestPinchGesture&) = delete; TestPinchGesture& operator=(const TestPinchGesture&) = delete; ~TestPinchGesture() override; }; // Manage zwp_linux_dmabuf_v1 object. class TestWpPointerGestures : public GlobalObject { public: TestWpPointerGestures(); TestWpPointerGestures(const TestWpPointerGestures&) = delete; TestWpPointerGestures& operator=(const TestWpPointerGestures&) = delete; ~TestWpPointerGestures() override; TestPinchGesture* pinch() const { return pinch_; } static void GetSwipeGesture(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* pointer); static void GetPinchGesture(struct wl_client* client, struct wl_resource* pointer_gestures_resource, uint32_t id, struct wl_resource* pointer); private: raw_ptr<TestPinchGesture> pinch_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_WP_POINTER_GESTURES_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_wp_pointer_gestures.h
C++
unknown
1,701
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_xdg_popup.h" #include "ui/ozone/platform/wayland/test/mock_xdg_surface.h" #include "ui/ozone/platform/wayland/test/test_positioner.h" namespace wl { namespace { void Grab(struct wl_client* client, struct wl_resource* resource, struct wl_resource* seat, uint32_t serial) { GetUserDataAs<TestXdgPopup>(resource)->set_grab_serial(serial); } void Reposition(struct wl_client* client, struct wl_resource* resource, struct wl_resource* positioner, uint32_t token) { auto* test_positioner = GetUserDataAs<TestPositioner>(positioner); DCHECK(test_positioner); GetUserDataAs<TestXdgPopup>(resource)->set_position( test_positioner->position()); } } // namespace const struct xdg_popup_interface kXdgPopupImpl = { &DestroyResource, // destroy &Grab, // grab &Reposition, // reposition }; TestXdgPopup::TestXdgPopup(wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) { auto* mock_xdg_surface = GetUserDataAs<MockXdgSurface>(surface_); if (mock_xdg_surface) mock_xdg_surface->set_xdg_popup(nullptr); } TestXdgPopup::~TestXdgPopup() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_xdg_popup.cc
C++
unknown
1,415
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_XDG_POPUP_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_XDG_POPUP_H_ #include <utility> #include <xdg-shell-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_positioner.h" struct wl_resource; namespace wl { extern const struct xdg_popup_interface kXdgPopupImpl; extern const struct zxdg_popup_v6_interface kZxdgPopupV6Impl; class TestXdgPopup : public ServerObject { public: TestXdgPopup(wl_resource* resource, wl_resource* surface); TestXdgPopup(const TestXdgPopup&) = delete; TestXdgPopup& operator=(const TestXdgPopup&) = delete; ~TestXdgPopup() override; struct TestPositioner::PopupPosition position() const { return position_; } void set_position(struct TestPositioner::PopupPosition position) { position_ = std::move(position); } // Returns and stores the serial used for grab. uint32_t grab_serial() const { return grab_serial_; } void set_grab_serial(uint32_t serial) { grab_serial_ = serial; } gfx::Rect anchor_rect() const { return position_.anchor_rect; } gfx::Size size() const { return position_.size; } uint32_t anchor() const { return position_.anchor; } uint32_t gravity() const { return position_.gravity; } uint32_t constraint_adjustment() const { return position_.constraint_adjustment; } private: struct TestPositioner::PopupPosition position_; // Ground surface for this popup. raw_ptr<wl_resource> surface_ = nullptr; uint32_t grab_serial_ = 0; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_XDG_POPUP_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_xdg_popup.h
C++
unknown
1,816
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_output.h" #include "base/bit_cast.h" #include "ui/base/wayland/wayland_display_util.h" #include "ui/ozone/platform/wayland/test/test_output_metrics.h" namespace wl { TestZAuraOutput::TestZAuraOutput(wl_resource* resource) : ServerObject(resource) {} TestZAuraOutput::~TestZAuraOutput() = default; void TestZAuraOutput::SendActivated() { zaura_output_send_activated(resource()); } void TestZAuraOutput::Flush(const TestOutputMetrics& metrics) { if (wl_resource_get_version(resource()) >= ZAURA_OUTPUT_DISPLAY_ID_SINCE_VERSION) { auto display_id = ui::wayland::ToWaylandDisplayIdPair(metrics.aura_display_id); zaura_output_send_display_id(resource(), display_id.high, display_id.low); } const auto insets = metrics.aura_logical_insets; zaura_output_send_insets(resource(), insets.top(), insets.left(), insets.bottom(), insets.right()); zaura_output_send_device_scale_factor( resource(), base::bit_cast<uint32_t>(metrics.aura_device_scale_factor)); zaura_output_send_logical_transform(resource(), metrics.aura_logical_transform); } const struct zaura_output_interface kTestZAuraOutputImpl { &DestroyResource, }; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_output.cc
C++
unknown
1,448
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_H_ #include <aura-shell-server-protocol.h> #include <wayland-client-protocol.h> #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/insets.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zaura_output_interface kTestZAuraOutputImpl; struct TestOutputMetrics; // Handles the server-side representation of the zaura_output. class TestZAuraOutput : public ServerObject { public: explicit TestZAuraOutput(wl_resource* resource); TestZAuraOutput(const TestZAuraOutput&) = delete; TestZAuraOutput& operator=(const TestZAuraOutput&) = delete; ~TestZAuraOutput() override; // Sends the activated event immediately. void SendActivated(); // Called by the owning wl_output as part of its Flush() operation that // propagates the current state of `metrics_` to clients. void Flush(const TestOutputMetrics& metrics); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_output.h
C++
unknown
1,257
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_output_manager.h" #include <aura-shell-server-protocol.h> #include "base/bit_cast.h" #include "ui/base/wayland/wayland_display_util.h" #include "ui/ozone/platform/wayland/test/test_output_metrics.h" namespace wl { namespace { constexpr uint32_t kZAuraOutputManagerVersion = 2; } // namespace TestZAuraOutputManager::TestZAuraOutputManager() : GlobalObject(&zaura_output_manager_interface, nullptr, kZAuraOutputManagerVersion) {} TestZAuraOutputManager::~TestZAuraOutputManager() = default; void TestZAuraOutputManager::SendOutputMetrics( wl_resource* output_resource, const TestOutputMetrics& metrics) { const auto& physical_size = metrics.wl_physical_size; zaura_output_manager_send_physical_size(resource(), output_resource, physical_size.width(), physical_size.height()); zaura_output_manager_send_panel_transform(resource(), output_resource, metrics.wl_panel_transform); const auto& logical_size = metrics.xdg_logical_size; zaura_output_manager_send_logical_size( resource(), output_resource, logical_size.width(), logical_size.height()); const auto& logical_origin = metrics.xdg_logical_origin; zaura_output_manager_send_logical_position( resource(), output_resource, logical_origin.x(), logical_origin.y()); const auto display_id = ui::wayland::ToWaylandDisplayIdPair(metrics.aura_display_id); zaura_output_manager_send_display_id(resource(), output_resource, display_id.high, display_id.low); const auto& insets = metrics.aura_logical_insets; zaura_output_manager_send_insets(resource(), output_resource, insets.top(), insets.left(), insets.bottom(), insets.right()); zaura_output_manager_send_device_scale_factor( resource(), output_resource, base::bit_cast<uint32_t>(metrics.aura_device_scale_factor)); zaura_output_manager_send_logical_transform(resource(), output_resource, metrics.aura_logical_transform); zaura_output_manager_send_done(resource(), output_resource); } void TestZAuraOutputManager::SendActivated(wl_resource* output_resource) { zaura_output_manager_send_activated(resource(), output_resource); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_output_manager.cc
C++
unknown
2,651
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_MANAGER_H_ #include "ui/ozone/platform/wayland/test/global_object.h" struct wl_resource; namespace wl { struct TestOutputMetrics; class TestZAuraOutputManager : public GlobalObject { public: TestZAuraOutputManager(); TestZAuraOutputManager(const TestZAuraOutputManager&) = delete; TestZAuraOutputManager& operator=(const TestZAuraOutputManager&) = delete; ~TestZAuraOutputManager() override; // Propagates events for metrics to bound clients for the output. void SendOutputMetrics(wl_resource* output_resource, const TestOutputMetrics& metrics); // Sends the activated event for the given output. void SendActivated(wl_resource* output_resource); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_OUTPUT_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_output_manager.h
C++
unknown
1,059
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_popup.h" #include <aura-shell-server-protocol.h> #include "base/notreached.h" namespace wl { namespace { void SurfaceSubmissionInPixelCoordinates(struct wl_client* client, struct wl_resource* resource) { // TODO(crbug.com/1346347): Implement zaura-shell protocol requests and test // their usage. NOTIMPLEMENTED_LOG_ONCE(); } void SetDecoration(struct wl_client* client, struct wl_resource* resource, uint32_t type) { NOTIMPLEMENTED_LOG_ONCE(); } void SetMenu(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } } // namespace TestZAuraPopup::TestZAuraPopup(wl_resource* resource) : ServerObject(resource) {} TestZAuraPopup::~TestZAuraPopup() = default; const struct zaura_popup_interface kTestZAuraPopupImpl = { &SurfaceSubmissionInPixelCoordinates, &SetDecoration, &SetMenu, &DestroyResource, }; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_popup.cc
C++
unknown
1,170
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_POPUP_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_POPUP_H_ #include <aura-shell-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zaura_popup_interface kTestZAuraPopupImpl; // Manages zaura_popup object. class TestZAuraPopup : public ServerObject { public: explicit TestZAuraPopup(wl_resource* resource); TestZAuraPopup(const TestZAuraPopup&) = delete; TestZAuraPopup& operator=(const TestZAuraPopup&) = delete; ~TestZAuraPopup() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_POPUP_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_popup.h
C++
unknown
807
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_shell.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_output.h" #include "ui/ozone/platform/wayland/test/test_zaura_output.h" #include "ui/ozone/platform/wayland/test/test_zaura_popup.h" #include "ui/ozone/platform/wayland/test/test_zaura_surface.h" #include "ui/ozone/platform/wayland/test/test_zaura_toplevel.h" namespace wl { namespace { constexpr uint32_t kZAuraShellVersion = 44; constexpr uint32_t kZAuraOutputVersion = 44; void GetAuraSurface(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface_resource) { CreateResourceWithImpl<TestZAuraSurface>(client, &zaura_surface_interface, kZAuraShellVersion, &kTestZAuraSurfaceImpl, id); } void GetAuraOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* output_resource) { wl_resource* zaura_output_resource = CreateResourceWithImpl<TestZAuraOutput>( client, &zaura_output_interface, kZAuraOutputVersion, &kTestZAuraOutputImpl, id); auto* output = GetUserDataAs<TestOutput>(output_resource); output->SetAuraOutput(GetUserDataAs<TestZAuraOutput>(zaura_output_resource)); } void SurfaceSubmissionInPixelCoordinates(wl_client* client, wl_resource* resource) { // TODO(crbug.com/1346347): Implement zaura-shell protocol requests and test // their usage. NOTIMPLEMENTED_LOG_ONCE(); } void GetAuraToplevelForXdgToplevel(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* toplevel) { CreateResourceWithImpl<TestZAuraToplevel>(client, &zaura_toplevel_interface, kZAuraShellVersion, &kTestZAuraToplevelImpl, id); } void GetAuraPopupForXdgPopup(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* popup) { CreateResourceWithImpl<TestZAuraPopup>(client, &zaura_popup_interface, kZAuraShellVersion, &kTestZAuraPopupImpl, id); } const struct zaura_shell_interface kTestZAuraShellImpl = { &GetAuraSurface, &GetAuraOutput, &SurfaceSubmissionInPixelCoordinates, &GetAuraToplevelForXdgToplevel, &GetAuraPopupForXdgPopup, &DestroyResource, }; } // namespace TestZAuraShell::TestZAuraShell() : GlobalObject(&zaura_shell_interface, &kTestZAuraShellImpl, kZAuraShellVersion) {} TestZAuraShell::~TestZAuraShell() = default; void TestZAuraShell::SetBugFixes(std::vector<uint32_t> bug_fixes) { bug_fixes_ = std::move(bug_fixes); MaybeSendBugFixes(); } void TestZAuraShell::OnBind() { MaybeSendBugFixes(); } void TestZAuraShell::MaybeSendBugFixes() { if (resource() && wl_resource_get_version(resource()) >= ZAURA_SHELL_BUG_FIX_SINCE_VERSION) { for (const uint32_t bug_fix : bug_fixes_) zaura_shell_send_bug_fix(resource(), bug_fix); } } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_shell.cc
C++
unknown
3,610
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SHELL_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SHELL_H_ #include <aura-shell-server-protocol.h> #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { class TestZAuraShell : public GlobalObject { public: TestZAuraShell(); TestZAuraShell(const TestZAuraShell&) = delete; TestZAuraShell& operator=(const TestZAuraShell&) = delete; ~TestZAuraShell() override; // Sets bug fixes and sends them out if the object is bound. void SetBugFixes(std::vector<uint32_t> bug_fixes); private: void OnBind() override; void MaybeSendBugFixes(); // Bug fixes that shall be sent to the client. std::vector<uint32_t> bug_fixes_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SHELL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_shell.h
C++
unknown
998
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_surface.h" #include <aura-shell-server-protocol.h> #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { // TODO(https://crbug.com/1395061): Replace NOTREACHED() by NOTIMPLEMENTED() for // all methods? void set_frame(struct wl_client* client, struct wl_resource* resource, uint32_t type) { NOTREACHED(); } void set_parent(struct wl_client* client, struct wl_resource* resource, struct wl_resource* parent, int32_t x, int32_t y) { NOTREACHED(); } void set_frame_colors(struct wl_client* client, struct wl_resource* resource, uint32_t active_color, uint32_t inactive_color) { NOTREACHED(); } void set_startup_id(struct wl_client* client, struct wl_resource* resource, const char* startup_id) { NOTREACHED(); } void set_application_id(struct wl_client* client, struct wl_resource* resource, const char* application_id) { NOTREACHED(); } void set_client_surface_id(struct wl_client* client, struct wl_resource* resource, int32_t client_surface_id) { NOTREACHED(); } void set_occlusion_tracking(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void unset_occlusion_tracking(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void activate(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void draw_attention(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void set_fullscreen_mode(struct wl_client* client, struct wl_resource* resource, uint32_t mode) { NOTIMPLEMENTED_LOG_ONCE(); } void set_client_surface_str_id(struct wl_client* client, struct wl_resource* resource, const char* client_surface_id) { NOTREACHED(); } void set_server_start_resize(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void intent_to_snap(struct wl_client* client, struct wl_resource* resource, uint32_t direction) { NOTREACHED(); } void set_snap_left(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void set_snap_right(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void unset_snap(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void set_window_session_id(struct wl_client* client, struct wl_resource* resource, int32_t id) { NOTREACHED(); } void set_can_go_back(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void unset_can_go_back(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void set_pip(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void unset_pip(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void set_aspect_ratio(struct wl_client* client, struct wl_resource* resource, int32_t width, int32_t height) { NOTREACHED(); } void move_to_desk(struct wl_client* client, struct wl_resource* resource, int32_t index) { NOTREACHED(); } void set_initial_workspace(struct wl_client* client, struct wl_resource* resource, const char* initial_workspace) { NOTREACHED(); } void set_pin(struct wl_client* client, struct wl_resource* resource, int32_t trusted) { NOTREACHED(); } void unset_pin(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } } // namespace TestZAuraSurface::TestZAuraSurface(wl_resource* resource) : ServerObject(resource) {} TestZAuraSurface::~TestZAuraSurface() = default; const struct zaura_surface_interface kTestZAuraSurfaceImpl = { &set_frame, &set_parent, &set_frame_colors, &set_startup_id, &set_application_id, &set_client_surface_id, &set_occlusion_tracking, &unset_occlusion_tracking, &activate, &draw_attention, &set_fullscreen_mode, &set_client_surface_str_id, &set_server_start_resize, &intent_to_snap, &set_snap_left, &set_snap_right, &unset_snap, &set_window_session_id, &set_can_go_back, &unset_can_go_back, &set_pip, &unset_pip, &set_aspect_ratio, &move_to_desk, &set_initial_workspace, &set_pin, &unset_pin, &DestroyResource, }; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_surface.cc
C++
unknown
5,141
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SURFACE_H_ #include <aura-shell-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zaura_surface_interface kTestZAuraSurfaceImpl; // Manages zaura_surface object. class TestZAuraSurface : public ServerObject { public: explicit TestZAuraSurface(wl_resource* resource); TestZAuraSurface(const TestZAuraSurface&) = delete; TestZAuraSurface& operator=(const TestZAuraSurface&) = delete; ~TestZAuraSurface() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_surface.h
C++
unknown
833
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zaura_toplevel.h" #include <aura-shell-server-protocol.h> #include "base/notreached.h" namespace wl { namespace { void SetOrientationLock(struct wl_client* client, struct wl_resource* resource, uint32_t orientation_lock) { NOTIMPLEMENTED_LOG_ONCE(); } void SurfaceSubmissionInPixelCoordinates(struct wl_client* client, struct wl_resource* resource) { // TODO(crbug.com/1346347): Implement zaura-shell protocol requests and test // their usage. NOTIMPLEMENTED_LOG_ONCE(); } void SetSupportsScreenCoordinates(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void SetWindowBounds(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height, struct wl_resource* output) { NOTIMPLEMENTED_LOG_ONCE(); } void SetOrigin(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, struct wl_resource* output) { NOTIMPLEMENTED_LOG_ONCE(); } void SetRestoreInfo(struct wl_client* client, struct wl_resource* resource, int32_t restore_session_id, int32_t restore_window_id) { NOTREACHED(); } void SetSystemModal(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void UnsetSystemModal(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void SetRestoreInfoWithWindowIdSource(struct wl_client* client, struct wl_resource* resource, int32_t restore_session_id, const char* restore_window_id_source) { NOTREACHED(); } void SetDecoration(struct wl_client* client, struct wl_resource* resource, uint32_t type) { NOTREACHED(); } void SetFloat(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void UnSetFloat(struct wl_client* client, struct wl_resource* resource) { NOTREACHED(); } void SetZOrder(struct wl_client* client, struct wl_resource* resource, uint32_t z_order) { NOTIMPLEMENTED_LOG_ONCE(); } void Activate(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void Dectivate(struct wl_client* client, struct wl_resource* resource) { NOTIMPLEMENTED_LOG_ONCE(); } void SetFullscreenMode(struct wl_client* client, struct wl_resource* resource, uint32_t mode) { NOTIMPLEMENTED_LOG_ONCE(); } } // namespace TestZAuraToplevel::TestZAuraToplevel(wl_resource* resource) : ServerObject(resource) {} TestZAuraToplevel::~TestZAuraToplevel() = default; const struct zaura_toplevel_interface kTestZAuraToplevelImpl = { &SetOrientationLock, &SurfaceSubmissionInPixelCoordinates, &SetSupportsScreenCoordinates, &SetWindowBounds, &SetRestoreInfo, &SetSystemModal, &UnsetSystemModal, &SetRestoreInfoWithWindowIdSource, &SetDecoration, &DestroyResource, &SetFloat, &UnSetFloat, &SetZOrder, &SetOrigin, &Activate, &Dectivate, &SetFullscreenMode, }; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_toplevel.cc
C++
unknown
3,682
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_TOPLEVEL_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_TOPLEVEL_H_ #include <aura-shell-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zaura_toplevel_interface kTestZAuraToplevelImpl; // Manages zaura_toplevel object. class TestZAuraToplevel : public ServerObject { public: explicit TestZAuraToplevel(wl_resource* resource); TestZAuraToplevel(const TestZAuraToplevel&) = delete; TestZAuraToplevel& operator=(const TestZAuraToplevel&) = delete; ~TestZAuraToplevel() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZAURA_TOPLEVEL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zaura_toplevel.h
C++
unknown
846
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zcr_pointer_stylus.h" namespace wl { const struct zcr_pointer_stylus_v2_interface kTestZcrPointerStylusImpl = { &DestroyResource, // destroy }; TestZcrPointerStylus::TestZcrPointerStylus(wl_resource* resource) : ServerObject(resource) {} TestZcrPointerStylus::~TestZcrPointerStylus() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_pointer_stylus.cc
C++
unknown
518
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_POINTER_STYLUS_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_POINTER_STYLUS_H_ #include <stylus-unstable-v2-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zcr_pointer_stylus_v2_interface kTestZcrPointerStylusImpl; class TestZcrPointerStylus : public ServerObject { public: explicit TestZcrPointerStylus(wl_resource* resource); TestZcrPointerStylus(const TestZcrPointerStylus&) = delete; TestZcrPointerStylus& operator=(const TestZcrPointerStylus&) = delete; ~TestZcrPointerStylus() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_POINTER_STYLUS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_pointer_stylus.h
C++
unknown
863
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zcr_stylus.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/mock_pointer.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_touch.h" #include "ui/ozone/platform/wayland/test/test_zcr_pointer_stylus.h" #include "ui/ozone/platform/wayland/test/test_zcr_touch_stylus.h" namespace wl { namespace { constexpr uint32_t kZcrStylusVersion = 2; void GetTouchStylus(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* touch_resource) { wl_resource* touch_stylus_resource = CreateResourceWithImpl<TestZcrTouchStylus>( client, &zcr_touch_stylus_v2_interface, wl_resource_get_version(resource), &kTestZcrTouchStylusImpl, id); GetUserDataAs<TestTouch>(touch_resource) ->set_touch_stylus( GetUserDataAs<TestZcrTouchStylus>(touch_stylus_resource)); } void GetPointerStylus(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* pointer_resource) { wl_resource* pointer_stylus_resource = CreateResourceWithImpl<TestZcrPointerStylus>( client, &zcr_pointer_stylus_v2_interface, wl_resource_get_version(resource), &kTestZcrPointerStylusImpl, id); GetUserDataAs<MockPointer>(pointer_resource) ->set_pointer_stylus( GetUserDataAs<TestZcrPointerStylus>(pointer_stylus_resource)); } const struct zcr_stylus_v2_interface kTestZcrStylusImpl = {&GetTouchStylus, &GetPointerStylus}; } // namespace TestZcrStylus::TestZcrStylus() : GlobalObject(&zcr_stylus_v2_interface, &kTestZcrStylusImpl, kZcrStylusVersion) {} TestZcrStylus::~TestZcrStylus() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_stylus.cc
C++
unknown
2,077
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_STYLUS_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_STYLUS_H_ #include <stylus-unstable-v2-server-protocol.h> #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { class TestZcrStylus : public GlobalObject { public: TestZcrStylus(); TestZcrStylus(const TestZcrStylus&) = delete; TestZcrStylus& operator=(const TestZcrStylus&) = delete; ~TestZcrStylus() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_STYLUS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_stylus.h
C++
unknown
680
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zcr_text_input_extension.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/mock_zcr_extended_text_input.h" namespace wl { namespace { void GetExtendedTextInput(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* text_input_resource) { wl_resource* text_resource = CreateResourceWithImpl<MockZcrExtendedTextInput>( client, &zcr_extended_text_input_v1_interface, wl_resource_get_version(resource), &kMockZcrExtendedTextInputV1Impl, id); GetUserDataAs<TestZcrTextInputExtensionV1>(resource)->set_extended_text_input( GetUserDataAs<MockZcrExtendedTextInput>(text_resource)); } } // namespace const struct zcr_text_input_extension_v1_interface kTestZcrTextInputExtensionV1Impl = { &GetExtendedTextInput, // get_extended_text_input }; TestZcrTextInputExtensionV1::TestZcrTextInputExtensionV1( TestZcrTextInputExtensionV1::Version version) : GlobalObject(&zcr_text_input_extension_v1_interface, &kTestZcrTextInputExtensionV1Impl, static_cast<uint32_t>(version)) {} TestZcrTextInputExtensionV1::~TestZcrTextInputExtensionV1() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_text_input_extension.cc
C++
unknown
1,472
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_TEXT_INPUT_EXTENSION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_TEXT_INPUT_EXTENSION_H_ #include <text-input-extension-unstable-v1-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct zcr_text_input_extension_v1_interface kTestZcrTextInputExtensionV1Impl; class MockZcrExtendedTextInput; // Manage zcr_text_input_extension_v1 object. class TestZcrTextInputExtensionV1 : public GlobalObject { public: enum class Version : uint32_t { kV7 = 7, kV8 = 8, }; explicit TestZcrTextInputExtensionV1(Version version); TestZcrTextInputExtensionV1(const TestZcrTextInputExtensionV1&) = delete; TestZcrTextInputExtensionV1& operator=(const TestZcrTextInputExtensionV1&) = delete; ~TestZcrTextInputExtensionV1() override; void set_extended_text_input(MockZcrExtendedTextInput* extended_text_input) { extended_text_input_ = extended_text_input; } MockZcrExtendedTextInput* extended_text_input() const { return extended_text_input_; } private: raw_ptr<MockZcrExtendedTextInput> extended_text_input_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_EXTENSION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_text_input_extension.h
C++
unknown
1,433
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zcr_touch_stylus.h" namespace wl { const struct zcr_touch_stylus_v2_interface kTestZcrTouchStylusImpl = { &DestroyResource, // destroy }; TestZcrTouchStylus::TestZcrTouchStylus(wl_resource* resource) : ServerObject(resource) {} TestZcrTouchStylus::~TestZcrTouchStylus() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_touch_stylus.cc
C++
unknown
504
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_TOUCH_STYLUS_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_TOUCH_STYLUS_H_ #include <stylus-unstable-v2-server-protocol.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zcr_touch_stylus_v2_interface kTestZcrTouchStylusImpl; class TestZcrTouchStylus : public ServerObject { public: explicit TestZcrTouchStylus(wl_resource* resource); TestZcrTouchStylus(const TestZcrTouchStylus&) = delete; TestZcrTouchStylus& operator=(const TestZcrTouchStylus&) = delete; ~TestZcrTouchStylus() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZCR_TOUCH_STYLUS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zcr_touch_stylus.h
C++
unknown
839
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h" #include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h" #include "ui/ozone/platform/wayland/test/test_buffer.h" namespace wl { namespace { void Add(wl_client* client, wl_resource* resource, int32_t fd, uint32_t plane_idx, uint32_t offset, uint32_t stride, uint32_t modifier_hi, uint32_t modifier_lo) { auto* buffer_params = GetUserDataAs<TestZwpLinuxBufferParamsV1>(resource); buffer_params->fds_.emplace_back(fd); buffer_params->modifier_lo_ = modifier_lo; buffer_params->modifier_hi_ = modifier_hi; } void CreateCommon(TestZwpLinuxBufferParamsV1* buffer_params, wl_client* client, int32_t width, int32_t height, uint32_t format, uint32_t flags) { wl_resource* buffer_resource = CreateResourceWithImpl<::testing::NiceMock<TestBuffer>>( client, &wl_buffer_interface, 1, &kTestWlBufferImpl, 0, std::move(buffer_params->fds_)); buffer_params->SetBufferResource(buffer_resource); } void Create(wl_client* client, wl_resource* buffer_params_resource, int32_t width, int32_t height, uint32_t format, uint32_t flags) { auto* buffer_params = GetUserDataAs<TestZwpLinuxBufferParamsV1>(buffer_params_resource); CreateCommon(buffer_params, client, width, height, format, flags); } void CreateImmed(wl_client* client, wl_resource* buffer_params_resource, uint32_t buffer_id, int32_t width, int32_t height, uint32_t format, uint32_t flags) { auto* buffer_params = GetUserDataAs<TestZwpLinuxBufferParamsV1>(buffer_params_resource); CreateCommon(buffer_params, client, width, height, format, flags); } } // namespace const struct zwp_linux_buffer_params_v1_interface kTestZwpLinuxBufferParamsV1Impl = {&DestroyResource, &Add, &Create, &CreateImmed}; TestZwpLinuxBufferParamsV1::TestZwpLinuxBufferParamsV1(wl_resource* resource) : ServerObject(resource) {} TestZwpLinuxBufferParamsV1::~TestZwpLinuxBufferParamsV1() { DCHECK(linux_dmabuf_); linux_dmabuf_->OnBufferParamsDestroyed(this); } void TestZwpLinuxBufferParamsV1::SetZwpLinuxDmabuf( MockZwpLinuxDmabufV1* linux_dmabuf) { DCHECK(!linux_dmabuf_); linux_dmabuf_ = linux_dmabuf; } void TestZwpLinuxBufferParamsV1::SetBufferResource(wl_resource* resource) { DCHECK(!buffer_resource_); buffer_resource_ = resource; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.cc
C++
unknown
2,852
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_BUFFER_PARAMS_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_BUFFER_PARAMS_H_ #include <linux-dmabuf-unstable-v1-server-protocol.h> #include "base/files/scoped_file.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zwp_linux_buffer_params_v1_interface kTestZwpLinuxBufferParamsV1Impl; class MockZwpLinuxDmabufV1; // Manage zwp_linux_buffer_params_v1 class TestZwpLinuxBufferParamsV1 : public ServerObject { public: explicit TestZwpLinuxBufferParamsV1(wl_resource* resource); TestZwpLinuxBufferParamsV1(const TestZwpLinuxBufferParamsV1&) = delete; TestZwpLinuxBufferParamsV1& operator=(const TestZwpLinuxBufferParamsV1&) = delete; ~TestZwpLinuxBufferParamsV1() override; void Destroy(wl_client* client, wl_resource* resource); void Add(wl_client* client, wl_resource* resource, int32_t fd, uint32_t plane_idx, uint32_t offset, uint32_t stride, uint32_t modifier_hi, uint32_t modifier_lo); void Create(wl_client* client, wl_resource* resource, int32_t width, int32_t height, uint32_t format, uint32_t flags); void CreateImmed(wl_client* client, wl_resource* resource, uint32_t buffer_id, int32_t width, int32_t height, uint32_t format, uint32_t flags); wl_resource* buffer_resource() const { return buffer_resource_; } void SetZwpLinuxDmabuf(MockZwpLinuxDmabufV1* linux_dmabuf); void SetBufferResource(wl_resource* resource); std::vector<base::ScopedFD> fds_; uint32_t modifier_hi_ = 0; uint32_t modifier_lo_ = 0; private: // Non-owned pointer to the linux dmabuf object, which created this params // resource and holds a pointer to it. On destruction, must notify it about // going out of scope. raw_ptr<MockZwpLinuxDmabufV1> linux_dmabuf_ = nullptr; // A buffer resource, which is created on Create or CreateImmed call. Can be // null if not created/failed to be created. raw_ptr<wl_resource> buffer_resource_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_BUFFER_PARAMS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h
C++
unknown
2,623
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zwp_linux_explicit_synchronization.h" #include <linux-explicit-synchronization-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include "base/check.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" namespace wl { namespace { constexpr uint32_t kLinuxExplicitSynchronizationVersion = 1; void GetSynchronization(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface_resource) { CreateResourceWithImpl<TestLinuxSurfaceSynchronization>( client, &zwp_linux_surface_synchronization_v1_interface, 1, &kMockZwpLinuxSurfaceSynchronizationImpl, id, surface_resource); } } // namespace const struct zwp_linux_explicit_synchronization_v1_interface kTestLinuxExplicitSynchronizationImpl = {DestroyResource, GetSynchronization}; TestLinuxSurfaceSynchronization::TestLinuxSurfaceSynchronization( wl_resource* resource, wl_resource* surface_resource) : ServerObject(resource), surface_resource_(surface_resource) {} TestLinuxSurfaceSynchronization::~TestLinuxSurfaceSynchronization() = default; TestZwpLinuxExplicitSynchronizationV1::TestZwpLinuxExplicitSynchronizationV1() : GlobalObject(&zwp_linux_explicit_synchronization_v1_interface, &kTestLinuxExplicitSynchronizationImpl, kLinuxExplicitSynchronizationVersion) {} TestZwpLinuxExplicitSynchronizationV1:: ~TestZwpLinuxExplicitSynchronizationV1() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_linux_explicit_synchronization.cc
C++
unknown
1,760
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { class TestLinuxSurfaceSynchronization : public ServerObject { public: TestLinuxSurfaceSynchronization(wl_resource* resource, wl_resource* surface_resource); ~TestLinuxSurfaceSynchronization() override; wl_resource* surface_resource() const { return surface_resource_; } private: raw_ptr<wl_resource> surface_resource_; }; // Manage wl_viewporter object. class TestZwpLinuxExplicitSynchronizationV1 : public GlobalObject { public: TestZwpLinuxExplicitSynchronizationV1(); ~TestZwpLinuxExplicitSynchronizationV1() override; TestZwpLinuxExplicitSynchronizationV1( const TestZwpLinuxExplicitSynchronizationV1& rhs) = delete; TestZwpLinuxExplicitSynchronizationV1& operator=( const TestZwpLinuxExplicitSynchronizationV1& rhs) = delete; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_linux_explicit_synchronization.h
C++
unknown
1,384
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zwp_primary_selection.h" #include <primary-selection-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include <cstdint> #include <memory> #include "base/memory/raw_ptr.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" // ZwpPrimarySelection* classes contain protocol-specific implementation of // TestSelection*::Delegate interfaces, such that primary selection test // cases may be set-up and run against test wayland compositor. namespace wl { namespace { void Destroy(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } struct ZwpPrimarySelectionOffer final : public TestSelectionOffer::Delegate { void SendOffer(const std::string& mime_type) override { zwp_primary_selection_offer_v1_send_offer(offer->resource(), mime_type.c_str()); } raw_ptr<TestSelectionOffer> offer = nullptr; }; struct ZwpPrimarySelectionDevice final : public TestSelectionDevice::Delegate { TestSelectionOffer* CreateAndSendOffer() override { static const struct zwp_primary_selection_offer_v1_interface kOfferImpl = { &TestSelectionOffer::Receive, &Destroy}; wl_resource* device_resource = device->resource(); const int version = wl_resource_get_version(device_resource); auto owned_delegate = std::make_unique<ZwpPrimarySelectionOffer>(); auto* delegate = owned_delegate.get(); wl_resource* new_offer_resource = CreateResourceWithImpl<TestSelectionOffer>( wl_resource_get_client(device->resource()), &zwp_primary_selection_offer_v1_interface, version, &kOfferImpl, 0, std::move(owned_delegate)); delegate->offer = GetUserDataAs<TestSelectionOffer>(new_offer_resource); zwp_primary_selection_device_v1_send_data_offer(device_resource, new_offer_resource); return delegate->offer; } void SendSelection(TestSelectionOffer* offer) override { CHECK(offer); zwp_primary_selection_device_v1_send_selection(device->resource(), offer->resource()); } void HandleSetSelection(TestSelectionSource* source, uint32_t serial) override { NOTIMPLEMENTED(); } raw_ptr<TestSelectionDevice> device = nullptr; }; struct ZwpPrimarySelectionSource : public TestSelectionSource::Delegate { void SendSend(const std::string& mime_type, base::ScopedFD write_fd) override { zwp_primary_selection_source_v1_send_send( source->resource(), mime_type.c_str(), write_fd.get()); wl_client_flush(wl_resource_get_client(source->resource())); } void SendFinished() override { NOTREACHED() << "The interface does not support this method."; } void SendCancelled() override { zwp_primary_selection_source_v1_send_cancelled(source->resource()); } void SendDndAction(uint32_t action) override { NOTREACHED() << "The interface does not support this method."; } raw_ptr<TestSelectionSource> source = nullptr; }; struct ZwpPrimarySelectionDeviceManager : public TestSelectionDeviceManager::Delegate { explicit ZwpPrimarySelectionDeviceManager(uint32_t version) : version_(version) {} ~ZwpPrimarySelectionDeviceManager() override = default; TestSelectionDevice* CreateDevice(wl_client* client, uint32_t id) override { static const struct zwp_primary_selection_device_v1_interface kTestSelectionDeviceImpl = {&TestSelectionDevice::SetSelection, &Destroy}; auto owned_delegate = std::make_unique<ZwpPrimarySelectionDevice>(); auto* delegate = owned_delegate.get(); wl_resource* resource = CreateResourceWithImpl<TestSelectionDevice>( client, &zwp_primary_selection_device_v1_interface, version_, &kTestSelectionDeviceImpl, id, std::move(owned_delegate)); delegate->device = GetUserDataAs<TestSelectionDevice>(resource); return delegate->device; } TestSelectionSource* CreateSource(wl_client* client, uint32_t id) override { static const struct zwp_primary_selection_source_v1_interface kTestSelectionSourceImpl = {&TestSelectionSource::Offer, &Destroy}; auto owned_delegate = std::make_unique<ZwpPrimarySelectionSource>(); auto* delegate = owned_delegate.get(); wl_resource* resource = CreateResourceWithImpl<TestSelectionSource>( client, &zwp_primary_selection_source_v1_interface, version_, &kTestSelectionSourceImpl, id, std::move(owned_delegate)); delegate->source = GetUserDataAs<TestSelectionSource>(resource); return delegate->source; } private: const uint32_t version_; }; } // namespace std::unique_ptr<TestSelectionDeviceManager> CreateTestSelectionManagerZwp() { constexpr uint32_t kVersion = 1; static const struct zwp_primary_selection_device_manager_v1_interface kTestSelectionManagerImpl = {&TestSelectionDeviceManager::CreateSource, &TestSelectionDeviceManager::GetDevice, &Destroy}; static const TestSelectionDeviceManager::InterfaceInfo interface_info = { .interface = &zwp_primary_selection_device_manager_v1_interface, .implementation = &kTestSelectionManagerImpl, .version = kVersion}; return std::make_unique<TestSelectionDeviceManager>( interface_info, std::make_unique<ZwpPrimarySelectionDeviceManager>(kVersion)); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_primary_selection.cc
C++
unknown
5,738
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_PRIMARY_SELECTION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_PRIMARY_SELECTION_H_ #include <memory> #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" namespace wl { std::unique_ptr<TestSelectionDeviceManager> CreateTestSelectionManagerZwp(); } #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_PRIMARY_SELECTION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_primary_selection.h
C++
unknown
545
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zwp_text_input_manager.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h" namespace wl { namespace { constexpr uint32_t kTextInputManagerVersion = 1; void CreateTextInput(struct wl_client* client, struct wl_resource* resource, uint32_t id) { wl_resource* text_resource = CreateResourceWithImpl<MockZwpTextInput>( client, &zwp_text_input_v1_interface, wl_resource_get_version(resource), &kMockZwpTextInputV1Impl, id); GetUserDataAs<TestZwpTextInputManagerV1>(resource)->set_text_input( GetUserDataAs<MockZwpTextInput>(text_resource)); } } // namespace const struct zwp_text_input_manager_v1_interface kTestZwpTextInputManagerV1Impl = { &CreateTextInput, // create_text_input }; TestZwpTextInputManagerV1::TestZwpTextInputManagerV1() : GlobalObject(&zwp_text_input_manager_v1_interface, &kTestZwpTextInputManagerV1Impl, kTextInputManagerVersion) {} TestZwpTextInputManagerV1::~TestZwpTextInputManagerV1() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_text_input_manager.cc
C++
unknown
1,303
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_ #include <text-input-unstable-v1-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct zwp_text_input_manager_v1_interface kTestZwpTextInputManagerV1Impl; class MockZwpTextInput; // Manage zwp_text_input_manager_v1 object. class TestZwpTextInputManagerV1 : public GlobalObject { public: TestZwpTextInputManagerV1(); TestZwpTextInputManagerV1(const TestZwpTextInputManagerV1&) = delete; TestZwpTextInputManagerV1& operator=(const TestZwpTextInputManagerV1&) = delete; ~TestZwpTextInputManagerV1() override; void set_text_input(MockZwpTextInput* text_input) { text_input_ = text_input; } MockZwpTextInput* text_input() const { return text_input_; } private: raw_ptr<MockZwpTextInput> text_input_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zwp_text_input_manager.h
C++
unknown
1,219
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zxdg_output.h" #include <xdg-output-unstable-v1-server-protocol.h> #include "ui/base/wayland/wayland_display_util.h" #include "ui/ozone/platform/wayland/test/test_output_metrics.h" namespace wl { TestZXdgOutput::TestZXdgOutput(wl_resource* resource) : ServerObject(resource) {} TestZXdgOutput::~TestZXdgOutput() = default; void TestZXdgOutput::Flush(const TestOutputMetrics& metrics) { zxdg_output_v1_send_logical_size(resource(), metrics.xdg_logical_size.width(), metrics.xdg_logical_size.height()); zxdg_output_v1_send_logical_position(resource(), metrics.xdg_logical_origin.x(), metrics.xdg_logical_origin.y()); } const struct zxdg_output_v1_interface kTestZXdgOutputImpl = { &DestroyResource, }; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zxdg_output.cc
C++
unknown
1,042
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_H_ #include <wayland-client-protocol.h> #include <xdg-output-unstable-v1-server-protocol.h> #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/size.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct zxdg_output_v1_interface kTestZXdgOutputImpl; struct TestOutputMetrics; // Handles the server-side representation of the zxdg_output. class TestZXdgOutput : public ServerObject { public: explicit TestZXdgOutput(wl_resource* resource); TestZXdgOutput(const TestZXdgOutput&) = delete; TestZXdgOutput& operator=(const TestZXdgOutput&) = delete; ~TestZXdgOutput() override; // Called by the owning wl_output as part of its Flush() operation that // propagates the current state of `metrics_` to clients. void Flush(const TestOutputMetrics& metrics); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zxdg_output.h
C++
unknown
1,188
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_zxdg_output_manager.h" #include <xdg-output-unstable-v1-server-protocol.h> #include "ui/ozone/platform/wayland/test/test_output.h" #include "ui/ozone/platform/wayland/test/test_zxdg_output.h" namespace wl { namespace { constexpr uint32_t kZXdgOutputManagerVersion = 3; constexpr uint32_t kZXdgOutputVersion = 3; void GetXdgOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* output_resource) { wl_resource* zxdg_output_resource = CreateResourceWithImpl<TestZXdgOutput>( client, &zxdg_output_v1_interface, kZXdgOutputVersion, &kTestZXdgOutputImpl, id); auto* output = GetUserDataAs<TestOutput>(output_resource); output->SetXdgOutput(GetUserDataAs<TestZXdgOutput>(zxdg_output_resource)); } const struct zxdg_output_manager_v1_interface kTestZXdgOutputManagerImpl = { &DestroyResource, &GetXdgOutput, }; } // namespace TestZXdgOutputManager::TestZXdgOutputManager() : GlobalObject(&zxdg_output_manager_v1_interface, &kTestZXdgOutputManagerImpl, kZXdgOutputManagerVersion) {} TestZXdgOutputManager::~TestZXdgOutputManager() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zxdg_output_manager.cc
C++
unknown
1,396
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_MANAGER_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { class TestZXdgOutputManager : public GlobalObject { public: TestZXdgOutputManager(); TestZXdgOutputManager(const TestZXdgOutputManager&) = delete; TestZXdgOutputManager& operator=(const TestZXdgOutputManager&) = delete; ~TestZXdgOutputManager() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZXDG_OUTPUT_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_zxdg_output_manager.h
C++
unknown
714
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/wayland_drag_drop_test.h" #include <wayland-server-protocol.h> #include <wayland-util.h> #include <cstdint> #include "base/functional/callback.h" #include "base/task/single_thread_task_runner.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/geometry/point.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/test/mock_pointer.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/test_data_device.h" #include "ui/ozone/platform/wayland/test/test_data_device_manager.h" #include "ui/ozone/platform/wayland/test/test_data_offer.h" #include "ui/ozone/platform/wayland/test/test_data_source.h" #include "ui/ozone/platform/wayland/test/test_touch.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" using testing::_; namespace ui { TestWaylandOSExchangeDataProvideFactory:: TestWaylandOSExchangeDataProvideFactory() { SetInstance(this); } TestWaylandOSExchangeDataProvideFactory:: ~TestWaylandOSExchangeDataProvideFactory() { SetInstance(nullptr); } std::unique_ptr<OSExchangeDataProvider> TestWaylandOSExchangeDataProvideFactory::CreateProvider() { return std::make_unique<WaylandExchangeDataProvider>(); } WaylandDragDropTest::WaylandDragDropTest() = default; WaylandDragDropTest::~WaylandDragDropTest() = default; void WaylandDragDropTest::SendDndEnter(WaylandWindow* window, const gfx::Point& location) { const uint32_t surface_id = window->root_surface()->get_surface_id(); PostToServerAndWait( [surface_id, location](wl::TestWaylandServerThread* server) { auto* origin = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(origin); auto* data_device = server->data_device_manager()->data_device(); ASSERT_TRUE(data_device); data_device->SendOfferAndEnter(origin, location); }); } void WaylandDragDropTest::SendDndLeave() { PostToServerAndWait([](wl::TestWaylandServerThread* server) { server->data_device_manager()->data_device()->OnLeave(); }); } void WaylandDragDropTest::SendDndMotion(const gfx::Point& location) { PostToServerAndWait([location](wl::TestWaylandServerThread* server) { auto* data_source = server->data_device_manager()->data_source(); ASSERT_TRUE(data_source); wl_fixed_t x = wl_fixed_from_int(location.x()); wl_fixed_t y = wl_fixed_from_int(location.y()); server->data_device_manager()->data_device()->OnMotion( server->GetNextTime(), x, y); }); } void WaylandDragDropTest::SendDndDrop() { PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* data_source = server->data_device_manager()->data_source(); ASSERT_TRUE(data_source); data_source->OnFinished(); }); } void WaylandDragDropTest::SendDndCancelled() { PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* data_source = server->data_device_manager()->data_source(); ASSERT_TRUE(data_source); data_source->OnCancelled(); }); } void WaylandDragDropTest::SendDndAction(uint32_t action) { PostToServerAndWait([action](wl::TestWaylandServerThread* server) { auto* data_source = server->data_device_manager()->data_source(); ASSERT_TRUE(data_source); data_source->OnDndAction(action); }); } void WaylandDragDropTest::ReadAndCheckData(const std::string& mime_type, const std::string& expected_data) { PostToServerAndWait( [mime_type, expected_data](wl::TestWaylandServerThread* server) { auto* data_source = server->data_device_manager()->data_source(); ASSERT_TRUE(data_source); base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); auto read_callback = base::BindOnce( [](std::string expected_data, base::RunLoop* loop, std::vector<uint8_t>&& data) { std::string result(data.begin(), data.end()); EXPECT_EQ(expected_data, result); loop->Quit(); }, std::move(expected_data), &run_loop); data_source->ReadData(mime_type, std::move(read_callback)); run_loop.Run(); }); } void WaylandDragDropTest::SendPointerEnter( WaylandWindow* window, MockPlatformWindowDelegate* delegate) { const uint32_t surface_id = window->root_surface()->get_surface_id(); PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) { auto* surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(surface); auto* pointer = server->seat()->pointer(); ASSERT_TRUE(pointer); wl_pointer_send_enter(pointer->resource(), server->GetNextSerial(), surface->resource(), 0, 0); wl_pointer_send_frame(pointer->resource()); }); } void WaylandDragDropTest::SendPointerLeave( WaylandWindow* window, MockPlatformWindowDelegate* delegate) { const uint32_t surface_id = window->root_surface()->get_surface_id(); PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) { auto* surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(surface); auto* pointer = server->seat()->pointer(); ASSERT_TRUE(pointer); wl_pointer_send_leave(pointer->resource(), server->GetNextSerial(), surface->resource()); wl_pointer_send_frame(pointer->resource()); }); } void WaylandDragDropTest::SendPointerButton( WaylandWindow* window, MockPlatformWindowDelegate* delegate, int button, bool pressed) { PostToServerAndWait([pressed, button](wl::TestWaylandServerThread* server) { uint32_t state = pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED; auto* pointer = server->seat()->pointer(); ASSERT_TRUE(pointer); wl_pointer_send_button(pointer->resource(), server->GetNextSerial(), server->GetNextTime(), button, state); wl_pointer_send_frame(pointer->resource()); }); } void WaylandDragDropTest::SendTouchDown(WaylandWindow* window, MockPlatformWindowDelegate* delegate, int id, const gfx::Point& location) { const uint32_t surface_id = window->root_surface()->get_surface_id(); PostToServerAndWait( [surface_id, id, location](wl::TestWaylandServerThread* server) { auto* surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(surface); auto* touch = server->seat()->touch(); ASSERT_TRUE(touch); wl_touch_send_down(touch->resource(), server->GetNextSerial(), server->GetNextTime(), surface->resource(), id, wl_fixed_from_double(location.x()), wl_fixed_from_double(location.y())); wl_touch_send_frame(touch->resource()); }); } void WaylandDragDropTest::SendTouchUp(int id) { PostToServerAndWait([id](wl::TestWaylandServerThread* server) { auto* touch = server->seat()->touch(); ASSERT_TRUE(touch); wl_touch_send_up(touch->resource(), server->GetNextSerial(), server->GetNextTime(), id); wl_touch_send_frame(touch->resource()); }); } void WaylandDragDropTest::SendTouchMotion(WaylandWindow* window, MockPlatformWindowDelegate* delegate, int id, const gfx::Point& location) { PostToServerAndWait([id, location](wl::TestWaylandServerThread* server) { auto* touch = server->seat()->touch(); ASSERT_TRUE(touch); wl_touch_send_motion(touch->resource(), server->GetNextSerial(), id, wl_fixed_from_double(location.x()), wl_fixed_from_double(location.y())); wl_touch_send_frame(touch->resource()); }); } void WaylandDragDropTest::SetUp() { WaylandTest::SetUp(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { wl_seat_send_capabilities(server->seat()->resource(), WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH | WL_SEAT_CAPABILITY_KEYBOARD); ASSERT_TRUE(server->data_device_manager()); }); ASSERT_TRUE(connection_->seat()); ASSERT_TRUE(connection_->seat()->pointer()); ASSERT_TRUE(connection_->seat()->touch()); ASSERT_TRUE(connection_->seat()->keyboard()); } void WaylandDragDropTest::ScheduleTestTask(base::OnceClosure test_task) { scheduled_tasks_.emplace_back(std::move(test_task)); MaybeRunScheduledTasks(); } void WaylandDragDropTest::MaybeRunScheduledTasks() { if (is_task_running_ || scheduled_tasks_.empty()) return; is_task_running_ = true; auto next_task = std::move(scheduled_tasks_.front()); scheduled_tasks_.erase(scheduled_tasks_.begin()); base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&WaylandDragDropTest::RunTestTask, base::Unretained(this), std::move(next_task))); } void WaylandDragDropTest::RunTestTask(base::OnceClosure test_task) { ASSERT_TRUE(is_task_running_); std::move(test_task).Run(); is_task_running_ = false; MaybeRunScheduledTasks(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/wayland_drag_drop_test.cc
C++
unknown
9,769
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_DRAG_DROP_TEST_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_DRAG_DROP_TEST_H_ #include <cstdint> #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h" #include "ui/ozone/platform/wayland/test/wayland_test.h" namespace gfx { class Point; } namespace ui { class WaylandWindow; class TestWaylandOSExchangeDataProvideFactory : public OSExchangeDataProviderFactoryOzone { public: TestWaylandOSExchangeDataProvideFactory(); ~TestWaylandOSExchangeDataProvideFactory() override; std::unique_ptr<OSExchangeDataProvider> CreateProvider() override; }; // Base class for Wayland drag-and-drop tests. Public methods allow test code to // emulate dnd-related events from the test compositor and can be used in both // data and window dragging test cases. class WaylandDragDropTest : public WaylandTest { public: WaylandDragDropTest(); WaylandDragDropTest(const WaylandDragDropTest&) = delete; WaylandDragDropTest& operator=(const WaylandDragDropTest&) = delete; ~WaylandDragDropTest() override; // These are public for convenience, as they must be callable from lambda // functions, usually posted to task queue while the drag loop runs. void SendDndEnter(WaylandWindow* window, const gfx::Point& location); void SendDndLeave(); void SendDndMotion(const gfx::Point& location); void SendDndDrop(); void SendDndCancelled(); void SendDndAction(uint32_t action); void ReadAndCheckData(const std::string& mime_type, const std::string& expected_data); virtual void SendPointerEnter(WaylandWindow* window, MockPlatformWindowDelegate* delegate); virtual void SendPointerLeave(WaylandWindow* window, MockPlatformWindowDelegate* delegate); virtual void SendPointerButton(WaylandWindow* window, MockPlatformWindowDelegate* delegate, int button, bool pressed); virtual void SendTouchDown(WaylandWindow* window, MockPlatformWindowDelegate* delegate, int id, const gfx::Point& location); virtual void SendTouchUp(int id); virtual void SendTouchMotion(WaylandWindow* window, MockPlatformWindowDelegate* delegate, int id, const gfx::Point& location); protected: // WaylandTest: void SetUp() override; void ScheduleTestTask(base::OnceClosure test_task); WaylandWindowManager* window_manager() const { return connection_->window_manager(); } private: void MaybeRunScheduledTasks(); void RunTestTask(base::OnceClosure test_task); TestWaylandOSExchangeDataProvideFactory os_exchange_factory_; // This is used to ensure FIFO of tasks and that they complete to run before // a next task is posted. bool is_task_running_ = false; std::vector<base::OnceClosure> scheduled_tasks_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_DRAG_DROP_TEST_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/wayland_drag_drop_test.h
C++
unknown
3,436
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/wayland_test.h" #include <memory> #include "base/run_loop.h" #include "ui/base/ui_base_features.h" #include "ui/events/devices/device_data_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/scoped_keyboard_layout_engine.h" #include "ui/ozone/common/features.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_screen.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/scoped_wl_array.h" #include "ui/ozone/platform/wayland/test/test_keyboard.h" #include "ui/ozone/platform/wayland/test/test_util.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include "ui/platform_window/platform_window_init_properties.h" #if BUILDFLAG(USE_XKBCOMMON) #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" #else #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #endif using ::testing::_; using ::testing::SaveArg; namespace ui { WaylandTestBase::WaylandTestBase(wl::ServerConfig config) : task_environment_(base::test::TaskEnvironment::MainThreadType::UI, base::test::TaskEnvironment::TimeSource::MOCK_TIME), server_(config) { #if BUILDFLAG(USE_XKBCOMMON) auto keyboard_layout_engine = std::make_unique<XkbKeyboardLayoutEngine>(xkb_evdev_code_converter_); #else auto keyboard_layout_engine = std::make_unique<StubKeyboardLayoutEngine>(); #endif scoped_keyboard_layout_engine_ = std::make_unique<ScopedKeyboardLayoutEngine>( std::move(keyboard_layout_engine)); connection_ = std::make_unique<WaylandConnection>(); buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>(); surface_factory_ = std::make_unique<WaylandSurfaceFactory>( connection_.get(), buffer_manager_gpu_.get()); } WaylandTestBase::~WaylandTestBase() = default; void WaylandTestBase::SetUp() { disabled_features_.push_back(ui::kWaylandSurfaceSubmissionInPixelCoordinates); disabled_features_.push_back(features::kWaylandScreenCoordinatesEnabled); feature_list_.InitWithFeatures(enabled_features_, disabled_features_); if (DeviceDataManager::HasInstance()) { // Another instance may have already been set before. DeviceDataManager::GetInstance()->ResetDeviceListsForTest(); } else { DeviceDataManager::CreateInstance(); } ASSERT_TRUE(server_.Start()); ASSERT_TRUE(connection_->Initialize()); screen_ = connection_->wayland_output_manager()->CreateWaylandScreen(); connection_->wayland_output_manager()->InitWaylandScreen(screen_.get()); EXPECT_CALL(delegate_, OnAcceleratedWidgetAvailable(_)) .WillOnce(SaveArg<0>(&widget_)); PlatformWindowInitProperties properties; properties.bounds = gfx::Rect(0, 0, 800, 600); properties.type = PlatformWindowType::kWindow; window_ = delegate_.CreateWaylandWindow(connection_.get(), std::move(properties)); ASSERT_NE(widget_, gfx::kNullAcceleratedWidget); window_->Show(false); // Wait for the client to flush all pending requests from initialization. wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); // The surface must be activated before buffers are attached. ActivateSurface(window_->root_surface()->get_surface_id()); EXPECT_EQ(0u, DeviceDataManager::GetInstance()->GetTouchscreenDevices().size()); EXPECT_EQ(0u, DeviceDataManager::GetInstance()->GetKeyboardDevices().size()); EXPECT_EQ(0u, DeviceDataManager::GetInstance()->GetMouseDevices().size()); EXPECT_EQ(0u, DeviceDataManager::GetInstance()->GetTouchpadDevices().size()); initialized_ = true; } void WaylandTestBase::TearDown() { if (initialized_) wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); } void WaylandTestBase::PostToServerAndWait( base::OnceCallback<void(wl::TestWaylandServerThread* server)> callback) { // Sync with the display to ensure client's requests are processed. wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); server_.RunAndWait(std::move(callback)); // Sync with the display to ensure server's events are received and processed. wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); } void WaylandTestBase::PostToServerAndWait(base::OnceClosure closure) { // Sync with the display to ensure client's requests are processed. wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); server_.RunAndWait(std::move(closure)); // Sync with the display to ensure server's events are received and processed wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); } void WaylandTestBase::DisableSyncOnTearDown() { initialized_ = false; } void WaylandTestBase::SetPointerFocusedWindow(WaylandWindow* window) { connection_->window_manager()->SetPointerFocusedWindow(window); } void WaylandTestBase::SetKeyboardFocusedWindow(WaylandWindow* window) { connection_->window_manager()->SetKeyboardFocusedWindow(window); } void WaylandTestBase::SendConfigureEvent(uint32_t surface_id, const gfx::Size& size, const wl::ScopedWlArray& states, absl::optional<uint32_t> serial) { PostToServerAndWait([size, surface_id, states, serial](wl::TestWaylandServerThread* server) { auto* surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(surface); auto* xdg_surface = surface->xdg_surface(); ASSERT_TRUE(xdg_surface); const int32_t width = size.width(); const int32_t height = size.height(); // In xdg_shell_v6+, both surfaces send serial configure event and toplevel // surfaces send other data like states, heights and widths. // Please note that toplevel surfaces may not exist if the surface was // created for the popup role. wl::ScopedWlArray surface_states(states); if (xdg_surface->xdg_toplevel()) { xdg_toplevel_send_configure(xdg_surface->xdg_toplevel()->resource(), width, height, surface_states.get()); } else { ASSERT_TRUE(xdg_surface->xdg_popup()->resource()); xdg_popup_send_configure(xdg_surface->xdg_popup()->resource(), 0, 0, width, height); } xdg_surface_send_configure( xdg_surface->resource(), serial.has_value() ? serial.value() : server->GetNextSerial()); }); } void WaylandTestBase::ActivateSurface(uint32_t surface_id, absl::optional<uint32_t> serial) { wl::ScopedWlArray state({XDG_TOPLEVEL_STATE_ACTIVATED}); SendConfigureEvent(surface_id, {0, 0}, state, serial); } void WaylandTestBase::InitializeSurfaceAugmenter() { PostToServerAndWait([](wl::TestWaylandServerThread* server) { server->EnsureSurfaceAugmenter(); }); } void WaylandTestBase::MaybeSetUpXkb() { #if BUILDFLAG(USE_XKBCOMMON) PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Set up XKB bits and set the keymap to the client. std::unique_ptr<xkb_context, ui::XkbContextDeleter> xkb_context( xkb_context_new(XKB_CONTEXT_NO_FLAGS)); std::unique_ptr<xkb_keymap, ui::XkbKeymapDeleter> xkb_keymap( xkb_keymap_new_from_names(xkb_context.get(), nullptr /*names*/, XKB_KEYMAP_COMPILE_NO_FLAGS)); std::unique_ptr<xkb_state, ui::XkbStateDeleter> xkb_state( xkb_state_new(xkb_keymap.get())); std::unique_ptr<char, base::FreeDeleter> keymap_string( xkb_keymap_get_as_string(xkb_keymap.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); ASSERT_TRUE(keymap_string.get()); size_t keymap_size = strlen(keymap_string.get()) + 1; base::UnsafeSharedMemoryRegion shared_keymap_region = base::UnsafeSharedMemoryRegion::Create(keymap_size); base::WritableSharedMemoryMapping shared_keymap = shared_keymap_region.Map(); base::subtle::PlatformSharedMemoryRegion platform_shared_keymap = base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( std::move(shared_keymap_region)); ASSERT_TRUE(shared_keymap.IsValid()); memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); auto* const keyboard = server->seat()->keyboard()->resource(); ASSERT_TRUE(keyboard); wl_keyboard_send_keymap(keyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, platform_shared_keymap.GetPlatformHandle().fd, keymap_size); }); #endif } void WaylandTestBase::WaitForAllDisplaysReady() { // First, make sure all outputs are created and are ready. base::RunLoop loop; base::RepeatingTimer timer; timer.Start( FROM_HERE, base::Milliseconds(1), base::BindLambdaForTesting([&]() { auto& outputs = connection_->wayland_output_manager()->GetAllOutputs(); for (auto& output : outputs) { // Displays are updated when the output is ready. if (!output.second->IsReady()) return; } return loop.Quit(); })); loop.Run(); // Secondly, make sure all events after 'done' are processed. wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); } std::unique_ptr<WaylandWindow> WaylandTestBase::CreateWaylandWindowWithParams( PlatformWindowType type, const gfx::Rect bounds, MockWaylandPlatformWindowDelegate* delegate, gfx::AcceleratedWidget parent_widget) { PlatformWindowInitProperties properties; properties.bounds = bounds; properties.type = type; properties.parent_widget = parent_widget; auto window = delegate->CreateWaylandWindow(connection_.get(), std::move(properties)); if (window) window->Show(false); return window; } WaylandTest::WaylandTest() : WaylandTestBase(GetParam()) {} WaylandTest::~WaylandTest() = default; void WaylandTest::SetUp() { WaylandTestBase::SetUp(); } void WaylandTest::TearDown() { WaylandTestBase::TearDown(); } bool WaylandTest::IsAuraShellEnabled() { return GetParam().enable_aura_shell == wl::EnableAuraShellProtocol::kEnabled; } WaylandTestSimple::WaylandTestSimple() : WaylandTestSimple(wl::ServerConfig{}) {} WaylandTestSimple::WaylandTestSimple(wl::ServerConfig config) : WaylandTestBase(config) {} WaylandTestSimple::~WaylandTestSimple() = default; void WaylandTestSimple::SetUp() { WaylandTestBase::SetUp(); } void WaylandTestSimple::TearDown() { WaylandTestBase::TearDown(); } WaylandTestSimpleWithAuraShell::WaylandTestSimpleWithAuraShell() : WaylandTestBase( {.enable_aura_shell = wl::EnableAuraShellProtocol::kEnabled}) {} WaylandTestSimpleWithAuraShell::~WaylandTestSimpleWithAuraShell() = default; void WaylandTestSimpleWithAuraShell::SetUp() { WaylandTestBase::SetUp(); } void WaylandTestSimpleWithAuraShell ::TearDown() { WaylandTestBase::TearDown(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/wayland_test.cc
C++
unknown
11,245
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_TEST_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_TEST_H_ #include <memory> #include "base/memory/raw_ptr.h" #include "base/test/bind.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/buildflags.h" #include "ui/base/ui_base_features.h" #include "ui/events/ozone/layout/keyboard_layout_engine.h" #include "ui/ozone/common/features.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/test/mock_wayland_platform_window_delegate.h" #include "ui/ozone/platform/wayland/test/scoped_wl_array.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #if BUILDFLAG(USE_XKBCOMMON) #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" #endif namespace ui { class ScopedKeyboardLayoutEngine; class WaylandScreen; // WaylandTest is a base class that sets up a display, window, and test server, // and allows easy synchronization between them. class WaylandTestBase { public: explicit WaylandTestBase(wl::ServerConfig config); WaylandTestBase(const WaylandTestBase&) = delete; WaylandTestBase& operator=(const WaylandTestBase&) = delete; ~WaylandTestBase(); void SetUp(); void TearDown(); // Posts 'callback' or 'closure' to run on the client thread; blocks till the // callable is run and all pending Wayland requests and events are delivered. void PostToServerAndWait( base::OnceCallback<void(wl::TestWaylandServerThread* server)> callback); void PostToServerAndWait(base::OnceClosure closure); // Similar to the two methods above, but provides the convenience of using a // capturing lambda directly. template < typename Lambda, typename = std::enable_if_t< std::is_invocable_r_v<void, Lambda, wl::TestWaylandServerThread*> || std::is_invocable_r_v<void, Lambda>>> void PostToServerAndWait(Lambda&& lambda) { PostToServerAndWait(base::BindLambdaForTesting(std::move(lambda))); } protected: // Disables client-server sync during the teardown. Used by tests that // intentionally spoil the client-server communication. void DisableSyncOnTearDown(); void SetPointerFocusedWindow(WaylandWindow* window); void SetKeyboardFocusedWindow(WaylandWindow* window); // Sends configure event for the |surface_id|. Please note that |surface_id| // must be an id of the wl_surface that has xdg_surface role. void SendConfigureEvent(uint32_t surface_id, const gfx::Size& size, const wl::ScopedWlArray& states, absl::optional<uint32_t> serial = absl::nullopt); // Sends XDG_TOPLEVEL_STATE_ACTIVATED to the surface that has |surface_id| and // has xdg surface role with width and height set to 0, which results in // asking the client to set the width and height of the surface. The client // test may pass |serial| that will be used to activate the surface. void ActivateSurface(uint32_t surface_id, absl::optional<uint32_t> serial = absl::nullopt); // Initializes SurfaceAugmenter in |server_|. void InitializeSurfaceAugmenter(); // A helper method that sets up the XKB configuration for tests that require // it. // Does nothing if XkbCommon is not used. void MaybeSetUpXkb(); // A helper method to ensure that information for all displays are populated // and ready. void WaitForAllDisplaysReady(); // Creates a Wayland window with the specified delegate, type, and bounds. std::unique_ptr<WaylandWindow> CreateWaylandWindowWithParams( PlatformWindowType type, const gfx::Rect bounds, MockWaylandPlatformWindowDelegate* delegate, gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget); base::test::TaskEnvironment task_environment_; wl::TestWaylandServerThread server_; ::testing::NiceMock<MockWaylandPlatformWindowDelegate> delegate_; std::unique_ptr<ScopedKeyboardLayoutEngine> scoped_keyboard_layout_engine_; std::unique_ptr<WaylandSurfaceFactory> surface_factory_; std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_gpu_; std::unique_ptr<WaylandConnection> connection_; std::unique_ptr<WaylandScreen> screen_; std::unique_ptr<WaylandWindow> window_; gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; std::vector<base::test::FeatureRef> enabled_features_{ features::kLacrosColorManagement, ui::kWaylandOverlayDelegation}; std::vector<base::test::FeatureRef> disabled_features_; private: bool initialized_ = false; #if BUILDFLAG(USE_XKBCOMMON) XkbEvdevCodes xkb_evdev_code_converter_; #endif std::unique_ptr<KeyboardLayoutEngine> keyboard_layout_engine_; base::test::ScopedFeatureList feature_list_; }; // Version of WaylandTestBase that uses parametrised tests (TEST_P). class WaylandTest : public WaylandTestBase, public ::testing::TestWithParam<wl::ServerConfig> { public: WaylandTest(); WaylandTest(const WaylandTest&) = delete; WaylandTest& operator=(const WaylandTest&) = delete; ~WaylandTest() override; void SetUp() override; void TearDown() override; bool IsAuraShellEnabled(); }; // Version of WaylandTest that uses simple test fixtures (TEST_F). class WaylandTestSimple : public WaylandTestBase, public ::testing::Test { public: WaylandTestSimple(); explicit WaylandTestSimple(wl::ServerConfig); WaylandTestSimple(const WaylandTestSimple&) = delete; WaylandTestSimple& operator=(const WaylandTestSimple&) = delete; ~WaylandTestSimple() override; void SetUp() override; void TearDown() override; }; // Version of WaylandTest that uses simple test fixtures (TEST_F) and // aura_shell enabled. class WaylandTestSimpleWithAuraShell : public WaylandTestBase, public ::testing::Test { public: WaylandTestSimpleWithAuraShell(); WaylandTestSimpleWithAuraShell(const WaylandTestSimple&) = delete; WaylandTestSimpleWithAuraShell& operator=(const WaylandTestSimple&) = delete; ~WaylandTestSimpleWithAuraShell() override; void SetUp() override; void TearDown() override; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_WAYLAND_TEST_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/wayland_test.h
C++
unknown
6,688
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/weston_test_ozone_ui_controls_test_helper.h" #include "base/memory/raw_ptr.h" #include <linux/input.h> #include "base/run_loop.h" #include "base/task/single_thread_task_runner.h" #include "ui/events/keycodes/dom/keycode_converter.h" #include "ui/events/keycodes/keyboard_code_conversion.h" #include "ui/ozone/platform/wayland/emulate/weston_test_input_emulate.h" #include "ui/ozone/platform/wayland/host/proxy/wayland_proxy.h" namespace wl { namespace { using ui_controls::DOWN; using ui_controls::LEFT; using ui_controls::MIDDLE; using ui_controls::MouseButton; using ui_controls::RIGHT; using ui_controls::UP; class WaylandGlobalEventWaiter : public WestonTestInputEmulate::Observer { public: enum class WaylandEventType { kMotion, kButton, kKey, kTouch, kUnknown, }; WaylandGlobalEventWaiter(WaylandEventType event_type, WestonTestInputEmulate* emulate) : event_type_(event_type), emulate_(emulate) { Initialize(); } WaylandGlobalEventWaiter(WaylandEventType event_type, int button, bool pressed, WestonTestInputEmulate* emulate) : event_type_(event_type), emulate_(emulate), button_or_key_(button), pressed_(pressed) { Initialize(); } ~WaylandGlobalEventWaiter() override = default; // This method assumes that a request has already been queued, with metadata // for the expected response stored on the WaylandGlobalEventWaiter. This: // * Flushes queued requests. // * Spins a nested run loop waiting for the expected response (event). // * When the event is received, synchronously flushes all pending // requests and events via wl_display_roundtrip_queue. See // https://crbug.com/1336706#c11 for why this is necessary. // * Dispatches the QuitClosure to avoid re-entrancy. void Wait() { // There's no guarantee that a flush has been scheduled. Given that we're // waiting for a response, we must manually flush. wl::WaylandProxy::GetInstance()->FlushForTesting(); // We disallow nestable tasks as that can result in re-entrancy if the test // is listening for side-effects from a wayland-event and then calls // PostTask. By using a non-nestable run loop we are relying on the // assumption that the ozone-wayland implementation does not rely on // PostTask. base::RunLoop run_loop; // This will be invoked causing the run-loop to quit once the expected event // is received. quit_closure_ = run_loop.QuitClosure(); run_loop.Run(); } private: void Initialize() { DCHECK_NE(event_type_, WaylandEventType::kUnknown); emulate_->AddObserver(this); } void OnPointerMotionGlobal(const gfx::Point& screen_position) override { if (event_type_ == WaylandEventType::kMotion) { QuitRunLoop(); } } void OnPointerButtonGlobal(int32_t button, bool pressed) override { if (event_type_ == WaylandEventType::kButton && button_or_key_ == button && pressed == pressed_) { QuitRunLoop(); } } void OnKeyboardKey(int32_t key, bool pressed) override { if (event_type_ == WaylandEventType::kKey && button_or_key_ == key && pressed == pressed_) { QuitRunLoop(); } } void OnTouchReceived(const gfx::Point& screen_position) override { if (event_type_ == WaylandEventType::kTouch) { QuitRunLoop(); } } void QuitRunLoop() { // Immediately remove the observer so that no further callbacks are posted. emulate_->RemoveObserver(this); // The weston-test protocol does not map cleanly onto ui controls semantics. // We need to wait for a wayland round-trip to ensure that all side-effects // have been processed. See https://crbug.com/1336706#c11 for details. wl::WaylandProxy::GetInstance()->RoundTripQueue(); // We're in a nested run-loop that doesn't support re-entrancy. Directly // invoke the quit closure. std::move(quit_closure_).Run(); } // Expected event type. WaylandEventType event_type_ = WaylandEventType::kUnknown; // Internal closure used to quit the nested run loop. base::RepeatingClosure quit_closure_; const raw_ptr<WestonTestInputEmulate> emulate_; // Expected button or key. int button_or_key_ = -1; // Expected key or button to be pressed or depressed. bool pressed_ = false; }; } // namespace WestonTestOzoneUIControlsTestHelper::WestonTestOzoneUIControlsTestHelper() : input_emulate_(std::make_unique<WestonTestInputEmulate>()) {} WestonTestOzoneUIControlsTestHelper::~WestonTestOzoneUIControlsTestHelper() = default; void WestonTestOzoneUIControlsTestHelper::Reset() { input_emulate_->Reset(); } bool WestonTestOzoneUIControlsTestHelper::SupportsScreenCoordinates() const { #if BUILDFLAG(IS_CHROMEOS_LACROS) return true; #else return false; #endif } unsigned WestonTestOzoneUIControlsTestHelper::ButtonDownMask() const { return button_down_mask_; } void WestonTestOzoneUIControlsTestHelper::SendKeyEvents( gfx::AcceleratedWidget widget, ui::KeyboardCode key, int key_event_types, int accelerator_state, base::OnceClosure closure) { if (key_event_types & ui_controls::kKeyPress) { SendKeyPressInternal(widget, key, accelerator_state, key_event_types & ui_controls::kKeyRelease ? base::OnceClosure() : std::move(closure), true); } if (key_event_types & ui_controls::kKeyRelease) { SendKeyPressInternal(widget, key, accelerator_state, std::move(closure), false); } } void WestonTestOzoneUIControlsTestHelper::SendMouseMotionNotifyEvent( gfx::AcceleratedWidget widget, const gfx::Point& mouse_loc, const gfx::Point& mouse_screen_loc, base::OnceClosure closure) { WaylandGlobalEventWaiter waiter( WaylandGlobalEventWaiter::WaylandEventType::kMotion, input_emulate_.get()); input_emulate_->EmulatePointerMotion(widget, mouse_loc, mouse_screen_loc); waiter.Wait(); if (!closure.is_null()) { // PostTask to avoid re-entrancy. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(closure)); } } void WestonTestOzoneUIControlsTestHelper::SendMouseEvent( gfx::AcceleratedWidget widget, ui_controls::MouseButton type, int button_state, int accelerator_state, const gfx::Point& mouse_loc, const gfx::Point& mouse_screen_loc, base::OnceClosure closure) { uint32_t changed_button = 0; switch (type) { case LEFT: changed_button = BTN_LEFT; break; case MIDDLE: changed_button = BTN_MIDDLE; break; case RIGHT: changed_button = BTN_RIGHT; break; default: NOTREACHED(); } #if !BUILDFLAG(IS_CHROMEOS_LACROS) SendMouseMotionNotifyEvent(widget, mouse_loc, mouse_screen_loc, {}); #endif // Press accelerator keys. if (accelerator_state) { SendKeyPressInternal(widget, ui::KeyboardCode::VKEY_UNKNOWN, accelerator_state, {}, true); } if (button_state & DOWN) { WaylandGlobalEventWaiter waiter( WaylandGlobalEventWaiter::WaylandEventType::kButton, changed_button, /*pressed=*/true, input_emulate_.get()); input_emulate_->EmulatePointerButton( widget, ui::EventType::ET_MOUSE_PRESSED, changed_button); button_down_mask_ |= changed_button; waiter.Wait(); } if (button_state & UP) { WaylandGlobalEventWaiter waiter( WaylandGlobalEventWaiter::WaylandEventType::kButton, changed_button, /*pressed=*/false, input_emulate_.get()); input_emulate_->EmulatePointerButton( widget, ui::EventType::ET_MOUSE_RELEASED, changed_button); button_down_mask_ = (button_down_mask_ | changed_button) ^ changed_button; waiter.Wait(); } // Depress accelerator keys. if (accelerator_state) { SendKeyPressInternal(widget, ui::KeyboardCode::VKEY_UNKNOWN, accelerator_state, {}, false); } if (!closure.is_null()) { // PostTask to avoid re-entrancy. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(closure)); } } #if BUILDFLAG(IS_CHROMEOS_LACROS) void WestonTestOzoneUIControlsTestHelper::SendTouchEvent( gfx::AcceleratedWidget widget, int action, int id, const gfx::Point& touch_loc, base::OnceClosure closure) { // TODO(rivr): ui_controls::TouchType is a bitmask, do we need to handle the // case where multiple actions are requested together? ui::EventType event_type; switch (action) { case ui_controls::kTouchPress: event_type = ui::EventType::ET_TOUCH_PRESSED; break; case ui_controls::kTouchRelease: event_type = ui::EventType::ET_TOUCH_RELEASED; break; default: event_type = ui::EventType::ET_TOUCH_MOVED; } WaylandGlobalEventWaiter waiter( WaylandGlobalEventWaiter::WaylandEventType::kTouch, input_emulate_.get()); input_emulate_->EmulateTouch(widget, event_type, id, touch_loc); waiter.Wait(); if (!closure.is_null()) { // PostTask to avoid re-entrancy. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(closure)); } } #endif void WestonTestOzoneUIControlsTestHelper::RunClosureAfterAllPendingUIEvents( base::OnceClosure closure) { NOTREACHED(); } bool WestonTestOzoneUIControlsTestHelper::MustUseUiControlsForMoveCursorTo() { return true; } void WestonTestOzoneUIControlsTestHelper::SendKeyPressInternal( gfx::AcceleratedWidget widget, ui::KeyboardCode key, int accelerator_state, base::OnceClosure closure, bool press_key) { auto dom_code = UsLayoutKeyboardCodeToDomCode(key); if (press_key) { if (accelerator_state & ui_controls::kControl) { DispatchKeyPress(widget, ui::EventType::ET_KEY_PRESSED, ui::DomCode::CONTROL_LEFT); } if (accelerator_state & ui_controls::kShift) { DispatchKeyPress(widget, ui::EventType::ET_KEY_PRESSED, ui::DomCode::SHIFT_LEFT); } if (accelerator_state & ui_controls::kAlt) { DispatchKeyPress(widget, ui::EventType::ET_KEY_PRESSED, ui::DomCode::ALT_LEFT); } DispatchKeyPress(widget, ui::EventType::ET_KEY_PRESSED, dom_code); } else { DispatchKeyPress(widget, ui::EventType::ET_KEY_RELEASED, dom_code); if (accelerator_state & ui_controls::kAlt) { DispatchKeyPress(/*widget=*/0, ui::EventType::ET_KEY_RELEASED, ui::DomCode::ALT_LEFT); } if (accelerator_state & ui_controls::kShift) { DispatchKeyPress(/*widget=*/0, ui::EventType::ET_KEY_RELEASED, ui::DomCode::SHIFT_LEFT); } if (accelerator_state & ui_controls::kControl) { DispatchKeyPress(/*widget=*/0, ui::EventType::ET_KEY_RELEASED, ui::DomCode::CONTROL_LEFT); } } if (!closure.is_null()) { // PostTask to avoid re-entrancy. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(closure)); } } void WestonTestOzoneUIControlsTestHelper::DispatchKeyPress( gfx::AcceleratedWidget widget, ui::EventType event_type, ui::DomCode dom_code) { WaylandGlobalEventWaiter waiter( WaylandGlobalEventWaiter::WaylandEventType::kKey, ui::KeycodeConverter::DomCodeToEvdevCode(dom_code), /*press_key=*/event_type == ui::EventType::ET_KEY_PRESSED, input_emulate_.get()); input_emulate_->EmulateKeyboardKey(widget, event_type, dom_code); waiter.Wait(); } } // namespace wl namespace ui { OzoneUIControlsTestHelper* CreateOzoneUIControlsTestHelperWayland() { return new wl::WestonTestOzoneUIControlsTestHelper(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/weston_test_ozone_ui_controls_test_helper.cc
C++
unknown
12,095
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_WESTON_TEST_OZONE_UI_CONTROLS_TEST_HELPER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_WESTON_TEST_OZONE_UI_CONTROLS_TEST_HELPER_H_ #include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/types/event_type.h" #include "ui/ozone/public/ozone_ui_controls_test_helper.h" namespace wl { class WestonTestInputEmulate; class WestonTestOzoneUIControlsTestHelper : public ui::OzoneUIControlsTestHelper { public: WestonTestOzoneUIControlsTestHelper(); WestonTestOzoneUIControlsTestHelper( const WestonTestOzoneUIControlsTestHelper&) = delete; WestonTestOzoneUIControlsTestHelper& operator=( const WestonTestOzoneUIControlsTestHelper&) = delete; ~WestonTestOzoneUIControlsTestHelper() override; // OzoneUIControlsTestHelper: void Reset() override; bool SupportsScreenCoordinates() const override; unsigned ButtonDownMask() const override; void SendKeyEvents(gfx::AcceleratedWidget widget, ui::KeyboardCode key, int key_event_types, int accelerator_state, base::OnceClosure closure) override; void SendMouseMotionNotifyEvent(gfx::AcceleratedWidget widget, const gfx::Point& mouse_loc, const gfx::Point& mouse_loc_in_screen, base::OnceClosure closure) override; void SendMouseEvent(gfx::AcceleratedWidget widget, ui_controls::MouseButton type, int button_state, int accelerator_state, const gfx::Point& mouse_loc, const gfx::Point& mouse_loc_in_screen, base::OnceClosure closure) override; #if BUILDFLAG(IS_CHROMEOS_LACROS) void SendTouchEvent(gfx::AcceleratedWidget widget, int action, int id, const gfx::Point& touch_loc, base::OnceClosure closure) override; #endif void RunClosureAfterAllPendingUIEvents(base::OnceClosure closure) override; bool MustUseUiControlsForMoveCursorTo() override; private: // Sends either press or release key based |press_key| value. void SendKeyPressInternal(gfx::AcceleratedWidget widget, ui::KeyboardCode key, int accelerator_state, base::OnceClosure closure, bool press_key); void DispatchKeyPress(gfx::AcceleratedWidget widget, ui::EventType event_type, ui::DomCode key); unsigned button_down_mask_ = 0; std::unique_ptr<WestonTestInputEmulate> input_emulate_; }; } // namespace wl namespace ui { OzoneUIControlsTestHelper* CreateOzoneUIControlsTestHelperWayland(); } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_WESTON_TEST_OZONE_UI_CONTROLS_TEST_HELPER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/weston_test_ozone_ui_controls_test_helper.h
C++
unknown
3,119
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #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 "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_util.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" using testing::_; using testing::Truly; using testing::Values; namespace ui { namespace { using MockTerminateGpuCallback = base::MockCallback<base::OnceCallback<void(std::string)>>; constexpr gfx::Size kDefaultSize(1024, 768); constexpr uint32_t kAugmentedSurfaceNotSupportedVersion = 0; // TODO(msisov): add a test to exercise buffer management with non-default scale // once all the patches land. constexpr float kDefaultScale = 1.f; struct InputData { bool has_file = false; gfx::Size size; uint32_t planes_count = 0; std::vector<uint32_t> strides; std::vector<uint32_t> offsets; std::vector<uint64_t> modifiers; uint32_t format = 0; uint32_t buffer_id = 0; }; class MockSurfaceGpu : public WaylandSurfaceGpu { public: MockSurfaceGpu(WaylandBufferManagerGpu* buffer_manager, gfx::AcceleratedWidget widget) : buffer_manager_(buffer_manager), widget_(widget) { buffer_manager_->RegisterSurface(widget_, this); } MockSurfaceGpu(const MockSurfaceGpu&) = delete; MockSurfaceGpu& operator=(const MockSurfaceGpu&) = delete; ~MockSurfaceGpu() override { buffer_manager_->UnregisterSurface(widget_); } MOCK_METHOD3(OnSubmission, void(uint32_t buffer_id, const gfx::SwapResult& swap_result, gfx::GpuFenceHandle release_fence)); MOCK_METHOD2(OnPresentation, void(uint32_t buffer_id, const gfx::PresentationFeedback& feedback)); private: const raw_ptr<WaylandBufferManagerGpu> buffer_manager_; const gfx::AcceleratedWidget widget_; }; } // namespace class WaylandBufferManagerTest : public WaylandTest { public: WaylandBufferManagerTest() = default; WaylandBufferManagerTest(const WaylandBufferManagerTest&) = delete; WaylandBufferManagerTest& operator=(const WaylandBufferManagerTest&) = delete; ~WaylandBufferManagerTest() override = default; void SetUp() override { // Surface submission in pixel coordinates is only checked once on surface // creation and persisted, so we must make sure the configuration is done // before we create the surface. connection_->set_surface_submission_in_pixel_coordinates( GetParam().surface_submission_in_pixel_coordinates); connection_->set_supports_viewporter_surface_scaling( GetParam().supports_viewporter_surface_scaling); // Set this bug fix so that WaylandFrameManager does not use a freeze // counter. Otherwise, we won't be able to have a reliable test order of // frame submissions. This must be set before any window is created // (WaylandTest does that for us during the SetUp phase). server_.zaura_shell()->SetBugFixes({1358908}); WaylandTest::SetUp(); manager_host_ = connection_->buffer_manager_host(); EXPECT_TRUE(manager_host_); // Use the helper methods below, which automatically set the termination // callback and bind the interface again if the manager failed. manager_host_->SetTerminateGpuCallback(callback_.Get()); auto interface_ptr = manager_host_->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, /*supports_dma_buf=*/false, /*supports_viewporter=*/true, /*supports_acquire_fence=*/false, /*supports_overlays=*/true, kAugmentedSurfaceNotSupportedVersion); surface_id_ = window_->root_surface()->get_surface_id(); } void TearDown() override { // MockGpuSurface will unregister itself from the WaylandBuffermanagerGpu, // which will remove objects associated with this surface on another thread. // This run loop gives it a chance to do that. base::RunLoop().RunUntilIdle(); WaylandTest::TearDown(); } protected: void SendFrameCallbackForSurface(uint32_t surface_id) { PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(mock_surface); mock_surface->SendFrameCallback(); }); } // Might be null. Make sure to not manipulate the returned resource on the // client thread. Though, if the client does that, the server is able to catch // calls for libwayland-server on a wrong thread. wl_resource* GetSurfaceAttachedBuffer(uint32_t surface_id) { wl_resource* wl_buffer = nullptr; PostToServerAndWait( [&wl_buffer, surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id); ASSERT_TRUE(mock_surface); wl_buffer = mock_surface->attached_buffer(); }); return wl_buffer; } base::ScopedFD MakeFD() { base::FilePath temp_path; EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); auto file = base::File(temp_path, base::File::FLAG_READ | base::File::FLAG_WRITE | base::File::FLAG_CREATE_ALWAYS); return base::ScopedFD(file.TakePlatformFile()); } // Sets the terminate gpu callback expectation, calls OnChannelDestroyed, // sets the same callback again and re-establishes mojo connection again // for convenience. void SetTerminateCallbackExpectationAndDestroyChannel( MockTerminateGpuCallback* callback, bool fail) { channel_destroyed_error_message_.clear(); if (!fail) { // To avoid warning messages as "Expected to be never called, but has 0 // WillOnce()s", split the expecations based on the expected call times. EXPECT_CALL(*callback, Run(_)).Times(0); } else { EXPECT_CALL(*callback, Run(_)) .Times(1) .WillRepeatedly( ::testing::Invoke([this, callback](std::string error_string) { channel_destroyed_error_message_ = error_string; manager_host_->OnChannelDestroyed(); manager_host_->SetTerminateGpuCallback(callback->Get()); auto interface_ptr = manager_host_->BindInterface(); // Recreate the gpu side manager (the production code does the // same). buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>(); buffer_manager_gpu_->Initialize( std::move(interface_ptr), {}, /*supports_dma_buf=*/false, /*supports_viewporter=*/true, /*supports_acquire_fence=*/false, /*supports_overlays=*/true, kAugmentedSurfaceNotSupportedVersion); })); } } void CreateDmabufBasedBufferAndSetTerminateExpectation( bool fail, uint32_t buffer_id, base::ScopedFD fd = base::ScopedFD(), const gfx::Size& size = kDefaultSize, const std::vector<uint32_t>& strides = {1}, const std::vector<uint32_t>& offsets = {2}, const std::vector<uint64_t>& modifiers = {3}, uint32_t format = DRM_FORMAT_R8, uint32_t planes_count = 1) { if (!fd.is_valid()) fd = MakeFD(); SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail); buffer_manager_gpu_->CreateDmabufBasedBuffer( std::move(fd), kDefaultSize, strides, offsets, modifiers, format, planes_count, buffer_id); base::RunLoop().RunUntilIdle(); } void CreateShmBasedBufferAndSetTerminateExpecation( bool fail, uint32_t buffer_id, const gfx::Size& size = kDefaultSize, size_t length = 0) { SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail); if (!length) length = size.width() * size.height() * 4; buffer_manager_gpu_->CreateShmBasedBuffer(MakeFD(), length, size, buffer_id); base::RunLoop().RunUntilIdle(); } void DestroyBufferAndSetTerminateExpectation(uint32_t buffer_id, bool fail) { SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail); buffer_manager_gpu_->DestroyBuffer(buffer_id); base::RunLoop().RunUntilIdle(); } void ProcessCreatedBufferResourcesWithExpectation(size_t expected_size, bool fail) { PostToServerAndWait( [expected_size, fail](wl::TestWaylandServerThread* server) { auto params_vector = server->zwp_linux_dmabuf_v1()->buffer_params(); // To ensure, no other buffers are created, test the size of the // vector. EXPECT_EQ(params_vector.size(), expected_size); for (auto* mock_params : params_vector) { if (!fail) { zwp_linux_buffer_params_v1_send_created( mock_params->resource(), mock_params->buffer_resource()); } else { zwp_linux_buffer_params_v1_send_failed(mock_params->resource()); } } }); } std::unique_ptr<WaylandWindow> CreateWindow( PlatformWindowType type = PlatformWindowType::kWindow, gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget) { testing::Mock::VerifyAndClearExpectations(&delegate_); PlatformWindowInitProperties properties; properties.bounds = gfx::Rect(0, 0, 800, 600); properties.type = type; properties.parent_widget = parent_widget; auto new_window = WaylandWindow::Create(&delegate_, connection_.get(), std::move(properties)); EXPECT_TRUE(new_window); wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); EXPECT_NE(new_window->GetWidget(), gfx::kNullAcceleratedWidget); return new_window; } wl::WaylandOverlayConfig CreateBasicWaylandOverlayConfig( int z_order, uint32_t buffer_id, const gfx::Rect& bounds_rect) { return CreateBasicWaylandOverlayConfig(z_order, buffer_id, gfx::RectF(bounds_rect)); } wl::WaylandOverlayConfig CreateBasicWaylandOverlayConfig( int z_order, uint32_t buffer_id, const gfx::RectF& bounds_rect) { wl::WaylandOverlayConfig config; config.z_order = z_order; config.buffer_id = buffer_id; config.bounds_rect = bounds_rect; config.damage_region = gfx::ToEnclosedRect(bounds_rect); return config; } void CommitBuffer(gfx::AcceleratedWidget widget, uint32_t frame_id, uint32_t buffer_id, gfx::FrameData data, const gfx::Rect& bounds_rect, const gfx::RoundedCornersF& corners, float surface_scale_factor, const gfx::Rect& damage_region) { buffer_manager_gpu_->CommitBuffer(widget, frame_id, buffer_id, data, bounds_rect, corners, surface_scale_factor, damage_region); // Let the mojo message to be processed. base::RunLoop().RunUntilIdle(); } MockTerminateGpuCallback callback_; raw_ptr<WaylandBufferManagerHost> manager_host_; // Error message that is received when the manager_host destroys the channel. std::string channel_destroyed_error_message_; uint32_t surface_id_ = 0u; }; TEST_P(WaylandBufferManagerTest, CreateDmabufBasedBuffers) { constexpr uint32_t kDmabufBufferId = 1; PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kDmabufBufferId); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); } TEST_P(WaylandBufferManagerTest, VerifyModifiers) { constexpr uint32_t kDmabufBufferId = 1; constexpr uint32_t kFourccFormatR8 = DRM_FORMAT_R8; constexpr uint64_t kFormatModiferLinear = DRM_FORMAT_MOD_LINEAR; const std::vector<uint64_t> kFormatModifiers{DRM_FORMAT_MOD_INVALID, kFormatModiferLinear}; // Tests that fourcc format is added, but invalid modifier is ignored first. // Then, when valid modifier comes, it is stored. for (const auto& modifier : kFormatModifiers) { PostToServerAndWait([modifier](wl::TestWaylandServerThread* server) { uint32_t modifier_hi = modifier >> 32; uint32_t modifier_lo = modifier & UINT32_MAX; zwp_linux_dmabuf_v1_send_modifier( server->zwp_linux_dmabuf_v1()->resource(), kFourccFormatR8, modifier_hi, modifier_lo); }); auto buffer_formats = connection_->buffer_factory()->GetSupportedBufferFormats(); ASSERT_EQ(buffer_formats.size(), 1u); ASSERT_EQ(buffer_formats.begin()->first, GetBufferFormatFromFourCCFormat(kFourccFormatR8)); auto modifiers = buffer_formats.begin()->second; if (modifier == DRM_FORMAT_MOD_INVALID) { ASSERT_EQ(modifiers.size(), 0u); } else { ASSERT_EQ(modifiers.size(), 1u); ASSERT_EQ(modifiers[0], modifier); } } PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation( false /*fail*/, kDmabufBufferId, base::ScopedFD(), kDefaultSize, {1}, {2}, {kFormatModiferLinear}, kFourccFormatR8, 1); PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto params_vector = server->zwp_linux_dmabuf_v1()->buffer_params(); EXPECT_EQ(params_vector.size(), 1u); EXPECT_EQ(params_vector[0]->modifier_hi_, kFormatModiferLinear >> 32); EXPECT_EQ(params_vector[0]->modifier_lo_, kFormatModiferLinear & UINT32_MAX); }); // Clean up. DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); } TEST_P(WaylandBufferManagerTest, CreateShmBasedBuffers) { constexpr uint32_t kShmBufferId = 1; CreateShmBasedBufferAndSetTerminateExpecation(false /*fail*/, kShmBufferId); DestroyBufferAndSetTerminateExpectation(kShmBufferId, false /*fail*/); } TEST_P(WaylandBufferManagerTest, ValidateDataFromGpu) { const InputData kBadInputs[] = { // All zeros. {}, // Valid file but zeros everywhereelse. {true}, // Valid file, invalid size, zeros elsewhere. {true, {kDefaultSize.width(), 0}}, {true, {0, kDefaultSize.height()}}, // Valid file and size but zeros in other fields. {true, kDefaultSize}, // Vectors have different lengths. {true, kDefaultSize, 1, {1}, {2, 3}, {4, 5, 6}}, // Vectors have same lengths but strides have a zero. {true, kDefaultSize, 1, {0}, {2}, {6}}, // Vectors are valid but buffer format is not. {true, kDefaultSize, 1, {1}, {2}, {6}}, // Everything is correct but the buffer ID is zero. {true, kDefaultSize, 1, {1}, {2}, {6}, DRM_FORMAT_R8}, }; for (const auto& bad : kBadInputs) { EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(0); base::ScopedFD dummy; CreateDmabufBasedBufferAndSetTerminateExpectation( true /*fail*/, bad.buffer_id, bad.has_file ? MakeFD() : std::move(dummy), bad.size, bad.strides, bad.offsets, bad.modifiers, bad.format, bad.planes_count); } } TEST_P(WaylandBufferManagerTest, CreateAndDestroyBuffer) { const uint32_t kBufferId1 = 1; const uint32_t kBufferId2 = 2; const gfx::AcceleratedWidget widget = window_->GetWidget(); // This section tests that it is impossible to create buffers with the same // id if they haven't been assigned to any surfaces yet. { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); // Can't create buffer with existing id. CreateDmabufBasedBufferAndSetTerminateExpectation(true /*fail*/, kBufferId2); } // ... impossible to create buffers with the same id if one of them // has already been attached to a surface. { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); CreateDmabufBasedBufferAndSetTerminateExpectation(true /*fail*/, kBufferId1); } // ... impossible to destroy non-existing buffer. { // Either it is attached... DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/); // Or not attached. DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/); } // Can destroy the buffer without specifying the widget. { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); } // Still can destroy the buffer even if it has not been attached to any // widgets. { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); } // ... impossible to destroy buffers twice. { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); // Attach to a surface. CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); // Created non-attached buffer as well. CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); // Can't destroy the buffer with non-existing id (the manager cleared the // state after the previous failure). DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/); // Non-attached buffer must have been also destroyed (we can't destroy it // twice) if there was a failure. DestroyBufferAndSetTerminateExpectation(kBufferId2, true /*fail*/); // Create and destroy non-attached buffer twice. CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, true /*fail*/); } } TEST_P(WaylandBufferManagerTest, CommitBufferNonExistingBufferId) { PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // Can't commit for non-existing buffer id. constexpr uint32_t kNumberOfCommits = 0; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); CommitBuffer(window_->GetWidget(), 1u, 5u, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); // Let the mojo call to go through. base::RunLoop().RunUntilIdle(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { testing::Mock::VerifyAndClearExpectations( server->GetObject<wl::MockSurface>(id)); }); } TEST_P(WaylandBufferManagerTest, CommitOverlaysNonExistingBufferId) { EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // Can't commit for non-existing buffer id. constexpr uint32_t kNumberOfCommits = 0; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); std::vector<wl::WaylandOverlayConfig> overlay_configs; overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( INT32_MIN, 1u, window_->GetBoundsInPixels())); // Non-existing buffer id overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(0, 2u, window_->GetBoundsInPixels())); buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); // Let the mojo call to go through. base::RunLoop().RunUntilIdle(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { testing::Mock::VerifyAndClearExpectations( server->GetObject<wl::MockSurface>(id)); }); } TEST_P(WaylandBufferManagerTest, CommitOverlaysWithSameBufferId) { const size_t expected_number_of_buffers = connection_->linux_explicit_synchronization_v1() ? 1 : 2; PostToServerAndWait( [expected_number_of_buffers](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)) .Times(expected_number_of_buffers); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u); // Re-using the same buffer id across multiple surfaces is allowed. SetTerminateCallbackExpectationAndDestroyChannel(&callback_, false /*fail*/); std::vector<wl::WaylandOverlayConfig> overlay_configs; overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(0, 1u, window_->GetBoundsInPixels())); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(1, 1u, window_->GetBoundsInPixels())); buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); // Let the mojo call to go through. base::RunLoop().RunUntilIdle(); ProcessCreatedBufferResourcesWithExpectation( expected_number_of_buffers /* expected size */, false /* fail */); } TEST_P(WaylandBufferManagerTest, CommitBufferNullWidget) { constexpr uint32_t kBufferId = 1; PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId); // Can't commit for non-existing widget. SetTerminateCallbackExpectationAndDestroyChannel(&callback_, true /*fail*/); CommitBuffer(gfx::kNullAcceleratedWidget, 1u, kBufferId, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); // Let the mojo call to go through. base::RunLoop().RunUntilIdle(); } // Tests that committing overlays with bounds_rect containing NaN or infinity // values is illegal - the host terminates the gpu process. TEST_P(WaylandBufferManagerTest, CommitOverlaysNonsensicalBoundsRect) { const std::vector<gfx::RectF> bounds_rect_test_data = { gfx::RectF(std::nanf(""), window_->GetBoundsInPixels().y(), std::nanf(""), window_->GetBoundsInPixels().height()), gfx::RectF(window_->GetBoundsInPixels().x(), std::numeric_limits<float>::infinity(), window_->GetBoundsInPixels().width(), std::numeric_limits<float>::infinity())}; constexpr bool config[2] = {/*root_has_nan_bounds=*/true, /*non_root_overlay_has_nan_bounds=*/false}; constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; for (bool should_root_have_nan_bounds : config) { for (const auto& faulty_bounds_rect : bounds_rect_test_data) { CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); // Can't commit for bounds rect containing NaN SetTerminateCallbackExpectationAndDestroyChannel(&callback_, true /*fail*/); size_t z_order = 0; std::vector<wl::WaylandOverlayConfig> overlay_configs; if (should_root_have_nan_bounds) { // The root surface has nan bounds. overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( INT32_MIN, kBufferId1, faulty_bounds_rect)); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( z_order++, kBufferId2, window_->GetBoundsInPixels())); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( z_order++, kBufferId3, window_->GetBoundsInPixels())); } else { // Overlays have nan bounds. Given playback starts with the biggest // z-order number, add two more overlays around the faulty overlay // config so that the test ensures no further playback happens and it // doesn't crash. overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( INT32_MIN, kBufferId1, window_->GetBoundsInPixels())); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( z_order++, kBufferId2, window_->GetBoundsInPixels())); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( z_order++, kBufferId3, faulty_bounds_rect)); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( z_order++, kBufferId2, window_->GetBoundsInPixels())); } buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); base::RunLoop().RunUntilIdle(); if (!should_root_have_nan_bounds && !connection_->linux_explicit_synchronization_v1()) { // This case submits kBufferId2 twice. So, a second handle is requested // during a frame playback if explicit sync is unavailable. ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); } EXPECT_EQ("Overlay bounds_rect is invalid (NaN or infinity).", channel_destroyed_error_message_); std::vector<uint32_t> ids_of_subsurfaces; ids_of_subsurfaces.reserve(window_->wayland_subsurfaces_.size()); for (auto& subsurface : window_->wayland_subsurfaces_) { ids_of_subsurfaces.emplace_back( subsurface->wayland_surface()->get_surface_id()); } PostToServerAndWait([id = surface_id_, ids_of_subsurfaces]( wl::TestWaylandServerThread* server) { // Clear all the possible frame and release callbacks. auto* mock_surface = server->GetObject<wl::MockSurface>(id); for (auto subsurface_id : ids_of_subsurfaces) { auto* mock_surface_of_subsurface = server->GetObject<wl::MockSurface>(subsurface_id); EXPECT_TRUE(mock_surface_of_subsurface); mock_surface_of_subsurface->SendFrameCallback(); mock_surface_of_subsurface->ClearBufferReleases(); } mock_surface->SendFrameCallback(); mock_surface->ClearBufferReleases(); }); } } } TEST_P(WaylandBufferManagerTest, EnsureCorrectOrderOfCallbacks) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; 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(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); constexpr uint32_t kNumberOfCommits = 3; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); // All the other expectations must come in order. ::testing::InSequence sequence; EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); // wp_presentation must not exist now. This means that the buffer // manager must send synthetized presentation feedbacks. ASSERT_TRUE(!connection_->presentation()); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); base::RunLoop().RunUntilIdle(); // As long as there hasn't any previous buffer attached (nothing to release // yet), it must be enough to just send a frame callback back. SendFrameCallbackForSurface(surface_id_); // Commit second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); base::RunLoop().RunUntilIdle(); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); mock_surface->SendFrameCallback(); }); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // wp_presentation is available now. auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); ASSERT_TRUE(mock_wp_presentation); EXPECT_CALL(*mock_wp_presentation, Feedback(_, _, mock_surface->resource(), _)) .Times(1); }); // Now, the wp_presentation object exists and there must be a real feedback // sent. Ensure the order now. ASSERT_TRUE(connection_->presentation()); // Commit second buffer now. CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); base::RunLoop().RunUntilIdle(); // Even though, the server send the presentation feedback, the host manager // must make sure the order of the submission and presentation callbacks is // correct. Thus, no callbacks must be received by the MockSurfaceGpu. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait([](wl::TestWaylandServerThread* server) { server->EnsureAndGetWpPresentation()->SendPresentationCallback(); }); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // Now, send the release callback. The host manager must send the submission // and presentation callbacks in correct order. mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); }); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); } TEST_P(WaylandBufferManagerTest, DestroyedBuffersGeneratePresentationFeedbackFailure) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; 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(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); ASSERT_TRUE(mock_surface); auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); ASSERT_TRUE(mock_wp_presentation); constexpr uint32_t kNumberOfCommits = 3; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); EXPECT_CALL(*mock_wp_presentation, Feedback(_, _, mock_surface->resource(), _)) .Times(3); }); ::testing::InSequence s; // wp_presentation_feedback should work now. ASSERT_TRUE(connection_->presentation()); // Commit the first buffer and expect OnSubmission immediately. EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Deliberately drop the presentation feedback for the first buffer, // since we will destroy it. auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks()); mock_wp_presentation->DropPresentationCallback(); }); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Commit second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Destroy the first buffer, which should trigger submission for the second // buffer. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); DestroyBufferAndSetTerminateExpectation(kBufferId1, /*fail=*/false); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->DestroyPrevAttachedBuffer(); mock_surface->SendFrameCallback(); }); PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Deliberately drop the presentation feedback for the second buffer, // since we will destroy it. auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks()); mock_wp_presentation->DropPresentationCallback(); }); // Commit buffer 3 then send the presentation callback for it. This should // not call OnPresentation as OnSubmission hasn't been called yet. Though, // the previously submitted buffers will have their presentation feedback // discarded and sent to the |mock_surface_gpu| as those buffers have already // been acked. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL( mock_surface_gpu, OnPresentation( kBufferId1, ::testing::Field( &gfx::PresentationFeedback::flags, ::testing::Eq(gfx::PresentationFeedback::Flags::kFailure)))) .Times(1); EXPECT_CALL( mock_surface_gpu, OnPresentation( kBufferId2, ::testing::Field( &gfx::PresentationFeedback::flags, ::testing::Eq(gfx::PresentationFeedback::Flags::kFailure)))) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); CommitBuffer(widget, kBufferId3, kBufferId3, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->SendFrameCallback(); server->EnsureAndGetWpPresentation()->SendPresentationCallback(); }); // Ensure that presentation feedback is flushed. task_environment_.FastForwardBy( WaylandFrameManager::GetPresentationFlushTimerDurationForTesting()); // Verify our expecations. testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Destroy buffer 2, which should trigger OnSubmission for buffer 3, and // finally OnPresentation for buffer 3. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1); DestroyBufferAndSetTerminateExpectation(kBufferId2, /*fail=*/false); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->DestroyPrevAttachedBuffer(); mock_surface->SendFrameCallback(); server->EnsureAndGetWpPresentation()->SendPresentationCallback(); }); // Let the mojo messages to be processed. // No need to fast forward to ensure the presentation flush timer is fired, // because in this case the OnSubmission should piggyback the feedback. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/); } // This test ensures that a discarded presentation feedback sent prior receiving // results for the previous presentation feedback does not make them // automatically failed. TEST_P(WaylandBufferManagerTest, EnsureDiscardedPresentationDoesNotMakePreviousFeedbacksFailed) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Enable wp_presentation support. 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(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); constexpr uint32_t kNumberOfCommits = 3; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); // All the other expectations must come in order. ::testing::InSequence sequence; EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); // Commit first buffer CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let the mojo message for OnSubmission go back. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { // Verify we have a presentation callback now. This will be sent later. EXPECT_EQ( 1u, server->EnsureAndGetWpPresentation()->num_of_presentation_callbacks()); server->GetObject<wl::MockSurface>(id)->SendFrameCallback(); }); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); // Commit second buffer CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { // Verify we have a presentation callback now. This will be sent later. EXPECT_EQ( 2u, server->EnsureAndGetWpPresentation()->num_of_presentation_callbacks()); // Release previous buffer and commit third buffer. auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); mock_surface->SendFrameCallback(); }); // Let the mojo message for OnSubmission go back. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); // Commit third buffer CommitBuffer(widget, kBufferId3, kBufferId3, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); }); // Let the mojo messages to be processed. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Even though WaylandBufferManagerHost stores the previous stores // presentation feedbacks and waits for their value, the current last one // mustn't result in the previous marked as failed. Thus, no feedback must be // actually sent to the MockSurfaceGpu as it's required to send feedbacks in // order. EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); EXPECT_EQ(3u, mock_wp_presentation->num_of_presentation_callbacks()); mock_wp_presentation->SendPresentationCallbackDiscarded(/*last=*/true); }); // Let the mojo messages to be processed if any to ensure there are no pending // messages. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Now, start to send all the previous callbacks. EXPECT_CALL(mock_surface_gpu, OnPresentation( kBufferId1, ::testing::Field( &gfx::PresentationFeedback::flags, ::testing::Eq(gfx::PresentationFeedback::Flags::kVSync)))) .Times(1); PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); EXPECT_EQ(2u, mock_wp_presentation->num_of_presentation_callbacks()); mock_wp_presentation->SendPresentationCallback(); }); // Ensure that presentation feedback is flushed. task_environment_.FastForwardBy( WaylandFrameManager::GetPresentationFlushTimerDurationForTesting()); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Now, send the second presentation feedback. It will send both second and // third feedback that was discarded. EXPECT_CALL(mock_surface_gpu, OnPresentation( kBufferId2, ::testing::Field( &gfx::PresentationFeedback::flags, ::testing::Eq(gfx::PresentationFeedback::Flags::kVSync)))) .Times(1); EXPECT_CALL( mock_surface_gpu, OnPresentation( kBufferId3, ::testing::Field( &gfx::PresentationFeedback::flags, ::testing::Eq(gfx::PresentationFeedback::Flags::kFailure)))) .Times(1); PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* mock_wp_presentation = server->EnsureAndGetWpPresentation(); EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks()); mock_wp_presentation->SendPresentationCallback(); }); // Ensure that presentation feedback is flushed. task_environment_.FastForwardBy( WaylandFrameManager::GetPresentationFlushTimerDurationForTesting()); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/); } TEST_P(WaylandBufferManagerTest, TestCommitBufferConditions) { constexpr uint32_t kDmabufBufferId = 1; constexpr uint32_t kDmabufBufferId2 = 2; const gfx::AcceleratedWidget widget = window_->GetWidget(); 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 /*fail*/, kDmabufBufferId); // Part 1: the surface mustn't have a buffer attached until // zwp_linux_buffer_params_v1_send_created is called. Instead, the buffer must // be set as pending buffer. PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); }); CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* linux_dmabuf = server->zwp_linux_dmabuf_v1(); // Once the client receives a "...send_created" call, it must destroy the // params resource. EXPECT_TRUE(linux_dmabuf->buffer_params().empty()); // Part 2: the surface mustn't have a buffer attached until frame callback // is sent by the server. EXPECT_CALL(*linux_dmabuf, CreateParams(_, _, _)).Times(1); testing::Mock::VerifyAndClearExpectations( server->GetObject<wl::MockSurface>(id)); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kDmabufBufferId2); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); }); CommitBuffer(widget, kDmabufBufferId2, kDmabufBufferId2, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, gfx::Rect(window_->applied_state().size_px)); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); // After the frame callback is sent, the pending buffer will be committed. EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); mock_surface->SendFrameCallback(); }); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId2, false /*fail*/); } // Tests the surface does not have buffers attached until it's configured at // least once. TEST_P(WaylandBufferManagerTest, TestCommitBufferConditionsAckConfigured) { constexpr uint32_t kDmabufBufferId = 1; // Exercise three window types that create different windows - toplevel, popup // and subsurface. std::vector<PlatformWindowType> window_types{PlatformWindowType::kWindow, PlatformWindowType::kPopup, PlatformWindowType::kTooltip}; for (const auto& type : window_types) { // If the type is not kWindow, provide default created window as parent of // the newly created window. auto temp_window = CreateWindow(type, type != PlatformWindowType::kWindow ? widget_ : gfx::kNullAcceleratedWidget); auto widget = temp_window->GetWidget(); temp_window->Show(false); const uint32_t temp_window_surface_id = temp_window->root_surface()->get_surface_id(); 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 /*fail*/, kDmabufBufferId); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(temp_window_surface_id); auto* xdg_surface = mock_surface->xdg_surface(); ASSERT_TRUE(xdg_surface); }); ASSERT_FALSE(temp_window->IsSurfaceConfigured()); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(temp_window_surface_id); auto* xdg_surface = mock_surface->xdg_surface(); EXPECT_CALL(*xdg_surface, SetWindowGeometry(_)).Times(0); EXPECT_CALL(*xdg_surface, AckConfigure(_)).Times(0); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); }); CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, window_->GetBoundsInPixels()); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(temp_window_surface_id); auto* xdg_surface = mock_surface->xdg_surface(); testing::Mock::VerifyAndClearExpectations(mock_surface); EXPECT_CALL(*xdg_surface, SetWindowGeometry(_)).Times(0); EXPECT_CALL(*xdg_surface, AckConfigure(_)).Times(1); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); // Commit() can be called a second time as part of the configure->ack // sequence. EXPECT_CALL(*mock_surface, Commit()).Times(testing::Between(1, 2)); }); ActivateSurface(temp_window_surface_id); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { testing::Mock::VerifyAndClearExpectations( server->GetObject<wl::MockSurface>(temp_window_surface_id)); }); SetPointerFocusedWindow(nullptr); temp_window.reset(); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); } } // Verifies toplevel surfaces do not have buffers attached until configured, // even when the initial configure sequence is not acked in response to // xdg_surface.configure event, i.e: done asynchronously when OnSequencePoint() // is called by they FrameManager). // // Regression test for https://crbug.com/1313023. TEST_P(WaylandBufferManagerTest, CommitBufferConditionsWithDeferredAckConfigure) { constexpr gfx::Rect kNormalBounds{800, 800}; constexpr gfx::Rect kRestoredBounds{500, 500}; constexpr uint32_t kDmabufBufferId = 1; testing::Mock::VerifyAndClearExpectations(&delegate_); PlatformWindowInitProperties properties; properties.type = PlatformWindowType::kWindow; properties.bounds = kNormalBounds; auto window = WaylandWindow::Create(&delegate_, connection_.get(), std::move(properties)); ASSERT_TRUE(window); ASSERT_NE(window->GetWidget(), gfx::kNullAcceleratedWidget); auto widget = window->GetWidget(); // Set restored bounds to a value different from the initial window bounds in // order to force WaylandWindow::ProcessPendingConfigureState() to defer the // very first configure ack to be done in the subsequent OnSequencePoint() // call. window->SetRestoredBoundsInDIP(kRestoredBounds); wl::SyncDisplay(connection_->display_wrapper(), *connection_->display()); gfx::Insets insets; window->SetDecorationInsets(&insets); window->Show(false); const uint32_t surface_id = window->root_surface()->get_surface_id(); 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 /*fail*/, kDmabufBufferId); PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id); auto* xdg_surface = mock_surface->xdg_surface(); ASSERT_TRUE(xdg_surface); }); ASSERT_FALSE(window->IsSurfaceConfigured()); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); // Emulate the following steps: // // 1. A CommitBuffer request coming from the GPU service, with frame // bounds that do not match the one stored in |pending_configures_| at Host // side (filled when processing 0x0 initial configure sequence sent by the // Wayland compositor. // 2. The initial configure sequence (i.e: with 0x0 size which means the // client must suggest the initial geometry of the surface. // 3. And then a CommitBuffer with the expected bounds (ie: suggested to the // Wayland compositor through a set_geometry/ack_configure sequence when // processing (2). // // And ensures the xdg and wl_surface objects received the correct requests // amount. I.e: No buffer attaches before setting geometry + acking initial // configure sequence, etc. constexpr uint32_t kActivateSerial = 1u; PostToServerAndWait([surface_id, bounds = kRestoredBounds]( wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id); auto* xdg_surface = mock_surface->xdg_surface(); EXPECT_CALL(*xdg_surface, SetWindowGeometry(bounds)).Times(1); EXPECT_CALL(*xdg_surface, AckConfigure(kActivateSerial)).Times(1); EXPECT_CALL(*mock_surface, Attach(_, 0, 0)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId, gfx::FrameData(delegate_.viz_seq() - 1), gfx::Rect{55, 55}, gfx::RoundedCornersF(), kDefaultScale, gfx::Rect{55, 55}); ActivateSurface(surface_id, kActivateSerial); CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId, gfx::FrameData(delegate_.viz_seq()), kRestoredBounds, gfx::RoundedCornersF(), kDefaultScale, kRestoredBounds); SetPointerFocusedWindow(nullptr); window.reset(); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); } // The buffer that is not originally attached to any of the surfaces, // must be attached when a commit request comes. Also, it must setup a buffer // release listener and OnSubmission must be called for that buffer if it is // released. TEST_P(WaylandBufferManagerTest, AnonymousBufferAttachedAndReleased) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; 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 /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); constexpr uint32_t kNumberOfCommits = 3; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); // All the other expectations must come in order. ::testing::InSequence sequence; EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); // Commit second buffer now. CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Now synchronously create a second buffer and commit it. The release // callback must be setup and OnSubmission must be called. EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); // Commit second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); }); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Now asynchronously create another buffer so that a commit request // comes earlier than it is created by the Wayland compositor, but it can // released once the buffer is committed and processed (that is, it must be // able to setup a buffer release callback). PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _)) .Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(0); CommitBuffer(widget, kBufferId3, kBufferId3, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be processed from host to gpu (if any). base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1); // Now, create the buffer from the Wayland compositor side and let the buffer // manager complete the commit request. ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); }); // Let mojo messages to be processed. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/); } TEST_P(WaylandBufferManagerTest, DestroyBufferForDestroyedWindow) { constexpr uint32_t kBufferId = 1; auto temp_window = CreateWindow(); auto widget = temp_window->GetWidget(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId); CommitBuffer(widget, kBufferId, kBufferId, gfx::FrameData(delegate_.viz_seq()), temp_window->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, temp_window->GetBoundsInPixels()); temp_window.reset(); DestroyBufferAndSetTerminateExpectation(kBufferId, false /*fail*/); } TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionSingleBuffer) { constexpr uint32_t kBufferId = 1; auto temp_window = CreateWindow(); auto widget = temp_window->GetWidget(); auto bounds = temp_window->GetBoundsInPixels(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); // All the other expectations must come in order. ::testing::InSequence sequence; EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); temp_window.reset(); CommitBuffer(widget, kBufferId, kBufferId, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); DestroyBufferAndSetTerminateExpectation(kBufferId, false /*fail*/); } TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionMultipleBuffers) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; auto temp_window = CreateWindow(); temp_window->Show(false); auto widget = temp_window->GetWidget(); auto bounds = temp_window->GetBoundsInPixels(); const uint32_t temp_window_surface_id = temp_window->root_surface()->get_surface_id(); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { ASSERT_TRUE(server->GetObject<wl::MockSurface>(temp_window_surface_id)); }); ActivateSurface(temp_window_surface_id); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); // All the other expectations must come in order. ::testing::InSequence sequence; EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); PostToServerAndWait([temp_window_surface_id]( wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(temp_window_surface_id) ->SendFrameCallback(); EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait( [temp_window_surface_id](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(temp_window_surface_id); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); }); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); temp_window.reset(); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); } // Tests that OnSubmission and OnPresentation are properly triggered if a buffer // is committed twice in a row and those buffers are destroyed. TEST_P(WaylandBufferManagerTest, DestroyBufferCommittedTwiceInARow) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Can't call OnSubmission until there is a release. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Destroying buffer2 should do nothing yet. DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Destroying buffer1 should give us two acks for buffer2. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(2); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(2); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); } // Tests that OnSubmission and OnPresentation are properly triggered if a buffer // is committed twice in a row and then released. TEST_P(WaylandBufferManagerTest, ReleaseBufferCommittedTwiceInARow) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Even though, this is stored on the client thread, but must only be used on // the server thread. wl_resource* wl_buffer1 = GetSurfaceAttachedBuffer(surface_id_); ASSERT_TRUE(wl_buffer1); // Can't call OnSubmission until there is a release. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Releasing buffer1 should trigger two acks for buffer2. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(2); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(2); PostToServerAndWait( [wl_buffer1, id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer1); }); // Let mojo messages to be processed back to the gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); } // Tests that OnSubmission and OnPresentation callbacks are properly called // even if buffers are not released in the same order they were committed. TEST_P(WaylandBufferManagerTest, ReleaseOrderDifferentToCommitOrder) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->GetObject<wl::MockSurface>(id), Attach(_, _, _)) .Times(1); }); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed and passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Even though, this is stored on the client thread, but must only be used on // the server thread. wl_resource* wl_buffer1 = GetSurfaceAttachedBuffer(surface_id_); ASSERT_TRUE(wl_buffer1); // Can't call OnSubmission until there is a release. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->GetObject<wl::MockSurface>(id), Attach(_, _, _)) .Times(2); }); CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Even though, this is stored on the client thread, but must only be used on // the server thread. wl_resource* wl_buffer2 = GetSurfaceAttachedBuffer(surface_id_); ASSERT_TRUE(wl_buffer2); CommitBuffer(widget, kBufferId3, kBufferId3, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Let mojo messages to be processed and passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Releasing buffer2 can't trigger OnSubmission for buffer3, because // OnSubmission for buffer2 has not been sent yet. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait( [wl_buffer2, id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer2); }); // Let mojo messages to be processed and passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Releasing buffer1 should trigger acks for both. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1); PostToServerAndWait( [wl_buffer1, id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer1); }); // Let mojo messages to be processed and passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/); } // This test verifies that submitting the buffer more than once results in // OnSubmission callback as Wayland compositor is not supposed to release the // buffer committed twice. TEST_P(WaylandBufferManagerTest, OnSubmissionCalledForBufferCommitedTwiceInARow) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); ASSERT_TRUE(!connection_->presentation()); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); PostToServerAndWait( [id = surface_id_, bounds](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, DamageBuffer(0, 0, bounds.width(), bounds.height())) .Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait( [id = surface_id_, bounds](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); mock_surface->SendFrameCallback(); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, DamageBuffer(0, 0, bounds.width(), bounds.height())) .Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); // Commit second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, DamageBuffer(_, _, _, _)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); mock_surface->SendFrameCallback(); }); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Now, commit the buffer with the |kBufferId2| again. The manager does not // sends the submission callback, the compositor is not going to release a // buffer as it was the same buffer submitted more than once. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1); PostToServerAndWait( [id = surface_id_, bounds](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, DamageBuffer(0, 0, bounds.width(), bounds.height())) .Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); // Commit second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, DamageBuffer(_, _, _, _)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); mock_surface->SendFrameCallback(); }); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // If we commit another buffer now, the manager host must not automatically // trigger OnSubmission and OnPresentation callbacks. EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0); EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); PostToServerAndWait( [id = surface_id_, bounds](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, DamageBuffer(0, 0, bounds.width(), bounds.height())) .Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Now, they must be triggered once the buffer is released. EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer()); mock_surface->SendFrameCallback(); }); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); } // Tests that submitting a single buffer only receives an OnSubmission. This is // required behaviour to make sure that submitting buffers in a quiescent state // will be immediately acked. TEST_P(WaylandBufferManagerTest, OnSubmissionCalledForSingleBuffer) { constexpr uint32_t kBufferId1 = 1; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); 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 /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); EXPECT_CALL(mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages to be passed from host to gpu. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); } // Tests that when CommitOverlays(), root_surface can only be committed once all // overlays in the frame are committed. TEST_P(WaylandBufferManagerTest, RootSurfaceIsCommittedLast) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* linux_dmabuf = server->zwp_linux_dmabuf_v1(); // Ack creation for only the first 2 wl_buffers. zwp_linux_buffer_params_v1_send_created( linux_dmabuf->buffer_params()[0]->resource(), linux_dmabuf->buffer_params()[0]->buffer_resource()); zwp_linux_buffer_params_v1_send_created( linux_dmabuf->buffer_params()[1]->resource(), linux_dmabuf->buffer_params()[1]->buffer_resource()); auto* mock_surface = server->GetObject<wl::MockSurface>(id); // root_surface shall not be committed as one of its subsurface is not // committed yet due to pending wl_buffer creation. EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(0); }); std::vector<wl::WaylandOverlayConfig> overlay_configs; overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(0, kBufferId2, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(1, kBufferId3, bounds)); buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); // Let mojo messages from gpu to host to go through. base::RunLoop().RunUntilIdle(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); testing::Mock::VerifyAndClearExpectations(mock_surface); auto* linux_dmabuf = server->zwp_linux_dmabuf_v1(); // Once wl_buffer is created, all subsurfaces are committed, hence // root_surface can be committed. zwp_linux_buffer_params_v1_send_created( linux_dmabuf->buffer_params()[0]->resource(), linux_dmabuf->buffer_params()[0]->buffer_resource()); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); } TEST_P(WaylandBufferManagerTest, FencedRelease) { if (!connection_->linux_explicit_synchronization_v1()) GTEST_SKIP(); constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; 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(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); constexpr uint32_t kNumberOfCommits = 3; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); ::testing::InSequence s; // Commit the first buffer and expect the OnSubmission immediately. EXPECT_CALL( mock_surface_gpu, OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, Truly([](const auto& fence) { return fence.is_null(); }))) .Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages from gpu to host to go through. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); SendFrameCallbackForSurface(surface_id_); // Commit the second buffer now. CommitBuffer(widget, kBufferId2, kBufferId2, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); EXPECT_CALL( mock_surface_gpu, OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, Truly([](const auto& fence) { return !fence.is_null(); }))) .Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { // Release the first buffer via fenced release. This should trigger // OnSubmission for the second buffer with a non-null fence. gfx::GpuFenceHandle handle; const int32_t kFenceFD = dup(1); handle.owned_fd.reset(kFenceFD); auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBufferFenced(mock_surface->prev_attached_buffer(), std::move(handle)); mock_surface->SendFrameCallback(); }); // Let mojo messages from gpu to host to go through. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); // Commit the third buffer now. CommitBuffer(widget, kBufferId3, kBufferId3, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); SendFrameCallbackForSurface(surface_id_); // Release the second buffer via immediate explicit release. This should // trigger OnSubmission for the second buffer with a null fence. EXPECT_CALL( mock_surface_gpu, OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, Truly([](const auto& fence) { return fence.is_null(); }))) .Times(1); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); mock_surface->ReleaseBufferFenced(mock_surface->prev_attached_buffer(), gfx::GpuFenceHandle()); mock_surface->SendFrameCallback(); }); // Let mojo messages from gpu to host to go through. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/); } // Tests that destroying a channel doesn't result in resetting surface state // and buffers can be attached after the channel has been reinitialized. TEST_P(WaylandBufferManagerTest, CanSubmitBufferAfterChannelDestroyedAndInitialized) { constexpr uint32_t kBufferId1 = 1; const gfx::AcceleratedWidget widget = window_->GetWidget(); const gfx::Rect bounds = window_->GetBoundsInPixels(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); auto mock_surface_gpu = std::make_unique<MockSurfaceGpu>(buffer_manager_gpu_.get(), widget); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); EXPECT_CALL(*mock_surface_gpu.get(), OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(*mock_surface_gpu.get(), OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages from host to gpu to go through. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // The root surface shouldn't get null buffer attached. EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0); EXPECT_CALL(*mock_surface, Commit()).Times(1); mock_surface->SendFrameCallback(); }); // After the channel has been destroyed and surface state has been reset, the // interface should bind again and it still should be possible to attach // buffers as WaylandBufferManagerHost::Surface::ResetSurfaceContents mustn't // reset the state of |configured|. manager_host_->OnChannelDestroyed(); manager_host_ = connection_->buffer_manager_host(); // Let mojo messages from host to gpu go through. base::RunLoop().RunUntilIdle(); // The surface must has the buffer detached and all the buffers are destroyed. // Release the fence as there is no further need to hold that as the client // no longer expects that. Moreover, its next attach may result in a DCHECK, // as the next buffer resource can be allocated on the same memory address // resulting in a DCHECK when set_linux_buffer_release is called. The reason // is that wl_resource_create calls internally calls malloc, which may reuse // that memory. PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->ClearBufferReleases(); }); auto interface_ptr = manager_host_->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, /*supports_dma_buf=*/false, /*supports_viewporter=*/true, /*supports_acquire_fence=*/false, /*supports_overlays=*/true, kAugmentedSurfaceNotSupportedVersion); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); // The buffer must be attached. EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1); EXPECT_CALL(*mock_surface, Frame(_)).Times(1); EXPECT_CALL(*mock_surface, Commit()).Times(1); }); EXPECT_CALL(*mock_surface_gpu.get(), OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _)) .Times(1); EXPECT_CALL(*mock_surface_gpu.get(), OnPresentation(kBufferId1, _)).Times(1); CommitBuffer(widget, kBufferId1, kBufferId1, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); // Let mojo messages from host to gpu to go through. base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); } // Tests that destroying a channel results in attaching null buffers to the root // surface, and hiding primary subsurface and overlay surfaces. This is required // to make it possible for a GPU service to switch from hw acceleration to sw // compositing. Otherwise, there will be frozen graphics represented by a // primary subsurface as sw compositing uses the root surface to draw new // frames. Verifies the fix for https://crbug.com/1201314 TEST_P(WaylandBufferManagerTest, HidesSubsurfacesOnChannelDestroyed) { constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; constexpr uint32_t kBufferId3 = 3; const gfx::Rect bounds = window_->GetBoundsInPixels(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3); ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */, false /* fail */); // Prepare a frame with one background buffer, one primary plane and one // additional overlay plane. This will simulate hw accelerated compositing. std::vector<wl::WaylandOverlayConfig> overlay_configs; overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(0, kBufferId2, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(1, kBufferId3, bounds)); buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); // Let mojo messages from gpu to host to go through. base::RunLoop().RunUntilIdle(); // 3 surfaces must exist - root surface, the primary subsurface and one // additional overlay surface. All of them must have buffers attached. EXPECT_EQ(1u, window_->wayland_subsurfaces().size()); PostToServerAndWait( [id = surface_id_, primary_subsurface_id = window_->primary_subsurface()->wayland_surface()->get_surface_id(), overlay_surface_id = window_->wayland_subsurfaces() .begin() ->get() ->wayland_surface() ->get_surface_id()](wl::TestWaylandServerThread* server) { EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer()); EXPECT_TRUE(server->GetObject<wl::MockSurface>(primary_subsurface_id) ->attached_buffer()); EXPECT_TRUE(server->GetObject<wl::MockSurface>(overlay_surface_id) ->attached_buffer()); }); // Pretend that the channel gets destroyed because of some internal reason. manager_host_->OnChannelDestroyed(); manager_host_ = connection_->buffer_manager_host(); // Let mojo messages from host to gpu go through. base::RunLoop().RunUntilIdle(); // The root surface should still have the buffer attached.... PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer()); }); // ... and the primary and secondary subsurfaces must be hidden. EXPECT_FALSE(window_->primary_subsurface()->IsVisible()); EXPECT_EQ(1u, window_->wayland_subsurfaces().size()); EXPECT_FALSE(window_->wayland_subsurfaces().begin()->get()->IsVisible()); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { server->GetObject<wl::MockSurface>(id)->ClearBufferReleases(); }); auto interface_ptr = manager_host_->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, /*supports_dma_buf=*/false, /*supports_viewporter=*/true, /*supports_acquire_fence=*/false, /*supports_overlays=*/true, kAugmentedSurfaceNotSupportedVersion); PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Now, create only one buffer and attach that to the root surface. The // primary subsurface and secondary subsurface must remain invisible. EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */, false /* fail */); std::vector<wl::WaylandOverlayConfig> overlay_configs2; overlay_configs2.push_back( CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds)); buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 2u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs2)); base::RunLoop().RunUntilIdle(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { // The root surface should have the buffer detached. EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer()); }); // The primary and secondary subsurfaces must remain hidden. EXPECT_FALSE(window_->primary_subsurface()->IsVisible()); EXPECT_EQ(1u, window_->wayland_subsurfaces().size()); EXPECT_FALSE(window_->wayland_subsurfaces().begin()->get()->IsVisible()); } TEST_P(WaylandBufferManagerTest, DoesNotAttachAndCommitOnHideIfNoBuffersAttached) { EXPECT_TRUE(window_->IsVisible()); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); constexpr uint32_t kNumberOfCommits = 0; EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); window_->Hide(); } TEST_P(WaylandBufferManagerTest, HasOverlayPrioritizer) { EXPECT_TRUE(connection_->overlay_prioritizer()); } TEST_P(WaylandBufferManagerTest, CanSubmitOverlayPriority) { std::vector<uint32_t> kBufferIds = {1, 2, 3}; MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), window_->GetWidget()); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3); }); for (auto id : kBufferIds) CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, id); PostToServerAndWait( [size = kBufferIds.size()](wl::TestWaylandServerThread* server) { auto* linux_dmabuf = server->zwp_linux_dmabuf_v1(); for (size_t i = 0; i < size; i++) { zwp_linux_buffer_params_v1_send_created( linux_dmabuf->buffer_params()[i]->resource(), linux_dmabuf->buffer_params()[i]->buffer_resource()); } }); std::vector<std::pair<gfx::OverlayPriorityHint, uint32_t>> priorities = { {gfx::OverlayPriorityHint::kNone, OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_NONE}, {gfx::OverlayPriorityHint::kRegular, OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REGULAR}, {gfx::OverlayPriorityHint::kVideo, OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REGULAR}, {gfx::OverlayPriorityHint::kLowLatencyCanvas, OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_PREFERRED_LOW_LATENCY_CANVAS}, {gfx::OverlayPriorityHint::kHardwareProtection, OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REQUIRED_HARDWARE_PROTECTION}}; uint32_t frame_id = 0u; for (const auto& priority : priorities) { std::vector<wl::WaylandOverlayConfig> overlay_configs; for (auto id : kBufferIds) { overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( id == 1 ? INT32_MIN : id, id, window_->GetBoundsInPixels())); overlay_configs.back().priority_hint = priority.first; } buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), ++frame_id, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); base::RunLoop().RunUntilIdle(); for (auto& subsurface : window_->wayland_subsurfaces_) { PostToServerAndWait( [subsurface_id = subsurface->wayland_surface()->get_surface_id(), &priority](wl::TestWaylandServerThread* server) { auto* mock_surface_of_subsurface = server->GetObject<wl::MockSurface>(subsurface_id); EXPECT_TRUE(mock_surface_of_subsurface); EXPECT_EQ(mock_surface_of_subsurface->prioritized_surface() ->overlay_priority(), priority.second); mock_surface_of_subsurface->SendFrameCallback(); }); } SendFrameCallbackForSurface(surface_id_); } } TEST_P(WaylandBufferManagerTest, HasSurfaceAugmenter) { InitializeSurfaceAugmenter(); EXPECT_TRUE(connection_->surface_augmenter()); } TEST_P(WaylandBufferManagerTest, CanSetRoundedCorners) { InitializeSurfaceAugmenter(); std::vector<uint32_t> kBufferIds = {1, 2, 3}; MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), window_->GetWidget()); PostToServerAndWait([](wl::TestWaylandServerThread* server) { EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3); }); for (auto id : kBufferIds) CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, id); PostToServerAndWait( [size = kBufferIds.size()](wl::TestWaylandServerThread* server) { auto* linux_dmabuf = server->zwp_linux_dmabuf_v1(); for (size_t i = 0; i < size; i++) { zwp_linux_buffer_params_v1_send_created( linux_dmabuf->buffer_params()[i]->resource(), linux_dmabuf->buffer_params()[i]->buffer_resource()); } }); std::vector<gfx::RRectF> rounded_corners_vec = { {{10, 10, 200, 200}, {1, 1, 1, 1}}, {{10, 10, 200, 200}, {0, 1, 0, 1}}, {{10, 10, 200, 200}, {1, 0, 1, 0}}, {{10, 10, 200, 200}, {5, 10, 0, 1}}, {{10, 10, 200, 200}, {0, 2, 20, 3}}, {{10, 10, 200, 200}, {2, 3, 4, 5}}, {{10, 10, 200, 200}, {0, 0, 0, 0}}, }; // Use different scale factors to verify Ozone/Wayland translates the corners // from px to dip. std::vector<float> scale_factors = {1, 1.2, 1.5, 2}; // Exo may allow to submit values in px. std::vector<bool> in_pixels = {true, false}; uint32_t frame_id = 0u; for (auto scale_factor : scale_factors) { if (scale_factor != std::ceil(scale_factor) && !GetParam().surface_submission_in_pixel_coordinates) { // Fractional scales not supported when surface submission in pixel // coordinates is disabled. continue; } for (const auto& rounded_corners : rounded_corners_vec) { std::vector<wl::WaylandOverlayConfig> overlay_configs; for (auto id : kBufferIds) { overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( id == 1 ? INT32_MIN : id, id, window_->GetBoundsInPixels())); overlay_configs.back().surface_scale_factor = scale_factor; overlay_configs.back().rounded_clip_bounds = rounded_corners; } buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), ++frame_id, gfx::FrameData(), std::move(overlay_configs)); base::RunLoop().RunUntilIdle(); for (auto& subsurface : window_->wayland_subsurfaces_) { gfx::RRectF rounded_clip_bounds_dip = rounded_corners; // If submission in px is allowed, there is no need to convert px to // dip. if (!GetParam().surface_submission_in_pixel_coordinates) { // Ozone/Wayland applies ceiled scale factor if it's fractional. rounded_clip_bounds_dip.Scale(1.f / std::ceil(scale_factor)); } PostToServerAndWait( [subsurface_id = subsurface->wayland_surface()->get_surface_id(), &rounded_clip_bounds_dip](wl::TestWaylandServerThread* server) { auto* mock_surface_of_subsurface = server->GetObject<wl::MockSurface>(subsurface_id); EXPECT_TRUE(mock_surface_of_subsurface); EXPECT_EQ(mock_surface_of_subsurface->augmented_surface() ->rounded_clip_bounds(), rounded_clip_bounds_dip); mock_surface_of_subsurface->SendFrameCallback(); }); } SendFrameCallbackForSurface(surface_id_); } } } // Verifies that there are no more than certain number of submitted frames that // wait presentation feedbacks. If the number of pending frames hit the // threshold, the feedbacks are marked as failed and discarded. See the comments // below in the test. TEST_P(WaylandBufferManagerTest, FeedbacksAreDiscardedIfClientMisbehaves) { PostToServerAndWait([](wl::TestWaylandServerThread* server) { ASSERT_TRUE(server->EnsureAndGetWpPresentation()); }); // 2 buffers are enough. constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; 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(2); }); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); // There will be 235 frames/commits. constexpr uint32_t kNumberOfCommits = 235u; PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits); EXPECT_CALL(*server->EnsureAndGetWpPresentation(), Feedback(_, _, _, _)) .Times(kNumberOfCommits); EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits); }); // The presentation feedbacks should fail after first 20 commits (that's the // threshold that WaylandFrameManager maintains). Next, the presentation // feedbacks will fail every consequent 17 commits as 3 frames out of 20 // previous frames that WaylandFrameManager stores are always preserved in // case if the client restores the behavior (which is very unlikely). uint32_t expect_presentation_failure_on_commit_seq = 20u; // Chooses the next buffer id that should be committed. uint32_t next_buffer_id_commit = 0; // Specifies the expected number of failing feedbacks if the client // misbehaves. constexpr uint32_t kExpectedFailedFeedbacks = 17u; for (auto commit_seq = 1u; commit_seq <= kNumberOfCommits; commit_seq++) { // All the other expectations must come in order. if (next_buffer_id_commit == kBufferId1) next_buffer_id_commit = kBufferId2; else next_buffer_id_commit = kBufferId1; EXPECT_CALL(mock_surface_gpu, OnSubmission(next_buffer_id_commit, gfx::SwapResult::SWAP_ACK, _)) .Times(1); if (commit_seq % expect_presentation_failure_on_commit_seq == 0) { EXPECT_CALL(mock_surface_gpu, OnPresentation(_, gfx::PresentationFeedback::Failure())) .Times(kExpectedFailedFeedbacks); // See comment near |expect_presentation_failure_on_commit_seq|. expect_presentation_failure_on_commit_seq += kExpectedFailedFeedbacks; } else { // The client misbehaves and doesn't send presentation feedbacks. The // frame manager doesn't mark the feedbacks as failed until the threshold // is hit. EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0); } CommitBuffer(widget, next_buffer_id_commit, next_buffer_id_commit, gfx::FrameData(delegate_.viz_seq()), bounds, gfx::RoundedCornersF(), kDefaultScale, bounds); PostToServerAndWait( [id = surface_id_](wl::TestWaylandServerThread* server) { auto* mock_surface = server->GetObject<wl::MockSurface>(id); if (auto* buffer = mock_surface->prev_attached_buffer()) mock_surface->ReleaseBuffer(buffer); server->EnsureAndGetWpPresentation()->DropPresentationCallback( /*last=*/true); mock_surface->SendFrameCallback(); }); base::RunLoop().RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu); } DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/); DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/); } TEST_P(WaylandBufferManagerTest, ExecutesTasksAfterInitialization) { // Unbind the pipe. manager_host_->OnChannelDestroyed(); base::RunLoop().RunUntilIdle(); EXPECT_FALSE(buffer_manager_gpu_->remote_host_); EXPECT_TRUE(buffer_manager_gpu_->pending_tasks_.empty()); constexpr uint32_t kDmabufBufferId = 1; CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kDmabufBufferId); CommitBuffer(window_->GetWidget(), kDmabufBufferId, kDmabufBufferId, gfx::FrameData(delegate_.viz_seq()), window_->GetBoundsInPixels(), gfx::RoundedCornersF(), kDefaultScale, window_->GetBoundsInPixels()); DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/); base::RunLoop().RunUntilIdle(); EXPECT_EQ(3u, buffer_manager_gpu_->pending_tasks_.size()); auto interface_ptr = manager_host_->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, /*supports_dma_buf=*/false, /*supports_viewporter=*/true, /*supports_acquire_fence=*/false, /*supports_overlays=*/true, kAugmentedSurfaceNotSupportedVersion); base::RunLoop().RunUntilIdle(); EXPECT_TRUE(buffer_manager_gpu_->pending_tasks_.empty()); } TEST_P(WaylandBufferManagerTest, DoesNotRequestReleaseForSolidColorBuffers) { if (!connection_->linux_explicit_synchronization_v1()) GTEST_SKIP(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { server->EnsureSurfaceAugmenter(); }); MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_); const auto solid_color_buffer_id = buffer_manager_gpu_->AllocateBufferID(); buffer_manager_gpu_->CreateSolidColorBuffer( SkColor4f::FromColor(SK_ColorBLUE), gfx::Size(1, 1), solid_color_buffer_id); base::RunLoop().RunUntilIdle(); 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); }); std::vector<wl::WaylandOverlayConfig> overlay_configs; auto bounds = window_->GetBoundsInPixels(); overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig( INT32_MIN, solid_color_buffer_id, bounds)); buffer_manager_gpu_->CommitOverlays(widget_, 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); base::RunLoop().RunUntilIdle(); PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) { EXPECT_FALSE( server->GetObject<wl::MockSurface>(id)->has_linux_buffer_release()); }); } class WaylandBufferManagerViewportTest : public WaylandBufferManagerTest { public: WaylandBufferManagerViewportTest() = default; ~WaylandBufferManagerViewportTest() override = default; protected: void ViewportDestinationTestHelper(const gfx::RectF& bounds_rect, const gfx::RectF& expected_bounds_rect) { auto temp_window = CreateWindow(); temp_window->Show(false); const uint32_t surface_id = temp_window->root_surface()->get_surface_id(); PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) { ASSERT_TRUE(server->GetObject<wl::MockSurface>(surface_id)); }); ActivateSurface(surface_id); constexpr uint32_t kBufferId1 = 1; constexpr uint32_t kBufferId2 = 2; MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), temp_window->GetWidget()); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1); CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2); ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */, false /* fail */); std::vector<wl::WaylandOverlayConfig> overlay_configs; auto bounds = temp_window->GetBoundsInPixels(); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(0, kBufferId1, bounds)); overlay_configs.emplace_back( CreateBasicWaylandOverlayConfig(1, kBufferId1, bounds_rect)); buffer_manager_gpu_->CommitOverlays(temp_window->GetWidget(), 1u, gfx::FrameData(delegate_.viz_seq()), std::move(overlay_configs)); base::RunLoop().RunUntilIdle(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { // Creates a handle for a subsurface. const std::vector<wl::TestZwpLinuxBufferParamsV1*>& params_vector = server->zwp_linux_dmabuf_v1()->buffer_params(); for (auto* mock_params : params_vector) { zwp_linux_buffer_params_v1_send_created(mock_params->resource(), mock_params->buffer_resource()); } }); EXPECT_EQ(temp_window->wayland_subsurfaces_.size(), 1u); WaylandSubsurface* subsurface = temp_window->wayland_subsurfaces_.begin()->get(); ASSERT_TRUE(subsurface); const uint32_t subsurface_id = subsurface->wayland_surface()->get_surface_id(); PostToServerAndWait([subsurface_id](wl::TestWaylandServerThread* server) { ASSERT_TRUE(server->GetObject<wl::MockSurface>(subsurface_id)); }); // The conversion from double to fixed and back is necessary because it // happens during the roundtrip, and it creates significant error. gfx::SizeF expected_size(wl_fixed_to_double(wl_fixed_from_double( expected_bounds_rect.size().width())), wl_fixed_to_double(wl_fixed_from_double( expected_bounds_rect.size().height()))); PostToServerAndWait([surface_id, subsurface_id, &expected_size](wl::TestWaylandServerThread* server) { auto* mock_surface_of_subsurface = server->GetObject<wl::MockSurface>(subsurface_id); auto* test_vp = mock_surface_of_subsurface->viewport(); EXPECT_EQ(expected_size, test_vp->destination_size()); mock_surface_of_subsurface->SendFrameCallback(); server->GetObject<wl::MockSurface>(surface_id)->SendFrameCallback(); }); DestroyBufferAndSetTerminateExpectation(kBufferId1, false); DestroyBufferAndSetTerminateExpectation(kBufferId2, false); } }; // Tests viewport destination is set correctly when the augmenter subsurface // protocol is not available and then becomes available. TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationNonInteger) { constexpr gfx::RectF test_data[2][2] = { {gfx::RectF({21, 18}, {7, 11}), gfx::RectF({21, 18}, {7, 11})}, {gfx::RectF({7, 8}, {43, 63}), gfx::RectF({7, 8}, {43, 63})}}; for (const auto& data : test_data) { ViewportDestinationTestHelper(data[0] /* display_rect */, data[1] /* expected_rect */); // Initialize the surface augmenter now. InitializeSurfaceAugmenter(); ASSERT_TRUE(connection_->surface_augmenter()); } } // Tests viewport destination is set correctly when the augmenter subsurface // protocol is not available (the destination is rounded), and the protocol is // available (the destination is set with floating point precision). TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationInteger) { constexpr gfx::RectF test_data[2][2] = { {gfx::RectF({21, 18}, {7.423, 11.854}), gfx::RectF({21, 18}, {7, 12})}, {gfx::RectF({7, 8}, {43.562, 63.76}), gfx::RectF({7, 8}, {43.562, 63.76})}}; for (const auto& data : test_data) { ViewportDestinationTestHelper(data[0] /* display_rect */, data[1] /* expected_rect */); // Initialize the surface augmenter now. InitializeSurfaceAugmenter(); ASSERT_TRUE(connection_->surface_augmenter()); } } INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest, WaylandBufferManagerTest, Values(wl::ServerConfig{})); INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest, WaylandBufferManagerViewportTest, Values(wl::ServerConfig{})); INSTANTIATE_TEST_SUITE_P( XdgVersionStableTestWithoutExplicitSync, WaylandBufferManagerTest, Values(wl::ServerConfig{ .use_explicit_synchronization = wl::ShouldUseExplicitSynchronizationProtocol::kNone})); INSTANTIATE_TEST_SUITE_P( XdgVersionStableTestWithExplicitSync, WaylandBufferManagerTest, Values(wl::ServerConfig{ .use_explicit_synchronization = wl::ShouldUseExplicitSynchronizationProtocol::kUse})); INSTANTIATE_TEST_SUITE_P( XdgVersionStableTestWithSurfaceSubmissionInPixelCoordinatesDisabled, WaylandBufferManagerTest, Values(wl::ServerConfig{.surface_submission_in_pixel_coordinates = false})); INSTANTIATE_TEST_SUITE_P( XdgVersionStableTestWithViewporterSurfaceScalingEnabled, WaylandBufferManagerTest, Values(wl::ServerConfig{.surface_submission_in_pixel_coordinates = false, .supports_viewporter_surface_scaling = true})); } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/wayland_buffer_manager_unittest.cc
C++
unknown
134,154
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/wayland_utils.h" #include "ui/gfx/image/image_skia.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_keyboard.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h" namespace ui { namespace { class WaylandScopedDisableClientSideDecorationsForTest : public PlatformUtils::ScopedDisableClientSideDecorationsForTest { public: WaylandScopedDisableClientSideDecorationsForTest() { wl::AllowClientSideDecorationsForTesting(false); } ~WaylandScopedDisableClientSideDecorationsForTest() override { wl::AllowClientSideDecorationsForTesting(true); } }; } // namespace WaylandUtils::WaylandUtils(WaylandConnection* connection) : connection_(connection) {} WaylandUtils::~WaylandUtils() = default; gfx::ImageSkia WaylandUtils::GetNativeWindowIcon(intptr_t target_window_id) { return {}; } std::string WaylandUtils::GetWmWindowClass( const std::string& desktop_base_name) { return desktop_base_name; } std::unique_ptr<PlatformUtils::ScopedDisableClientSideDecorationsForTest> WaylandUtils::DisableClientSideDecorationsForTest() { return std::make_unique<WaylandScopedDisableClientSideDecorationsForTest>(); } void WaylandUtils::OnUnhandledKeyEvent(const KeyEvent& key_event) { auto* seat = connection_->seat(); if (!seat) return; auto* keyboard = seat->keyboard(); if (!keyboard) return; keyboard->OnUnhandledKeyEvent(key_event); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/wayland_utils.cc
C++
unknown
1,723
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_UTILS_H_ #define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_UTILS_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/public/platform_utils.h" namespace ui { #define PARAM_TO_FLOAT(x) (x / 10000.f) #define FLOAT_TO_PARAM(x) static_cast<uint32_t>(x * 10000) class WaylandConnection; class WaylandUtils : public PlatformUtils { public: explicit WaylandUtils(WaylandConnection* connection); WaylandUtils(const WaylandUtils&) = delete; WaylandUtils& operator=(const WaylandUtils&) = delete; ~WaylandUtils() override; gfx::ImageSkia GetNativeWindowIcon(intptr_t target_window_id) override; std::string GetWmWindowClass(const std::string& desktop_base_name) override; std::unique_ptr<PlatformUtils::ScopedDisableClientSideDecorationsForTest> DisableClientSideDecorationsForTest() override; void OnUnhandledKeyEvent(const KeyEvent& key_event) override; private: const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_WAYLAND_UTILS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/wayland_utils.h
C++
unknown
1,188
include_rules = [ "+net/base/network_interfaces.h", "+ui/base/x", "+ui/base", "+ui/linux", ] specific_include_rules = { "x11_ozone_ui_controls_test_helper.cc": [ "+ui/aura", ] }
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/DEPS
Python
unknown
195
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/x11/atk_event_conversion.h" #include "base/check.h" #include "base/notreached.h" #include "ui/events/x/events_x_utils.h" #include "ui/gfx/x/connection.h" #include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto_types.h" namespace ui { std::unique_ptr<AtkKeyEventStruct> AtkKeyEventFromXEvent( const x11::Event& x11_event) { auto atk_key_event = std::make_unique<AtkKeyEventStruct>(); auto* xkey = x11_event.As<x11::KeyEvent>(); DCHECK(xkey); atk_key_event->type = xkey->opcode == x11::KeyEvent::Press ? ATK_KEY_EVENT_PRESS : ATK_KEY_EVENT_RELEASE; auto state = static_cast<int>(xkey->state); auto keycode = xkey->detail; auto keysym = x11::Connection::Get()->KeycodeToKeysym(keycode, state); atk_key_event->state = state; atk_key_event->keyval = keysym; atk_key_event->keycode = static_cast<uint8_t>(keycode); atk_key_event->timestamp = static_cast<uint32_t>(xkey->time); // This string property matches the one that was removed from GdkEventKey. In // the future, ATK clients should no longer rely on it, so we set it to null. atk_key_event->string = nullptr; atk_key_event->length = 0; int flags = ui::EventFlagsFromXEvent(x11_event); if (flags & ui::EF_SHIFT_DOWN) atk_key_event->state |= AtkKeyModifierMask::kAtkShiftMask; if (flags & ui::EF_CAPS_LOCK_ON) atk_key_event->state |= AtkKeyModifierMask::kAtkLockMask; if (flags & ui::EF_CONTROL_DOWN) atk_key_event->state |= AtkKeyModifierMask::kAtkControlMask; if (flags & ui::EF_ALT_DOWN) atk_key_event->state |= AtkKeyModifierMask::kAtkMod1Mask; if (flags & ui::EF_NUM_LOCK_ON) atk_key_event->state |= AtkKeyModifierMask::kAtkMod2Mask; if (flags & ui::EF_MOD3_DOWN) atk_key_event->state |= AtkKeyModifierMask::kAtkMod3Mask; if (flags & ui::EF_COMMAND_DOWN) atk_key_event->state |= AtkKeyModifierMask::kAtkMod4Mask; if (flags & ui::EF_ALTGR_DOWN) atk_key_event->state |= AtkKeyModifierMask::KAtkMod5Mask; return atk_key_event; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/atk_event_conversion.cc
C++
unknown
2,223
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_X11_ATK_EVENT_CONVERSION_H_ #define UI_OZONE_PLATFORM_X11_ATK_EVENT_CONVERSION_H_ #include <atk/atk.h> #include <memory> #include "ui/gfx/x/event.h" namespace ui { // These values are duplicates of the GDK values that can be found in // <gdk/gdktypes.h>. ATK expects the GDK values, but we don't want to depend on // GDK here. typedef enum { kAtkShiftMask = 1 << 0, kAtkLockMask = 1 << 1, kAtkControlMask = 1 << 2, kAtkMod1Mask = 1 << 3, kAtkMod2Mask = 1 << 4, kAtkMod3Mask = 1 << 5, kAtkMod4Mask = 1 << 6, KAtkMod5Mask = 1 << 7, } AtkKeyModifierMask; std::unique_ptr<AtkKeyEventStruct> AtkKeyEventFromXEvent(const x11::Event& xev); } // namespace ui #endif // UI_OZONE_PLATFORM_X11_ATK_EVENT_CONVERSION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/atk_event_conversion.h
C++
unknown
903
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/x11/client_native_pixmap_factory_x11.h" #include "ui/gfx/linux/client_native_pixmap_factory_dmabuf.h" namespace ui { gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryX11() { return gfx::CreateClientNativePixmapFactoryDmabuf(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/client_native_pixmap_factory_x11.cc
C++
unknown
440
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_X11_CLIENT_NATIVE_PIXMAP_FACTORY_X11_H_ #define UI_OZONE_PLATFORM_X11_CLIENT_NATIVE_PIXMAP_FACTORY_X11_H_ namespace gfx { class ClientNativePixmapFactory; } namespace ui { // Constructor hook for use in constructor_list.cc gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryX11(); } // namespace ui #endif // UI_OZONE_PLATFORM_X11_CLIENT_NATIVE_PIXMAP_FACTORY_X11_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/client_native_pixmap_factory_x11.h
C++
unknown
556
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/x11/gl_egl_utility_x11.h" #include "ui/base/x/visual_picker_glx.h" #include "ui/base/x/x11_gl_egl_utility.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/gpu_extra_info.h" #include "ui/gfx/linux/gpu_memory_buffer_support_x11.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_utils.h" namespace ui { GLEGLUtilityX11::GLEGLUtilityX11() = default; GLEGLUtilityX11::~GLEGLUtilityX11() = default; void GLEGLUtilityX11::GetAdditionalEGLAttributes( EGLenum platform_type, std::vector<EGLAttrib>* display_attributes) { GetPlatformExtraDisplayAttribs(platform_type, display_attributes); } void GLEGLUtilityX11::ChooseEGLAlphaAndBufferSize(EGLint* alpha_size, EGLint* buffer_size) { ChoosePlatformCustomAlphaAndBufferSize(alpha_size, buffer_size); } bool GLEGLUtilityX11::IsTransparentBackgroundSupported() const { return ui::IsTransparentBackgroundSupported(); } void GLEGLUtilityX11::CollectGpuExtraInfo( bool enable_native_gpu_memory_buffers, gfx::GpuExtraInfo& gpu_extra_info) const { // TODO(https://crbug.com/1031269): Enable by default. if (enable_native_gpu_memory_buffers) { gpu_extra_info.gpu_memory_buffer_support_x11 = ui::GpuMemoryBufferSupportX11::GetInstance()->supported_configs(); } if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE) { // ANGLE does not yet support EGL_EXT_image_dma_buf_import[_modifiers]. gpu_extra_info.gpu_memory_buffer_support_x11.clear(); } } bool GLEGLUtilityX11::X11DoesVisualHaveAlphaForTest() const { return ui::DoesVisualHaveAlphaForTest(); } bool GLEGLUtilityX11::HasVisualManager() { return true; } absl::optional<base::ScopedEnvironmentVariableOverride> GLEGLUtilityX11::MaybeGetScopedDisplayUnsetForVulkan() { // Unset DISPLAY env, so the vulkan can be initialized successfully, if the // X server doesn't support Vulkan surface. if (!ui::IsVulkanSurfaceSupported()) return absl::optional<base::ScopedEnvironmentVariableOverride>("DISPLAY"); return absl::nullopt; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/gl_egl_utility_x11.cc
C++
unknown
2,252
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_X11_GL_EGL_UTILITY_X11_H_ #define UI_OZONE_PLATFORM_X11_GL_EGL_UTILITY_X11_H_ #include "ui/ozone/public/platform_gl_egl_utility.h" namespace ui { // Allows EGL to ask platforms for platform specific EGL attributes. class GLEGLUtilityX11 : public PlatformGLEGLUtility { public: GLEGLUtilityX11(); ~GLEGLUtilityX11() override; GLEGLUtilityX11(const GLEGLUtilityX11& util) = delete; GLEGLUtilityX11& operator=(const GLEGLUtilityX11& util) = delete; // PlatformGLEGLUtility overrides: void GetAdditionalEGLAttributes( EGLenum platform_type, std::vector<EGLAttrib>* display_attributes) override; void ChooseEGLAlphaAndBufferSize(EGLint* alpha_size, EGLint* buffer_size) override; bool IsTransparentBackgroundSupported() const override; void CollectGpuExtraInfo(bool enable_native_gpu_memory_buffers, gfx::GpuExtraInfo& gpu_extra_info) const override; bool X11DoesVisualHaveAlphaForTest() const override; bool HasVisualManager() override; absl::optional<base::ScopedEnvironmentVariableOverride> MaybeGetScopedDisplayUnsetForVulkan() override; }; } // namespace ui #endif // UI_OZONE_PLATFORM_X11_GL_EGL_UTILITY_X11_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/gl_egl_utility_x11.h
C++
unknown
1,391
// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/x11/gl_surface_egl_readback_x11.h" #include "base/logging.h" #include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkPixmap.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/x/xproto.h" namespace ui { namespace { constexpr x11::GraphicsContext kNoGC = x11::GraphicsContext{}; } GLSurfaceEglReadbackX11::GLSurfaceEglReadbackX11(gl::GLDisplayEGL* display, gfx::AcceleratedWidget window) : GLSurfaceEglReadback(display), window_(static_cast<x11::Window>(window)), connection_(x11::Connection::Get()) {} bool GLSurfaceEglReadbackX11::Initialize(gl::GLSurfaceFormat format) { if (!GLSurfaceEglReadback::Initialize(format)) return false; // We don't need to reinitialize |window_graphics_context_|. if (window_graphics_context_ != kNoGC) return true; window_graphics_context_ = connection_->GenerateId<x11::GraphicsContext>(); auto gc_future = connection_->CreateGC({window_graphics_context_, window_}); if (auto attributes = connection_->GetWindowAttributes({window_}).Sync()) { visual_ = attributes->visual; } else { DLOG(ERROR) << "Failed to get attributes for window " << static_cast<uint32_t>(window_); Destroy(); return false; } if (gc_future.Sync().error) { DLOG(ERROR) << "XCreateGC failed"; Destroy(); return false; } return true; } void GLSurfaceEglReadbackX11::Destroy() { if (window_graphics_context_ != kNoGC) { connection_->FreeGC({window_graphics_context_}); window_graphics_context_ = kNoGC; } connection_->Sync(); GLSurfaceEglReadback::Destroy(); } GLSurfaceEglReadbackX11::~GLSurfaceEglReadbackX11() { Destroy(); } bool GLSurfaceEglReadbackX11::HandlePixels(uint8_t* pixels) { SkImageInfo image_info = SkImageInfo::Make(GetSize().width(), GetSize().height(), kBGRA_8888_SkColorType, kPremul_SkAlphaType); SkPixmap pixmap(image_info, pixels, image_info.minRowBytes()); // Copy pixels into pixmap and then update the XWindow. const gfx::Size size = GetSize(); DrawPixmap(connection_, visual_, window_, window_graphics_context_, pixmap, 0, 0, 0, 0, size.width(), size.height()); return true; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/gl_surface_egl_readback_x11.cc
C++
unknown
2,469
// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_X11_GL_SURFACE_EGL_READBACK_X11_H_ #define UI_OZONE_PLATFORM_X11_GL_SURFACE_EGL_READBACK_X11_H_ #include "base/memory/raw_ptr.h" #include "ui/gfx/x/xproto.h" #include "ui/ozone/common/gl_surface_egl_readback.h" namespace ui { // GLSurface implementation that copies pixels from readback to an XWindow. class GLSurfaceEglReadbackX11 : public GLSurfaceEglReadback { public: GLSurfaceEglReadbackX11(gl::GLDisplayEGL* display, gfx::AcceleratedWidget window); GLSurfaceEglReadbackX11(const GLSurfaceEglReadbackX11&) = delete; GLSurfaceEglReadbackX11& operator=(const GLSurfaceEglReadbackX11&) = delete; // gl::GLSurface: bool Initialize(gl::GLSurfaceFormat format) override; void Destroy() override; private: ~GLSurfaceEglReadbackX11() override; // gl::GLSurfaceEglReadback: bool HandlePixels(uint8_t* pixels) override; const x11::Window window_; const raw_ptr<x11::Connection> connection_; x11::GraphicsContext window_graphics_context_{}; x11::VisualId visual_{}; }; } // namespace ui #endif // UI_OZONE_PLATFORM_X11_GL_SURFACE_EGL_READBACK_X11_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/gl_surface_egl_readback_x11.h
C++
unknown
1,280
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/x11/hit_test_x11.h" #include "ui/base/hit_test.h" namespace ui { namespace { // These constants are said to be defined in the Extended Window Manager Hints // standard but to be not found in any headers... constexpr int kSizeTopLeft = 0; constexpr int kSizeTop = 1; constexpr int kSizeTopRight = 2; constexpr int kSizeRight = 3; constexpr int kSizeBottomRight = 4; constexpr int kSizeBottom = 5; constexpr int kSizeBottomLeft = 6; constexpr int kSizeLeft = 7; constexpr int kMove = 8; } // namespace int HitTestToWmMoveResizeDirection(int hittest) { switch (hittest) { case HTBOTTOM: return kSizeBottom; case HTBOTTOMLEFT: return kSizeBottomLeft; case HTBOTTOMRIGHT: return kSizeBottomRight; case HTCAPTION: return kMove; case HTLEFT: return kSizeLeft; case HTRIGHT: return kSizeRight; case HTTOP: return kSizeTop; case HTTOPLEFT: return kSizeTopLeft; case HTTOPRIGHT: return kSizeTopRight; default: return -1; } } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/x11/hit_test_x11.cc
C++
unknown
1,218