OLD | NEW |
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...) Expand all Loading... |
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 24 matching lines...) Expand all Loading... |
66 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get())); | 80 kDefaultWidgetHandle, drm_device_manager_.get(), screen_manager_.get())); |
67 window->Initialize(); | 81 window->Initialize(); |
68 window->OnBoundsChanged( | 82 window->OnBoundsChanged( |
69 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); | 83 gfx::Rect(gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay))); |
70 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass()); | 84 screen_manager_->AddWindow(kDefaultWidgetHandle, window.Pass()); |
71 | 85 |
72 surface_.reset( | 86 surface_.reset( |
73 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle))); | 87 new ui::DrmSurface(screen_manager_->GetWindow(kDefaultWidgetHandle))); |
74 surface_->ResizeCanvas( | 88 surface_->ResizeCanvas( |
75 gfx::Size(kDefaultMode.hdisplay, kDefaultMode.vdisplay)); | 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()); |
76 } | 94 } |
77 | 95 |
78 void DrmSurfaceTest::TearDown() { | 96 void DrmSurfaceTest::TearDown() { |
79 surface_.reset(); | 97 surface_.reset(); |
80 scoped_ptr<ui::DrmWindow> window = | 98 scoped_ptr<ui::DrmWindow> window = |
81 screen_manager_->RemoveWindow(kDefaultWidgetHandle); | 99 screen_manager_->RemoveWindow(kDefaultWidgetHandle); |
82 window->Shutdown(); | 100 window->Shutdown(); |
83 drm_ = nullptr; | 101 drm_ = nullptr; |
84 message_loop_.reset(); | 102 message_loop_.reset(); |
85 } | 103 } |
86 | 104 |
87 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) { | 105 TEST_F(DrmSurfaceTest, CheckFBIDOnSwap) { |
88 surface_->PresentCanvas(gfx::Rect()); | 106 surface_->PresentCanvas(gfx::Rect()); |
89 drm_->RunCallbacks(); | 107 drm_->RunCallbacks(); |
90 // Framebuffer ID 1 is allocated in SetUp for the buffer used to modeset. | 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. |
91 EXPECT_EQ(3u, drm_->current_framebuffer()); | 111 EXPECT_EQ(3u, drm_->current_framebuffer()); |
92 surface_->PresentCanvas(gfx::Rect()); | 112 surface_->PresentCanvas(gfx::Rect()); |
93 drm_->RunCallbacks(); | 113 drm_->RunCallbacks(); |
94 EXPECT_EQ(2u, drm_->current_framebuffer()); | 114 EXPECT_EQ(4u, drm_->current_framebuffer()); |
95 } | 115 } |
96 | 116 |
97 TEST_F(DrmSurfaceTest, CheckSurfaceContents) { | 117 TEST_F(DrmSurfaceTest, CheckSurfaceContents) { |
98 SkPaint paint; | 118 SkPaint paint; |
99 paint.setColor(SK_ColorWHITE); | 119 paint.setColor(SK_ColorWHITE); |
100 SkRect rect = | 120 SkRect rect = |
101 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2); | 121 SkRect::MakeWH(kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2); |
102 surface_->GetSurface()->getCanvas()->drawRect(rect, paint); | 122 surface_->GetSurface()->getCanvas()->drawRect(rect, paint); |
103 surface_->PresentCanvas( | 123 surface_->PresentCanvas( |
104 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); | 124 gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2)); |
105 drm_->RunCallbacks(); | 125 drm_->RunCallbacks(); |
106 | 126 |
107 SkBitmap image; | 127 SkBitmap image; |
108 std::vector<skia::RefPtr<SkSurface>> framebuffers; | 128 std::vector<skia::RefPtr<SkSurface>> framebuffers = |
109 for (const auto& buffer : drm_->buffers()) { | 129 GetFramebuffers(drm_.get()); |
110 // Skip cursor buffers. | |
111 if (buffer->width() == kDefaultCursorSize && | |
112 buffer->height() == kDefaultCursorSize) | |
113 continue; | |
114 | 130 |
115 framebuffers.push_back(buffer); | 131 // Buffer 0 is the modesetting buffer, buffer 2 is the frontbuffer and buffer |
116 } | 132 // 1 is the backbuffer. |
117 | |
118 // Buffer 0 is the modesetting buffer, buffer 1 is the frontbuffer and buffer | |
119 // 2 is the backbuffer. | |
120 EXPECT_EQ(3u, framebuffers.size()); | 133 EXPECT_EQ(3u, framebuffers.size()); |
121 | 134 |
122 image.setInfo(framebuffers[2]->getCanvas()->imageInfo()); | 135 image.setInfo(framebuffers[1]->getCanvas()->imageInfo()); |
123 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0)); | 136 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0)); |
124 | 137 |
125 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); | 138 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); |
126 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); | 139 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); |
127 | 140 |
128 // Make sure the updates are correctly propagated to the native surface. | 141 // Make sure the updates are correctly propagated to the native surface. |
129 for (int i = 0; i < image.height(); ++i) { | 142 for (int i = 0; i < image.height(); ++i) { |
130 for (int j = 0; j < image.width(); ++j) { | 143 for (int j = 0; j < image.width(); ++j) { |
131 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) | 144 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) |
132 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); | 145 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); |
133 else | 146 else |
(...skipping 16 matching lines...) Expand all Loading... |
150 | 163 |
151 paint.setColor(SK_ColorRED); | 164 paint.setColor(SK_ColorRED); |
152 rect.SetRect(0, kDefaultMode.vdisplay / 2, kDefaultMode.hdisplay / 2, | 165 rect.SetRect(0, kDefaultMode.vdisplay / 2, kDefaultMode.hdisplay / 2, |
153 kDefaultMode.vdisplay / 2); | 166 kDefaultMode.vdisplay / 2); |
154 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint); | 167 surface_->GetSurface()->getCanvas()->drawRect(RectToSkRect(rect), paint); |
155 surface_->PresentCanvas(rect); | 168 surface_->PresentCanvas(rect); |
156 | 169 |
157 drm_->RunCallbacks(); | 170 drm_->RunCallbacks(); |
158 | 171 |
159 SkBitmap image; | 172 SkBitmap image; |
160 std::vector<skia::RefPtr<SkSurface>> framebuffers; | 173 std::vector<skia::RefPtr<SkSurface>> framebuffers = |
161 for (const auto& buffer : drm_->buffers()) { | 174 GetFramebuffers(drm_.get()); |
162 // Skip cursor buffers. | |
163 if (buffer->width() == kDefaultCursorSize && | |
164 buffer->height() == kDefaultCursorSize) | |
165 continue; | |
166 | 175 |
167 framebuffers.push_back(buffer); | 176 // Buffer 0 is the modesetting buffer, buffer 2 is the backbuffer and buffer |
168 } | 177 // 1 is the frontbuffer. |
169 | |
170 // Buffer 0 is the modesetting buffer, buffer 1 is the backbuffer and buffer | |
171 // 2 is the frontbuffer. | |
172 EXPECT_EQ(3u, framebuffers.size()); | 178 EXPECT_EQ(3u, framebuffers.size()); |
173 | 179 |
174 image.setInfo(framebuffers[1]->getCanvas()->imageInfo()); | 180 image.setInfo(framebuffers[2]->getCanvas()->imageInfo()); |
175 EXPECT_TRUE(framebuffers[1]->getCanvas()->readPixels(&image, 0, 0)); | 181 EXPECT_TRUE(framebuffers[2]->getCanvas()->readPixels(&image, 0, 0)); |
176 | 182 |
177 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); | 183 EXPECT_EQ(kDefaultMode.hdisplay, image.width()); |
178 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); | 184 EXPECT_EQ(kDefaultMode.vdisplay, image.height()); |
179 | 185 |
180 // Make sure the updates are correctly propagated to the native surface. | 186 // Make sure the updates are correctly propagated to the native surface. |
181 for (int i = 0; i < image.height(); ++i) { | 187 for (int i = 0; i < image.height(); ++i) { |
182 for (int j = 0; j < image.width(); ++j) { | 188 for (int j = 0; j < image.width(); ++j) { |
183 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) | 189 if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2) |
184 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); | 190 EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i)); |
185 else if (j < kDefaultMode.hdisplay / 2) | 191 else if (j < kDefaultMode.hdisplay / 2) |
186 EXPECT_EQ(SK_ColorRED, image.getColor(j, i)); | 192 EXPECT_EQ(SK_ColorRED, image.getColor(j, i)); |
187 else | 193 else |
188 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); | 194 EXPECT_EQ(SK_ColorBLACK, image.getColor(j, i)); |
189 } | 195 } |
190 } | 196 } |
191 } | 197 } |
OLD | NEW |