| 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 "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | 5 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" |
| 6 | 6 |
| 7 #include <xf86drm.h> | 7 #include <xf86drm.h> |
| 8 #include <xf86drmMode.h> | 8 #include <xf86drmMode.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "ui/ozone/platform/dri/crtc_controller.h" | |
| 13 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" | 12 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" |
| 14 | 13 |
| 15 namespace ui { | 14 namespace ui { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 template<class Object> Object* DrmAllocator() { | 18 template<class Object> Object* DrmAllocator() { |
| 20 return static_cast<Object*>(drmMalloc(sizeof(Object))); | 19 return static_cast<Object*>(drmMalloc(sizeof(Object))); |
| 21 } | 20 } |
| 22 | 21 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 planes_.push_back( | 33 planes_.push_back( |
| 35 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx)); | 34 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx)); |
| 36 } | 35 } |
| 37 } | 36 } |
| 38 } | 37 } |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 } // namespace | 40 } // namespace |
| 42 | 41 |
| 43 MockDriWrapper::MockDriWrapper(int fd) | 42 MockDriWrapper::MockDriWrapper(int fd) |
| 44 : DriWrapper(""), | 43 : DriWrapper("", true), |
| 45 get_crtc_call_count_(0), | 44 get_crtc_call_count_(0), |
| 46 set_crtc_call_count_(0), | 45 set_crtc_call_count_(0), |
| 47 restore_crtc_call_count_(0), | 46 restore_crtc_call_count_(0), |
| 48 add_framebuffer_call_count_(0), | 47 add_framebuffer_call_count_(0), |
| 49 remove_framebuffer_call_count_(0), | 48 remove_framebuffer_call_count_(0), |
| 50 page_flip_call_count_(0), | 49 page_flip_call_count_(0), |
| 51 overlay_flip_call_count_(0), | 50 overlay_flip_call_count_(0), |
| 52 handle_events_count_(0), | |
| 53 set_crtc_expectation_(true), | 51 set_crtc_expectation_(true), |
| 54 add_framebuffer_expectation_(true), | 52 add_framebuffer_expectation_(true), |
| 55 page_flip_expectation_(true), | 53 page_flip_expectation_(true), |
| 56 create_dumb_buffer_expectation_(true), | 54 create_dumb_buffer_expectation_(true), |
| 57 current_framebuffer_(0) { | 55 current_framebuffer_(0) { |
| 58 fd_ = fd; | 56 fd_ = fd; |
| 59 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | 57 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); |
| 60 } | 58 } |
| 61 | 59 |
| 62 MockDriWrapper::MockDriWrapper(int fd, | 60 MockDriWrapper::MockDriWrapper(int fd, |
| 61 bool software_mode, |
| 63 std::vector<uint32_t> crtcs, | 62 std::vector<uint32_t> crtcs, |
| 64 size_t planes_per_crtc) | 63 size_t planes_per_crtc) |
| 65 : DriWrapper(""), | 64 : DriWrapper("", software_mode), |
| 66 get_crtc_call_count_(0), | 65 get_crtc_call_count_(0), |
| 67 set_crtc_call_count_(0), | 66 set_crtc_call_count_(0), |
| 68 restore_crtc_call_count_(0), | 67 restore_crtc_call_count_(0), |
| 69 add_framebuffer_call_count_(0), | 68 add_framebuffer_call_count_(0), |
| 70 remove_framebuffer_call_count_(0), | 69 remove_framebuffer_call_count_(0), |
| 71 page_flip_call_count_(0), | 70 page_flip_call_count_(0), |
| 72 overlay_flip_call_count_(0), | 71 overlay_flip_call_count_(0), |
| 73 handle_events_count_(0), | |
| 74 set_crtc_expectation_(true), | 72 set_crtc_expectation_(true), |
| 75 add_framebuffer_expectation_(true), | 73 add_framebuffer_expectation_(true), |
| 76 page_flip_expectation_(true), | 74 page_flip_expectation_(true), |
| 77 create_dumb_buffer_expectation_(true), | 75 create_dumb_buffer_expectation_(true), |
| 78 current_framebuffer_(0) { | 76 current_framebuffer_(0) { |
| 79 fd_ = fd; | 77 fd_ = fd; |
| 80 plane_manager_.reset( | 78 plane_manager_.reset( |
| 81 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc)); | 79 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc)); |
| 82 } | 80 } |
| 83 | 81 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 remove_framebuffer_call_count_++; | 128 remove_framebuffer_call_count_++; |
| 131 return true; | 129 return true; |
| 132 } | 130 } |
| 133 | 131 |
| 134 ScopedDrmFramebufferPtr MockDriWrapper::GetFramebuffer(uint32_t framebuffer) { | 132 ScopedDrmFramebufferPtr MockDriWrapper::GetFramebuffer(uint32_t framebuffer) { |
| 135 return ScopedDrmFramebufferPtr(); | 133 return ScopedDrmFramebufferPtr(); |
| 136 } | 134 } |
| 137 | 135 |
| 138 bool MockDriWrapper::PageFlip(uint32_t crtc_id, | 136 bool MockDriWrapper::PageFlip(uint32_t crtc_id, |
| 139 uint32_t framebuffer, | 137 uint32_t framebuffer, |
| 140 void* data) { | 138 const PageFlipCallback& callback) { |
| 141 page_flip_call_count_++; | 139 page_flip_call_count_++; |
| 142 current_framebuffer_ = framebuffer; | 140 current_framebuffer_ = framebuffer; |
| 143 controllers_.push(static_cast<ui::CrtcController*>(data)); | 141 if (page_flip_expectation_) { |
| 142 if (software_mode_) |
| 143 callback.Run(0, 0, 0); |
| 144 else |
| 145 callbacks_.push(callback); |
| 146 } |
| 147 |
| 144 return page_flip_expectation_; | 148 return page_flip_expectation_; |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, | 151 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, |
| 148 uint32_t framebuffer, | 152 uint32_t framebuffer, |
| 149 const gfx::Rect& location, | 153 const gfx::Rect& location, |
| 150 const gfx::Rect& source, | 154 const gfx::Rect& source, |
| 151 int overlay_plane) { | 155 int overlay_plane) { |
| 152 overlay_flip_call_count_++; | 156 overlay_flip_call_count_++; |
| 153 return true; | 157 return true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 177 bool MockDriWrapper::SetCursor(uint32_t crtc_id, | 181 bool MockDriWrapper::SetCursor(uint32_t crtc_id, |
| 178 uint32_t handle, | 182 uint32_t handle, |
| 179 const gfx::Size& size) { | 183 const gfx::Size& size) { |
| 180 return true; | 184 return true; |
| 181 } | 185 } |
| 182 | 186 |
| 183 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | 187 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { |
| 184 return true; | 188 return true; |
| 185 } | 189 } |
| 186 | 190 |
| 187 void MockDriWrapper::HandleEvent(drmEventContext& event) { | |
| 188 CHECK(!controllers_.empty()); | |
| 189 controllers_.front()->OnPageFlipEvent(0, 0, 0); | |
| 190 controllers_.pop(); | |
| 191 handle_events_count_++; | |
| 192 } | |
| 193 | |
| 194 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, | 191 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, |
| 195 uint32_t* handle, | 192 uint32_t* handle, |
| 196 uint32_t* stride, | 193 uint32_t* stride, |
| 197 void** pixels) { | 194 void** pixels) { |
| 198 if (!create_dumb_buffer_expectation_) | 195 if (!create_dumb_buffer_expectation_) |
| 199 return false; | 196 return false; |
| 200 | 197 |
| 201 *handle = 0; | 198 *handle = 0; |
| 202 *stride = info.minRowBytes(); | 199 *stride = info.minRowBytes(); |
| 203 *pixels = new char[info.getSafeSize(*stride)]; | 200 *pixels = new char[info.getSafeSize(*stride)]; |
| 204 buffers_.push_back( | 201 buffers_.push_back( |
| 205 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); | 202 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); |
| 206 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); | 203 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); |
| 207 | 204 |
| 208 return true; | 205 return true; |
| 209 } | 206 } |
| 210 | 207 |
| 211 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | 208 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, |
| 212 uint32_t handle, | 209 uint32_t handle, |
| 213 uint32_t stride, | 210 uint32_t stride, |
| 214 void* pixels) { | 211 void* pixels) { |
| 215 delete[] static_cast<char*>(pixels); | 212 delete[] static_cast<char*>(pixels); |
| 216 } | 213 } |
| 217 | 214 |
| 215 void MockDriWrapper::RunCallbacks() { |
| 216 while (!callbacks_.empty()) { |
| 217 PageFlipCallback callback = callbacks_.front(); |
| 218 callbacks_.pop(); |
| 219 callback.Run(0, 0, 0); |
| 220 } |
| 221 } |
| 222 |
| 218 } // namespace ui | 223 } // namespace ui |
| OLD | NEW |