merge: remove direct3d (there are some remaining files, they will be deleted with ecore merge)

SVN revision: 79989
This commit is contained in:
Vincent Torri 2012-12-02 21:07:10 +00:00
parent 1eac4b2f47
commit 09358c71d1
31 changed files with 0 additions and 4794 deletions

View File

@ -1,3 +0,0 @@
Name: evas-direct3d
Description: Evas Direct3D engine
Version: @VERSION@

View File

@ -93,7 +93,6 @@ evas_module_paths_init(void)
{ evas_##Tn##_##Name##_init, evas_##Tn##_##Name##_shutdown }
EVAS_EINA_STATIC_MODULE_DEFINE(engine, buffer);
EVAS_EINA_STATIC_MODULE_DEFINE(engine, direct3d);
EVAS_EINA_STATIC_MODULE_DEFINE(engine, directfb);
EVAS_EINA_STATIC_MODULE_DEFINE(engine, fb);
EVAS_EINA_STATIC_MODULE_DEFINE(engine, gl_x11);
@ -132,9 +131,6 @@ static const struct {
#ifdef EVAS_STATIC_BUILD_BUFFER
EVAS_EINA_STATIC_MODULE_USE(engine, buffer),
#endif
#ifdef EVAS_STATIC_BUILD_DIRECT3D
EVAS_EINA_STATIC_MODULE_USE(engine, direct3d),
#endif
#ifdef EVAS_STATIC_BUILD_DIRECTFB
EVAS_EINA_STATIC_MODULE_USE(engine, directfb),
#endif
@ -150,18 +146,6 @@ static const struct {
#ifdef EVAS_STATIC_BUILD_PSL1GHT
EVAS_EINA_STATIC_MODULE_USE(engine, psl1ght),
#endif
#ifdef EVAS_STATIC_BUILD_SOFTWARE_GDI
EVAS_EINA_STATIC_MODULE_USE(engine, software_gdi),
#endif
#ifdef EVAS_STATIC_BUILD_SOFTWARE_DDRAW
EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw),
#endif
#ifdef EVAS_STATIC_BUILD_SOFTWARE_8
EVAS_EINA_STATIC_MODULE_USE(engine, software_8),
#endif
#ifdef EVAS_STATIC_BUILD_SOFTWARE_8_X11
EVAS_EINA_STATIC_MODULE_USE(engine, software_8_x11),
#endif
#ifdef EVAS_STATIC_BUILD_SOFTWARE_DDRAW
EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw),
#endif

View File

@ -1,36 +0,0 @@
#ifndef __EVAS_ENGINE_DIRECT3D_H__
#define __EVAS_ENGINE_DIRECT3D_H__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
typedef struct _Evas_Engine_Info_Direct3D Evas_Engine_Info_Direct3D;
struct _Evas_Engine_Info_Direct3D
{
/* PRIVATE - don't mess with this baby or evas will poke its tongue out */
/* at you and make nasty noises */
Evas_Engine_Info magic;
struct {
HWND window;
int rotation;
int depth;
int fullscreen : 1;
int layered : 1;
} info;
struct {
unsigned short width;
unsigned short height;
unsigned char *mask;
} *shape;
/* non-blocking or blocking mode */
Evas_Engine_Render_Mode render_mode;
};
#endif /* __EVAS_ENGINE_DIRECT3D_H__ */

View File

@ -1,305 +0,0 @@
#ifndef __ARRAY_H__
#define __ARRAY_H__
#include "ref.h"
#include <assert.h>
template <class T>
class TArray : virtual public Referenc
{
public:
TArray();
TArray(const TArray<T> &arr)
{
data = NULL;
size = num = 0;
block_size = arr.block_size;
keep_order = arr.keep_order;
//assert(0 && "Direct assignment for arrays is NOT allowed");
// risky probably, but anyway
arr.CopyTo(*this);
}
~TArray();
bool Allocate(int new_num);
bool Resize(int new_size = 0);
bool Add(T &el);
bool Add(const T &el);
inline T &operator[](int i);
inline const T &operator[](int i) const;
inline const TArray<T> &operator =(const TArray<T> &arr)
{
block_size = arr.block_size;
keep_order = arr.keep_order;
//assert(0 && "Direct assignment for arrays is NOT allowed");
// risky probably, but anyway
arr.CopyTo(*this);
return *this;
}
T *Last()
{
if (num > 0)
return &data[num - 1];
return NULL;
}
inline int Length() const
{
return num;
}
inline int Size() const
{
return size;
}
inline int BlockSize() const
{
return block_size;
}
inline T *Data()
{
return data;
}
inline T **DataPtr()
{
return &data;
}
inline const T *Data() const
{
return data;
}
inline void SetKeepOrder(bool enable)
{
keep_order = enable;
}
bool Find(const T &el);
bool Add(TArray<T> &arr);
bool CopyTo(TArray<T> &dest) const;
bool Init(const T *arr, int len);
void Swap(int to, int from);
void Replace(int i);
bool SetBlockSize(int new_size);
void Set(T &el);
void Set(const T &el);
protected:
T *data;
int size;
int num;
int block_size;
// Some operations restricted, order of the elements is fixed
bool keep_order;
};
namespace Array
{
const int default_block_size = 16;
const int max_array_size = 0xffffff;
}
template <class T> TArray<T>::TArray()
: data(NULL), size(0), num(0), block_size(Array::default_block_size), keep_order(false)
{
}
template <class T> TArray<T>::~TArray()
{
if (data != NULL)
Resize();
}
template <class T> bool TArray<T>::Allocate(int new_num)
{
assert(new_num >= 0 && new_num <= Array::max_array_size);
if (new_num > size)
{
if (!Resize(new_num))
return false;
}
num = new_num;
return true;
}
template <class T> bool TArray<T>::Resize(int new_size)
{
assert(new_size >= 0 && new_size <= Array::max_array_size);
if (new_size == 0)
{
delete[] data;
data = NULL;
size = 0;
num = 0;
return true;
}
if (new_size == size)
return true;
T *new_data = new T[new_size];
if (new_data == NULL)
return false;
if (data != NULL && num > 0)
{
//CopyMemory(new_data, data, num * sizeof(T));
for (int i = 0; i < num && i < new_size; i++)
new_data[i] = data[i];
}
delete[] data;
data = new_data;
size = new_size;
return true;
}
template <class T> bool TArray<T>::Add(T &el)
{
if (data == NULL)
Resize(1);
if (num < size)
{
data[num++] = el;
return true;
}
// num >= size
int new_size = size + block_size;
if (!Resize(new_size))
return false;
data[num++] = el;
return true;
}
template <class T> bool TArray<T>::Add(const T &el)
{
if (data == NULL)
Resize(1);
if (num < size)
{
data[num++] = *(T *)&el;
return true;
}
// num >= size
int new_size = size + block_size;
if (!Resize(new_size))
return false;
data[num++] = *(T *)&el;
return true;
}
template <class T> bool TArray<T>::Add(TArray<T> &arr)
{
if (arr.Length() == 0)
return true;
int numf = num;
if (!Allocate(Length() + arr.Length()))
return false;
CopyMemory(&data[numf], arr.Data(), arr.Length() * sizeof(T));
return true;
}
template <class T> T &TArray<T>::operator [](int i)
{
assert(i >= 0 && i < num);
return data[i];
}
template <class T> const T &TArray<T>::operator [](int i) const
{
assert(i >= 0 && i < num);
return data[i];
}
template <class T> bool TArray<T>::SetBlockSize(int new_size)
{
assert(new_size >= 0 && new_size <= Array::max_array_size);
block_size = new_size;
return true;
}
template <class T> void TArray<T>::Set(T &el)
{
for (int i = 0; i < num; i++)
data[i] = el;
}
template <class T> void TArray<T>::Set(const T &el)
{
for (int i = 0; i < num; i++)
data[i] = el;
}
template <class T> bool TArray<T>::CopyTo(TArray<T> &dest) const
{
if (!dest.Resize(size))
return false;
dest.num = 0;
for (int i = 0; i < num; i++)
dest.Add(data[i]);
return true;
}
template <class T> bool TArray<T>::Init(const T *arr, int len)
{
assert(arr != NULL);
if (!Resize(len))
return false;
num = 0;
for (int i = 0; i < len; i++)
Add((T)arr[i]);
return true;
}
template <class T> void TArray<T>::Swap(int to, int from)
{
assert(to >= 0 && to < num && from >= 0 && from < num);
if (keep_order)
return;
T t = data[to];
data[to] = data[from];
data[from] = t;
}
template <class T> void TArray<T>::Replace(int i)
{
assert(i >= 0 && i < num);
if (keep_order)
return;
if (num >= 1)
{
data[i] = data[num - 1];
num--;
}
}
// operator == for type T should be defined
template <class T> bool TArray<T>::Find(const T &el)
{
for (int i = 0; i < num; i++)
{
if (data[i] == el)
return true;
}
return false;
}
#endif // __ARRAY_H__

View File

@ -1,8 +0,0 @@
#include "evas_direct3d_context.h"
D3DContext::D3DContext()
{
color = 0xff000000;
color_mul = 0xffffffff;
}

View File

@ -1,22 +0,0 @@
#ifndef __EVAS_DIRECT3D_CONTEXT_H__
#define __EVAS_DIRECT3D_CONTEXT_H__
#include "evas_engine.h"
#include "ref.h"
#include "evas_direct3d_object.h"
class D3DContext : virtual public Referenc
{
public:
D3DContext();
public:
DWORD color;
DWORD color_mul;
Ref<D3DObject> font;
};
#endif // __EVAS_DIRECT3D_CONTEXT_H__

View File

@ -1,393 +0,0 @@
//#define ENABLE_LOG_PRINTF
#include "evas_direct3d_device.h"
#include "evas_direct3d_vertex_buffer_cache.h"
D3DDevice::D3DDevice()
{
ResetParams();
}
bool D3DDevice::Init(HWND window, int depth, bool fullscreen)
{
D3DPRESENT_PARAMETERS pp;
D3DDISPLAYMODE dm;
D3DCAPS9 caps;
RECT rect;
DWORD flag;
HRESULT hr;
if (window == NULL)
return false;
Destroy();
_object = Direct3DCreate9(D3D_SDK_VERSION);
if (_object == NULL)
return false;
if (FAILED(hr = _object->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm)))
{
ERR("GetAdapterDisplayMode failed: %x", hr);
Destroy();
return false;
}
if (FAILED(hr = _object->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
{
ERR("GetDeviceCaps failed: %x", hr);
Destroy();
return false;
}
if (!GetClientRect(window, &rect))
{
ERR("GetClientRect failed: %x", GetLastError());
Destroy();
return false;
}
if (SUCCEEDED(_object->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
dm.Format, 0, D3DRTYPE_TEXTURE, (depth == 16) ? D3DFMT_R5G6B5 : D3DFMT_A8R8G8B8)))
{
dm.Format = (depth == 16) ? D3DFMT_R5G6B5 : D3DFMT_A8R8G8B8;
}
flag = (caps.VertexProcessingCaps != 0) ?
(D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE) :
D3DCREATE_SOFTWARE_VERTEXPROCESSING;
ZeroMemory(&pp, sizeof(pp));
if (!fullscreen)
{
pp.BackBufferWidth = rect.right - rect.left;
pp.BackBufferHeight = rect.bottom - rect.top;
}
else
{
pp.BackBufferWidth = ::GetSystemMetrics(SM_CXSCREEN);
pp.BackBufferHeight = ::GetSystemMetrics(SM_CYSCREEN);
}
pp.BackBufferFormat = dm.Format;
pp.BackBufferCount = 1;
pp.MultiSampleType = D3DMULTISAMPLE_NONE;
pp.MultiSampleQuality = 0;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.hDeviceWindow = window;
pp.Windowed = fullscreen ? FALSE : TRUE;
//pp.EnableAutoDepthStencil = TRUE;
//pp.AutoDepthStencilFormat = D3DFMT_D16;
pp.FullScreen_RefreshRateInHz = 0;
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
if (FAILED(hr = _object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
window, flag, &pp, &_device)))
{
WRN("CreateDevice failed: %x", hr);
Destroy();
return false;
}
LPDIRECT3DSURFACE9 backbuffer = NULL;
_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
backbuffer->GetDesc(&_backbuffer_desc);
backbuffer->Release();
switch (dm.Format) {
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
_depth = 32;
break;
case D3DFMT_R5G6B5:
_depth = 16;
break;
default:
WRN("No supported format found");
Destroy();
return false;
}
//_render_to_texture = false;
_d3dpp = pp;
_device_lost = FALSE;
_scene_rendering = FALSE;
_width = rect.right - rect.left;
_height = rect.bottom - rect.top;
_window = window;
if (FAILED(CreateRenderTarget()))
{
ERR("Failed to create render target");
Destroy();
return false;
}
Log("initialized");
return true;
}
bool D3DDevice::Reset(int width, int height, int fullscreen)
{
D3DPRESENT_PARAMETERS pp = _d3dpp;
_d3dpp.BackBufferWidth = (width > 0) ? width : _d3dpp.BackBufferWidth;
_d3dpp.BackBufferHeight = (height > 0) ? height : _d3dpp.BackBufferHeight;
_d3dpp.Windowed = (fullscreen == 1) ? FALSE : ((fullscreen == 0) ? TRUE : _d3dpp.Windowed);
if (FAILED(ResetDevice()))
{
WRN("Couldnt restore device");
_d3dpp = pp;
return SUCCEEDED(ResetDevice());
}
_width = _d3dpp.BackBufferWidth;
_height = _d3dpp.BackBufferHeight;
return true;
}
void D3DDevice::Destroy()
{
//if (_render_target != NULL)
//{
// _render_target->Release();
// _render_target = NULL;
//}
if (_render_target_data != NULL)
{
_render_target_data->Release();
_render_target_data = NULL;
}
if (_device != NULL)
{
int num = _device->Release();
assert(num == 0);
}
if (_object != NULL)
_object->Release();
ResetParams();
INF("uninitialized");
}
void D3DDevice::ResetParams()
{
_window = NULL;
_object = NULL;
_device = NULL;
_width = 0;
_height = 0;
_rot = 0;
_depth = 0;
_device_lost = false;
_scene_rendering = false;
ZeroMemory(&_d3dpp, sizeof(_d3dpp));
ZeroMemory(&_backbuffer_desc, sizeof(_backbuffer_desc));
//_render_target = NULL;
_render_target_data = NULL;
_render_data_updated = false;
_render_data.Resize();
//_original_render_target = NULL;
//_render_to_texture = false;
}
HRESULT D3DDevice::RestoreDevice()
{
Log("restore");
assert(_device != NULL);
HRESULT hr = S_OK;
// Test the cooperative level to see if it's okay to render
if (SUCCEEDED(hr = _device->TestCooperativeLevel()))
{
_device_lost = FALSE;
DBG("render test ok");
return S_OK;
}
// If the device was lost, do not render until we get it back
if (hr == D3DERR_DEVICELOST)
return E_FAIL;
// Check if the device needs to be reset.
if (hr == D3DERR_DEVICENOTRESET)
{
if (FAILED(hr = ResetDevice()))
return hr;
}
return hr;
}
HRESULT D3DDevice::ResetDevice()
{
DBG("reset");
HRESULT hr = S_OK;
_scene_rendering = FALSE;
// Release all video memory objects
// Bad to call such, make better
D3DVertexBufferCache::Current()->Uninitialize();
//if (_render_target != NULL)
//{
// _render_target->Release();
// _render_target = NULL;
//}
if (_render_target_data != NULL)
{
_render_target_data->Release();
_render_target_data = NULL;
}
// Reset the device
if (FAILED(hr = _device->Reset(&_d3dpp)))
{
ERR("D3DDevice: Reset of the device failed! Error (%X)", (DWORD)hr);
return hr;
}
// Store render target surface desc
LPDIRECT3DSURFACE9 backbuffer = NULL;
_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
if (backbuffer != NULL)
{
backbuffer->GetDesc(&_backbuffer_desc);
backbuffer->Release();
}
// Initialize the app's device-dependent objects
hr = CreateRenderTarget();
if (FAILED(hr))
{
WRN("Restoration of device objects failed");
// Invalidate objects
return E_FAIL;
}
DBG("Device objects were successfuly restored");
_textures.Set(NULL);
//_device_objects_restored = true;
return S_OK;
}
bool D3DDevice::Begin()
{
if (FAILED(RestoreDevice()))
return false;
//if (_render_to_texture && _render_target != NULL)
//{
// if (FAILED(_device->GetRenderTarget(0, &_original_render_target)))
// return false;
// if (FAILED(_device->SetRenderTarget(0, _render_target)))
// return false;
//}
HRESULT hr;
if (FAILED(hr = _device->BeginScene()))
{
WRN("Cannot begin scene: %X", (DWORD)hr);
return false;
}
//static const D3DVIEWPORT9 vp = {0, 0, _width, _height, 0.f, 1.f};
//_device->SetViewport(&vp);
//_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
//_device->Clear(0, NULL, D3DCLEAR_TARGET /*| D3DCLEAR_ZBUFFER*/, 0xff8080ff, 1.f, 0);
return true;
}
bool D3DDevice::End()
{
_device->EndScene();
_device->Present(NULL, NULL, NULL, NULL);
_render_data_updated = false;
//if (_render_to_texture && _render_target != NULL && _original_render_target != NULL)
//{
// if (FAILED(_device->SetRenderTarget(0, _original_render_target)))
// return false;
//}
return true;
}
TArray<DWORD> &D3DDevice::GetRenderData()
{
if (_render_data_updated)
return _render_data;
_render_data.Allocate(0);
if (_render_target_data == NULL)
return _render_data;
LPDIRECT3DSURFACE9 surf = NULL;
HRESULT hr;
if (FAILED(_device->GetRenderTarget(0, &surf)))
return _render_data;
if (FAILED(hr = _device->GetRenderTargetData(surf, _render_target_data)))
{
WRN("Failed to get render target data (%X)", (DWORD)hr);
surf->Release();
return _render_data;
}
D3DLOCKED_RECT lr;
if (FAILED(_render_target_data->LockRect(&lr, NULL, D3DLOCK_READONLY)))
{
surf->Release();
return _render_data;
}
_render_data.Allocate(_width * _height);
for (int i = 0; i < _height; i++)
{
CopyMemory(&_render_data[i * _width], (BYTE *)lr.pBits + i * lr.Pitch,
_width * sizeof(DWORD));
}
_render_target_data->UnlockRect();
_render_data_updated = true;
surf->Release();
return _render_data;
}
HRESULT D3DDevice::SetTexture(DWORD stage, LPDIRECT3DTEXTURE9 tex)
{
if (stage >= 8)
return E_FAIL;
if (_textures.Length() <= (int)stage)
_textures.Allocate(stage + 1);
if (_textures[stage] != tex)
{
_textures[stage] = tex;
return _device->SetTexture(stage, tex);
}
return S_OK;
}
HRESULT D3DDevice::CreateRenderTarget()
{
if (_device == NULL)
return E_FAIL;
//if (_render_target != NULL &&
if (_render_target_data != NULL)
return S_OK;
//if (FAILED(_device->CreateRenderTarget(_width, _height, _backbuffer_desc.Format,
// D3DMULTISAMPLE_NONE, 0, FALSE, &_render_target, NULL)))
//{
// return E_FAIL;
//}
if (FAILED(_device->CreateOffscreenPlainSurface(_backbuffer_desc.Width,
_backbuffer_desc.Height, _backbuffer_desc.Format, D3DPOOL_SYSTEMMEM,
&_render_target_data, NULL)))
{
return E_FAIL;
}
return S_OK;
}

