Add support to set CursorSize by quering via Capabilities.
[chromium-blink-merge.git] / ui / ozone / platform / dri / test / mock_dri_wrapper.cc
blob76c3ee188a5299f21e1163993f4453a46f7e2689
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.
5 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h"
7 #include <xf86drm.h>
8 #include <xf86drmMode.h>
10 #include "base/logging.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/ozone/platform/dri/crtc_controller.h"
14 namespace ui {
16 namespace {
18 template<class Object> Object* DrmAllocator() {
19 return static_cast<Object*>(drmMalloc(sizeof(Object)));
22 } // namespace
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;
42 MockDriWrapper::~MockDriWrapper() {
43 fd_ = -1;
46 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) {
47 get_crtc_call_count_++;
48 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>());
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_;
60 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc,
61 std::vector<uint32_t> connectors) {
62 restore_crtc_call_count_++;
63 return true;
66 ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) {
67 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>());
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_;
82 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) {
83 remove_framebuffer_call_count_++;
84 return true;
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_;
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;
105 ScopedDrmPropertyPtr MockDriWrapper::GetProperty(drmModeConnector* connector,
106 const char* name) {
107 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>());
110 bool MockDriWrapper::SetProperty(uint32_t connector_id,
111 uint32_t property_id,
112 uint64_t value) {
113 return true;
116 bool MockDriWrapper::GetCapability(uint64_t capability, uint64_t* value) {
117 return true;
120 ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob(
121 drmModeConnector* connector,
122 const char* name) {
123 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>());
126 bool MockDriWrapper::SetCursor(uint32_t crtc_id,
127 uint32_t handle,
128 const gfx::Size& size) {
129 return true;
132 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) {
133 return true;
136 void MockDriWrapper::HandleEvent(drmEventContext& event) {
137 CHECK(!controllers_.empty());
138 controllers_.front()->OnPageFlipEvent(0, 0, 0);
139 controllers_.pop();
140 handle_events_count_++;
143 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info,
144 uint32_t* handle,
145 uint32_t* stride,
146 void** pixels) {
147 if (!create_dumb_buffer_expectation_)
148 return false;
150 *handle = 0;
151 *stride = info.minRowBytes();
152 *pixels = new char[info.getSafeSize(*stride)];
153 buffers_.push_back(
154 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride)));
155 buffers_.back()->getCanvas()->clear(SK_ColorBLACK);
157 return true;
160 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info,
161 uint32_t handle,
162 uint32_t stride,
163 void* pixels) {
164 delete[] static_cast<char*>(pixels);
167 } // namespace ui