| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "ui/gfx/ozone/dri/dri_skbitmap.h" | 6 #include "ui/gfx/ozone/dri/dri_skbitmap.h" |
| 7 #include "ui/gfx/ozone/dri/dri_surface.h" | 7 #include "ui/gfx/ozone/dri/dri_surface.h" |
| 8 #include "ui/gfx/ozone/dri/dri_wrapper.h" | 8 #include "ui/gfx/ozone/dri/dri_wrapper.h" |
| 9 #include "ui/gfx/ozone/dri/hardware_display_controller.h" | 9 #include "ui/gfx/ozone/dri/hardware_display_controller.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // The real DriWrapper makes actual DRM calls which we can't use in unit tests. | 28 // The real DriWrapper makes actual DRM calls which we can't use in unit tests. |
| 29 class MockDriWrapper : public gfx::DriWrapper { | 29 class MockDriWrapper : public gfx::DriWrapper { |
| 30 public: | 30 public: |
| 31 MockDriWrapper(int fd) : DriWrapper(""), | 31 MockDriWrapper(int fd) : DriWrapper(""), |
| 32 get_crtc_call_count_(0), | 32 get_crtc_call_count_(0), |
| 33 free_crtc_call_count_(0), | 33 free_crtc_call_count_(0), |
| 34 restore_crtc_call_count_(0), | 34 restore_crtc_call_count_(0), |
| 35 add_framebuffer_call_count_(0), | 35 add_framebuffer_call_count_(0), |
| 36 remove_framebuffer_call_count_(0), | 36 remove_framebuffer_call_count_(0), |
| 37 set_crtc_expectation_(true), | 37 set_crtc_expectation_(true), |
| 38 add_framebuffer_expectation_(true), | |
| 39 page_flip_expectation_(true) { | 38 page_flip_expectation_(true) { |
| 40 fd_ = fd; | 39 fd_ = fd; |
| 41 } | 40 } |
| 42 | 41 |
| 43 virtual ~MockDriWrapper() { fd_ = -1; } | 42 virtual ~MockDriWrapper() { fd_ = -1; } |
| 44 | 43 |
| 45 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE { | 44 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE { |
| 46 get_crtc_call_count_++; | 45 get_crtc_call_count_++; |
| 47 return new drmModeCrtc; | 46 return new drmModeCrtc; |
| 48 } | 47 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 return true; | 63 return true; |
| 65 } | 64 } |
| 66 | 65 |
| 67 virtual bool AddFramebuffer(const drmModeModeInfo& mode, | 66 virtual bool AddFramebuffer(const drmModeModeInfo& mode, |
| 68 uint8_t depth, | 67 uint8_t depth, |
| 69 uint8_t bpp, | 68 uint8_t bpp, |
| 70 uint32_t stride, | 69 uint32_t stride, |
| 71 uint32_t handle, | 70 uint32_t handle, |
| 72 uint32_t* framebuffer) OVERRIDE { | 71 uint32_t* framebuffer) OVERRIDE { |
| 73 add_framebuffer_call_count_++; | 72 add_framebuffer_call_count_++; |
| 73 *framebuffer = add_framebuffer_call_count_; |
| 74 return add_framebuffer_expectation_; | 74 return add_framebuffer_expectation_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual bool RemoveFramebuffer(uint32_t framebuffer) OVERRIDE { | 77 virtual bool RemoveFramebuffer(uint32_t framebuffer) OVERRIDE { |
| 78 remove_framebuffer_call_count_++; | 78 remove_framebuffer_call_count_++; |
| 79 return true; | 79 return framebuffer != 0; |
| 80 } | 80 } |
| 81 | 81 |
| 82 virtual bool PageFlip(uint32_t crtc_id, | 82 virtual bool PageFlip(uint32_t crtc_id, |
| 83 uint32_t framebuffer, | 83 uint32_t framebuffer, |
| 84 void* data) OVERRIDE { | 84 void* data) OVERRIDE { |
| 85 return page_flip_expectation_; | 85 return page_flip_expectation_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual bool ConnectorSetProperty(uint32_t connector_id, | 88 virtual bool ConnectorSetProperty(uint32_t connector_id, |
| 89 uint32_t property_id, | 89 uint32_t property_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 int get_remove_framebuffer_call_count() const { | 108 int get_remove_framebuffer_call_count() const { |
| 109 return remove_framebuffer_call_count_; | 109 return remove_framebuffer_call_count_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void set_set_crtc_expectation(bool state) { | 112 void set_set_crtc_expectation(bool state) { |
| 113 set_crtc_expectation_ = state; | 113 set_crtc_expectation_ = state; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void set_add_framebuffer_expectation(bool state) { | |
| 117 add_framebuffer_expectation_ = state; | |
| 118 } | |
| 119 | |
| 120 void set_page_flip_expectation(bool state) { | 116 void set_page_flip_expectation(bool state) { |
| 121 page_flip_expectation_ = state; | 117 page_flip_expectation_ = state; |
| 122 } | 118 } |
| 123 | 119 |
| 124 private: | 120 private: |
| 125 int get_crtc_call_count_; | 121 int get_crtc_call_count_; |
| 126 int free_crtc_call_count_; | 122 int free_crtc_call_count_; |
| 127 int restore_crtc_call_count_; | 123 int restore_crtc_call_count_; |
| 128 int add_framebuffer_call_count_; | 124 int add_framebuffer_call_count_; |
| 129 int remove_framebuffer_call_count_; | 125 int remove_framebuffer_call_count_; |
| 130 | 126 |
| 131 bool set_crtc_expectation_; | 127 bool set_crtc_expectation_; |
| 132 bool add_framebuffer_expectation_; | |
| 133 bool page_flip_expectation_; | 128 bool page_flip_expectation_; |
| 134 | 129 |
| 135 DISALLOW_COPY_AND_ASSIGN(MockDriWrapper); | 130 DISALLOW_COPY_AND_ASSIGN(MockDriWrapper); |
| 136 }; | 131 }; |
| 137 | 132 |
| 138 class MockDriSkBitmap : public gfx::DriSkBitmap { | 133 class MockDriSkBitmap : public gfx::DriSkBitmap { |
| 139 public: | 134 public: |
| 140 MockDriSkBitmap(int fd) : DriSkBitmap(fd) {} | 135 MockDriSkBitmap(int fd) : DriSkBitmap(fd) {} |
| 141 virtual ~MockDriSkBitmap() {} | 136 virtual ~MockDriSkBitmap() {} |
| 142 | 137 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 TEST_F(HardwareDisplayControllerTest, | 190 TEST_F(HardwareDisplayControllerTest, |
| 196 CheckStateAfterControllerIsInitialized) { | 191 CheckStateAfterControllerIsInitialized) { |
| 197 controller_->SetControllerInfo( | 192 controller_->SetControllerInfo( |
| 198 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 193 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 199 | 194 |
| 200 EXPECT_EQ(1, drm_->get_get_crtc_call_count()); | 195 EXPECT_EQ(1, drm_->get_get_crtc_call_count()); |
| 201 EXPECT_EQ(gfx::HardwareDisplayController::UNINITIALIZED, | 196 EXPECT_EQ(gfx::HardwareDisplayController::UNINITIALIZED, |
| 202 controller_->get_state()); | 197 controller_->get_state()); |
| 203 } | 198 } |
| 204 | 199 |
| 200 TEST_F(HardwareDisplayControllerTest, CheckStateAfterAddFramebufferFails) { |
| 201 controller_->SetControllerInfo( |
| 202 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 203 |
| 204 drm_->set_add_framebuffer_expectation(false); |
| 205 uint32_t framebuffer = 0; |
| 206 EXPECT_FALSE(controller_->AddFramebuffer(24, 32, 100, 1, &framebuffer)); |
| 207 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, |
| 208 controller_->get_state()); |
| 209 } |
| 210 |
| 211 TEST_F(HardwareDisplayControllerTest, CheckReturnOfInvalidRemoveFramebuffer) { |
| 212 controller_->SetControllerInfo( |
| 213 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 214 |
| 215 EXPECT_FALSE(controller_->RemoveFramebuffer(0)); |
| 216 } |
| 217 |
| 205 TEST_F(HardwareDisplayControllerTest, CheckStateAfterSurfaceIsBound) { | 218 TEST_F(HardwareDisplayControllerTest, CheckStateAfterSurfaceIsBound) { |
| 206 controller_->SetControllerInfo( | 219 controller_->SetControllerInfo( |
| 207 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 220 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 208 scoped_ptr<gfx::DriSurface> surface( | 221 scoped_ptr<gfx::ScanoutSurface> surface( |
| 209 new MockDriSurface(controller_.get())); | 222 new MockDriSurface(controller_.get())); |
| 210 | 223 |
| 211 EXPECT_TRUE(surface->Initialize()); | 224 EXPECT_TRUE(surface->Initialize()); |
| 212 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); | 225 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); |
| 213 | 226 |
| 214 EXPECT_EQ(2, drm_->get_add_framebuffer_call_count()); | 227 EXPECT_EQ(2, drm_->get_add_framebuffer_call_count()); |
| 215 EXPECT_EQ(gfx::HardwareDisplayController::SURFACE_INITIALIZED, | 228 EXPECT_EQ(gfx::HardwareDisplayController::SURFACE_INITIALIZED, |
| 216 controller_->get_state()); | 229 controller_->get_state()); |
| 217 } | 230 } |
| 218 | 231 |
| 219 TEST_F(HardwareDisplayControllerTest, CheckStateIfBindingFails) { | 232 TEST_F(HardwareDisplayControllerTest, CheckStateAfterPageFlip) { |
| 220 drm_->set_add_framebuffer_expectation(false); | |
| 221 | |
| 222 controller_->SetControllerInfo( | 233 controller_->SetControllerInfo( |
| 223 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 234 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 224 scoped_ptr<gfx::DriSurface> surface( | 235 scoped_ptr<gfx::ScanoutSurface> surface( |
| 225 new MockDriSurface(controller_.get())); | 236 new MockDriSurface(controller_.get())); |
| 226 | 237 |
| 227 EXPECT_TRUE(surface->Initialize()); | 238 EXPECT_TRUE(surface->Initialize()); |
| 228 EXPECT_FALSE(controller_->BindSurfaceToController(surface.Pass())); | |
| 229 | |
| 230 EXPECT_EQ(1, drm_->get_add_framebuffer_call_count()); | |
| 231 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, | |
| 232 controller_->get_state()); | |
| 233 } | |
| 234 | |
| 235 TEST_F(HardwareDisplayControllerTest, CheckStateAfterPageFlip) { | |
| 236 controller_->SetControllerInfo( | |
| 237 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | |
| 238 scoped_ptr<gfx::DriSurface> surface( | |
| 239 new MockDriSurface(controller_.get())); | |
| 240 | |
| 241 EXPECT_TRUE(surface->Initialize()); | |
| 242 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); | 239 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); |
| 243 | 240 |
| 244 controller_->SchedulePageFlip(); | 241 controller_->SchedulePageFlip(); |
| 245 | 242 |
| 246 EXPECT_EQ(gfx::HardwareDisplayController::INITIALIZED, | 243 EXPECT_EQ(gfx::HardwareDisplayController::INITIALIZED, |
| 247 controller_->get_state()); | 244 controller_->get_state()); |
| 248 } | 245 } |
| 249 | 246 |
| 250 TEST_F(HardwareDisplayControllerTest, CheckStateIfModesetFails) { | 247 TEST_F(HardwareDisplayControllerTest, CheckStateIfModesetFails) { |
| 251 drm_->set_set_crtc_expectation(false); | 248 drm_->set_set_crtc_expectation(false); |
| 252 | 249 |
| 253 controller_->SetControllerInfo( | 250 controller_->SetControllerInfo( |
| 254 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 251 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 255 scoped_ptr<gfx::DriSurface> surface( | 252 scoped_ptr<gfx::ScanoutSurface> surface( |
| 256 new MockDriSurface(controller_.get())); | 253 new MockDriSurface(controller_.get())); |
| 257 | 254 |
| 258 EXPECT_TRUE(surface->Initialize()); | 255 EXPECT_TRUE(surface->Initialize()); |
| 259 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); | 256 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); |
| 260 | 257 |
| 261 controller_->SchedulePageFlip(); | 258 controller_->SchedulePageFlip(); |
| 262 | 259 |
| 263 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, | 260 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, |
| 264 controller_->get_state()); | 261 controller_->get_state()); |
| 265 } | 262 } |
| 266 | 263 |
| 267 TEST_F(HardwareDisplayControllerTest, CheckStateIfPageFlipFails) { | 264 TEST_F(HardwareDisplayControllerTest, CheckStateIfPageFlipFails) { |
| 268 drm_->set_page_flip_expectation(false); | 265 drm_->set_page_flip_expectation(false); |
| 269 | 266 |
| 270 controller_->SetControllerInfo( | 267 controller_->SetControllerInfo( |
| 271 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 268 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 272 scoped_ptr<gfx::DriSurface> surface( | 269 scoped_ptr<gfx::ScanoutSurface> surface( |
| 273 new MockDriSurface(controller_.get())); | 270 new MockDriSurface(controller_.get())); |
| 274 | 271 |
| 275 EXPECT_TRUE(surface->Initialize()); | 272 EXPECT_TRUE(surface->Initialize()); |
| 276 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); | 273 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); |
| 277 | 274 |
| 278 controller_->SchedulePageFlip(); | 275 controller_->SchedulePageFlip(); |
| 279 | 276 |
| 280 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, | 277 EXPECT_EQ(gfx::HardwareDisplayController::FAILED, |
| 281 controller_->get_state()); | 278 controller_->get_state()); |
| 282 } | 279 } |
| 283 | 280 |
| 284 TEST_F(HardwareDisplayControllerTest, CheckProperDestruction) { | 281 TEST_F(HardwareDisplayControllerTest, CheckProperDestruction) { |
| 285 controller_->SetControllerInfo( | 282 controller_->SetControllerInfo( |
| 286 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); | 283 drm_.get(), kConnectorId, kCrtcId, kDPMSPropertyId, kDefaultMode); |
| 287 scoped_ptr<gfx::DriSurface> surface( | 284 scoped_ptr<gfx::ScanoutSurface> surface( |
| 288 new MockDriSurface(controller_.get())); | 285 new MockDriSurface(controller_.get())); |
| 289 | 286 |
| 290 EXPECT_TRUE(surface->Initialize()); | 287 EXPECT_TRUE(surface->Initialize()); |
| 291 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); | 288 EXPECT_TRUE(controller_->BindSurfaceToController(surface.Pass())); |
| 292 | 289 |
| 293 EXPECT_EQ(gfx::HardwareDisplayController::SURFACE_INITIALIZED, | 290 EXPECT_EQ(gfx::HardwareDisplayController::SURFACE_INITIALIZED, |
| 294 controller_->get_state()); | 291 controller_->get_state()); |
| 295 | 292 |
| 296 controller_.reset(); | 293 controller_.reset(); |
| 297 | 294 |
| 298 EXPECT_EQ(2, drm_->get_remove_framebuffer_call_count()); | 295 EXPECT_EQ(2, drm_->get_remove_framebuffer_call_count()); |
| 299 EXPECT_EQ(1, drm_->get_restore_crtc_call_count()); | 296 EXPECT_EQ(1, drm_->get_restore_crtc_call_count()); |
| 300 EXPECT_EQ(1, drm_->get_free_crtc_call_count()); | 297 EXPECT_EQ(1, drm_->get_free_crtc_call_count()); |
| 301 } | 298 } |
| OLD | NEW |