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 #ifndef UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRI_WRAPPER_H_ 6 #define UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRI_WRAPPER_H_ 7 8 #include "ui/ozone/platform/dri/dri_wrapper.h" 9 10 namespace ui { 11 12 // The real DriWrapper makes actual DRM calls which we can't use in unit tests. 13 class MockDriWrapper : public ui::DriWrapper { 14 public: 15 MockDriWrapper(int fd); 16 virtual ~MockDriWrapper(); 17 18 int get_get_crtc_call_count() const { return get_crtc_call_count_; } 19 int get_free_crtc_call_count() const { return free_crtc_call_count_; } 20 int get_restore_crtc_call_count() const { return restore_crtc_call_count_; } 21 int get_add_framebuffer_call_count() const { 22 return add_framebuffer_call_count_; 23 } 24 int get_remove_framebuffer_call_count() const { 25 return remove_framebuffer_call_count_; 26 } 27 int get_page_flip_call_count() const { return page_flip_call_count_; } 28 void fail_init() { fd_ = -1; } 29 void set_set_crtc_expectation(bool state) { set_crtc_expectation_ = state; } 30 void set_page_flip_expectation(bool state) { page_flip_expectation_ = state; } 31 void set_add_framebuffer_expectation(bool state) { 32 add_framebuffer_expectation_ = state; 33 } 34 35 // DriWrapper: 36 virtual drmModeCrtc* GetCrtc(uint32_t crtc_id) OVERRIDE; 37 virtual void FreeCrtc(drmModeCrtc* crtc) OVERRIDE; 38 virtual bool SetCrtc(uint32_t crtc_id, 39 uint32_t framebuffer, 40 uint32_t* connectors, 41 drmModeModeInfo* mode) OVERRIDE; 42 virtual bool SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) OVERRIDE; 43 virtual bool AddFramebuffer(uint32_t width, 44 uint32_t height, 45 uint8_t depth, 46 uint8_t bpp, 47 uint32_t stride, 48 uint32_t handle, 49 uint32_t* framebuffer) OVERRIDE; 50 virtual bool RemoveFramebuffer(uint32_t framebuffer) OVERRIDE; 51 virtual bool PageFlip(uint32_t crtc_id, 52 uint32_t framebuffer, 53 void* data) OVERRIDE; 54 virtual bool SetProperty(uint32_t connector_id, 55 uint32_t property_id, 56 uint64_t value) OVERRIDE; 57 virtual void FreeProperty(drmModePropertyRes* prop) OVERRIDE; 58 virtual drmModePropertyBlobRes* GetPropertyBlob(drmModeConnector* connector, 59 const char* name) OVERRIDE; 60 virtual void FreePropertyBlob(drmModePropertyBlobRes* blob) OVERRIDE; 61 virtual bool SetCursor(uint32_t crtc_id, 62 uint32_t handle, 63 uint32_t width, 64 uint32_t height) OVERRIDE; 65 virtual bool MoveCursor(uint32_t crtc_id, int x, int y) OVERRIDE; 66 virtual void HandleEvent(drmEventContext& event) OVERRIDE; 67 68 private: 69 int get_crtc_call_count_; 70 int free_crtc_call_count_; 71 int restore_crtc_call_count_; 72 int add_framebuffer_call_count_; 73 int remove_framebuffer_call_count_; 74 int page_flip_call_count_; 75 76 bool set_crtc_expectation_; 77 bool add_framebuffer_expectation_; 78 bool page_flip_expectation_; 79 80 DISALLOW_COPY_AND_ASSIGN(MockDriWrapper); 81 }; 82 83 } // namespace ui 84 85 #endif // UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRI_WRAPPER_H_ 86