View File

@ -1,87 +0,0 @@
#ifndef __EVAS_DIRECT3D_DEVICE_H__
#define __EVAS_DIRECT3D_DEVICE_H__
#include "evas_engine.h"
#include <assert.h>
#include "ref.h"
#include "array.h"
class D3DDevice : virtual public Referenc
{
public:
D3DDevice();
bool Init(HWND window, int depth, bool fullscreen = false);
bool Reset(int width, int height, int fullscreen);
void Destroy();
bool Begin();
bool End();
inline LPDIRECT3DDEVICE9 GetDevice();
inline int GetWidth();
inline int GetHeight();
inline HWND GetWindow();
inline bool GetFullscreen();
TArray<DWORD> &GetRenderData();
HRESULT SetTexture(DWORD stage, LPDIRECT3DTEXTURE9 tex);
private:
HRESULT RestoreDevice();
HRESULT ResetDevice();
void ResetParams();
HRESULT CreateRenderTarget();
private:
HWND _window;
LPDIRECT3D9 _object;
LPDIRECT3DDEVICE9 _device;
int _width;
int _height;
int _rot;
int _depth;
bool _device_lost;
bool _scene_rendering;
D3DPRESENT_PARAMETERS _d3dpp;
D3DSURFACE_DESC _backbuffer_desc;
//LPDIRECT3DSURFACE9 _render_target;
LPDIRECT3DSURFACE9 _render_target_data;
//LPDIRECT3DSURFACE9 _original_render_target;
//bool _render_to_texture;
TArray<DWORD> _render_data;
bool _render_data_updated;
TArray<LPDIRECT3DTEXTURE9> _textures;
};
LPDIRECT3DDEVICE9 D3DDevice::GetDevice()
{
return _device;
}
int D3DDevice::GetWidth()
{
return _width;
}
int D3DDevice::GetHeight()
{
return _height;
}
HWND D3DDevice::GetWindow()
{
return _window;
}
bool D3DDevice::GetFullscreen()
{
return (_d3dpp.Windowed == 0);
}
#endif // __EVAS_DIRECT3D_DEVICE_H__

