~mterry/mir/session-for-surface

« back to all changes in this revision

Viewing changes to src/client/mir_connection.cpp

  • Committer: Michael Terry
  • Date: 2013-07-29 17:51:51 UTC
  • mfrom: (832.1.58 trunk)
  • Revision ID: michael.terry@canonical.com-20130729175151-3thcnlepeihhzbb8
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "client_platform_factory.h"
25
25
#include "rpc/mir_basic_rpc_channel.h"
26
26
#include "connection_configuration.h"
 
27
#include "display_configuration.h"
 
28
#include "surface_map.h"
27
29
 
 
30
#include <algorithm>
28
31
#include <cstddef>
29
 
#include <sstream>
30
32
#include <unistd.h>
31
33
 
32
34
namespace mcl = mir::client;
46
48
        server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL),
47
49
        logger(conf.the_logger()),
48
50
        client_platform_factory(conf.the_client_platform_factory()),
49
 
        input_platform(conf.the_input_platform())
 
51
        input_platform(conf.the_input_platform()),
 
52
        surface_map(conf.the_surface_map())
50
53
{
51
 
    channel->set_event_handler(this);
52
54
    {
53
55
        std::lock_guard<std::mutex> lock(connection_guard);
54
56
        valid_connections.insert(this);
130
132
    auto new_wait_handle = new MirWaitHandle;
131
133
 
132
134
    SurfaceRelease surf_release{surface, new_wait_handle, callback, context};
133
 
 
134
 
    valid_surfaces.erase(surface->id());
 
135
    surface_map->erase(surface->id());
135
136
 
136
137
    mir::protobuf::SurfaceId message;
137
138
    message.set_value(surface->id());
271
272
    }
272
273
}
273
274
 
274
 
void MirConnection::populate(MirDisplayInfo& display_info)
 
275
MirDisplayConfiguration* MirConnection::create_copy_of_display_config()
275
276
{
276
277
    std::lock_guard<std::recursive_mutex> lock(mutex);
277
 
 
278
 
    if (!connect_result.has_error() && connect_result.has_display_info())
279
 
    {
280
 
        auto const& connection_display_info = connect_result.display_info();
281
 
 
282
 
        display_info.width = connection_display_info.width();
283
 
        display_info.height = connection_display_info.height();
284
 
 
285
 
        auto const pf_size = connection_display_info.supported_pixel_format_size();
286
 
 
287
 
        /* Ensure we don't overflow the supported_pixel_format array */
288
 
        display_info.supported_pixel_format_items = pf_size > mir_supported_pixel_format_max ?
289
 
                                                    mir_supported_pixel_format_max :
290
 
                                                    pf_size;
291
 
 
292
 
        for (int i = 0; i < display_info.supported_pixel_format_items; ++i)
 
278
    if (!connect_result.has_error() && (connect_result.display_output_size() > 0))
 
279
    {
 
280
        return mcl::set_display_config_from_message(connect_result);
 
281
    }
 
282
    return nullptr;
 
283
}
 
284
 
 
285
void MirConnection::possible_pixel_formats(MirPixelFormat* formats,
 
286
                                unsigned int formats_size, unsigned int& valid_formats)
 
287
{
 
288
    //TODO we're just using the display buffer's pixel formats as the list of supported
 
289
    //     formats for the time being. should have a separate message
 
290
    if (!connect_result.has_error() && (connect_result.display_output_size() > 0))
 
291
    {
 
292
        auto display_output = connect_result.display_output(0);
 
293
        valid_formats = std::min(
 
294
            static_cast<unsigned int>(display_output.pixel_format_size()), formats_size);
 
295
 
 
296
        for(auto i=0u; i < valid_formats; i++)
293
297
        {
294
 
            display_info.supported_pixel_format[i] =
295
 
                static_cast<MirPixelFormat>(connection_display_info.supported_pixel_format(i));
296
 
        }
297
 
    }
298
 
    else
299
 
    {
300
 
        display_info.width = 0;
301
 
        display_info.height = 0;
302
 
        display_info.supported_pixel_format_items = 0;
 
298
            formats[i] = static_cast<MirPixelFormat>(display_output.pixel_format(i));
 
299
        }      
303
300
    }
304
301
}
305
302
 
306
 
 
307
303
std::shared_ptr<mir::client::ClientPlatform> MirConnection::get_client_platform()
308
304
{
309
305
    std::lock_guard<std::recursive_mutex> lock(mutex);
325
321
 
326
322
void MirConnection::on_surface_created(int id, MirSurface* surface)
327
323
{
328
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
329
 
 
330
 
    valid_surfaces[id] = surface;
331
 
}
332
 
 
333
 
void MirConnection::handle_event(MirEvent const& e)
334
 
{
335
 
    std::lock_guard<std::recursive_mutex> lock(mutex);
336
 
 
337
 
    switch (e.type)
338
 
    {
339
 
    case mir_event_type_surface:
340
 
        {
341
 
            int id = e.surface.id;
342
 
            SurfaceMap::iterator it = valid_surfaces.find(id);
343
 
            if (it != valid_surfaces.end())
344
 
            {
345
 
                MirSurface *surface = it->second;
346
 
                surface->handle_event(e);
347
 
            }
348
 
            else
349
 
            {
350
 
                std::stringstream ss;
351
 
                ss << __PRETTY_FUNCTION__
352
 
                   << ": mir_event_type_surface "
353
 
                   << "received for non-existent surface ID "
354
 
                   << id
355
 
                   << ".\n";
356
 
                logger->log<mir::logging::Logger::error>(ss.str(), "mir_connection");
357
 
            }
358
 
        }
359
 
        break;
360
 
    default:
361
 
        // Don't worry. This function only gets called for events from the
362
 
        // RPC channel (not input). So you will never see this error unless
363
 
        // you make a mistake.
364
 
        {
365
 
            std::stringstream ss;
366
 
            ss << __PRETTY_FUNCTION__
367
 
               << ": Unsupported event type "
368
 
               << e.type
369
 
               << " received from server.\n";
370
 
            logger->log<mir::logging::Logger::error>(ss.str(), "mir_connection");
371
 
        }
372
 
        break;
373
 
    }
 
324
    surface_map->insert(id, surface);
374
325
}