aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/software_16_wince/evas_wince_ddraw_buffer.cpp
blob: 944ed53282ecd82d3eecd37e634d8591cac30639 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

#include <cstdio>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <ddraw.h>

#include "evas_common.h"
#include "evas_engine.h"


typedef LONG (*fct_DirectDrawCreate)(LPGUID, LPUNKNOWN *, LPUNKNOWN *);

fct_DirectDrawCreate lib_DirectDrawCreate;

typedef struct Evas_Engine_WinCE_DDraw_Priv Evas_Engine_WinCE_DDraw_Priv;

struct Evas_Engine_WinCE_DDraw_Priv
{
   HMODULE             module;
   LPDIRECTDRAW        object;
   LPDIRECTDRAWSURFACE surface;
   int                 width;
   int                 height;
   int                 stride;
};

void *
evas_software_wince_ddraw_init(HWND window,
                               int  width,
                               int  height)
{
   DDSURFACEDESC                 surface_desc;
   Evas_Engine_WinCE_DDraw_Priv *priv;
   HRESULT                       res;

   priv = (Evas_Engine_WinCE_DDraw_Priv *)malloc(sizeof(Evas_Engine_WinCE_DDraw_Priv));
   if (!priv)
     return NULL;
   
   priv->module = LoadLibrary(L"ddraw.dll");
   if (!priv->module)
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not load ddraw.dll\n");
        goto free_priv;
     }

   lib_DirectDrawCreate = (fct_DirectDrawCreate)GetProcAddress(priv->module, L"DirectDrawCreate");
   if (!lib_DirectDrawCreate)
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not initialize DirectDraw\n");
        goto free_lib;
     }

   res = lib_DirectDrawCreate(NULL, (IUnknown**)&priv->object, NULL);
   if (FAILED(res))
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not create DirectDraw object\n");
        goto free_lib;
     }

   res = priv->object->SetCooperativeLevel(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
   if (FAILED(res))
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not set window to fullscreen\n");
        goto release_object;
     }

   memset(&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   surface_desc.dwFlags = DDSD_CAPS;
   surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

   res = priv->object->CreateSurface(&surface_desc, &priv->surface, NULL);
   if (FAILED(res))
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not create surface\n");
        goto release_object;
     }

   memset(&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   res = priv->surface->Lock(NULL, &surface_desc, DDLOCK_READONLY, NULL);
   if (FAILED(res))
     {
        fprintf(stderr, "[Evas] [Engine] [WinCE DDraw] Can not lock surface\n");
        goto release_surface;
     }

   priv->width = surface_desc.dwWidth;
   priv->height = surface_desc.dwHeight;
   priv->stride = surface_desc.lPitch / 2;

   if ((priv->width != width) ||
       (priv->height != height))
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Size mismatch\n");
        fprintf(stderr, "[Engine] [WinCE DDraw] asked : %dx%d\n", width, height);
        fprintf(stderr, "[Engine] [WinCE DDraw] got   : %dx%d\n", priv->width, priv->height);
        goto release_surface;
     }

   res = priv->surface->Unlock(NULL);
   if (FAILED(res))
     {
        fprintf(stderr, "[Engine] [WinCE DDraw] Can not unlock surface\n");
        goto release_surface;
     }

   return priv;

 release_surface:
   priv->surface->Release();
 release_object:
   priv->object->Release();
 free_lib:
   FreeLibrary(priv->module);
 free_priv:
   free(priv);

  return 0;
}

void
evas_software_wince_ddraw_shutdown(void *priv)
{
   ((Evas_Engine_WinCE_DDraw_Priv *)priv)->surface->Release();
   ((Evas_Engine_WinCE_DDraw_Priv *)priv)->object->Release();
   FreeLibrary(((Evas_Engine_WinCE_DDraw_Priv *)priv)->module);
   free(priv);
}


FB_Output_Buffer *
evas_software_wince_ddraw_output_buffer_new(void *priv,
                                            int   width,
                                            int   height)
{
   FB_Output_Buffer *fbob;
   void             *buffer;

   fbob = (FB_Output_Buffer *)calloc(1, sizeof(FB_Output_Buffer));
   if (!fbob) return NULL;

   buffer = malloc (width * height * 2); /* we are sure to have 16bpp */
   if (!buffer)
     {
        free(fbob);
        return NULL;
     }

   fbob->priv = priv;

   fbob->im = (Soft16_Image *) evas_cache_image_data(evas_common_soft16_image_cache_get(), width, height, (DATA32 *)buffer, 0, EVAS_COLORSPACE_RGB565_A5P);
   if (fbob->im)
     fbob->im->stride = ((Evas_Engine_WinCE_DDraw_Priv *)priv)->stride;

   return fbob;
}

void
evas_software_wince_ddraw_output_buffer_free(FB_Output_Buffer *fbob)
{
   free(fbob->im->pixels);
   free(fbob);
}

void
evas_software_wince_ddraw_output_buffer_paste(FB_Output_Buffer *fbob)
{
   DDSURFACEDESC                 surface_desc;
   Evas_Engine_WinCE_DDraw_Priv *priv;
   HRESULT                       res;

   priv = (Evas_Engine_WinCE_DDraw_Priv *)fbob->priv;

   memset(&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   res = priv->surface->Lock(NULL, &surface_desc, DDLOCK_WRITEONLY, NULL);
   if (FAILED(res))
     return;

   if ((fbob->im->cache_entry.w == surface_desc.dwWidth) &&
       (fbob->im->cache_entry.h == surface_desc.dwHeight))
     memcpy(surface_desc.lpSurface, fbob->im->pixels,
            surface_desc.dwWidth * surface_desc.dwHeight * 2);

   priv->surface->Unlock(NULL);
}

void
evas_software_wince_ddraw_surface_resize(FB_Output_Buffer *fbob)
{
}