summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/software_gdi/evas_gdi_buffer.c
blob: 8d9c1ac425af194fdc08dc0644f195d736125678 (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
#include <string.h>

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

Gdi_Output_Buffer *
evas_software_gdi_output_buffer_new(HDC             dc,
                                    BITMAPINFO_GDI *bitmap_info,
                                    int             width,
                                    int             height,
                                    void           *data)
{
   Gdi_Output_Buffer *gdiob;

   gdiob = calloc(1, sizeof(Gdi_Output_Buffer));
   if (!gdiob) return NULL;

   if (!data)
     {
        bitmap_info->bih.biWidth = width;
        bitmap_info->bih.biHeight = -height;
        bitmap_info->bih.biSizeImage = 4 * width * height;
        gdiob->bitmap = CreateDIBSection(dc,
                                         (const BITMAPINFO *)bitmap_info,
                                         DIB_RGB_COLORS,
                                         (void **)(&data),
                                         NULL,
                                         0);
        if (!gdiob->bitmap)
          {
             free(gdiob);
             return NULL;
          }
     }

   gdiob->bitmap_info = bitmap_info;
   gdiob->dc = dc;
   gdiob->data = data;
   gdiob->width = width;
   gdiob->height = height;
   gdiob->pitch = width * 4;

   return gdiob;
}

void
evas_software_gdi_output_buffer_free(Gdi_Output_Buffer *gdiob)
{
   DeleteObject(gdiob->bitmap);
   free(gdiob);
}

void
evas_software_gdi_output_buffer_paste(Gdi_Output_Buffer *gdiob,
                                      int                x,
                                      int                y)
{
   HDC     dc;
   HGDIOBJ obj;

   dc = CreateCompatibleDC(gdiob->dc);
   if (dc)
     {
        obj = SelectObject(dc, gdiob->bitmap);
        BitBlt(gdiob->dc,
               x, y,
               gdiob->width, gdiob->height,
               dc,
               0, 0,
               SRCCOPY);
        SelectObject(dc, obj);
        DeleteDC(dc);
     }
}

DATA8 *
evas_software_gdi_output_buffer_data(Gdi_Output_Buffer *gdiob,
                                     int               *pitch)
{
   if (pitch) *pitch = gdiob->pitch;
   return gdiob->data;
}