From 157765aeab7ee377864ee93477be2df104475286 Mon Sep 17 00:00:00 2001 From: Ken Rockot Date: Fri, 7 May 2021 22:55:55 +0000 Subject: [PATCH] Revert "GPU: Migrate remaining control IPCs to Mojo" This reverts commit 42c21d0c3762650824e92882e0c1b64929923879. Reason for revert: Need to revert a CL this depended on, due to crbug.com/1206286 Original change's description: > GPU: Migrate remaining control IPCs to Mojo > > This migrates the GPU Channel's remaining three legacy IPC control > messages to Mojo. Remaining legacy IPC messages are specific to shared > images, or individual command buffers or stream texures. > > Bug: 1196476 > Change-Id: I79a788fefa986d5d9572cc6768970195342d3d9f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2847202 > Commit-Queue: Ken Rockot > Reviewed-by: Sunny Sachanandani > Reviewed-by: Tom Sepez > Reviewed-by: Xiaohan Wang > Cr-Commit-Position: refs/heads/master@{#879814} Bug: 1196476 Change-Id: Ic3bfc62b6d1b876290c2621fba5d3a1c54043956 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2879898 Bot-Commit: Rubber Stamper Owners-Override: Joseph Arhar (please use jarhar@chromium.org) Commit-Queue: Ken Rockot Reviewed-by: Xiaohan Wang Cr-Commit-Position: refs/heads/master@{#880611} --- .../media/android/stream_texture_factory.cc | 5 +- gpu/ipc/client/command_buffer_proxy_impl.cc | 29 +-- .../command_buffer_proxy_impl_unittest.cc | 79 ++----- gpu/ipc/common/BUILD.gn | 36 +-- .../context_creation_attribs_mojom_traits.cc | 47 ---- .../context_creation_attribs_mojom_traits.h | 214 ------------------ gpu/ipc/common/gpu_channel.mojom | 88 ------- gpu/ipc/common/gpu_messages.h | 32 +++ gpu/ipc/common/gpu_param_traits_macros.h | 2 + gpu/ipc/common/mock_gpu_channel.h | 16 -- .../common/scheduling_priority_mojom_traits.h | 52 ----- gpu/ipc/service/command_buffer_stub.cc | 2 +- gpu/ipc/service/command_buffer_stub.h | 6 +- gpu/ipc/service/gles2_command_buffer_stub.cc | 4 +- gpu/ipc/service/gles2_command_buffer_stub.h | 4 +- gpu/ipc/service/gpu_channel.cc | 177 +++++---------- gpu/ipc/service/gpu_channel.h | 21 +- .../service/gpu_channel_manager_unittest.cc | 32 ++- gpu/ipc/service/gpu_channel_test_common.cc | 37 +-- gpu/ipc/service/gpu_channel_test_common.h | 23 +- gpu/ipc/service/gpu_channel_unittest.cc | 198 ++++++++-------- .../image_decode_accelerator_stub_unittest.cc | 38 ++-- gpu/ipc/service/raster_command_buffer_stub.cc | 4 +- gpu/ipc/service/raster_command_buffer_stub.h | 4 +- gpu/ipc/service/webgpu_command_buffer_stub.cc | 4 +- gpu/ipc/service/webgpu_command_buffer_stub.h | 4 +- .../cpp/bindings/sync_call_restrictions.h | 12 +- 27 files changed, 317 insertions(+), 853 deletions(-) delete mode 100644 gpu/ipc/common/context_creation_attribs_mojom_traits.cc delete mode 100644 gpu/ipc/common/context_creation_attribs_mojom_traits.h delete mode 100644 gpu/ipc/common/scheduling_priority_mojom_traits.h diff --git a/content/renderer/media/android/stream_texture_factory.cc b/content/renderer/media/android/stream_texture_factory.cc index 15eec24c70daf9..29a376026367a2 100644 --- a/content/renderer/media/android/stream_texture_factory.cc +++ b/content/renderer/media/android/stream_texture_factory.cc @@ -137,10 +137,9 @@ bool StreamTextureFactory::IsLost() const { unsigned StreamTextureFactory::CreateStreamTexture() { int32_t stream_id = channel_->GenerateRouteID(); bool succeeded = false; - mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync; - channel_->GetGpuChannel().CreateStreamTexture(stream_id, &succeeded); + channel_->Send(new GpuChannelMsg_CreateStreamTexture(stream_id, &succeeded)); if (!succeeded) { - DLOG(ERROR) << "CreateStreamTexture returned failure"; + DLOG(ERROR) << "GpuChannelMsg_CreateStreamTexture returned failure"; return 0; } return stream_id; diff --git a/gpu/ipc/client/command_buffer_proxy_impl.cc b/gpu/ipc/client/command_buffer_proxy_impl.cc index dcd39eda005325..60f03e9d8f14da 100644 --- a/gpu/ipc/client/command_buffer_proxy_impl.cc +++ b/gpu/ipc/client/command_buffer_proxy_impl.cc @@ -32,7 +32,6 @@ #include "gpu/ipc/common/gpu_channel.mojom.h" #include "gpu/ipc/common/gpu_messages.h" #include "gpu/ipc/common/gpu_param_traits.h" -#include "mojo/public/cpp/bindings/sync_call_restrictions.h" #include "mojo/public/cpp/system/buffer.h" #include "mojo/public/cpp/system/platform_handle.h" #include "ui/gfx/buffer_format_util.h" @@ -78,14 +77,14 @@ ContextResult CommandBufferProxyImpl::Initialize( // prevent cleanup on destruction. auto channel = std::move(channel_); - auto params = mojom::CreateCommandBufferParams::New(); - params->surface_handle = surface_handle; - params->share_group_id = + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = surface_handle; + init_params.share_group_id = share_group ? share_group->route_id_ : MSG_ROUTING_NONE; - params->stream_id = stream_id_; - params->stream_priority = stream_priority; - params->attribs = attribs; - params->active_url = active_url; + init_params.stream_id = stream_id_; + init_params.stream_priority = stream_priority; + init_params.attribs = attribs; + init_params.active_url = active_url; TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); std::tie(shared_state_shm_, shared_state_mapping_) = @@ -118,17 +117,16 @@ ContextResult CommandBufferProxyImpl::Initialize( // so it won't cause additional jank. // TODO(piman): Make this asynchronous (http://crbug.com/125248). ContextResult result = ContextResult::kSuccess; - mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync; - bool sent = channel->GetGpuChannel().CreateCommandBuffer( - std::move(params), route_id_, std::move(region), &result, &capabilities_); + bool sent = channel->Send(new GpuChannelMsg_CreateCommandBuffer( + init_params, route_id_, std::move(region), &result, &capabilities_)); if (!sent) { channel->RemoveRoute(route_id_); LOG(ERROR) << "ContextResult::kTransientFailure: " - "Failed to send GpuControl.CreateCommandBuffer."; + "Failed to send GpuChannelMsg_CreateCommandBuffer."; return ContextResult::kTransientFailure; } if (result != ContextResult::kSuccess) { - DLOG(ERROR) << "Failure processing GpuControl.CreateCommandBuffer."; + DLOG(ERROR) << "Failure processing GpuChannelMsg_CreateCommandBuffer."; channel->RemoveRoute(route_id_); return result; } @@ -921,10 +919,7 @@ void CommandBufferProxyImpl::DisconnectChannel() { return; disconnected_ = true; channel_->VerifyFlush(UINT32_MAX); - - mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync; - channel_->GetGpuChannel().DestroyCommandBuffer(route_id_); - + channel_->Send(new GpuChannelMsg_DestroyCommandBuffer(route_id_)); channel_->RemoveRoute(route_id_); if (gpu_control_client_) gpu_control_client_->OnGpuControlLostContext(); diff --git a/gpu/ipc/client/command_buffer_proxy_impl_unittest.cc b/gpu/ipc/client/command_buffer_proxy_impl_unittest.cc index b89a407b742807..45c3df4e55e5d1 100644 --- a/gpu/ipc/client/command_buffer_proxy_impl_unittest.cc +++ b/gpu/ipc/client/command_buffer_proxy_impl_unittest.cc @@ -87,20 +87,6 @@ class CommandBufferProxyImplTest : public testing::Test { auto proxy = std::make_unique( channel_, nullptr /* gpu_memory_buffer_manager */, 0 /* stream_id */, base::ThreadTaskRunnerHandle::Get()); - - // The Initialize() call below synchronously requests a new CommandBuffer - // using the channel's GpuControl interface. Simulate success, since we're - // not actually talking to the service in these tests. - EXPECT_CALL(mock_gpu_channel_, CreateCommandBuffer(_, _, _, _, _)) - .Times(1) - .WillOnce(Invoke( - [&](mojom::CreateCommandBufferParamsPtr params, int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state, - ContextResult* result, Capabilities* capabilities) -> bool { - *result = ContextResult::kSuccess; - return true; - })); - proxy->Initialize(kNullSurfaceHandle, nullptr, SchedulingPriority::kNormal, ContextCreationAttribs(), GURL()); // Use an arbitrary valid shm_id. The command buffer doesn't use this @@ -151,12 +137,7 @@ TEST_F(CommandBufferProxyImplTest, OrderingBarriersAreCoalescedWithFlush) { proxy1->OrderingBarrier(40); proxy1->Flush(50); - // Once for each proxy. - EXPECT_CALL(mock_gpu_channel_, DestroyCommandBuffer(_)) - .Times(2) - .WillRepeatedly(Return(true)); - - // Each proxy sends a sync GpuControl flush on disconnect. + // Each proxy sends a sync GpuChannel flush on disconnect. EXPECT_CALL(mock_gpu_channel_, Flush()).Times(2).WillRepeatedly(Return(true)); EXPECT_EQ(0u, sink_.message_count()); } @@ -179,12 +160,7 @@ TEST_F(CommandBufferProxyImplTest, FlushPendingWorkFlushesOrderingBarriers) { proxy1->OrderingBarrier(30); proxy2->FlushPendingWork(); - // Once for each proxy. - EXPECT_CALL(mock_gpu_channel_, DestroyCommandBuffer(_)) - .Times(2) - .WillRepeatedly(Return(true)); - - // Each proxy sends a sync GpuControl flush on disconnect. + // Each proxy sends a sync GpuChannel flush on disconnect. EXPECT_CALL(mock_gpu_channel_, Flush()).Times(2).WillRepeatedly(Return(true)); EXPECT_EQ(0u, sink_.message_count()); } @@ -193,23 +169,21 @@ TEST_F(CommandBufferProxyImplTest, EnsureWorkVisibleFlushesOrderingBarriers) { auto proxy1 = CreateAndInitializeProxy(); auto proxy2 = CreateAndInitializeProxy(); - // Ordering of these flush operations must be preserved. - { - ::testing::InSequence in_sequence; - - // First we expect to see a FlushDeferredRequests call. - EXPECT_CALL(mock_gpu_channel_, FlushDeferredRequests(_)) - .Times(1) - .WillOnce(Invoke([&](std::vector requests) { - EXPECT_EQ(3u, requests.size()); - ExpectOrderingBarrier(*requests[0], proxy1->route_id(), 10); - ExpectOrderingBarrier(*requests[1], proxy2->route_id(), 20); - ExpectOrderingBarrier(*requests[2], proxy1->route_id(), 30); - })); - - // Next we expect a full `Flush()`. - EXPECT_CALL(mock_gpu_channel_, Flush()).Times(1).RetiresOnSaturation(); - } + // Ordering of the flush operations must be preserved. + ::testing::InSequence in_sequence; + + // First we expect to see a FlushDeferredRequests call. + EXPECT_CALL(mock_gpu_channel_, FlushDeferredRequests(_)) + .Times(1) + .WillOnce(Invoke([&](std::vector requests) { + EXPECT_EQ(3u, requests.size()); + ExpectOrderingBarrier(*requests[0], proxy1->route_id(), 10); + ExpectOrderingBarrier(*requests[1], proxy2->route_id(), 20); + ExpectOrderingBarrier(*requests[2], proxy1->route_id(), 30); + })); + + // Next we expect a full `Flush()`. + EXPECT_CALL(mock_gpu_channel_, Flush()).Times(1); proxy1->OrderingBarrier(10); proxy2->OrderingBarrier(20); @@ -217,12 +191,7 @@ TEST_F(CommandBufferProxyImplTest, EnsureWorkVisibleFlushesOrderingBarriers) { proxy2->EnsureWorkVisible(); - // Once for each proxy. - EXPECT_CALL(mock_gpu_channel_, DestroyCommandBuffer(_)) - .Times(2) - .WillRepeatedly(Return(true)); - - // Each proxy sends a sync GpuControl flush on disconnect. + // Each proxy sends a sync GpuChannel flush on disconnect. EXPECT_CALL(mock_gpu_channel_, Flush()).Times(2).WillRepeatedly(Return(true)); EXPECT_EQ(0u, sink_.message_count()); } @@ -258,11 +227,7 @@ TEST_F(CommandBufferProxyImplTest, proxy1->FlushPendingWork(); - EXPECT_CALL(mock_gpu_channel_, DestroyCommandBuffer(_)) - .Times(1) - .WillOnce(Return(true)); - - // The proxy sends a sync GpuControl flush on disconnect. + // The proxy sends a sync GpuChannel flush on disconnect. EXPECT_CALL(mock_gpu_channel_, Flush()).Times(1).WillRepeatedly(Return(true)); EXPECT_EQ(0u, sink_.message_count()); } @@ -313,11 +278,7 @@ TEST_F(CommandBufferProxyImplTest, CreateTransferBufferOOM) { std::numeric_limits::max(), &id, TransferBufferAllocationOption::kLoseContextOnOOM); - EXPECT_CALL(mock_gpu_channel_, DestroyCommandBuffer(_)) - .Times(1) - .WillOnce(Return(true)); - - // The proxy sends a sync GpuControl flush on disconnect. + // The proxy sends a sync GpuChannel flush on disconnect. EXPECT_CALL(mock_gpu_channel_, Flush()).Times(1).WillRepeatedly(Return(true)); } diff --git a/gpu/ipc/common/BUILD.gn b/gpu/ipc/common/BUILD.gn index 87ca0a1ceb1042..98bca0a03eb664 100644 --- a/gpu/ipc/common/BUILD.gn +++ b/gpu/ipc/common/BUILD.gn @@ -235,44 +235,10 @@ mojom("gpu_channel_mojom") { "//skia/public/mojom", "//ui/gfx/geometry/mojom", "//ui/gfx/mojom", - "//ui/gl/mojom", - "//url/mojom:url_mojom_gurl", ] mojom_source_deps = [ ":interfaces" ] - cpp_typemaps = [ - { - types = [ - { - mojom = "gpu.mojom.ContextColorspace" - cpp = "::gpu::ColorSpace" - }, - { - mojom = "gpu.mojom.ContextCreationAttribs" - cpp = "::gpu::ContextCreationAttribs" - }, - { - mojom = "gpu.mojom.ContextType" - cpp = "::gpu::ContextType" - }, - ] - traits_headers = [ "context_creation_attribs_mojom_traits.h" ] - traits_sources = [ "context_creation_attribs_mojom_traits.cc" ] - traits_public_deps = [ "//gpu/command_buffer/common:common_base_sources" ] - }, - { - types = [ - { - mojom = "gpu.mojom.SchedulingPriority" - cpp = "::gpu::SchedulingPriority" - }, - ] - traits_headers = [ "scheduling_priority_mojom_traits.h" ] - traits_public_deps = [ "//gpu/command_buffer/common:common_base_sources" ] - }, - ] - # Unlike some definitions in ":interfaces_mojom", these bindings are never # used in Blink. We disable variants to simplify the dependency graph. disable_variants = true @@ -725,7 +691,7 @@ source_set("test_support") { "mock_gpu_channel.h", ] public_deps = [ - ":common", + ":interfaces", "//testing/gmock", ] } diff --git a/gpu/ipc/common/context_creation_attribs_mojom_traits.cc b/gpu/ipc/common/context_creation_attribs_mojom_traits.cc deleted file mode 100644 index d650cc62edf7c8..00000000000000 --- a/gpu/ipc/common/context_creation_attribs_mojom_traits.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "gpu/ipc/common/context_creation_attribs_mojom_traits.h" - -#include "ui/gfx/geometry/mojom/geometry_mojom_traits.h" -#include "ui/gl/mojom/gpu_preference_mojom_traits.h" - -namespace mojo { - -bool StructTraits:: - Read(gpu::mojom::ContextCreationAttribsDataView data, - gpu::ContextCreationAttribs* out) { - if (!data.ReadOffscreenFramebufferSize(&out->offscreen_framebuffer_size) || - !data.ReadGpuPreference(&out->gpu_preference) || - !data.ReadContextType(&out->context_type) || - !data.ReadColorSpace(&out->color_space)) { - return false; - } - out->alpha_size = data.alpha_size(); - out->blue_size = data.blue_size(); - out->green_size = data.green_size(); - out->red_size = data.red_size(); - out->depth_size = data.depth_size(); - out->stencil_size = data.stencil_size(); - out->samples = data.samples(); - out->sample_buffers = data.sample_buffers(); - out->buffer_preserved = data.buffer_preserved(); - out->bind_generates_resource = data.bind_generates_resource(); - out->fail_if_major_perf_caveat = data.fail_if_major_perf_caveat(); - out->lose_context_when_out_of_memory = data.lose_context_when_out_of_memory(); - out->should_use_native_gmb_for_backbuffer = - data.should_use_native_gmb_for_backbuffer(); - out->own_offscreen_surface = data.own_offscreen_surface(); - out->single_buffer = data.single_buffer(); - out->enable_gles2_interface = data.enable_gles2_interface(); - out->enable_grcontext = data.enable_grcontext(); - out->enable_raster_interface = data.enable_raster_interface(); - out->enable_oop_rasterization = data.enable_oop_rasterization(); - out->enable_swap_timestamps_if_supported = - data.enable_swap_timestamps_if_supported(); - return true; -} - -} // namespace mojo diff --git a/gpu/ipc/common/context_creation_attribs_mojom_traits.h b/gpu/ipc/common/context_creation_attribs_mojom_traits.h deleted file mode 100644 index 3f786ebf2e3d89..00000000000000 --- a/gpu/ipc/common/context_creation_attribs_mojom_traits.h +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_IPC_COMMON_CONTEXT_CREATION_ATTRIBS_MOJOM_TRAITS_H_ -#define GPU_IPC_COMMON_CONTEXT_CREATION_ATTRIBS_MOJOM_TRAITS_H_ - -#include "gpu/command_buffer/common/context_creation_attribs.h" -#include "gpu/gpu_export.h" -#include "gpu/ipc/common/gpu_channel.mojom-shared.h" -#include "mojo/public/cpp/bindings/enum_traits.h" -#include "mojo/public/cpp/bindings/struct_traits.h" - -namespace mojo { - -template <> -struct GPU_EXPORT EnumTraits { - static gpu::mojom::ContextColorSpace ToMojom(gpu::ColorSpace color_space) { - switch (color_space) { - case gpu::COLOR_SPACE_UNSPECIFIED: - return gpu::mojom::ContextColorSpace::kUnspecified; - case gpu::COLOR_SPACE_SRGB: - return gpu::mojom::ContextColorSpace::kSRGB; - case gpu::COLOR_SPACE_DISPLAY_P3: - return gpu::mojom::ContextColorSpace::kDisplayP3; - default: - NOTREACHED(); - } - } - - static bool FromMojom(gpu::mojom::ContextColorSpace color_space, - gpu::ColorSpace* out) { - switch (color_space) { - case gpu::mojom::ContextColorSpace::kUnspecified: - *out = gpu::COLOR_SPACE_UNSPECIFIED; - return true; - case gpu::mojom::ContextColorSpace::kSRGB: - *out = gpu::COLOR_SPACE_SRGB; - return true; - case gpu::mojom::ContextColorSpace::kDisplayP3: - *out = gpu::COLOR_SPACE_DISPLAY_P3; - return true; - default: - return false; - } - } -}; - -template <> -struct GPU_EXPORT EnumTraits { - static gpu::mojom::ContextType ToMojom(gpu::ContextType type) { - switch (type) { - case gpu::CONTEXT_TYPE_WEBGL1: - return gpu::mojom::ContextType::kWebGL1; - case gpu::CONTEXT_TYPE_WEBGL2: - return gpu::mojom::ContextType::kWebGL2; - case gpu::CONTEXT_TYPE_OPENGLES2: - return gpu::mojom::ContextType::kOpenGLES2; - case gpu::CONTEXT_TYPE_OPENGLES3: - return gpu::mojom::ContextType::kOpenGLES3; - case gpu::CONTEXT_TYPE_OPENGLES31_FOR_TESTING: - return gpu::mojom::ContextType::kOpenGLES31ForTesting; - case gpu::CONTEXT_TYPE_WEBGPU: - return gpu::mojom::ContextType::kWebGPU; - default: - NOTREACHED(); - } - } - - static bool FromMojom(gpu::mojom::ContextType type, gpu::ContextType* out) { - switch (type) { - case gpu::mojom::ContextType::kWebGL1: - *out = gpu::CONTEXT_TYPE_WEBGL1; - return true; - case gpu::mojom::ContextType::kWebGL2: - *out = gpu::CONTEXT_TYPE_WEBGL2; - return true; - case gpu::mojom::ContextType::kOpenGLES2: - *out = gpu::CONTEXT_TYPE_OPENGLES2; - return true; - case gpu::mojom::ContextType::kOpenGLES3: - *out = gpu::CONTEXT_TYPE_OPENGLES3; - return true; - case gpu::mojom::ContextType::kOpenGLES31ForTesting: - *out = gpu::CONTEXT_TYPE_OPENGLES31_FOR_TESTING; - return true; - case gpu::mojom::ContextType::kWebGPU: - *out = gpu::CONTEXT_TYPE_WEBGPU; - return true; - default: - return false; - } - } -}; - -template <> -struct GPU_EXPORT StructTraits { - static gfx::Size offscreen_framebuffer_size( - const gpu::ContextCreationAttribs& attribs) { - return attribs.offscreen_framebuffer_size; - } - - static gl::GpuPreference gpu_preference( - const gpu::ContextCreationAttribs& attribs) { - return attribs.gpu_preference; - } - - static int32_t alpha_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.alpha_size; - } - - static int32_t blue_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.blue_size; - } - - static int32_t green_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.green_size; - } - - static int32_t red_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.red_size; - } - - static int32_t depth_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.depth_size; - } - - static int32_t stencil_size(const gpu::ContextCreationAttribs& attribs) { - return attribs.stencil_size; - } - - static int32_t samples(const gpu::ContextCreationAttribs& attribs) { - return attribs.samples; - } - - static int32_t sample_buffers(const gpu::ContextCreationAttribs& attribs) { - return attribs.sample_buffers; - } - - static bool buffer_preserved(const gpu::ContextCreationAttribs& attribs) { - return attribs.buffer_preserved; - } - - static bool bind_generates_resource( - const gpu::ContextCreationAttribs& attribs) { - return attribs.bind_generates_resource; - } - - static bool fail_if_major_perf_caveat( - const gpu::ContextCreationAttribs& attribs) { - return attribs.fail_if_major_perf_caveat; - } - - static bool lose_context_when_out_of_memory( - const gpu::ContextCreationAttribs& attribs) { - return attribs.lose_context_when_out_of_memory; - } - - static bool should_use_native_gmb_for_backbuffer( - const gpu::ContextCreationAttribs& attribs) { - return attribs.should_use_native_gmb_for_backbuffer; - } - - static bool own_offscreen_surface( - const gpu::ContextCreationAttribs& attribs) { - return attribs.own_offscreen_surface; - } - - static bool single_buffer(const gpu::ContextCreationAttribs& attribs) { - return attribs.single_buffer; - } - - static bool enable_gles2_interface( - const gpu::ContextCreationAttribs& attribs) { - return attribs.enable_gles2_interface; - } - - static bool enable_grcontext(const gpu::ContextCreationAttribs& attribs) { - return attribs.enable_grcontext; - } - - static bool enable_raster_interface( - const gpu::ContextCreationAttribs& attribs) { - return attribs.enable_raster_interface; - } - - static bool enable_oop_rasterization( - const gpu::ContextCreationAttribs& attribs) { - return attribs.enable_oop_rasterization; - } - - static bool enable_swap_timestamps_if_supported( - const gpu::ContextCreationAttribs& attribs) { - return attribs.enable_swap_timestamps_if_supported; - } - - static gpu::ContextType context_type( - const gpu::ContextCreationAttribs& attribs) { - return attribs.context_type; - } - - static gpu::ColorSpace color_space( - const gpu::ContextCreationAttribs& attribs) { - return attribs.color_space; - } - - static bool Read(gpu::mojom::ContextCreationAttribsDataView data, - gpu::ContextCreationAttribs* out); -}; - -} // namespace mojo - -#endif // GPU_IPC_COMMON_CONTEXT_CREATION_ATTRIBS_MOJOM_TRAITS_H_ diff --git a/gpu/ipc/common/gpu_channel.mojom b/gpu/ipc/common/gpu_channel.mojom index 95ef9ecb3025f1..2d8c41783b2d11 100644 --- a/gpu/ipc/common/gpu_channel.mojom +++ b/gpu/ipc/common/gpu_channel.mojom @@ -4,84 +4,14 @@ module gpu.mojom; -import "gpu/ipc/common/capabilities.mojom"; -import "gpu/ipc/common/context_result.mojom"; import "gpu/ipc/common/mailbox.mojom"; -import "gpu/ipc/common/surface_handle.mojom"; import "gpu/ipc/common/sync_token.mojom"; -import "mojo/public/mojom/base/shared_memory.mojom"; import "services/viz/public/mojom/compositing/resource_format.mojom"; import "skia/public/mojom/image_info.mojom"; import "skia/public/mojom/surface_origin.mojom"; import "ui/gfx/geometry/mojom/geometry.mojom"; import "ui/gfx/mojom/color_space.mojom"; import "ui/gfx/mojom/gpu_fence_handle.mojom"; -import "ui/gl/mojom/gpu_preference.mojom"; -import "url/mojom/url.mojom"; - -// Maps to its namesake in gpu/command_buffer/common/context_creation_attribs.h. -enum ContextType { - kWebGL1, - kWebGL2, - kOpenGLES2, - kOpenGLES3, - kOpenGLES31ForTesting, - kWebGPU, -}; - -// Maps to its namesake in gpu/command_buffer/common/context_creation_attribs.h. -enum ContextColorSpace { - kUnspecified, - kSRGB, - kDisplayP3, -}; - -// Maps to its namesake in gpu/command_buffer/common/scheduling_priority.h. -enum SchedulingPriority { - kHigh, - kNormal, - kLow, -}; - -// Maps to its namesake in gpu/command_buffer/common/context_creation_attribs.h. -struct ContextCreationAttribs { - gfx.mojom.Size offscreen_framebuffer_size; - gl.mojom.GpuPreference gpu_preference = kLowPower; - - // -1 if invalid or unspecified. - int32 alpha_size = -1; - int32 blue_size = -1; - int32 green_size = -1; - int32 red_size = -1; - int32 depth_size = -1; - int32 stencil_size = -1; - int32 samples = -1; - int32 sample_buffers = -1; - bool buffer_preserved = true; - bool bind_generates_resource = true; - bool fail_if_major_perf_caveat = false; - bool lose_context_when_out_of_memory = false; - bool should_use_native_gmb_for_backbuffer = false; - bool own_offscreen_surface = false; - bool single_buffer = false; - bool enable_gles2_interface = true; - bool enable_grcontext = false; - bool enable_raster_interface = false; - bool enable_oop_rasterization = false; - bool enable_swap_timestamps_if_supported = false; - - ContextType context_type = kOpenGLES2; - ContextColorSpace color_space = kUnspecified; -}; - -struct CreateCommandBufferParams { - SurfaceHandle surface_handle; - int32 share_group_id; - int32 stream_id; - SchedulingPriority stream_priority; - ContextCreationAttribs attribs; - url.mojom.Url active_url; -}; struct ScheduleImageDecodeParams { array encoded_data; @@ -122,21 +52,6 @@ interface GpuChannel { // GPU IO thread, which is never allowed to block. [Sync, NoInterrupt] Flush() => (); - // Tells the GPU process to create a new command buffer. A corresponding - // CommandBufferStub is created. If `params` provides a non-null - // SurfaceHandle, |size| is ignored and it will render directly to the native - // surface (only the browser process is allowed to create those). Otherwise it - // will create an offscreen backbuffer of dimensions `size`. - [Sync, NoInterrupt] CreateCommandBuffer( - CreateCommandBufferParams params, int32 routing_id, - mojo_base.mojom.UnsafeSharedMemoryRegion shared_state) - => (ContextResult result, Capabilities capabilties); - - // The CommandBufferProxy sends this to the CommandBufferStub in its - // destructor, so that the stub deletes the actual CommandBufferService - // object that it's hosting. - [Sync, NoInterrupt] DestroyCommandBuffer(int32 routing_id) => (); - // Schedules a hardware-accelerated image decode in the GPU process. Renderers // should use gpu::ImageDecodeAcceleratorProxy to schedule decode requests // which are processed by gpu::ImageDecodeAcceleratorStub on the service side. @@ -145,9 +60,6 @@ interface GpuChannel { // Sends a batch of DeferredRequests to be executed by the service. FlushDeferredRequests(array requests); - - // Creates a StreamTexture associated with the given `stream_id`. - [Sync] CreateStreamTexture(int32 stream_id) => (bool success); }; // DeferredRequests are batched locally by clients and sent to the service only diff --git a/gpu/ipc/common/gpu_messages.h b/gpu/ipc/common/gpu_messages.h index f03e137e8b6548..b4ad95300079c4 100644 --- a/gpu/ipc/common/gpu_messages.h +++ b/gpu/ipc/common/gpu_messages.h @@ -63,6 +63,15 @@ IPC_STRUCT_BEGIN(GPUCommandBufferConsoleMessage) IPC_STRUCT_MEMBER(std::string, message) IPC_STRUCT_END() +IPC_STRUCT_BEGIN(GPUCreateCommandBufferConfig) + IPC_STRUCT_MEMBER(gpu::SurfaceHandle, surface_handle) + IPC_STRUCT_MEMBER(int32_t, share_group_id) + IPC_STRUCT_MEMBER(int32_t, stream_id) + IPC_STRUCT_MEMBER(gpu::SchedulingPriority, stream_priority) + IPC_STRUCT_MEMBER(gpu::ContextCreationAttribs, attribs) + IPC_STRUCT_MEMBER(GURL, active_url) +IPC_STRUCT_END() + IPC_STRUCT_BEGIN(GpuCommandBufferMsg_CreateImage_Params) IPC_STRUCT_MEMBER(int32_t, id) IPC_STRUCT_MEMBER(gfx::GpuMemoryBufferHandle, gpu_memory_buffer) @@ -91,6 +100,24 @@ IPC_STRUCT_END() // GPU Channel Messages // These are messages from a renderer process to the GPU process. +// Tells the GPU process to create a new command buffer. A corresponding +// CommandBufferStub is created. If |surface_handle| is non-null, |size| +// is ignored, and it will render directly to the native surface (only the +// browser process is allowed to create those). Otherwise it will create an +// offscreen backbuffer of dimensions |size|. +IPC_SYNC_MESSAGE_CONTROL3_2(GpuChannelMsg_CreateCommandBuffer, + GPUCreateCommandBufferConfig /* init_params */, + int32_t /* route_id */, + base::UnsafeSharedMemoryRegion /* shared_state */, + gpu::ContextResult, + gpu::Capabilities /* capabilities */) + +// The CommandBufferProxy sends this to the CommandBufferStub in its +// destructor, so that the stub deletes the actual CommandBufferService +// object that it's hosting. +IPC_SYNC_MESSAGE_CONTROL1_0(GpuChannelMsg_DestroyCommandBuffer, + int32_t /* instance_id */) + IPC_MESSAGE_ROUTED1(GpuChannelMsg_CreateGMBSharedImage, GpuChannelMsg_CreateGMBSharedImage_Params /* params */) @@ -107,6 +134,11 @@ IPC_MESSAGE_ROUTED1(GpuChannelMsg_ReleaseSysmemBufferCollection, IPC_MESSAGE_ROUTED1(GpuChannelMsg_RegisterSharedImageUploadBuffer, base::ReadOnlySharedMemoryRegion /* shm */) +// Creates a StreamTexture attached to the provided |stream_id|. +IPC_SYNC_MESSAGE_CONTROL1_1(GpuChannelMsg_CreateStreamTexture, + int32_t, /* stream_id */ + bool /* succeeded */) + #if defined(OS_ANDROID) //------------------------------------------------------------------------------ // Tells the StreamTexture to send its SurfaceTexture to the browser process, diff --git a/gpu/ipc/common/gpu_param_traits_macros.h b/gpu/ipc/common/gpu_param_traits_macros.h index 4514e1ad88b67e..9fd93a4b637667 100644 --- a/gpu/ipc/common/gpu_param_traits_macros.h +++ b/gpu/ipc/common/gpu_param_traits_macros.h @@ -21,6 +21,8 @@ IPC_ENUM_TRAITS_MAX_VALUE(gpu::SchedulingPriority, gpu::SchedulingPriority::kLast) +IPC_ENUM_TRAITS_MAX_VALUE(gpu::ContextResult, + gpu::ContextResult::kLastContextResult) IPC_STRUCT_TRAITS_BEGIN(gpu::SwapBuffersCompleteParams) IPC_STRUCT_TRAITS_MEMBER(ca_layer_params) diff --git a/gpu/ipc/common/mock_gpu_channel.h b/gpu/ipc/common/mock_gpu_channel.h index aa4110494330b7..a11480b2e3a8d0 100644 --- a/gpu/ipc/common/mock_gpu_channel.h +++ b/gpu/ipc/common/mock_gpu_channel.h @@ -20,26 +20,10 @@ class MockGpuChannel : public mojom::GpuChannel { MOCK_METHOD0(TerminateForTesting, void()); MOCK_METHOD0(Flush, bool()); MOCK_METHOD1(Flush, void(FlushCallback)); - MOCK_METHOD4(CreateCommandBuffer, - void(mojom::CreateCommandBufferParamsPtr, - int32_t, - base::UnsafeSharedMemoryRegion, - CreateCommandBufferCallback)); - MOCK_METHOD5(CreateCommandBuffer, - bool(mojom::CreateCommandBufferParamsPtr, - int32_t, - base::UnsafeSharedMemoryRegion, - ContextResult*, - Capabilities*)); - MOCK_METHOD1(DestroyCommandBuffer, bool(int32_t)); - MOCK_METHOD2(DestroyCommandBuffer, - void(int32_t, DestroyCommandBufferCallback)); MOCK_METHOD2(ScheduleImageDecode, void(mojom::ScheduleImageDecodeParamsPtr, uint64_t)); MOCK_METHOD1(FlushDeferredRequests, void(std::vector)); - MOCK_METHOD2(CreateStreamTexture, bool(int32_t, bool*)); - MOCK_METHOD2(CreateStreamTexture, void(int32_t, CreateStreamTextureCallback)); }; } // namespace gpu diff --git a/gpu/ipc/common/scheduling_priority_mojom_traits.h b/gpu/ipc/common/scheduling_priority_mojom_traits.h deleted file mode 100644 index 85cfa1030c5029..00000000000000 --- a/gpu/ipc/common/scheduling_priority_mojom_traits.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_IPC_COMMON_SCHEDULING_PRIORITY_MOJOM_TRAITS_H_ -#define GPU_IPC_COMMON_SCHEDULING_PRIORITY_MOJOM_TRAITS_H_ - -#include "gpu/command_buffer/common/scheduling_priority.h" -#include "gpu/gpu_export.h" -#include "gpu/ipc/common/gpu_channel.mojom-shared.h" -#include "mojo/public/cpp/bindings/enum_traits.h" - -namespace mojo { - -template <> -struct GPU_EXPORT - EnumTraits { - static gpu::mojom::SchedulingPriority ToMojom( - gpu::SchedulingPriority priority) { - switch (priority) { - case gpu::SchedulingPriority::kHigh: - return gpu::mojom::SchedulingPriority::kHigh; - case gpu::SchedulingPriority::kNormal: - return gpu::mojom::SchedulingPriority::kNormal; - case gpu::SchedulingPriority::kLow: - return gpu::mojom::SchedulingPriority::kNormal; - default: - NOTREACHED(); - } - } - - static bool FromMojom(gpu::mojom::SchedulingPriority priority, - gpu::SchedulingPriority* out_priority) { - switch (priority) { - case gpu::mojom::SchedulingPriority::kHigh: - *out_priority = gpu::SchedulingPriority::kHigh; - return true; - case gpu::mojom::SchedulingPriority::kNormal: - *out_priority = gpu::SchedulingPriority::kNormal; - return true; - case gpu::mojom::SchedulingPriority::kLow: - *out_priority = gpu::SchedulingPriority::kLow; - return true; - default: - return false; - } - } -}; - -} // namespace mojo - -#endif // GPU_IPC_COMMON_SCHEDULING_PRIORITY_MOJOM_TRAITS_H_ diff --git a/gpu/ipc/service/command_buffer_stub.cc b/gpu/ipc/service/command_buffer_stub.cc index 9bc0ab7a5748f8..64b24c3d7f0d1a 100644 --- a/gpu/ipc/service/command_buffer_stub.cc +++ b/gpu/ipc/service/command_buffer_stub.cc @@ -100,7 +100,7 @@ DevToolsChannelData::CreateForChannel(GpuChannel* channel) { CommandBufferStub::CommandBufferStub( GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, diff --git a/gpu/ipc/service/command_buffer_stub.h b/gpu/ipc/service/command_buffer_stub.h index 49bfb0080332e1..b44a507736decb 100644 --- a/gpu/ipc/service/command_buffer_stub.h +++ b/gpu/ipc/service/command_buffer_stub.h @@ -41,6 +41,8 @@ #include "ui/gl/gpu_preference.h" #include "url/gurl.h" +struct GPUCreateCommandBufferConfig; + namespace gpu { class DecoderContext; class MemoryTracker; @@ -68,7 +70,7 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub }; CommandBufferStub(GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -81,7 +83,7 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub // the gpu::Capabilities. virtual gpu::ContextResult Initialize( CommandBufferStub* share_group, - const mojom::CreateCommandBufferParams& params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) = 0; MemoryTracker* GetMemoryTracker() const; diff --git a/gpu/ipc/service/gles2_command_buffer_stub.cc b/gpu/ipc/service/gles2_command_buffer_stub.cc index d01073bf7f2d0c..c1bd47758ca561 100644 --- a/gpu/ipc/service/gles2_command_buffer_stub.cc +++ b/gpu/ipc/service/gles2_command_buffer_stub.cc @@ -62,7 +62,7 @@ namespace gpu { GLES2CommandBufferStub::GLES2CommandBufferStub( GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -79,7 +79,7 @@ GLES2CommandBufferStub::~GLES2CommandBufferStub() = default; gpu::ContextResult GLES2CommandBufferStub::Initialize( CommandBufferStub* share_command_buffer_stub, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) { TRACE_EVENT0("gpu", "GLES2CommandBufferStub::Initialize"); UpdateActiveUrl(); diff --git a/gpu/ipc/service/gles2_command_buffer_stub.h b/gpu/ipc/service/gles2_command_buffer_stub.h index 38d9d9552330b9..aba4a565ee829a 100644 --- a/gpu/ipc/service/gles2_command_buffer_stub.h +++ b/gpu/ipc/service/gles2_command_buffer_stub.h @@ -22,7 +22,7 @@ class GPU_IPC_SERVICE_EXPORT GLES2CommandBufferStub public base::SupportsWeakPtr { public: GLES2CommandBufferStub(GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -35,7 +35,7 @@ class GPU_IPC_SERVICE_EXPORT GLES2CommandBufferStub // the gpu::Capabilities. gpu::ContextResult Initialize( CommandBufferStub* share_group, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) override; MemoryTracker* GetContextGroupMemoryTracker() const override; diff --git a/gpu/ipc/service/gpu_channel.cc b/gpu/ipc/service/gpu_channel.cc index 7de04ca34e6074..8cc5fa15a72e79 100644 --- a/gpu/ipc/service/gpu_channel.cc +++ b/gpu/ipc/service/gpu_channel.cc @@ -17,7 +17,6 @@ #include "base/atomicops.h" #include "base/bind.h" -#include "base/bind_post_task.h" #include "base/command_line.h" #include "base/containers/circular_deque.h" #include "base/location.h" @@ -81,17 +80,6 @@ struct GpuChannelMessage { DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage); }; -namespace { - -bool TryCreateStreamTexture(base::WeakPtr channel, - int32_t stream_id) { - if (!channel) - return false; - return channel->CreateStreamTexture(stream_id); -} - -} // namespace - // This filter does the following: // - handles the Nop message used for verifying sync tokens on the IO thread // - forwards messages to child message filters @@ -146,18 +134,10 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter void CrashForTesting() override; void TerminateForTesting() override; void Flush(FlushCallback callback) override; - void CreateCommandBuffer(mojom::CreateCommandBufferParamsPtr config, - int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state, - CreateCommandBufferCallback callback) override; - void DestroyCommandBuffer(int32_t routing_id, - DestroyCommandBufferCallback callback) override; void ScheduleImageDecode(mojom::ScheduleImageDecodeParamsPtr params, uint64_t decode_release_count) override; void FlushDeferredRequests( std::vector requests) override; - void CreateStreamTexture(int32_t stream_id, - CreateStreamTextureCallback callback) override; IPC::Channel* ipc_channel_ = nullptr; base::ProcessId peer_pid_ = base::kNullProcessId; @@ -403,42 +383,6 @@ void GpuChannelMessageFilter::Flush(FlushCallback callback) { std::move(callback).Run(); } -void GpuChannelMessageFilter::CreateCommandBuffer( - mojom::CreateCommandBufferParamsPtr params, - int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state, - CreateCommandBufferCallback callback) { - base::AutoLock auto_lock(gpu_channel_lock_); - if (!gpu_channel_) { - std::move(callback).Run(ContextResult::kFatalFailure, Capabilities()); - return; - } - - main_task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&gpu::GpuChannel::CreateCommandBuffer, - gpu_channel_->AsWeakPtr(), std::move(params), routing_id, - std::move(shared_state), - base::BindPostTask(base::ThreadTaskRunnerHandle::Get(), - std::move(callback)))); -} - -void GpuChannelMessageFilter::DestroyCommandBuffer( - int32_t routing_id, - DestroyCommandBufferCallback callback) { - base::AutoLock auto_lock(gpu_channel_lock_); - if (!gpu_channel_) { - std::move(callback).Run(); - return; - } - - main_task_runner_->PostTaskAndReply( - FROM_HERE, - base::BindOnce(&gpu::GpuChannel::DestroyCommandBuffer, - gpu_channel_->AsWeakPtr(), routing_id), - std::move(callback)); -} - void GpuChannelMessageFilter::ScheduleImageDecode( mojom::ScheduleImageDecodeParamsPtr params, uint64_t decode_release_count) { @@ -446,16 +390,6 @@ void GpuChannelMessageFilter::ScheduleImageDecode( decode_release_count); } -void GpuChannelMessageFilter::CreateStreamTexture( - int32_t stream_id, - CreateStreamTextureCallback callback) { - main_task_runner_->PostTaskAndReplyWithResult( - FROM_HERE, - base::BindOnce(&TryCreateStreamTexture, gpu_channel_->AsWeakPtr(), - stream_id), - std::move(callback)); -} - GpuChannel::GpuChannel( GpuChannelManager* gpu_channel_manager, Scheduler* scheduler, @@ -639,6 +573,20 @@ void GpuChannel::RemoveRoute(int32_t route_id) { router_.RemoveRoute(route_id); } +bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) + IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateCommandBuffer, + OnCreateCommandBuffer) + IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, + OnDestroyCommandBuffer) + IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateStreamTexture, + OnCreateStreamTexture) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + void GpuChannel::HandleMessage(const IPC::Message& msg) { int32_t routing_id = msg.routing_id(); CommandBufferStub* stub = LookupCommandBuffer(routing_id); @@ -722,8 +670,11 @@ void GpuChannel::HandleMessageHelper(const IPC::Message& msg) { int32_t routing_id = msg.routing_id(); bool handled = false; - if (routing_id != MSG_ROUTING_CONTROL) + if (routing_id == MSG_ROUTING_CONTROL) { + handled = OnControlMessageReceived(msg); + } else { handled = router_.RouteMessage(msg); + } if (!handled && unhandled_message_listener_) handled = unhandled_message_listener_->OnMessageReceived(msg); @@ -761,39 +712,20 @@ void GpuChannel::DestroyStreamTexture(int32_t stream_id) { } #endif -// Helper to ensure CreateCommandBuffer below always invokes its response -// callback. -class ScopedCreateCommandBufferResponder { - public: - explicit ScopedCreateCommandBufferResponder( - mojom::GpuChannel::CreateCommandBufferCallback callback) - : callback_(std::move(callback)) {} - ~ScopedCreateCommandBufferResponder() { - std::move(callback_).Run(result_, capabilities_); - } - - void set_result(ContextResult result) { result_ = result; } - void set_capabilities(const Capabilities& capabilities) { - capabilities_ = capabilities; - } - - private: - mojom::GpuChannel::CreateCommandBufferCallback callback_; - ContextResult result_ = ContextResult::kFatalFailure; - Capabilities capabilities_; -}; - -void GpuChannel::CreateCommandBuffer( - mojom::CreateCommandBufferParamsPtr init_params, +void GpuChannel::OnCreateCommandBuffer( + const GPUCreateCommandBufferConfig& init_params, int32_t route_id, base::UnsafeSharedMemoryRegion shared_state_shm, - mojom::GpuChannel::CreateCommandBufferCallback callback) { - ScopedCreateCommandBufferResponder responder(std::move(callback)); - TRACE_EVENT2("gpu", "GpuChannel::CreateCommandBuffer", "route_id", route_id, - "offscreen", - (init_params->surface_handle == kNullSurfaceHandle)); - - if (init_params->surface_handle != kNullSurfaceHandle && !is_gpu_host_) { + ContextResult* result, + gpu::Capabilities* capabilities) { + TRACE_EVENT2("gpu", "GpuChannel::OnCreateCommandBuffer", "route_id", route_id, + "offscreen", (init_params.surface_handle == kNullSurfaceHandle)); + // Default result on failure. Override with a more accurate failure if needed, + // or with success. + *result = ContextResult::kFatalFailure; + *capabilities = gpu::Capabilities(); + + if (init_params.surface_handle != kNullSurfaceHandle && !is_gpu_host_) { LOG(ERROR) << "ContextResult::kFatalFailure: " "attempt to create a view context on a non-privileged channel"; @@ -803,12 +735,12 @@ void GpuChannel::CreateCommandBuffer( if (gpu_channel_manager_->delegate()->IsExiting()) { LOG(ERROR) << "ContextResult::kTransientFailure: trying to create command " "buffer during process shutdown."; - responder.set_result(ContextResult::kTransientFailure); + *result = gpu::ContextResult::kTransientFailure; return; } - int32_t stream_id = init_params->stream_id; - int32_t share_group_id = init_params->share_group_id; + int32_t stream_id = init_params.stream_id; + int32_t share_group_id = init_params.share_group_id; CommandBufferStub* share_group = LookupCommandBuffer(share_group_id); if (!share_group && share_group_id != MSG_ROUTING_NONE) { @@ -834,7 +766,7 @@ void GpuChannel::CreateCommandBuffer( // The caller should retry to get a context. LOG(ERROR) << "ContextResult::kTransientFailure: " "shared context was already lost"; - responder.set_result(ContextResult::kTransientFailure); + *result = gpu::ContextResult::kTransientFailure; return; } @@ -843,38 +775,35 @@ void GpuChannel::CreateCommandBuffer( SequenceId sequence_id = stream_sequences_[stream_id]; if (sequence_id.is_null()) { - sequence_id = scheduler_->CreateSequence(init_params->stream_priority); + sequence_id = scheduler_->CreateSequence(init_params.stream_priority); stream_sequences_[stream_id] = sequence_id; } std::unique_ptr stub; - if (init_params->attribs.context_type == CONTEXT_TYPE_WEBGPU) { + if (init_params.attribs.context_type == CONTEXT_TYPE_WEBGPU) { if (!gpu_channel_manager_->gpu_preferences().enable_webgpu) { DLOG(ERROR) << "ContextResult::kFatalFailure: WebGPU not enabled"; return; } stub = std::make_unique( - this, *init_params, command_buffer_id, sequence_id, stream_id, - route_id); - } else if (init_params->attribs.enable_raster_interface && - !init_params->attribs.enable_gles2_interface && - !init_params->attribs.enable_grcontext) { + this, init_params, command_buffer_id, sequence_id, stream_id, route_id); + } else if (init_params.attribs.enable_raster_interface && + !init_params.attribs.enable_gles2_interface && + !init_params.attribs.enable_grcontext) { stub = std::make_unique( - this, *init_params, command_buffer_id, sequence_id, stream_id, - route_id); + this, init_params, command_buffer_id, sequence_id, stream_id, route_id); } else { stub = std::make_unique( - this, *init_params, command_buffer_id, sequence_id, stream_id, - route_id); + this, init_params, command_buffer_id, sequence_id, stream_id, route_id); } auto stub_result = - stub->Initialize(share_group, *init_params, std::move(shared_state_shm)); + stub->Initialize(share_group, init_params, std::move(shared_state_shm)); if (stub_result != gpu::ContextResult::kSuccess) { DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): failed to initialize " "CommandBufferStub"; - responder.set_result(stub_result); + *result = stub_result; return; } @@ -883,12 +812,12 @@ void GpuChannel::CreateCommandBuffer( return; } - responder.set_result(ContextResult::kSuccess); - responder.set_capabilities(stub->decoder_context()->GetCapabilities()); + *result = ContextResult::kSuccess; + *capabilities = stub->decoder_context()->GetCapabilities(); stubs_[route_id] = std::move(stub); } -void GpuChannel::DestroyCommandBuffer(int32_t route_id) { +void GpuChannel::OnDestroyCommandBuffer(int32_t route_id) { TRACE_EVENT1("gpu", "GpuChannel::OnDestroyCommandBuffer", "route_id", route_id); @@ -908,23 +837,25 @@ void GpuChannel::DestroyCommandBuffer(int32_t route_id) { RemoveRoute(route_id); } -bool GpuChannel::CreateStreamTexture(int32_t stream_id) { +void GpuChannel::OnCreateStreamTexture(int32_t stream_id, bool* succeeded) { #if defined(OS_ANDROID) auto found = stream_textures_.find(stream_id); if (found != stream_textures_.end()) { LOG(ERROR) << "Trying to create a StreamTexture with an existing stream_id."; - return false; + *succeeded = false; + return; } scoped_refptr stream_texture = StreamTexture::Create(this, stream_id); if (!stream_texture) { - return false; + *succeeded = false; + return; } stream_textures_.emplace(stream_id, std::move(stream_texture)); - return true; + *succeeded = true; #else - return false; + *succeeded = false; #endif } diff --git a/gpu/ipc/service/gpu_channel.h b/gpu/ipc/service/gpu_channel.h index 38c9517c0495c4..0beb9373b32436 100644 --- a/gpu/ipc/service/gpu_channel.h +++ b/gpu/ipc/service/gpu_channel.h @@ -21,10 +21,8 @@ #include "base/single_thread_task_runner.h" #include "base/trace_event/memory_dump_provider.h" #include "build/build_config.h" -#include "gpu/command_buffer/common/capabilities.h" #include "gpu/command_buffer/common/context_result.h" #include "gpu/command_buffer/service/sync_point_manager.h" -#include "gpu/ipc/common/gpu_channel.mojom.h" #include "gpu/ipc/service/command_buffer_stub.h" #include "gpu/ipc/service/gpu_ipc_service_export.h" #include "gpu/ipc/service/shared_image_stub.h" @@ -36,6 +34,8 @@ #include "ui/gl/gl_share_group.h" #include "ui/gl/gpu_preference.h" +struct GPUCreateCommandBufferConfig; + namespace base { class WaitableEvent; } @@ -181,14 +181,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener, return shared_image_stub_.get(); } - void CreateCommandBuffer( - mojom::CreateCommandBufferParamsPtr init_params, - int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state_shm, - mojom::GpuChannel::CreateCommandBufferCallback callback); - void DestroyCommandBuffer(int32_t routing_id); - bool CreateStreamTexture(int32_t stream_id); - private: // Takes ownership of the renderer process handle. GpuChannel(GpuChannelManager* gpu_channel_manager, @@ -202,11 +194,18 @@ class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener, bool is_gpu_host, ImageDecodeAcceleratorWorker* image_decode_accelerator_worker); - void OnDestroyCommandBuffer(int32_t route_id); + bool OnControlMessageReceived(const IPC::Message& msg); void HandleMessageHelper(const IPC::Message& msg); // Message handlers for control messages. + void OnCreateCommandBuffer(const GPUCreateCommandBufferConfig& init_params, + int32_t route_id, + base::UnsafeSharedMemoryRegion shared_state_shm, + gpu::ContextResult* result, + gpu::Capabilities* capabilities); + void OnDestroyCommandBuffer(int32_t route_id); + void OnCreateStreamTexture(int32_t stream_id, bool* succeeded); bool CreateSharedImageStub(); std::unique_ptr sync_channel_; // nullptr in tests. diff --git a/gpu/ipc/service/gpu_channel_manager_unittest.cc b/gpu/ipc/service/gpu_channel_manager_unittest.cc index 8b59b1bd6d7b9e..1baf932acaffc3 100644 --- a/gpu/ipc/service/gpu_channel_manager_unittest.cc +++ b/gpu/ipc/service/gpu_channel_manager_unittest.cc @@ -12,11 +12,9 @@ #include "base/trace_event/trace_event_filter.h" #include "base/trace_event/trace_event_impl.h" #include "base/trace_event/trace_log.h" -#include "gpu/command_buffer/common/capabilities.h" -#include "gpu/command_buffer/common/context_result.h" #include "gpu/command_buffer/service/memory_tracking.h" #include "gpu/ipc/common/command_buffer_id.h" -#include "gpu/ipc/common/gpu_channel.mojom.h" +#include "gpu/ipc/common/gpu_messages.h" #include "gpu/ipc/service/gpu_channel.h" #include "gpu/ipc/service/gpu_channel_manager.h" #include "gpu/ipc/service/gpu_channel_test_common.h" @@ -134,20 +132,20 @@ class GpuChannelManagerTest : public GpuChannelTestCommon { static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; const SurfaceHandle kFakeSurfaceHandle = 1; SurfaceHandle surface_handle = kFakeSurfaceHandle; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = surface_handle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->attribs.context_type = type; - init_params->active_url = GURL(); - - ContextResult result = ContextResult::kFatalFailure; - Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); - EXPECT_EQ(result, ContextResult::kSuccess); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = surface_handle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.attribs.context_type = type; + init_params.active_url = GURL(); + gpu::ContextResult result = gpu::ContextResult::kFatalFailure; + gpu::Capabilities capabilities; + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); + EXPECT_EQ(result, gpu::ContextResult::kSuccess); auto raster_decoder_state = channel_manager()->GetSharedContextState(&result); diff --git a/gpu/ipc/service/gpu_channel_test_common.cc b/gpu/ipc/service/gpu_channel_test_common.cc index 4de3cfc23d9449..7364038f7a076d 100644 --- a/gpu/ipc/service/gpu_channel_test_common.cc +++ b/gpu/ipc/service/gpu_channel_test_common.cc @@ -7,8 +7,6 @@ #include #include "base/memory/unsafe_shared_memory_region.h" -#include "base/run_loop.h" -#include "base/test/bind.h" #include "base/test/test_simple_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "base/trace_event/memory_dump_manager.h" @@ -72,9 +70,11 @@ GpuChannelTestCommon::GpuChannelTestCommon( bool use_stub_bindings) : memory_dump_manager_( base::trace_event::MemoryDumpManager::CreateInstanceForTesting()), + task_runner_(new base::TestSimpleTaskRunner), + io_task_runner_(new base::TestSimpleTaskRunner), sync_point_manager_(new SyncPointManager()), shared_image_manager_(new SharedImageManager(false /* thread_safe */)), - scheduler_(new Scheduler(task_environment_.GetMainThreadTaskRunner(), + scheduler_(new Scheduler(task_runner_, sync_point_manager_.get(), GpuPreferences())), channel_manager_delegate_( @@ -92,8 +92,7 @@ GpuChannelTestCommon::GpuChannelTestCommon( channel_manager_ = std::make_unique( GpuPreferences(), channel_manager_delegate_.get(), nullptr, /* watchdog */ - task_environment_.GetMainThreadTaskRunner(), - task_environment_.GetMainThreadTaskRunner(), scheduler_.get(), + task_runner_.get(), io_task_runner_.get(), scheduler_.get(), sync_point_manager_.get(), shared_image_manager_.get(), nullptr, /* gpu_memory_buffer_factory */ std::move(feature_info), GpuProcessActivityFlags(), @@ -104,7 +103,11 @@ GpuChannelTestCommon::GpuChannelTestCommon( GpuChannelTestCommon::~GpuChannelTestCommon() { // Command buffers can post tasks and run GL in destruction so do this first. channel_manager_ = nullptr; - task_environment_.RunUntilIdle(); + + // Clear pending tasks to avoid refptr cycles that get flagged by ASAN. + task_runner_->ClearPendingTasks(); + io_task_runner_->ClearPendingTasks(); + gl::init::ShutdownGL(false); } @@ -119,26 +122,6 @@ GpuChannel* GpuChannelTestCommon::CreateChannel(int32_t client_id, return channel; } -void GpuChannelTestCommon::CreateCommandBuffer( - GpuChannel& channel, - mojom::CreateCommandBufferParamsPtr init_params, - int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state, - ContextResult* out_result, - Capabilities* out_capabilities) { - base::RunLoop loop; - auto quit = loop.QuitClosure(); - channel.CreateCommandBuffer( - std::move(init_params), routing_id, std::move(shared_state), - base::BindLambdaForTesting( - [&](ContextResult result, const Capabilities& capabilities) { - *out_result = result; - *out_capabilities = capabilities; - quit.Run(); - })); - loop.Run(); -} - void GpuChannelTestCommon::HandleMessage(GpuChannel* channel, IPC::Message* msg) { // Some IPCs (such as GpuCommandBufferMsg_Initialize) will generate more @@ -152,7 +135,7 @@ void GpuChannelTestCommon::HandleMessage(GpuChannel* channel, channel->HandleMessageForTesting(*msg); // Run the HandleMessage task posted to the main thread. - task_environment_.RunUntilIdle(); + task_runner()->RunPendingTasks(); // Replies are sent to the sink. if (msg->is_sync()) { diff --git a/gpu/ipc/service/gpu_channel_test_common.h b/gpu/ipc/service/gpu_channel_test_common.h index 3efbfcce53255d..be33807487ae33 100644 --- a/gpu/ipc/service/gpu_channel_test_common.h +++ b/gpu/ipc/service/gpu_channel_test_common.h @@ -10,18 +10,16 @@ #include "base/memory/ref_counted.h" #include "base/memory/unsafe_shared_memory_region.h" -#include "base/sequenced_task_runner.h" -#include "base/test/task_environment.h" -#include "gpu/command_buffer/common/capabilities.h" -#include "gpu/command_buffer/common/context_result.h" -#include "gpu/ipc/common/gpu_channel.mojom.h" #include "ipc/ipc_test_sink.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { +class TestSimpleTaskRunner; + namespace trace_event { class MemoryDumpManager; } // namespace trace_event + } // namespace base namespace IPC { @@ -47,25 +45,22 @@ class GpuChannelTestCommon : public testing::Test { protected: Scheduler* scheduler() const { return scheduler_.get(); } GpuChannelManager* channel_manager() const { return channel_manager_.get(); } - base::test::TaskEnvironment& task_environment() { return task_environment_; } + base::TestSimpleTaskRunner* task_runner() const { return task_runner_.get(); } + base::TestSimpleTaskRunner* io_task_runner() const { + return io_task_runner_.get(); + } GpuChannel* CreateChannel(int32_t client_id, bool is_gpu_host); - void CreateCommandBuffer(GpuChannel& channel, - mojom::CreateCommandBufferParamsPtr init_params, - int32_t routing_id, - base::UnsafeSharedMemoryRegion shared_state, - ContextResult* out_result, - Capabilities* out_capabilities); - void HandleMessage(GpuChannel* channel, IPC::Message* msg); base::UnsafeSharedMemoryRegion GetSharedMemoryRegion(); private: - base::test::TaskEnvironment task_environment_; std::unique_ptr memory_dump_manager_; IPC::TestSink sink_; + scoped_refptr task_runner_; + scoped_refptr io_task_runner_; std::unique_ptr sync_point_manager_; std::unique_ptr shared_image_manager_; std::unique_ptr scheduler_; diff --git a/gpu/ipc/service/gpu_channel_unittest.cc b/gpu/ipc/service/gpu_channel_unittest.cc index 578bb6880bf118..d9eb13b7c07ab3 100644 --- a/gpu/ipc/service/gpu_channel_unittest.cc +++ b/gpu/ipc/service/gpu_channel_unittest.cc @@ -4,10 +4,9 @@ #include -#include "base/run_loop.h" #include "base/test/test_simple_task_runner.h" #include "gpu/ipc/common/command_buffer_id.h" -#include "gpu/ipc/common/gpu_channel.mojom.h" +#include "gpu/ipc/common/gpu_messages.h" #include "gpu/ipc/service/gpu_channel.h" #include "gpu/ipc/service/gpu_channel_manager.h" #include "gpu/ipc/service/gpu_channel_test_common.h" @@ -37,17 +36,18 @@ TEST_F(GpuChannelTest, CreateViewCommandBufferAllowed) { int32_t kRouteId = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = surface_handle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = surface_handle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kSuccess); CommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); @@ -65,17 +65,18 @@ TEST_F(GpuChannelTest, CreateViewCommandBufferDisallowed) { int32_t kRouteId = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = surface_handle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = surface_handle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kFatalFailure); CommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); @@ -89,17 +90,18 @@ TEST_F(GpuChannelTest, CreateOffscreenCommandBuffer) { int32_t kRouteId = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kSuccess); CommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId); @@ -115,17 +117,18 @@ TEST_F(GpuChannelTest, IncompatibleStreamIds) { int32_t kRouteId1 = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; int32_t kStreamId1 = 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = kStreamId1; - init_params->stream_priority = SchedulingPriority::kNormal; - auto init_params2 = init_params.Clone(); - + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = kStreamId1; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId1, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId1, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kSuccess); CommandBufferStub* stub = channel->LookupCommandBuffer(kRouteId1); @@ -135,11 +138,14 @@ TEST_F(GpuChannelTest, IncompatibleStreamIds) { int32_t kRouteId2 = kRouteId1 + 1; int32_t kStreamId2 = 2; - init_params2->share_group_id = kRouteId1; - init_params2->stream_id = kStreamId2; - init_params2->stream_priority = SchedulingPriority::kNormal; - CreateCommandBuffer(*channel, std::move(init_params2), kRouteId2, - GetSharedMemoryRegion(), &result, &capabilities); + init_params.share_group_id = kRouteId1; + init_params.stream_id = kStreamId2; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId2, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kFatalFailure); stub = channel->LookupCommandBuffer(kRouteId2); @@ -156,17 +162,19 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; { SCOPED_TRACE("kSharedRouteId"); - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kSharedRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, + new GpuChannelMsg_CreateCommandBuffer( + init_params, kSharedRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kSuccess); } EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); @@ -175,17 +183,19 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { int32_t kFriendlyRouteId = kSharedRouteId + 1; { SCOPED_TRACE("kFriendlyRouteId"); - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = kSharedRouteId; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = kSharedRouteId; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kFriendlyRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, + new GpuChannelMsg_CreateCommandBuffer( + init_params, kFriendlyRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kSuccess); } EXPECT_TRUE(channel->LookupCommandBuffer(kFriendlyRouteId)); @@ -198,17 +208,19 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { int32_t kAnotherRouteId = kFriendlyRouteId + 1; { SCOPED_TRACE("kAnotherRouteId"); - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = kSharedRouteId; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = kSharedRouteId; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kAnotherRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, + new GpuChannelMsg_CreateCommandBuffer( + init_params, kAnotherRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kTransientFailure); } EXPECT_FALSE(channel->LookupCommandBuffer(kAnotherRouteId)); @@ -218,8 +230,10 @@ TEST_F(GpuChannelTest, CreateFailsIfSharedContextIsLost) { EXPECT_TRUE(channel->LookupCommandBuffer(kSharedRouteId)); // Destroy the command buffers we initialized before destoying GL. - channel->DestroyCommandBuffer(kFriendlyRouteId); - channel->DestroyCommandBuffer(kSharedRouteId); + HandleMessage(channel, + new GpuChannelMsg_DestroyCommandBuffer(kFriendlyRouteId)); + HandleMessage(channel, + new GpuChannelMsg_DestroyCommandBuffer(kSharedRouteId)); } class GpuChannelExitForContextLostTest : public GpuChannelTestCommon { @@ -240,7 +254,7 @@ TEST_F(GpuChannelExitForContextLostTest, // Calling OnContextLost() above may destroy the gpu channel via post task. // Ensure that post task has happened. - base::RunLoop().RunUntilIdle(); + task_runner()->RunPendingTasks(); // If the channel is destroyed, then skip the test. if (!channel_manager()->LookupChannel(kClientId)) @@ -249,17 +263,18 @@ TEST_F(GpuChannelExitForContextLostTest, // Try to create a context. int32_t kRouteId = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kTransientFailure); EXPECT_FALSE(channel->LookupCommandBuffer(kRouteId)); } @@ -277,17 +292,18 @@ TEST_F(GpuChannelExitForContextLostTest, // Try to create a context. int32_t kRouteId = static_cast(GpuChannelReservedRoutes::kMaxValue) + 1; - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.active_url = GURL(); gpu::ContextResult result = gpu::ContextResult::kSuccess; gpu::Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, new GpuChannelMsg_CreateCommandBuffer( + init_params, kRouteId, GetSharedMemoryRegion(), + &result, &capabilities)); EXPECT_EQ(result, gpu::ContextResult::kTransientFailure); EXPECT_FALSE(channel->LookupCommandBuffer(kRouteId)); } diff --git a/gpu/ipc/service/image_decode_accelerator_stub_unittest.cc b/gpu/ipc/service/image_decode_accelerator_stub_unittest.cc index ae11064ddb45e3..8e9bdbe1711ba2 100644 --- a/gpu/ipc/service/image_decode_accelerator_stub_unittest.cc +++ b/gpu/ipc/service/image_decode_accelerator_stub_unittest.cc @@ -306,27 +306,30 @@ class ImageDecodeAcceleratorStubTest // would make RunTasksUntilIdle() run forever. CommandBufferStub::SetMemoryTrackerFactoryForTesting( base::BindRepeating(&CreateMockMemoryTracker)); - auto init_params = mojom::CreateCommandBufferParams::New(); - init_params->surface_handle = kNullSurfaceHandle; - init_params->share_group_id = MSG_ROUTING_NONE; - init_params->stream_id = 0; - init_params->stream_priority = SchedulingPriority::kNormal; - init_params->attribs = ContextCreationAttribs(); - init_params->attribs.enable_gles2_interface = false; - init_params->attribs.enable_raster_interface = true; - init_params->attribs.bind_generates_resource = false; - init_params->active_url = GURL(); + GPUCreateCommandBufferConfig init_params; + init_params.surface_handle = kNullSurfaceHandle; + init_params.share_group_id = MSG_ROUTING_NONE; + init_params.stream_id = 0; + init_params.stream_priority = SchedulingPriority::kNormal; + init_params.attribs = ContextCreationAttribs(); + init_params.attribs.enable_gles2_interface = false; + init_params.attribs.enable_raster_interface = true; + init_params.attribs.bind_generates_resource = false; + init_params.active_url = GURL(); ContextResult result = ContextResult::kTransientFailure; Capabilities capabilities; - CreateCommandBuffer(*channel, std::move(init_params), kCommandBufferRouteId, - GetSharedMemoryRegion(), &result, &capabilities); + HandleMessage(channel, + new GpuChannelMsg_CreateCommandBuffer( + init_params, kCommandBufferRouteId, + GetSharedMemoryRegion(), &result, &capabilities)); ASSERT_EQ(ContextResult::kSuccess, result); CommandBufferStub* command_buffer = channel->LookupCommandBuffer(kCommandBufferRouteId); ASSERT_TRUE(command_buffer); // Make sure there are no pending tasks before starting the test. - ASSERT_TRUE(task_environment().MainThreadIsIdle()); + ASSERT_EQ(0u, task_runner()->NumPendingTasks()); + ASSERT_EQ(0u, io_task_runner()->NumPendingTasks()); } void TearDown() override { @@ -421,7 +424,13 @@ class ImageDecodeAcceleratorStubTest return decode_sync_token; } - void RunTasksUntilIdle() { task_environment().RunUntilIdle(); } + void RunTasksUntilIdle() { + while (task_runner()->HasPendingTask() || + io_task_runner()->HasPendingTask()) { + task_runner()->RunUntilIdle(); + io_task_runner()->RunUntilIdle(); + } + } void CheckTransferCacheEntries( const std::vector& expected_entries) { @@ -645,6 +654,7 @@ class ImageDecodeAcceleratorStubTest } protected: + base::test::SingleThreadTaskEnvironment task_environment_; StrictMock image_decode_accelerator_worker_; private: diff --git a/gpu/ipc/service/raster_command_buffer_stub.cc b/gpu/ipc/service/raster_command_buffer_stub.cc index 538516eb5d325c..120a42928dfafe 100644 --- a/gpu/ipc/service/raster_command_buffer_stub.cc +++ b/gpu/ipc/service/raster_command_buffer_stub.cc @@ -50,7 +50,7 @@ namespace gpu { RasterCommandBufferStub::RasterCommandBufferStub( GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -66,7 +66,7 @@ RasterCommandBufferStub::~RasterCommandBufferStub() {} gpu::ContextResult RasterCommandBufferStub::Initialize( CommandBufferStub* share_command_buffer_stub, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) { TRACE_EVENT0("gpu", "RasterBufferStub::Initialize"); UpdateActiveUrl(); diff --git a/gpu/ipc/service/raster_command_buffer_stub.h b/gpu/ipc/service/raster_command_buffer_stub.h index 40ca9da9f183ad..0c9162de388414 100644 --- a/gpu/ipc/service/raster_command_buffer_stub.h +++ b/gpu/ipc/service/raster_command_buffer_stub.h @@ -13,7 +13,7 @@ class GPU_IPC_SERVICE_EXPORT RasterCommandBufferStub : public CommandBufferStub { public: RasterCommandBufferStub(GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -25,7 +25,7 @@ class GPU_IPC_SERVICE_EXPORT RasterCommandBufferStub // the gpu::Capabilities. gpu::ContextResult Initialize( CommandBufferStub* share_group, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) override; MemoryTracker* GetContextGroupMemoryTracker() const override; diff --git a/gpu/ipc/service/webgpu_command_buffer_stub.cc b/gpu/ipc/service/webgpu_command_buffer_stub.cc index f7988720bec94b..c4dd246a099b5c 100644 --- a/gpu/ipc/service/webgpu_command_buffer_stub.cc +++ b/gpu/ipc/service/webgpu_command_buffer_stub.cc @@ -51,7 +51,7 @@ namespace gpu { WebGPUCommandBufferStub::WebGPUCommandBufferStub( GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -72,7 +72,7 @@ WebGPUCommandBufferStub::~WebGPUCommandBufferStub() { gpu::ContextResult WebGPUCommandBufferStub::Initialize( CommandBufferStub* share_command_buffer_stub, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) { #if defined(OS_FUCHSIA) // TODO(crbug.com/707031): Implement this. diff --git a/gpu/ipc/service/webgpu_command_buffer_stub.h b/gpu/ipc/service/webgpu_command_buffer_stub.h index 9c94a41aa02486..913eae7f98623c 100644 --- a/gpu/ipc/service/webgpu_command_buffer_stub.h +++ b/gpu/ipc/service/webgpu_command_buffer_stub.h @@ -13,7 +13,7 @@ class GPU_IPC_SERVICE_EXPORT WebGPUCommandBufferStub : public CommandBufferStub { public: WebGPUCommandBufferStub(GpuChannel* channel, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, CommandBufferId command_buffer_id, SequenceId sequence_id, int32_t stream_id, @@ -25,7 +25,7 @@ class GPU_IPC_SERVICE_EXPORT WebGPUCommandBufferStub // the gpu::Capabilities. gpu::ContextResult Initialize( CommandBufferStub* share_group, - const mojom::CreateCommandBufferParams& init_params, + const GPUCreateCommandBufferConfig& init_params, base::UnsafeSharedMemoryRegion shared_state_shm) override; MemoryTracker* GetContextGroupMemoryTracker() const override; diff --git a/mojo/public/cpp/bindings/sync_call_restrictions.h b/mojo/public/cpp/bindings/sync_call_restrictions.h index fd962645ec69cc..73c3cf30dc94e7 100644 --- a/mojo/public/cpp/bindings/sync_call_restrictions.h +++ b/mojo/public/cpp/bindings/sync_call_restrictions.h @@ -20,20 +20,14 @@ class CastCdmOriginProvider; } // namespace chromecast namespace content { -class AndroidOverlaySyncHelper; class DesktopCapturerLacros; -class StreamTextureFactory; +class AndroidOverlaySyncHelper; } // namespace content namespace crosapi { class ScopedAllowSyncCall; } // namespace crosapi -namespace gpu { -class CommandBufferProxyImpl; -class GpuChannelHost; -} // namespace gpu - namespace ui { class Compositor; } // namespace ui @@ -105,10 +99,8 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions { // Android requires synchronous processing when overlay surfaces are // destroyed, else behavior is undefined. friend class content::AndroidOverlaySyncHelper; - // GPU client code uses a few sync IPCs, grandfathered in from legacy IPC. + // GpuChannelHost uses a few sync IPCs, grandfathered in from legacy IPC. friend class gpu::GpuChannelHost; - friend class gpu::CommandBufferProxyImpl; - friend class content::StreamTextureFactory; // END ALLOWED USAGE. #if ENABLE_SYNC_CALL_RESTRICTIONS