From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 12 Jun 2024 11:26:55 +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 1sHKFr-004ji3-0P for lore@lore.pengutronix.de; Wed, 12 Jun 2024 11:26:55 +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-0004Lr-39; Wed, 12 Jun 2024 11:26:46 +0200 Received: from mail-db3eur04on2041.outbound.protection.outlook.com ([40.107.6.41] helo=EUR04-DB3-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 1sHFGG-00038O-6e for oss-tools@pengutronix.de; Wed, 12 Jun 2024 06:07:02 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+Zgfvnof7NJsbiMPPKeqyG2etS/4o/pHyFIWpp79hIulcCro2HbYPAmekZTrO6L3ciXlSdNn3t0iIlEU9tJ4deagKKPlqVc6jC3W8B0In7R9gN6m5VUDjG3zvAZkLYYK/wtc2TuYu14TMzlPgu2hTPNhtY4kXfDFgpgKQJxhT2KP1Tllj+6smGKSzPB9PmXQvTaFUyai10asAKAM4WCjE7jo0GKpCGKiag4n0QLlqvz+NowA0NTUYsyQq3Zru9tnjcp55/VSKr8nxmhLGSiewc24zjT8KWp5QjoBoGbmeQwg1NDiJzb96tIDBiGD5G3Ir3TatVdcZJcGfc3himFjw== 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=UTPnEroPg41OJBHmwVNR/9hELkGmbDs695ZoCEIfvGdEn7ChbFniL9li/f/TCzbw+JYBO6yB4x8Mmk6b/loDtpkSbxjB57OfGrX6K1mPGtN1LoCfHAWtQXbS/CZhn6STDuLqkAnZ5Z5US7zf1ZUtEkBZsvDTV7xWPX5Khc2/9bN7fbNm5ww/TQjur2ld+06NyIc8e3az6sT2i/HmM27hsUBGwCITu1sQVsGUPpobk/LH3ApxBoACFozhI0Yzim5+LylQRG3MPesCDPb2NLD8NzB56mnbEmgnUGjLmA1r5qx5xhgXBsDuDDJKxaeuDrf7PqUK33rXT781AEHy/VOizQ== 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=s1ZYtMTP0x8ZuuZN+UIGUVnW4hxxkG8MfXhejRWamP54XFFATXhdwRzYnS7auO2K0VAvj4ceI/TNU0pItm9CU7eynfoYcTVVGST2JRY5bQHA5Ql/50z9I7KvEtsIOZNeUvGp3AFSMrWgadWbrrCHAqNzuxbdZ47KSYr46rQkhA0= Received: from AM6PR08CA0026.eurprd08.prod.outlook.com (2603:10a6:20b:c0::14) by PA2PR06MB9657.eurprd06.prod.outlook.com (2603:10a6:102:415::18) 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 04:06:58 +0000 Received: from AM2PEPF0001C712.eurprd05.prod.outlook.com (2603:10a6:20b:c0:cafe::e3) by AM6PR08CA0026.outlook.office365.com (2603:10a6:20b:c0::14) 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 04:06:58 +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 AM2PEPF0001C712.mail.protection.outlook.com (10.167.16.182) 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 04:06:58 +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 06:06:56 +0200 From: LI Qingwu To: Qing-wu.Li@leica-geosystems.com.cn, oss-tools@pengutronix.de Date: Wed, 12 Jun 2024 06:06:54 +0200 Message-Id: <20240612040654.2472120-3-Qing-wu.Li@leica-geosystems.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612040654.2472120-1-Qing-wu.Li@leica-geosystems.com.cn> References: <20240612040654.2472120-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 04:06:56.0369 (UTC) FILETIME=[F71D7E10:01DABC7D] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM2PEPF0001C712:EE_|PA2PR06MB9657:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d9f68f3-bab4-4050-53d3-08dc8a951a95 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?bWk1cEpxUmpsQ0E1OTQyQS9rUk0xTVFkQytseEV4MWJFV0hjNURKSVhWc2ly?= =?utf-8?B?SGdRU2FvK1BvQ1JJSkRmeE9kd2FveGtnYlN0dEN4RFFVOHdHeVR3SFVsN1Bl?= =?utf-8?B?OXVkeEFZUGNQU29ORlIwSW91a1FFR05HQnY3V3ZyVGtFc1VBR3grR1BpN0wx?= =?utf-8?B?SWE0a3pVcWpWWXVSMVNoOGlIT2lvcWF4TWFpMDJmK2ZBRGpHT1NEN2FVVXFG?= =?utf-8?B?OW8za2dNY1k4L0tmUXZneTFhS3Q3OExqbm1mWXVVY0Vyb2orVFp4dURqem5J?= =?utf-8?B?VWNuTk1MZFc3akduRUpwdW9oL0YzcUM2KytLQ0RKS1k1RklDdmRCYzFmZHRa?= =?utf-8?B?U1RkOE11UFdrMnRaTGozU1A0UVE3QkU0Q1N3V1pJUGtuL1NrUFhEWXJUV29Y?= =?utf-8?B?cWE4U05IU0x6TkJ1T0tFV2ZCcTZ1eDYrM0NtcnFQOUpyb1UvOExJWnkxUDZo?= =?utf-8?B?KzczSG12WkRZV01nTkdwRFFXRExSWC9FWlhxc3puYU9SQlZ4MmxqNVlpMkhB?= =?utf-8?B?ZzdMeUtENzJLdktJSjRleEJtY05rTFA3VGxHTFM0dVZVK1VHbmpPTkpvbWZr?= =?utf-8?B?YWhzZTZnNE93aUs2WmdGT2ZwbWt2OGRpeG8vbTU1REdFMXY2dDBrMkU0Z1lJ?= =?utf-8?B?UUo2ancxNEs5T1RwOS9hUkZrK29nMTFYTjNFM25QeXNHQWdvUXZVU2JFRHJp?= =?utf-8?B?aFcvRGhrOU5Ic2VpY0Y5cXNPcUF6SjYyaGNGdy82cVpZb3RuZEtFVTZ5MGVn?= =?utf-8?B?YVdIMVJvbHBBRFpqeThFN1psb0hwbXMwaHJ0WTR3dW9zZlMrOG16RFJ4ME80?= =?utf-8?B?MXdNWDVwVVZUOElRZXJTTFBnS2hnN3JpenppYnpqTzB0VndwM1F2aUdXRnVi?= =?utf-8?B?R0lOem1sZ05TMENwWjcramhXVno4MDBUYVFmQUVrZ2lVaTVsRm5JVDl6Ri9E?= =?utf-8?B?WHNBQXpEZ0k3MGlPWW5DV015clN6ZnlCanFCN1NuTnZmNDcvVmpNZFR3Z1Ix?= =?utf-8?B?OGlPUHlTd3Y5YmEzYXA3QVBhRnhFNkxIR2RySnlyYUI5L3VhTXBkTCs0S29h?= =?utf-8?B?Vnk5WFpyckMvaVJGR2RxdkhSNUs3bXllNXo2cVBSWjRHbXR3SUx3Umo0V0VP?= =?utf-8?B?TllkRE5FZmlqdlYwRVFzVWdxRG1KVk11TEZGOVBpaVFIV0JuRW1XSjlFcm5L?= =?utf-8?B?TW5GeGt5S1ZXRVdzSnBBUzd4V0JsckJranhYZm9RU21MRTJLM0Y4Q2FhVkdy?= =?utf-8?B?a2gvM2xScGp3TGV1QVk5NzVveXNHUnVtTlZueE1ZZHdNdHJROVY0RXRqVkhO?= =?utf-8?B?SFhlOUN1Nmtxc2Y2aE5FZjR2MDM4Z1AyOURCcTY5UXhwRVNSc2YwT3l1RG1p?= =?utf-8?B?K0hBcHUvYmhEeTlsZGVacStlY0VmL0FxelNISWFEZFNFekFJcTN0ZGptQldP?= =?utf-8?B?Slg5NFdkL3J2cUNiZUJqN0c1a0tJYjA3TSsxOGZ3Q3IwWldoTW4yanRTR0Fp?= =?utf-8?B?cXRvYlVMTC8zeGFJOWF1Z2Z6VVROYWlobXVPMWpWQUZZZVFCU1lCbUhSSWhH?= =?utf-8?B?N1FYd2duS1g5bzFoRXREWG0zWG5zRHpIREh5cGpuSGx6MlVwUlF1YVVXKzBN?= =?utf-8?B?NTZuRFJGMDNYd2VvbWpweWdrS0RBNXZXYi9COUIzNy9NUnRVV1NuUzhGQ251?= =?utf-8?B?cnh5K2gyeUJobG5KUkcyT05KczBhMi94Q1NZT2ExYUkxUWsrbm9HdStuaTBR?= =?utf-8?B?Y1hLUThnUWg4aVpzQ2M4SGRMRnJIZXJKNEN5emd0NDNKeVBrcW5IdUMrOFFr?= =?utf-8?B?ODZLaCtiZnA3elpGTG5aeGY2TXZzaDVMZUZCQ0g0V3ZFK2FmZnJVdjlXVmxy?= =?utf-8?B?S2VQUjgyRkRkTmUyUmhEV1Y5cE5sR0o3ZkFTalJHNmJka0E9PQ==?= 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 04:06:58.0209 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d9f68f3-bab4-4050-53d3-08dc8a951a95 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: AM2PEPF0001C712.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR06MB9657 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_DNSWL_NONE, 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