Commit 064c1945 authored by Weiliang Chen's avatar Weiliang Chen Committed by Commit Bot

viz: OverlayProcessor Sends Candidate Directly for Android Pre-SC

For Andorid Pre-SurfaceControl, overlay processor can send the
overlay candidates directly.

This is CL 6/? for sending the overlay candidates directly to gpu thread.

R=rjkroege

Bug: 979788
Change-Id: I76d97e8c8cfece078f6ea8d90bf8d3e7ae02dbfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1985305
Commit-Queue: weiliangc <weiliangc@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733619}
parent 6474322c
...@@ -414,8 +414,14 @@ void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order, ...@@ -414,8 +414,14 @@ void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
current_frame()->output_surface_plane->gpu_fence_id = current_frame()->output_surface_plane->gpu_fence_id =
output_surface_->UpdateGpuFence(); output_surface_->UpdateGpuFence();
if (overlay_processor_)
overlay_processor_->TakeOverlayCandidates(&current_frame()->overlay_list);
FinishDrawingFrame(); FinishDrawingFrame();
if (overlay_processor_)
overlay_processor_->ScheduleOverlays(resource_provider_);
render_passes_in_draw_order->clear(); render_passes_in_draw_order->clear();
render_pass_filters_.clear(); render_pass_filters_.clear();
render_pass_backdrop_filters_.clear(); render_pass_backdrop_filters_.clear();
......
...@@ -721,6 +721,7 @@ void Display::DidReceiveSwapBuffersAck(const gfx::SwapTimings& timings) { ...@@ -721,6 +721,7 @@ void Display::DidReceiveSwapBuffersAck(const gfx::SwapTimings& timings) {
if (no_pending_swaps_callback_ && pending_swaps_ == 0) if (no_pending_swaps_callback_ && pending_swaps_ == 0)
std::move(no_pending_swaps_callback_).Run(); std::move(no_pending_swaps_callback_).Run();
overlay_processor_->OverlayPresentationComplete();
if (renderer_) if (renderer_)
renderer_->SwapBuffersComplete(); renderer_->SwapBuffersComplete();
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "components/viz/common/quads/stream_video_draw_quad.h" #include "components/viz/common/quads/stream_video_draw_quad.h"
#include "components/viz/service/display/display_resource_provider.h"
#include "components/viz/service/display/overlay_processor_on_gpu.h" #include "components/viz/service/display/overlay_processor_on_gpu.h"
#include "components/viz/service/display/overlay_strategy_underlay.h" #include "components/viz/service/display/overlay_strategy_underlay.h"
#include "components/viz/service/display/skia_output_surface.h" #include "components/viz/service/display/skia_output_surface.h"
...@@ -89,18 +88,15 @@ void OverlayProcessorAndroid::ScheduleOverlays( ...@@ -89,18 +88,15 @@ void OverlayProcessorAndroid::ScheduleOverlays(
if (!gpu_task_scheduler_) if (!gpu_task_scheduler_)
return; return;
std::vector< pending_overlay_locks_.emplace_back();
std::unique_ptr<DisplayResourceProvider::ScopedReadLockSharedImage>> auto& locks = pending_overlay_locks_.back();
locks;
for (auto& candidate : overlay_candidates_) { for (auto& candidate : overlay_candidates_) {
locks.emplace_back( locks.emplace_back(resource_provider, candidate.resource_id);
std::make_unique<DisplayResourceProvider::ScopedReadLockSharedImage>(
resource_provider, candidate.resource_id));
} }
std::vector<gpu::SyncToken> locks_sync_tokens; std::vector<gpu::SyncToken> locks_sync_tokens;
for (auto& read_lock : locks) for (auto& read_lock : locks)
locks_sync_tokens.push_back(read_lock->sync_token()); locks_sync_tokens.push_back(read_lock.sync_token());
auto task = base::BindOnce(&OverlayProcessorOnGpu::ScheduleOverlays, auto task = base::BindOnce(&OverlayProcessorOnGpu::ScheduleOverlays,
base::Unretained(processor_on_gpu_.get()), base::Unretained(processor_on_gpu_.get()),
...@@ -109,6 +105,14 @@ void OverlayProcessorAndroid::ScheduleOverlays( ...@@ -109,6 +105,14 @@ void OverlayProcessorAndroid::ScheduleOverlays(
overlay_candidates_.clear(); overlay_candidates_.clear();
} }
void OverlayProcessorAndroid::OverlayPresentationComplete() {
// This is a signal from Display::DidReceiveSwapBuffersAck. We use this to
// help clear locks on resources from old frame.
committed_overlay_locks_.clear();
std::swap(committed_overlay_locks_, pending_overlay_locks_.front());
pending_overlay_locks_.pop_front();
}
void OverlayProcessorAndroid::CheckOverlaySupport( void OverlayProcessorAndroid::CheckOverlaySupport(
const OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane, const OverlayProcessorInterface::OutputSurfaceOverlayPlane* primary_plane,
OverlayCandidateList* candidates) { OverlayCandidateList* candidates) {
...@@ -154,6 +158,12 @@ gfx::Rect OverlayProcessorAndroid::GetOverlayDamageRectForOutputSurface( ...@@ -154,6 +158,12 @@ gfx::Rect OverlayProcessorAndroid::GetOverlayDamageRectForOutputSurface(
return ToEnclosedRect(overlay.display_rect); return ToEnclosedRect(overlay.display_rect);
} }
void OverlayProcessorAndroid::TakeOverlayCandidates(
OverlayCandidateList* candidate_list) {
overlay_candidates_.swap(*candidate_list);
candidate_list->clear();
}
void OverlayProcessorAndroid::NotifyOverlayPromotion( void OverlayProcessorAndroid::NotifyOverlayPromotion(
DisplayResourceProvider* resource_provider, DisplayResourceProvider* resource_provider,
const CandidateList& candidates, const CandidateList& candidates,
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_ANDROID_H_ #ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_ANDROID_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_ANDROID_H_ #define COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_ANDROID_H_
#include "base/containers/circular_deque.h"
#include "components/viz/service/display/display_resource_provider.h"
#include "components/viz/service/display/overlay_processor_using_strategy.h" #include "components/viz/service/display/overlay_processor_using_strategy.h"
namespace base { namespace base {
...@@ -38,6 +40,8 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid ...@@ -38,6 +40,8 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid
void ScheduleOverlays( void ScheduleOverlays(
DisplayResourceProvider* display_resource_provider) override; DisplayResourceProvider* display_resource_provider) override;
void OverlayPresentationComplete() override;
// Override OverlayProcessorUsingStrategy. // Override OverlayProcessorUsingStrategy.
void SetDisplayTransformHint(gfx::OverlayTransform transform) override {} void SetDisplayTransformHint(gfx::OverlayTransform transform) override {}
void SetViewportSize(const gfx::Size& size) override {} void SetViewportSize(const gfx::Size& size) override {}
...@@ -55,6 +59,7 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid ...@@ -55,6 +59,7 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid
void InitializeOverlayProcessorOnGpu( void InitializeOverlayProcessorOnGpu(
gpu::SharedImageManager* shared_image_manager); gpu::SharedImageManager* shared_image_manager);
void DestroyOverlayProcessorOnGpu(base::WaitableEvent* event); void DestroyOverlayProcessorOnGpu(base::WaitableEvent* event);
void TakeOverlayCandidates(CandidateList* candidate_list) override;
void NotifyOverlayPromotion( void NotifyOverlayPromotion(
DisplayResourceProvider* display_resource_provider, DisplayResourceProvider* display_resource_provider,
const OverlayCandidateList& candidate_list, const OverlayCandidateList& candidate_list,
...@@ -78,6 +83,15 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid ...@@ -78,6 +83,15 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid
std::unique_ptr<OverlayProcessorOnGpu> processor_on_gpu_; std::unique_ptr<OverlayProcessorOnGpu> processor_on_gpu_;
OverlayCandidateList overlay_candidates_; OverlayCandidateList overlay_candidates_;
using OverlayResourceLock =
DisplayResourceProvider::ScopedReadLockSharedImage;
// Locks for overlays are pending for OverlayPresentationComplete.
base::circular_deque<std::vector<OverlayResourceLock>> pending_overlay_locks_;
// Locks for overlays have been committed. |pending_overlay_locks_| will
// be moved to |committed_overlay_locks_| after OverlayPresentationComplete.
std::vector<OverlayResourceLock> committed_overlay_locks_;
}; };
} // namespace viz } // namespace viz
......
...@@ -163,4 +163,6 @@ OverlayProcessorInterface::ProcessOutputSurfaceAsOverlay( ...@@ -163,4 +163,6 @@ OverlayProcessorInterface::ProcessOutputSurfaceAsOverlay(
void OverlayProcessorInterface::ScheduleOverlays( void OverlayProcessorInterface::ScheduleOverlays(
DisplayResourceProvider* display_resource_provider) {} DisplayResourceProvider* display_resource_provider) {}
void OverlayProcessorInterface::OverlayPresentationComplete() {}
} // namespace viz } // namespace viz
...@@ -129,10 +129,21 @@ class VIZ_SERVICE_EXPORT OverlayProcessorInterface { ...@@ -129,10 +129,21 @@ class VIZ_SERVICE_EXPORT OverlayProcessorInterface {
virtual void AdjustOutputSurfaceOverlay( virtual void AdjustOutputSurfaceOverlay(
base::Optional<OutputSurfaceOverlayPlane>* output_surface_plane) = 0; base::Optional<OutputSurfaceOverlayPlane>* output_surface_plane) = 0;
// Before the overlay refactor to use OverlayProcessorOnGpu, overlay
// candidates are stored inside DirectRenderer. Those overlay candidates are
// later sent over to the GPU thread by GLRenderer or SkiaRenderer. This is a
// helper function to take these overlay candidates inside overlay processor
// to avoid sending over DirectRenderer implementation. This is overridden by
// each platform that is ready to send overlay candidates inside overlay
// processo. Must be called before ScheduleOverlays().
virtual void TakeOverlayCandidates(CandidateList* candidate_list) {}
// TODO(weiliangc): Make it pure virtual after it is implemented by every // TODO(weiliangc): Make it pure virtual after it is implemented by every
// subclass. // subclass.
virtual void ScheduleOverlays( virtual void ScheduleOverlays(
DisplayResourceProvider* display_resource_provider); DisplayResourceProvider* display_resource_provider);
// This is a signal from Display::DidReceiveSwapBuffersAck.
virtual void OverlayPresentationComplete();
// These two functions are used by Android SurfaceControl. // These two functions are used by Android SurfaceControl.
virtual void SetDisplayTransformHint(gfx::OverlayTransform transform) {} virtual void SetDisplayTransformHint(gfx::OverlayTransform transform) {}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/viz/service/display/overlay_processor_on_gpu.h" #include "components/viz/service/display/overlay_processor_on_gpu.h"
#include "gpu/command_buffer/service/shared_image_factory.h" #include "gpu/command_buffer/service/shared_image_factory.h"
#include "gpu/command_buffer/service/shared_image_manager.h" #include "gpu/command_buffer/service/shared_image_manager.h"
#include "ui/gfx/geometry/rect_conversions.h"
namespace viz { namespace viz {
...@@ -24,7 +25,28 @@ OverlayProcessorOnGpu::~OverlayProcessorOnGpu() { ...@@ -24,7 +25,28 @@ OverlayProcessorOnGpu::~OverlayProcessorOnGpu() {
void OverlayProcessorOnGpu::ScheduleOverlays( void OverlayProcessorOnGpu::ScheduleOverlays(
CandidateList&& overlay_candidates) { CandidateList&& overlay_candidates) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// TODO(weiliangc): Use shared image to schedule overlays. #if defined(OS_ANDROID)
// TODO(weiliangc): Currently only implemented for Android Classic code path.
for (auto& overlay : overlay_candidates) {
auto shared_image_overlay =
shared_image_representation_factory_->ProduceOverlay(overlay.mailbox);
// When display is re-opened, the first few frames might not have video
// resource ready. Possible investigation crbug.com/1023971.
if (!shared_image_overlay)
continue;
// In current implementation, the BeginReadAccess will ends up calling
// CodecImage::RenderToOverlay. Currently this code path is only used for
// Android Classic video overlay, where update of the overlay plane is
// within media code. Since we are not actually passing an overlay plane to
// the display controller here, we are able to call EndReadAccess directly
// after BeginReadAccess.
shared_image_overlay->NotifyOverlayPromotion(
true, ToNearestRect(overlay.display_rect));
std::unique_ptr<gpu::SharedImageRepresentationOverlay::ScopedReadAccess>
scoped_access = shared_image_overlay->BeginScopedReadAccess(
false /* needs_gl_image */);
}
#endif
} }
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
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