| OLD | NEW |
| (Empty) |
| 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 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | |
| 6 | |
| 7 #include <xf86drm.h> | |
| 8 #include <xf86drmMode.h> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | |
| 12 #include "ui/ozone/platform/dri/crtc_controller.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 template<class Object> Object* DrmAllocator() { | |
| 19 return static_cast<Object*>(drmMalloc(sizeof(Object))); | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 MockDriWrapper::MockDriWrapper(int fd) | |
| 25 : DriWrapper(""), | |
| 26 get_crtc_call_count_(0), | |
| 27 set_crtc_call_count_(0), | |
| 28 restore_crtc_call_count_(0), | |
| 29 add_framebuffer_call_count_(0), | |
| 30 remove_framebuffer_call_count_(0), | |
| 31 page_flip_call_count_(0), | |
| 32 overlay_flip_call_count_(0), | |
| 33 handle_events_count_(0), | |
| 34 set_crtc_expectation_(true), | |
| 35 add_framebuffer_expectation_(true), | |
| 36 page_flip_expectation_(true), | |
| 37 create_dumb_buffer_expectation_(true), | |
| 38 current_framebuffer_(0) { | |
| 39 fd_ = fd; | |
| 40 } | |
| 41 | |
| 42 MockDriWrapper::~MockDriWrapper() { | |
| 43 fd_ = -1; | |
| 44 } | |
| 45 | |
| 46 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) { | |
| 47 get_crtc_call_count_++; | |
| 48 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); | |
| 49 } | |
| 50 | |
| 51 bool MockDriWrapper::SetCrtc(uint32_t crtc_id, | |
| 52 uint32_t framebuffer, | |
| 53 std::vector<uint32_t> connectors, | |
| 54 drmModeModeInfo* mode) { | |
| 55 current_framebuffer_ = framebuffer; | |
| 56 set_crtc_call_count_++; | |
| 57 return set_crtc_expectation_; | |
| 58 } | |
| 59 | |
| 60 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, | |
| 61 std::vector<uint32_t> connectors) { | |
| 62 restore_crtc_call_count_++; | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) { | |
| 67 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>()); | |
| 68 } | |
| 69 | |
| 70 bool MockDriWrapper::AddFramebuffer(uint32_t width, | |
| 71 uint32_t height, | |
| 72 uint8_t depth, | |
| 73 uint8_t bpp, | |
| 74 uint32_t stride, | |
| 75 uint32_t handle, | |
| 76 uint32_t* framebuffer) { | |
| 77 add_framebuffer_call_count_++; | |
| 78 *framebuffer = add_framebuffer_call_count_; | |
| 79 return add_framebuffer_expectation_; | |
| 80 } | |
| 81 | |
| 82 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | |
| 83 remove_framebuffer_call_count_++; | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 bool MockDriWrapper::PageFlip(uint32_t crtc_id, | |
| 88 uint32_t framebuffer, | |
| 89 void* data) { | |
| 90 page_flip_call_count_++; | |
| 91 current_framebuffer_ = framebuffer; | |
| 92 controllers_.push(static_cast<ui::CrtcController*>(data)); | |
| 93 return page_flip_expectation_; | |
| 94 } | |
| 95 | |
| 96 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, | |
| 97 uint32_t framebuffer, | |
| 98 const gfx::Rect& location, | |
| 99 const gfx::RectF& source, | |
| 100 int overlay_plane) { | |
| 101 overlay_flip_call_count_++; | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 ScopedDrmPropertyPtr MockDriWrapper::GetProperty(drmModeConnector* connector, | |
| 106 const char* name) { | |
| 107 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>()); | |
| 108 } | |
| 109 | |
| 110 bool MockDriWrapper::SetProperty(uint32_t connector_id, | |
| 111 uint32_t property_id, | |
| 112 uint64_t value) { | |
| 113 return true; | |
| 114 } | |
| 115 | |
| 116 ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob( | |
| 117 drmModeConnector* connector, | |
| 118 const char* name) { | |
| 119 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>()); | |
| 120 } | |
| 121 | |
| 122 bool MockDriWrapper::SetCursor(uint32_t crtc_id, | |
| 123 uint32_t handle, | |
| 124 const gfx::Size& size) { | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | |
| 129 return true; | |
| 130 } | |
| 131 | |
| 132 void MockDriWrapper::HandleEvent(drmEventContext& event) { | |
| 133 CHECK(!controllers_.empty()); | |
| 134 controllers_.front()->OnPageFlipEvent(0, 0, 0); | |
| 135 controllers_.pop(); | |
| 136 handle_events_count_++; | |
| 137 } | |
| 138 | |
| 139 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, | |
| 140 uint32_t* handle, | |
| 141 uint32_t* stride, | |
| 142 void** pixels) { | |
| 143 if (!create_dumb_buffer_expectation_) | |
| 144 return false; | |
| 145 | |
| 146 *handle = 0; | |
| 147 *stride = info.minRowBytes(); | |
| 148 *pixels = new char[info.getSafeSize(*stride)]; | |
| 149 buffers_.push_back( | |
| 150 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); | |
| 151 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); | |
| 152 | |
| 153 return true; | |
| 154 } | |
| 155 | |
| 156 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | |
| 157 uint32_t handle, | |
| 158 uint32_t stride, | |
| 159 void* pixels) { | |
| 160 delete[] static_cast<char*>(pixels); | |
| 161 } | |
| 162 | |
| 163 } // namespace ui | |
| OLD | NEW |