summaryrefslogtreecommitdiff
path: root/src/libplybootsplash/ply-pixel-display.c
blob: 37151203b6d1dd63ad34c38ca1fef3cf62bb44a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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 <rstrode@redhat.com>
 */
#include "config.h"
#include "ply-pixel-display.h"

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>

#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 */