File: overlay_processor_interface.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (247 lines) | stat: -rw-r--r-- 9,395 bytes parent folder | download | duplicates (5)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/viz/service/display/overlay_processor_interface.h"

#include <utility>

#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "components/viz/common/buildflags.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/features.h"
#include "components/viz/service/display/display_compositor_memory_and_task_controller.h"
#include "components/viz/service/display/overlay_processor_stub.h"
#include "components/viz/service/display_embedder/skia_output_surface_dependency.h"
#include "ui/gfx/overlay_priority_hint.h"

#if BUILDFLAG(IS_APPLE)
#include "components/viz/service/display/overlay_processor_mac.h"
#elif BUILDFLAG(IS_WIN)
#include "components/viz/service/display/overlay_processor_win.h"
#elif BUILDFLAG(IS_ANDROID)
#include "components/viz/service/display/overlay_processor_android.h"
#include "components/viz/service/display/overlay_processor_surface_control.h"
#elif BUILDFLAG(IS_OZONE)
#include "components/viz/service/display/overlay_processor_delegated.h"
#include "components/viz/service/display/overlay_processor_ozone.h"
#include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
#include "ui/ozone/public/overlay_manager_ozone.h"
#include "ui/ozone/public/ozone_platform.h"
#endif

namespace viz {
namespace {

#if BUILDFLAG(IS_OZONE)
class SharedImageManagerPixmapProvider
    : public OverlayProcessorOzone::PixmapProvider {
 public:
  explicit SharedImageManagerPixmapProvider(gpu::SharedImageManager* manager)
      : manager_(manager) {
    CHECK(manager_);
  }

  scoped_refptr<gfx::NativePixmap> GetNativePixmap(
      const gpu::Mailbox& mailbox) override {
    return manager_->GetNativePixmap(mailbox);
  }

  const raw_ptr<gpu::SharedImageManager> manager_;
};
#endif

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UnderlayDamage {
  kZeroDamageRect,
  kNonOccludingDamageOnly,
  kOccludingDamageOnly,  // deprecated
  kOccludingAndNonOccludingDamages,
  kMaxValue = kOccludingAndNonOccludingDamages,
};
}  // namespace

// Record UMA histograms for overlays
// 1. Underlay vs. Overlay
// 2. Full screen mode vs. Non Full screen (Windows) mode
// 3. Overlay zero damage rect vs. non zero damage rect
// 4. Underlay zero damage rect, non-zero damage rect with non-occluding damage
//   only, non-zero damage rect with occluding damage, and non-zero damage rect
//   with both damages

// static
void OverlayProcessorInterface::RecordOverlayDamageRectHistograms(
    bool is_overlay,
    bool has_occluding_surface_damage,
    bool zero_damage_rect) {
  if (is_overlay) {
    UMA_HISTOGRAM_BOOLEAN("Viz.DisplayCompositor.RootDamageRect.Overlay",
                          !zero_damage_rect);
  } else {  // underlay
    UnderlayDamage underlay_damage = UnderlayDamage::kZeroDamageRect;
    if (zero_damage_rect) {
      underlay_damage = UnderlayDamage::kZeroDamageRect;
    } else {
      if (has_occluding_surface_damage) {
        underlay_damage = UnderlayDamage::kOccludingAndNonOccludingDamages;
      } else {
        underlay_damage = UnderlayDamage::kNonOccludingDamageOnly;
      }
    }
    UMA_HISTOGRAM_ENUMERATION("Viz.DisplayCompositor.RootDamageRect.Underlay",
                              underlay_damage);
  }
}

OverlayProcessorInterface::OutputSurfaceOverlayPlane::
    OutputSurfaceOverlayPlane() = default;
OverlayProcessorInterface::OutputSurfaceOverlayPlane::OutputSurfaceOverlayPlane(
    const OutputSurfaceOverlayPlane&) = default;
OverlayProcessorInterface::OutputSurfaceOverlayPlane&
OverlayProcessorInterface::OutputSurfaceOverlayPlane::operator=(
    const OutputSurfaceOverlayPlane&) = default;
OverlayProcessorInterface::OutputSurfaceOverlayPlane::
    ~OutputSurfaceOverlayPlane() = default;

std::unique_ptr<OverlayProcessorInterface>
OverlayProcessorInterface::CreateOverlayProcessor(
    OutputSurface* output_surface,
    gpu::SurfaceHandle surface_handle,
    const OutputSurface::Capabilities& capabilities,
    DisplayCompositorMemoryAndTaskController* display_controller,
    gpu::SharedImageManager* shared_image_manager,
    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 BUILDFLAG(IS_APPLE)
  DCHECK(capabilities.supports_surfaceless);
  return std::make_unique<OverlayProcessorMac>();
#elif BUILDFLAG(IS_WIN)
  if (capabilities.dc_support_level == OutputSurface::DCSupportLevel::kNone) {
    return std::make_unique<OverlayProcessorStub>();
  }

  DCHECK(display_controller);
  DCHECK(display_controller->skia_dependency());
  return std::make_unique<OverlayProcessorWin>(
      capabilities.dc_support_level, debug_settings,
      std::make_unique<DCLayerOverlayProcessor>(
          capabilities.allowed_yuv_overlay_count,
          display_controller->skia_dependency()
              ->GetGpuDriverBugWorkarounds()
              .disable_video_overlay_if_moving));

#elif BUILDFLAG(IS_OZONE)
#if !BUILDFLAG(IS_CASTOS)
  // In tests and Ozone/X11, we do not expect surfaceless surface support.
  // For CastOS, we always need OverlayProcessorOzone.
  if (!capabilities.supports_surfaceless)
    return std::make_unique<OverlayProcessorStub>();
#endif  // #if !BUILDFLAG(IS_CASTOS)

  std::unique_ptr<OverlayProcessorOzone::PixmapProvider> pixmap_provider;
  auto* overlay_manager = ui::OzonePlatform::GetInstance()->GetOverlayManager();
  std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates;
  if (overlay_manager) {
    overlay_candidates =
        overlay_manager->CreateOverlayCandidates(surface_handle);
    if (overlay_manager->allow_sync_and_real_buffer_page_flip_testing()) {
      pixmap_provider = std::make_unique<SharedImageManagerPixmapProvider>(
          shared_image_manager);
    }
  }

  return std::make_unique<OverlayProcessorOzone>(
      std::move(overlay_candidates),
      std::move(renderer_settings.overlay_strategies),
      std::move(pixmap_provider));

#elif BUILDFLAG(IS_ANDROID)
  DCHECK(display_controller);

  if (capabilities.supports_surfaceless) {
    // This is for Android SurfaceControl case.
    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
    // that we use a SurfaceControl backed GLSurface. If we're creating a
    // 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.
    if (capabilities.android_surface_control_feature_enabled)
      return std::make_unique<OverlayProcessorStub>();

    return std::make_unique<OverlayProcessorAndroid>(display_controller);
  }
#else  // Default
  return std::make_unique<OverlayProcessorStub>();
#endif
}

bool OverlayProcessorInterface::DisableSplittingQuads() const {
  return false;
}

OverlayProcessorInterface::OutputSurfaceOverlayPlane
OverlayProcessorInterface::ProcessOutputSurfaceAsOverlay(
    const gfx::Size& viewport_size,
    const gfx::Size& resource_size,
    const SharedImageFormat si_format,
    const gfx::ColorSpace& color_space,
    bool has_alpha,
    float opacity,
    const gpu::Mailbox& mailbox) {
  OutputSurfaceOverlayPlane overlay_plane;
  overlay_plane.transform = gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE;
  overlay_plane.uv_rect = gfx::RectF(
      0.f, 0.f,
      viewport_size.width() / static_cast<float>(resource_size.width()),
      viewport_size.height() / static_cast<float>(resource_size.height()));
  overlay_plane.resource_size = resource_size;
  overlay_plane.format = si_format;
  overlay_plane.color_space = color_space;
  overlay_plane.enable_blending = has_alpha;
  overlay_plane.opacity = opacity;
  overlay_plane.mailbox = mailbox;
  overlay_plane.priority_hint = gfx::OverlayPriorityHint::kRegular;
  overlay_plane.rounded_corners = gfx::RRectF();

  // Adjust transformation and display_rect based on display rotation.
  overlay_plane.display_rect =
      gfx::RectF(viewport_size.width(), viewport_size.height());

#if BUILDFLAG(ALWAYS_ENABLE_BLENDING_FOR_PRIMARY)
  // On Chromecast, always use RGBA as the scanout format for the primary plane.
  overlay_plane.enable_blending = true;
#endif
  return overlay_plane;
}

void OverlayProcessorInterface::ScheduleOverlays(
    DisplayResourceProvider* display_resource_provider) {}

void OverlayProcessorInterface::OverlayPresentationComplete() {}

gfx::CALayerResult OverlayProcessorInterface::GetCALayerErrorCode() const {
  return gfx::kCALayerSuccess;
}

gfx::RectF OverlayProcessorInterface::GetUnassignedDamage() const {
  return gfx::RectF();
}

bool OverlayProcessorInterface::SupportsFlipRotateTransform() const {
  return false;
}

}  // namespace viz