Commit a1fc5f9d authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

Reland "media/gpu/chromeos/MailboxVFConverter: Set visible size to SharedImage"

This is a reland of 7d82db05

Original change's description:
> media/gpu/chromeos/MailboxVFConverter: Set visible size to SharedImage
>
> MailboxVideoFrameConverter sets coded size to SharedImage. It
> causes that a green line is shown at the bottom and right edge
> when playing a video.
>
> This fixes the issue by setting visible size to SharedImage so
> that GPU doesn't access non visible area.
> Note that MailboxVideoFrameConverter needs to recreate
> SharedImage if the visible rectangle of the current video frame
> is changed, which should be rare though.
>
> Bug: 1043582
> Test: Play a 1920x1080 video on soraka with --enable-features=ChromeosVideoDecoder
> Change-Id: I76878a27fa92d755380d9b92b94d20e765056fac
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2011586
> Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
> Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#734795}

Bug: 1043582, 1045661
Change-Id: I0dc09d3936924086f4b433d204b57002fc75a1e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2021562
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738891}
parent 8936b152
...@@ -39,9 +39,11 @@ class MailboxVideoFrameConverter::ScopedSharedImage { ...@@ -39,9 +39,11 @@ class MailboxVideoFrameConverter::ScopedSharedImage {
gpu::SharedImageStub::SharedImageDestructionCallback; gpu::SharedImageStub::SharedImageDestructionCallback;
ScopedSharedImage(const gpu::Mailbox& mailbox, ScopedSharedImage(const gpu::Mailbox& mailbox,
const gfx::Rect& rect,
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner, scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
DestroySharedImageCB destroy_shared_image_cb) DestroySharedImageCB destroy_shared_image_cb)
: mailbox_(mailbox), : mailbox_(mailbox),
rect_(rect),
destroy_shared_image_cb_(std::move(destroy_shared_image_cb)), destroy_shared_image_cb_(std::move(destroy_shared_image_cb)),
destruction_task_runner_(std::move(gpu_task_runner)) {} destruction_task_runner_(std::move(gpu_task_runner)) {}
~ScopedSharedImage() { ~ScopedSharedImage() {
...@@ -55,9 +57,11 @@ class MailboxVideoFrameConverter::ScopedSharedImage { ...@@ -55,9 +57,11 @@ class MailboxVideoFrameConverter::ScopedSharedImage {
} }
const gpu::Mailbox& mailbox() const { return mailbox_; } const gpu::Mailbox& mailbox() const { return mailbox_; }
const gfx::Rect& rect() const { return rect_; }
private: private:
const gpu::Mailbox mailbox_; const gpu::Mailbox mailbox_;
const gfx::Rect rect_;
DestroySharedImageCB destroy_shared_image_cb_; DestroySharedImageCB destroy_shared_image_cb_;
const scoped_refptr<base::SequencedTaskRunner> destruction_task_runner_; const scoped_refptr<base::SequencedTaskRunner> destruction_task_runner_;
...@@ -150,8 +154,14 @@ void MailboxVideoFrameConverter::ConvertFrame(scoped_refptr<VideoFrame> frame) { ...@@ -150,8 +154,14 @@ void MailboxVideoFrameConverter::ConvertFrame(scoped_refptr<VideoFrame> frame) {
gpu::Mailbox mailbox; gpu::Mailbox mailbox;
const UniqueID origin_frame_id = origin_frame->unique_id(); const UniqueID origin_frame_id = origin_frame->unique_id();
if (shared_images_.find(origin_frame_id) != shared_images_.end()) if (shared_images_.find(origin_frame_id) != shared_images_.end()) {
mailbox = shared_images_[origin_frame_id]->mailbox(); // If visible_rect() is changed, recreate SharedImage with the new
// visible_rect().
if (shared_images_[origin_frame_id]->rect() == frame->visible_rect())
mailbox = shared_images_[origin_frame_id]->mailbox();
else
shared_images_[origin_frame_id].reset();
}
input_frame_queue_.emplace(frame, origin_frame_id); input_frame_queue_.emplace(frame, origin_frame_id);
...@@ -223,6 +233,7 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread( ...@@ -223,6 +233,7 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread(
DCHECK(gpu_task_runner_->BelongsToCurrentThread()); DCHECK(gpu_task_runner_->BelongsToCurrentThread());
TRACE_EVENT1("media,gpu", "ConvertFrameOnGPUThread", "VideoFrame id", TRACE_EVENT1("media,gpu", "ConvertFrameOnGPUThread", "VideoFrame id",
origin_frame->unique_id()); origin_frame->unique_id());
const gfx::Rect visible_rect = frame->visible_rect();
// |origin_frame| is kept alive by |frame|. // |origin_frame| is kept alive by |frame|.
auto wrap_mailbox_and_video_frame_and_output_cb = base::BindOnce( auto wrap_mailbox_and_video_frame_and_output_cb = base::BindOnce(
...@@ -242,7 +253,8 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread( ...@@ -242,7 +253,8 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread(
} }
std::unique_ptr<ScopedSharedImage> scoped_shared_image; std::unique_ptr<ScopedSharedImage> scoped_shared_image;
scoped_shared_image = GenerateSharedImageOnGPUThread(origin_frame); scoped_shared_image =
GenerateSharedImageOnGPUThread(origin_frame, visible_rect);
if (!scoped_shared_image) if (!scoped_shared_image)
return; return;
...@@ -262,7 +274,8 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread( ...@@ -262,7 +274,8 @@ void MailboxVideoFrameConverter::ConvertFrameOnGPUThread(
std::unique_ptr<MailboxVideoFrameConverter::ScopedSharedImage> std::unique_ptr<MailboxVideoFrameConverter::ScopedSharedImage>
MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread( MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread(
VideoFrame* video_frame) { VideoFrame* video_frame,
const gfx::Rect& destination_visible_rect) {
DCHECK(gpu_task_runner_->BelongsToCurrentThread()); DCHECK(gpu_task_runner_->BelongsToCurrentThread());
DVLOGF(4) << "frame: " << video_frame->unique_id(); DVLOGF(4) << "frame: " << video_frame->unique_id();
...@@ -293,6 +306,10 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread( ...@@ -293,6 +306,10 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread(
gpu::SharedImageStub* shared_image_stub = gpu_channel_->shared_image_stub(); gpu::SharedImageStub* shared_image_stub = gpu_channel_->shared_image_stub();
DCHECK(shared_image_stub); DCHECK(shared_image_stub);
// Destination VideoFrames should have visible rectangles stating at the
// origin.
DCHECK(destination_visible_rect.origin().IsOrigin());
// The allocated SharedImages should be usable for the (Display) compositor // The allocated SharedImages should be usable for the (Display) compositor
// and, potentially, for overlays (Scanout). // and, potentially, for overlays (Scanout).
const uint32_t shared_image_usage = const uint32_t shared_image_usage =
...@@ -300,7 +317,7 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread( ...@@ -300,7 +317,7 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread(
const bool success = shared_image_stub->CreateSharedImage( const bool success = shared_image_stub->CreateSharedImage(
mailbox, shared_image_stub->channel()->client_id(), mailbox, shared_image_stub->channel()->client_id(),
std::move(gpu_memory_buffer_handle), *buffer_format, std::move(gpu_memory_buffer_handle), *buffer_format,
gpu::kNullSurfaceHandle, video_frame->coded_size(), gpu::kNullSurfaceHandle, destination_visible_rect.size(),
video_frame->ColorSpace(), shared_image_usage); video_frame->ColorSpace(), shared_image_usage);
if (!success) { if (!success) {
OnError(FROM_HERE, "Failed to create shared image."); OnError(FROM_HERE, "Failed to create shared image.");
...@@ -309,7 +326,7 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread( ...@@ -309,7 +326,7 @@ MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread(
// There's no need to UpdateSharedImage() after CreateSharedImage(). // There's no need to UpdateSharedImage() after CreateSharedImage().
return std::make_unique<ScopedSharedImage>( return std::make_unique<ScopedSharedImage>(
mailbox, gpu_task_runner_, mailbox, destination_visible_rect, gpu_task_runner_,
shared_image_stub->GetSharedImageDestructionCallback(mailbox)); shared_image_stub->GetSharedImageDestructionCallback(mailbox));
} }
......
...@@ -99,7 +99,8 @@ class MEDIA_GPU_EXPORT MailboxVideoFrameConverter : public VideoFrameConverter { ...@@ -99,7 +99,8 @@ class MEDIA_GPU_EXPORT MailboxVideoFrameConverter : public VideoFrameConverter {
// alive for the duration of this method. This method runs on // alive for the duration of this method. This method runs on
// |gpu_task_runner_|. // |gpu_task_runner_|.
std::unique_ptr<ScopedSharedImage> GenerateSharedImageOnGPUThread( std::unique_ptr<ScopedSharedImage> GenerateSharedImageOnGPUThread(
VideoFrame* video_frame); VideoFrame* video_frame,
const gfx::Rect& destination_visible_rect);
// Registers the mapping between a DMA-buf VideoFrame and the SharedImage. // Registers the mapping between a DMA-buf VideoFrame and the SharedImage.
// |origin_frame| must be kept alive for the duration of this method. // |origin_frame| must be kept alive for the duration of this method.
......
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