3
* Copyright © 2015 Canonical Ltd.
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Author: Alan Griffiths <alan@octopull.co.uk>
21
#include <mir_toolkit/mir_client_library.h>
25
#include <GLES2/gl2.h>
28
/// A simple orange client surface with a simple grey tooltip
30
static MirPixelFormat select_pixel_format(MirConnection* connection);
31
static MirSurface* create_tooltip(MirConnection* const connection, MirSurface* const parent, const MirPixelFormat format);
38
int main(int argc, char *argv[])
40
float const opacity = mir_eglapp_background_opacity;
41
Color const orange = {0.866666667f, 0.282352941f, 0.141414141f, opacity};
43
unsigned int width = 300, height = 200;
45
if (!mir_eglapp_init(argc, argv, &width, &height))
48
glClearColor(orange.r, orange.g, orange.b, orange.a);
49
glClear(GL_COLOR_BUFFER_BIT);
50
mir_eglapp_swap_buffers();
52
MirConnection* const connection = mir_eglapp_native_connection();
53
MirSurface* const parent = mir_eglapp_native_surface();
55
MirSurfaceSpec* const spec = mir_connection_create_spec_for_changes(connection);
56
mir_surface_spec_set_name(spec, "tooltip example");
57
mir_surface_spec_set_min_width(spec, width/2);
58
mir_surface_spec_set_max_width(spec, width*2);
59
mir_surface_spec_set_min_height(spec, height/2);
60
mir_surface_spec_set_max_height(spec, height*2);
61
mir_surface_apply_spec(parent, spec);
62
mir_surface_spec_release(spec);
64
MirSurface* tooltip = create_tooltip(connection, parent, select_pixel_format(connection));
65
while (mir_eglapp_running())
69
mir_surface_release_sync(tooltip);
70
mir_eglapp_shutdown();
75
static MirPixelFormat select_pixel_format(MirConnection* connection)
77
unsigned int format[mir_pixel_formats];
78
unsigned int nformats;
80
mir_connection_get_available_surface_formats(connection,
81
format, mir_pixel_formats, &nformats);
83
MirPixelFormat pixel_format = format[0];
84
for (unsigned int f = 0; f < nformats; f++)
86
const bool opaque = (format[f] == mir_pixel_format_xbgr_8888 ||
87
format[f] == mir_pixel_format_xrgb_8888 ||
88
format[f] == mir_pixel_format_bgr_888);
92
pixel_format = format[f];
100
static MirSurface* create_tooltip(MirConnection* const connection, MirSurface* const parent, const MirPixelFormat format)
102
MirRectangle zone = { 0, 0, 10, 10 };
103
int const width = 50;
104
int const height = 20;
105
MirSurfaceSpec* const spec = mir_connection_create_spec_for_tooltip(
106
connection, width, height, format, parent, &zone);
108
mir_surface_spec_set_buffer_usage(spec, mir_buffer_usage_software);
109
mir_surface_spec_set_name(spec, "tooltip");
110
mir_surface_spec_set_min_width(spec, width);
111
mir_surface_spec_set_max_width(spec, width);
112
mir_surface_spec_set_min_height(spec, height);
113
mir_surface_spec_set_max_height(spec, height);
115
MirSurface* tooltip = mir_surface_create_sync(spec);
116
mir_surface_spec_release(spec);
118
MirBufferStream* const bs = mir_surface_get_buffer_stream(tooltip);
119
MirGraphicsRegion buffer;
120
mir_buffer_stream_get_graphics_region(bs, &buffer);
122
for (int y = 0; y != buffer.height; ++y)
124
for (int n = 0; n != buffer.width; ++n)
127
case mir_pixel_format_abgr_8888:
128
case mir_pixel_format_argb_8888:
130
uint32_t* const pixel = (uint32_t*) (buffer.vaddr + y * buffer.stride);
131
pixel[n] = 0xff7f7f7f;
134
case mir_pixel_format_xbgr_8888:
135
case mir_pixel_format_xrgb_8888:
137
uint32_t* const pixel = (uint32_t*) (buffer.vaddr + y * buffer.stride);
138
pixel[n] = 0x007f7f7f;
141
case mir_pixel_format_bgr_888:
143
uint8_t* const subpixel = (uint8_t*) (buffer.vaddr + y * buffer.stride);
144
subpixel[3 * n + 0] = 0x7f;
145
subpixel[3 * n + 1] = 0x7f;
146
subpixel[3 * n + 2] = 0x7f;
154
mir_buffer_stream_swap_buffers_sync(bs);