View File

@ -1,436 +0,0 @@
#include "evas_direct3d_image_cache.h"
#include "evas_direct3d_device.h"
#include <assert.h>
Ref<D3DImageCache> D3DImageCache::_this;
D3DImageCache::D3DImageCache()
{
_max_width = 512;
_max_height = 512;
_margin = 0;
}
D3DImageCache::~D3DImageCache()
{
Uninitialize();
}
D3DImageCache *D3DImageCache::Current()
{
if (_this.IsNull())
_this = new D3DImageCache();
return _this;
}
void D3DImageCache::SetCurrent(D3DImageCache *obj)
{
_this = obj;
}
void D3DImageCache::Uninitialize()
{
for (int i = 0; i < _cache.Length(); i++)
{
// In normal case they all will be NULL
if (_cache[i].texture != NULL)
_cache[i].texture->Release();
}
_cache.Resize();
}
bool D3DImageCache::SelectImageToDevice(D3DDevice *d3d, int id)
{
if (id < 0 || id >= _cache.Length())
return false;
assert(_cache[id].texture != NULL);
return SUCCEEDED(d3d->SetTexture(_cache[id].stage, _cache[id].texture));
}
void D3DImageCache::RemoveImageUser(int id)
{
if (id < 0 || id >= _cache.Length())
return;
assert(_cache[id].texture != NULL);
_cache[id].users--;
if (_cache[id].users == 0)
{
_cache[id].texture->Release();
ZeroMemory(&_cache[id], sizeof(_cache[id]));
}
}
void D3DImageCache::AddImageUser(int id)
{
if (id < 0 || id >= _cache.Length())
return;
assert(_cache[id].texture != NULL);
_cache[id].users++;
}
bool D3DImageCache::InsertImage(D3DDevice *d3d, DWORD *data, int w, int h, CacheEntryInfo &info)
{
CacheEntry *ce = NULL;
int id = -1;
for (int i = 0; i < _cache.Length(); i++)
{
if (!_cache[i].locked && RequestInsert(_cache[i], w, h))
{
ce = &_cache[i];
id = i;
break;
}
}
if (ce == NULL)
{
CacheEntry new_entry;
if (!CreateEntry(d3d, new_entry, w, h))
return false;
for (id = 0; id < _cache.Length(); id++)
{
if (_cache[id].texture == NULL)
break;
}
if (id < _cache.Length())
{
_cache[id] = new_entry;
ce = &_cache[id];
}
else
{
_cache.Add(new_entry);
ce = _cache.Last();
id = _cache.Length() - 1;
}
}
assert(ce != NULL && ce->texture != NULL);
if (!InsertData(*ce, data, w, h))
return false;
info.id = id;
info.u = FLOAT(ce->cur_x) / FLOAT(ce->width);
info.v = FLOAT(ce->cur_y) / FLOAT(ce->height);
info.du = FLOAT(w) / FLOAT(ce->width);
info.dv = FLOAT(h) / FLOAT(ce->height);
info.width = w;
info.height = h;
UpdateInsert(*ce, w, h);
return true;
}
bool D3DImageCache::InsertImage(D3DDevice *d3d, int id, DWORD *data, int w, int h, CacheEntryInfo &info)
{
if (id < 0 || id >= _cache.Length())
return false;
assert(_cache[id].texture != NULL);
CacheEntry *ce = &_cache[id];
if (!RequestInsert(*ce, w, h))
return false;
if (!InsertData(*ce, data, w, h))
return false;
info.id = id;
info.u = FLOAT(ce->cur_x) / FLOAT(ce->width);
info.v = FLOAT(ce->cur_y) / FLOAT(ce->height);
info.du = FLOAT(w) / FLOAT(ce->width);
info.dv = FLOAT(h) / FLOAT(ce->height);
info.width = w;
info.height = h;
UpdateInsert(*ce, w, h);
return true;
}
bool D3DImageCache::CreateImage(D3DDevice *d3d, int w, int h, bool locked, CacheEntryInfo &info)
{
int id;
CacheEntry new_entry;
CacheEntry *ce = NULL;
if (!CreateEntry(d3d, new_entry, w, h, true))
return false;
for (id = 0; id < _cache.Length(); id++)
{
if (_cache[id].texture == NULL)
break;
}
if (id < _cache.Length())
{
_cache[id] = new_entry;
ce = &_cache[id];
}
else
{
_cache.Add(new_entry);
ce = _cache.Last();
id = _cache.Length() - 1;
}
assert(ce != NULL && ce->texture != NULL);
// Fill with zero
if (!InsertData(*ce, NULL, w, h))
return false;
info.id = id;
info.u = 0;
info.v = 0;
info.du = 1;
info.dv = 1;
info.width = w;
info.height = h;
UpdateInsert(*ce, 0, 0);
ce->locked = locked;
return true;
}
bool D3DImageCache::ResizeImage(D3DDevice *d3d, int nw, int nh, int id)
{
if (id < 0 || id >= _cache.Length())
return false;
assert(_cache[id].texture != NULL);
CacheEntry *ce = &_cache[id];
if (ce->width == nw && ce->height == nh)
return true;
LPDIRECT3DTEXTURE9 tex = NULL;
HRESULT hr;
if (FAILED(hr = d3d->GetDevice()->CreateTexture(nw, nh, 0, 0, D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED, &tex, NULL)))
{
WRN("Failed to create texture: %X", hr);
return false;
}
assert(tex != NULL);
ce->texture->Release();
ce->texture = tex;
ce->width = nw;
ce->height = nh;
return true;
}
bool D3DImageCache::RequestInsert(CacheEntry &entry, int w, int h)
{
// If we already have large image entry
if (entry.width > _max_width || entry.height > _max_height)
return false;
// If requested size does not fit into this entry at all
if (entry.height - entry.cur_h < h + _margin * 2 || entry.width < w + _margin * 2)
return false;
// If requested size does not fit into the current line of the entry
if (entry.width - entry.cur_x < w + _margin * 2)
{
entry.cur_y = entry.cur_h + _margin;
entry.cur_x = _margin;
return true;
}
entry.cur_x += _margin;
return true;
}
bool D3DImageCache::CreateEntry(D3DDevice *d3d, CacheEntry &entry, int w, int h, bool exact_size)
{
int width = exact_size ? w : max(_max_width, w);
int height = exact_size ? h : max(_max_height, h);
HRESULT hr;
if (FAILED(hr = d3d->GetDevice()->CreateTexture(width, height, 0, 0, D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED, &entry.texture, NULL)))
{
WRN("Failed to create texture: %X", hr);
return false;
}
entry.cur_x = entry.cur_y = entry.cur_h = 0;
entry.width = width;
entry.height = height;
entry.users = 0;
entry.locked = false;
entry.stage = 0;
return true;
}
bool D3DImageCache::InsertData(CacheEntry &entry, DWORD *data, int w, int h)
{
if (entry.texture == NULL)
return false;
RECT rc = {entry.cur_x, entry.cur_y, entry.cur_x + w, entry.cur_y + h};
D3DLOCKED_RECT lr;
if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
{
WRN("Failed to lock texture");
return false;
}
if (data != NULL)
{
for (int i = 0; i < h; i++)
CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch, data + i * w, sizeof(DWORD) * w);
}
else
{
for (int i = 0; i < h; i++)
ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch, sizeof(DWORD) * w);
}
if (FAILED(entry.texture->UnlockRect(0)))
{
WRN("Failed to unlock texture");
return false;
}
return true;
}
bool D3DImageCache::RetrieveData(CacheEntry &entry, DWORD *data, int w, int h)
{
if (entry.texture == NULL || data == NULL)
return false;
RECT rc = {entry.cur_x, entry.cur_y, entry.cur_x + w, entry.cur_y + h};
D3DLOCKED_RECT lr;
if (FAILED(entry.texture->LockRect(0, &lr, &rc, D3DLOCK_READONLY)))
{
WRN("Failed to lock texture");
return false;
}
for (int i = 0; i < h; i++)
CopyMemory(data + i * w, ((BYTE *)lr.pBits) + i * lr.Pitch, sizeof(DWORD) * w);
if (FAILED(entry.texture->UnlockRect(0)))
{
WRN("Failed to unlock texture");
return false;
}
return true;
}
void D3DImageCache::UpdateInsert(CacheEntry &entry, int w, int h)
{
entry.cur_h = max(entry.cur_h, entry.cur_y + h + _margin);
entry.cur_x += w + _margin;
entry.users++;
}
bool D3DImageCache::UpdateImageData(CacheEntryInfo &info, DWORD *data)
{
assert(data != NULL);
if (info.id < 0 || info.id >= _cache.Length())
return false;
CacheEntry ce_copy = _cache[info.id];
ce_copy.cur_x = int(info.u * FLOAT(ce_copy.width));
ce_copy.cur_y = int(info.v * FLOAT(ce_copy.height));
return InsertData(ce_copy, data, info.width, info.height);
}
bool D3DImageCache::UpdateImageDataWithDirtyInfo(CacheEntryInfo &info, DWORD *data, POINT *dirty)
{
if (info.id < 0 || info.id >= _cache.Length())
return false;
CacheEntry &entry = _cache[info.id];
if (entry.texture == NULL)
return false;
RECT rc = {0, 0, entry.width, entry.height};
D3DLOCKED_RECT lr;
if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
{
WRN("Failed to lock texture");
return false;
}
if (data != NULL)
{
for (int i = 0; i < rc.bottom; i++)
{
if (dirty[i].x < 0 && dirty[i].y < 0)
continue;
if (dirty[i].x >= 0 && dirty[i].y >= 0)
{
CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
data + i * rc.right + dirty[i].x, sizeof(DWORD) * (dirty[i].y - dirty[i].x + 1));
dirty[i].y = -dirty[i].y;
}
else if (dirty[i].x >= 0 && dirty[i].y < 0)
{
ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
sizeof(DWORD) * (-dirty[i].y - dirty[i].x + 1));
dirty[i].x = -dirty[i].x;
}
}
}
else
{
for (int i = 0; i < rc.bottom; i++)
{
if (dirty[i].x < 0 || dirty[i].y < 0)
continue;
ZeroMemory(((BYTE *)lr.pBits) + i * lr.Pitch + dirty[i].x * 4,
sizeof(DWORD) * (dirty[i].y - dirty[i].x + 1));
}
}
if (FAILED(entry.texture->UnlockRect(0)))
{
WRN("Failed to unlock texture");
return false;
}
return true;
}
bool D3DImageCache::UpdateImageDataDiscard(CacheEntryInfo &info, DWORD *data)
{
assert(data != NULL);
if (info.id < 0 || info.id >= _cache.Length())
return false;
CacheEntry &entry = _cache[info.id];
if (entry.texture == NULL)
return false;
RECT rc = {0, 0, entry.width, entry.height};
D3DLOCKED_RECT lr;
if (FAILED(entry.texture->LockRect(0, &lr, &rc, 0)))
{
WRN("Failed to lock texture");
return false;
}
for (int i = 0; i < rc.bottom; i++)
{
CopyMemory(((BYTE *)lr.pBits) + i * lr.Pitch,
data + i * rc.right, sizeof(DWORD) * rc.right);
}
if (FAILED(entry.texture->UnlockRect(0)))
{
WRN("Failed to unlock texture");
return false;
}
return true;
}
bool D3DImageCache::GetImageData(CacheEntryInfo &info, TArray<DWORD> &data)
{
if (info.id < 0 || info.id >= _cache.Length())
return false;
CacheEntry ce_copy = _cache[info.id];
ce_copy.cur_x = int(info.u * FLOAT(ce_copy.width));
ce_copy.cur_y = int(info.v * FLOAT(ce_copy.height));
data.Allocate(info.width * info.height);
return RetrieveData(ce_copy, data.Data(), info.width, info.height);
}

