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