File: wayland_overlay_manager_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (149 lines) | stat: -rw-r--r-- 5,726 bytes parent folder | download | duplicates (4)
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#include "ui/ozone/platform/wayland/gpu/wayland_overlay_manager.h"

#include <drm_fourcc.h>

#include "base/containers/flat_map.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
#include "ui/ozone/public/overlay_surface_candidate.h"

namespace ui {
namespace {

constexpr gfx::AcceleratedWidget kPrimaryWidget = 1;

OverlaySurfaceCandidate CreateCandidate(const gfx::Rect& rect,
                                        int plane_z_order) {
  ui::OverlaySurfaceCandidate candidate;
  candidate.transform = gfx::OVERLAY_TRANSFORM_NONE;
  candidate.format = gfx::BufferFormat::YUV_420_BIPLANAR;
  candidate.plane_z_order = plane_z_order;
  candidate.buffer_size = rect.size();
  candidate.display_rect = gfx::RectF(rect);
  candidate.crop_rect = gfx::RectF(rect);
  return candidate;
}

}  // namespace

class WaylandOverlayManagerTest : public WaylandTest {
 public:
  WaylandOverlayManagerTest() = default;

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

  ~WaylandOverlayManagerTest() override = default;

  void SetUp() override {
    const base::flat_map<gfx::BufferFormat, std::vector<uint64_t>>
        kSupportedFormatsWithModifiers{
            {gfx::BufferFormat::YUV_420_BIPLANAR, {DRM_FORMAT_MOD_LINEAR}}};

    WaylandTest::SetUp();

    auto manager_ptr = connection_->buffer_manager_host()->BindInterface();
    buffer_manager_gpu_->Initialize(std::move(manager_ptr),
                                    kSupportedFormatsWithModifiers,
                                    /*supports_dma_buf=*/false,
                                    /*supports_viewporter=*/true,
                                    /*supports_acquire_fence=*/false,
                                    /*supports_overlays=*/true,
                                    /*supports_single_pixel_buffer=*/true);

    // Wait until initialization and mojo calls go through.
    base::RunLoop().RunUntilIdle();
  }
};

TEST_P(WaylandOverlayManagerTest, MultipleOverlayCandidates) {
  // WaylandBufferManagerGpu manager_gpu;
  WaylandOverlayManager manager(buffer_manager_gpu_.get());

  std::vector<OverlaySurfaceCandidate> candidates = {
      CreateCandidate(gfx::Rect(10, 10, 20, 20), -2),
      CreateCandidate(gfx::Rect(30, 30, 10, 10), -1),
      CreateCandidate(gfx::Rect(0, 0, 100, 100), 0),
      CreateCandidate(gfx::Rect(40, 40, 20, 20), 1),
      CreateCandidate(gfx::Rect(60, 60, 20, 20), 2)};

  // Submit a set of candidates that could potentially be displayed in an
  // overlay. All candidates should be marked as handled.
  manager.CheckOverlaySupport(&candidates, kPrimaryWidget);
  EXPECT_TRUE(candidates[0].overlay_handled);
  EXPECT_TRUE(candidates[1].overlay_handled);
  EXPECT_TRUE(candidates[2].overlay_handled);
  EXPECT_TRUE(candidates[3].overlay_handled);
  EXPECT_TRUE(candidates[4].overlay_handled);
}

TEST_P(WaylandOverlayManagerTest, FormatSupportTest) {
  WaylandOverlayManager manager(buffer_manager_gpu_.get());

  std::vector<OverlaySurfaceCandidate> candidates = {
      CreateCandidate(gfx::Rect(0, 0, 100, 100), 0),
      CreateCandidate(gfx::Rect(10, 10, 20, 20), 1)};
  candidates[1].format = gfx::BufferFormat::RGBX_8888;
  manager.CheckOverlaySupport(&candidates, kPrimaryWidget);
  EXPECT_TRUE(candidates[0].overlay_handled);
  EXPECT_FALSE(candidates[1].overlay_handled);
}

namespace {

void NonIntegerDisplayRectTestHelper(WaylandBufferManagerGpu* manager_gpu,
                                     bool is_context_delegated,
                                     bool expect_candidates_handled) {
  WaylandOverlayManager manager(manager_gpu);
  if (is_context_delegated)
    manager.SetContextDelegated();

  // Candidates for output surface and single-on-top quad.
  std::vector<OverlaySurfaceCandidate> candidates = {
      CreateCandidate(gfx::Rect(0, 0, 100, 100), 0),
      CreateCandidate(gfx::Rect(10, 10, 20, 20), 1)};

  // Submit a set of candidates that could potentially be displayed in an
  // overlay.
  manager.CheckOverlaySupport(&candidates, kPrimaryWidget);
  EXPECT_TRUE(candidates[0].overlay_handled);
  EXPECT_TRUE(candidates[1].overlay_handled);

  candidates[0].overlay_handled = false;
  candidates[1].overlay_handled = false;

  // Modify the display_rect for the second candidate so it's non-integer. We
  // will try to promote this to an overlay iff subpixel accurate position is
  // supported and overlay delegation is enabled.
  candidates[1].display_rect = gfx::RectF(9.4, 10.43, 20.11, 20.99);
  manager.CheckOverlaySupport(&candidates, kPrimaryWidget);
  EXPECT_TRUE(candidates[0].overlay_handled);
  EXPECT_EQ(expect_candidates_handled, candidates[1].overlay_handled);
}

}  // namespace

TEST_P(WaylandOverlayManagerTest, DoesNotSupportNonIntegerDisplayRect) {
  constexpr std::array<std::array<bool, 2>, 2> test_data = {
      {{false, false}, {true, false}}};
  for (const auto& data : test_data) {
    NonIntegerDisplayRectTestHelper(buffer_manager_gpu_.get(),
                                    data[0] /* is_delegated_context */,
                                    data[1] /* expect_candidates_handled */);
  }
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WaylandOverlayManagerTest);

}  // namespace ui