View File

@ -1,108 +0,0 @@
#ifndef __EVAS_DIRECT3D_IMAGE_CACHE_H__
#define __EVAS_DIRECT3D_IMAGE_CACHE_H__
#include "evas_engine.h"
#include "ref.h"
#include "array.h"
class D3DDevice;
class D3DImageCache : virtual public Referenc
{
public:
struct CacheEntryInfo
{
int id;
int width, height;
FLOAT u, v;
FLOAT du, dv;
};
public:
~D3DImageCache();
static D3DImageCache *Current();
static void SetCurrent(D3DImageCache *obj);
inline void SetMaxSize(int w, int h);
inline void SetMargin(int margin);
bool InsertImage(D3DDevice *d3d, DWORD *data, int w, int h, CacheEntryInfo &info);
bool InsertImage(D3DDevice *d3d, int id, DWORD *data, int w, int h, CacheEntryInfo &info);
bool CreateImage(D3DDevice *d3d, int w, int h, bool locked, CacheEntryInfo &info);
bool ResizeImage(D3DDevice *d3d, int nw, int nh, int id);
bool SelectImageToDevice(D3DDevice *d3d, int id);
void RemoveImageUser(int id);
void AddImageUser(int id);
bool UpdateImageData(CacheEntryInfo &info, DWORD *data);
bool UpdateImageDataWithDirtyInfo(CacheEntryInfo &info, DWORD *data, POINT *dirty);
bool UpdateImageDataDiscard(CacheEntryInfo &info, DWORD *data);
bool GetImageData(CacheEntryInfo &info, TArray<DWORD> &data);
void Uninitialize();
inline int GetImageWidth(int image_id);
inline int GetImageHeight(int image_id);
inline void SetImageStage(int image_id, int stage);
private:
struct CacheEntry
{
LPDIRECT3DTEXTURE9 texture;
int width;
int height;
int cur_x;
int cur_y;
int cur_h;
int users;
bool locked;
int stage;
};
private:
D3DImageCache();
bool RequestInsert(CacheEntry &entry, int w, int h);
bool CreateEntry(D3DDevice *d3d, CacheEntry &entry, int w, int h, bool exact_size = false);
bool InsertData(CacheEntry &entry, DWORD *data, int w, int h);
bool RetrieveData(CacheEntry &entry, DWORD *data, int w, int h);
void UpdateInsert(CacheEntry &entry, int w, int h);
private:
TArray<CacheEntry> _cache;
int _max_width;
int _max_height;
int _margin;
static Ref<D3DImageCache> _this;
};
void D3DImageCache::SetMaxSize(int w, int h)
{
_max_width = w;
_max_height = h;
}
void D3DImageCache::SetMargin(int margin)
{
_margin = margin;
}
int D3DImageCache::GetImageWidth(int image_id)
{
return _cache[image_id].width;
}
int D3DImageCache::GetImageHeight(int image_id)
{
return _cache[image_id].height;
}
void D3DImageCache::SetImageStage(int image_id, int stage)
{
_cache[image_id].stage = stage;
}
#endif // __EVAS_DIRECT3D_IMAGE_CACHE_H__

View File

@ -1,774 +0,0 @@
// Force the layered windows APIs to be visible.
#define _WIN32_WINNT 0x0500
#include "evas_engine.h"
#include <assert.h>
#include <d3dx9.h>
#include "evas_direct3d_device.h"
#include "evas_direct3d_context.h"
#include "evas_direct3d_shader_pack.h"
#include "evas_direct3d_scene.h"
#include "evas_direct3d_image_cache.h"
#include "evas_direct3d_object_line.h"
#include "evas_direct3d_object_rect.h"
#include "evas_direct3d_object_image.h"
#include "evas_direct3d_vertex_buffer_cache.h"
#include "evas_direct3d_object_font.h"
// Internal structure that joins two types of objects
struct ImagePtr
{
Ref<D3DObjectImage> ref;
RGBA_Image *img;
};
struct DevicePtr
{
Ref<D3DDevice> device;
Ref<D3DScene> scene;
Ref<D3DContext> context;
Ref<D3DImageCache> image_cache;
Ref<D3DShaderPack> shader_pack;
Ref<D3DVertexBufferCache> vb_cache;
int fonts_buffer_image_id;
// Layered windows cannot render D3D in the normal way
bool layered;
// Window shape mask
struct
{