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