| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 class DrmWindowTest : public testing::Test { | 57 class DrmWindowTest : public testing::Test { |
| 58 public: | 58 public: |
| 59 DrmWindowTest() {} | 59 DrmWindowTest() {} |
| 60 | 60 |
| 61 void SetUp() override; | 61 void SetUp() override; |
| 62 void TearDown() override; | 62 void TearDown() override; |
| 63 | 63 |
| 64 void OnSwapBuffers(gfx::SwapResult result) { |
| 65 on_swap_buffers_count_++; |
| 66 last_swap_buffers_result_ = result; |
| 67 } |
| 68 |
| 64 protected: | 69 protected: |
| 65 scoped_ptr<base::MessageLoop> message_loop_; | 70 scoped_ptr<base::MessageLoop> message_loop_; |
| 66 scoped_refptr<ui::MockDrmDevice> drm_; | 71 scoped_refptr<ui::MockDrmDevice> drm_; |
| 67 scoped_ptr<ui::MockBufferGenerator> buffer_generator_; | 72 scoped_ptr<ui::MockBufferGenerator> buffer_generator_; |
| 68 scoped_ptr<ui::ScreenManager> screen_manager_; | 73 scoped_ptr<ui::ScreenManager> screen_manager_; |
| 69 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_; | 74 scoped_ptr<ui::DrmDeviceManager> drm_device_manager_; |
| 70 | 75 |
| 76 int on_swap_buffers_count_; |
| 77 gfx::SwapResult last_swap_buffers_result_; |
| 78 |
| 71 private: | 79 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(DrmWindowTest); | 80 DISALLOW_COPY_AND_ASSIGN(DrmWindowTest); |
| 73 }; | 81 }; |
| 74 | 82 |
| 75 void DrmWindowTest::SetUp() { | 83 void DrmWindowTest::SetUp() { |
| 84 on_swap_buffers_count_ = 0; |
| 85 last_swap_buffers_result_ = gfx::SwapResult::SWAP_FAILED; |
| 86 |
| 76 message_loop_.reset(new base::MessageLoopForUI); | 87 message_loop_.reset(new base::MessageLoopForUI); |
| 77 drm_ = new ui::MockDrmDevice(); | 88 drm_ = new ui::MockDrmDevice(); |
| 78 buffer_generator_.reset(new ui::MockBufferGenerator()); | 89 buffer_generator_.reset(new ui::MockBufferGenerator()); |
| 79 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get())); | 90 screen_manager_.reset(new ui::ScreenManager(buffer_generator_.get())); |
| 80 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector); | 91 screen_manager_->AddDisplayController(drm_, kDefaultCrtc, kDefaultConnector); |
| 81 screen_manager_->ConfigureDisplayController( | 92 screen_manager_->ConfigureDisplayController( |
| 82 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode); | 93 drm_, kDefaultCrtc, kDefaultConnector, gfx::Point(), kDefaultMode); |
| 83 | 94 |
| 84 drm_device_manager_.reset(new ui::DrmDeviceManager(nullptr)); | 95 drm_device_manager_.reset(new ui::DrmDeviceManager(nullptr)); |
| 85 | 96 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 150 |
| 140 // Move window to the display on the new device. | 151 // Move window to the display on the new device. |
| 141 screen_manager_->GetWindow(kDefaultWidgetHandle) | 152 screen_manager_->GetWindow(kDefaultWidgetHandle) |
| 142 ->SetBounds(gfx::Rect(0, kDefaultMode.vdisplay, kDefaultMode.hdisplay, | 153 ->SetBounds(gfx::Rect(0, kDefaultMode.vdisplay, kDefaultMode.hdisplay, |
| 143 kDefaultMode.vdisplay)); | 154 kDefaultMode.vdisplay)); |
| 144 | 155 |
| 145 EXPECT_EQ(2u, GetCursorBuffers(drm).size()); | 156 EXPECT_EQ(2u, GetCursorBuffers(drm).size()); |
| 146 // Make sure the cursor is showing on the new display. | 157 // Make sure the cursor is showing on the new display. |
| 147 EXPECT_NE(0u, drm->get_cursor_handle_for_crtc(kDefaultCrtc)); | 158 EXPECT_NE(0u, drm->get_cursor_handle_for_crtc(kDefaultCrtc)); |
| 148 } | 159 } |
| 160 |
| 161 TEST_F(DrmWindowTest, CheckCallbackOnFailedSwap) { |
| 162 const gfx::Size window_size(6, 4); |
| 163 ui::MockBufferGenerator buffer_generator; |
| 164 ui::DrmWindow* window = screen_manager_->GetWindow(kDefaultWidgetHandle); |
| 165 ui::OverlayPlane plane( |
| 166 buffer_generator.Create(drm_, gfx::BufferFormat::BGRX_8888, window_size)); |
| 167 |
| 168 drm_->set_page_flip_expectation(false); |
| 169 |
| 170 // Window was re-sized, so the expectation is to re-create the buffers first. |
| 171 window->SchedulePageFlip( |
| 172 std::vector<ui::OverlayPlane>(1, ui::OverlayPlane(plane)), |
| 173 base::Bind(&DrmWindowTest::OnSwapBuffers, base::Unretained(this))); |
| 174 EXPECT_EQ(1, on_swap_buffers_count_); |
| 175 EXPECT_EQ(gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS, |
| 176 last_swap_buffers_result_); |
| 177 |
| 178 window->SchedulePageFlip( |
| 179 std::vector<ui::OverlayPlane>(1, ui::OverlayPlane(plane)), |
| 180 base::Bind(&DrmWindowTest::OnSwapBuffers, base::Unretained(this))); |
| 181 EXPECT_EQ(2, on_swap_buffers_count_); |
| 182 EXPECT_EQ(gfx::SwapResult::SWAP_FAILED, last_swap_buffers_result_); |
| 183 } |
| OLD | NEW |