From 91abc08d3b8253ca882e485db106910d56bf9b1a Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 21 Aug 2009 19:21:53 -0400 Subject: [PATCH] [libplybootsplash] Add pixel-display class This is the graphical output portion of the window class. This commit and the previous few commits lay the foundation needed for dropping the window class and getting multi-head rendering support. --- src/libplybootsplash/Makefile.am | 2 + src/libplybootsplash/ply-pixel-display.c | 175 +++++++++++++++++++++++ src/libplybootsplash/ply-pixel-display.h | 68 +++++++++ 3 files changed, 245 insertions(+) create mode 100644 src/libplybootsplash/ply-pixel-display.c create mode 100644 src/libplybootsplash/ply-pixel-display.h diff --git a/src/libplybootsplash/Makefile.am b/src/libplybootsplash/Makefile.am index 25c48539..19479e21 100644 --- a/src/libplybootsplash/Makefile.am +++ b/src/libplybootsplash/Makefile.am @@ -17,6 +17,7 @@ libplybootsplash_HEADERS = \ ply-label.h \ ply-label-plugin.h \ ply-pixel-buffer.h \ + ply-pixel-display.h \ ply-progress-animation.h \ ply-progress-bar.h \ ply-renderer.h \ @@ -47,6 +48,7 @@ libplybootsplash_la_SOURCES = \ ply-progress-bar.c \ ply-throbber.c \ ply-animation.c \ + ply-pixel-display.c \ ply-progress-animation.c \ ply-text-display.c \ ply-text-progress-bar.c \ diff --git a/src/libplybootsplash/ply-pixel-display.c b/src/libplybootsplash/ply-pixel-display.c new file mode 100644 index 00000000..37151203 --- /dev/null +++ b/src/libplybootsplash/ply-pixel-display.c @@ -0,0 +1,175 @@ +/* ply-pixel-display.c - APIs for putting up a pixel + * + * Copyright (C) 2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: Ray Strode + */ +#include "config.h" +#include "ply-pixel-display.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ply-event-loop.h" +#include "ply-list.h" +#include "ply-logger.h" +#include "ply-pixel-buffer.h" +#include "ply-renderer.h" +#include "ply-utils.h" + +struct _ply_pixel_display +{ + ply_event_loop_t *loop; + + ply_renderer_t *renderer; + ply_renderer_head_t *head; + + unsigned long width; + unsigned long height; + + ply_pixel_display_draw_handler_t draw_handler; + void *draw_handler_user_data; + + int pause_count; + +}; + +ply_pixel_display_t * +ply_pixel_display_new (ply_renderer_t *renderer, + ply_renderer_head_t *head) +{ + ply_pixel_display_t *display; + ply_pixel_buffer_t *pixel_buffer; + ply_rectangle_t size; + + display = calloc (1, sizeof (ply_pixel_display_t)); + + display->loop = ply_event_loop_get_default (); + display->renderer = renderer; + display->head = head; + + pixel_buffer = ply_renderer_get_buffer_for_head (renderer, head); + ply_pixel_buffer_get_size (pixel_buffer, &size); + + display->width = size.width; + display->height = size.height; + + return display; +} + +unsigned long +ply_pixel_display_get_width (ply_pixel_display_t *display) +{ + return display->width; +} + +unsigned long +ply_pixel_display_get_height (ply_pixel_display_t *display) +{ + return display->height; +} + +static void +ply_pixel_display_flush (ply_pixel_display_t *display) +{ + if (display->pause_count > 0) + return; + + ply_renderer_flush_head (display->renderer, display->head); +} + +void +ply_pixel_display_pause_updates (ply_pixel_display_t *display) +{ + assert (display != NULL); + + display->pause_count++; +} + +void +ply_pixel_display_unpause_updates (ply_pixel_display_t *display) +{ + assert (display != NULL); + + display->pause_count--; + + ply_pixel_display_flush (display); +} + +void +ply_pixel_display_draw_area (ply_pixel_display_t *display, + int x, + int y, + int width, + int height) +{ + + ply_pixel_buffer_t *pixel_buffer; + + pixel_buffer = ply_renderer_get_buffer_for_head (display->renderer, + display->head); + + if (display->draw_handler != NULL) + { + ply_rectangle_t clip_area; + + clip_area.x = x; + clip_area.y = y; + clip_area.width = width; + clip_area.height = height; + ply_pixel_buffer_push_clip_area (pixel_buffer, &clip_area); + display->draw_handler (display->draw_handler_user_data, + pixel_buffer, + x, y, width, height, display); + ply_pixel_buffer_pop_clip_area (pixel_buffer); + } + + ply_pixel_display_flush (display); +} + +void +ply_pixel_display_free (ply_pixel_display_t *display) +{ + if (display == NULL) + return; + + free (display); +} + +void +ply_pixel_display_set_draw_handler (ply_pixel_display_t *display, + ply_pixel_display_draw_handler_t draw_handler, + void *user_data) +{ + assert (display != NULL); + + display->draw_handler = draw_handler; + display->draw_handler_user_data = user_data; +} + +/* vim: set ts=4 sw=4 et ai ci cino={.5s,^-2,+.5s,t0,g0,e-2,n-2,p2s,(0,=.5s,:.5s */ diff --git a/src/libplybootsplash/ply-pixel-display.h b/src/libplybootsplash/ply-pixel-display.h new file mode 100644 index 00000000..98a6b3c8 --- /dev/null +++ b/src/libplybootsplash/ply-pixel-display.h @@ -0,0 +1,68 @@ +/* ply-pixel-display.h - APIs for displaying pixels + * + * Copyright (C) 2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written By: Ray Strode + */ +#ifndef PLY_PIXEL_DISPLAY_H +#define PLY_PIXEL_DISPLAY_H + +#include +#include +#include + +#include "ply-event-loop.h" +#include "ply-pixel-buffer.h" +#include "ply-renderer.h" + +typedef struct _ply_pixel_display ply_pixel_display_t; + +typedef void (* ply_pixel_display_draw_handler_t) (void *user_data, + ply_pixel_buffer_t *pixel_buffer, + int x, + int y, + int width, + int height, + ply_pixel_display_t *pixel_display); + +#ifndef PLY_HIDE_FUNCTION_DECLARATIONS +ply_pixel_display_t *ply_pixel_display_new (ply_renderer_t *renderer, + ply_renderer_head_t *head); + +void ply_pixel_display_free (ply_pixel_display_t *display); + +unsigned long ply_pixel_display_get_width (ply_pixel_display_t *display); +unsigned long ply_pixel_display_get_height (ply_pixel_display_t *display); + +void ply_pixel_display_set_draw_handler (ply_pixel_display_t *display, + ply_pixel_display_draw_handler_t draw_handler, + void *user_data); + +void ply_pixel_display_draw_area (ply_pixel_display_t *display, + int x, + int y, + int width, + int height); + +void ply_pixel_display_pause_updates (ply_pixel_display_t *display); +void ply_pixel_display_unpause_updates (ply_pixel_display_t *display); + +#endif + +#endif /* PLY_PIXEL_DISPLAY_H */ +/* vim: set ts=4 sw=4 et ai ci cino={.5s,^-2,+.5s,t0,g0,e-2,n-2,p2s,(0,=.5s,:.5s */