Mir
basic.c

A simple mir client

MirDemoState

The handles needs to be accessible both to callbacks and to the control function.

// Utility structure for the state of a single surface session.
typedef struct MirDemoState
{
MirConnection *connection;
MirWindow* window;

Callbacks

This program opens a mir connection and creates a surface. The handles needs to be accessible both to callbacks and to the control function.

/*
* Copyright © 2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alan Griffiths <alan@octopull.co.uk>
*/
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
// Utility structure for the state of a single surface session.
typedef struct MirDemoState
{
MirConnection *connection;
MirWindow* window;
int demo_client(const char* server, int buffer_swap_count)
{
mcd.connection = 0;
mcd.window = 0;
puts("Starting");
mcd.connection = mir_connect_sync(server, __FILE__);
puts("Connected");
if (mcd.connection == NULL || !mir_connection_is_valid(mcd.connection))
{
const char *error = "Unknown error";
if (mcd.connection != NULL)
error = mir_connection_get_error_message(mcd.connection);
fprintf(stderr, "Failed to connect to server `%s': %s\n",
server == NULL ? "<default>" : server, error);
return 1;
}
{
MirModuleProperties properties = { NULL, -1, -1, -1, NULL };
MirExtensionGraphicsModuleV1 const* ext = mir_extension_graphics_module_v1(mcd.connection);
assert(ext);
ext->graphics_module(mcd.connection, &properties);
assert(NULL != properties.name);
assert(0 <= properties.major_version);
assert(0 <= properties.minor_version);
assert(0 <= properties.micro_version);
assert(NULL != properties.filename);
}
// Identify a supported pixel format
unsigned int valid_formats;
mir_connection_get_available_surface_formats(mcd.connection, &pixel_format, 1, &valid_formats);
MirWindowSpec *spec = mir_create_normal_window_spec(mcd.connection, 640, 480);
assert(spec != NULL);
mir_window_spec_set_pixel_format(spec, pixel_format);
mir_window_spec_set_name(spec, __FILE__);
// ...we create a surface using that format.
mcd.window = mir_create_window_sync(spec);
puts("Window created");
// We expect a surface handle;
// we expect it to be valid; and,
// we don't expect an error description
assert(mcd.window != NULL);
if (!mir_window_is_valid(mcd.window))
{
fprintf(stderr, "Failed to create surface: %s",
return 1;
}
else
assert(strcmp(mir_window_get_error_message(mcd.window), "") == 0);
// We can keep exchanging the current buffer for a new one
for (int i = 0; i < buffer_swap_count; i++)
{
// We can query the current graphics buffer attributes
{
MirNativeBuffer* buffer_package = NULL;
assert(buffer_package != NULL);
MirGraphicsRegion graphics_region;
// In a real application we'd render into the current buffer
}
}
// We should release our surface
puts("Window released");
// We should release our connection
mir_connection_release(mcd.connection);
puts("Connection released");
return 0;
}
// The main() function deals with parsing arguments and defaults
int main(int argc, char* argv[])
{
// Some variables for holding command line options
char const *server = NULL;
int buffer_swap_count = 0;
// Parse the command line
{
int arg;
opterr = 0;
while ((arg = getopt (argc, argv, "c:hm:")) != -1)
{
switch (arg)
{
case 'c':
buffer_swap_count = atoi(optarg);
break;
case 'm':
server = optarg;
break;
case '?':
case 'h':
default:
puts(argv[0]);
puts("Usage:");
puts(" -m <Mir server socket>");
puts(" -h: this help text");
return -1;
}
}
}
return demo_client(server, buffer_swap_count);
}

Copyright © 2012-2016 Canonical Ltd.
Generated on Mon Jun 5 13:49:26 UTC 2017