~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to src/client/mir_surface.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-02-04 14:49:07 UTC
  • mto: This revision was merged to the branch mainline in revision 61.
  • Revision ID: package-import@ubuntu.com-20140204144907-o3ruhix0ey26lchl
Tags: upstream-0.1.4+14.04.20140204
ImportĀ upstreamĀ versionĀ 0.1.4+14.04.20140204

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
namespace mp = mir::protobuf;
34
34
namespace gp = google::protobuf;
35
35
 
 
36
namespace
 
37
{
 
38
void null_callback(MirSurface*, void*) {}
 
39
}
 
40
 
36
41
MirSurface::MirSurface(
37
42
    MirConnection *allocating_connection,
38
43
    mp::DisplayServer::Stub & server,
64
69
 
65
70
MirSurface::~MirSurface()
66
71
{
67
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
72
    std::lock_guard<decltype(mutex)> lock(mutex);
68
73
 
69
74
    if (input_thread)
70
75
    {
80
85
 
81
86
MirSurfaceParameters MirSurface::get_parameters() const
82
87
{
83
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
88
    std::lock_guard<decltype(mutex)> lock(mutex);
84
89
 
85
90
    return MirSurfaceParameters {
86
91
        0,
93
98
 
94
99
char const * MirSurface::get_error_message()
95
100
{
96
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
101
    std::lock_guard<decltype(mutex)> lock(mutex);
97
102
 
98
103
    if (surface.has_error())
99
104
    {
104
109
 
105
110
int MirSurface::id() const
106
111
{
107
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
112
    std::lock_guard<decltype(mutex)> lock(mutex);
108
113
 
109
114
    return surface.id().value();
110
115
}
111
116
 
112
117
bool MirSurface::is_valid() const
113
118
{
114
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
119
    std::lock_guard<decltype(mutex)> lock(mutex);
115
120
 
116
121
    return !surface.has_error();
117
122
}
118
123
 
119
124
void MirSurface::get_cpu_region(MirGraphicsRegion& region_out)
120
125
{
121
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
126
    std::lock_guard<decltype(mutex)> lock(mutex);
122
127
 
123
128
    auto buffer = buffer_depository->current_buffer();
124
129
 
126
131
    region_out.width = secured_region->width.as_uint32_t();
127
132
    region_out.height = secured_region->height.as_uint32_t();
128
133
    region_out.stride = secured_region->stride.as_uint32_t();
129
 
    region_out.pixel_format = static_cast<MirPixelFormat>(secured_region->format);
130
 
 
 
134
    region_out.pixel_format = secured_region->format;
131
135
    region_out.vaddr = secured_region->vaddr.get();
132
136
}
133
137
 
134
138
void MirSurface::release_cpu_region()
135
139
{
136
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
137
 
 
138
140
    secured_region.reset();
139
141
}
140
142
 
141
143
MirWaitHandle* MirSurface::next_buffer(mir_surface_callback callback, void * context)
142
144
{
143
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
144
 
 
 
145
    std::unique_lock<decltype(mutex)> lock(mutex);
145
146
    release_cpu_region();
 
147
    auto const id = &surface.id();
 
148
    auto const mutable_buffer = surface.mutable_buffer();
 
149
    lock.unlock();
146
150
 
147
151
    server.next_buffer(
148
152
        0,
149
 
        &surface.id(),
150
 
        surface.mutable_buffer(),
 
153
        id,
 
154
        mutable_buffer,
151
155
        google::protobuf::NewCallback(this, &MirSurface::new_buffer, callback, context));
152
156
 
153
157
    return &next_buffer_wait_handle;
167
171
 
168
172
void MirSurface::process_incoming_buffer()
169
173
{
170
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
171
 
 
172
174
    auto const& buffer = surface.buffer();
173
175
 
174
176
    /*
202
204
 
203
205
void MirSurface::created(mir_surface_callback callback, void * context)
204
206
{
 
207
    auto platform = connection->get_client_platform();
 
208
 
205
209
    {
206
 
        std::lock_guard<std::recursive_mutex> lock(mutex);
 
210
        std::lock_guard<decltype(mutex)> lock(mutex);
207
211
 
208
212
        process_incoming_buffer();
209
 
 
210
 
        auto platform = connection->get_client_platform();
211
213
        accelerated_window = platform->create_egl_native_window(this);
212
 
 
213
 
        connection->on_surface_created(id(), this);
214
214
    }
215
215
 
 
216
    connection->on_surface_created(id(), this);
216
217
    callback(this, context);
217
218
    create_wait_handle.result_received();
218
219
}
220
221
void MirSurface::new_buffer(mir_surface_callback callback, void * context)
221
222
{
222
223
    {
223
 
        std::lock_guard<std::recursive_mutex> lock(mutex);
 
224
        std::lock_guard<decltype(mutex)> lock(mutex);
224
225
        process_incoming_buffer();
225
226
    }
226
227
 
245
246
 
246
247
std::shared_ptr<mcl::ClientBuffer> MirSurface::get_current_buffer()
247
248
{
248
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
249
    std::lock_guard<decltype(mutex)> lock(mutex);
249
250
 
250
251
    return buffer_depository->current_buffer();
251
252
}
252
253
 
253
254
uint32_t MirSurface::get_current_buffer_id() const
254
255
{
255
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
256
    std::lock_guard<decltype(mutex)> lock(mutex);
256
257
 
257
258
    return buffer_depository->current_buffer_id();
258
259
}
259
260
 
260
261
void MirSurface::populate(MirBufferPackage& buffer_package)
261
262
{
262
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
263
 
 
264
 
    if (is_valid() && surface.has_buffer())
 
263
    if (!surface.has_error() && surface.has_buffer())
265
264
    {
266
265
        auto const& buffer = surface.buffer();
267
266
 
293
292
 
294
293
EGLNativeWindowType MirSurface::generate_native_window()
295
294
{
296
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
295
    std::lock_guard<decltype(mutex)> lock(mutex);
297
296
 
298
297
    return *accelerated_window;
299
298
}
300
299
 
301
300
MirWaitHandle* MirSurface::configure(MirSurfaceAttrib at, int value)
302
301
{
303
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
304
 
 
 
302
    std::unique_lock<decltype(mutex)> lock(mutex);
305
303
    mp::SurfaceSetting setting;
306
304
    setting.mutable_surfaceid()->CopyFrom(surface.id());
307
305
    setting.set_attrib(at);
308
306
    setting.set_ivalue(value);
 
307
    lock.unlock();
309
308
 
310
309
    configure_wait_handle.expect_result();
311
310
    server.configure_surface(0, &setting, &configure_result,
316
315
 
317
316
void MirSurface::on_configured()
318
317
{
319
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
318
    std::lock_guard<decltype(mutex)> lock(mutex);
320
319
 
321
320
    if (configure_result.has_surfaceid() &&
322
321
        configure_result.surfaceid().value() == surface.id().value() &&
346
345
 
347
346
int MirSurface::attrib(MirSurfaceAttrib at) const
348
347
{
349
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
348
    std::lock_guard<decltype(mutex)> lock(mutex);
350
349
 
351
350
    return attrib_cache[at];
352
351
}
353
352
 
354
353
void MirSurface::set_event_handler(MirEventDelegate const* delegate)
355
354
{
356
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
355
    std::lock_guard<decltype(mutex)> lock(mutex);
357
356
 
358
357
    if (input_thread)
359
358
    {
379
378
 
380
379
void MirSurface::handle_event(MirEvent const& e)
381
380
{
382
 
    std::unique_lock<std::recursive_mutex> lock(mutex);
 
381
    std::unique_lock<decltype(mutex)> lock(mutex);
383
382
 
384
383
    if (e.type == mir_event_type_surface)
385
384
    {
398
397
 
399
398
MirPlatformType MirSurface::platform_type()
400
399
{
401
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
 
400
    std::lock_guard<decltype(mutex)> lock(mutex);
402
401
 
403
402
    auto platform = connection->get_client_platform();
404
403
    return platform->platform_type();
405
404
}
 
405
 
 
406
void MirSurface::request_and_wait_for_next_buffer()
 
407
{
 
408
    next_buffer(null_callback, nullptr)->wait_for_all();
 
409
}
 
410
 
 
411
void MirSurface::request_and_wait_for_configure(MirSurfaceAttrib a, int value)
 
412
{
 
413
    configure(a, value)->wait_for_all();
 
414
}