1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_WIN_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_WIN_H_
#include <memory>
#include <utility>
#include <vector>
#include "base/check_is_test.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "components/viz/common/features.h"
#include "components/viz/common/quads/aggregated_render_pass.h"
#include "components/viz/service/display/dc_layer_overlay.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/display/overlay_processor_delegated_support.h"
#include "components/viz/service/display/overlay_processor_interface.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/ipc/common/surface_handle.h"
namespace viz {
class DisplayResourceProvider;
struct DebugRendererSettings;
class OverlayCandidateFactory;
class VIZ_SERVICE_EXPORT OverlayProcessorWin
: public OverlayProcessorInterface {
public:
OverlayProcessorWin(
OutputSurface::DCSupportLevel dc_support_level,
const DebugRendererSettings* debug_settings,
std::unique_ptr<DCLayerOverlayProcessor> dc_layer_overlay_processor);
OverlayProcessorWin(const OverlayProcessorWin&) = delete;
OverlayProcessorWin& operator=(const OverlayProcessorWin&) = delete;
~OverlayProcessorWin() override;
bool DisableSplittingQuads() const override;
bool IsOverlaySupported() const override;
gfx::Rect GetAndResetOverlayDamage() override;
// Returns true if the platform supports hw overlays and surface occluding
// damage rect needs to be computed since it will be used by overlay
// processor.
bool NeedsSurfaceDamageRectList() const override;
// Sets |is_page_fullscreen_mode_|.
void SetIsPageFullscreen(bool enabled) override;
void AdjustOutputSurfaceOverlay(
std::optional<OutputSurfaceOverlayPlane>* output_surface_plane) override;
// Attempt to replace quads from the specified root render pass with overlays
// or CALayers. This must be called every frame.
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_in_root_space,
OutputSurfaceOverlayPlane* output_surface_plane,
OverlayCandidateList* overlay_candidates,
gfx::Rect* root_damage_rect,
std::vector<gfx::Rect>* content_bounds) override;
void SetFrameHasDelegatedInk() override;
bool frame_has_forced_dcomp_surface_for_testing() const {
CHECK_IS_TEST();
return frame_has_forced_dcomp_surface_;
}
// Sets whether or not |render_pass_id| will be marked for a DComp surface
// backing. If |value| is true, this also resets the frame count since
// enabling DC layers.
void SetUsingDCLayersForTesting(AggregatedRenderPassId render_pass_id,
bool value);
static gfx::Rect InsertSurfaceContentOverlaysAndSetPlaneZOrderForTesting(
DCLayerOverlayProcessor::RenderPassOverlayDataMap
surface_content_render_passes,
OverlayCandidateList& candidates);
protected:
// For testing.
DCLayerOverlayProcessor* GetOverlayProcessor() {
return dc_layer_overlay_processor_.get();
}
private:
void InsertDebugBorderDrawQuadsForOverlayCandidates(
const OverlayCandidateList& dc_layer_overlays,
AggregatedRenderPass* render_pass,
gfx::Rect& damage_rect);
// Promote a subset of quads from the root render pass using
// |DCLayerOverlayProcessor| while still intending to schedule the primary
// plane as its own overlay. This is the fallback for delegated compositing
// that still allows quads to be promoted e.g. for protected content or for
// performance reasons.
void ProcessOverlaysFromOutputSurfacePlane(
DisplayResourceProvider* resource_provider,
AggregatedRenderPassList* render_passes,
const SkM44& output_color_matrix,
const OverlayProcessorInterface::FilterOperationsMap& render_pass_filters,
const OverlayProcessorInterface::FilterOperationsMap&
render_pass_backdrop_filters,
const SurfaceDamageRectList& surface_damage_rect_list_in_root_space,
OutputSurfaceOverlayPlane* output_surface_plane,
CandidateList* candidates,
gfx::Rect* root_damage_rect);
// Try to promote all quads from the root render pass to overlay.
// In partially delegated compositing, RPDQs that represent surfaces will have
// quads promoted from their render passes using |DCLayerOverlayProcessor|.
DelegationStatus ProcessOverlaysForDelegation(
DisplayResourceProvider* resource_provider,
AggregatedRenderPassList* render_passes,
const SkM44& output_color_matrix,
const OverlayProcessorInterface::FilterOperationsMap& render_pass_filters,
const OverlayProcessorInterface::FilterOperationsMap&
render_pass_backdrop_filters,
const SurfaceDamageRectList& surface_damage_rect_list_in_root_space,
CandidateList* candidates,
gfx::Rect* root_damage_rect);
// This struct holds information about the RPDQ overlays promoted during
// delegated compositing. It references objects in the current frame and is
// only valid while the render pass list's pointers are valid.
// TODO(crbug.com/324460866): Used for partially delegated compositing.
struct PromotedRenderPassesInfo {
PromotedRenderPassesInfo();
~PromotedRenderPassesInfo();
PromotedRenderPassesInfo(PromotedRenderPassesInfo&&);
PromotedRenderPassesInfo& operator=(PromotedRenderPassesInfo&&);
// List of render passes that were embedded by a promoted RPDQ overlay.
base::flat_set<raw_ref<AggregatedRenderPass>> promoted_render_passes;
// List of RPDQs that were promoted to overlay.
std::vector<raw_ref<const AggregatedRenderPassDrawQuad>> promoted_rpdqs;
};
// Result of attempting delegated compositing.
struct DelegatedCompositingResult {
DelegatedCompositingResult();
~DelegatedCompositingResult();
DelegatedCompositingResult(DelegatedCompositingResult&&);
DelegatedCompositingResult& operator=(DelegatedCompositingResult&&);
OverlayCandidateList candidates;
PromotedRenderPassesInfo promoted_render_passes_info;
};
// Attempt to promote all the quads in |root_render_pass|. Promoted quads will
// be placed in |out_candidates| in back-to-front order. Returns true if all
// quads were successfully promoted.
base::expected<DelegatedCompositingResult, DelegationStatus>
TryDelegatedCompositing(
bool is_full_delegated_compositing,
const AggregatedRenderPassList& render_passes,
const OverlayCandidateFactory& factory,
const OverlayProcessorInterface::FilterOperationsMap&
render_pass_backdrop_filters,
const DisplayResourceProvider* resource_provider) const;
// Modifies the properties of |promoted_render_passes| for passes that are
// referenced by RPDQ overlays. This gives |SkiaRenderer| enough information
// to decide whether or not a RPDQ overlay can skip the copy in
// |PrepareRenderPassOverlay| and, if so, whether to allocate a swap chain or
// DComp surface backing. Returns the set of surfaces we should use
// |DCLayerOverlayProcessor| to promote overlays from.
// TODO(crbug.com/324460866): Used for partially delegated compositing.
static DCLayerOverlayProcessor::RenderPassOverlayDataMap
UpdatePromotedRenderPassPropertiesAndGetSurfaceContentPasses(
const AggregatedRenderPassList& render_passes,
const PromotedRenderPassesInfo& promoted_render_passes_info);
// Insert overlay candidates from |surface_content_render_passes| into
// |candidates|, assigning correct plane z-order in the process. |candidates|
// is assumed to be in back-to-front. The resulting candidates list is not
// sorted. Returns the union rect of overlays in
// |surface_content_render_passes|.
// TODO(crbug.com/324460866): Used for partially delegated compositing.
static gfx::Rect InsertSurfaceContentOverlaysAndSetPlaneZOrder(
DCLayerOverlayProcessor::RenderPassOverlayDataMap
surface_content_render_passes,
OverlayCandidateList& candidates);
const std::optional<features::DelegatedCompositingMode>
delegated_compositing_supported_;
// Reference to the global viz singleton.
const raw_ptr<const DebugRendererSettings> debug_settings_;
// Number of frames since the last time direct composition layers were used
// for each render pass we promote overlays from in the frame. Presence in
// this map indicates that the render pass is using a DComp surface.
base::flat_map<AggregatedRenderPassId, int> frames_since_using_dc_layers_map_;
// TODO(weiliangc): Eventually fold DCLayerOverlayProcessor into this class.
std::unique_ptr<DCLayerOverlayProcessor> dc_layer_overlay_processor_;
bool is_page_fullscreen_mode_ = false;
bool delegation_succeeded_last_frame_ = false;
// If true, causes the use of DComp surfaces as the backing image of all
// render passes for the frame.
bool frame_has_forced_dcomp_surface_ = false;
// Returned and reset by |GetAndResetOverlayDamage| to fully damage the root
// render pass when we drop out of delegated compositing. This is essentially
// a binary of "full damage needed" or "no full damage needed" for the primary
// plane.
gfx::Rect overlay_damage_rect_;
// The union of the current frame's overlays that were promoted from surface
// content passes to be read on the subsequent frame. This is used to
// correctly damage surface content backings if we had previously removed
// damage due to overlay occlusion.
gfx::Rect previous_frame_overlay_rect_;
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_PROCESSOR_WIN_H_
|