ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

swapchain.c
Go to the documentation of this file.
00001 /*
00002  * IDirect3DSwapChain8 implementation
00003  *
00004  * Copyright 2005 Oliver Stieber
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "config.h"
00022 #include "d3d8_private.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
00025 
00026 static inline IDirect3DSwapChain8Impl *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
00027 {
00028     return CONTAINING_RECORD(iface, IDirect3DSwapChain8Impl, IDirect3DSwapChain8_iface);
00029 }
00030 
00031 static HRESULT WINAPI IDirect3DSwapChain8Impl_QueryInterface(IDirect3DSwapChain8 *iface,
00032         REFIID riid, void **ppobj)
00033 {
00034     IDirect3DSwapChain8Impl *This = impl_from_IDirect3DSwapChain8(iface);
00035 
00036     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
00037 
00038     if (IsEqualGUID(riid, &IID_IUnknown)
00039         || IsEqualGUID(riid, &IID_IDirect3DSwapChain8)) {
00040         IUnknown_AddRef(iface);
00041         *ppobj = This;
00042         return S_OK;
00043     }
00044 
00045     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
00046     *ppobj = NULL;
00047     return E_NOINTERFACE;
00048 }
00049 
00050 static ULONG WINAPI IDirect3DSwapChain8Impl_AddRef(IDirect3DSwapChain8 *iface)
00051 {
00052     IDirect3DSwapChain8Impl *This = impl_from_IDirect3DSwapChain8(iface);
00053     ULONG ref = InterlockedIncrement(&This->ref);
00054 
00055     TRACE("%p increasing refcount to %u.\n", iface, ref);
00056 
00057     if (ref == 1)
00058     {
00059         if (This->parentDevice)
00060             IDirect3DDevice8_AddRef(This->parentDevice);
00061         wined3d_mutex_lock();
00062         wined3d_swapchain_incref(This->wined3d_swapchain);
00063         wined3d_mutex_unlock();
00064     }
00065 
00066     return ref;
00067 }
00068 
00069 static ULONG WINAPI IDirect3DSwapChain8Impl_Release(IDirect3DSwapChain8 *iface)
00070 {
00071     IDirect3DSwapChain8Impl *This = impl_from_IDirect3DSwapChain8(iface);
00072     ULONG ref = InterlockedDecrement(&This->ref);
00073 
00074     TRACE("%p decreasing refcount to %u.\n", iface, ref);
00075 
00076     if (!ref)
00077     {
00078         IDirect3DDevice8 *parentDevice = This->parentDevice;
00079 
00080         wined3d_mutex_lock();
00081         wined3d_swapchain_decref(This->wined3d_swapchain);
00082         wined3d_mutex_unlock();
00083 
00084         if (parentDevice)
00085             IDirect3DDevice8_Release(parentDevice);
00086     }
00087     return ref;
00088 }
00089 
00090 static HRESULT WINAPI IDirect3DSwapChain8Impl_Present(IDirect3DSwapChain8 *iface,
00091         const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride,
00092         const RGNDATA *pDirtyRegion)
00093 {
00094     IDirect3DSwapChain8Impl *This = impl_from_IDirect3DSwapChain8(iface);
00095     HRESULT hr;
00096 
00097     TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
00098             iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
00099 
00100     wined3d_mutex_lock();
00101     hr = wined3d_swapchain_present(This->wined3d_swapchain, pSourceRect,
00102             pDestRect, hDestWindowOverride, pDirtyRegion, 0);
00103     wined3d_mutex_unlock();
00104 
00105     return hr;
00106 }
00107 
00108 static HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(IDirect3DSwapChain8 *iface,
00109         UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
00110 {
00111     IDirect3DSwapChain8Impl *This = impl_from_IDirect3DSwapChain8(iface);
00112     struct wined3d_surface *wined3d_surface = NULL;
00113     HRESULT hr;
00114 
00115     TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
00116             iface, iBackBuffer, Type, ppBackBuffer);
00117 
00118     wined3d_mutex_lock();
00119     hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
00120             iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
00121     if (SUCCEEDED(hr) && wined3d_surface)
00122     {
00123         *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
00124         IDirect3DSurface8_AddRef(*ppBackBuffer);
00125         wined3d_surface_decref(wined3d_surface);
00126     }
00127     wined3d_mutex_unlock();
00128 
00129     return hr;
00130 }
00131 
00132 static const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
00133 {
00134     IDirect3DSwapChain8Impl_QueryInterface,
00135     IDirect3DSwapChain8Impl_AddRef,
00136     IDirect3DSwapChain8Impl_Release,
00137     IDirect3DSwapChain8Impl_Present,
00138     IDirect3DSwapChain8Impl_GetBackBuffer
00139 };
00140 
00141 static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
00142 {
00143     HeapFree(GetProcessHeap(), 0, parent);
00144 }
00145 
00146 static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
00147 {
00148     d3d8_swapchain_wined3d_object_released,
00149 };
00150 
00151 HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
00152         D3DPRESENT_PARAMETERS *present_parameters)
00153 {
00154     struct wined3d_swapchain_desc desc;
00155     HRESULT hr;
00156 
00157     swapchain->ref = 1;
00158     swapchain->IDirect3DSwapChain8_iface.lpVtbl = &Direct3DSwapChain8_Vtbl;
00159 
00160     desc.backbuffer_width = present_parameters->BackBufferWidth;
00161     desc.backbuffer_height = present_parameters->BackBufferHeight;
00162     desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
00163     desc.backbuffer_count = max(1, present_parameters->BackBufferCount);
00164     desc.multisample_type = present_parameters->MultiSampleType;
00165     desc.multisample_quality = 0; /* d3d9 only */
00166     desc.swap_effect = present_parameters->SwapEffect;
00167     desc.device_window = present_parameters->hDeviceWindow;
00168     desc.windowed = present_parameters->Windowed;
00169     desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
00170     desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
00171     desc.flags = present_parameters->Flags;
00172     desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
00173     desc.swap_interval = present_parameters->FullScreen_PresentationInterval;
00174     desc.auto_restore_display_mode = TRUE;
00175 
00176     wined3d_mutex_lock();
00177     hr = wined3d_swapchain_create(device->wined3d_device, &desc,
00178             SURFACE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops,
00179             &swapchain->wined3d_swapchain);
00180     wined3d_mutex_unlock();
00181 
00182     present_parameters->BackBufferWidth = desc.backbuffer_width;
00183     present_parameters->BackBufferHeight = desc.backbuffer_height;
00184     present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
00185     present_parameters->BackBufferCount = desc.backbuffer_count;
00186     present_parameters->MultiSampleType = desc.multisample_type;
00187     present_parameters->SwapEffect = desc.swap_effect;
00188     present_parameters->hDeviceWindow = desc.device_window;
00189     present_parameters->Windowed = desc.windowed;
00190     present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
00191     present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
00192     present_parameters->Flags = desc.flags;
00193     present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
00194     present_parameters->FullScreen_PresentationInterval = desc.swap_interval;
00195 
00196     if (FAILED(hr))
00197     {
00198         WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
00199         return hr;
00200     }
00201 
00202     swapchain->parentDevice = &device->IDirect3DDevice8_iface;
00203     IDirect3DDevice8_AddRef(swapchain->parentDevice);
00204 
00205     return D3D_OK;
00206 }

Generated on Thu May 24 2012 04:22:24 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.