00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Core/precomp.h"
00016
00017 #include "API/Core/System/cl_assert.h"
00018 #include "API/Core/System/error.h"
00019
00020 #include "dx_target.h"
00021
00022 CL_Target_DX::CL_Target_DX(LPDIRECTDRAWSURFACE surface)
00023 {
00024 m_surface = NULL;
00025 m_data = NULL;
00026 m_surface_is_video = false;
00027 m_width = 0;
00028 m_height = 0;
00029 m_pitch = 0;
00030 m_depth = 0;
00031 m_red_mask = 0;
00032 m_green_mask = 0;
00033 m_blue_mask = 0;
00034 m_alpha_mask = 0;
00035 m_ref_count = 0;
00036
00037 if (surface != NULL) set_surface(surface);
00038 }
00039
00040 CL_Target_DX::~CL_Target_DX()
00041 {
00042 if (m_surface != NULL)
00043 {
00044 m_surface->SetClipper(NULL);
00045 m_surface->Release();
00046 }
00047 }
00048
00049 void CL_Target_DX::set_surface(LPDIRECTDRAWSURFACE surface)
00050 {
00051 m_surface = surface;
00052
00053 get_palette_from_surface();
00054
00055 DDSURFACEDESC surface_desc;
00056 surface_desc.dwSize = sizeof(DDSURFACEDESC);
00057
00058 m_surface->GetSurfaceDesc(&surface_desc);
00059
00060 m_pitch = surface_desc.lPitch;
00061 m_width = surface_desc.dwWidth;
00062 m_height = surface_desc.dwHeight;
00063 m_depth = surface_desc.ddpfPixelFormat.dwRGBBitCount;
00064 m_red_mask = surface_desc.ddpfPixelFormat.dwRBitMask;
00065 m_green_mask = surface_desc.ddpfPixelFormat.dwGBitMask;
00066 m_blue_mask = surface_desc.ddpfPixelFormat.dwBBitMask;
00067 m_alpha_mask = surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask;
00068 m_surface_is_video = false;
00069 if (surface_desc.ddsCaps.dwCaps | DDSCAPS_VIDEOMEMORY) m_surface_is_video = true;
00070 }
00071
00072 void CL_Target_DX::lock()
00073 {
00074 cl_assert(m_surface != NULL);
00075
00076 m_ref_count++;
00077 if (m_ref_count == 1)
00078 {
00079 DDSURFACEDESC surface_desc;
00080 memset(&surface_desc, 0, sizeof(DDSURFACEDESC));
00081 surface_desc.dwSize = sizeof(DDSURFACEDESC);
00082
00083 HRESULT err = m_surface->Lock(
00084 NULL,
00085 &surface_desc,
00086 DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
00087 NULL);
00088
00089 if (err != DD_OK) { throw CL_Error("DAMMIT"); }
00090
00091 m_data = (unsigned char *) surface_desc.lpSurface;
00092 m_pitch = surface_desc.lPitch;
00093 m_width = surface_desc.dwWidth;
00094 m_height = surface_desc.dwHeight;
00095 m_depth = surface_desc.ddpfPixelFormat.dwRGBBitCount;
00096 m_red_mask = surface_desc.ddpfPixelFormat.dwRBitMask;
00097 m_green_mask = surface_desc.ddpfPixelFormat.dwGBitMask;
00098 m_blue_mask = surface_desc.ddpfPixelFormat.dwBBitMask;
00099 m_alpha_mask = surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask;
00100 }
00101 }
00102
00103 void CL_Target_DX::unlock()
00104 {
00105 m_ref_count--;
00106 cl_assert(m_ref_count >= 0);
00107
00108 if (m_ref_count == 0)
00109 {
00110 HRESULT err = m_surface->Unlock(m_data);
00111 cl_assert(err == DD_OK);
00112 }
00113 }
00114
00115 void CL_Target_DX::set_palette(CL_Palette *pal)
00116 {
00117 memcpy(m_palette.palette, pal->palette, m_palette.num_colors*3);
00118 }
00119
00120 CL_Palette *CL_Target_DX::get_palette() const
00121 {
00122 return (CL_Palette*) &m_palette;
00123 }
00124
00125 void CL_Target_DX::get_palette_from_surface()
00126 {
00127
00128 }