Commit 550ad6ff authored by Weiliang Chen's avatar Weiliang Chen Committed by Commit Bot

overlay: Use a Stub OverlayProcessor When Offscreen

When the display compositor is offscreen, and the passed in surface
handle is null, return a stub class for overlay processor. This removes
enable_overlay and could_overlay bools from other overlay processor
classes.

R=Khushal

Bug: 898680
Change-Id: I75f72ba3dfabcc3ab0e2fe80509bb6cad7a74910
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446463Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: default avatarMaggie Chen <magchen@chromium.org>
Commit-Queue: weiliangc <weiliangc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816631}
parent c6edb33a
......@@ -95,8 +95,7 @@ class OverlayOutputSurface : public OutputSurface {
class CATestOverlayProcessor : public OverlayProcessorMac {
public:
CATestOverlayProcessor()
: OverlayProcessorMac(true /* could_overlay */,
true /* enable_ca_overlay */) {}
: OverlayProcessorMac(true /* enable_ca_overlay */) {}
};
std::unique_ptr<AggregatedRenderPass> CreateRenderPass() {
......
......@@ -20,14 +20,8 @@ namespace viz {
OverlayProcessorAndroid::OverlayProcessorAndroid(
gpu::SharedImageManager* shared_image_manager,
gpu::MemoryTracker* memory_tracker,
gpu::GpuTaskSchedulerHelper* gpu_task_scheduler,
bool enable_overlay)
: OverlayProcessorUsingStrategy(),
gpu_task_scheduler_(gpu_task_scheduler),
overlay_enabled_(enable_overlay) {
if (!overlay_enabled_)
return;
gpu::GpuTaskSchedulerHelper* gpu_task_scheduler)
: OverlayProcessorUsingStrategy(), gpu_task_scheduler_(gpu_task_scheduler) {
// In unittests, we don't have the gpu_task_scheduler_ set up, but still want
// to test ProcessForOverlays functionalities where we are making overlay
// candidates correctly.
......@@ -90,7 +84,7 @@ void OverlayProcessorAndroid::DestroyOverlayProcessorOnGpu(
}
bool OverlayProcessorAndroid::IsOverlaySupported() const {
return overlay_enabled_;
return true;
}
bool OverlayProcessorAndroid::NeedsSurfaceDamageRectList() const {
......
......@@ -34,8 +34,7 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid
public:
OverlayProcessorAndroid(gpu::SharedImageManager* shared_image_manager,
gpu::MemoryTracker* memory_tracker,
gpu::GpuTaskSchedulerHelper* gpu_task_scheduler,
bool enable_overlay);
gpu::GpuTaskSchedulerHelper* gpu_task_scheduler);
~OverlayProcessorAndroid() override;
bool IsOverlaySupported() const override;
......@@ -79,7 +78,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorAndroid
PromotionHintInfoMap promotion_hint_info_map_;
gpu::GpuTaskSchedulerHelper* gpu_task_scheduler_;
const bool overlay_enabled_;
// This class is created, accessed, and destroyed on the gpu thread.
std::unique_ptr<OverlayProcessorOnGpu> processor_on_gpu_;
......
......@@ -88,25 +88,34 @@ OverlayProcessorInterface::CreateOverlayProcessor(
gpu::SharedImageInterface* shared_image_interface,
const RendererSettings& renderer_settings,
const DebugRendererSettings* debug_settings) {
// If we are offscreen, we don't have overlay support.
// TODO(vasilyt): WebView would have a kNullSurfaceHandle. Make sure when
// overlay for WebView is enabled, this check still works.
if (surface_handle == gpu::kNullSurfaceHandle)
return std::make_unique<OverlayProcessorStub>();
#if defined(OS_APPLE)
bool could_overlay =
output_surface->GetSurfaceHandle() != gpu::kNullSurfaceHandle;
could_overlay &= output_surface->capabilities().supports_surfaceless;
bool enable_ca_overlay = could_overlay && renderer_settings.allow_overlays;
DCHECK(capabilities.supports_surfaceless);
return std::make_unique<OverlayProcessorMac>(could_overlay,
enable_ca_overlay);
return std::make_unique<OverlayProcessorMac>(
renderer_settings.allow_overlays);
#elif defined(OS_WIN)
if (!capabilities.supports_dc_layers)
return std::make_unique<OverlayProcessorStub>();
return std::make_unique<OverlayProcessorWin>(
output_surface, std::make_unique<DCLayerOverlayProcessor>(
debug_settings, /*allowed_yuv_overlay_count=*/1));
#elif defined(USE_OZONE)
if (!features::IsUsingOzonePlatform())
return std::make_unique<OverlayProcessorStub>();
bool overlay_enabled = surface_handle != gpu::kNullSurfaceHandle;
overlay_enabled &= !renderer_settings.overlay_strategies.empty();
// In tests and Ozone/X11, we do not expect surfaceless surface support.
if (!capabilities.supports_surfaceless)
return std::make_unique<OverlayProcessorStub>();
std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates;
if (overlay_enabled) {
if (!renderer_settings.overlay_strategies.empty()) {
auto* overlay_manager =
ui::OzonePlatform::GetInstance()->GetOverlayManager();
overlay_candidates =
......@@ -114,19 +123,18 @@ OverlayProcessorInterface::CreateOverlayProcessor(
}
gpu::SharedImageInterface* sii = nullptr;
if (overlay_enabled && features::ShouldUseRealBuffersForPageFlipTest()) {
if (features::ShouldUseRealBuffersForPageFlipTest()) {
sii = shared_image_interface;
CHECK(shared_image_interface);
}
return std::make_unique<OverlayProcessorOzone>(
overlay_enabled, std::move(overlay_candidates),
std::move(overlay_candidates),
std::move(renderer_settings.overlay_strategies), sii);
#elif defined(OS_ANDROID)
bool overlay_enabled = surface_handle != gpu::kNullSurfaceHandle;
if (capabilities.supports_surfaceless) {
// This is for Android SurfaceControl case.
return std::make_unique<OverlayProcessorSurfaceControl>(overlay_enabled);
return std::make_unique<OverlayProcessorSurfaceControl>();
} else {
// When SurfaceControl is enabled, any resource backed by
// an AHardwareBuffer can be marked as an overlay candidate but it requires
......@@ -134,10 +142,11 @@ OverlayProcessorInterface::CreateOverlayProcessor(
// native window backed GLSurface, the overlay processing code will
// incorrectly assume these resources can be overlaid. So we disable all
// overlay processing for this OutputSurface.
overlay_enabled &= !capabilities.android_surface_control_feature_enabled;
if (capabilities.android_surface_control_feature_enabled)
return std::make_unique<OverlayProcessorStub>();
return std::make_unique<OverlayProcessorAndroid>(
shared_image_manager, memory_tracker, gpu_task_scheduler,
overlay_enabled);
shared_image_manager, memory_tracker, gpu_task_scheduler);
}
#else // Default
return std::make_unique<OverlayProcessorStub>();
......
......@@ -15,17 +15,14 @@
#include "ui/gfx/geometry/rect_conversions.h"
namespace viz {
OverlayProcessorMac::OverlayProcessorMac(bool could_overlay,
bool enable_ca_overlay)
: could_overlay_(could_overlay),
enable_ca_overlay_(enable_ca_overlay),
OverlayProcessorMac::OverlayProcessorMac(bool enable_ca_overlay)
: enable_ca_overlay_(enable_ca_overlay),
ca_layer_overlay_processor_(std::make_unique<CALayerOverlayProcessor>()) {
}
OverlayProcessorMac::OverlayProcessorMac(
std::unique_ptr<CALayerOverlayProcessor> ca_layer_overlay_processor)
: could_overlay_(true),
enable_ca_overlay_(true),
: enable_ca_overlay_(true),
ca_layer_overlay_processor_(std::move(ca_layer_overlay_processor)) {}
OverlayProcessorMac::~OverlayProcessorMac() = default;
......@@ -35,7 +32,7 @@ bool OverlayProcessorMac::DisableSplittingQuads() const {
}
bool OverlayProcessorMac::IsOverlaySupported() const {
return could_overlay_;
return true;
}
gfx::Rect OverlayProcessorMac::GetPreviousFrameOverlaysBoundingRect() const {
......
......@@ -27,7 +27,7 @@ class VIZ_SERVICE_EXPORT OverlayProcessorMac
public:
using CandidateList = CALayerOverlayList;
OverlayProcessorMac(bool could_overlay, bool enable_ca_overlay);
explicit OverlayProcessorMac(bool enable_ca_overlay);
// For testing.
explicit OverlayProcessorMac(
std::unique_ptr<CALayerOverlayProcessor> ca_layer_overlay_processor);
......@@ -67,7 +67,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorMac
base::Optional<OutputSurfaceOverlayPlane>* output_surface_plane) override;
private:
const bool could_overlay_;
const bool enable_ca_overlay_;
gfx::Rect ca_overlay_damage_rect_;
gfx::Rect previous_frame_full_bounding_rect_;
......
......@@ -71,37 +71,32 @@ void ReportSharedImageExists(bool exists) {
// |available_strategies| is a list of overlay strategies that should be
// initialized by InitializeStrategies.
OverlayProcessorOzone::OverlayProcessorOzone(
bool overlay_enabled,
std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates,
std::vector<OverlayStrategy> available_strategies,
gpu::SharedImageInterface* shared_image_interface)
: OverlayProcessorUsingStrategy(),
overlay_enabled_(overlay_enabled),
overlay_candidates_(std::move(overlay_candidates)),
available_strategies_(std::move(available_strategies)),
shared_image_interface_(shared_image_interface) {
if (overlay_enabled_) {
for (OverlayStrategy strategy : available_strategies_) {
switch (strategy) {
case OverlayStrategy::kFullscreen:
strategies_.push_back(
std::make_unique<OverlayStrategyFullscreen>(this));
break;
case OverlayStrategy::kSingleOnTop:
strategies_.push_back(
std::make_unique<OverlayStrategySingleOnTop>(this));
break;
case OverlayStrategy::kUnderlay:
strategies_.push_back(
std::make_unique<OverlayStrategyUnderlay>(this));
break;
case OverlayStrategy::kUnderlayCast:
strategies_.push_back(
std::make_unique<OverlayStrategyUnderlayCast>(this));
break;
default:
NOTREACHED();
}
for (OverlayStrategy strategy : available_strategies_) {
switch (strategy) {
case OverlayStrategy::kFullscreen:
strategies_.push_back(
std::make_unique<OverlayStrategyFullscreen>(this));
break;
case OverlayStrategy::kSingleOnTop:
strategies_.push_back(
std::make_unique<OverlayStrategySingleOnTop>(this));
break;
case OverlayStrategy::kUnderlay:
strategies_.push_back(std::make_unique<OverlayStrategyUnderlay>(this));
break;
case OverlayStrategy::kUnderlayCast:
strategies_.push_back(
std::make_unique<OverlayStrategyUnderlayCast>(this));
break;
default:
NOTREACHED();
}
}
}
......@@ -109,7 +104,7 @@ OverlayProcessorOzone::OverlayProcessorOzone(
OverlayProcessorOzone::~OverlayProcessorOzone() = default;
bool OverlayProcessorOzone::IsOverlaySupported() const {
return overlay_enabled_;
return true;
}
bool OverlayProcessorOzone::NeedsSurfaceDamageRectList() const {
......
......@@ -18,7 +18,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorOzone
: public OverlayProcessorUsingStrategy {
public:
OverlayProcessorOzone(
bool overlay_enabled,
std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates,
std::vector<OverlayStrategy> available_strategies,
gpu::SharedImageInterface* shared_image_interface);
......@@ -45,8 +44,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorOzone
bool SetNativePixmapForCandidate(ui::OverlaySurfaceCandidate* candidate,
const gpu::Mailbox& mailbox);
const bool overlay_enabled_;
std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates_;
const std::vector<OverlayStrategy> available_strategies_;
gpu::SharedImageInterface* const shared_image_interface_;
......
......@@ -30,19 +30,16 @@ gfx::RectF ClipFromOrigin(gfx::RectF input) {
} // namespace
OverlayProcessorSurfaceControl::OverlayProcessorSurfaceControl(
bool enable_overlay)
: OverlayProcessorUsingStrategy(), overlay_enabled_(enable_overlay) {
if (overlay_enabled_) {
strategies_.push_back(std::make_unique<OverlayStrategyUnderlay>(
this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates));
}
OverlayProcessorSurfaceControl::OverlayProcessorSurfaceControl()
: OverlayProcessorUsingStrategy() {
strategies_.push_back(std::make_unique<OverlayStrategyUnderlay>(
this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates));
}
OverlayProcessorSurfaceControl::~OverlayProcessorSurfaceControl() {}
bool OverlayProcessorSurfaceControl::IsOverlaySupported() const {
return overlay_enabled_;
return true;
}
bool OverlayProcessorSurfaceControl::NeedsSurfaceDamageRectList() const {
......
......@@ -13,7 +13,7 @@ namespace viz {
class VIZ_SERVICE_EXPORT OverlayProcessorSurfaceControl
: public OverlayProcessorUsingStrategy {
public:
explicit OverlayProcessorSurfaceControl(bool enable_overlay);
OverlayProcessorSurfaceControl();
~OverlayProcessorSurfaceControl() override;
bool IsOverlaySupported() const override;
......@@ -32,7 +32,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorSurfaceControl
const OverlayCandidate& overlay) const override;
private:
const bool overlay_enabled_;
gfx::OverlayTransform display_transform_ = gfx::OVERLAY_TRANSFORM_NONE;
gfx::Size viewport_size_;
};
......
......@@ -20,7 +20,7 @@ TEST(OverlayCandidateValidatorSurfaceControlTest, NoClipOrNegativeOffset) {
OverlayCandidateList candidates;
candidates.push_back(candidate);
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.CheckOverlaySupport(nullptr, &candidates);
EXPECT_TRUE(candidates.at(0).overlay_handled);
EXPECT_RECTF_EQ(candidates.at(0).display_rect, gfx::RectF(10.f, 10.f));
......@@ -37,7 +37,7 @@ TEST(OverlayProcessorSurfaceControlTest, Clipped) {
OverlayCandidateList candidates;
candidates.push_back(candidate);
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.CheckOverlaySupport(nullptr, &candidates);
EXPECT_TRUE(candidates.at(0).overlay_handled);
EXPECT_RECTF_EQ(candidates.at(0).display_rect,
......@@ -56,7 +56,7 @@ TEST(OverlayProcessorSurfaceControlTest, NegativeOffset) {
OverlayCandidateList candidates;
candidates.push_back(candidate);
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.CheckOverlaySupport(nullptr, &candidates);
EXPECT_TRUE(candidates.at(0).overlay_handled);
EXPECT_RECTF_EQ(candidates.at(0).display_rect,
......@@ -75,7 +75,7 @@ TEST(OverlayProcessorSurfaceControlTest, ClipAndNegativeOffset) {
OverlayCandidateList candidates;
candidates.push_back(candidate);
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.CheckOverlaySupport(nullptr, &candidates);
EXPECT_TRUE(candidates.at(0).overlay_handled);
EXPECT_RECTF_EQ(candidates.at(0).display_rect,
......@@ -92,7 +92,7 @@ TEST(OverlayProcessorSurfaceControlTest, DisplayTransformOverlay) {
OverlayCandidateList candidates;
candidates.push_back(candidate);
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.SetViewportSize(gfx::Size(100, 200));
processor.SetDisplayTransformHint(gfx::OVERLAY_TRANSFORM_ROTATE_90);
......@@ -116,7 +116,7 @@ TEST(OverlayProcessorSurfaceControlTest, DisplayTransformOutputSurfaceOverlay) {
base::Optional<OverlayProcessorInterface::OutputSurfaceOverlayPlane>
overlay_plane = candidate;
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.SetViewportSize(gfx::Size(100, 200));
processor.SetDisplayTransformHint(gfx::OVERLAY_TRANSFORM_ROTATE_90);
processor.AdjustOutputSurfaceOverlay(&overlay_plane);
......@@ -130,7 +130,7 @@ TEST(OverlayCandidateValidatorTest, OverlayDamageRectForOutputSurface) {
candidate.transform = gfx::OVERLAY_TRANSFORM_ROTATE_90;
candidate.overlay_handled = false;
OverlayProcessorSurfaceControl processor(true);
OverlayProcessorSurfaceControl processor;
processor.SetViewportSize(gfx::Size(100, 200));
processor.SetDisplayTransformHint(gfx::OVERLAY_TRANSFORM_ROTATE_90);
......
......@@ -27,13 +27,14 @@ OverlayProcessorWin::OverlayProcessorWin(
OutputSurface* output_surface,
std::unique_ptr<DCLayerOverlayProcessor> dc_layer_overlay_processor)
: output_surface_(output_surface),
supports_dc_layers_(output_surface->capabilities().supports_dc_layers),
dc_layer_overlay_processor_(std::move(dc_layer_overlay_processor)) {}
dc_layer_overlay_processor_(std::move(dc_layer_overlay_processor)) {
DCHECK(output_surface_->capabilities().supports_dc_layers);
}
OverlayProcessorWin::~OverlayProcessorWin() = default;
bool OverlayProcessorWin::IsOverlaySupported() const {
return supports_dc_layers_;
return true;
}
gfx::Rect OverlayProcessorWin::GetPreviousFrameOverlaysBoundingRect() const {
......@@ -85,9 +86,6 @@ void OverlayProcessorWin::ProcessForOverlays(
return;
}
if (!supports_dc_layers_)
return;
dc_layer_overlay_processor_->Process(
resource_provider, gfx::RectF(root_render_pass->output_rect),
render_passes, damage_rect, surface_damage_rect_list, candidates);
......
......@@ -70,8 +70,6 @@ class VIZ_SERVICE_EXPORT OverlayProcessorWin
private:
OutputSurface* const output_surface_;
// Whether direct composition layers are supported by the output surface.
const bool supports_dc_layers_;
// Whether direct composition layers are being used with SetEnableDCLayers().
bool using_dc_layers_ = false;
// Number of frames since the last time direct composition layers were used.
......
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