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  * IDirect3DSwapChain9 implementation
00003  *
00004  * Copyright 2002-2003 Jason Edmeades
00005  *                     Raphael Junqueira
00006  * Copyright 2005 Oliver Stieber
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00021  */
00022 
00023 #include "config.h"
00024 #include "d3d9_private.h"
00025 
00026 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
00027 
00028 /* IDirect3DSwapChain IUnknown parts follow: */
00029 static HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
00030 {
00031     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00032 
00033     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
00034 
00035     if (IsEqualGUID(riid, &IID_IUnknown)
00036         || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
00037         IDirect3DSwapChain9_AddRef(iface);
00038         *ppobj = This;
00039         return S_OK;
00040     }
00041 
00042     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
00043     *ppobj = NULL;
00044     return E_NOINTERFACE;
00045 }
00046 
00047 static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
00048     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00049     ULONG ref = InterlockedIncrement(&This->ref);
00050 
00051     TRACE("%p increasing refcount to %u.\n", iface, ref);
00052 
00053     if (ref == 1)
00054     {
00055         if (This->parentDevice)
00056             IDirect3DDevice9Ex_AddRef(This->parentDevice);
00057 
00058         wined3d_mutex_lock();
00059         wined3d_swapchain_incref(This->wined3d_swapchain);
00060         wined3d_mutex_unlock();
00061     }
00062 
00063     return ref;
00064 }
00065 
00066 static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
00067     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00068     ULONG ref = InterlockedDecrement(&This->ref);
00069 
00070     TRACE("%p decreasing refcount to %u.\n", iface, ref);
00071 
00072     if (ref == 0) {
00073         IDirect3DDevice9Ex *parentDevice = This->parentDevice;
00074 
00075         wined3d_mutex_lock();
00076         wined3d_swapchain_decref(This->wined3d_swapchain);
00077         wined3d_mutex_unlock();
00078 
00079         /* Release the device last, as it may cause the device to be destroyed. */
00080         if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
00081     }
00082     return ref;
00083 }
00084 
00085 /* IDirect3DSwapChain9 parts follow: */
00086 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
00087     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00088     HRESULT hr;
00089 
00090     TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x.\n",
00091             iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
00092 
00093     wined3d_mutex_lock();
00094     hr = wined3d_swapchain_present(This->wined3d_swapchain, pSourceRect,
00095             pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
00096     wined3d_mutex_unlock();
00097 
00098     return hr;
00099 }
00100 
00101 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(IDirect3DSwapChain9 *iface,
00102         IDirect3DSurface9 *pDestSurface)
00103 {
00104     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00105     IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestSurface);
00106     HRESULT hr;
00107 
00108     TRACE("iface %p, surface %p.\n", iface, pDestSurface);
00109 
00110     wined3d_mutex_lock();
00111     hr = wined3d_swapchain_get_front_buffer_data(This->wined3d_swapchain, dst->wined3d_surface);
00112     wined3d_mutex_unlock();
00113 
00114     return hr;
00115 }
00116 
00117 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(IDirect3DSwapChain9 *iface,
00118         UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
00119 {
00120     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00121     struct wined3d_surface *wined3d_surface = NULL;
00122     HRESULT hr;
00123 
00124     TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
00125             iface, iBackBuffer, Type, ppBackBuffer);
00126 
00127     wined3d_mutex_lock();
00128     hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
00129             iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
00130     if (SUCCEEDED(hr) && wined3d_surface)
00131     {
00132        *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
00133        IDirect3DSurface9_AddRef(*ppBackBuffer);
00134        wined3d_surface_decref(wined3d_surface);
00135     }
00136     wined3d_mutex_unlock();
00137 
00138     /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
00139     return hr;
00140 }
00141 
00142 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
00143     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00144     HRESULT hr;
00145 
00146     TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
00147 
00148     wined3d_mutex_lock();
00149     hr = wined3d_swapchain_get_raster_status(This->wined3d_swapchain, (struct wined3d_raster_status *)pRasterStatus);
00150     wined3d_mutex_unlock();
00151 
00152     return hr;
00153 }
00154 
00155 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
00156     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00157     HRESULT hr;
00158 
00159     TRACE("iface %p, mode %p.\n", iface, pMode);
00160 
00161     wined3d_mutex_lock();
00162     hr = wined3d_swapchain_get_display_mode(This->wined3d_swapchain, (struct wined3d_display_mode *)pMode);
00163     wined3d_mutex_unlock();
00164 
00165     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
00166 
00167     return hr;
00168 }
00169 
00170 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *iface, IDirect3DDevice9 **device)
00171 {
00172     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00173 
00174     TRACE("iface %p, device %p.\n", iface, device);
00175 
00176     *device = (IDirect3DDevice9 *)This->parentDevice;
00177     IDirect3DDevice9_AddRef(*device);
00178 
00179     TRACE("Returning device %p.\n", *device);
00180 
00181     return D3D_OK;
00182 }
00183 
00184 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(IDirect3DSwapChain9 *iface,
00185         D3DPRESENT_PARAMETERS *pPresentationParameters)
00186 {
00187     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
00188     struct wined3d_swapchain_desc desc;
00189     HRESULT hr;
00190 
00191     TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
00192 
00193     wined3d_mutex_lock();
00194     hr = wined3d_swapchain_get_desc(This->wined3d_swapchain, &desc);
00195     wined3d_mutex_unlock();
00196 
00197     pPresentationParameters->BackBufferWidth = desc.backbuffer_width;
00198     pPresentationParameters->BackBufferHeight = desc.backbuffer_height;
00199     pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
00200     pPresentationParameters->BackBufferCount = desc.backbuffer_count;
00201     pPresentationParameters->MultiSampleType = desc.multisample_type;
00202     pPresentationParameters->MultiSampleQuality = desc.multisample_quality;
00203     pPresentationParameters->SwapEffect = desc.swap_effect;
00204     pPresentationParameters->hDeviceWindow = desc.device_window;
00205     pPresentationParameters->Windowed = desc.windowed;
00206     pPresentationParameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
00207     pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
00208     pPresentationParameters->Flags = desc.flags;
00209     pPresentationParameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
00210     pPresentationParameters->PresentationInterval = desc.swap_interval;
00211 
00212     return hr;
00213 }
00214 
00215 
00216 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
00217 {
00218     IDirect3DSwapChain9Impl_QueryInterface,
00219     IDirect3DSwapChain9Impl_AddRef,
00220     IDirect3DSwapChain9Impl_Release,
00221     IDirect3DSwapChain9Impl_Present,
00222     IDirect3DSwapChain9Impl_GetFrontBufferData,
00223     IDirect3DSwapChain9Impl_GetBackBuffer,
00224     IDirect3DSwapChain9Impl_GetRasterStatus,
00225     IDirect3DSwapChain9Impl_GetDisplayMode,
00226     IDirect3DSwapChain9Impl_GetDevice,
00227     IDirect3DSwapChain9Impl_GetPresentParameters
00228 };
00229 
00230 static void STDMETHODCALLTYPE d3d9_swapchain_wined3d_object_released(void *parent)
00231 {
00232     HeapFree(GetProcessHeap(), 0, parent);
00233 }
00234 
00235 static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
00236 {
00237     d3d9_swapchain_wined3d_object_released,
00238 };
00239 
00240 HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
00241         D3DPRESENT_PARAMETERS *present_parameters)
00242 {
00243     struct wined3d_swapchain_desc desc;
00244     HRESULT hr;
00245 
00246     swapchain->ref = 1;
00247     swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl;
00248 
00249     desc.backbuffer_width = present_parameters->BackBufferWidth;
00250     desc.backbuffer_height = present_parameters->BackBufferHeight;
00251     desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
00252     desc.backbuffer_count = max(1, present_parameters->BackBufferCount);
00253     desc.multisample_type = present_parameters->MultiSampleType;
00254     desc.multisample_quality = present_parameters->MultiSampleQuality;
00255     desc.swap_effect = present_parameters->SwapEffect;
00256     desc.device_window = present_parameters->hDeviceWindow;
00257     desc.windowed = present_parameters->Windowed;
00258     desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
00259     desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
00260     desc.flags = present_parameters->Flags;
00261     desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
00262     desc.swap_interval = present_parameters->PresentationInterval;
00263     desc.auto_restore_display_mode = TRUE;
00264 
00265     wined3d_mutex_lock();
00266     hr = wined3d_swapchain_create(device->wined3d_device, &desc,
00267             SURFACE_OPENGL, swapchain, &d3d9_swapchain_wined3d_parent_ops,
00268             &swapchain->wined3d_swapchain);
00269     wined3d_mutex_unlock();
00270 
00271     present_parameters->BackBufferWidth = desc.backbuffer_width;
00272     present_parameters->BackBufferHeight = desc.backbuffer_height;
00273     present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
00274     present_parameters->BackBufferCount = desc.backbuffer_count;
00275     present_parameters->MultiSampleType = desc.multisample_type;
00276     present_parameters->MultiSampleQuality = desc.multisample_quality;
00277     present_parameters->SwapEffect = desc.swap_effect;
00278     present_parameters->hDeviceWindow = desc.device_window;
00279     present_parameters->Windowed = desc.windowed;
00280     present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
00281     present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
00282     present_parameters->Flags = desc.flags;
00283     present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
00284     present_parameters->PresentationInterval = desc.swap_interval;
00285 
00286     if (FAILED(hr))
00287     {
00288         WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
00289         return hr;
00290     }
00291 
00292     swapchain->parentDevice = &device->IDirect3DDevice9Ex_iface;
00293     IDirect3DDevice9Ex_AddRef(swapchain->parentDevice);
00294 
00295     return D3D_OK;
00296 }

Generated on Sat May 26 2012 04:20:40 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.