summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-02 21:07:10 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-02 21:07:10 +0000
commit09358c71d149fec793a8cc7f72a70d417ccae9d6 (patch)
tree6d2e8658b95dd8a777cfe443f46e515311e58dba
parent1eac4b2f476d6484fd606ae3c84881a3c29ac09e (diff)
merge: remove direct3d (there are some remaining files, they will be deleted with ecore merge)
SVN revision: 79989
-rw-r--r--pc/evas-direct3d.pc.in3
-rw-r--r--src/lib/evas/file/evas_module.c16
-rw-r--r--src/modules/evas/engines/direct3d/Evas_Engine_Direct3D.h36
-rw-r--r--src/modules/evas/engines/direct3d/array.h305
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_buffer.c0
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_context.cpp8
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_context.h22
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_device.cpp393
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_device.h87
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_image_cache.cpp436
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_image_cache.h108
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_main.cpp774
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object.cpp12
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object.h35
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_font.cpp231
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_font.h113
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_image.cpp320
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_image.h127
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_line.cpp60
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_line.h37
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_rect.cpp65
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_object_rect.h37
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_scene.cpp33
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_scene.h63
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_shader_pack.cpp344
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_shader_pack.h75
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_vertex_buffer_cache.cpp154
-rw-r--r--src/modules/evas/engines/direct3d/evas_direct3d_vertex_buffer_cache.h60
-rw-r--r--src/modules/evas/engines/direct3d/evas_engine.c505
-rw-r--r--src/modules/evas/engines/direct3d/evas_engine.h125
-rw-r--r--src/modules/evas/engines/direct3d/ref.h210
31 files changed, 0 insertions, 4794 deletions
diff --git a/pc/evas-direct3d.pc.in b/pc/evas-direct3d.pc.in
deleted file mode 100644
index 493f8cce07..0000000000
--- a/pc/evas-direct3d.pc.in
+++ /dev/null
@@ -1,3 +0,0 @@
1Name: evas-direct3d
2Description: Evas Direct3D engine
3Version: @VERSION@
diff --git a/src/lib/evas/file/evas_module.c b/src/lib/evas/file/evas_module.c
index 27ac42d5d3..8c693ad2d9 100644
--- a/src/lib/evas/file/evas_module.c
+++ b/src/lib/evas/file/evas_module.c
@@ -93,7 +93,6 @@ evas_module_paths_init(void)
93 { evas_##Tn##_##Name##_init, evas_##Tn##_##Name##_shutdown } 93 { evas_##Tn##_##Name##_init, evas_##Tn##_##Name##_shutdown }
94 94
95EVAS_EINA_STATIC_MODULE_DEFINE(engine, buffer); 95EVAS_EINA_STATIC_MODULE_DEFINE(engine, buffer);
96EVAS_EINA_STATIC_MODULE_DEFINE(engine, direct3d);
97EVAS_EINA_STATIC_MODULE_DEFINE(engine, directfb); 96EVAS_EINA_STATIC_MODULE_DEFINE(engine, directfb);
98EVAS_EINA_STATIC_MODULE_DEFINE(engine, fb); 97EVAS_EINA_STATIC_MODULE_DEFINE(engine, fb);
99EVAS_EINA_STATIC_MODULE_DEFINE(engine, gl_x11); 98EVAS_EINA_STATIC_MODULE_DEFINE(engine, gl_x11);
@@ -132,9 +131,6 @@ static const struct {
132#ifdef EVAS_STATIC_BUILD_BUFFER 131#ifdef EVAS_STATIC_BUILD_BUFFER
133 EVAS_EINA_STATIC_MODULE_USE(engine, buffer), 132 EVAS_EINA_STATIC_MODULE_USE(engine, buffer),
134#endif 133#endif
135#ifdef EVAS_STATIC_BUILD_DIRECT3D
136 EVAS_EINA_STATIC_MODULE_USE(engine, direct3d),
137#endif
138#ifdef EVAS_STATIC_BUILD_DIRECTFB 134#ifdef EVAS_STATIC_BUILD_DIRECTFB
139 EVAS_EINA_STATIC_MODULE_USE(engine, directfb), 135 EVAS_EINA_STATIC_MODULE_USE(engine, directfb),
140#endif 136#endif
@@ -150,18 +146,6 @@ static const struct {
150#ifdef EVAS_STATIC_BUILD_PSL1GHT 146#ifdef EVAS_STATIC_BUILD_PSL1GHT
151 EVAS_EINA_STATIC_MODULE_USE(engine, psl1ght), 147 EVAS_EINA_STATIC_MODULE_USE(engine, psl1ght),
152#endif 148#endif
153#ifdef EVAS_STATIC_BUILD_SOFTWARE_GDI
154 EVAS_EINA_STATIC_MODULE_USE(engine, software_gdi),
155#endif
156#ifdef EVAS_STATIC_BUILD_SOFTWARE_DDRAW
157 EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw),
158#endif
159#ifdef EVAS_STATIC_BUILD_SOFTWARE_8
160 EVAS_EINA_STATIC_MODULE_USE(engine, software_8),
161#endif
162#ifdef EVAS_STATIC_BUILD_SOFTWARE_8_X11
163 EVAS_EINA_STATIC_MODULE_USE(engine, software_8_x11),
164#endif
165#ifdef EVAS_STATIC_BUILD_SOFTWARE_DDRAW 149#ifdef EVAS_STATIC_BUILD_SOFTWARE_DDRAW
166 EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw), 150 EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw),
167#endif 151#endif
diff --git a/src/modules/evas/engines/direct3d/Evas_Engine_Direct3D.h b/src/modules/evas/engines/direct3d/Evas_Engine_Direct3D.h
deleted file mode 100644
index f9b7a9c592..0000000000
--- a/src/modules/evas/engines/direct3d/Evas_Engine_Direct3D.h
+++ /dev/null
@@ -1,36 +0,0 @@
1#ifndef __EVAS_ENGINE_DIRECT3D_H__
2#define __EVAS_ENGINE_DIRECT3D_H__
3
4
5#define WIN32_LEAN_AND_MEAN
6#include <windows.h>
7#undef WIN32_LEAN_AND_MEAN
8
9typedef struct _Evas_Engine_Info_Direct3D Evas_Engine_Info_Direct3D;
10
11struct _Evas_Engine_Info_Direct3D
12{
13 /* PRIVATE - don't mess with this baby or evas will poke its tongue out */
14 /* at you and make nasty noises */
15 Evas_Engine_Info magic;
16
17 struct {
18 HWND window;
19 int rotation;
20 int depth;
21 int fullscreen : 1;
22 int layered : 1;
23 } info;
24
25 struct {
26 unsigned short width;
27 unsigned short height;
28 unsigned char *mask;
29 } *shape;
30
31 /* non-blocking or blocking mode */
32 Evas_Engine_Render_Mode render_mode;
33};
34
35
36#endif /* __EVAS_ENGINE_DIRECT3D_H__ */
diff --git a/src/modules/evas/engines/direct3d/array.h b/src/modules/evas/engines/direct3d/array.h
deleted file mode 100644
index dfd80b7236..0000000000
--- a/src/modules/evas/engines/direct3d/array.h
+++ /dev/null
@@ -1,305 +0,0 @@
1#ifndef __ARRAY_H__
2#define __ARRAY_H__
3
4#include "ref.h"
5#include <assert.h>
6
7template <class T>
8class TArray : virtual public Referenc
9{
10public:
11 TArray();
12 TArray(const TArray<T> &arr)
13 {
14 data = NULL;
15 size = num = 0;
16 block_size = arr.block_size;
17 keep_order = arr.keep_order;
18
19 //assert(0 && "Direct assignment for arrays is NOT allowed");
20 // risky probably, but anyway
21 arr.CopyTo(*this);
22 }
23 ~TArray();
24
25 bool Allocate(int new_num);
26 bool Resize(int new_size = 0);
27 bool Add(T &el);
28 bool Add(const T &el);
29
30 inline T &operator[](int i);
31 inline const T &operator[](int i) const;
32 inline const TArray<T> &operator =(const TArray<T> &arr)
33 {
34 block_size = arr.block_size;
35 keep_order = arr.keep_order;
36
37 //assert(0 && "Direct assignment for arrays is NOT allowed");
38 // risky probably, but anyway
39 arr.CopyTo(*this);
40 return *this;
41 }
42
43 T *Last()
44 {
45 if (num > 0)
46 return &data[num - 1];
47 return NULL;
48 }
49
50 inline int Length() const
51 {
52 return num;
53 }
54
55 inline int Size() const
56 {
57 return size;
58 }
59
60 inline int BlockSize() const
61 {
62 return block_size;
63 }
64
65 inline T *Data()
66 {
67 return data;
68 }
69
70 inline T **DataPtr()
71 {
72 return &data;
73 }
74
75 inline const T *Data() const
76 {
77 return data;
78 }
79
80 inline void SetKeepOrder(bool enable)
81 {
82 keep_order = enable;
83 }
84
85 bool Find(const T &el);
86
87 bool Add(TArray<T> &arr);
88 bool CopyTo(TArray<T> &dest) const;
89 bool Init(const T *arr, int len);
90
91 void Swap(int to, int from);
92 void Replace(int i);
93
94 bool SetBlockSize(int new_size);
95 void Set(T &el);
96 void Set(const T &el);
97
98protected:
99 T *data;
100 int size;
101 int num;
102 int block_size;
103 // Some operations restricted, order of the elements is fixed
104 bool keep_order;
105
106};
107
108namespace Array
109{
110 const int default_block_size = 16;
111 const int max_array_size = 0xffffff;
112}
113
114
115template <class T> TArray<T>::TArray()
116: data(NULL), size(0), num(0), block_size(Array::default_block_size), keep_order(false)
117{
118}
119
120template <class T> TArray<T>::~TArray()
121{
122 if (data != NULL)
123 Resize();
124}
125
126template <class T> bool TArray<T>::Allocate(int new_num)
127{
128 assert(new_num >= 0 && new_num <= Array::max_array_size);
129 if (new_num > size)
130 {
131 if (!Resize(new_num))
132 return false;
133 }
134 num = new_num;
135 return true;
136}
137
138template <class T> bool TArray<T>::Resize(int new_size)
139{
140 assert(new_size >= 0 && new_size <= Array::max_array_size);
141 if (new_size == 0)
142 {
143 delete[] data;
144 data = NULL;
145 size = 0;
146 num = 0;
147 return true;
148 }
149 if (new_size == size)
150 return true;
151
152 T *new_data = new T[new_size];
153 if (new_data == NULL)
154 return false;
155
156 if (data != NULL && num > 0)
157 {
158 //CopyMemory(new_data, data, num * sizeof(T));
159 for (int i = 0; i < num && i < new_size; i++)
160 new_data[i] = data[i];
161 }
162 delete[] data;
163
164 data = new_data;
165 size = new_size;
166 return true;
167}
168
169template <class T> bool TArray<T>::Add(T &el)
170{
171 if (data == NULL)
172 Resize(1);
173
174 if (num < size)
175 {
176 data[num++] = el;
177 return true;
178 }
179 // num >= size
180 int new_size = size + block_size;
181 if (!Resize(new_size))
182 return false;
183
184 data[num++] = el;
185 return true;
186}
187
188template <class T> bool TArray<T>::Add(const T &el)
189{
190 if (data == NULL)
191 Resize(1);
192
193 if (num < size)
194 {
195 data[num++] = *(T *)&el;
196 return true;
197 }
198 // num >= size
199 int new_size = size + block_size;
200 if (!Resize(new_size))
201 return false;
202
203 data[num++] = *(T *)&el;
204 return true;
205}
206
207template <class T> bool TArray<T>::Add(TArray<T> &arr)
208{
209 if (arr.Length() == 0)
210 return true;
211 int numf = num;
212 if (!Allocate(Length() + arr.Length()))
213 return false;
214 CopyMemory(&data[numf], arr.Data(), arr.Length() * sizeof(T));
215 return true;
216}
217
218template <class T> T &TArray<T>::operator [](int i)
219{
220 assert(i >= 0 && i < num);
221 return data[i];
222}
223
224template <class T> const T &TArray<T>::operator [](int i) const
225{
226 assert(i >= 0 && i < num);
227 return data[i];
228}
229
230template <class T> bool TArray<T>::SetBlockSize(int new_size)
231{
232 assert(new_size >= 0 && new_size <= Array::max_array_size);
233 block_size = new_size;
234 return true;
235}
236
237template <class T> void TArray<T>::Set(T &el)
238{
239 for (int i = 0; i < num; i++)
240 data[i] = el;
241}
242
243template <class T> void TArray<T>::Set(const T &el)
244{
245 for (int i = 0; i < num; i++)
246 data[i] = el;
247}
248
249template <class T> bool TArray<T>::CopyTo(TArray<T> &dest) const
250{
251 if (!dest.Resize(size))
252 return false;
253 dest.num = 0;
254 for (int i = 0; i < num; i++)
255 dest.Add(data[i]);
256
257 return true;
258}
259
260template <class T> bool TArray<T>::Init(const T *arr, int len)
261{
262 assert(arr != NULL);
263 if (!Resize(len))
264 return false;
265 num = 0;
266 for (int i = 0; i < len; i++)
267 Add((T)arr[i]);
268
269 return true;
270}
271
272template <class T> void TArray<T>::Swap(int to, int from)
273{
274 assert(to >= 0 && to < num && from >= 0 && from < num);
275 if (keep_order)
276 return;
277 T t = data[to];
278 data[to] = data[from];
279 data[from] = t;
280}
281
282template <class T> void TArray<T>::Replace(int i)
283{
284 assert(i >= 0 && i < num);
285 if (keep_order)
286 return;
287 if (num >= 1)
288 {
289 data[i] = data[num - 1];
290 num--;
291 }
292}
293
294// operator == for type T should be defined
295template <class T> bool TArray<T>::Find(const T &el)
296{
297 for (int i = 0; i < num; i++)
298 {
299 if (data[i] == el)
300 return true;
301 }
302 return false;
303}
304
305#endif // __ARRAY_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_buffer.c b/src/modules/evas/engines/direct3d/evas_direct3d_buffer.c
deleted file mode 100644
index e69de29bb2..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_buffer.c
+++ /dev/null
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_context.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_context.cpp
deleted file mode 100644
index 07cfa3d08b..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_context.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
1
2#include "evas_direct3d_context.h"
3
4D3DContext::D3DContext()
5{
6 color = 0xff000000;
7 color_mul = 0xffffffff;
8}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_context.h b/src/modules/evas/engines/direct3d/evas_direct3d_context.h
deleted file mode 100644
index 763d1890be..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_context.h
+++ /dev/null
@@ -1,22 +0,0 @@
1#ifndef __EVAS_DIRECT3D_CONTEXT_H__
2#define __EVAS_DIRECT3D_CONTEXT_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "evas_direct3d_object.h"
8
9class D3DContext : virtual public Referenc
10{
11public:
12 D3DContext();
13
14public:
15 DWORD color;
16 DWORD color_mul;
17
18 Ref<D3DObject> font;
19
20};
21
22#endif // __EVAS_DIRECT3D_CONTEXT_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_device.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_device.cpp
deleted file mode 100644
index ce0d985565..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_device.cpp
+++ /dev/null
@@ -1,393 +0,0 @@
1//#define ENABLE_LOG_PRINTF
2
3#include "evas_direct3d_device.h"
4
5#include "evas_direct3d_vertex_buffer_cache.h"
6
7D3DDevice::D3DDevice()
8{
9 ResetParams();
10}
11
12bool D3DDevice::Init(HWND window, int depth, bool fullscreen)
13{
14 D3DPRESENT_PARAMETERS pp;
15 D3DDISPLAYMODE dm;
16 D3DCAPS9 caps;
17 RECT rect;
18 DWORD flag;
19 HRESULT hr;
20
21 if (window == NULL)
22 return false;
23
24 Destroy();
25
26 _object = Direct3DCreate9(D3D_SDK_VERSION);
27 if (_object == NULL)
28 return false;
29
30 if (FAILED(hr = _object->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm)))
31 {
32 ERR("GetAdapterDisplayMode failed: %x", hr);
33 Destroy();
34 return false;
35 }
36
37 if (FAILED(hr = _object->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
38 {
39 ERR("GetDeviceCaps failed: %x", hr);
40 Destroy();
41 return false;
42 }
43
44 if (!GetClientRect(window, &rect))
45 {
46 ERR("GetClientRect failed: %x", GetLastError());
47 Destroy();
48 return false;
49 }
50
51 if (SUCCEEDED(_object->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
52 dm.Format, 0, D3DRTYPE_TEXTURE, (depth == 16) ? D3DFMT_R5G6B5 : D3DFMT_A8R8G8B8)))
53 {
54 dm.Format = (depth == 16) ? D3DFMT_R5G6B5 : D3DFMT_A8R8G8B8;
55 }
56
57 flag = (caps.VertexProcessingCaps != 0) ?
58 (D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE) :
59 D3DCREATE_SOFTWARE_VERTEXPROCESSING;
60
61 ZeroMemory(&pp, sizeof(pp));
62 if (!fullscreen)
63 {
64 pp.BackBufferWidth = rect.right - rect.left;
65 pp.BackBufferHeight = rect.bottom - rect.top;
66 }
67 else
68 {
69 pp.BackBufferWidth = ::GetSystemMetrics(SM_CXSCREEN);
70 pp.BackBufferHeight = ::GetSystemMetrics(SM_CYSCREEN);
71 }
72 pp.BackBufferFormat = dm.Format;
73 pp.BackBufferCount = 1;
74 pp.MultiSampleType = D3DMULTISAMPLE_NONE;
75 pp.MultiSampleQuality = 0;
76 pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
77 pp.hDeviceWindow = window;
78 pp.Windowed = fullscreen ? FALSE : TRUE;
79 //pp.EnableAutoDepthStencil = TRUE;
80 //pp.AutoDepthStencilFormat = D3DFMT_D16;
81 pp.FullScreen_RefreshRateInHz = 0;
82 pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
83
84 if (FAILED(hr = _object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
85 window, flag, &pp, &_device)))
86 {
87 WRN("CreateDevice failed: %x", hr);
88 Destroy();
89 return false;
90 }
91
92 LPDIRECT3DSURFACE9 backbuffer = NULL;
93 _device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
94 backbuffer->GetDesc(&_backbuffer_desc);
95 backbuffer->Release();
96
97 switch (dm.Format) {
98 case D3DFMT_A8R8G8B8:
99 case D3DFMT_X8R8G8B8:
100 _depth = 32;
101 break;
102 case D3DFMT_R5G6B5:
103 _depth = 16;
104 break;
105 default:
106 WRN("No supported format found");
107 Destroy();
108 return false;
109 }
110
111 //_render_to_texture = false;
112
113 _d3dpp = pp;
114 _device_lost = FALSE;
115 _scene_rendering = FALSE;
116 _width = rect.right - rect.left;
117 _height = rect.bottom - rect.top;
118 _window = window;
119
120 if (FAILED(CreateRenderTarget()))
121 {
122 ERR("Failed to create render target");
123 Destroy();
124 return false;
125 }
126
127 Log("initialized");
128 return true;
129}
130
131bool D3DDevice::Reset(int width, int height, int fullscreen)
132{
133 D3DPRESENT_PARAMETERS pp = _d3dpp;
134 _d3dpp.BackBufferWidth = (width > 0) ? width : _d3dpp.BackBufferWidth;
135 _d3dpp.BackBufferHeight = (height > 0) ? height : _d3dpp.BackBufferHeight;
136 _d3dpp.Windowed = (fullscreen == 1) ? FALSE : ((fullscreen == 0) ? TRUE : _d3dpp.Windowed);
137 if (FAILED(ResetDevice()))
138 {
139 WRN("Couldnt restore device");
140 _d3dpp = pp;
141 return SUCCEEDED(ResetDevice());
142 }
143 _width = _d3dpp.BackBufferWidth;
144 _height = _d3dpp.BackBufferHeight;
145 return true;
146}
147
148void D3DDevice::Destroy()
149{
150 //if (_render_target != NULL)
151 //{
152 // _render_target->Release();
153 // _render_target = NULL;
154 //}
155 if (_render_target_data != NULL)
156 {
157 _render_target_data->Release();
158 _render_target_data = NULL;
159 }
160 if (_device != NULL)
161 {
162 int num = _device->Release();
163 assert(num == 0);
164 }
165 if (_object != NULL)
166 _object->Release();
167 ResetParams();
168
169 INF("uninitialized");
170}
171
172void D3DDevice::ResetParams()
173{
174 _window = NULL;
175 _object = NULL;
176 _device = NULL;
177 _width = 0;
178 _height = 0;
179 _rot = 0;
180 _depth = 0;
181 _device_lost = false;
182 _scene_rendering = false;
183 ZeroMemory(&_d3dpp, sizeof(_d3dpp));
184 ZeroMemory(&_backbuffer_desc, sizeof(_backbuffer_desc));
185 //_render_target = NULL;
186 _render_target_data = NULL;
187 _render_data_updated = false;
188 _render_data.Resize();
189 //_original_render_target = NULL;
190 //_render_to_texture = false;
191}
192
193HRESULT D3DDevice::RestoreDevice()
194{
195 Log("restore");
196 assert(_device != NULL);
197
198 HRESULT hr = S_OK;
199
200 // Test the cooperative level to see if it's okay to render
201 if (SUCCEEDED(hr = _device->TestCooperativeLevel()))
202 {
203 _device_lost = FALSE;
204 DBG("render test ok");
205 return S_OK;
206 }
207
208 // If the device was lost, do not render until we get it back
209 if (hr == D3DERR_DEVICELOST)
210 return E_FAIL;
211
212 // Check if the device needs to be reset.
213 if (hr == D3DERR_DEVICENOTRESET)
214 {
215 if (FAILED(hr = ResetDevice()))
216 return hr;
217 }
218 return hr;
219}
220
221HRESULT D3DDevice::ResetDevice()
222{
223 DBG("reset");
224 HRESULT hr = S_OK;
225
226 _scene_rendering = FALSE;
227
228 // Release all video memory objects
229 // Bad to call such, make better
230 D3DVertexBufferCache::Current()->Uninitialize();
231
232 //if (_render_target != NULL)
233 //{
234 // _render_target->Release();
235 // _render_target = NULL;
236 //}
237 if (_render_target_data != NULL)
238 {
239 _render_target_data->Release();
240 _render_target_data = NULL;
241 }
242
243 // Reset the device
244 if (FAILED(hr = _device->Reset(&_d3dpp)))
245 {
246 ERR("D3DDevice: Reset of the device failed! Error (%X)", (DWORD)hr);
247 return hr;
248 }
249
250 // Store render target surface desc
251 LPDIRECT3DSURFACE9 backbuffer = NULL;
252 _device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
253 if (backbuffer != NULL)
254 {
255 backbuffer->GetDesc(&_backbuffer_desc);
256 backbuffer->Release();
257 }
258
259 // Initialize the app's device-dependent objects
260 hr = CreateRenderTarget();
261
262 if (FAILED(hr))
263 {
264 WRN("Restoration of device objects failed");
265 // Invalidate objects
266
267 return E_FAIL;
268 }
269
270 DBG("Device objects were successfuly restored");
271 _textures.Set(NULL);
272
273 //_device_objects_restored = true;
274 return S_OK;
275}
276
277bool D3DDevice::Begin()
278{
279 if (FAILED(RestoreDevice()))
280 return false;
281
282 //if (_render_to_texture && _render_target != NULL)
283 //{
284 // if (FAILED(_device->GetRenderTarget(0, &_original_render_target)))
285 // return false;
286 // if (FAILED(_device->SetRenderTarget(0, _render_target)))
287 // return false;
288 //}
289
290 HRESULT hr;
291 if (FAILED(hr = _device->BeginScene()))
292 {
293 WRN("Cannot begin scene: %X", (DWORD)hr);
294 return false;
295 }
296
297 //static const D3DVIEWPORT9 vp = {0, 0, _width, _height, 0.f, 1.f};
298 //_device->SetViewport(&vp);
299 //_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
300
301 //_device->Clear(0, NULL, D3DCLEAR_TARGET /*| D3DCLEAR_ZBUFFER*/, 0xff8080ff, 1.f, 0);
302 return true;
303}
304
305bool D3DDevice::End()
306{
307 _device->EndScene();
308 _device->Present(NULL, NULL, NULL, NULL);
309
310 _render_data_updated = false;
311
312 //if (_render_to_texture && _render_target != NULL && _original_render_target != NULL)
313 //{
314 // if (FAILED(_device->SetRenderTarget(0, _original_render_target)))
315 // return false;
316 //}
317
318 return true;
319}
320
321TArray<DWORD> &D3DDevice::GetRenderData()
322{
323 if (_render_data_updated)
324 return _render_data;
325 _render_data.Allocate(0);
326 if (_render_target_data == NULL)
327 return _render_data;
328
329 LPDIRECT3DSURFACE9 surf = NULL;
330 HRESULT hr;
331 if (FAILED(_device->GetRenderTarget(0, &surf)))
332 return _render_data;
333 if (FAILED(hr = _device->GetRenderTargetData(surf, _render_target_data)))
334 {
335 WRN("Failed to get render target data (%X)", (DWORD)hr);
336 surf->Release();
337 return _render_data;
338 }
339 D3DLOCKED_RECT lr;
340 if (FAILED(_render_target_data->LockRect(&lr, NULL, D3DLOCK_READONLY)))
341 {
342 surf->Release();
343 return _render_data;
344 }
345 _render_data.Allocate(_width * _height);
346
347 for (int i = 0; i < _height; i++)
348 {
349 CopyMemory(&_render_data[i * _width], (BYTE *)lr.pBits + i * lr.Pitch,
350 _width * sizeof(DWORD));
351 }
352
353 _render_target_data->UnlockRect();
354 _render_data_updated = true;
355 surf->Release();
356 return _render_data;
357}
358
359HRESULT D3DDevice::SetTexture(DWORD stage, LPDIRECT3DTEXTURE9 tex)
360{
361 if (stage >= 8)
362 return E_FAIL;
363 if (_textures.Length() <= (int)stage)
364 _textures.Allocate(stage + 1);
365 if (_textures[stage] != tex)
366 {
367 _textures[stage] = tex;
368 return _device->SetTexture(stage, tex);
369 }
370 return S_OK;
371}
372
373HRESULT D3DDevice::CreateRenderTarget()
374{
375 if (_device == NULL)
376 return E_FAIL;
377 //if (_render_target != NULL &&
378 if (_render_target_data != NULL)
379 return S_OK;
380
381 //if (FAILED(_device->CreateRenderTarget(_width, _height, _backbuffer_desc.Format,
382 // D3DMULTISAMPLE_NONE, 0, FALSE, &_render_target, NULL)))
383 //{
384 // return E_FAIL;
385 //}
386 if (FAILED(_device->CreateOffscreenPlainSurface(_backbuffer_desc.Width,
387 _backbuffer_desc.Height, _backbuffer_desc.Format, D3DPOOL_SYSTEMMEM,
388 &_render_target_data, NULL)))
389 {
390 return E_FAIL;
391 }
392 return S_OK;
393}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_device.h b/src/modules/evas/engines/direct3d/evas_direct3d_device.h
deleted file mode 100644
index c5a4b49b66..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_device.h
+++ /dev/null
@@ -1,87 +0,0 @@
1#ifndef __EVAS_DIRECT3D_DEVICE_H__
2#define __EVAS_DIRECT3D_DEVICE_H__
3
4#include "evas_engine.h"
5
6#include <assert.h>
7
8#include "ref.h"
9#include "array.h"
10
11
12class D3DDevice : virtual public Referenc
13{
14public:
15 D3DDevice();
16
17 bool Init(HWND window, int depth, bool fullscreen = false);
18 bool Reset(int width, int height, int fullscreen);
19 void Destroy();
20 bool Begin();
21 bool End();
22
23 inline LPDIRECT3DDEVICE9 GetDevice();
24 inline int GetWidth();
25 inline int GetHeight();
26 inline HWND GetWindow();
27 inline bool GetFullscreen();
28
29 TArray<DWORD> &GetRenderData();
30
31 HRESULT SetTexture(DWORD stage, LPDIRECT3DTEXTURE9 tex);
32
33private:
34 HRESULT RestoreDevice();
35 HRESULT ResetDevice();
36 void ResetParams();
37
38 HRESULT CreateRenderTarget();
39
40private:
41 HWND _window;
42 LPDIRECT3D9 _object;
43 LPDIRECT3DDEVICE9 _device;
44 int _width;
45 int _height;
46 int _rot;
47 int _depth;
48 bool _device_lost;
49 bool _scene_rendering;
50 D3DPRESENT_PARAMETERS _d3dpp;
51 D3DSURFACE_DESC _backbuffer_desc;
52 //LPDIRECT3DSURFACE9 _render_target;
53 LPDIRECT3DSURFACE9 _render_target_data;
54 //LPDIRECT3DSURFACE9 _original_render_target;
55 //bool _render_to_texture;
56 TArray<DWORD> _render_data;
57 bool _render_data_updated;
58
59 TArray<LPDIRECT3DTEXTURE9> _textures;
60};
61
62LPDIRECT3DDEVICE9 D3DDevice::GetDevice()
63{
64 return _device;
65}
66
67int D3DDevice::GetWidth()
68{
69 return _width;
70}
71
72int D3DDevice::GetHeight()
73{
74 return _height;
75}
76
77HWND D3DDevice::GetWindow()
78{
79 return _window;
80}
81
82bool D3DDevice::GetFullscreen()
83{
84 return (_d3dpp.Windowed == 0);
85}
86
87#endif // __EVAS_DIRECT3D_DEVICE_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.cpp
deleted file mode 100644
index aa44eb9cb4..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.cpp
+++ /dev/null
@@ -1,436 +0,0 @@
1#include "evas_direct3d_image_cache.h"
2
3#include "evas_direct3d_device.h"
4
5#include <assert.h>
6
7Ref<D3DImageCache> D3DImageCache::_this;
8
9D3DImageCache::D3DImageCache()
10{
11 _max_width = 512;
12 _max_height = 512;
13 _margin = 0;
14}
15
16D3DImageCache::~D3DImageCache()
17{
18 Uninitialize();
19}
20
21D3DImageCache *D3DImageCache::Current()
22{
23 if (_this.IsNull())
24 _this = new D3DImageCache();
25 return _this;
26}
27
28void D3DImageCache::SetCurrent(D3DImageCache *obj)
29{
30 _this = obj;
31}
32
33void D3DImageCache::Uninitialize()
34{
35 for (int i = 0; i < _cache.Length(); i++)
36 {
37 // In normal case they all will be NULL
38 if (_cache[i].texture != NULL)
39 _cache[i].texture->Release();
40 }
41 _cache.Resize();
42}
43
44bool D3DImageCache::SelectImageToDevice(D3DDevice *d3d, int id)
45{
46 if (id < 0 || id >= _cache.Length())
47 return false;
48 assert(_cache[id].texture != NULL);
49 return SUCCEEDED(d3d->SetTexture(_cache[id].stage, _cache[id].texture));
50}
51
52void D3DImageCache::RemoveImageUser(int id)
53{
54 if (id < 0 || id >= _cache.Length())
55 return;
56 assert(_cache[id].texture != NULL);
57 _cache[id].users--;
58 if (_cache[id].users == 0)
59 {
60 _cache[id].texture->Release();
61 ZeroMemory(&_cache[id], sizeof(_cache[id]));
62 }
63}
64
65void D3DImageCache::AddImageUser(int id)
66{
67 if (id < 0 || id >= _cache.Length())
68 return;
69 assert(_cache[id].texture != NULL);
70 _cache[id].users++;
71}
72
73bool D3DImageCache::InsertImage(D3DDevice *d3d, DWORD *data, int w, int h, CacheEntryInfo &info)
74{
75 CacheEntry *ce = NULL;
76 int id = -1;
77 for (int i = 0; i < _cache.Length(); i++)
78 {
79 if (!_cache[i].locked && RequestInsert(_cache[i], w, h))
80 {
81 ce = &_cache[i];
82 id = i;
83 break;
84 }
85 }
86 if (ce == NULL)
87 {
88 CacheEntry new_entry;
89 if (!CreateEntry(d3d, new_entry, w, h))
90 return false;
91 for (id = 0; id < _cache.Length(); id++)
92 {
93 if (_cache[id].texture == NULL)
94 break;
95 }
96
97 if (id < _cache.Length())
98 {
99 _cache[id] = new_entry;
100 ce = &_cache[id];
101 }
102 else
103 {
104 _cache.Add(new_entry);
105 ce = _cache.Last();
106 id = _cache.Length() - 1;
107 }
108 }
109
110 assert(ce != NULL && ce->texture != NULL);
111
112 if (!InsertData(*ce, data, w, h))
113 return false;
114
115 info.id = id;
116 info.u = FLOAT(ce->cur_x) / FLOAT(ce->width);
117 info.v = FLOAT(ce->cur_y) / FLOAT(ce->height);
118 info.du = FLOAT(w) / FLOAT(ce->width);
119 info.dv = FLOAT(h) / FLOAT(ce->height);
120 info.width = w;
121 info.height = h;
122
123 UpdateInsert(*ce, w, h);
124 return true;
125}
126
127bool D3DImageCache::InsertImage(D3DDevice *d3d, int id, DWORD *data, int w, int h, CacheEntryInfo &info)
128{
129 if (id < 0 || id >= _cache.Length())
130 return false;
131 assert(_cache[id].texture != NULL);
132 CacheEntry *ce = &_cache[id];
133 if (!RequestInsert(*ce, w, h))
134 return false;
135 if (!InsertData(*ce, data, w, h))
136 return false;
137
138 info.id = id;
139 info.u = FLOAT(ce->cur_x) / FLOAT(ce->width);
140 info.v = FLOAT(ce->cur_y) / FLOAT(ce->height);
141 info.du = FLOAT(w) / FLOAT(ce->width);
142 info.dv = FLOAT(h) / FLOAT(ce->height);
143 info.width = w;
144 info.height = h;
145
146 UpdateInsert(*ce, w, h);
147 return true;
148}
149
150bool D3DImageCache::CreateImage(D3DDevice *d3d, int w, int h, bool locked, CacheEntryInfo &info)
151{
152 int id;
153 CacheEntry new_entry;
154 CacheEntry *ce = NULL;
155
156 if (!CreateEntry(d3d, new_entry, w, h, true))
157 return false;
158 for (id = 0; id < _cache.Length(); id++)
159 {
160 if (_cache[id].texture == NULL)
161 break;
162 }
163
164 if (id < _cache.Length())
165 {
166 _cache[id] = new_entry;
167 ce = &_cache[id];
168 }
169 else
170 {
171 _cache.Add(new_entry);
172 ce = _cache.Last();
173 id = _cache.Length() - 1;
174 }
175
176 assert(ce != NULL && ce->texture != NULL);
177
178 // Fill with zero
179 if (!InsertData(*ce, NULL, w, h))
180 return false;
181
182 info.id = id;
183 info.u = 0;
184 info.v = 0;
185 info.du = 1;
186 info.dv = 1;
187 info.width = w;
188 info.height = h;
189
190 UpdateInsert(*ce, 0, 0);
191 ce->locked = locked;
192 return true;
193}
194
195bool D3DImageCache::ResizeImage(D3DDevice *d3d, int nw, int nh, int id)
196{
197 if (id < 0 || id >= _cache.Length())
198 return false;
199 assert(_cache[id].texture != NULL);
200 CacheEntry *ce = &_cache[id];
201
202 if (ce->width == nw && ce->height == nh)
203 return true;
204
205 LPDIRECT3DTEXTURE9 tex = NULL;
206
207 HRESULT hr;
208 if (FAILED(hr = d3d->GetDevice()->CreateTexture(nw, nh, 0, 0, D3DFMT_A8R8G8B8,
209 D3DPOOL_MANAGED, &tex, NULL)))
210 {
211 WRN("Failed to create texture: %X", hr);
212 return false;
213 }
214 assert(tex != NULL);
215
216 ce->texture->Release();
217 ce->texture = tex;
218 ce->width = nw;
219 ce->height = nh;
220 return true;
221}
222
223bool D3DImageCache::RequestInsert(CacheEntry &entry, int w, int h)
224{
225 // If we already have large image entry
226 if (entry.width > _max_width || entry.height > _max_height)
227 return false;
228 // If requested size does not fit into this entry at all
229 if (entry.height - entry.cur_h < h + _margin * 2 || entry.width < w + _margin * 2)
230 return false;
231
232 // If requested size does not fit into the current line of the entry
233 if (entry.width - entry.cur_x < w + _margin * 2)
234 {
235 entry.cur_y = entry.cur_h + _margin;
236 entry.cur_x = _margin;
237 return true;
238 }
239 entry.cur_x += _margin;
240
241 return true;
242}
243
244bool D3DImageCache::CreateEntry(D3DDevice *d3d, CacheEntry &entry, int w, int h, bool exact_size)
245{
246 int width = exact_size ? w : max(_max_width, w);
247 int height = exact_size ? h : max(_max_height, h);
248 HRESULT hr;
249 if (FAILED(hr = d3d->GetDevice()->CreateTexture(width, height, 0, 0, D3DFMT_A8R8G8B8,
250 D3DPOOL_MANAGED, &entry.texture, NULL)))
251 {
252 WRN("Failed to create texture: %X", hr);
253 return false;
254 }
255
256 entry.cur_x = entry.cur_y = entry.cur_h = 0;
257 entry.width = width;
258 entry.height = height;
259 entry.users = 0;
260 entry.locked = false;
261 entry.stage = 0;
262 return true;
263}
264
265bool D3DImageCache::InsertData(CacheEntry &entry, DWORD *data, int w, int h)
266{
267 if (entry.texture == NULL)
268 return false;
269
270 RECT rc = {entry.cur_x, entry.cur_y, entry.cur_x + w, entry.cur_y + h};
271 D3DLOCKED_RECT lr;
272 if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
273 {
274 WRN("Failed to lock texture");
275 return false;
276 }
277
278 if (data != NULL)
279 {
280 for (int i = 0; i < h; i++)
281 CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch, data + i * w, sizeof(DWORD) * w);
282 }
283 else
284 {
285 for (int i = 0; i < h; i++)
286 ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch, sizeof(DWORD) * w);
287 }
288
289 if (FAILED(entry.texture->UnlockRect(0)))
290 {
291 WRN("Failed to unlock texture");
292 return false;
293 }
294 return true;
295}
296
297
298bool D3DImageCache::RetrieveData(CacheEntry &entry, DWORD *data, int w, int h)
299{
300 if (entry.texture == NULL || data == NULL)
301 return false;
302
303 RECT rc = {entry.cur_x, entry.cur_y, entry.cur_x + w, entry.cur_y + h};
304 D3DLOCKED_RECT lr;
305 if (FAILED(entry.texture->LockRect(0, &lr, &rc, D3DLOCK_READONLY)))
306 {
307 WRN("Failed to lock texture");
308 return false;
309 }
310
311 for (int i = 0; i < h; i++)
312 CopyMemory(data + i * w, ((BYTE *)lr.pBits) + i * lr.Pitch, sizeof(DWORD) * w);
313
314 if (FAILED(entry.texture->UnlockRect(0)))
315 {
316 WRN("Failed to unlock texture");
317 return false;
318 }
319 return true;
320}
321
322void D3DImageCache::UpdateInsert(CacheEntry &entry, int w, int h)
323{
324 entry.cur_h = max(entry.cur_h, entry.cur_y + h + _margin);
325 entry.cur_x += w + _margin;
326 entry.users++;
327}
328
329bool D3DImageCache::UpdateImageData(CacheEntryInfo &info, DWORD *data)
330{
331 assert(data != NULL);
332 if (info.id < 0 || info.id >= _cache.Length())
333 return false;
334 CacheEntry ce_copy = _cache[info.id];
335 ce_copy.cur_x = int(info.u * FLOAT(ce_copy.width));
336 ce_copy.cur_y = int(info.v * FLOAT(ce_copy.height));
337 return InsertData(ce_copy, data, info.width, info.height);
338}
339
340bool D3DImageCache::UpdateImageDataWithDirtyInfo(CacheEntryInfo &info, DWORD *data, POINT *dirty)
341{
342 if (info.id < 0 || info.id >= _cache.Length())
343 return false;
344 CacheEntry &entry = _cache[info.id];
345 if (entry.texture == NULL)
346 return false;
347
348 RECT rc = {0, 0, entry.width, entry.height};
349 D3DLOCKED_RECT lr;
350 if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
351 {
352 WRN("Failed to lock texture");
353 return false;
354 }
355
356 if (data != NULL)
357 {
358 for (int i = 0; i < rc.bottom; i++)
359 {
360 if (dirty[i].x < 0 && dirty[i].y < 0)
361 continue;
362 if (dirty[i].x >= 0 && dirty[i].y >= 0)
363 {
364 CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
365 data + i * rc.right + dirty[i].x, sizeof(DWORD) * (dirty[i].y - dirty[i].x + 1));
366 dirty[i].y = -dirty[i].y;
367 }
368 else if (dirty[i].x >= 0 && dirty[i].y < 0)
369 {
370 ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
371 sizeof(DWORD) * (-dirty[i].y - dirty[i].x + 1));
372 dirty[i].x = -dirty[i].x;
373 }
374 }
375 }
376 else
377 {
378 for (int i = 0; i < rc.bottom; i++)
379 {
380 if (dirty[i].x < 0 || dirty[i].y < 0)
381 continue;
382 ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
383 sizeof(DWORD) * (dirty[i].y - dirty[i].x + 1));
384 }
385 }
386
387 if (FAILED(entry.texture->UnlockRect(0)))
388 {
389 WRN("Failed to unlock texture");
390 return false;
391 }
392 return true;
393}
394
395bool D3DImageCache::UpdateImageDataDiscard(CacheEntryInfo &info, DWORD *data)
396{
397 assert(data != NULL);
398 if (info.id < 0 || info.id >= _cache.Length())
399 return false;
400 CacheEntry &entry = _cache[info.id];
401 if (entry.texture == NULL)
402 return false;
403
404 RECT rc = {0, 0, entry.width, entry.height};
405 D3DLOCKED_RECT lr;
406 if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
407 {
408 WRN("Failed to lock texture");
409 return false;
410 }
411
412 for (int i = 0; i < rc.bottom; i++)
413 {
414 CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch,
415 data + i * rc.right, sizeof(DWORD) * rc.right);
416 }
417
418 if (FAILED(entry.texture->UnlockRect(0)))
419 {
420 WRN("Failed to unlock texture");
421 return false;
422 }
423 return true;
424}
425
426bool D3DImageCache::GetImageData(CacheEntryInfo &info, TArray<DWORD> &data)
427{
428 if (info.id < 0 || info.id >= _cache.Length())
429 return false;
430 CacheEntry ce_copy = _cache[info.id];
431 ce_copy.cur_x = int(info.u * FLOAT(ce_copy.width));
432 ce_copy.cur_y = int(info.v * FLOAT(ce_copy.height));
433 data.Allocate(info.width * info.height);
434
435 return RetrieveData(ce_copy, data.Data(), info.width, info.height);
436}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.h b/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.h
deleted file mode 100644
index 6fb4c18120..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_image_cache.h
+++ /dev/null
@@ -1,108 +0,0 @@
1#ifndef __EVAS_DIRECT3D_IMAGE_CACHE_H__
2#define __EVAS_DIRECT3D_IMAGE_CACHE_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "array.h"
8
9class D3DDevice;
10
11class D3DImageCache : virtual public Referenc
12{
13public:
14 struct CacheEntryInfo
15 {
16 int id;
17 int width, height;
18 FLOAT u, v;
19 FLOAT du, dv;
20 };
21
22public:
23 ~D3DImageCache();
24
25 static D3DImageCache *Current();
26 static void SetCurrent(D3DImageCache *obj);
27
28 inline void SetMaxSize(int w, int h);
29 inline void SetMargin(int margin);
30
31 bool InsertImage(D3DDevice *d3d, DWORD *data, int w, int h, CacheEntryInfo &info);
32 bool InsertImage(D3DDevice *d3d, int id, DWORD *data, int w, int h, CacheEntryInfo &info);
33 bool CreateImage(D3DDevice *d3d, int w, int h, bool locked, CacheEntryInfo &info);
34 bool ResizeImage(D3DDevice *d3d, int nw, int nh, int id);
35 bool SelectImageToDevice(D3DDevice *d3d, int id);
36 void RemoveImageUser(int id);
37 void AddImageUser(int id);
38 bool UpdateImageData(CacheEntryInfo &info, DWORD *data);
39 bool UpdateImageDataWithDirtyInfo(CacheEntryInfo &info, DWORD *data, POINT *dirty);
40 bool UpdateImageDataDiscard(CacheEntryInfo &info, DWORD *data);
41 bool GetImageData(CacheEntryInfo &info, TArray<DWORD> &data);
42 void Uninitialize();
43
44 inline int GetImageWidth(int image_id);
45 inline int GetImageHeight(int image_id);
46
47 inline void SetImageStage(int image_id, int stage);
48
49private:
50 struct CacheEntry
51 {
52 LPDIRECT3DTEXTURE9 texture;
53 int width;
54 int height;
55 int cur_x;
56 int cur_y;
57 int cur_h;
58 int users;
59 bool locked;
60 int stage;
61 };
62
63private:
64 D3DImageCache();
65
66 bool RequestInsert(CacheEntry &entry, int w, int h);
67 bool CreateEntry(D3DDevice *d3d, CacheEntry &entry, int w, int h, bool exact_size = false);
68 bool InsertData(CacheEntry &entry, DWORD *data, int w, int h);
69 bool RetrieveData(CacheEntry &entry, DWORD *data, int w, int h);
70 void UpdateInsert(CacheEntry &entry, int w, int h);
71
72private:
73 TArray<CacheEntry> _cache;
74 int _max_width;
75 int _max_height;
76
77 int _margin;
78
79 static Ref<D3DImageCache> _this;
80};
81
82void D3DImageCache::SetMaxSize(int w, int h)
83{
84 _max_width = w;
85 _max_height = h;
86}
87
88void D3DImageCache::SetMargin(int margin)
89{
90 _margin = margin;
91}
92
93int D3DImageCache::GetImageWidth(int image_id)
94{
95 return _cache[image_id].width;
96}
97
98int D3DImageCache::GetImageHeight(int image_id)
99{
100 return _cache[image_id].height;
101}
102
103void D3DImageCache::SetImageStage(int image_id, int stage)
104{
105 _cache[image_id].stage = stage;
106}
107
108#endif // __EVAS_DIRECT3D_IMAGE_CACHE_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_main.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_main.cpp
deleted file mode 100644
index fe1e13f83b..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_main.cpp
+++ /dev/null
@@ -1,774 +0,0 @@
1// Force the layered windows APIs to be visible.
2#define _WIN32_WINNT 0x0500
3
4#include "evas_engine.h"
5#include <assert.h>
6
7#include <d3dx9.h>
8
9#include "evas_direct3d_device.h"
10#include "evas_direct3d_context.h"
11#include "evas_direct3d_shader_pack.h"
12#include "evas_direct3d_scene.h"
13#include "evas_direct3d_image_cache.h"
14#include "evas_direct3d_object_line.h"
15#include "evas_direct3d_object_rect.h"
16#include "evas_direct3d_object_image.h"
17#include "evas_direct3d_vertex_buffer_cache.h"
18#include "evas_direct3d_object_font.h"
19
20// Internal structure that joins two types of objects
21struct ImagePtr
22{
23 Ref<D3DObjectImage> ref;
24 RGBA_Image *img;
25};
26
27struct DevicePtr
28{
29 Ref<D3DDevice> device;
30 Ref<D3DScene> scene;
31 Ref<D3DContext> context;
32 Ref<D3DImageCache> image_cache;
33 Ref<D3DShaderPack> shader_pack;
34 Ref<D3DVertexBufferCache> vb_cache;
35
36 int fonts_buffer_image_id;
37
38 // Layered windows cannot render D3D in the normal way
39 bool layered;
40
41 // Window shape mask
42 struct
43 {
44 // Width and height may be different from target size
45 int width;
46 int height;
47 // Pointer to external memory location, dont do anything with it
48 unsigned char *mask;
49 } shape;
50
51 // GDI output target
52 struct
53 {
54 HBITMAP image;
55 HDC hdc;
56 BITMAPINFO info;
57 BYTE *data;
58 } dib;
59
60};
61
62DevicePtr *SelectDevice(Direct3DDeviceHandler d3d)
63{
64 DevicePtr *dev_ptr = (DevicePtr *)d3d;
65 D3DImageCache::SetCurrent(dev_ptr->image_cache);
66 D3DShaderPack::SetCurrent(dev_ptr->shader_pack);
67 D3DVertexBufferCache::SetCurrent(dev_ptr->vb_cache);
68 return dev_ptr;
69}
70
71void DeleteDIBObjects(DevicePtr *dev_ptr)
72{
73 assert(dev_ptr != NULL);
74 if (dev_ptr->dib.image != NULL)
75 DeleteObject(dev_ptr->dib.image);
76 if (dev_ptr->dib.hdc != NULL)
77 DeleteDC(dev_ptr->dib.hdc);
78 ZeroMemory(&dev_ptr->dib, sizeof(dev_ptr->dib));
79}
80
81bool CreateDIBObjects(DevicePtr *dev_ptr)
82{
83 assert(dev_ptr != NULL);
84 if ((dev_ptr->dib.hdc = CreateCompatibleDC(NULL)) == NULL)
85 {
86 WRN("Failed to create compatible DC");
87 return false;
88 }
89 ZeroMemory(&dev_ptr->dib.info, sizeof(dev_ptr->dib.info));
90 dev_ptr->dib.info.bmiHeader.biSize = sizeof(dev_ptr->dib.info.bmiHeader);
91 dev_ptr->dib.info.bmiHeader.biBitCount = 32;
92 dev_ptr->dib.info.bmiHeader.biWidth = dev_ptr->device->GetWidth();
93 dev_ptr->dib.info.bmiHeader.biHeight = -dev_ptr->device->GetHeight();
94 dev_ptr->dib.info.bmiHeader.biCompression = BI_RGB;
95 dev_ptr->dib.info.bmiHeader.biPlanes = 1;
96 if ((dev_ptr->dib.image = CreateDIBSection(dev_ptr->dib.hdc, &dev_ptr->dib.info,
97 DIB_RGB_COLORS, (void **)&dev_ptr->dib.data, NULL, 0)) == NULL)
98 {
99 WRN("Failed to create dib section");
100 DeleteDIBObjects(dev_ptr);
101 return false;
102 }
103 assert(dev_ptr->dib.data != NULL);
104 GdiFlush();
105 return true;
106}
107
108
109
110
111extern "C" {
112
113Direct3DDeviceHandler evas_direct3d_init(HWND window, int depth, int fullscreen)
114{
115 Ref<D3DDevice> device = new D3DDevice();
116 if (!device->Init(window, depth, fullscreen == 1))
117 return NULL;
118
119 D3DImageCache::SetCurrent(NULL);
120 D3DShaderPack::SetCurrent(NULL);
121 D3DVertexBufferCache::SetCurrent(NULL);
122
123 if (!D3DShaderPack::Current()->Initialize(device))
124 {
125 ERR("Failed to build shader pack");
126 device->Destroy();
127 return NULL;
128 }
129
130 DevicePtr *dev_ptr = new DevicePtr;
131 ZeroMemory(dev_ptr, sizeof(DevicePtr));
132 dev_ptr->device = device;
133 dev_ptr->scene = new D3DScene();
134 dev_ptr->context = new D3DContext();
135 dev_ptr->image_cache = D3DImageCache::Current();
136 dev_ptr->shader_pack = D3DShaderPack::Current();
137 dev_ptr->vb_cache = D3DVertexBufferCache::Current();
138 dev_ptr->fonts_buffer_image_id = -1;
139
140 D3DImageCache::CacheEntryInfo info;
141 if (!D3DImageCache::Current()->CreateImage(device, device->GetWidth(), device->GetHeight(),
142 true, info))
143 {
144 WRN("Failed to create fonts image buffer");
145 return NULL;
146 }
147 dev_ptr->fonts_buffer_image_id = info.id;
148 D3DImageCache::Current()->SetImageStage(info.id, 1);
149
150 return (Direct3DDeviceHandler)dev_ptr;
151}
152
153void
154evas_direct3d_free(Direct3DDeviceHandler d3d)
155{
156 DevicePtr *dev_ptr = SelectDevice(d3d);
157
158 DeleteDIBObjects(dev_ptr);
159
160 dev_ptr->context = NULL;
161 dev_ptr->scene = NULL;
162 dev_ptr->image_cache = NULL;
163 dev_ptr->shader_pack = NULL;
164 D3DShaderPack::Current()->Uninitialize();
165 D3DImageCache::Current()->Uninitialize();
166 D3DVertexBufferCache::Current()->Uninitialize();
167 D3DShaderPack::SetCurrent(NULL);
168 D3DImageCache::SetCurrent(NULL);
169 D3DVertexBufferCache::SetCurrent(NULL);
170
171 dev_ptr->device = NULL;
172 delete dev_ptr;
173
174 DBG("uninitialized");
175}
176
177void
178evas_direct3d_resize(Direct3DDeviceHandler d3d, int width, int height)
179{
180 DevicePtr *dev_ptr = SelectDevice(d3d);
181 D3DDevice *device = dev_ptr->device;
182 if (!device->Reset(width, height, -1))
183 {
184 ERR("Failed to resize");
185 return;
186 }
187 if (!D3DImageCache::Current()->ResizeImage(device, width, height,
188 dev_ptr->fonts_buffer_image_id))
189 {
190 WRN("Failed to resize fonts image buffer");
191 }
192 if (dev_ptr->layered)
193 {
194 DeleteDIBObjects(dev_ptr);
195 if (!CreateDIBObjects(dev_ptr))
196 WRN("Failed to create dib objects");
197 }
198}
199
200void
201evas_direct3d_set_fullscreen(Direct3DDeviceHandler d3d, int width, int height, int fullscreen)
202{
203 DevicePtr *dev_ptr = SelectDevice(d3d);
204 D3DDevice *device = dev_ptr->device;
205
206 if (width < 0)
207 width = ::GetSystemMetrics(SM_CXSCREEN);
208 if (height < 0)
209 height = ::GetSystemMetrics(SM_CYSCREEN);
210
211 if (!device->Reset(width, height, fullscreen))
212 {
213 WRN("Failed to resize");
214 return;
215 }
216 if (!D3DImageCache::Current()->ResizeImage(device, width, height,
217 dev_ptr->fonts_buffer_image_id))
218 {
219 WRN("Failed to resize fonts image buffer");
220 }
221
222 if (fullscreen == 0)
223 InvalidateRect(HWND_DESKTOP, NULL, TRUE);
224}
225
226void
227evas_direct3d_set_layered(Direct3DDeviceHandler d3d, int layered,
228 int mask_width, int mask_height, unsigned char *mask)
229{
230 DevicePtr *dev_ptr = SelectDevice(d3d);
231 dev_ptr->layered = (layered != 0);
232 dev_ptr->shape.width = mask_width;
233 dev_ptr->shape.height = mask_height;
234 dev_ptr->shape.mask = mask;
235
236 if (dev_ptr->layered && dev_ptr->dib.data == NULL)
237 CreateDIBObjects(dev_ptr);
238 else if (!dev_ptr->layered)
239 DeleteDIBObjects(dev_ptr);
240}
241
242void
243evas_direct3d_context_color_set(Direct3DDeviceHandler d3d, int r, int g, int b, int a)
244{
245 DevicePtr *dev_ptr = SelectDevice(d3d);
246 dev_ptr->context->color = ((a & 0xff) << 24) | ((r & 0xff) << 16) |
247 ((g & 0xff) << 8) | (b & 0xff);
248}
249
250void
251evas_direct3d_context_set_multiplier(Direct3DDeviceHandler d3d, int r, int g, int b, int a)
252{
253 DevicePtr *dev_ptr = SelectDevice(d3d);
254 dev_ptr->context->color_mul = ((a & 0xff) << 24) | ((r & 0xff) << 16) |
255 ((g & 0xff) << 8) | (b & 0xff);
256}
257
258void
259evas_direct3d_render_all(Direct3DDeviceHandler d3d)
260{
261 DBG("render");
262 assert(d3d != NULL);
263 DevicePtr *dev_ptr = SelectDevice(d3d);
264 D3DDevice *device = dev_ptr->device;
265 D3DScene *scene = dev_ptr->scene;
266
267 if (!device->Begin())
268 return;
269
270 device->GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
271 device->GetDevice()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
272 device->GetDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
273
274 //device->GetDevice()->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
275 //device->GetDevice()->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
276
277 D3DObjectLine::BeginCache();
278 D3DObjectRect::BeginCache();
279 D3DObjectImage::BeginCache();
280 scene->DrawAll(device);
281 D3DObjectLine::EndCache(device);
282 D3DObjectRect::EndCache(device);
283 D3DObjectImage::EndCache(device);
284 D3DObjectFont::EndCache(device);
285
286 device->End();
287
288 if (dev_ptr->layered && !device->GetFullscreen() && dev_ptr->dib.data != NULL)
289 {
290 HDC hdc = GetDC(device->GetWindow());
291 if (hdc != NULL)
292 {
293 POINT dest = {0, 0};
294 POINT src = {0, 0};
295 SIZE client = {device->GetWidth(), device->GetHeight()};
296 BLENDFUNCTION blend_func = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
297
298 if (device->GetRenderData().Length() == client.cx * client.cy)
299 {
300 CopyMemory(dev_ptr->dib.data, device->GetRenderData().Data(),
301 sizeof(DWORD) * client.cx * client.cy);
302 }
303
304 for (int i = 0; i < client.cy; i++)
305 {
306 for (int j = 0; j < client.cx; j++)
307 {
308 int mask_i = int(dev_ptr->shape.height * float(i) / float(client.cy));
309 int mask_j = int(dev_ptr->shape.width * float(j) / float(client.cx));
310 if (mask_i < 0)
311 mask_i = 0;
312 else if (mask_i >= dev_ptr->shape.height)
313 mask_i = dev_ptr->shape.height - 1;
314 if (mask_j < 0)
315 mask_j = 0;
316 else if (mask_j >= dev_ptr->shape.width)
317 mask_j = dev_ptr->shape.width - 1;
318 BYTE mask_b = dev_ptr->shape.mask[mask_i * dev_ptr->shape.width + mask_j];
319 float alpha = float(mask_b) / 255.f;
320
321 dev_ptr->dib.data[j * 4 + 0 + i * 4 * client.cx] = BYTE(float(dev_ptr->dib.data[j * 4 + 0 + i * 4 * client.cx]) * alpha);
322 dev_ptr->dib.data[j * 4 + 1 + i * 4 * client.cx] = BYTE(float(dev_ptr->dib.data[j * 4 + 1 + i * 4 * client.cx]) * alpha);
323 dev_ptr->dib.data[j * 4 + 2 + i * 4 * client.cx] = BYTE(float(dev_ptr->dib.data[j * 4 + 2 + i * 4 * client.cx]) * alpha);
324 dev_ptr->dib.data[j * 4 + 3 + i * 4 * client.cx] = mask_b;
325 }
326 }
327 HGDIOBJ prev_obj = SelectObject(dev_ptr->dib.hdc, dev_ptr->dib.image);
328 ClientToScreen(device->GetWindow(), &dest);
329
330 UpdateLayeredWindow(device->GetWindow(), hdc, &dest, &client,
331 dev_ptr->dib.hdc, &src, 0, &blend_func, ULW_ALPHA);
332
333 SelectObject(dev_ptr->dib.hdc, prev_obj);
334 ReleaseDC(device->GetWindow(), hdc);
335 }
336 }
337 scene->FreeObjects();
338}
339
340void evas_direct3d_line_draw(Direct3DDeviceHandler d3d, int x1, int y1, int x2, int y2)
341{
342 DevicePtr *dev_ptr = SelectDevice(d3d);
343 D3DDevice *device = dev_ptr->device;
344 D3DScene *scene = dev_ptr->scene;
345 D3DContext *context = dev_ptr->context;
346
347 Ref<D3DObjectLine> line = scene->GetFreeObject<D3DObjectLine>();
348 if (line == NULL)
349 {
350 line = new D3DObjectLine();
351 scene->AddObject(line);
352 DBG("New line object (total objects: %d)", scene->GetObjectCount());
353 }
354 else
355 {
356 line->SetFree(false);
357 DBG("Line reused (object: %p)", line.Addr());
358 }
359
360 line->Setup(
361 2.f * float(x1) / float(device->GetWidth()) - 1.f,
362 2.f * (1.f - float(y1) / float(device->GetHeight())) - 1.f,
363 2.f * float(x2) / float(device->GetWidth()) - 1.f,
364 2.f * (1.f - float(y2) / float(device->GetHeight())) - 1.f,
365 context->color);
366}
367
368void evas_direct3d_rectangle_draw(Direct3DDeviceHandler d3d, int x, int y, int w, int h)
369{
370 DevicePtr *dev_ptr = SelectDevice(d3d);
371 D3DDevice *device = dev_ptr->device;
372 D3DScene *scene = dev_ptr->scene;
373 D3DContext *context = dev_ptr->context;
374
375 Ref<D3DObjectRect> rect = scene->GetFreeObject<D3DObjectRect>();
376 if (rect == NULL)
377 {
378 rect = new D3DObjectRect();
379 scene->AddObject(rect);
380 DBG("New rect object (total objects: %d)", scene->GetObjectCount());
381 }
382 else
383 {
384 rect->SetFree(false);
385 DBG("Rect reused (object: %p)", rect.Addr());
386 }
387
388 rect->Setup(
389 2.f * float(x) / float(device->GetWidth()) - 1.f,
390 2.f * (1.f - float(y) / float(device->GetHeight())) - 1.f,
391 2.f * float(w) / float(device->GetWidth()),
392 -2.f * float(h) / float(device->GetHeight()),
393 context->color);
394}
395
396Direct3DImageHandler evas_direct3d_image_load(Direct3DDeviceHandler d3d,
397 const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
398{
399 DevicePtr *dev_ptr = SelectDevice(d3d);
400 D3DDevice *device = dev_ptr->device;
401 D3DScene *scene = dev_ptr->scene;
402
403 RGBA_Image *evas_image = evas_common_load_image_from_file(file, key, lo);
404 if (evas_image == NULL)
405 {
406 WRN("Failed to load image from %s", file);
407 return NULL;
408 }
409 int image_width = evas_image->cache_entry.w;
410 int image_height = evas_image->cache_entry.h;
411 assert(image_width > 0 && image_height > 0);
412
413 D3DImageCache::CacheEntryInfo info;
414 ZeroMemory(&info, sizeof(info));
415 info.id = -1;
416
417 Ref<D3DObjectImage> image = new D3DObjectImage();
418 image->Init(info.u, info.v, info.du, info.dv, info.id,
419 info.width, info.height, evas_image->cache_entry.file);
420 image->SetFree(true);
421 scene->AddObject(image);
422
423 DBG("New image object (total objects: %d)", scene->GetObjectCount());
424
425 ImagePtr *ptr = new ImagePtr;
426 ptr->ref = image;
427 ptr->img = evas_image;
428
429 return (Direct3DImageHandler)ptr;
430}
431
432Direct3DImageHandler evas_direct3d_image_new_from_data(Direct3DDeviceHandler d3d,
433 int w, int h, DWORD *image_data, int alpha, int cspace)
434{
435 DevicePtr *dev_ptr = SelectDevice(d3d);
436 D3DDevice *device = dev_ptr->device;
437 D3DScene *scene = dev_ptr->scene;
438
439 int image_width = w;
440 int image_height = h;
441 assert(image_width > 0 && image_height > 0);
442
443 Ref<D3DObjectImage> image = new D3DObjectImage();
444
445 D3DImageCache::CacheEntryInfo info;
446 ZeroMemory(&info, sizeof(info));
447 if (!D3DImageCache::Current()->InsertImage(device, image_data,
448 image_width, image_height, info))
449 {
450 WRN("Couldnt add image to the cache");
451 return NULL;
452 }
453 char buf[64];
454 sprintf(buf, "%p", image_data);
455 image->Init(info.u, info.v, info.du, info.dv, info.id,
456 info.width, info.height, buf);
457
458 image->SetFree(true);
459 scene->AddObject(image);
460
461 DBG("New image object (total objects: %d)", scene->GetObjectCount());
462
463 ImagePtr *ptr = new ImagePtr;
464 ptr->ref = image;
465 ptr->img = NULL;
466
467 return (Direct3DImageHandler)ptr;
468}
469
470Direct3DImageHandler evas_direct3d_image_new_from_copied_data(Direct3DDeviceHandler d3d,
471 int w, int h, DWORD *image_data, int alpha, int cspace)
472{
473 return evas_direct3d_image_new_from_data(d3d, w, h, image_data, alpha, cspace);
474}
475
476void evas_direct3d_image_free(Direct3DDeviceHandler d3d, Direct3DImageHandler image)
477{
478 DevicePtr *dev_ptr = SelectDevice(d3d);
479 D3DDevice *device = dev_ptr->device;
480 D3DScene *scene = dev_ptr->scene;
481
482 ImagePtr *ptr = (ImagePtr *)image;
483
484 Ref<D3DObjectImage> image_ref = ptr->ref;
485 assert(!image_ref.IsNull());
486 scene->DeleteObject(image_ref);
487
488 delete ptr;
489}
490
491void evas_direct3d_image_data_put(Direct3DDeviceHandler d3d, Direct3DImageHandler image,
492 DWORD *image_data)
493{
494 ImagePtr *ptr = (ImagePtr *)image;
495 Ref<D3DObjectImage> image_ref = ptr->ref;
496 //assert(!image_ref.IsNull());
497 if (image_ref.IsNull())
498 return;
499
500 if (!image_ref->UpdateImageData(image_data))
501 ERR("Failed to update image data");
502}
503
504void evas_direct3d_image_data_get(Direct3DDeviceHandler d3d, Direct3DImageHandler image,
505 int to_write, DATA32 **image_data)
506{
507 ImagePtr *ptr = (ImagePtr *)image;
508 Ref<D3DObjectImage> image_ref = ptr->ref;
509 if (image_ref.IsNull())
510 return;
511 if (image_data == NULL)
512 return;
513 assert(sizeof(DATA32) == sizeof(DWORD));
514 *image_data = (DATA32 *)image_ref->GetImageData();
515}
516
517void evas_direct3d_image_draw(Direct3DDeviceHandler d3d, Direct3DImageHandler image,
518 int src_x, int src_y, int src_w, int src_h,
519 int dst_x, int dst_y, int dst_w, int dst_h, int smooth)
520{
521 ImagePtr *ptr = (ImagePtr *)image;
522 Ref<D3DObjectImage> image_ref = ptr->ref;
523 RGBA_Image *evas_image = ptr->img;
524 DevicePtr *dev_ptr = SelectDevice(d3d);
525 D3DDevice *device = dev_ptr->device;
526 D3DScene *scene = dev_ptr->scene;
527 //assert(!image_ref.IsNull());
528 if (image_ref.IsNull())
529 return;
530
531 if (!image_ref->IsValid())
532 {
533 TArray<D3DObjectImage *> images;
534 scene->GetObjectsOfType<D3DObjectImage>(images);
535 bool found = false;
536 for (int i = 0; i < images.Length(); i++)
537 {
538 if (images[i]->IsValid() &&
539 _stricmp(images[i]->GetSource(), image_ref->GetSource()) == 0)
540 {
541 images[i]->CopyTo(image_ref);
542 found = true;
543 WRN("Image object info reused, source: \"%s\"", image_ref->GetSource());
544 break;
545 }
546 }
547 if (!found && evas_image != NULL)
548 evas_cache_image_load_data(&evas_image->cache_entry);
549 }
550
551 // If the image object wasn't initialized yet
552 if (evas_image != NULL && evas_image->image.data != NULL && !image_ref->IsValid())
553 {
554 D3DImageCache::CacheEntryInfo info;
555 ZeroMemory(&info, sizeof(info));
556 if (!D3DImageCache::Current()->InsertImage(device, (DWORD *)evas_image->image.data,
557 evas_image->cache_entry.w, evas_image->cache_entry.h, info))
558 {
559 WRN("Couldnt add image to the cache");
560 return;
561 }
562 image_ref->Init(info.u, info.v, info.du, info.dv, info.id,
563 info.width, info.height, evas_image->cache_entry.file);
564 }
565
566 // Do not draw invalid objects
567 if (!image_ref->IsValid())
568 {
569 image_ref->SetFree(true);
570 return;
571 }
572
573 image_ref->Setup(
574 2.f * float(dst_x) / float(device->GetWidth()) - 1.f,
575 2.f * (1.f - float(dst_y) / float(device->GetHeight())) - 1.f,
576 2.f * float(dst_w) / float(device->GetWidth()),
577 -2.f * float(dst_h) / float(device->GetHeight()),
578 src_x, src_y, src_w, src_h);
579
580 image_ref->SetupColorFilter(dev_ptr->context->color_mul);
581
582 image_ref->SetFree(false);
583}
584
585void evas_direct3d_image_size_get(Direct3DImageHandler image, int *w, int *h)
586{
587 ImagePtr *ptr = (ImagePtr *)image;
588 if (ptr == NULL)
589 return;
590 if (ptr->img != NULL)
591 {
592 if (w != NULL)
593 *w = ptr->img->cache_entry.w;
594 if (h != NULL)
595 *h = ptr->img->cache_entry.h;
596 }
597 else if (!ptr->ref.IsNull())
598 {
599 if (w != NULL)
600 *w = ptr->ref->GetWidth();
601 if (h != NULL)
602 *h = ptr->ref->GetHeight();
603 }
604}
605
606void evas_direct3d_image_border_set(Direct3DDeviceHandler d3d, Direct3DImageHandler image,
607 int l, int r, int t, int b)
608{
609 ImagePtr *ptr = (ImagePtr *)image;
610 Ref<D3DObjectImage> image_ref = ptr->ref;
611 DevicePtr *dev_ptr = SelectDevice(d3d);
612 D3DDevice *device = dev_ptr->device;
613 if (image_ref.IsNull())
614 return;
615
616 int im_w, im_h;
617 if (ptr->img != NULL)
618 {
619 im_w = ptr->img->cache_entry.w;
620 im_h = ptr->img->cache_entry.h;
621 }
622 else
623 {
624 im_w = image_ref->GetWidth();
625 im_h = image_ref->GetHeight();
626 }
627
628 image_ref->SetupBorder(
629 D3DXVECTOR4(
630 2.f * float(l) / float(device->GetWidth()),
631 -2.f * float(t) / float(device->GetHeight()),
632 2.f * float(r) / float(device->GetWidth()),
633 -2.f * float(b) / float(device->GetHeight())),
634 D3DXVECTOR4(float(l) / float(im_w),
635 float(t) / float(im_h),
636 float(r) / float(im_w),
637 float(b) / float(im_h)));
638}
639
640void evas_direct3d_image_border_get(Direct3DDeviceHandler d3d, Direct3DImageHandler image,
641 int *l, int *r, int *t, int *b)
642{
643 ImagePtr *ptr = (ImagePtr *)image;
644 Ref<D3DObjectImage> image_ref = ptr->ref;
645 DevicePtr *dev_ptr = SelectDevice(d3d);
646 D3DDevice *device = dev_ptr->device;
647 if (image_ref.IsNull())
648 return;
649 assert(l != NULL && r != NULL && b != NULL && t != NULL);
650 *l = (int)(0.5f * image_ref->GetBorderLeft() * device->GetWidth());
651 *r = (int)(0.5f * image_ref->GetBorderRight() * device->GetWidth());
652 *t = (int)(-0.5f * image_ref->GetBorderTop() * device->GetHeight());
653 *b = (int)(-0.5f * image_ref->GetBorderBottom() * device->GetHeight());
654}
655
656
657Direct3DFontGlyphHandler evas_direct3d_font_texture_new(Direct3DDeviceHandler d3d,
658 RGBA_Font_Glyph *fg)
659{
660 DevicePtr *dev_ptr = SelectDevice(d3d);
661 D3DContext *context = dev_ptr->context;
662 D3DDevice *device = dev_ptr->device;
663
664 if (context->font.IsNull())
665 return NULL;
666
667 D3DObjectFont *font = (D3DObjectFont *)context->font.Addr();
668 // This is not reliable
669 //D3DObjectFont::Glyph *glyph = (D3DObjectFont::Glyph *)fg->ext_dat;
670 D3DObjectFont::Glyph *glyph = font->GetGlyph(fg);
671 if (glyph != NULL)
672 {
673 assert(glyph->Compare(fg));
674 return glyph;
675 }
676 glyph = font->AddGlyph(device, fg, fg->glyph_out->bitmap.buffer,
677 fg->glyph_out->bitmap.width, fg->glyph_out->bitmap.rows, fg->glyph_out->bitmap.pitch);
678 return (Direct3DFontGlyphHandler)glyph;
679}
680
681void evas_direct3d_font_texture_free(Direct3DFontGlyphHandler ft)
682{
683 if (ft == NULL)
684 return;
685 D3DObjectFont::Glyph *glyph = (D3DObjectFont::Glyph *)ft;
686 RGBA_Font_Glyph *fg = (RGBA_Font_Glyph *)glyph->Source();
687 fg->ext_dat = NULL;
688}
689
690void evas_direct3d_font_texture_draw(Direct3DDeviceHandler d3d, void *, void *,
691 RGBA_Font_Glyph *fg, int x, int y)
692{
693 DevicePtr *dev_ptr = SelectDevice(d3d);
694 D3DContext *context = dev_ptr->context;
695 D3DDevice *device = dev_ptr->device;
696
697 if (context->font.IsNull())
698 return;
699
700 D3DObjectFont *font = (D3DObjectFont *)context->font.Addr();
701 D3DObjectFont::Glyph *glyph = (D3DObjectFont::Glyph *)fg->ext_dat;
702 if (glyph == NULL)
703 return;
704 assert(glyph->Compare(fg));
705
706 font->SetColor(context->color);
707 font->PushForDraw(glyph, x, y);
708 font->SetFree(false);
709}
710
711void evas_direct3d_select_or_create_font(Direct3DDeviceHandler d3d, void *font)
712{
713 // The Plan
714 // 1. Create D3DObjectFont with source string = "%p" (font)
715 // 2. Or find this object in the scene
716 // 3. On each texture_new call - fill internal texture with glyph, remember the
717 // glyph pointer - we'll use it.
718
719 DevicePtr *dev_ptr = SelectDevice(d3d);
720 D3DContext *context = dev_ptr->context;
721
722 if (!context->font.IsNull() && ((D3DObjectFont *)context->font.Addr())->Compare(font))
723 return;
724
725 D3DScene *scene = dev_ptr->scene;
726
727 static TArray<D3DObjectFont *> fonts;
728 scene->GetObjectsOfType<D3DObjectFont>(fonts);
729 for (int i = 0; i < fonts.Length(); i++)
730 {
731 if (fonts[i]->Compare(font))
732 {
733 context->font = fonts[i];
734 return;
735 }
736 }
737
738 D3DDevice *device = dev_ptr->device;
739
740 assert(dev_ptr->fonts_buffer_image_id >= 0);
741
742 Ref<D3DObjectFont> new_font = new D3DObjectFont(font, dev_ptr->fonts_buffer_image_id);
743 scene->AddObject(new_font);
744 context->font = new_font;
745}
746
747void evas_direct3d_font_free(Direct3DDeviceHandler d3d, void *font)
748{
749 DevicePtr *dev_ptr = SelectDevice(d3d);
750 D3DContext *context = dev_ptr->context;
751 D3DScene *scene = dev_ptr->scene;
752
753 if (context->font.IsNull() || !((D3DObjectFont *)context->font.Addr())->Compare(font))
754 {
755 D3DScene *scene = dev_ptr->scene;
756
757 static TArray<D3DObjectFont *> fonts;
758 scene->GetObjectsOfType<D3DObjectFont>(fonts);
759 for (int i = 0; i < fonts.Length(); i++)
760 {
761 if (fonts[i]->Compare(font))
762 {
763 context->font = fonts[i];
764 break;
765 }
766 }
767 }
768
769 scene->DeleteObject(context->font);
770 context->font = NULL;
771}
772
773
774} // extern "C"
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_object.cpp
deleted file mode 100644
index 15a801e0af..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
1
2#include "evas_direct3d_object.h"
3
4D3DObject::D3DObject()
5{
6 _free = false;
7}
8
9D3DObject::~D3DObject()
10{
11}
12
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object.h b/src/modules/evas/engines/direct3d/evas_direct3d_object.h
deleted file mode 100644
index 8c4e6df202..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object.h
+++ /dev/null
@@ -1,35 +0,0 @@
1#ifndef __EVAS_DIRECT3D_OBJECT_H__
2#define __EVAS_DIRECT3D_OBJECT_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7
8class D3DDevice;
9
10class D3DObject : virtual public Referenc
11{
12public:
13 D3DObject();
14 virtual ~D3DObject();
15
16 virtual void Draw(D3DDevice *d3d) = 0;
17
18 inline bool IsFree();
19 inline void SetFree(bool state);
20
21private:
22 bool _free;
23};
24
25bool D3DObject::IsFree()
26{
27 return _free;
28}
29
30void D3DObject::SetFree(bool state)
31{
32 _free = state;
33}
34
35#endif // __EVAS_DIRECT3D_OBJECT_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_font.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_object_font.cpp
deleted file mode 100644
index f072e87523..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_font.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
1//#define ENABLE_LOG_PRINTF
2
3#include <string.h>
4
5#include "evas_direct3d_object_font.h"
6#include "evas_direct3d_image_cache.h"
7#include "evas_direct3d_device.h"
8#include "evas_direct3d_shader_pack.h"
9#include "evas_direct3d_vertex_buffer_cache.h"
10
11D3DObjectFont::Cache D3DObjectFont::_cache;
12
13D3DObjectFont::D3DObjectFont(void *source, int image_id)
14{
15 _image_id = image_id;
16 _color = 0xff000000;
17 _source = source;
18 D3DImageCache::Current()->AddImageUser(_image_id);
19}
20
21D3DObjectFont::~D3DObjectFont()
22{
23 D3DImageCache::Current()->RemoveImageUser(_image_id);
24}
25
26void D3DObjectFont::CopyTo(D3DObjectFont *font)
27{
28 assert(font != NULL);
29 font->_image_id = _image_id;
30 font->_source = _source;
31 D3DImageCache::Current()->AddImageUser(font->_image_id);
32 _glyphs.CopyTo(font->_glyphs);
33}
34
35void D3DObjectFont::BeginCache(int image_id)
36{
37 if (_cache.enabled)
38 return;
39 int w = D3DImageCache::Current()->GetImageWidth(image_id);
40 int h = D3DImageCache::Current()->GetImageHeight(image_id);
41 _cache.enabled = true;
42 _cache.image_id = image_id;
43 _cache.data.Allocate(w * h);
44
45 if (_cache.dirty.Length() != h)
46 {
47 _cache.dirty.Allocate(h);
48 memset(_cache.dirty.Data(), 0xff, sizeof(POINT) * _cache.dirty.Length());
49 }
50
51 ZeroMemory(_cache.data.Data(), sizeof(DWORD) * _cache.data.Length());
52 _cache.width = w;
53 _cache.height = h;
54
55 _cache.valid_rect.left = w;
56 _cache.valid_rect.right = 0;
57 _cache.valid_rect.top = h;
58 _cache.valid_rect.bottom = 0;
59}
60
61void D3DObjectFont::Draw(D3DDevice *d3d)
62{
63 assert(_cache.image_id == _image_id);
64}
65
66void D3DObjectFont::EndCache(D3DDevice *d3d)
67{
68 if (!_cache.enabled)
69 return;
70 _cache.enabled = false;
71
72 if (_cache.data.Length() == 0)
73 return;
74
75 D3DImageCache::CacheEntryInfo info;
76 ZeroMemory(&info, sizeof(info));
77 info.id = _cache.image_id;
78 info.width = _cache.width;
79 info.height = _cache.height;
80 if (!D3DImageCache::Current()->UpdateImageDataWithDirtyInfo(info,
81 _cache.data.Data(), _cache.dirty.Data()))
82 //if (!D3DImageCache::Current()->UpdateImageDataDiscard(info, _cache.data.Data()));
83 {
84 return;
85 }
86
87 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYUV);
88 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_UV);
89 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_TEX_2); // This image is in s1
90 D3DImageCache::Current()->SelectImageToDevice(d3d, _cache.image_id);
91
92 const FLOAT half_x = 0.5f / FLOAT(_cache.width);
93 const FLOAT half_y = 0.5f / FLOAT(_cache.height);
94 FLOAT left = FLOAT(_cache.valid_rect.left - 5) / FLOAT(_cache.width),
95 top = FLOAT(_cache.valid_rect.top - 5) / FLOAT(_cache.height),
96 right = FLOAT(_cache.valid_rect.right + 5) / FLOAT(_cache.width),
97 bottom = FLOAT(_cache.valid_rect.bottom + 5) / FLOAT(_cache.height);
98
99 const Vertex data[6] = {
100 {left * 2 - 1, 2 * (1 - bottom) - 1, left + half_x, bottom + half_y},
101 {left * 2 - 1, 2 * (1 - top) - 1, left + half_x, top + half_y},
102 {right * 2 - 1, 2 * (1 - bottom) - 1, right + half_x, bottom + half_y},
103 {right * 2 - 1, 2 * (1 - bottom) - 1, right + half_x, bottom + half_y},
104 {left * 2 - 1, 2 * (1 - top) - 1, left + half_x, top + half_y},
105 {right * 2 - 1, 2 * (1 - top) - 1, right + half_x, top + half_y}};
106
107 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, data, sizeof(Vertex));
108
109 //D3DImageCache::Current()->UpdateImageDataWithDirtyInfo(info, NULL, _cache.dirty.Data());
110}
111
112D3DObjectFont::Glyph *D3DObjectFont::GetGlyph(void *source)
113{
114 if (_image_id < 0)
115 {
116 WRN("Font is not initialized");
117 return NULL;
118 }
119 for (int i = 0; i < _glyphs.Length(); i++)
120 {
121 if (_glyphs[i]->Compare(source))
122 return _glyphs[i];
123 }
124 return NULL;
125}
126
127D3DObjectFont::Glyph *D3DObjectFont::AddGlyph(D3DDevice *d3d, void *source,
128 BYTE *data8, int width, int height, int pitch)
129{
130 if (_image_id < 0)
131 {
132 WRN("Font is not initialized");
133 return NULL;
134 }
135 for (int i = 0; i < _glyphs.Length(); i++)
136 {
137 if (_glyphs[i]->Compare(source))
138 return _glyphs[i];
139 }
140 Ref<Glyph> glyph = new Glyph(source);
141 glyph->_data.Allocate(width * height);
142 glyph->_width = width;
143 glyph->_height = height;
144
145 for (int i = 0; i < height; i++)
146 CopyMemory(&glyph->_data[i * width], &data8[i * pitch], width);
147
148 Log("Glyph added (%p) (%dx%d)", source, width, height);
149 _glyphs.Add(glyph);
150 return _glyphs.Last()->Addr();
151}
152
153void D3DObjectFont::PushForDraw(Glyph *glyph, int x, int y)
154{
155 BeginCache(_image_id);
156
157 // Uff, I'm not sure about multiple windows...
158
159#define LERP(a, b, t1, t2) (BYTE)(FLOAT(a) * (t1) + FLOAT(b) * (t2))
160
161 Color dc, sc;
162 FLOAT a;
163 sc.color = _color;
164
165 const FLOAT color_alpha = sc.Alpha();
166
167 DWORD *data = _cache.data.Data();
168 BYTE *gdata = glyph->_data.Data();
169 const int glyph_height = glyph->_height;
170 const int cache_height = _cache.height;
171 const int glyph_width = glyph->_width;
172 const int cache_width = _cache.width;
173
174 for (int i = 0, yi = y; i < glyph_height && yi < cache_height; i++, yi++)
175 {
176 if (yi < 0)
177 continue;
178 DWORD *dst = data + ((yi) * cache_width + x);
179 BYTE *src = gdata + (i * glyph_width);
180 POINT *dirty_yi = &_cache.dirty[yi];
181
182 if (_cache.valid_rect.top > yi)
183 _cache.valid_rect.top = yi;
184 if (_cache.valid_rect.bottom < yi)
185 _cache.valid_rect.bottom = yi;
186
187 for (int j = 0, xj = x; j < glyph_width && xj < cache_width; j++, xj++, dst++, src++)
188 {
189 if (xj < 0)
190 continue;
191 BYTE glyph_pix = *src;
192 if (glyph_pix == 0)
193 continue;
194
195 if (dirty_yi->x >= 0 && dirty_yi->y < 0)
196 dirty_yi->x = 0, dirty_yi->y = cache_width - 1;
197 else
198 {
199 if (dirty_yi->x < 0 || dirty_yi->x > xj)
200 dirty_yi->x = xj;
201 if (dirty_yi->y < 0 || dirty_yi->y < xj)
202 dirty_yi->y = xj;
203 }
204
205 if (_cache.valid_rect.left > xj)
206 _cache.valid_rect.left = xj;
207 if (_cache.valid_rect.right < xj)
208 _cache.valid_rect.right = xj;
209
210 if (glyph_pix == 0xff && sc.a == 0xff)
211 {
212 *dst = sc.color;
213 continue;
214 }
215 a = FLOAT(glyph_pix) * color_alpha / 255.f;
216 if (*dst == 0)
217 {
218 *dst = (BYTE(255.f * a) << 24) | (0x00ffffff & sc.color);
219 continue;
220 }
221
222 dc.color = *dst;
223
224 dc.r = LERP(dc.r, sc.r, 1 - a, a);
225 dc.g = LERP(dc.g, sc.g, 1 - a, a);
226 dc.b = LERP(dc.b, sc.b, 1 - a, a);
227 dc.a = max(dc.a, BYTE(255.f * a));
228 *dst = dc.color;
229 }
230 }
231}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_font.h b/src/modules/evas/engines/direct3d/evas_direct3d_object_font.h
deleted file mode 100644
index e8c0196827..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_font.h
+++ /dev/null
@@ -1,113 +0,0 @@
1#ifndef __EVAS_DIRECT3D_OBJECT_FONT_H__
2#define __EVAS_DIRECT3D_OBJECT_FONT_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "array.h"
8
9#include "evas_direct3d_object.h"
10
11class D3DObjectFont : public D3DObject
12{
13public:
14
15 class Glyph : public Referenc
16 {
17 public:
18 Glyph(void *source)
19 : _source(source), _width(0), _height(0) {};
20
21 bool Compare(void *source)
22 {
23 return (_source == source);
24 }
25 void *Source()
26 {
27 return _source;
28 }
29
30 private:
31 friend class D3DObjectFont;
32 void *_source;
33 TArray<BYTE> _data;
34 int _width;
35 int _height;
36 };
37
38public:
39 D3DObjectFont(void *source, int image_id);
40 ~D3DObjectFont();
41
42 inline bool Compare(void *source);
43 void CopyTo(D3DObjectFont *font);
44
45 virtual void Draw(D3DDevice *d3d);
46 static void EndCache(D3DDevice *d3d);
47
48 inline void SetColor(DWORD color);
49
50 Glyph *GetGlyph(void *source);
51 Glyph *AddGlyph(D3DDevice *d3d, void *source, BYTE *data8, int width, int height, int pitch);
52 void PushForDraw(Glyph *glyph, int x, int y);
53
54protected:
55 static void BeginCache(int image_id);
56
57private:
58 struct Vertex
59 {
60 FLOAT x, y;
61 FLOAT u, v;
62 };
63
64 struct Color
65 {
66 union
67 {
68 struct
69 {
70 BYTE b, g, r, a;
71 };
72 DWORD color;
73 };
74
75 FLOAT Alpha() { return FLOAT(a) / 255.f; }
76 };
77
78 class Cache
79 {
80 public:
81 Cache()
82 : enabled(false), image_id(-1), width(0), height(0) {};
83 public:
84 TArray<DWORD> data;
85 TArray<POINT> dirty; // Start, End
86 bool enabled;
87 int image_id;
88 int width;
89 int height;
90 RECT valid_rect;
91 };
92
93private:
94 DWORD _color;
95 void *_source;
96 int _image_id;
97
98 TArray<Ref<Glyph> > _glyphs;
99
100 static Cache _cache;
101};
102
103bool D3DObjectFont::Compare(void *source)
104{
105 return (_source == source);
106}
107
108void D3DObjectFont::SetColor(DWORD color)
109{
110 _color = color;
111}
112
113#endif // __EVAS_DIRECT3D_OBJECT_FONT_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_image.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_object_image.cpp
deleted file mode 100644
index 3bfbe1e565..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_image.cpp
+++ /dev/null
@@ -1,320 +0,0 @@
1//#define ENABLE_LOG_PRINTF
2
3#include <string.h>
4
5#include <d3dx9.h>
6
7#include "evas_direct3d_object_image.h"
8#include "evas_direct3d_image_cache.h"
9#include "evas_direct3d_device.h"
10#include "evas_direct3d_shader_pack.h"
11#include "evas_direct3d_vertex_buffer_cache.h"
12
13TArray<D3DObjectImage *> D3DObjectImage::_cache;
14bool D3DObjectImage::_cache_enabled = false;
15
16D3DObjectImage::D3DObjectImage()
17{
18 _x = _y = _w = _h = 0;
19 _sx = _sy = _sw = _sh = 0;
20 _u = _v = _du = _dv = 0;
21 _image_id = -1;
22 _width = _height = 0;
23 _source[0] = 0;
24 _color = 0xffffffff;
25 _cache_i = 0;
26 _border = D3DXVECTOR4(0, 0, 0, 0);
27 _uvborder = D3DXVECTOR4(0, 0, 0, 0);
28 _with_border = false;
29 _dirty = false;
30 _image_data_updated = false;
31}
32
33D3DObjectImage::~D3DObjectImage()
34{
35 D3DImageCache::Current()->RemoveImageUser(_image_id);
36}
37
38void D3DObjectImage::CopyTo(D3DObjectImage *image)
39{
40 assert(image != NULL);
41 image->_u = _u;
42 image->_v = _v;
43 image->_du = _du;
44 image->_dv = _dv;
45 image->_image_id = _image_id;
46 image->_width = _width;
47 image->_height = _height;
48 CopyMemory(image->_source, _source, sizeof(_source));
49 D3DImageCache::Current()->AddImageUser(image->_image_id);
50}
51
52void D3DObjectImage::BeginCache()
53{
54 _cache.Allocate(0);
55 _cache_enabled = true;
56}
57
58void D3DObjectImage::EndCache(D3DDevice *d3d)
59{
60 if (!_cache_enabled || _cache.Length() == 0)
61 return;
62 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYUVC);
63 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_UV_COLOR);
64 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_TEX_COLOR_FILTER);
65
66 static TArray<Vertex> sorted;
67 static TArray<GroupDesc> groups;
68 sorted.Allocate(0);
69 groups.Allocate(0);
70
71 bool found = true;
72 while (found)
73 {
74 found = false;
75 int cur_id = -1;
76 int num = 0;
77 for (int i = 0; i < _cache.Length(); i++)
78 {
79 // We have processed this
80 if (_cache[i]->_image_id < 0)
81 continue;
82 found = true;
83 if (cur_id < 0)
84 cur_id = _cache[i]->_image_id;
85 if (_cache[i]->_image_id == cur_id)
86 {
87 if (!_cache[i]->_with_border)
88 {
89 Vertex *data = _cache[i]->MakeData();
90 sorted.Add(data[0]);
91 sorted.Add(data[1]);
92 sorted.Add(data[2]);
93 sorted.Add(data[3]);
94 sorted.Add(data[4]);
95 sorted.Add(data[5]);
96 _cache[i]->_image_id = -_cache[i]->_image_id - 1;
97 num++;
98 }
99 else
100 {
101 Vertex *data = _cache[i]->MakeDataBorder();
102 int last_len = sorted.Length();
103 sorted.Allocate(last_len + 6 * 9);
104 CopyMemory(&sorted[last_len], data, sizeof(Vertex) * 6 * 9);
105 _cache[i]->_image_id = -_cache[i]->_image_id - 1;
106 num += 9;
107 }
108 }
109 }
110 if (num > 0)
111 {
112 GroupDesc gd = {num, cur_id};
113 groups.Add(gd);
114 }
115 }
116
117 // Restore ids
118 for (int i = 0; i < _cache.Length(); i++)
119 _cache[i]->_image_id = -_cache[i]->_image_id - 1;
120
121 D3DVertexBufferCache::CacheEntryInfo ce_info;
122 if (!D3DVertexBufferCache::Current()->InitBuffer(d3d, (BYTE *)sorted.Data(),
123 sorted.Length() * sizeof(Vertex), ce_info))
124 {
125 return;
126 }
127 D3DVertexBufferCache::Current()->SelectBufferToDevice(d3d, ce_info.id, sizeof(Vertex));
128
129 HRESULT hr;
130 for (int i = 0, cur = 0; i < groups.Length(); i++)
131 {
132 if (FAILED(hr = D3DImageCache::Current()->SelectImageToDevice(d3d, groups[i].id)))
133 {
134 Log("Failed to select texture: %X", (DWORD)hr);
135 }
136// d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, groups[i].num * 2,
137// &sorted[cur], sizeof(Vertex));
138 d3d->GetDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, cur, groups[i].num * 2);
139 cur += groups[i].num * 6;
140 }
141
142 DBG("Image cache drawn: %d items, %d groups", _cache.Length(), groups.Length());
143 _cache_enabled = false;
144}
145
146void D3DObjectImage::Draw(D3DDevice *d3d)
147{
148 _dirty = false;
149
150 DBG("Image draw: (%.3f, %.3f, %.3f, %.3f)", _x, _y, _w, _h);
151
152 if (_cache_enabled)
153 {
154 _cache.Add(this);
155 _cache_i = _cache.Length() - 1;
156 return;
157 }
158
159 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYUVC);
160 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_UV_COLOR);
161 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_TEX_COLOR_FILTER);
162 D3DImageCache::Current()->SelectImageToDevice(d3d, _image_id);
163
164 if (!_with_border)
165 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, MakeData(), sizeof(Vertex));
166 else
167 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 18, MakeDataBorder(), sizeof(Vertex));
168}
169
170void D3DObjectImage::Init(FLOAT u, FLOAT v, FLOAT du, FLOAT dv,
171 int image_id, int width, int height, const char *source)
172{
173 _u = u;
174 _v = v;
175 _du = du;
176 _dv = dv;
177 _image_id = image_id;
178 _width = width;
179 _height = height;
180#ifdef __MINGW32__
181 strncpy(_source, source, sizeof(_source) - 1);
182#else
183 strncpy_s(_source, sizeof(_source), source, sizeof(_source) - 1);
184#endif // ! __MINGW32__
185}
186
187void D3DObjectImage::Setup(FLOAT x, FLOAT y, FLOAT w, FLOAT h,
188 int sx, int sy, int sw, int sh)
189{
190 if (!_dirty)
191 {
192 _x = 1.f;
193 _y = -1.f;
194 _w = _h = 0.f;
195 _sx = _sy = 1.f;
196 _sw = _sh = 0.f;
197 }
198
199 if (!_with_border)
200 {
201 _x = x;
202 _y = y;
203 _w = w;
204 _h = h;
205 _sx = FLOAT(sx) / FLOAT(_width);
206 _sy = FLOAT(sy) / FLOAT(_height);
207 _sw = FLOAT(sw) / FLOAT(_width);
208 _sh = FLOAT(sh) / FLOAT(_height);
209 }
210 else
211 {
212 _x = min(_x, x);
213 _y = max(_y, y);
214 _w += w / 3;
215 _h += h / 3;
216 _sx = min(_sx, FLOAT(sx) / FLOAT(_width));
217 _sy = min(_sy, FLOAT(sy) / FLOAT(_height));
218 _sw += FLOAT(sw) / (3.f * FLOAT(_width));
219 _sh += FLOAT(sh) / (3.f * FLOAT(_height));
220 }
221 _dirty = true;
222
223}
224
225void D3DObjectImage::SetupColorFilter(DWORD color)
226{
227 //_color = ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
228 _color = color;
229}
230
231D3DObjectImage::Vertex *D3DObjectImage::MakeData()
232{
233 //FLOAT z = (FLOAT(_cache_i) + 0.5f) / _cache.Length();
234 Vertex data[6] = {
235 {_x, _y, _u + _sx * _du, _v + _sy * _dv, _color},
236 {_x + _w, _y, _u + (_sx + _sw) * _du, _v + _sy * _dv, _color},
237 {_x, _y + _h, _u + _sx * _du, _v + (_sy + _sh) * _dv, _color},
238 {_x, _y + _h, _u + _sx * _du, _v + (_sy + _sh) * _dv, _color},
239 {_x + _w, _y, _u + (_sx + _sw) * _du, _v + _sy * _dv, _color},
240 {_x + _w, _y + _h, _u + (_sx + _sw) * _du, _v + (_sy + _sh) * _dv, _color}};
241 CopyMemory(_data, data, sizeof(data));
242 return _data;
243}
244
245D3DObjectImage::Vertex *D3DObjectImage::MakeDataBorder()
246{
247 //FLOAT z = (FLOAT(_cache_i) + 0.5f) / _cache.Length();
248 if (_border.x + _border.z > _w)
249 _border.x = _border.z = _w / 2;
250 if (_border.y + _border.w < _h)
251 _border.y = _border.w = _h / 2;
252
253 FLOAT ul, ut, ur, ub;
254 ul = _uvborder.x * _du;
255 ut = _uvborder.y * _dv;
256 ur = _uvborder.z * _du;
257 ub = _uvborder.w * _dv;
258 FLOAT bl, bt, br, bb;
259 bl = _border.x;
260 bt = _border.y;
261 br = _border.z;
262 bb = _border.w;
263
264 const FLOAT half_x = 0.5f * _du / FLOAT(_width);
265 const FLOAT half_y = 0.5f * _dv / FLOAT(_height);
266
267 // Diagonal knots
268 Vertex data[4] = {
269 {_x, _y, _u + _sx * _du + half_x, _v + _sy * _dv + half_y, _color},
270 {_x + bl, _y + bt, _u + ul + _sx * _du, _v + ut + _sy * _dv, _color},
271 {_x + _w - br, _y + _h - bb, _u - ur + (_sx + _sw) * _du, _v - ub + (_sy + _sh) * _dv, _color},
272 {_x + _w, _y + _h, _u + (_sx + _sw) * _du - half_x, _v + (_sy + _sh) * _dv - half_y, _color}};
273
274 static const int yshift[6] = {0, 0, 1, 1, 0, 1};
275 static const int xshift[6] = {0, 1, 0, 0, 1, 1};
276
277 int vi = 0;
278 for (int i = 0; i < 3; i++)
279 {
280 for (int j = 0; j < 3; j++)
281 {
282 for (int v = 0; v < 6; v++)
283 {
284 _data[vi].x = data[xshift[v] + j].x;
285 _data[vi].y = data[yshift[v] + i].y;
286 _data[vi].u = data[xshift[v] + j].u;
287 _data[vi].v = data[yshift[v] + i].v;
288 _data[vi].col = data[0].col;
289 vi++;
290 }
291 }
292 }
293
294 return _data;
295}
296
297void D3DObjectImage::SetupBorder(const D3DXVECTOR4 &world_border, const D3DXVECTOR4 &pix_border)
298{
299 _border = world_border;
300 _uvborder = pix_border;
301 _with_border = (_border.x > 0.0001f || _border.y > 0.0001f ||
302 _border.z > 0.0001f || _border.w > 0.0001f);
303}
304
305bool D3DObjectImage::UpdateImageData(DWORD *image_data)
306{
307 D3DImageCache::CacheEntryInfo info = {_image_id, _width, _height, _u, _v, _du, _dv};
308 _image_data_updated = false;
309 return D3DImageCache::Current()->UpdateImageData(info, image_data);
310}
311
312DWORD *D3DObjectImage::GetImageData()
313{
314 if (_image_data_updated)
315 return _image_data.Data();
316 _image_data_updated = true;
317 D3DImageCache::CacheEntryInfo info = {_image_id, _width, _height, _u, _v, _du, _dv};
318 D3DImageCache::Current()->GetImageData(info, _image_data);
319 return _image_data.Data();
320}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_image.h b/src/modules/evas/engines/direct3d/evas_direct3d_object_image.h
deleted file mode 100644
index 379207b114..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_image.h
+++ /dev/null
@@ -1,127 +0,0 @@
1#ifndef __EVAS_DIRECT3D_OBJECT_IMAGE_H__
2#define __EVAS_DIRECT3D_OBJECT_IMAGE_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "array.h"
8
9#include "evas_direct3d_object.h"
10
11class D3DObjectImage : public D3DObject
12{
13public:
14 D3DObjectImage();
15 virtual ~D3DObjectImage();
16
17 void CopyTo(D3DObjectImage *image);
18
19 static void BeginCache();
20 virtual void Draw(D3DDevice *d3d);
21 static void EndCache(D3DDevice *d3d);
22
23 void Init(FLOAT u, FLOAT v, FLOAT du, FLOAT dv, int image_id,
24 int width, int height, const char *source);
25 void Setup(FLOAT x, FLOAT y, FLOAT w, FLOAT h,
26 int sx, int sy, int sw, int sh);
27 void SetupColorFilter(DWORD color);
28 void SetupBorder(const D3DXVECTOR4 &world_border, const D3DXVECTOR4 &pix_border);
29
30 inline bool IsValid();
31 inline const char *GetSource();
32 inline int GetWidth();
33 inline int GetHeight();
34 inline FLOAT GetBorderLeft();
35 inline FLOAT GetBorderRight();
36 inline FLOAT GetBorderTop();
37 inline FLOAT GetBorderBottom();
38
39 bool UpdateImageData(DWORD *image_data);
40 DWORD *GetImageData();
41
42private:
43 struct Vertex
44 {
45 FLOAT x, y;
46 FLOAT u, v;
47 D3DCOLOR col;
48 };
49
50 struct GroupDesc
51 {
52 int num;
53 int id;
54 };
55
56private:
57 Vertex *MakeData();
58 Vertex *MakeDataBorder();
59
60private:
61 FLOAT _x, _y, _w, _h;
62 FLOAT _sx, _sy, _sw, _sh;
63 D3DXVECTOR4 _border;
64 D3DXVECTOR4 _uvborder;
65
66 FLOAT _u, _v, _du, _dv;
67 int _image_id;
68 int _width, _height;
69
70 D3DCOLOR _color;
71 int _cache_i;
72 bool _with_border;
73 bool _dirty;
74
75 TArray<DWORD> _image_data;
76 bool _image_data_updated;
77
78 char _source[256];
79
80 Vertex _data[54];
81
82 static TArray<D3DObjectImage *> _cache;
83 static bool _cache_enabled;
84};
85
86bool D3DObjectImage::IsValid()
87{
88 return _image_id >= 0 && _width > 0 && _height > 0;
89}
90
91const char *D3DObjectImage::GetSource()
92{
93 return _source;
94}
95
96int D3DObjectImage::GetWidth()
97{
98 return _width;
99}
100
101int D3DObjectImage::GetHeight()
102{
103 return _height;
104}
105
106FLOAT D3DObjectImage::GetBorderLeft()
107{
108 return _border.x;
109}
110
111FLOAT D3DObjectImage::GetBorderRight()
112{
113 return _border.z;
114}
115
116FLOAT D3DObjectImage::GetBorderTop()
117{
118 return _border.y;
119}
120
121FLOAT D3DObjectImage::GetBorderBottom()
122{
123 return _border.w;
124}
125
126
127#endif // __EVAS_DIRECT3D_OBJECT_IMAGE_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_line.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_object_line.cpp
deleted file mode 100644
index 9442243ab5..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_line.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
1
2#include "evas_direct3d_object_line.h"
3#include "evas_direct3d_device.h"
4#include "evas_direct3d_shader_pack.h"
5
6TArray<D3DObjectLine::Vertex> D3DObjectLine::_cache;
7bool D3DObjectLine::_cache_enabled = false;
8
9D3DObjectLine::D3DObjectLine()
10{
11 _x1 = _y1 = 0;
12 _x2 = _y2 = 0;
13}
14
15void D3DObjectLine::BeginCache()
16{
17 _cache.Allocate(0);
18 _cache_enabled = true;
19}
20
21void D3DObjectLine::EndCache(D3DDevice *d3d)
22{
23 if (!_cache_enabled || _cache.Length() == 0)
24 return;
25 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
26 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
27 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
28 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_LINELIST, _cache.Length() / 2,
29 _cache.Data(), sizeof(Vertex));
30
31 DBG("Line cache drawn: %d items", _cache.Length() / 2);
32 _cache_enabled = false;
33}
34
35void D3DObjectLine::Draw(D3DDevice *d3d)
36{
37 Vertex data[2] = {{_x1, _y1, _color}, {_x2, _y2, _color}};
38
39 if (!_cache_enabled)
40 {
41 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
42 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
43 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
44 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_LINELIST, 1, data, sizeof(Vertex));
45 }
46 else
47 {
48 _cache.Add(data[0]);
49 _cache.Add(data[1]);
50 }
51}
52
53void D3DObjectLine::Setup(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, DWORD color)
54{
55 _x1 = x1;
56 _y1 = y1;
57 _x2 = x2;
58 _y2 = y2;
59 _color = color;
60}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_line.h b/src/modules/evas/engines/direct3d/evas_direct3d_object_line.h
deleted file mode 100644
index 0e5d8078dc..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_line.h
+++ /dev/null
@@ -1,37 +0,0 @@
1#ifndef __EVAS_DIRECT3D_OBJECT_LINE_H__
2#define __EVAS_DIRECT3D_OBJECT_LINE_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "array.h"
8
9#include "evas_direct3d_object.h"
10
11class D3DObjectLine : public D3DObject
12{
13public:
14 D3DObjectLine();
15
16 static void BeginCache();
17 virtual void Draw(D3DDevice *d3d);
18 static void EndCache(D3DDevice *d3d);
19
20 void Setup(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, DWORD color);
21
22private:
23 FLOAT _x1, _y1, _x2, _y2;
24 DWORD _color;
25
26private:
27 struct Vertex
28 {
29 FLOAT x, y;
30 DWORD color;
31 };
32
33 static TArray<Vertex> _cache;
34 static bool _cache_enabled;
35};
36
37#endif // __EVAS_DIRECT3D_OBJECT_LINE_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.cpp
deleted file mode 100644
index ebdd22be95..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
1#include "evas_direct3d_object_rect.h"
2#include "evas_direct3d_device.h"
3#include "evas_direct3d_shader_pack.h"
4
5TArray<D3DObjectRect::Vertex> D3DObjectRect::_cache;
6bool D3DObjectRect::_cache_enabled = false;
7
8D3DObjectRect::D3DObjectRect()
9{
10 _x = _y = 0;
11 _w = _h = 0;
12}
13
14void D3DObjectRect::BeginCache()
15{
16 _cache.Allocate(0);
17 _cache_enabled = true;
18}
19
20void D3DObjectRect::EndCache(D3DDevice *d3d)
21{
22 if (!_cache_enabled || _cache.Length() == 0)
23 return;
24 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
25 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
26 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
27 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, _cache.Length() / 3,
28 _cache.Data(), sizeof(Vertex));
29
30 DBG("Rect cache drawn: %d items", _cache.Length() / 6);
31 _cache_enabled = false;
32}
33
34void D3DObjectRect::Draw(D3DDevice *d3d)
35{
36 Vertex data[6] = {
37 {_x, _y, _color}, {_x + _w, _y, _color}, {_x, _y + _h, _color},
38 {_x, _y + _h, _color}, {_x + _w, _y, _color}, {_x + _w, _y + _h, _color}};
39
40 if (!_cache_enabled)
41 {
42 D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
43 D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
44 D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
45 d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, data, sizeof(Vertex));
46 }
47 else
48 {
49 _cache.Add(data[0]);
50 _cache.Add(data[1]);
51 _cache.Add(data[2]);
52 _cache.Add(data[3]);
53 _cache.Add(data[4]);
54 _cache.Add(data[5]);
55 }
56}
57
58void D3DObjectRect::Setup(FLOAT x, FLOAT y, FLOAT w, FLOAT h, DWORD color)
59{
60 _x = x;
61 _y = y;
62 _w = w;
63 _h = h;
64 _color = color;
65}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.h b/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.h
deleted file mode 100644
index f7ef084ab2..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_object_rect.h
+++ /dev/null
@@ -1,37 +0,0 @@
1#ifndef __EVAS_DIRECT3D_OBJECT_RECT_H__
2#define __EVAS_DIRECT3D_OBJECT_RECT_H__
3
4#include "evas_engine.h"
5
6#include "ref.h"
7#include "array.h"
8
9#include "evas_direct3d_object.h"
10
11class D3DObjectRect : public D3DObject
12{
13public:
14 D3DObjectRect();
15
16 static void BeginCache();
17 virtual void Draw(D3DDevice *d3d);
18 static void EndCache(D3DDevice *d3d);
19
20 void Setup(FLOAT x, FLOAT y, FLOAT w, FLOAT h, DWORD color);
21
22private:
23 FLOAT _x, _y, _w, _h;
24 DWORD _color;
25
26private:
27 struct Vertex
28 {
29 FLOAT x, y;
30 DWORD color;
31 };
32
33 static TArray<Vertex> _cache;
34 static bool _cache_enabled;
35};
36
37#endif // __EVAS_DIRECT3D_OBJECT_RECT_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_scene.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_scene.cpp
deleted file mode 100644
index b171fc0d8c..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_scene.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
1
2#include "evas_direct3d_scene.h"
3
4D3DScene::D3DScene()
5{
6}
7
8void D3DScene::FreeObjects()
9{
10 for (int i = 0; i < _objects.Length(); i++)
11 _objects[i]->SetFree(true);
12}
13
14void D3DScene::DrawAll(D3DDevice *d3d)
15{
16 for (int i = 0; i < _objects.Length(); i++)
17 {
18 if (!_objects[i]->IsFree())
19 _objects[i]->Draw(d3d);
20 }
21}
22
23void D3DScene::DeleteObject(D3DObject *object)
24{
25 for (int i = 0; i < _objects.Length(); i++)
26 {
27 if (_objects[i].Addr() == object)
28 {
29 _objects.Replace(i);
30 return;
31 }
32 }
33}
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_scene.h b/src/modules/evas/engines/direct3d/evas_direct3d_scene.h
deleted file mode 100644
index e2f5f944ce..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_scene.h
+++ /dev/null
@@ -1,63 +0,0 @@
1#ifndef __EVAS_DIRECT3D_SCENE_H__
2#define __EVAS_DIRECT3D_SCENE_H__
3
4#include "evas_engine.h"
5
6#include <assert.h>
7#include <typeinfo>
8
9#include "ref.h"
10#include "array.h"
11
12#include "evas_direct3d_object.h"
13
14class D3DDevice;
15
16class D3DScene : virtual public Referenc
17{
18public:
19 D3DScene();
20
21 void FreeObjects();
22
23 inline void AddObject(D3DObject *object);
24 inline int GetObjectCount();
25 void DeleteObject(D3DObject *object);
26
27 void DrawAll(D3DDevice *d3d);
28
29 template <class T> T *GetFreeObject()
30 {
31 for (int i = 0; i < _objects.Length(); i++)
32 {
33 if (typeid(T) == typeid(*_objects[i].Addr()) && _objects[i]->IsFree())
34 return (T *)_objects[i].Addr();
35 }
36 return NULL;
37 }
38
39 template <class T> void GetObjectsOfType(TArray<T *> &res)
40 {
41 for (int i = 0; i < _objects.Length(); i++)
42 {
43 if (typeid(T) == typeid(*_objects[i].Addr()))
44 res.Add((T *)_objects[i].Addr());
45 }
46 }
47
48private:
49 TArray<Ref<D3DObject> > _objects;
50};
51
52void D3DScene::AddObject(D3DObject *object)
53{
54 assert(object != NULL);
55 _objects.Add(object);
56}
57
58int D3DScene::GetObjectCount()
59{
60 return _objects.Length();
61}
62
63#endif // __EVAS_DIRECT3D_SCENE_H__
diff --git a/src/modules/evas/engines/direct3d/evas_direct3d_shader_pack.cpp b/src/modules/evas/engines/direct3d/evas_direct3d_shader_pack.cpp
deleted file mode 100644
index d9c868f9b6..0000000000
--- a/src/modules/evas/engines/direct3d/evas_direct3d_shader_pack.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
1
2#include <assert.h>
3
4#include <d3dx9.h>
5
6#include "evas_direct3d_shader_pack.h"
7#include "evas_direct3d_device.h"
8
9Ref<D3DShaderPack> D3DShaderPack::_this;
10
11D3DShaderPack::D3DShaderPack()
12{
13}
14
15D3DShaderPack::~D3DShaderPack()
16{
17 Uninitialize();
18}
19
20D3DShaderPack *D3DShaderPack::Current()
21{
22 if (_this.IsNull())
23 _this = new D3DShaderPack();
24 return _this;
25}
26
27void D3DShaderPack::SetCurrent(D3DShaderPack *obj)
28{
29 _this = obj;
30}
31
32
33bool D3DShaderPack::Initialize(D3DDevice *d3d)
34{
35 bool res = true;
36 if (!(res = InitVertexDeclarations(d3d) && res))
37 WRN("Failed to create vdecl set");
38 if (!(res = InitVertexShaders(d3d) && res))
39 WRN("Failed to create vs set");
40 if (!(res = InitPixelShaders(d3d) && res))
41 WRN("Failed to create ps set");
42 return res;
43}
44
45void D3DShaderPack::Uninitialize()
46{
47 for (int i = 0; i < _vdecl.Length(); i++)
48 {
49 if (_vdecl[i] != NULL)
50 {
51 _vdecl[i]->Release();
52 _vdecl[i] = NULL;
53 }
54 }
55
56 for (int i = 0; i < _vs.Length(); i++)
57 {
58 if (_vs[i] != NULL)
59 {
60 _vs[i]->Release();
61 _vs[i] = NULL;
62 }
63 }
64
65 for (int i = 0; i < _ps.Length(); i++)
66 {
67 if (_ps[i] != NULL)
68 {
69 _ps[i]->Release();
70 _ps[i] = NULL;
71 }
72 }
73}
74
75bool D3DShaderPack::InitVertexDeclarations(D3DDevice *d3d)
76{
77 _vdecl.Allocate(VDECL_NUM);
78 _vdecl.Set(NULL);
79
80 LPDIRECT3DVERTEXDECLARATION9 vdecl = NULL;
81 {
82 D3DVERTEXELEMENT9 elements[] = {
83 {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
84 {0, 8, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
85 D3DDECL_END()
86 };
87 if (FAILED(d3d->GetDevice()->CreateVertexDeclaration(elements, &vdecl)))
88 return false;
89 if (vdecl == NULL)
90 return false;
91 }
92 _vdecl[VDECL_XYC] = vdecl;
93 vdecl = NULL;
94 {
95 D3DVERTEXELEMENT9 elements[] = {
96 {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
97 {0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
98 D3DDECL_END()
99 };
100 if (FAILED(d3d->GetDevice()->CreateVertexDeclaration(elements, &vdecl)))
101 return false;
102 if (vdecl == NULL)
103 return false;
104 }
105 _vdecl[VDECL_XYUV] = vdecl;
106 vdecl = NULL;
107 {
108 D3DVERTEXELEMENT9 elements[] = {
109 {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
110 {0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
111 {0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
112 D3DDECL_END()
113 };
114 if (FAILED(d3d->GetDevice()->CreateVertexDeclaration(elements, &vdecl)))
115 return false;
116 if (vdecl == NULL)
117 return false;
118 }
119 _vdecl[VDECL_XYUVC] = vdecl;
120 vdecl = NULL;
121 {
122 D3DVERTEXELEMENT9 elements[] = {
123 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
124 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
125 {0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
126 D3DDECL_END()
127 };
128 if (FAILED(d3d->GetDevice()->CreateVertexDeclaration(elements, &vdecl)))
129 return false;
130 if (vdecl == NULL)
131 return false;
132 }
133 _vdecl[VDECL_XYZUVC] = vdecl;
134
135 return true;
136}
137
138bool D3DShaderPack::InitVertexShaders(D3DDevice *d3d)
139{
140 _vs.Allocate(VS_NUM);
141 _vs.Set(NULL);
142
143 {
144 char buf[] =
145 "struct VsInput { float2 pos : POSITION; float4 col : COLOR; };\n"
146 "struct VsOutput { float4 pos : POSITION; float4 col : COLOR0; };\n"
147 "VsOutput main(VsInput vs_in) {\n"
148 "VsOutput vs_out;\n"
149 "vs_out.pos = float4(vs_in.pos, 0, 1);\n"
150 "vs_out.col = vs_in.col;\n"
151 "return vs_out;}";
152
153 _vs[VS_COPY_COLOR] = (LPDIRECT3DVERTEXSHADER9)
154 CompileShader(d3d, true, "CopyColor", buf, sizeof(buf) - 1);
155 if (_vs[VS_COPY_COLOR] == NULL)
156 return false;
157 }
158
159 {
160 char buf[] =
161 "struct VsInput { float2 pos : POSITION; float2 tex : TEXCOORD0; };\n"
162 "struct VsOutput { float4 pos : POSITION; float2 tex : TEXCOORD0; };\n"
163 "VsOutput main(VsInput vs_in) {\n"
164 "VsOutput vs_out;\n"
165 "vs_out.pos = float4(vs_in.pos, 0, 1);\n"
166 "vs_out.tex = vs_in.tex;\n"
167 "return vs_out;}";
168
169 _vs[VS_COPY_UV] = (LPDIRECT3DVERTEXSHADER9)
170 CompileShader(d3d, true, "CopyUV", buf, sizeof(buf) - 1);
171 if (_vs[VS_COPY_UV] == NULL)
172 return false;
173 }
174
175 {
176 char buf[] =
177 "struct VsInput { float2 pos : POSITION; float2 tex : TEXCOORD0; float4 col : COLOR; };\n"
178 "struct VsOutput { float4 pos : POSITION; float2 tex : TEXCOORD0; float4 col : COLOR0; };\n"
179 "VsOutput main(VsInput vs_in) {\n"
180 "VsOutput vs_out;\n"
181 "vs_out.pos = float4(vs_in.pos, 0, 1);\n"
182 "vs_out.tex = vs_in.tex;\n"
183 "vs_out.col = vs_in.col;\n"
184 "return vs_out;}";
185
186 _vs[VS_COPY_UV_COLOR] = (LPDIRECT3DVERTEXSHADER9)
187 CompileShader(d3d, true, "CopyUVColor", buf, sizeof(buf) - 1);
188 if (_vs[VS_COPY_UV_COLOR] == NULL)
189 return false;
190 }
191
192 {
193 char buf[] =
194 "struct VsInput { float3 pos : POSITION; float2 tex : TEXCOORD0; float4 col : COLOR; };\n"
195 "struct VsOutput { float4 pos : POSITION; float2 tex : TEXCOORD0; float4 col : COLOR0; };\n"
196 "VsOutput main(VsInput vs_in) {\n"
197 "VsOutput vs_out;\n"
198 "vs_out.pos = float4(vs_in.pos, 1);\n"
199 "vs_out.tex = vs_in.tex;\n"
200 "vs_out.col = vs_in.col;\n"
201 "return vs_out;}";
202
203 _vs[VS_COPY_UV_COLOR_Z] = (LPDIRECT3DVERTEXSHADER9)
204 CompileShader(d3d, true, "CopyUVColorZ", buf, sizeof(buf) - 1);
205 if (_vs[VS_COPY_UV_COLOR_Z] == NULL)
206 return false;