[PATCH] wined3d/d3d9: Set the initial scissorrect to the dimesio=
=3D?utf-8?q?Rico=3D20Sch=3DC3=3DBCller?=3D
kgbricola at web.de
Sun Aug 31 05:20:28 CDT 2008
ns of the backbuffer from the first swapchain of the device
---
dlls/d3d9/tests/device.c | 96 +++++++++++++++++++++++++++++++++++=
++++++
dlls/wined3d/stateblock.c | 30 +++++++++++++
dlls/wined3d/swapchain_base.c | 9 ++++
3 files changed, 135 insertions(+), 0 deletions(-)
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 3164b81..41dcafb 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -3,6 +3,7 @@
* Copyright (C) 2006 Chris Robinson
* Copyright (C) 2006-2007 Stefan D=F6singer(For CodeWeavers)
* Copyright 2007 Henri Verbeet
+ * Copyright (C) 2008 Rico Sch=FCller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -2016,6 +2017,100 @@ static void test_display_formats()
if(d3d9) IDirect3D9_Release(d3d9);
}
=20
+static void test_scissor_size(void)
+{
+ IDirect3D9 *d3d9_ptr =3D 0;
+ int i;
+ static const struct {
+ int winx; int winy; int backx; int backy; BOOL window;
+ } scts[] =3D { /* scissor tests */
+ {800, 600, 640, 480, TRUE},
+ {800, 600, 640, 480, FALSE},
+ {640, 480, 800, 600, TRUE},
+ {640, 480, 800, 600, FALSE},
+ };
+
+ d3d9_ptr =3D pDirect3DCreate9(D3D_SDK_VERSION);
+ ok(d3d9_ptr !=3D NULL, "Failed to create IDirect3D9 object\n");
+ if (!d3d9_ptr){
+ skip("Failed to create IDirect3D9 object\n");
+ return;
+ }
+
+ for(i=3D0; i<sizeof(scts)/sizeof(scts[0]); i++) {
+ IDirect3DDevice9 *device_ptr =3D 0;
+ D3DPRESENT_PARAMETERS present_parameters;
+ HRESULT hr;
+ WNDCLASS wc =3D {0};
+ HWND hwnd =3D 0;
+ RECT scissorrect;
+
+ wc.lpfnWndProc =3D DefWindowProc;
+ wc.lpszClassName =3D "d3d9_test_wc";
+ RegisterClass(&wc);
+
+ hwnd =3D CreateWindow("d3d9_test_wc", "d3d9_test",
+ WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, sc=
ts[i].winx, scts[i].winy, 0, 0, 0, 0);
+
+ ZeroMemory(&present_parameters, sizeof(present_parameters));
+ present_parameters.Windowed =3D scts[i].window;
+ present_parameters.hDeviceWindow =3D hwnd;
+ present_parameters.SwapEffect =3D D3DSWAPEFFECT_DISCARD;
+ present_parameters.BackBufferWidth =3D scts[i].backx;
+ present_parameters.BackBufferHeight =3D scts[i].backy;
+ present_parameters.BackBufferFormat =3D D3DFMT_A8R8G8B8;
+ present_parameters.EnableAutoDepthStencil =3D TRUE;
+ present_parameters.AutoDepthStencilFormat =3D D3DFMT_D24S8;
+
+ hr =3D IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3D=
DEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXP=
ROCESSING, &present_parameters, &device_ptr);
+ if(FAILED(hr)) {
+ present_parameters.AutoDepthStencilFormat =3D D3DFMT_D16;
+ hr =3D IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT,=
D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VER=
TEXPROCESSING, &present_parameters, &device_ptr);
+ if(FAILED(hr)) {
+ hr =3D IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFA=
ULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE=
_VERTEXPROCESSING, &present_parameters, &device_ptr);
+ }
+ }
+ ok(hr =3D=3D D3D_OK || hr =3D=3D D3DERR_NOTAVAILABLE, "IDirect3D=
_CreateDevice returned: %08x\n", hr);
+
+ if (!device_ptr)
+ {
+ DestroyWindow(hwnd);
+ skip("Creating the device failed\n");
+ goto err_out;
+ }
+
+ /* Check for the default scissor rect size */
+ hr =3D IDirect3DDevice9_GetScissorRect(device_ptr, &scissorrect)=
;
+ ok(hr =3D=3D D3D_OK, "IDirect3DDevice9_GetScissorRect failed wit=
h: %08x\n", hr);
+ ok(scissorrect.right =3D=3D scts[i].backx && scissorrect.bottom =
=3D=3D scts[i].backy && scissorrect.top =3D=3D 0 && scissorrect.left =3D=3D=
0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect.ri=
ght, scissorrect.bottom, scts[i].backx, scts[i].backy);
+
+ /* check the scissorrect values after a reset */
+ present_parameters.BackBufferWidth =3D 1024;
+ present_parameters.BackBufferHeight =3D 768;
+ hr =3D IDirect3DDevice9_Reset(device_ptr, &present_parameters);
+ ok(hr =3D=3D D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n"=
, hr);
+ hr =3D IDirect3DDevice9_TestCooperativeLevel(device_ptr);
+ ok(hr =3D=3D D3D_OK, "IDirect3DDevice9_TestCooperativeLevel afte=
r a successful reset returned %#x\n", hr);
+
+ hr =3D IDirect3DDevice9_GetScissorRect(device_ptr, &scissorrect)=
;
+ ok(hr =3D=3D D3D_OK, "IDirect3DDevice9_GetScissorRect failed wit=
h: %08x\n", hr);
+ ok(scissorrect.right =3D=3D 1024 && scissorrect.bottom =3D=3D 76=
8 && scissorrect.top =3D=3D 0 && scissorrect.left =3D=3D 0, "Scissorrect =
missmatch (%d, %d) should be (%d, %d)\n", scissorrect.right, scissorrect.=
bottom, 1024, 768);
+
+ if(device_ptr) {
+ ULONG ref;
+
+ ref =3D IDirect3DDevice9_Release(device_ptr);
+ DestroyWindow(hwnd);
+ ok(ref =3D=3D 0, "The device was not properly freed: refcoun=
t %u\n", ref);
+ }
+ }
+
+err_out:
+ if(d3d9_ptr) IDirect3D9_Release(d3d9_ptr);
+ return;
+}
+
+
START_TEST(device)
{
HMODULE d3d9_handle =3D LoadLibraryA( "d3d9.dll" );
@@ -2045,5 +2140,6 @@ START_TEST(device)
test_vertex_buffer_alignment();
test_lights();
test_set_stream_source();
+ test_scissor_size();
}
}
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index e8ff6c1..78268d8 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -1037,6 +1037,12 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Init=
StartupStateBlock(IWineD3DStat
DWORD d;
} tmpfloat;
unsigned int i;
+ IWineD3DSwapChain *swapchain;
+ IWineD3DSurface *backbuffer;
+ WINED3DSURFACE_DESC desc =3D {0};
+ UINT width, height;
+ RECT scissorrect;
+ HRESULT hr;
=20
/* Note this may have a large overhead but it should only be execute=
d
once, in order to initialize the complete state of the device and
@@ -1239,6 +1245,30 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Init=
StartupStateBlock(IWineD3DStat
This->textures[i] =3D NULL;
}
=20
+ /* Set the default scissor rect values */
+ desc.Width =3D &width;
+ desc.Height =3D &height;
+
+ /* check the return values, because the GetBackBuffer call isn't val=
id for ddraw */
+ hr =3D IWineD3DDevice_GetSwapChain(device, 0, &swapchain);
+ if( hr =3D=3D WINED3D_OK && swapchain !=3D NULL) {
+ hr =3D IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACK=
BUFFER_TYPE_MONO, &backbuffer);
+ if( hr =3D=3D WINED3D_OK && backbuffer !=3D NULL) {
+ IWineD3DSurface_GetDesc(backbuffer, &desc);
+ IWineD3DSurface_Release(backbuffer);
+
+ scissorrect.left =3D 0;
+ scissorrect.right =3D width;
+ scissorrect.top =3D 0;
+ scissorrect.bottom =3D height;
+ hr =3D IWineD3DDevice_SetScissorRect(device, &scissorrect);
+ if( hr !=3D WINED3D_OK ) {
+ ERR("This should never happen, expect rendering issues!\=
n");
+ }
+ }
+ IWineD3DSwapChain_Release(swapchain);
+ }
+
TRACE("-----------------------> Device defaults now set up...\n");
return WINED3D_OK;
}
diff --git a/dlls/wined3d/swapchain_base.c b/dlls/wined3d/swapchain_base.=
c
index 6b91234..75adf77 100644
--- a/dlls/wined3d/swapchain_base.c
+++ b/dlls/wined3d/swapchain_base.c
@@ -102,6 +102,15 @@ HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuff=
er(IWineD3DSwapChain *iface,
return WINED3DERR_INVALIDCALL;
}
=20
+ /* Return invalid if there is no backbufferarray, otherwise it will =
crash when ddraw is
+ * used (there This->backBuffer is allways NULL). We need this becau=
se this function have
+ * to be called from IWineD3DStateBlockImpl_InitStartupStateBlock to=
get the default
+ * scissorrect dimensions. */
+ if( !This->backBuffer ) {
+ *ppBackBuffer =3D NULL;
+ return WINED3DERR_INVALIDCALL;
+ }
+
*ppBackBuffer =3D This->backBuffer[iBackBuffer];
TRACE("(%p) : BackBuf %d Type %d returning %p\n", This, iBackBuffer=
, Type, *ppBackBuffer);
=20
--=20
1.5.5.1
--------------050602030001050602080508--
More information about the wine-patches
mailing list