From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 12 Jun 2024 11:26:49 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHKFk-004jgg-39 for lore@lore.pengutronix.de; Wed, 12 Jun 2024 11:26:48 +0200 Received: from localhost ([127.0.0.1] helo=metis.whiteo.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1sHKFi-0004OI-J9; Wed, 12 Jun 2024 11:26:46 +0200 Received: from mail-am6eur05on2056.outbound.protection.outlook.com ([40.107.22.56] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sHInv-0002qt-Ch; Wed, 12 Jun 2024 09:54:00 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JdIxpPDuHTbXiP1DDc66oACT5cNl7NUk1TiqBb1hAAufQZDA/aN2dmzE1cTQJdslbCUxak3tT0qWudsWTeY+ZIZg/dnM2Kk5XrUooaMDbNUYrv+BjdLyNamXyoGx1FhuJYlY6c+4NJPJAGKpjoeTQvNqQmnRJaZKWcBqQBLx+vm7/J3yLAYC2Cokn/HTyMXn4QuZA70ytXj152oFYJWP8nECXdJjJ8xKukKJLfqV1CA0ZxntWx9hn+3G32cV+0319J97p4UQnGgPQUE3i9n93Lau/MxNjG2LxmkSv+pQ6FrHvE7p2U+ilszcDSddDHdhJtIjS0p+If0GeBawe0xCMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2yQIOp9Zpe4S7zYfwBoFY2/BbAlYmhGZmwKID0mUcQc=; b=ckg/MQU/SgQfUmfO2TDJN34rqiVpEH4Jb46457IFkQehtOE9O0El1Y+rRA9s7Zqjw4wcgoPcBbc8Iqh8wvq+CWHsHk0+VzjWAotuiV/6/wWihktzkgZwoAWRHkyMhHqEKk2T2sCpWAKNEkDdXqbRQAhBsiwZGCZ3BANeGjqbH/HhD9/uzf1EJcK4i2x57lJuZy8M35C4bcccDBqhdNlkWGoh3sxVCKaB2S7ePyOacha6c+Uv+o7T0TN7wLeEU7aDXI9ZEfWLV0sY3NYj+MqcKI2HrJHpum3sCaly0v/xeZZZriH/uyAaKJRCUXdkmUQU9X33DyFEpDesTjygrk2yuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 193.8.40.94) smtp.rcpttodomain=pengutronix.de smtp.mailfrom=leica-geosystems.com.cn; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=leica-geosystems.com.cn; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leica-geosystems.com.cn; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2yQIOp9Zpe4S7zYfwBoFY2/BbAlYmhGZmwKID0mUcQc=; b=jS422vakZ25ayVhULYC7JvcrYa8SodI7RehTdDhNw0GuJ192wscbH3NBMplT3pMmJ7/3ZjzQiKmCFO2CLW5zRY4mDrK652bOzZTJlcxQuUR4QZpxmcYpX/Ojkcq00OtSObgkFYYxwdMJiPNkTx7uBtbamBL+9KPYyIaVvykn0QY= Received: from DU2PR04CA0168.eurprd04.prod.outlook.com (2603:10a6:10:2b0::23) by AS8PR06MB7960.eurprd06.prod.outlook.com (2603:10a6:20b:3c3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.37; Wed, 12 Jun 2024 07:53:57 +0000 Received: from DB5PEPF00014B8F.eurprd02.prod.outlook.com (2603:10a6:10:2b0:cafe::ce) by DU2PR04CA0168.outlook.office365.com (2603:10a6:10:2b0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20 via Frontend Transport; Wed, 12 Jun 2024 07:53:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 193.8.40.94) smtp.mailfrom=leica-geosystems.com.cn; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=leica-geosystems.com.cn; Received-SPF: Pass (protection.outlook.com: domain of leica-geosystems.com.cn designates 193.8.40.94 as permitted sender) receiver=protection.outlook.com; client-ip=193.8.40.94; helo=hexagon.com; pr=C Received: from hexagon.com (193.8.40.94) by DB5PEPF00014B8F.mail.protection.outlook.com (10.167.8.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 07:53:57 +0000 Received: from aherlnxbspsrv01.lgs-net.com ([10.60.34.116]) by hexagon.com with Microsoft SMTPSVC(10.0.17763.1697); Wed, 12 Jun 2024 09:53:55 +0200 From: LI Qingwu To: Qing-wu.Li@leica-geosystems.com.cn, oss-tools@pengutronix.de, m.felsch@pengutronix.de Date: Wed, 12 Jun 2024 09:53:53 +0200 Message-Id: <20240612075353.2551648-3-Qing-wu.Li@leica-geosystems.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612075353.2551648-1-Qing-wu.Li@leica-geosystems.com.cn> References: <20240612075353.2551648-1-Qing-wu.Li@leica-geosystems.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 12 Jun 2024 07:53:55.0843 (UTC) FILETIME=[ACF44D30:01DABC9D] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B8F:EE_|AS8PR06MB7960:EE_ X-MS-Office365-Filtering-Correlation-Id: 85fa793a-c5f1-4771-23f2-08dc8ab4d095 X-SET-LOWER-SCL-SCANNER: YES X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230032|82310400018|36860700005|376006|1800799016; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Q2o5WWpGWHhPOXlveGhjcXdEeVJnaTBHNVkrRTBscXlQV25vUGZON2VzMHhP?= =?utf-8?B?TFNJbHZPWExkMGJaTFBXTDN6QjZYSjhGc09zdmk5TGQrT0IwNGVLampiTnIz?= =?utf-8?B?ZWVZRWY1Qkx0cnplZ1BiTlQ5T0FtMmRPckJaTDBtUVNJdXQyR1VNZisyWlIx?= =?utf-8?B?Z3dmTnpDNXZNZUFDd1FxV3Y1aS81UDFoc3JnakJsSDhHSDRhZUIrOVdoZW9a?= =?utf-8?B?QlZRaXRWVkMvTUZqL0JGdUlNYzRsYXpUdDBLK2VTRThZdE1xMENMNE02a1pJ?= =?utf-8?B?djF1b1JURVc4MmpjVzJ5ejlUT2cxZzRlZG1WaTIzSkthYndoc2ZqVG11YUFj?= =?utf-8?B?QU04ZGZrdXFLWFJRQjZXaEdBYTdwa05WaHlOL1dBbWZKRFJydGdYYmlMdDR0?= =?utf-8?B?eUFvamN4Q2hPQlpGTjg5T0o0Tzl6UXRBQ0dpQWp0cTA2RXhIakNaZ2pOTkFs?= =?utf-8?B?N0dZZ24wcWdQSzhCUlY5eFdjeFlLUnJkeSsrbEY0bkdDTy9kTC9oWi9SeG9E?= =?utf-8?B?djM3RmUvWWJaVFdUSU5CRjZlZWNSMi9xMDRBRGNWVm9UNzdGMmE3UFFxZ3dE?= =?utf-8?B?Q0FlRitMUkdwcGlUVGFjWDc1cUpIOStoZ0JyQmMrU1R6UkNPbFcvODV0bk1h?= =?utf-8?B?MzJVZTl5ZUhHMW0yWTNyOTZ2OXBlWncwNXYzbmxEaW1tNG1WMUFiVHd2L0RI?= =?utf-8?B?RlRMREEzNWpHaElVTi9Ncncxa2s3M3VmUnYybFJhMG1GTWdpYXNFYzVTYkFN?= =?utf-8?B?czl1ZXRvYWo4Ky9TaUJ4TVJwUFo0Nk53ckpDcWZoRkE5L1k5WVRES0JudTJv?= =?utf-8?B?MFlzNW45TmFVc1dMcHA2T3ZLWWJnK1MvbDY4SXRTOFVodmRjcVBxZmplWkhj?= =?utf-8?B?MzVLZHlrdStqNmhCN0V3dHROTGdCTGZnWTh2SkxOQXRFT3JPNmZ4YmplZi9N?= =?utf-8?B?SDRQQmpEMzlrMWRwZmhHekNJSDFGcjJXVFNzM2VsM3R5UDlJQS80ZzA4STd3?= =?utf-8?B?WUdoWVRWVCtkZkRNQm8zQTVhV1NZZ0I0ZVRPT0FZRHFucmRBR0RNRkVBMk9j?= =?utf-8?B?TFhzajVtSjVkeStNcFVGZllOcDlXSjd5b1NzWkZjNCtwdHZ0anJhTXZvSkxz?= =?utf-8?B?QlY5bzlZbEhBeWhFVkgrSHN4MDFvOEczT2VFSmxSUGRLcWMwZVZPYWY2RERo?= =?utf-8?B?RHR6aG02MGhvQm8rZ0xlcDBpaGJIUnRobW9kUkg3MkNkY0t3ak5LRXM5cjln?= =?utf-8?B?MW43QituUk1DTk05NkptdEx2enNmL09Da3IxZHBoMlE1T0FVZmdQTDNXZkll?= =?utf-8?B?VFNiUWFvbkhUZVlLSEdqQTdGSGM2aGpLcTFlSXFPQmY0WXFFYXIrS1pRMFZr?= =?utf-8?B?SkExdlJZWDFqVmIxSHRSeS92MnhOY2U1Rzl2S2JYT0M2QUZRQzgxRlBESTNE?= =?utf-8?B?Y2lqZk1Na0VlZjRReGpkOU5KV2RicENtNm5NN1NaMFYvREhudGcwdVlQeVN1?= =?utf-8?B?enpPMDkrbFh6SXNmVWVYbEU1NmZaK0V5Zm5rRkRSR2ZNdFlCSXl6QkFKempK?= =?utf-8?B?WU5hc1BCUlJwUGM1Y2NjeUF3M2xITDYrRnA5bUNQK2RMNXgxZHJWUDh5d3pX?= =?utf-8?B?cG95OW80dzBpSXRVOVE5RkErWTJiYTRlUGU1dUFoSFVtMmZwd2FsM0tnMzEr?= =?utf-8?B?SWtYVlRUWHprVDhRanRkMWdCVGxhU0wxS2xkNEhhTlJoTUM3S0VyeFFNZktK?= =?utf-8?B?dUNCOVBjZjdnSTVqVEVlc2hTeFRPdFBHeFZwRXhDTFVXTEFnd1ZpMFdqZ3Rz?= =?utf-8?B?ZXQrZ243aktoRGM3Wm4vQWV0ZkFkTEg2OHlYelFsR3lLQXJCLyswOXlpcSs4?= =?utf-8?B?LzM3NStyVG8zZk4yNkVISzZpdEsyTklmTWhZbWpCdXkrSFE9PQ==?= X-Forefront-Antispam-Report: CIP:193.8.40.94; CTRY:CH; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:hexagon.com; PTR:ahersrvdom50.leica-geosystems.com; CAT:NONE; SFS:(13230032)(82310400018)(36860700005)(376006)(1800799016); DIR:OUT; SFP:1101; X-OriginatorOrg: leica-geosystems.com.cn X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 07:53:57.6542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 85fa793a-c5f1-4771-23f2-08dc8ab4d095 X-MS-Exchange-CrossTenant-Id: 1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a; Ip=[193.8.40.94]; Helo=[hexagon.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B8F.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR06MB7960 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=4.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 X-Mailman-Approved-At: Wed, 12 Jun 2024 11:26:43 +0200 Subject: [OSS-Tools] [PATCH platsch 3/3] Add spinner executable for boot animation and text show X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false This commit introduces a new executable, spinner, which supports two types of animations for boot sequences: 1 rotates square PNG images per frame 2 shows a sequence of square images from a strip of PNG images. it supports read configuration from a conf file. the default path of conf is /usr/share/platsch/spinner.conf the dir of the conf can be set via env platsch_directory here is an example of conf: backdrop="/usr/share/platsch/splash.png" symbol="/usr/share/platsch/Spinner.png" fps=20 frames=0 text="Now loading..." text_x=350 text_y=400 text_font="Sans" textsize=30 Signed-off-by: LI Qingwu --- README.rst | 76 ++++++++++++- meson.build | 30 +++++- meson_options.txt | 1 + spinner.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++ spinner.conf | 13 +++ spinner_conf.c | 66 ++++++++++++ spinner_conf.h | 39 +++++++ 7 files changed, 487 insertions(+), 4 deletions(-) create mode 100644 spinner.c create mode 100644 spinner.conf create mode 100644 spinner_conf.c create mode 100644 spinner_conf.h diff --git a/README.rst b/README.rst index 2af29e4..ee0da5f 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ RGB565 This generates a 1920x1080 splash image in ``RGB565`` format from a png file:: #!/bin/bash - magick \ + convert \ /path/to/source.png \ -resize 1920x1080\! \ -flip \ @@ -62,7 +62,7 @@ This generates a 1920x1080 splash image in ``XRGB8888`` format from a png file:: #!/bin/bash - magick \ + convert \ /path/to/source.png \ -resize 1920x1080\! \ -flip \ @@ -149,9 +149,42 @@ To cross-compile the project, use the following commands: .. code-block:: shell - meson build --cross-file= + meson setup --cross-file= ninja -C build +Here are sample cross commands: + +.. code-block:: shell + + meson setup ./build -DHAVE_CAIRO=true --cross-file ./meson.cross + ninja -C build + +Here is a sample cross file: + +.. code-block:: ini + + [binaries] + c = ${CC} + cpp = ${CXX} + cython = 'cython3' + ar = '${AR}' + nm = '${NM}' + strip = '${STRIP}' + readelf = '${READELF}' + objcopy = '${OBJCOPY}' + pkgconfig = '${pkgconfig}' + + [properties] + needs_exe_wrapper = true + + + [target_machine] + system = 'linux' + cpu_family = 'aarch64' + cpu = 'aarch64' + endian = 'little' + + Build options ------------- @@ -168,3 +201,40 @@ The following build options are available: - true, false - true - Enable Cairo support + * - SPINNER + - true, false + - false + - Enable spinner + +Spinner - Splash Screen with Animation +====================================== + +The `spinner` executable is designed to provide boot animations. It supports two types of animations: + +1. **Square PNG Rotation Animation**: Rotates a square PNG image. +2. **Sequence Move Rectangle Animation**: Displays a sequence of square images from a strip of PNG images. + +spinner Configuration +--------------------- + +The configuration for the `spinner` executable is read from a configuration file, +with a default path of `/usr/share/platsch/spinner.conf`. +The directory of the configuration file can be set via the `platsch_directory` environment variable. + +Example Configuration File +-------------------------- + +Here is an example of a configuration file (`spinner.conf`): + +.. code-block:: ini + + backdrop="/usr/share/platsch/splash.png" + symbol="/usr/share/platsch/Spinner.png" + fps=20 + # frames=0 means infinite + frames=0 + text="text to display" + text_x=350 + text_y=400 + text_font="Sans" + text_size=30 diff --git a/meson.build b/meson.build index 8c15fb9..f12b2da 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,13 @@ project('platsch', 'c') -have_cairo = get_option('HAVE_CAIRO') + +# If SPINNER is true, force HAVE_CAIRO to be true +if get_option('SPINNER') + message('SPINNER is enabled, forcing HAVE_CAIRO to be true') + have_cairo = true +else + have_cairo = get_option('HAVE_CAIRO') +endif # Define dependencies conditionally based on the HAVE_CAIRO option platsch_dep = [dependency('libdrm', required: true)] @@ -33,3 +40,24 @@ executable('platsch', install: true, include_directories: include_directories('.') ) + +# Create the spinner executable if SPINNER true +if get_option('SPINNER') + spinner_dep = [ + dependency('cairo', required: true), + dependency('libdrm', required: true) + ] + + spinner_src = [ + 'spinner.c', + 'spinner_conf.c' + ] + executable('spinner', + spinner_src, + dependencies: spinner_dep, + link_with: libplatsch, + c_args: args, + install: true, + include_directories: include_directories('.') + ) +endif \ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt index 1adfef3..78c4fba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('HAVE_CAIRO', type: 'boolean', value: true, description: 'Enable Cairo support') +option('SPINNER', type: 'boolean', value: false, description: 'Enable spinner') diff --git a/spinner.c b/spinner.c new file mode 100644 index 0000000..9a68be7 --- /dev/null +++ b/spinner.c @@ -0,0 +1,266 @@ +#include "libplatsch.h" +#include "spinner_conf.h" +#include +#include +#include + +typedef struct spinner { + cairo_format_t fmt; + cairo_surface_t *background_surface; + cairo_surface_t *icon_surface; + cairo_surface_t *image_surface; + cairo_surface_t *drawing_surface; + cairo_t *cr_background; + cairo_t *cr_drawing; + cairo_t *device_cr; + int background_height; + int background_width; + int display_height; + int display_width; + int icon_height; + int icon_width; + struct modeset_dev *dev; + struct spinner *next; +} spinner_t; + +void on_draw_Sequence_animation(cairo_t *cr, spinner_t *data) +{ + static int current_frame; + int num_frames = data->icon_width / data->icon_height; + int frame_width = data->icon_height; + + cairo_set_source_surface(cr, data->background_surface, 0, 0); + cairo_paint(cr); + + cairo_save(cr); + + cairo_translate(cr, data->display_width / 2, data->display_height / 2); + + cairo_set_source_surface(cr, data->icon_surface, + -frame_width / 2 - current_frame * frame_width, + -frame_width / 2); + + cairo_rectangle(cr, -frame_width / 2, -frame_width / 2, + frame_width, frame_width); + cairo_clip(cr); + cairo_paint(cr); + + cairo_restore(cr); + + current_frame = (current_frame + 1) % num_frames; +} + +void on_draw_rotation_animation(cairo_t *cr, spinner_t *data) +{ + static float angle = 0.0; + + cairo_set_source_surface(cr, data->background_surface, 0, 0); + cairo_paint(cr); + cairo_save(cr); + cairo_translate(cr, data->background_width / 2, data->background_height / 2); + cairo_rotate(cr, angle); + cairo_translate(cr, -data->icon_width / 2, -data->icon_height / 2); + cairo_set_source_surface(cr, data->icon_surface, 0, 0); + cairo_paint(cr); + cairo_restore(cr); + angle += 0.1; + if (angle > 2 * M_PI) + angle = 0.0; +} + +int main(int argc, char *argv[]) +{ + bool pid1 = getpid() == 1; + char filename[128]; + Config config = DEFAULT_CONFIG; + const char *base = "splash"; + const char *dir = "/usr/share/platsch"; + const char *env; + int frames; + int ret; + long elapsed_time; + + spinner_t *spinner_list = NULL, *spinner_node = NULL, *spinner_iter = NULL; + struct modeset_dev *iter; + struct timeval start, end; + + env = getenv("platsch_directory"); + if (env) + dir = env; + + env = getenv("platsch_basename"); + if (env) + base = env; + + ret = snprintf(filename, sizeof(filename), "%s/spinner.conf", dir); + if (ret >= sizeof(filename)) { + error("Failed to fit filename\n"); + return EXIT_FAILURE; + } + + parseConfig(filename, &config); + + struct modeset_dev *modeset_list = init(); + + if (!modeset_list) { + fprintf(stderr, "Failed to initialize modeset\n"); + return EXIT_FAILURE; + } + + for (iter = modeset_list; iter; iter = iter->next) { + spinner_node = (spinner_t *)malloc(sizeof(spinner_t)); + if (!spinner_node) { + fprintf(stderr, "Failed to allocate memory for spinner_node\n"); + return EXIT_FAILURE; + } + memset(spinner_node, 0, sizeof(*spinner_node)); + printf("spinner_node=%p\n", spinner_node); + + spinner_node->device_cr = cairo_init(iter, dir, base); + if (!spinner_node->device_cr) + return EXIT_FAILURE; + + cairo_surface_t *surface = cairo_get_target(spinner_node->device_cr); + + if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "Failed to get cairo surface\n"); + return EXIT_FAILURE; + } + spinner_node->display_width = cairo_image_surface_get_width(surface); + spinner_node->display_height = cairo_image_surface_get_height(surface); + spinner_node->fmt = cairo_image_surface_get_format(surface); + + spinner_node->background_surface = cairo_image_surface_create( + spinner_node->fmt, + spinner_node->display_width, + spinner_node->display_height); + if (cairo_surface_status(spinner_node->background_surface) + != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "Failed to load splash.png\n"); + return EXIT_FAILURE; + } + + spinner_node->image_surface = cairo_image_surface_create_from_png(config.backdrop); + if (cairo_surface_status(spinner_node->image_surface) != CAIRO_STATUS_SUCCESS) { + error("Failed to create cairo surface from %s\n", config.backdrop); + return EXIT_FAILURE; + } + + int image_width = cairo_image_surface_get_width(spinner_node->image_surface); + int image_height = cairo_image_surface_get_height(spinner_node->image_surface); + double scale_x = (double)spinner_node->display_width / image_width; + double scale_y = (double)spinner_node->display_height / image_height; + + spinner_node->cr_background = cairo_create(spinner_node->background_surface); + cairo_scale(spinner_node->cr_background, scale_x, scale_y); + cairo_set_source_surface(spinner_node->cr_background, + spinner_node->image_surface, 0, 0); + + cairo_paint(spinner_node->cr_background); + + cairo_select_font_face(spinner_node->cr_background, config.text_font, + CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(spinner_node->cr_background, (double)config.text_size); + cairo_set_source_rgb(spinner_node->cr_background, 0, 0, 0); + cairo_move_to(spinner_node->cr_background, config.text_x, config.text_y); + cairo_show_text(spinner_node->cr_background, config.text); + + spinner_node->background_width = cairo_image_surface_get_width( + spinner_node->background_surface); + spinner_node->background_height = cairo_image_surface_get_height( + spinner_node->background_surface); + printf("spinner_node->background_width=%d, spinner_node->background_height=%d\n", + spinner_node->background_width, spinner_node->background_height); + + spinner_node->icon_surface = cairo_image_surface_create_from_png(config.symbol); + if (cairo_surface_status(spinner_node->icon_surface) != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "Failed to load %s\n", config.symbol); + return EXIT_FAILURE; + } + spinner_node->icon_width = cairo_image_surface_get_width( + spinner_node->icon_surface); + spinner_node->icon_height = cairo_image_surface_get_height( + spinner_node->icon_surface); + printf("spinner_node->icon_width=%d, spinner_node->icon_height=%d\n", + spinner_node->icon_width, spinner_node->icon_height); + + spinner_node->drawing_surface = cairo_image_surface_create( + spinner_node->fmt, + spinner_node->display_width, + spinner_node->display_height); + if (cairo_surface_status(spinner_node->drawing_surface) != CAIRO_STATUS_SUCCESS) { + error("Failed to create drawing surface\n"); + return EXIT_FAILURE; + } + spinner_node->cr_drawing = cairo_create(spinner_node->drawing_surface); + + cairo_set_source_surface( + spinner_node->device_cr, + spinner_node->drawing_surface, 0, 0); + update_display(iter); + + spinner_node->next = spinner_list; + spinner_list = spinner_node; + } + + if (pid1) { + char **initsargv; + + ret = fork(); + printf("fork ret=%d\n", ret); + if (ret < 0) + error("failed to fork for init: %m\n"); + else if (ret == 0) + goto drawing; + + initsargv = calloc(sizeof(argv[0]), argc + 1); + + if (!initsargv) { + error("failed to allocate argv for init\n"); + return EXIT_FAILURE; + } + memcpy(initsargv, argv, argc * sizeof(argv[0])); + initsargv[0] = "/sbin/init"; + initsargv[argc] = NULL; + + execv("/sbin/init", initsargv); + + error("failed to exec init: %m\n"); + + return EXIT_FAILURE; + } + +drawing: + printf("drawing\n"); + frames = config.frames; + if (config.frames == 0) + frames = 1; + + while (frames) { + gettimeofday(&start, NULL); + for (spinner_iter = spinner_list; spinner_iter; spinner_iter = spinner_iter->next) { + if (spinner_node->icon_width / spinner_node->icon_height > 2) + on_draw_Sequence_animation(spinner_iter->cr_drawing, spinner_iter); + else + on_draw_rotation_animation(spinner_iter->cr_drawing, spinner_iter); + + cairo_set_source_surface( + spinner_iter->device_cr, + spinner_iter->drawing_surface, 0, 0); + cairo_paint(spinner_iter->device_cr); + } + gettimeofday(&end, NULL); + elapsed_time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + + long sleep_time = (1000000 / config.fps) - elapsed_time; + + if (sleep_time > 0) + usleep(sleep_time); + + if (config.frames > 0) + frames--; + } + + return 0; +} diff --git a/spinner.conf b/spinner.conf new file mode 100644 index 0000000..c95a850 --- /dev/null +++ b/spinner.conf @@ -0,0 +1,13 @@ + +backdrop="/mnt/data/platsch/splash.png" +#symbol="/mnt/data/platsch/Spider.png" +symbol="/mnt/data/platsch/Spinner.png" + +fps=1 +#frames=0 for infinite +frames=0 +text="hello" +text_x=350 +text_y=400 +text_font="Sans" +text_size=30 diff --git a/spinner_conf.c b/spinner_conf.c new file mode 100644 index 0000000..c50a08c --- /dev/null +++ b/spinner_conf.c @@ -0,0 +1,66 @@ +#include "spinner_conf.h" +#include +#include + +int parseConfig(const char *filename, Config *config) +{ + FILE *file; + char line[MAX_LINE_LENGTH*2]; + char key[MAX_LINE_LENGTH]; + char value[MAX_LINE_LENGTH+1]; + char *value_start; + char *value_end; + + file = fopen(filename, "r"); + if (file == NULL) { + fprintf(stderr, "Unable to open file: %s\n", filename); + return -EFAULT; + } + + while (fgets(line, sizeof(line), file)) { + if (strlen(line) > MAX_LINE_LENGTH) { + fprintf(stderr, "conf string too long\n"); + continue; + } + if (line[0] != '#' && sscanf(line, "%[^=]=%[^\n]", key, value) == 2) { + value_start = strchr(line, '=') + 1; + value_end = line + strlen(line) - 1; + + while (isspace(*value_start)) value_start++; + while (isspace(*value_end) || *value_end == '"') value_end--; + + if (*value_start == '"') { + value_start++; + if (*value_end == '"') value_end--; + } + + strncpy(value, value_start, value_end - value_start + 1); + value[value_end - value_start + 1] = '\0'; + value[sizeof(value) - 1] = '\0'; + + if (strcmp(key, "backdrop") == 0) { + strncpy(config->backdrop, value, MAX_LINE_LENGTH); + config->backdrop[sizeof(config->backdrop) - 1] = '\0'; + } else if (strcmp(key, "symbol") == 0) { + strncpy(config->symbol, value, MAX_LINE_LENGTH); + config->symbol[sizeof(config->symbol) - 1] = '\0'; + } else if (strcmp(key, "fps") == 0) { + config->fps = atoi(value); + } else if (strcmp(key, "frames") == 0) { + config->frames = atoi(value); + } else if (strcmp(key, "text_x") == 0) { + config->text_x = atoi(value); + } else if (strcmp(key, "text_y") == 0) { + config->text_y = atoi(value); + } else if (strcmp(key, "text_font") == 0) { + strncpy(config->text_font, value, MAX_LINE_LENGTH); + config->text_font[sizeof(config->text_font) - 1] = '\0'; + } else if (strcmp(key, "text_size") == 0) { + config->text_size = atoi(value); + } + } + } + + fclose(file); + return 0; +} diff --git a/spinner_conf.h b/spinner_conf.h new file mode 100644 index 0000000..e797f3e --- /dev/null +++ b/spinner_conf.h @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +#ifndef __SPINNER_CONF_H__ +#define __SPINNER_CONF_H__ + + +#define MAX_LINE_LENGTH 128 + +typedef struct { + char backdrop[MAX_LINE_LENGTH]; + char symbol[MAX_LINE_LENGTH]; + char type[MAX_LINE_LENGTH]; + int fps; + int frames; + int text_x; + int text_y; + char text_font[MAX_LINE_LENGTH]; + int text_size; + char text[MAX_LINE_LENGTH]; +} Config; + +int parseConfig(const char *filename, Config *config); + +#define DEFAULT_CONFIG { \ + .backdrop = "/usr/share/platsch/splash.png", \ + .symbol = "/usr/share/platsch/spinner.png", \ + .type = "Rotation", \ + .fps = 20, \ + .frames = 0, \ + .text_x = 100, \ + .text_y = 100, \ + .text_font = "Sans", \ + .text_size = 30, \ + .text = "Now loading..." \ +} +#endif -- 2.34.1