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 <queue> 9 #include <vector> 10 11 #include "skia/ext/refptr.h" 12 #include "third_party/skia/include/core/SkSurface.h" 13 #include "ui/ozone/platform/dri/dri_wrapper.h" 14 15 namespace ui { 16 17 class HardwareDisplayController; 18 19 // The real DriWrapper makes actual DRM calls which we can't use in unit tests. 20 class MockDriWrapper : public ui::DriWrapper { 21 public: 22 MockDriWrapper(int fd); 23 virtual ~MockDriWrapper(); 24 25 int get_get_crtc_call_count() const { return get_crtc_call_count_; } 26 int get_set_crtc_call_count() const { return set_crtc_call_count_; } 27 int get_restore_crtc_call_count() const { return restore_crtc_call_count_; } 28 int get_add_framebuffer_call_count() const { 29 return add_framebuffer_call_count_; 30 } 31 int get_remove_framebuffer_call_count() const { 32 return remove_framebuffer_call_count_; 33 } 34 int get_page_flip_call_count() const { return page_flip_call_count_; } 35 int get_overlay_flip_call_count() const { return overlay_flip_call_count_; } 36 void fail_init() { fd_ = -1; } 37 void set_set_crtc_expectation(bool state) { set_crtc_expectation_ = state; } 38 void set_page_flip_expectation(bool state) { page_flip_expectation_ = state; } 39 void set_add_framebuffer_expectation(bool state) { 40 add_framebuffer_expectation_ = state; 41 } 42 void set_create_dumb_buffer_expectation(bool state) { 43 create_dumb_buffer_expectation_ = state; 44 } 45 46 uint32_t current_framebuffer() const { return current_framebuffer_; } 47 48 const std::vector<skia::RefPtr<SkSurface> > buffers() const { 49 return buffers_; 50 } 51 52 // DriWrapper: 53 virtual ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id) OVERRIDE; 54 virtual bool SetCrtc(uint32_t crtc_id, 55 uint32_t framebuffer, 56 std::vector<uint32_t> connectors, 57 drmModeModeInfo* mode) OVERRIDE; 58 virtual bool SetCrtc(drmModeCrtc* crtc, 59 std::vector<uint32_t> connectors) OVERRIDE; 60 virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id) OVERRIDE; 61 virtual bool AddFramebuffer(uint32_t width, 62 uint32_t height, 63 uint8_t depth, 64 uint8_t bpp, 65 uint32_t stride, 66 uint32_t handle, 67 uint32_t* framebuffer) OVERRIDE; 68 virtual bool RemoveFramebuffer(uint32_t framebuffer) OVERRIDE; 69 virtual bool PageFlip(uint32_t crtc_id, 70 uint32_t framebuffer, 71 void* data) OVERRIDE; 72 virtual bool PageFlipOverlay(uint32_t crtc_id, 73 uint32_t framebuffer, 74 const gfx::Rect& location, 75 const gfx::RectF& source, 76 int overlay_plane) OVERRIDE; 77 virtual ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector, 78 const char* name) OVERRIDE; 79 virtual bool SetProperty(uint32_t connector_id, 80 uint32_t property_id, 81 uint64_t value) OVERRIDE; 82 virtual ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector, 83 const char* name) OVERRIDE; 84 virtual bool SetCursor(uint32_t crtc_id, 85 uint32_t handle, 86 const gfx::Size& size) OVERRIDE; 87 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point) OVERRIDE; 88 virtual void HandleEvent(drmEventContext& event) OVERRIDE; 89 virtual bool CreateDumbBuffer(const SkImageInfo& info, 90 uint32_t* handle, 91 uint32_t* stride, 92 void** pixels) OVERRIDE; 93 virtual void DestroyDumbBuffer(const SkImageInfo& info, 94 uint32_t handle, 95 uint32_t stride, 96 void* pixels) OVERRIDE; 97 98 private: 99 int get_crtc_call_count_; 100 int set_crtc_call_count_; 101 int restore_crtc_call_count_; 102 int add_framebuffer_call_count_; 103 int remove_framebuffer_call_count_; 104 int page_flip_call_count_; 105 int overlay_flip_call_count_; 106 107 bool set_crtc_expectation_; 108 bool add_framebuffer_expectation_; 109 bool page_flip_expectation_; 110 bool create_dumb_buffer_expectation_; 111 112 uint32_t current_framebuffer_; 113 114 std::vector<skia::RefPtr<SkSurface> > buffers_; 115 116 std::queue<HardwareDisplayController*> controllers_; 117 118 DISALLOW_COPY_AND_ASSIGN(MockDriWrapper); 119 }; 120 121 } // namespace ui 122 123 #endif // UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRI_WRAPPER_H_ 124