Chromium Code Reviews

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

Issue 1327413003: [Ozone-DRM] Modeset when re-mapping windows to controllers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-scanout2
Patch Set: fixed unittests Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | ui/ozone/platform/drm/gpu/drm_window_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/skia/include/core/SkCanvas.h" 7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/core/SkDevice.h" 9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "ui/ozone/platform/drm/gpu/crtc_controller.h" 10 #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
(...skipping 11 matching lines...)
22 // Create a basic mode for a 6x4 screen. 22 // Create a basic mode for a 6x4 screen.
23 const drmModeModeInfo kDefaultMode = 23 const drmModeModeInfo kDefaultMode =
24 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; 24 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}};
25 25
26 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; 26 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1;
27 const uint32_t kDefaultCrtc = 1; 27 const uint32_t kDefaultCrtc = 1;
28 const uint32_t kDefaultConnector = 2; 28 const uint32_t kDefaultConnector = 2;
29 const size_t kPlanesPerCrtc = 1; 29 const size_t kPlanesPerCrtc = 1;
30 const uint32_t kDefaultCursorSize = 64; 30 const uint32_t kDefaultCursorSize = 64;
31 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
32 } // namespace 46 } // namespace
33 47
34 class DrmSurfaceTest : public testing::Test { 48 class DrmSurfaceTest : public testing::Test {
35 public: 49 public:
36 DrmSurfaceTest() {} 50 DrmSurfaceTest() {}
37 51
38 void SetUp() override; 52 void SetUp() override;
39 void TearDown() override; 53 void TearDown() override;
40 54
41 protected: 55 protected:
(...skipping 42 matching lines...)
84 scoped_ptr<ui::DrmWindow> window = 98 scoped_ptr<ui::DrmWindow> window =
85 screen_manager_->RemoveWindow(kDefaultWidgetHandle); 99 screen_manager_->RemoveWindow(kDefaultWidgetHandle);
86 window->Shutdown(); 100 window->Shutdown();
87 drm_ = nullptr; 101 drm_ = nullptr;
88 message_loop_.reset(); 102 message_loop_.reset();
89 } 103 }
90 104
91 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) { 105 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) {
92 surface_->PresentCanvas(gfx::Rect()); 106 surface_->PresentCanvas(gfx::Rect());
93 drm_->RunCallbacks(); 107 drm_->RunCallbacks();
94 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset. 108
95 EXPECT_EQ(2u, drm_->current_framebuffer()); 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());
96 surface_->PresentCanvas(gfx::Rect()); 112 surface_->PresentCanvas(gfx::Rect());
97 drm_->RunCallbacks(); 113 drm_->RunCallbacks();
98 EXPECT_EQ(3u, drm_->current_framebuffer()); 114 EXPECT_EQ(4u, drm_->current_framebuffer());
99 } 115 }
100 116
101 TEST_F(DrmSurfaceTest, CheckSurfaceContents) { 117 TEST_F(DrmSurfaceTest, CheckSurfaceContents) {
102 SkPaint paint; 118 SkPaint paint;
103 paint.setColor(SK_ColorWHITE); 119 paint.setColor(SK_ColorWHITE);
104 SkRect rect = 120 SkRect rect =
105 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2); 121 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2);
106 surface_->GetSurface()->getCanvas()->drawRect(rect, paint); 122 surface_->GetSurface()->getCanvas()->drawRect(rect, paint);
107 surface_->PresentCanvas( 123 surface_->PresentCanvas(
108 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); 124 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
109 drm_->RunCallbacks(); 125 drm_->RunCallbacks();
110 126
111 SkBitmap image; 127 SkBitmap image;
112 std::vector<skia::RefPtr<SkSurface>> framebuffers; 128 std::vector<skia::RefPtr<SkSurface>> framebuffers =
113 for (const auto& buffer : drm_->buffers()) { 129 GetFramebuffers(drm_.get());
114 // Skip cursor buffers.
115 if (buffer->width() == kDefaultCursorSize &&
116 buffer->height() == kDefaultCursorSize)
117 continue;
118
119 framebuffers.push_back(buffer);
120 }
121 130
122 // Buffer 0 is the modesetting buffer, buffer 2 is the frontbuffer and buffer 131 // Buffer 0 is the modesetting buffer, buffer 2 is the frontbuffer and buffer
123 // 1 is the backbuffer. 132 // 1 is the backbuffer.
124 EXPECT_EQ(3u, framebuffers.size()); 133 EXPECT_EQ(3u, framebuffers.size());
125 134
126 image.setInfo(framebuffers[1]->getCanvas()->imageInfo()); 135 image.setInfo(framebuffers[1]->getCanvas()->imageInfo());
127 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0)); 136 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0));
128 137
129 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); 138 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
130 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); 139 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
(...skipping 23 matching lines...)
154 163
155 paint.setColor(SK_ColorRED); 164 paint.setColor(SK_ColorRED);
156 rect.SetRect(0, kDefaultMode.vdisplay / 2, kDefaultMode.hdisplay / 2, 165 rect.SetRect(0, kDefaultMode.vdisplay / 2, kDefaultMode.hdisplay / 2,
157 kDefaultMode.vdisplay / 2); 166 kDefaultMode.vdisplay / 2);
158 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint); 167 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint);
159 surface_->PresentCanvas(rect); 168 surface_->PresentCanvas(rect);
160 169
161 drm_->RunCallbacks(); 170 drm_->RunCallbacks();
162 171
163 SkBitmap image; 172 SkBitmap image;
164 std::vector<skia::RefPtr<SkSurface>> framebuffers; 173 std::vector<skia::RefPtr<SkSurface>> framebuffers =
165 for (const auto& buffer : drm_->buffers()) { 174 GetFramebuffers(drm_.get());
166 // Skip cursor buffers.
167 if (buffer->width() == kDefaultCursorSize &&
168 buffer->height() == kDefaultCursorSize)
169 continue;
170
171 framebuffers.push_back(buffer);
172 }
173 175
174 // Buffer 0 is the modesetting buffer, buffer 2 is the backbuffer and buffer 176 // Buffer 0 is the modesetting buffer, buffer 2 is the backbuffer and buffer
175 // 1 is the frontbuffer. 177 // 1 is the frontbuffer.
176 EXPECT_EQ(3u, framebuffers.size()); 178 EXPECT_EQ(3u, framebuffers.size());
177 179
178 image.setInfo(framebuffers[2]->getCanvas()->imageInfo()); 180 image.setInfo(framebuffers[2]->getCanvas()->imageInfo());
179 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0)); 181 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0));
180 182
181 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); 183 EXPECT_EQ(kDefaultMode.hdisplay, image.width());
182 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); 184 EXPECT_EQ(kDefaultMode.vdisplay, image.height());
183 185
184 // Make sure the updates are correctly propagated to the native surface. 186 // Make sure the updates are correctly propagated to the native surface.
185 for (int i = 0; i < image.height(); ++i) { 187 for (int i = 0; i < image.height(); ++i) {
186 for (int j = 0; j < image.width(); ++j) { 188 for (int j = 0; j < image.width(); ++j) {
187 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) 189 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
188 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); 190 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));
189 else if (j < kDefaultMode.hdisplay / 2) 191 else if (j < kDefaultMode.hdisplay / 2)
190 EXPECT_EQ(SK_ColorRED, image.getColor(j, i)); 192 EXPECT_EQ(SK_ColorRED, image.getColor(j, i));
191 else 193 else
192 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); 194 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i));
193 } 195 }
194 } 196 }
195 } 197 }
OLDNEW
« no previous file with comments | « no previous file | ui/ozone/platform/drm/gpu/drm_window_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine