summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/software_ddraw/evas_ddraw_buffer.c
blob: 3b94686d68d02ff56072c6c3054f264af900eacd (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
#include <string.h>

#include "evas_common_private.h"
#include "evas_engine.h"


DD_Output_Buffer *
evas_software_ddraw_output_buffer_new(int   depth,
                                      int   width,
                                      int   height,
                                      void *data)
{
   DD_Output_Buffer *ddob;

   ddob = calloc(1, sizeof(DD_Output_Buffer));
   if (!ddob) return NULL;

   ddob->data = data;
   ddob->depth = depth;
   ddob->width = width;
   ddob->height = height;
   ddob->pitch = width * depth / 8;
   ddob->psize = ddob->pitch * height;

   if (!ddob->data)
     {
        ddob->data = malloc(ddob->pitch * height);
        if (!ddob->data)
          {
            free(ddob);
            return NULL;
          }
     }

   return ddob;
}

void
evas_software_ddraw_output_buffer_free(DD_Output_Buffer *ddob)
{
   if (ddob->data) free(ddob->data);
   free(ddob);
}

void
evas_software_ddraw_output_buffer_paste(DD_Output_Buffer *ddob,
                                        void             *ddraw_data,
                                        int               ddraw_width,
                                        int               ddraw_height,
                                        int               ddraw_pitch,
                                        int               ddraw_depth,
                                        int               x,
                                        int               y)
{
   DATA8 *dd_data;
   DATA8 *evas_data;
   int    width;
   int    height;
   int    pitch;
   int    j;

   if ((x >= ddraw_width) || (y >= ddraw_height))
     return;

   /* compute the size of the data to copy on the back surface */
   width = ((x + ddob->width) > ddraw_width)
     ? ddraw_width - x
     : ddob->width;
   height = ((y + ddob->height) > ddraw_height)
     ? ddraw_height - y
     : ddob->height;
   pitch = width * ddob->depth / 8;

   dd_data = (DATA8 *)ddraw_data + y * ddraw_pitch + x * ddraw_depth;
   evas_data = (unsigned char *)ddob->data;
   for (j = 0; j < height; j++, evas_data += ddob->pitch, dd_data += ddraw_pitch)
     memcpy(dd_data, evas_data, pitch);
}

DATA8 *
evas_software_ddraw_output_buffer_data(DD_Output_Buffer *ddob,
                                       int              *bytes_per_line_ret)
{
   if (bytes_per_line_ret) *bytes_per_line_ret = ddob->pitch;
   return ddob->data;
}

int
evas_software_ddraw_output_buffer_depth(DD_Output_Buffer *ddob)
{
   return ddob->depth;
}