1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27#include "launcher_rpi.h"
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include "bcm_host.h"
33
34static int create_native_window(EGL_DISPMANX_WINDOW_T *native_win)
35{
36 int32_t status = 0;
37 DISPMANX_DISPLAY_HANDLE_T disp;
38 DISPMANX_ELEMENT_HANDLE_T elem;
39 DISPMANX_UPDATE_HANDLE_T update;
40 VC_DISPMANX_ALPHA_T alpha = {DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0};
41 VC_RECT_T src_rect = {0};
42 VC_RECT_T dest_rect = {0};
43 uint32_t display_width, display_height;
44 uint32_t disp_num = 0; // Primary
45 uint32_t layer_num = 0;
46
47 status = graphics_get_display_size(0, &display_width, &display_height);
48 if (status != 0)
49 return status;
50
51 /* Fullscreen */
52 display_width = 1280;
53 display_height = 720;
54 dest_rect.width = display_width;
55 dest_rect.height = display_height;
56 src_rect.width = display_width << 16;
57 src_rect.height = display_height << 16;
58
59 disp = vc_dispmanx_display_open(disp_num);
60 update = vc_dispmanx_update_start(0);
61 elem = vc_dispmanx_element_add(update, disp, layer_num, &dest_rect, 0,
62 &src_rect, DISPMANX_PROTECTION_NONE, &alpha, NULL, DISPMANX_NO_ROTATE);
63
64 native_win->element = elem;
65 native_win->width = display_width;
66 native_win->height = display_height;
67 vc_dispmanx_update_submit_sync(update);
68
69 return 0;
70}
71
72int runApp(const char *name, RUN_APP_FN_T run_app_fn, const void *params, size_t param_size)
73{
74 EGL_DISPMANX_WINDOW_T win;
75 (void) param_size;
76
77
78 vcos_log_trace("Initialsing BCM HOST");
79 bcm_host_init();
80
81 vcos_log_trace("Starting '%s'", name);
82 if (create_native_window(&win) != 0)
83 return -1;
84
85 return run_app_fn(params, (EGLNativeWindowType *) &win);
86}
87
88