#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_INTERFACE_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_INTERFACE_H_
#include <memory>
#include <vector>
#include "base/containers/flat_map.h"
#include "build/build_config.h"
#include "components/viz/common/quads/aggregated_render_pass.h"
#include "components/viz/service/display/aggregated_frame.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/service/gpu_task_scheduler_helper.h"
#include "gpu/ipc/common/surface_handle.h"
#include "ui/gfx/ca_layer_result.h"
#include "ui/gfx/geometry/rrect_f.h"
#include "ui/gfx/overlay_priority_hint.h"
#if BUILDFLAG(IS_WIN)
#include "components/viz/service/display/dc_layer_overlay.h"
#endif
#if BUILDFLAG(IS_APPLE)
#include "components/viz/service/display/ca_layer_overlay.h"
#endif
namespace cc {
class DisplayResourceProvider;
}
namespace gpu {
class SharedImageInterface;
}
namespace viz {
struct DebugRendererSettings;
class OutputSurface;
class RendererSettings;
class VIZ_SERVICE_EXPORT OverlayProcessorInterface {
public:
using PlatformOverlayCandidate = OverlayCandidate;
using CandidateList = OverlayCandidateList;
using FilterOperationsMap =
base::flat_map<AggregatedRenderPassId, cc::FilterOperations*>;
virtual bool DisableSplittingQuads() const;
static void RecordOverlayDamageRectHistograms(
bool is_overlay,
bool has_occluding_surface_damage,
bool zero_damage_rect);
struct VIZ_SERVICE_EXPORT OutputSurfaceOverlayPlane {
OutputSurfaceOverlayPlane();
OutputSurfaceOverlayPlane(const OutputSurfaceOverlayPlane&);
OutputSurfaceOverlayPlane& operator=(const OutputSurfaceOverlayPlane&);
~OutputSurfaceOverlayPlane();
gfx::OverlayTransform transform;
gfx::RectF display_rect;
gfx::RectF uv_rect;
gfx::Size resource_size;
gfx::BufferFormat format;
gfx::ColorSpace color_space;
bool enable_blending;
float opacity;
gpu::Mailbox mailbox;
gfx::OverlayPriorityHint priority_hint;
gfx::RRectF rounded_corners;
absl::optional<gfx::Rect> damage_rect;
};
static OutputSurfaceOverlayPlane ProcessOutputSurfaceAsOverlay(
const gfx::Size& viewport_size,
const gfx::Size& resource_size,
const gfx::BufferFormat& buffer_format,
const gfx::ColorSpace& color_space,
bool has_alpha,
float opacity,
const gpu::Mailbox& mailbox);
static std::unique_ptr<OverlayProcessorInterface> CreateOverlayProcessor(
OutputSurface* output_surface,
gpu::SurfaceHandle surface_handle,
const OutputSurface::Capabilities& capabilities,
DisplayCompositorMemoryAndTaskController* display_controller,
gpu::SharedImageInterface* shared_image_interface,
const RendererSettings& renderer_settings,
const DebugRendererSettings* debug_settings);
OverlayProcessorInterface(const OverlayProcessorInterface&) = delete;
OverlayProcessorInterface& operator=(const OverlayProcessorInterface&) =
delete;
virtual ~OverlayProcessorInterface() = default;
virtual bool IsOverlaySupported() const = 0;
virtual gfx::Rect GetPreviousFrameOverlaysBoundingRect() const = 0;
virtual gfx::Rect GetAndResetOverlayDamage() = 0;
virtual bool NeedsSurfaceDamageRectList() const = 0;
virtual void ProcessForOverlays(
DisplayResourceProvider* resource_provider,
AggregatedRenderPassList* render_passes,
const SkM44& output_color_matrix,
const FilterOperationsMap& render_pass_filters,
const FilterOperationsMap& render_pass_backdrop_filters,
SurfaceDamageRectList surface_damage_rect_list,
OutputSurfaceOverlayPlane* output_surface_plane,
CandidateList* overlay_candidates,
gfx::Rect* damage_rect,
std::vector<gfx::Rect>* content_bounds) = 0;
virtual void AdjustOutputSurfaceOverlay(
absl::optional<OutputSurfaceOverlayPlane>* output_surface_plane) = 0;
virtual void TakeOverlayCandidates(CandidateList* candidate_list) {}
virtual void ScheduleOverlays(
DisplayResourceProvider* display_resource_provider);
virtual void OverlayPresentationComplete();
virtual void SetDisplayTransformHint(gfx::OverlayTransform transform) {}
virtual void SetViewportSize(const gfx::Size& size) {}
virtual void SetFrameSequenceNumber(uint64_t frame_sequence_number) {}
virtual void SetIsVideoCaptureEnabled(bool enabled) {}
virtual void SetIsPageFullscreen(bool enabled) {}
virtual gfx::CALayerResult GetCALayerErrorCode() const;
protected:
OverlayProcessorInterface() = default;
};
}
#endif