move around - flatter.
[profile/ivi/evas.git] / src / modules / engines / software_ddraw / evas_ddraw_buffer.c
1 #include <string.h>
2
3 #include "evas_common.h"
4 #include "evas_engine.h"
5
6
7 DD_Output_Buffer *
8 evas_software_ddraw_output_buffer_new(int   depth,
9                                       int   width,
10                                       int   height,
11                                       void *data)
12 {
13    DD_Output_Buffer *ddob;
14
15    ddob = calloc(1, sizeof(DD_Output_Buffer));
16    if (!ddob) return NULL;
17
18    ddob->data = data;
19    ddob->depth = depth;
20    ddob->width = width;
21    ddob->height = height;
22    ddob->pitch = width * depth / 8;
23
24    if (!ddob->data)
25      {
26         ddob->data = malloc(ddob->pitch * height);
27         if (!ddob->data)
28           {
29             free(ddob);
30             return NULL;
31           }
32      }
33
34    return ddob;
35 }
36
37 void
38 evas_software_ddraw_output_buffer_free(DD_Output_Buffer *ddob)
39 {
40    if (ddob->data) free(ddob->data);
41    free(ddob);
42 }
43
44 void
45 evas_software_ddraw_output_buffer_paste(DD_Output_Buffer *ddob,
46                                         void             *ddraw_data,
47                                         int               ddraw_width,
48                                         int               ddraw_height,
49                                         int               ddraw_pitch,
50                                         int               ddraw_depth,
51                                         int               x,
52                                         int               y)
53 {
54    DATA8 *dd_data;
55    DATA8 *evas_data;
56    int    width;
57    int    height;
58    int    pitch;
59    int    j;
60
61    if ((x >= ddraw_width) || (y >= ddraw_height))
62      return;
63
64    /* compute the size of the data to copy on the back surface */
65    width = ((x + ddob->width) > ddraw_width)
66      ? ddraw_width - x
67      : ddob->width;
68    height = ((y + ddob->height) > ddraw_height)
69      ? ddraw_height - y
70      : ddob->height;
71    pitch = width * ddob->depth / 8;
72
73    dd_data = (DATA8 *)ddraw_data + y * ddraw_pitch + x * ddraw_depth;
74    evas_data = (unsigned char *)ddob->data;
75    for (j = 0; j < height; j++, evas_data += ddob->pitch, dd_data += ddraw_pitch)
76      memcpy(dd_data, evas_data, pitch);
77 }
78
79 DATA8 *
80 evas_software_ddraw_output_buffer_data(DD_Output_Buffer *ddob,
81                                        int              *bytes_per_line_ret)
82 {
83    if (bytes_per_line_ret) *bytes_per_line_ret = ddob->pitch;
84    return ddob->data;
85 }
86
87 int
88 evas_software_ddraw_output_buffer_depth(DD_Output_Buffer *ddob)
89 {
90    return ddob->depth;
91 }