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

palette.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006 Stefan Dösinger
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 #include "wine/port.h"
00021 
00022 #include "ddraw_private.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
00025 
00026 /*****************************************************************************
00027  * IDirectDrawPalette::QueryInterface
00028  *
00029  * A usual QueryInterface implementation. Can only Query IUnknown and
00030  * IDirectDrawPalette
00031  *
00032  * Params:
00033  *  refiid: The interface id queried for
00034  *  obj: Address to return the interface pointer at
00035  *
00036  * Returns:
00037  *  S_OK on success
00038  *  E_NOINTERFACE if the requested interface wasn't found
00039  *****************************************************************************/
00040 static HRESULT WINAPI
00041 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette *iface,
00042                                       REFIID refiid,
00043                                       void **obj)
00044 {
00045     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
00046 
00047     if (IsEqualGUID(refiid, &IID_IUnknown)
00048         || IsEqualGUID(refiid, &IID_IDirectDrawPalette))
00049     {
00050         *obj = iface;
00051         IDirectDrawPalette_AddRef(iface);
00052         return S_OK;
00053     }
00054     else
00055     {
00056         *obj = NULL;
00057         return E_NOINTERFACE;
00058     }
00059 }
00060 
00061 /*****************************************************************************
00062  * IDirectDrawPaletteImpl::AddRef
00063  *
00064  * Increases the refcount.
00065  *
00066  * Returns:
00067  *  The new refcount
00068  *
00069  *****************************************************************************/
00070 static ULONG WINAPI
00071 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface)
00072 {
00073     IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface);
00074     ULONG ref = InterlockedIncrement(&This->ref);
00075 
00076     TRACE("%p increasing refcount to %u.\n", This, ref);
00077 
00078     return ref;
00079 }
00080 
00081 /*****************************************************************************
00082  * IDirectDrawPaletteImpl::Release
00083  *
00084  * Reduces the refcount. If the refcount falls to 0, the object is destroyed
00085  *
00086  * Returns:
00087  *  The new refcount
00088  *
00089  *****************************************************************************/
00090 static ULONG WINAPI
00091 IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
00092 {
00093     IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface);
00094     ULONG ref = InterlockedDecrement(&This->ref);
00095 
00096     TRACE("%p decreasing refcount to %u.\n", This, ref);
00097 
00098     if (ref == 0)
00099     {
00100         wined3d_mutex_lock();
00101         wined3d_palette_decref(This->wineD3DPalette);
00102         if(This->ifaceToRelease)
00103         {
00104             IUnknown_Release(This->ifaceToRelease);
00105         }
00106         wined3d_mutex_unlock();
00107 
00108         HeapFree(GetProcessHeap(), 0, This);
00109     }
00110 
00111     return ref;
00112 }
00113 
00114 /*****************************************************************************
00115  * IDirectDrawPalette::Initialize
00116  *
00117  * Initializes the palette. As we start initialized, return
00118  * DDERR_ALREADYINITIALIZED
00119  *
00120  * Params:
00121  *  DD: DirectDraw interface this palette is assigned to
00122  *  Flags: Some flags, as usual
00123  *  ColorTable: The startup color table
00124  *
00125  * Returns:
00126  *  DDERR_ALREADYINITIALIZED
00127  *
00128  *****************************************************************************/
00129 static HRESULT WINAPI
00130 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette *iface,
00131                                   IDirectDraw *DD,
00132                                   DWORD Flags,
00133                                   PALETTEENTRY *ColorTable)
00134 {
00135     TRACE("iface %p, ddraw %p, flags %#x, entries %p.\n",
00136             iface, DD, Flags, ColorTable);
00137 
00138     return DDERR_ALREADYINITIALIZED;
00139 }
00140 
00141 /*****************************************************************************
00142  * IDirectDrawPalette::GetCaps
00143  *
00144  * Returns the palette description
00145  *
00146  * Params:
00147  *  Caps: Address to store the caps at
00148  *
00149  * Returns:
00150  *  D3D_OK on success
00151  *  DDERR_INVALIDPARAMS if Caps is NULL
00152  *  For more details, see IWineD3DPalette::GetCaps
00153  *
00154  *****************************************************************************/
00155 static HRESULT WINAPI
00156 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
00157                                DWORD *Caps)
00158 {
00159     IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface);
00160 
00161     TRACE("iface %p, caps %p.\n", iface, Caps);
00162 
00163     wined3d_mutex_lock();
00164     *Caps = wined3d_palette_get_flags(This->wineD3DPalette);
00165     wined3d_mutex_unlock();
00166 
00167     return D3D_OK;
00168 }
00169 
00170 /*****************************************************************************
00171  * IDirectDrawPalette::SetEntries
00172  *
00173  * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
00174  * care for updating the surface.
00175  *
00176  * Params:
00177  *  Flags: Flags, as usual
00178  *  Start: First palette entry to set
00179  *  Count: Number of entries to set
00180  *  PalEnt: Source entries
00181  *
00182  * Returns:
00183  *  D3D_OK on success
00184  *  DDERR_INVALIDPARAMS if PalEnt is NULL
00185  *  For details, see IWineD3DDevice::SetEntries
00186  *
00187  *****************************************************************************/
00188 static HRESULT WINAPI
00189 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
00190                                   DWORD Flags,
00191                                   DWORD Start,
00192                                   DWORD Count,
00193                                   PALETTEENTRY *PalEnt)
00194 {
00195     IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface);
00196     HRESULT hr;
00197 
00198     TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
00199             iface, Flags, Start, Count, PalEnt);
00200 
00201     if(!PalEnt)
00202         return DDERR_INVALIDPARAMS;
00203 
00204     wined3d_mutex_lock();
00205     hr = wined3d_palette_set_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
00206     wined3d_mutex_unlock();
00207 
00208     return hr;
00209 }
00210 
00211 /*****************************************************************************
00212  * IDirectDrawPalette::GetEntries
00213  *
00214  * Returns the entries stored in this interface.
00215  *
00216  * Params:
00217  *  Flags: Flags :)
00218  *  Start: First entry to return
00219  *  Count: The number of entries to return
00220  *  PalEnt: PALETTEENTRY structure to write the entries to
00221  *
00222  * Returns:
00223  *  D3D_OK on success
00224  *  DDERR_INVALIDPARAMS if PalEnt is NULL
00225  *  For details, see IWineD3DDevice::SetEntries
00226  *
00227  *****************************************************************************/
00228 static HRESULT WINAPI
00229 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
00230                                   DWORD Flags,
00231                                   DWORD Start,
00232                                   DWORD Count,
00233                                   PALETTEENTRY *PalEnt)
00234 {
00235     IDirectDrawPaletteImpl *This = impl_from_IDirectDrawPalette(iface);
00236     HRESULT hr;
00237 
00238     TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
00239             iface, Flags, Start, Count, PalEnt);
00240 
00241     if(!PalEnt)
00242         return DDERR_INVALIDPARAMS;
00243 
00244     wined3d_mutex_lock();
00245     hr = wined3d_palette_get_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
00246     wined3d_mutex_unlock();
00247 
00248     return hr;
00249 }
00250 
00251 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl =
00252 {
00253     /*** IUnknown ***/
00254     IDirectDrawPaletteImpl_QueryInterface,
00255     IDirectDrawPaletteImpl_AddRef,
00256     IDirectDrawPaletteImpl_Release,
00257     /*** IDirectDrawPalette ***/
00258     IDirectDrawPaletteImpl_GetCaps,
00259     IDirectDrawPaletteImpl_GetEntries,
00260     IDirectDrawPaletteImpl_Initialize,
00261     IDirectDrawPaletteImpl_SetEntries
00262 };
00263 
00264 IDirectDrawPaletteImpl *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface)
00265 {
00266     if (!iface) return NULL;
00267     assert(iface->lpVtbl == &ddraw_palette_vtbl);
00268     return CONTAINING_RECORD(iface, IDirectDrawPaletteImpl, IDirectDrawPalette_iface);
00269 }
00270 
00271 HRESULT ddraw_palette_init(IDirectDrawPaletteImpl *palette,
00272         IDirectDrawImpl *ddraw, DWORD flags, PALETTEENTRY *entries)
00273 {
00274     HRESULT hr;
00275 
00276     palette->IDirectDrawPalette_iface.lpVtbl = &ddraw_palette_vtbl;
00277     palette->ref = 1;
00278 
00279     hr = wined3d_palette_create(ddraw->wined3d_device, flags,
00280             entries, palette, &palette->wineD3DPalette);
00281     if (FAILED(hr))
00282     {
00283         WARN("Failed to create wined3d palette, hr %#x.\n", hr);
00284         return hr;
00285     }
00286 
00287     palette->ifaceToRelease = (IUnknown *)&ddraw->IDirectDraw7_iface;
00288     IUnknown_AddRef(palette->ifaceToRelease);
00289 
00290     return DD_OK;
00291 }

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