Commit 932d3f04 authored by Miguel Casas-Sanchez's avatar Miguel Casas-Sanchez Committed by Commit Bot

SharedImageStub: Add Create/UpdateSharedImage() methods

This CL follows up on a comment [1], where instead of forcing clients
to make the context current and then call either CreateSharedImage or
UpdateSharedImage, it is suggested to have public methods bundling those
operations in SharedImageStub.  This CL does just that, making the
current OnCreateGMBSharedImage and OnUpdateSharedImage use the newly
introduced ones.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1772642/30/media/gpu/linux/mailbox_video_frame_converter.cc#361

Bug: 998279
Change-Id: If39d94b04d2851e6ed8e248e9af96908dfa27e8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1794274Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695266}
parent c8040888
...@@ -89,6 +89,61 @@ bool SharedImageStub::OnMessageReceived(const IPC::Message& msg) { ...@@ -89,6 +89,61 @@ bool SharedImageStub::OnMessageReceived(const IPC::Message& msg) {
return handled; return handled;
} }
bool SharedImageStub::CreateSharedImage(const Mailbox& mailbox,
int client_id,
gfx::GpuMemoryBufferHandle handle,
gfx::BufferFormat format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) {
TRACE_EVENT2("gpu", "SharedImageStub::CreateSharedImage", "width",
size.width(), "height", size.height());
if (!mailbox.IsSharedImage()) {
LOG(ERROR) << "SharedImageStub: Trying to create a SharedImage with a "
"non-SharedImage mailbox.";
OnError();
return false;
}
if (!MakeContextCurrent()) {
OnError();
return false;
}
if (!factory_->CreateSharedImage(mailbox, client_id, std::move(handle),
format, surface_handle, size, color_space,
usage)) {
LOG(ERROR) << "SharedImageStub: Unable to create shared image";
OnError();
return false;
}
return true;
}
bool SharedImageStub::UpdateSharedImage(
const Mailbox& mailbox,
const gfx::GpuFenceHandle& in_fence_handle) {
TRACE_EVENT0("gpu", "SharedImageStub::UpdateSharedImage");
std::unique_ptr<gfx::GpuFence> in_fence;
if (!in_fence_handle.is_null())
in_fence.reset(new gfx::GpuFence(in_fence_handle));
if (!mailbox.IsSharedImage()) {
LOG(ERROR) << "SharedImageStub: Trying to access a SharedImage with a "
"non-SharedImage mailbox.";
OnError();
return false;
}
if (!MakeContextCurrent()) {
OnError();
return false;
}
if (!factory_->UpdateSharedImage(mailbox, std::move(in_fence))) {
LOG(ERROR) << "SharedImageStub: Unable to update shared image";
OnError();
return false;
}
return true;
}
void SharedImageStub::OnCreateSharedImage( void SharedImageStub::OnCreateSharedImage(
const GpuChannelMsg_CreateSharedImage_Params& params) { const GpuChannelMsg_CreateSharedImage_Params& params) {
TRACE_EVENT2("gpu", "SharedImageStub::OnCreateSharedImage", "width", TRACE_EVENT2("gpu", "SharedImageStub::OnCreateSharedImage", "width",
...@@ -182,26 +237,12 @@ void SharedImageStub::OnCreateGMBSharedImage( ...@@ -182,26 +237,12 @@ void SharedImageStub::OnCreateGMBSharedImage(
GpuChannelMsg_CreateGMBSharedImage_Params params) { GpuChannelMsg_CreateGMBSharedImage_Params params) {
TRACE_EVENT2("gpu", "SharedImageStub::OnCreateGMBSharedImage", "width", TRACE_EVENT2("gpu", "SharedImageStub::OnCreateGMBSharedImage", "width",
params.size.width(), "height", params.size.height()); params.size.width(), "height", params.size.height());
if (!params.mailbox.IsSharedImage()) {
LOG(ERROR) << "SharedImageStub: Trying to create a SharedImage with a "
"non-SharedImage mailbox.";
OnError();
return;
}
if (!MakeContextCurrent()) {
OnError();
return;
}
// TODO(piman): add support for SurfaceHandle (for backbuffers for ozone/drm). // TODO(piman): add support for SurfaceHandle (for backbuffers for ozone/drm).
SurfaceHandle surface_handle = kNullSurfaceHandle; constexpr SurfaceHandle surface_handle = kNullSurfaceHandle;
if (!factory_->CreateSharedImage(params.mailbox, channel_->client_id(), if (!CreateSharedImage(params.mailbox, channel_->client_id(),
std::move(params.handle), params.format, std::move(params.handle), params.format,
surface_handle, params.size, surface_handle, params.size, params.color_space,
params.color_space, params.usage)) { params.usage)) {
LOG(ERROR) << "SharedImageStub: Unable to create shared image";
OnError();
return; return;
} }
...@@ -218,26 +259,9 @@ void SharedImageStub::OnUpdateSharedImage( ...@@ -218,26 +259,9 @@ void SharedImageStub::OnUpdateSharedImage(
uint32_t release_id, uint32_t release_id,
const gfx::GpuFenceHandle& in_fence_handle) { const gfx::GpuFenceHandle& in_fence_handle) {
TRACE_EVENT0("gpu", "SharedImageStub::OnUpdateSharedImage"); TRACE_EVENT0("gpu", "SharedImageStub::OnUpdateSharedImage");
std::unique_ptr<gfx::GpuFence> in_fence;
if (!in_fence_handle.is_null())
in_fence.reset(new gfx::GpuFence(in_fence_handle));
if (!mailbox.IsSharedImage()) {
LOG(ERROR) << "SharedImageStub: Trying to access a SharedImage with a "
"non-SharedImage mailbox.";
OnError();
return;
}
if (!MakeContextCurrent()) {
OnError();
return;
}
if (!factory_->UpdateSharedImage(mailbox, std::move(in_fence))) { if (!UpdateSharedImage(mailbox, in_fence_handle))
LOG(ERROR) << "SharedImageStub: Unable to update shared image";
OnError();
return; return;
}
SyncToken sync_token(sync_point_client_state_->namespace_id(), SyncToken sync_token(sync_point_client_state_->namespace_id(),
sync_point_client_state_->command_buffer_id(), sync_point_client_state_->command_buffer_id(),
...@@ -373,13 +397,12 @@ bool SharedImageStub::MakeContextCurrent() { ...@@ -373,13 +397,12 @@ bool SharedImageStub::MakeContextCurrent() {
// improve performance. https://crbug.com/457431 // improve performance. https://crbug.com/457431
auto* context = context_state_->real_context(); auto* context = context_state_->real_context();
if (context->IsCurrent(nullptr) || if (context->IsCurrent(nullptr) ||
context_state_->real_context()->MakeCurrent(context_state_->surface())) { context->MakeCurrent(context_state_->surface())) {
return true; return true;
} else { }
context_state_->MarkContextLost(); context_state_->MarkContextLost();
LOG(ERROR) << "SharedImageStub: MakeCurrent failed"; LOG(ERROR) << "SharedImageStub: MakeCurrent failed";
return false; return false;
}
} }
ContextResult SharedImageStub::MakeContextCurrentAndCreateFactory() { ContextResult SharedImageStub::MakeContextCurrentAndCreateFactory() {
......
...@@ -56,6 +56,17 @@ class GPU_IPC_SERVICE_EXPORT SharedImageStub ...@@ -56,6 +56,17 @@ class GPU_IPC_SERVICE_EXPORT SharedImageStub
SharedImageDestructionCallback GetSharedImageDestructionCallback( SharedImageDestructionCallback GetSharedImageDestructionCallback(
const Mailbox& mailbox); const Mailbox& mailbox);
bool CreateSharedImage(const Mailbox& mailbox,
int client_id,
gfx::GpuMemoryBufferHandle handle,
gfx::BufferFormat format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage);
bool UpdateSharedImage(const Mailbox& mailbox,
const gfx::GpuFenceHandle& in_fence_handle);
private: private:
SharedImageStub(GpuChannel* channel, int32_t route_id); SharedImageStub(GpuChannel* channel, int32_t route_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment