| 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 "third_party/skia/include/core/SkCanvas.h" |   10 #include "third_party/skia/include/core/SkCanvas.h" | 
|   11 #include "ui/ozone/platform/dri/dri_surface.h" |  | 
|   12 #include "ui/ozone/platform/dri/hardware_display_controller.h" |   11 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 
|   13  |   12  | 
|   14 namespace ui { |   13 namespace ui { | 
|   15  |   14  | 
|   16 namespace { |   15 namespace { | 
|   17  |   16  | 
|   18 template<class Object> Object* DrmAllocator() { |   17 template<class Object> Object* DrmAllocator() { | 
|   19   return static_cast<Object*>(drmMalloc(sizeof(Object))); |   18   return static_cast<Object*>(drmMalloc(sizeof(Object))); | 
|   20 } |   19 } | 
|   21  |   20  | 
|   22 }  // namespace |   21 }  // namespace | 
|   23  |   22  | 
|   24 MockDriWrapper::MockDriWrapper(int fd) |   23 MockDriWrapper::MockDriWrapper(int fd) | 
|   25     : DriWrapper(""), |   24     : DriWrapper(""), | 
|   26       get_crtc_call_count_(0), |   25       get_crtc_call_count_(0), | 
|   27       restore_crtc_call_count_(0), |   26       restore_crtc_call_count_(0), | 
|   28       add_framebuffer_call_count_(0), |   27       add_framebuffer_call_count_(0), | 
|   29       remove_framebuffer_call_count_(0), |   28       remove_framebuffer_call_count_(0), | 
|   30       page_flip_call_count_(0), |   29       page_flip_call_count_(0), | 
|   31       overlay_flip_call_count_(0), |   30       overlay_flip_call_count_(0), | 
|   32       set_crtc_expectation_(true), |   31       set_crtc_expectation_(true), | 
|   33       add_framebuffer_expectation_(true), |   32       add_framebuffer_expectation_(true), | 
|   34       page_flip_expectation_(true), |   33       page_flip_expectation_(true), | 
|   35       create_dumb_buffer_expectation_(true) { |   34       create_dumb_buffer_expectation_(true), | 
 |   35       current_framebuffer_(0), | 
 |   36       controller_(NULL) { | 
|   36   fd_ = fd; |   37   fd_ = fd; | 
|   37 } |   38 } | 
|   38  |   39  | 
|   39 MockDriWrapper::~MockDriWrapper() { |   40 MockDriWrapper::~MockDriWrapper() { | 
|   40   fd_ = -1; |   41   fd_ = -1; | 
|   41 } |   42 } | 
|   42  |   43  | 
|   43 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) { |   44 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) { | 
|   44   get_crtc_call_count_++; |   45   get_crtc_call_count_++; | 
|   45   return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); |   46   return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); | 
|   46 } |   47 } | 
|   47  |   48  | 
|   48 bool MockDriWrapper::SetCrtc(uint32_t crtc_id, |   49 bool MockDriWrapper::SetCrtc(uint32_t crtc_id, | 
|   49                              uint32_t framebuffer, |   50                              uint32_t framebuffer, | 
|   50                              uint32_t* connectors, |   51                              uint32_t* connectors, | 
|   51                              drmModeModeInfo* mode) { |   52                              drmModeModeInfo* mode) { | 
 |   53   current_framebuffer_ = framebuffer; | 
|   52   return set_crtc_expectation_; |   54   return set_crtc_expectation_; | 
|   53 } |   55 } | 
|   54  |   56  | 
|   55 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) { |   57 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, uint32_t* connectors) { | 
|   56   restore_crtc_call_count_++; |   58   restore_crtc_call_count_++; | 
|   57   return true; |   59   return true; | 
|   58 } |   60 } | 
|   59  |   61  | 
|   60 bool MockDriWrapper::AddFramebuffer(uint32_t width, |   62 bool MockDriWrapper::AddFramebuffer(uint32_t width, | 
|   61                                     uint32_t height, |   63                                     uint32_t height, | 
|   62                                     uint8_t depth, |   64                                     uint8_t depth, | 
|   63                                     uint8_t bpp, |   65                                     uint8_t bpp, | 
|   64                                     uint32_t stride, |   66                                     uint32_t stride, | 
|   65                                     uint32_t handle, |   67                                     uint32_t handle, | 
|   66                                     uint32_t* framebuffer) { |   68                                     uint32_t* framebuffer) { | 
|   67   add_framebuffer_call_count_++; |   69   add_framebuffer_call_count_++; | 
|   68   *framebuffer = add_framebuffer_call_count_; |   70   *framebuffer = add_framebuffer_call_count_; | 
|   69   return add_framebuffer_expectation_; |   71   return add_framebuffer_expectation_; | 
|   70 } |   72 } | 
|   71  |   73  | 
|   72 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) { |   74 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | 
|   73   remove_framebuffer_call_count_++; |   75   remove_framebuffer_call_count_++; | 
|   74   return true; |   76   return true; | 
|   75 } |   77 } | 
|   76  |   78  | 
|   77 bool MockDriWrapper::PageFlip(uint32_t crtc_id, |   79 bool MockDriWrapper::PageFlip(uint32_t crtc_id, | 
|   78                               uint32_t framebuffer, |   80                               uint32_t framebuffer, | 
|   79                               void* data) { |   81                               void* data) { | 
|   80   page_flip_call_count_++; |   82   page_flip_call_count_++; | 
|   81   static_cast<ui::HardwareDisplayController*>(data)->surface()->SwapBuffers(); |   83   current_framebuffer_ = framebuffer; | 
 |   84   controller_ = static_cast<ui::HardwareDisplayController*>(data); | 
|   82   return page_flip_expectation_; |   85   return page_flip_expectation_; | 
|   83 } |   86 } | 
|   84  |   87  | 
|   85 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, |   88 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, | 
|   86                                      uint32_t framebuffer, |   89                                      uint32_t framebuffer, | 
|   87                                      const gfx::Rect& location, |   90                                      const gfx::Rect& location, | 
|   88                                      const gfx::RectF& source, |   91                                      const gfx::RectF& source, | 
|   89                                      int overlay_plane) { |   92                                      int overlay_plane) { | 
|   90   overlay_flip_call_count_++; |   93   overlay_flip_call_count_++; | 
|   91   return true; |   94   return true; | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  112                                uint32_t handle, |  115                                uint32_t handle, | 
|  113                                const gfx::Size& size) { |  116                                const gfx::Size& size) { | 
|  114   return true; |  117   return true; | 
|  115 } |  118 } | 
|  116  |  119  | 
|  117 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { |  120 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | 
|  118   return true; |  121   return true; | 
|  119 } |  122 } | 
|  120  |  123  | 
|  121 void MockDriWrapper::HandleEvent(drmEventContext& event) { |  124 void MockDriWrapper::HandleEvent(drmEventContext& event) { | 
 |  125   if (controller_) | 
 |  126     controller_->OnPageFlipEvent(0, 0, 0); | 
|  122 } |  127 } | 
|  123  |  128  | 
|  124 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, |  129 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, | 
|  125                                       uint32_t* handle, |  130                                       uint32_t* handle, | 
|  126                                       uint32_t* stride, |  131                                       uint32_t* stride, | 
|  127                                       void** pixels) { |  132                                       void** pixels) { | 
|  128   if (!create_dumb_buffer_expectation_) |  133   if (!create_dumb_buffer_expectation_) | 
|  129     return false; |  134     return false; | 
|  130  |  135  | 
|  131   *handle = 0; |  136   *handle = 0; | 
|  132   *stride = info.minRowBytes(); |  137   *stride = info.minRowBytes(); | 
|  133   *pixels = new char[info.getSafeSize(*stride)]; |  138   *pixels = new char[info.getSafeSize(*stride)]; | 
|  134   buffers_.push_back( |  139   buffers_.push_back( | 
|  135       skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); |  140       skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); | 
|  136   buffers_.back()->getCanvas()->clear(SK_ColorBLACK); |  141   buffers_.back()->getCanvas()->clear(SK_ColorBLACK); | 
|  137  |  142  | 
|  138   return true; |  143   return true; | 
|  139 } |  144 } | 
|  140  |  145  | 
|  141 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, |  146 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | 
|  142                                        uint32_t handle, |  147                                        uint32_t handle, | 
|  143                                        uint32_t stride, |  148                                        uint32_t stride, | 
|  144                                        void* pixels) { |  149                                        void* pixels) { | 
|  145   delete[] static_cast<char*>(pixels); |  150   delete[] static_cast<char*>(pixels); | 
|  146 } |  151 } | 
|  147  |  152  | 
|  148 }  // namespace ui |  153 }  // namespace ui | 
| OLD | NEW |