Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / hardware_display_plane_manager_unittest.cc
blob862b99ef21f96bcff65e1526b4a08cc9e58c3c68
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
10 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
11 #include "ui/ozone/platform/drm/gpu/hardware_display_plane.h"
12 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.h"
13 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_legacy.h"
14 #include "ui/ozone/platform/drm/gpu/overlay_plane.h"
15 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
16 #include "ui/ozone/platform/drm/test/mock_drm_device.h"
18 namespace {
20 struct FakePlaneInfo {
21 uint32_t id;
22 uint32_t allowed_crtc_mask;
25 const FakePlaneInfo kOnePlanePerCrtc[] = {{10, 1}, {20, 2}};
26 const FakePlaneInfo kTwoPlanesPerCrtc[] = {{10, 1}, {11, 1}, {20, 2}, {21, 2}};
27 const FakePlaneInfo kOnePlanePerCrtcWithShared[] = {{10, 1}, {20, 2}, {50, 3}};
29 class FakeScanoutBuffer : public ui::ScanoutBuffer {
30 public:
31 FakeScanoutBuffer() {}
33 // ui::ScanoutBuffer:
34 uint32_t GetFramebufferId() const override { return 1; }
35 uint32_t GetHandle() const override { return 0; }
36 gfx::Size GetSize() const override { return gfx::Size(1, 1); }
38 protected:
39 ~FakeScanoutBuffer() override {}
42 class FakePlaneManager : public ui::HardwareDisplayPlaneManager {
43 public:
44 FakePlaneManager() : plane_count_(0) {}
45 ~FakePlaneManager() override {}
47 // Normally we'd use DRM to figure out the controller configuration. But we
48 // can't use DRM in unit tests, so we just create a fake configuration.
49 void InitForTest(const FakePlaneInfo* planes,
50 size_t count,
51 const std::vector<uint32_t>& crtcs) {
52 crtcs_ = crtcs;
53 for (size_t i = 0; i < count; i++) {
54 planes_.push_back(new ui::HardwareDisplayPlane(
55 planes[i].id, planes[i].allowed_crtc_mask));
57 // The real HDPM uses sorted planes, so sort them for consistency.
58 std::sort(planes_.begin(), planes_.end(),
59 [](ui::HardwareDisplayPlane* l, ui::HardwareDisplayPlane* r) {
60 return l->plane_id() < r->plane_id();
61 });
64 bool Commit(ui::HardwareDisplayPlaneList* plane_list, bool is_sync) override {
65 return false;
68 bool SetPlaneData(ui::HardwareDisplayPlaneList* plane_list,
69 ui::HardwareDisplayPlane* hw_plane,
70 const ui::OverlayPlane& overlay,
71 uint32_t crtc_id,
72 const gfx::Rect& src_rect,
73 ui::CrtcController* crtc) override {
74 // Check that the chosen plane is a legal choice for the crtc.
75 EXPECT_NE(-1, LookupCrtcIndex(crtc_id));
76 EXPECT_TRUE(hw_plane->CanUseForCrtc(LookupCrtcIndex(crtc_id)));
77 EXPECT_FALSE(hw_plane->in_use());
78 plane_count_++;
79 return true;
82 int plane_count() const { return plane_count_; }
84 private:
85 DISALLOW_COPY_AND_ASSIGN(FakePlaneManager);
87 int plane_count_;
90 class HardwareDisplayPlaneManagerTest : public testing::Test {
91 public:
92 HardwareDisplayPlaneManagerTest() {}
94 void SetUp() override;
96 protected:
97 scoped_ptr<FakePlaneManager> plane_manager_;
98 ui::HardwareDisplayPlaneList state_;
99 std::vector<uint32_t> default_crtcs_;
100 scoped_refptr<ui::ScanoutBuffer> fake_buffer_;
102 private:
103 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayPlaneManagerTest);
106 void HardwareDisplayPlaneManagerTest::SetUp() {
107 fake_buffer_ = new FakeScanoutBuffer();
108 plane_manager_.reset(new FakePlaneManager());
109 default_crtcs_.push_back(100);
110 default_crtcs_.push_back(200);
113 TEST_F(HardwareDisplayPlaneManagerTest, SinglePlaneAssignment) {
114 ui::OverlayPlaneList assigns;
115 assigns.push_back(ui::OverlayPlane(fake_buffer_));
116 plane_manager_->InitForTest(kOnePlanePerCrtc, arraysize(kOnePlanePerCrtc),
117 default_crtcs_);
118 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
119 default_crtcs_[0], nullptr));
120 EXPECT_EQ(1, plane_manager_->plane_count());
123 TEST_F(HardwareDisplayPlaneManagerTest, BadCrtc) {
124 ui::OverlayPlaneList assigns;
125 assigns.push_back(ui::OverlayPlane(fake_buffer_));
126 plane_manager_->InitForTest(kOnePlanePerCrtc, arraysize(kOnePlanePerCrtc),
127 default_crtcs_);
128 EXPECT_FALSE(
129 plane_manager_->AssignOverlayPlanes(&state_, assigns, 1, nullptr));
132 TEST_F(HardwareDisplayPlaneManagerTest, MultiplePlaneAssignment) {
133 ui::OverlayPlaneList assigns;
134 assigns.push_back(ui::OverlayPlane(fake_buffer_));
135 assigns.push_back(ui::OverlayPlane(fake_buffer_));
136 plane_manager_->InitForTest(kTwoPlanesPerCrtc, arraysize(kTwoPlanesPerCrtc),
137 default_crtcs_);
138 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
139 default_crtcs_[0], nullptr));
140 EXPECT_EQ(2, plane_manager_->plane_count());
143 TEST_F(HardwareDisplayPlaneManagerTest, NotEnoughPlanes) {
144 ui::OverlayPlaneList assigns;
145 assigns.push_back(ui::OverlayPlane(fake_buffer_));
146 assigns.push_back(ui::OverlayPlane(fake_buffer_));
147 plane_manager_->InitForTest(kOnePlanePerCrtc, arraysize(kOnePlanePerCrtc),
148 default_crtcs_);
150 EXPECT_FALSE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
151 default_crtcs_[0], nullptr));
154 TEST_F(HardwareDisplayPlaneManagerTest, MultipleCrtcs) {
155 ui::OverlayPlaneList assigns;
156 assigns.push_back(ui::OverlayPlane(fake_buffer_));
157 plane_manager_->InitForTest(kOnePlanePerCrtc, arraysize(kOnePlanePerCrtc),
158 default_crtcs_);
160 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
161 default_crtcs_[0], nullptr));
162 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
163 default_crtcs_[1], nullptr));
164 EXPECT_EQ(2, plane_manager_->plane_count());
167 TEST_F(HardwareDisplayPlaneManagerTest, MultiplePlanesAndCrtcs) {
168 ui::OverlayPlaneList assigns;
169 assigns.push_back(ui::OverlayPlane(fake_buffer_));
170 assigns.push_back(ui::OverlayPlane(fake_buffer_));
171 plane_manager_->InitForTest(kTwoPlanesPerCrtc, arraysize(kTwoPlanesPerCrtc),
172 default_crtcs_);
173 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
174 default_crtcs_[0], nullptr));
175 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
176 default_crtcs_[1], nullptr));
177 EXPECT_EQ(4, plane_manager_->plane_count());
180 TEST_F(HardwareDisplayPlaneManagerTest, MultipleFrames) {
181 ui::OverlayPlaneList assigns;
182 assigns.push_back(ui::OverlayPlane(fake_buffer_));
183 plane_manager_->InitForTest(kTwoPlanesPerCrtc, arraysize(kTwoPlanesPerCrtc),
184 default_crtcs_);
186 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
187 default_crtcs_[0], nullptr));
188 EXPECT_EQ(1, plane_manager_->plane_count());
189 // Pretend we committed the frame.
190 state_.committed = true;
191 state_.plane_list.swap(state_.old_plane_list);
192 ui::HardwareDisplayPlane* old_plane = state_.old_plane_list[0];
193 // The same plane should be used.
194 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
195 default_crtcs_[0], nullptr));
196 EXPECT_EQ(2, plane_manager_->plane_count());
197 EXPECT_EQ(state_.plane_list[0], old_plane);
200 TEST_F(HardwareDisplayPlaneManagerTest, MultipleFramesDifferentPlanes) {
201 ui::OverlayPlaneList assigns;
202 assigns.push_back(ui::OverlayPlane(fake_buffer_));
203 plane_manager_->InitForTest(kTwoPlanesPerCrtc, arraysize(kTwoPlanesPerCrtc),
204 default_crtcs_);
206 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
207 default_crtcs_[0], nullptr));
208 EXPECT_EQ(1, plane_manager_->plane_count());
209 // The other plane should be used.
210 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
211 default_crtcs_[0], nullptr));
212 EXPECT_EQ(2, plane_manager_->plane_count());
213 EXPECT_NE(state_.plane_list[0], state_.plane_list[1]);
216 TEST_F(HardwareDisplayPlaneManagerTest, SharedPlanes) {
217 ui::OverlayPlaneList assigns;
218 assigns.push_back(ui::OverlayPlane(fake_buffer_));
219 assigns.push_back(ui::OverlayPlane(fake_buffer_));
220 plane_manager_->InitForTest(kOnePlanePerCrtcWithShared,
221 arraysize(kOnePlanePerCrtcWithShared),
222 default_crtcs_);
224 EXPECT_TRUE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
225 default_crtcs_[1], nullptr));
226 EXPECT_EQ(2, plane_manager_->plane_count());
227 // The shared plane is now unavailable for use by the other CRTC.
228 EXPECT_FALSE(plane_manager_->AssignOverlayPlanes(&state_, assigns,
229 default_crtcs_[0], nullptr));
232 TEST(HardwareDisplayPlaneManagerLegacyTest, UnusedPlanesAreReleased) {
233 std::vector<uint32_t> crtcs;
234 crtcs.push_back(100);
235 scoped_refptr<ui::MockDrmDevice> drm = new ui::MockDrmDevice(false, crtcs, 2);
236 ui::OverlayPlaneList assigns;
237 scoped_refptr<FakeScanoutBuffer> fake_buffer = new FakeScanoutBuffer();
238 assigns.push_back(ui::OverlayPlane(fake_buffer));
239 assigns.push_back(ui::OverlayPlane(fake_buffer));
240 ui::HardwareDisplayPlaneList hdpl;
241 ui::CrtcController crtc(drm, crtcs[0], 0);
242 EXPECT_TRUE(drm->plane_manager()->AssignOverlayPlanes(&hdpl, assigns,
243 crtcs[0], &crtc));
244 EXPECT_TRUE(drm->plane_manager()->Commit(&hdpl, false));
245 assigns.clear();
246 assigns.push_back(ui::OverlayPlane(fake_buffer));
247 EXPECT_TRUE(drm->plane_manager()->AssignOverlayPlanes(&hdpl, assigns,
248 crtcs[0], &crtc));
249 EXPECT_EQ(0, drm->get_overlay_clear_call_count());
250 EXPECT_TRUE(drm->plane_manager()->Commit(&hdpl, false));
251 EXPECT_EQ(1, drm->get_overlay_clear_call_count());
254 } // namespace