File: overlay_candidate_factory.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (187 lines) | stat: -rw-r--r-- 8,293 bytes parent folder | download | duplicates (6)
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
// Copyright 2022 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_CANDIDATE_FACTORY_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_CANDIDATE_FACTORY_H_

#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "components/viz/common/quads/aggregated_render_pass.h"
#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/common/resources/resource_id.h"
#include "components/viz/service/display/aggregated_frame.h"
#include "components/viz/service/display/overlay_candidate.h"
#include "components/viz/service/display/overlay_processor_interface.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/hdr_metadata.h"
#include "ui/gfx/overlay_priority_hint.h"
#include "ui/gfx/overlay_transform.h"

namespace gfx {
class Rect;
}

namespace viz {
class AggregatedRenderPassDrawQuad;
class DisplayResourceProvider;
class SolidColorDrawQuad;
class TextureDrawQuad;
class VideoHoleDrawQuad;

// This is a factory to help with the creation of |OverlayCandidates|.  On
// construction, this factory captures the required objects to create candidates
// from a draw quad.  Common computations for all possible candidates can be
// made at construction time. This class is const after construction and not
// copy/moveable to avoid capture ownership issues.
class VIZ_SERVICE_EXPORT OverlayCandidateFactory {
 public:
  using CandidateStatus = OverlayCandidate::CandidateStatus;

  struct VIZ_SERVICE_EXPORT OverlayContext {
    OverlayContext();
    OverlayContext(const OverlayContext&);

    bool is_delegated_context = false;
    // When false, the factory can modify the candidate to provide the same
    // output but result in a smaller serialization size.
    bool disable_wire_size_optimization = false;
    bool supports_clip_rect = false;
    bool supports_out_of_window_clip_rect = false;
    bool supports_arbitrary_transform = false;
    bool supports_rounded_display_masks = false;
    bool supports_mask_filter = false;
    bool transform_and_clip_rpdq = false;
    bool supports_flip_rotate_transform = false;
  };

  // The coordinate space of |render_pass| is the target space for candidates
  // produced by this factory.
  OverlayCandidateFactory(
      const AggregatedRenderPass* render_pass,
      const DisplayResourceProvider* resource_provider,
      const SurfaceDamageRectList* surface_damage_rect_list,
      const SkM44* output_color_matrix,
      const gfx::RectF primary_rect,
      const OverlayProcessorInterface::FilterOperationsMap* render_pass_filters,
      const OverlayContext& context);

  OverlayCandidateFactory(const OverlayCandidateFactory&) = delete;
  OverlayCandidateFactory& operator=(const OverlayCandidateFactory&) = delete;

  ~OverlayCandidateFactory();

  // Returns |kSuccess| and fills in |candidate| if |draw_quad| is of a known
  // quad type and contains an overlayable resource. |primary_rect| can be empty
  // in the case of a null primary plane. |candidate| is expected to be a
  // freshly constructed |OverlayCandidate| object.
  CandidateStatus FromDrawQuad(const DrawQuad* quad,
                               OverlayCandidate& candidate) const;

  // Returns an estimate of this |quad|'s actual visible damage area as float
  // pixels squared. This visible damage is computed by combining from input
  // |surface_damage_rect_list_| with the occluding rects in the quad_list. This
  // is an estimate since the occluded damage area is calculated on a per quad
  // basis. The |quad_list_begin| and |quad_list_end| provide the range of valid
  // occluders of this |candidate|.
  // TODO(petermcneeley): Can we replace this with |visible_rect| in |DrawQuad|?
  float EstimateVisibleDamage(const DrawQuad* quad,
                              const OverlayCandidate& candidate,
                              QuadList::ConstIterator quad_list_begin,
                              QuadList::ConstIterator quad_list_end) const;

  // Returns true if any of the quads in the list given by |quad_list_begin|
  // and |quad_list_end| have an associated filter and occlude |quad|.
  // |quad| should normally be at |quad_list_end| since we only want to check
  // for occlusion with quads above it.
  static bool IsOccludedByFilteredQuad(
      const DrawQuad& quad,
      QuadList::ConstIterator quad_list_begin,
      QuadList::ConstIterator quad_list_end,
      const base::flat_map<AggregatedRenderPassId,
                           raw_ptr<cc::FilterOperations, CtnExperimental>>&
          render_pass_backdrop_filters);

  // Returns true if any of the quads in the list given by |quad_list_begin|
  // and |quad_list_end| occlude |quad|.
  // |quad| should normally be at |quad_list_end| since we only want to check
  // for occlusion with quads above it.
  static bool IsOccluded(const DrawQuad& quad,
                         QuadList::ConstIterator quad_list_begin,
                         QuadList::ConstIterator quad_list_end);

  gfx::Rect GetUnassignedDamage() { return unassigned_surface_damage_; }

  // Adjusts candidate for subsampling and cliping for required overlay
  // and logging purposes.
  void HandleClipAndSubsampling(OverlayCandidate& candidate) const;

 private:
  CandidateStatus FromDrawQuadResource(const DrawQuad* quad,
                                       ResourceId resource_id,
                                       bool y_flipped,
                                       OverlayCandidate& candidate) const;

  CandidateStatus FromTextureQuad(const TextureDrawQuad* quad,
                                  OverlayCandidate& candidate) const;

  CandidateStatus FromTileQuad(const TileDrawQuad* quad,
                               OverlayCandidate& candidate) const;

  CandidateStatus FromAggregateQuad(const AggregatedRenderPassDrawQuad* quad,
                                    OverlayCandidate& candidate) const;

  CandidateStatus FromSolidColorQuad(const SolidColorDrawQuad* quad,
                                     OverlayCandidate& candidate) const;

  CandidateStatus FromVideoHoleQuad(const VideoHoleDrawQuad* quad,
                                    OverlayCandidate& candidate) const;

  void AssignDamage(const DrawQuad* quad, OverlayCandidate& candidate) const;

  // Damage returned from this function is in target space.
  gfx::RectF GetDamageRect(const DrawQuad* quad) const;

  gfx::RectF GetDamageEstimate(const OverlayCandidate& candidate) const;

  // Apply clipping "geometrically" by adjusting the |quad->rect| and
  // |quad->uv_rect|. May return CandidateStatus::kFailVisible if the clipping
  // to be applied is empty.
  CandidateStatus DoGeometricClipping(const DrawQuad* quad,
                                      OverlayCandidate& candidate) const;

  // Apply |quad_to_target_transform| to the candidate, based on
  // |OverlayContext| settings.
  CandidateStatus ApplyTransform(const gfx::Transform& quad_to_target_transform,
                                 const bool y_flipped,
                                 OverlayCandidate& candidate) const;

  // Set |candidate.display_rect| based on |quad|. In delegated contexts, this
  // will also apply content clipping in the quad, and expand to a render pass's
  // filter bounds.
  void SetDisplayRect(const DrawQuad& quad, OverlayCandidate& candidate) const;

  raw_ptr<const AggregatedRenderPass> render_pass_;
  raw_ptr<const DisplayResourceProvider> resource_provider_;
  raw_ptr<const SurfaceDamageRectList> surface_damage_rect_list_;
  const gfx::RectF primary_rect_;
  raw_ptr<const OverlayProcessorInterface::FilterOperationsMap>
      render_pass_filters_;
  const OverlayContext context_;

  // The union of all surface damages that are not specifically assigned to a
  // draw quad.
  gfx::Rect unassigned_surface_damage_;
  bool has_custom_color_matrix_;
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_SERVICE_DISPLAY_OVERLAY_CANDIDATE_FACTORY_H_