Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_surface_unittest.cc

Issue 1350473002: Revert of ozone: Remove the "drm" software composited platform (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "base/message_loop/message_loop.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
11 #include "ui/ozone/platform/drm/gpu/drm_buffer.h"
12 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
13 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
14 #include "ui/ozone/platform/drm/gpu/drm_surface.h"
15 #include "ui/ozone/platform/drm/gpu/drm_window.h"
16 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
17 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
18 #include "ui/ozone/platform/drm/test/mock_drm_device.h"
19
20 namespace {
21
22 // Create a basic mode for a 6x4 screen.
23 const drmModeModeInfo kDefaultMode =
24 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
25
26 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1;
27 const uint32_t kDefaultCrtc = 1;
28 const uint32_t kDefaultConnector = 2;
29 const size_t kPlanesPerCrtc = 1;
30 const uint32_t kDefaultCursorSize = 64;
31
32 std::vector<skia::RefPtr<SkSurface>> GetFramebuffers(ui::MockDrmDevice* drm) {
33 std::vector<skia::RefPtr<SkSurface>> framebuffers;
34 for (const auto& buffer : drm->buffers()) {
35 // Skip destroyed buffers and cursor buffers.
36 if (!buffer || (buffer->width() == kDefaultCursorSize &&
37 buffer->height() == kDefaultCursorSize))
38 continue;
39
40 framebuffers.push_back(buffer);
41 }
42
43 return framebuffers;
44 }
45
46 } // namespace
47
48 class DrmSurfaceTest : public testing::Test {
49 public:
50 DrmSurfaceTest() {}
51
52 void SetUp() override;
53 void TearDown() override;
54
55 protected:
56 scoped_ptr<base::MessageLoop> message_loop_;
57 scoped_refptr<ui::MockDrmDevice> drm_;
58 scoped_ptr<ui::DrmBufferGenerator> buffer_generator_;
59 scoped_ptr<ui::ScreenManager> screen_manager_;
60 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_;
61 scoped_ptr<ui::DrmSurface> surface_;
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(DrmSurfaceTest);
65 };
66
67 void DrmSurfaceTest::SetUp() {
68 message_loop_.reset(new base::MessageLoopForUI);
69 std::vector<uint32_t> crtcs;
70 crtcs.push_back(kDefaultCrtc);
71 drm_ = new ui::MockDrmDevice(false, crtcs, kPlanesPerCrtc);
72 buffer_generator_.reset(new ui::DrmBufferGenerator());
73 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get()));
74 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector);
75 screen_manager_->ConfigureDisplayController(
76 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode);
77
78 drm_device_manager_.reset(new ui::DrmDeviceManager(nullptr));
79 scoped_ptr<ui::DrmWindow> window(new ui::DrmWindow(
80 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get()));
81 window->Initialize();
82 window->OnBoundsChanged(
83 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)));
84 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass());
85
86 surface_.reset(
87 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle)));
88 surface_->ResizeCanvas(
89 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay));
90
91 // The window has been remapped to a controller. The first swap will cause the
92 // SWAP_NAK_RECREATE_BUFFERS without actually using the buffers.
93 surface_->PresentCanvas(gfx::Rect());
94 }
95
96 void DrmSurfaceTest::TearDown() {
97 surface_.reset();
98 scoped_ptr<ui::DrmWindow> window =
99 screen_manager_->RemoveWindow(kDefaultWidgetHandle);
100 window->Shutdown();
101 drm_ = nullptr;
102 message_loop_.reset();
103 }
104
105 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) {
106 surface_->PresentCanvas(gfx::Rect());
107 drm_->RunCallbacks();
108
109 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset and
110 // framebuffer ID 2 is used when the window to display mapping is done.
111 EXPECT_EQ(3u, drm_->current_framebuffer());
112 surface_->PresentCanvas(gfx::Rect());
113 drm_->RunCallbacks();
114 EXPECT_EQ(4u, drm_->current_framebuffer());
115 }
116
117 TEST_F(DrmSurfaceTest, CheckSurfaceContents) {
118 SkPaint paint;
119 paint.setColor(SK_ColorWHITE);
120 SkRect rect =
121 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
122 surface_->GetSurface()->getCanvas()->drawRect(rect, paint);
123 surface_->PresentCanvas(
124 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
125 drm_->RunCallbacks();
126
127 SkBitmap image;
128 std::vector<skia::RefPtr<SkSurface>> framebuffers =
129 GetFramebuffers(drm_.get());
130
131 // Buffer 0 is the modesetting buffer, buffer 2 is the frontbuffer and buffer
132 // 1 is the backbuffer.
133 EXPECT_EQ(3u, framebuffers.size());
134
135 image.setInfo(framebuffers[1]->getCanvas()->imageInfo());
136 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0));
137
138 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
139 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
140
141 // Make sure the updates are correctly propagated to the native surface.
142 for (int i = 0; i < image.height(); ++i) {
143 for (int j = 0; j < image.width(); ++j) {
144 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
145 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
146 else
147 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
148 }
149 }
150 }
151
152 TEST_F(DrmSurfaceTest, CheckSurfaceContentsAfter2QueuedPresents) {
153 gfx::Rect rect;
154 // Present an empty buffer but don't respond with the page flip event since we
155 // want to make sure the following presents will aggregate correctly.
156 surface_->PresentCanvas(rect);
157
158 SkPaint paint;
159 paint.setColor(SK_ColorWHITE);
160 rect.SetRect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
161 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint);
162 surface_->PresentCanvas(rect);
163
164 paint.setColor(SK_ColorRED);
165 rect.SetRect(0, kDefaultMode.vdisplay / 2, kDefaultMode.hdisplay / 2,
166 kDefaultMode.vdisplay / 2);
167 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint);
168 surface_->PresentCanvas(rect);
169
170 drm_->RunCallbacks();
171
172 SkBitmap image;
173 std::vector<skia::RefPtr<SkSurface>> framebuffers =
174 GetFramebuffers(drm_.get());
175
176 // Buffer 0 is the modesetting buffer, buffer 2 is the backbuffer and buffer
177 // 1 is the frontbuffer.
178 EXPECT_EQ(3u, framebuffers.size());
179
180 image.setInfo(framebuffers[2]->getCanvas()->imageInfo());
181 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0));
182
183 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
184 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
185
186 // Make sure the updates are correctly propagated to the native surface.
187 for (int i = 0; i < image.height(); ++i) {
188 for (int j = 0; j < image.width(); ++j) {
189 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
190 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
191 else if (j < kDefaultMode.hdisplay / 2)
192 EXPECT_EQ(SK_ColorRED, image.getColor(j, i));
193 else
194 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
195 }
196 }
197 }
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_surface_factory.cc ('k') | ui/ozone/platform/drm/gpu/gbm_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698