OSDN Git Service

Merge branch 'feature/#36529_SlimDXからSharpDXへの移行' into develop
[dtxmania/dtxmania.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / Surface.cpp
diff --git a/SlimDXc_Jun2010(VC++2008)/source/direct3d9/Surface.cpp b/SlimDXc_Jun2010(VC++2008)/source/direct3d9/Surface.cpp
deleted file mode 100644 (file)
index e8b3d42..0000000
+++ /dev/null
@@ -1,801 +0,0 @@
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include <d3d9.h>\r
-#include <d3dx9.h>\r
-#include <vcclr.h>\r
-\r
-#include "../ComObject.h"\r
-#include "../DataStream.h"\r
-#include "../InternalHelpers.h"\r
-\r
-#include "Direct3D9Exception.h"\r
-\r
-#include "DeviceEx.h"\r
-#include "Surface.h"\r
-#include "Texture.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-using namespace System::Reflection;\r
-using namespace msclr::interop;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
-       int Surface::ComputeLockedSize(const D3DLOCKED_RECT& lockedRect)\r
-       {\r
-               D3DSURFACE_DESC desc;\r
-               InternalPointer->GetDesc(&desc);\r
-\r
-               int height = desc.Height;\r
-               //compute size differently for DXT surfaces\r
-               if(desc.Format >= D3DFMT_DXT1 && desc.Format <= D3DFMT_DXT5 && desc.Height > 0)\r
-                       height = (desc.Height + 3) / 4;\r
-\r
-               return lockedRect.Pitch * height;\r
-       }\r
-\r
-       Surface^ Surface::CreateRenderTarget( SlimDX::Direct3D9::Device^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool lockable )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateRenderTarget( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, lockable, &surface, NULL );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateOffscreenPlain( SlimDX::Direct3D9::Device^ device, int width, int height, Format format, Pool pool )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateOffscreenPlainSurface( width, height,\r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &surface, NULL );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateDepthStencil( SlimDX::Direct3D9::Device^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool discard )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateDepthStencilSurface( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, discard, &surface, NULL );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateRenderTarget( SlimDX::Direct3D9::Device^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool lockable, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE sharedHandleNative = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateRenderTarget( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, lockable, &surface, &sharedHandleNative );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               sharedHandle = IntPtr(sharedHandleNative);\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateOffscreenPlain( SlimDX::Direct3D9::Device^ device, int width, int height, Format format,\r
-               Pool pool, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE sharedHandleNative = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateOffscreenPlainSurface( width, height,\r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &surface, &sharedHandleNative );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-               sharedHandle = IntPtr(sharedHandleNative);\r
-\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateDepthStencil( SlimDX::Direct3D9::Device^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool discard, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE sharedHandleNative = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateDepthStencilSurface( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, discard, &surface, &sharedHandleNative );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               sharedHandle = IntPtr(sharedHandleNative);\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateRenderTargetEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool lockable, Usage usage )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateRenderTargetEx( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality,\r
-                       lockable, &surface, NULL, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateRenderTargetEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool lockable, Usage usage, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE localHandle = NULL;\r
-               sharedHandle = IntPtr::Zero;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateRenderTargetEx( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, lockable,\r
-                       &surface, &localHandle, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               sharedHandle = IntPtr( localHandle );\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateOffscreenPlainEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height,\r
-               Format format, Pool pool, Usage usage )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateOffscreenPlainSurfaceEx( width, height,\r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &surface,\r
-                       NULL, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateOffscreenPlainEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height,\r
-               Format format, Pool pool, Usage usage, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE localHandle = NULL;\r
-               sharedHandle = IntPtr::Zero;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateOffscreenPlainSurfaceEx( width, height,\r
-                       static_cast<D3DFORMAT>( format ), static_cast<D3DPOOL>( pool ), &surface,\r
-                       &localHandle, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               sharedHandle = IntPtr( localHandle );\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               if( pool == Pool::Default )\r
-                       result->IsDefaultPool = true;\r
-\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateDepthStencilEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool discard, Usage usage )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateDepthStencilSurfaceEx( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, discard,\r
-                       &surface, NULL, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Surface^ Surface::CreateDepthStencilEx( SlimDX::Direct3D9::DeviceEx^ device, int width, int height, Format format,\r
-               MultisampleType multiSampleType, int multiSampleQuality, bool discard, Usage usage, [Out] IntPtr% sharedHandle )\r
-       {\r
-               IDirect3DSurface9* surface = NULL;\r
-               HANDLE localHandle = NULL;\r
-               sharedHandle = IntPtr::Zero;\r
-\r
-               HRESULT hr = device->InternalPointer->CreateDepthStencilSurfaceEx( width, height, static_cast<D3DFORMAT>( format ),\r
-                       static_cast<D3DMULTISAMPLE_TYPE>( multiSampleType ), multiSampleQuality, discard,\r
-                       &surface, &localHandle, static_cast<DWORD>( usage ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               sharedHandle = IntPtr( localHandle );\r
-               Surface^ result = gcnew Surface( surface, nullptr );\r
-               result->IsDefaultPool = true;\r
-               return result;\r
-       }\r
-\r
-       Result Surface::FromMemory_Internal( Surface^ surface, const void* memory, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, const RECT* sourceRectangle, const RECT* destinationRectangle, \r
-               array<PaletteEntry>^ sourcePalette, array<PaletteEntry>^ destinationPalette )\r
-       {\r
-               pin_ptr<PaletteEntry> pinnedSourcePalette = sourcePalette == nullptr ? nullptr : &sourcePalette[0];\r
-               pin_ptr<PaletteEntry> pinnedDestPalette = destinationPalette == nullptr ? nullptr : &destinationPalette[0];\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromMemory( surface->InternalPointer,\r
-                       reinterpret_cast<const PALETTEENTRY*>( pinnedDestPalette ),\r
-                       destinationRectangle, memory, static_cast<D3DFORMAT>( sourceFormat ),\r
-                       sourcePitch, reinterpret_cast<const PALETTEENTRY*>( pinnedSourcePalette ),\r
-                       sourceRectangle, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );\r
-\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromMemory( Surface^ surface, array<System::Byte>^ memory, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               System::Drawing::Rectangle destinationRectangle, array<PaletteEntry>^ sourcePalette,\r
-               array<PaletteEntry>^ destinationPalette )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromMemory_Internal( surface, pinnedMemory, filter, colorKey, sourceFormat, sourcePitch,\r
-                       &source, &dest, sourcePalette, destinationPalette );\r
-       }\r
-\r
-       Result Surface::FromMemory( Surface^ surface, array<System::Byte>^ memory, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromMemory_Internal( surface, pinnedMemory, filter, colorKey, sourceFormat, sourcePitch,\r
-                       &source, &dest, nullptr, nullptr );\r
-       }\r
-\r
-       Result Surface::FromMemory( Surface^ surface, array<System::Byte>^ memory, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               array<PaletteEntry>^ sourcePalette,     array<PaletteEntry>^ destinationPalette )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromMemory_Internal( surface, pinnedMemory, filter, colorKey, sourceFormat, sourcePitch,\r
-                       &source, NULL, sourcePalette, destinationPalette );\r
-       }\r
-\r
-       Result Surface::FromMemory( Surface^ surface, array<System::Byte>^ memory, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromMemory_Internal( surface, pinnedMemory, filter, colorKey, sourceFormat, sourcePitch,\r
-                       &source, NULL, nullptr, nullptr );\r
-       }\r
-\r
-       Result Surface::FromStream( Surface^ surface, System::IO::Stream^ stream, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               System::Drawing::Rectangle destinationRectangle, array<PaletteEntry>^ sourcePalette,\r
-               array<PaletteEntry>^ destinationPalette )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-                       RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-                       return FromMemory_Internal( surface, ds->SeekToEnd(), filter, colorKey, sourceFormat, sourcePitch,\r
-                               &source, &dest, sourcePalette, destinationPalette );\r
-               }\r
-\r
-               return Surface::FromMemory( surface, data, filter, colorKey, sourceFormat, sourcePitch,\r
-                       sourceRectangle, destinationRectangle, sourcePalette, destinationPalette );\r
-       }\r
-\r
-       Result Surface::FromStream( Surface^ surface, System::IO::Stream^ stream, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               array<PaletteEntry>^ sourcePalette, array<PaletteEntry>^ destinationPalette )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-\r
-                       return FromMemory_Internal( surface, ds->SeekToEnd(), filter, colorKey, sourceFormat, sourcePitch,\r
-                               &source, NULL, sourcePalette, destinationPalette );\r
-               }\r
-\r
-               return Surface::FromMemory( surface, data, filter, colorKey, sourceFormat, sourcePitch,\r
-                       sourceRectangle, sourcePalette, destinationPalette );\r
-       }\r
-\r
-       Result Surface::FromStream( Surface^ surface, System::IO::Stream^ stream, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle,\r
-               System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-                       RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-                       return FromMemory_Internal( surface, ds->SeekToEnd(), filter, colorKey, sourceFormat, sourcePitch,\r
-                               &source, &dest, nullptr, nullptr );\r
-               }\r
-\r
-               return Surface::FromMemory( surface, data, filter, colorKey, sourceFormat, sourcePitch,\r
-                       sourceRectangle, destinationRectangle );\r
-       }\r
-\r
-       Result Surface::FromStream( Surface^ surface, System::IO::Stream^ stream, Filter filter, int colorKey,\r
-               Format sourceFormat, int sourcePitch, System::Drawing::Rectangle sourceRectangle )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-\r
-                       return FromMemory_Internal( surface, ds->SeekToEnd(), filter, colorKey, sourceFormat, sourcePitch,\r
-                               &source, NULL, nullptr, nullptr );\r
-               }\r
-\r
-               return Surface::FromMemory( surface, data, filter, colorKey, sourceFormat, sourcePitch, sourceRectangle );\r
-       }\r
-\r
-       Result Surface::FromFileInMemory_Internal( Surface^ surface, const void* memory, UINT size, Filter filter,\r
-               int colorKey, const RECT* sourceRectangle, const RECT* destinationRectangle,\r
-               array<PaletteEntry>^ palette, ImageInformation* imageInformation )\r
-       {\r
-               pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromFileInMemory( surface->InternalPointer, \r
-                       reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ), destinationRectangle, memory, size, sourceRectangle, \r
-                       static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( imageInformation ) );\r
-               \r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromFileInMemory( Surface^ surface, array<Byte>^ memory, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle,     System::Drawing::Rectangle destinationRectangle,\r
-               array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-               return FromFileInMemory_Internal( surface, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,\r
-                       &source, &dest, palette, pinnedImageInfo );\r
-       }\r
-\r
-       Result Surface::FromFileInMemory( Surface^ surface, array<Byte>^ memory, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle,     System::Drawing::Rectangle destinationRectangle,\r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-               return FromFileInMemory_Internal( surface, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,\r
-                       &source, &dest, nullptr, pinnedImageInfo );\r
-       }\r
-\r
-       Result Surface::FromFileInMemory( Surface^ surface, array<Byte>^ memory, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle,     System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromFileInMemory_Internal( surface, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,\r
-                       &source, &dest, nullptr, NULL );\r
-       }\r
-\r
-       Result Surface::FromFileInMemory( Surface^ surface, array<Byte>^ memory, Filter filter, int colorKey )\r
-       {\r
-               pin_ptr<unsigned char> pinnedMemory = &memory[0];\r
-               return FromFileInMemory_Internal( surface, pinnedMemory, static_cast<UINT>( memory->Length ), filter, colorKey,\r
-                       NULL, NULL, nullptr, NULL );\r
-       }\r
-\r
-       Result Surface::FromFileInStream( Surface^ surface, Stream^ stream, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle,\r
-               array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-                       RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-                       pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-                       UINT size = static_cast<UINT>( ds->RemainingLength );\r
-                       return FromFileInMemory_Internal( surface, ds->SeekToEnd(), size, filter, colorKey,\r
-                               &source, &dest, palette, pinnedImageInfo );\r
-               }\r
-\r
-               return Surface::FromFileInMemory( surface, data, filter, colorKey, sourceRectangle, destinationRectangle,\r
-                       palette, imageInformation );\r
-       }\r
-\r
-       Result Surface::FromFileInStream( Surface^ surface, Stream^ stream, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle,\r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-                       RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-                       pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-                       UINT size = static_cast<UINT>( ds->RemainingLength );\r
-                       return FromFileInMemory_Internal( surface, ds->SeekToEnd(), size, filter, colorKey,\r
-                               &source, &dest, nullptr, pinnedImageInfo );\r
-               }\r
-\r
-               return Surface::FromFileInMemory( surface, data, filter, colorKey, sourceRectangle, destinationRectangle,\r
-                       imageInformation );\r
-       }\r
-\r
-       Result Surface::FromFileInStream( Surface^ surface, Stream^ stream, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       RECT source = marshal_as<RECT>( sourceRectangle );\r
-                       RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-                       UINT size = static_cast<UINT>( ds->RemainingLength );\r
-                       return FromFileInMemory_Internal( surface, ds->SeekToEnd(), size, filter, colorKey,\r
-                               &source, &dest, nullptr, NULL );\r
-               }\r
-\r
-               return Surface::FromFileInMemory( surface, data, filter, colorKey, sourceRectangle, destinationRectangle );\r
-       }\r
-\r
-       Result Surface::FromFileInStream( Surface^ surface, Stream^ stream, Filter filter, int colorKey )\r
-       {\r
-               DataStream^ ds = nullptr;\r
-               array<Byte>^ data = Utilities::ReadStream( stream, &ds );\r
-\r
-               if( data == nullptr )\r
-               {\r
-                       UINT size = static_cast<UINT>( ds->RemainingLength );\r
-                       return FromFileInMemory_Internal( surface, ds->SeekToEnd(), size, filter, colorKey,\r
-                               NULL, NULL, nullptr, NULL );\r
-               }\r
-\r
-               return Surface::FromFileInMemory( surface, data, filter, colorKey );\r
-       }\r
-\r
-       Result Surface::FromFile( Surface^ surface, String^ fileName, Filter filter, int colorKey, \r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle,\r
-               array<PaletteEntry>^ palette, [Out] ImageInformation% imageInformation )\r
-       {\r
-               pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromFile( surface->InternalPointer, \r
-                       reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ), &dest, pinnedName,\r
-                       &source, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromFile( Surface^ surface, String^ fileName, Filter filter, int colorKey, \r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle,\r
-               [Out] ImageInformation% imageInformation )\r
-       {\r
-               pin_ptr<ImageInformation> pinnedImageInfo = &imageInformation;\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromFile( surface->InternalPointer, NULL, &dest, pinnedName,\r
-                       &source, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), reinterpret_cast<D3DXIMAGE_INFO*>( pinnedImageInfo ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromFile( Surface^ surface, String^ fileName, Filter filter, int colorKey, \r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromFile( surface->InternalPointer, NULL, &dest, pinnedName,\r
-                       &source, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), NULL );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromFile( Surface^ surface, String^ fileName, Filter filter, int colorKey )\r
-       {\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars( fileName );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromFile( surface->InternalPointer, NULL, NULL, pinnedName,\r
-                       NULL, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ), NULL );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromSurface( Surface^ destinationSurface, Surface^ sourceSurface, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle,\r
-               array<PaletteEntry>^ destinationPalette, array<PaletteEntry>^ sourcePalette )\r
-       {\r
-               pin_ptr<PaletteEntry> pinnedSource = sourcePalette == nullptr ? nullptr : &sourcePalette[0];\r
-               pin_ptr<PaletteEntry> pinnedDest = destinationPalette == nullptr ? nullptr : &destinationPalette[0];\r
-\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromSurface( destinationSurface->InternalPointer, \r
-                       reinterpret_cast<const PALETTEENTRY*>( pinnedDest ), &dest,\r
-                       sourceSurface->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedSource ), \r
-                       &source, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromSurface( Surface^ destinationSurface, Surface^ sourceSurface, Filter filter, int colorKey,\r
-               System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle )\r
-       {\r
-               RECT source = marshal_as<RECT>( sourceRectangle );\r
-               RECT dest = marshal_as<RECT>( destinationRectangle );\r
-\r
-               HRESULT hr = D3DXLoadSurfaceFromSurface( destinationSurface->InternalPointer, \r
-                       NULL, &dest, sourceSurface->InternalPointer, NULL, &source, static_cast<DWORD>( filter ), \r
-                       static_cast<D3DCOLOR>( colorKey ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::FromSurface( Surface^ destinationSurface, Surface^ sourceSurface, Filter filter, int colorKey )\r
-       {\r
-               HRESULT hr = D3DXLoadSurfaceFromSurface( destinationSurface->InternalPointer, NULL, NULL, \r
-                       sourceSurface->InternalPointer, NULL, NULL, static_cast<DWORD>( filter ), static_cast<D3DCOLOR>( colorKey ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       DataStream^ Surface::ToStream( Surface^ surface, ImageFileFormat format, System::Drawing::Rectangle rectangle,\r
-               array<PaletteEntry>^ palette )\r
-       {\r
-               ID3DXBuffer *result = NULL;\r
-               pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];\r
-\r
-               RECT rect = marshal_as<RECT>( rectangle );\r
-\r
-               HRESULT hr = D3DXSaveSurfaceToFileInMemory( &result, static_cast<D3DXIMAGE_FILEFORMAT>( format ),\r
-                       surface->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ), &rect );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return gcnew DataStream( result );\r
-       }\r
-\r
-       DataStream^ Surface::ToStream( Surface^ surface, ImageFileFormat format, System::Drawing::Rectangle rectangle )\r
-       {\r
-               ID3DXBuffer *result = NULL;\r
-               RECT rect = marshal_as<RECT>( rectangle );\r
-\r
-               HRESULT hr = D3DXSaveSurfaceToFileInMemory( &result, static_cast<D3DXIMAGE_FILEFORMAT>( format ),\r
-                       surface->InternalPointer, NULL, &rect );\r
-       \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return gcnew DataStream( result );\r
-       }\r
-\r
-       DataStream^ Surface::ToStream( Surface^ surface, ImageFileFormat format )\r
-       {\r
-               ID3DXBuffer *result = NULL;\r
-\r
-               HRESULT hr = D3DXSaveSurfaceToFileInMemory( &result, static_cast<D3DXIMAGE_FILEFORMAT>( format ),\r
-                       surface->InternalPointer, NULL, NULL );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-\r
-               return gcnew DataStream( result );\r
-       }\r
-\r
-       Result Surface::ToFile( Surface^ surface, String^ fileName, ImageFileFormat format, \r
-               System::Drawing::Rectangle rectangle, array<PaletteEntry>^ palette )\r
-       {\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);\r
-               pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];\r
-\r
-               RECT rect = marshal_as<RECT>( rectangle );\r
-               \r
-               HRESULT hr = D3DXSaveSurfaceToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ), \r
-                       surface->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ), &rect );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::ToFile( Surface^ surface, String^ fileName, ImageFileFormat format, \r
-               System::Drawing::Rectangle rectangle )\r
-       {\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);\r
-               RECT rect = marshal_as<RECT>( rectangle );\r
-               \r
-               HRESULT hr = D3DXSaveSurfaceToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ), \r
-                       surface->InternalPointer, NULL, &rect );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       Result Surface::ToFile( Surface^ surface, String^ fileName, ImageFileFormat format )\r
-       {\r
-               pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);\r
-               \r
-               HRESULT hr = D3DXSaveSurfaceToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ), \r
-                       surface->InternalPointer, NULL, NULL );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       SurfaceDescription Surface::Description::get()\r
-       {\r
-               SurfaceDescription description;\r
-\r
-               HRESULT hr = InternalPointer->GetDesc( reinterpret_cast<D3DSURFACE_DESC*>( &description ) );\r
-               RECORD_D3D9( hr );\r
-\r
-               return description;\r
-       }\r
-\r
-       DataRectangle^ Surface::LockRectangle( LockFlags flags )\r
-       {\r
-               D3DLOCKED_RECT lockedRect;\r
-               \r
-               HRESULT hr = InternalPointer->LockRect( &lockedRect, NULL, static_cast<DWORD>( flags ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-               \r
-               int lockedSize = ComputeLockedSize(lockedRect);\r
-               bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;\r
-               DataRectangle^ outRect = gcnew DataRectangle( lockedRect.Pitch, gcnew DataStream( lockedRect.pBits, lockedSize, true, !readOnly, false ) );\r
-               return outRect;\r
-       }\r
-\r
-       DataRectangle^ Surface::LockRectangle( System::Drawing::Rectangle rect, LockFlags flags )\r
-       {\r
-               D3DLOCKED_RECT lockedRect;\r
-               RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
-\r
-               HRESULT hr = InternalPointer->LockRect( &lockedRect, &nativeRect, static_cast<DWORD>( flags ) );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return nullptr;\r
-               \r
-               int lockedSize = lockedRect.Pitch * Description.Height;\r
-               \r
-               bool readOnly = (flags & LockFlags::ReadOnly) == LockFlags::ReadOnly;\r
-               DataRectangle^ outRect = gcnew DataRectangle( lockedRect.Pitch, gcnew DataStream( lockedRect.pBits, lockedSize, true, !readOnly, false ) );\r
-               return outRect;\r
-       }\r
-\r
-       Result Surface::UnlockRectangle()\r
-       {\r
-               HRESULT hr = InternalPointer->UnlockRect();\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       IntPtr Surface::GetDC()\r
-       {\r
-               HDC hdc;\r
-               \r
-               HRESULT hr = InternalPointer->GetDC( &hdc );\r
-               \r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return IntPtr::Zero;\r
-\r
-               IntPtr ptr( hdc );\r
-               return ptr;\r
-       }\r
-\r
-       Result Surface::ReleaseDC( IntPtr hdc )\r
-       {\r
-               HRESULT hr = InternalPointer->ReleaseDC( static_cast<HDC>( hdc.ToPointer() ) );\r
-               return RECORD_D3D9( hr );\r
-       }\r
-\r
-       generic<typename TContainer>\r
-       TContainer Surface::GetContainer()\r
-       {\r
-               GUID guid = Utilities::GetNativeGuidForType( TContainer::typeid );\r
-               void *resultPointer;\r
-\r
-               HRESULT hr = InternalPointer->GetContainer( guid, &resultPointer );\r
-               if( RECORD_D3D9( hr ).IsFailure )\r
-                       return TContainer();\r
-\r
-               MethodInfo^ method = TContainer::typeid->GetMethod( "FromPointer", BindingFlags::Public | BindingFlags::Static );\r
-               return safe_cast<TContainer>( method->Invoke( nullptr, gcnew array<Object^> { IntPtr( resultPointer ) } ) );\r
-       }\r
-}\r
-}\r