d3dxbuffer.c 2.62 KB
Newer Older
Raphael Junqueira's avatar
Raphael Junqueira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * ID3DXBuffer implementation
 *
 * Copyright 2002 Raphael Junqueira
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Raphael Junqueira's avatar
Raphael Junqueira committed
19 20 21 22 23
 */

#include "config.h"
#include "wine/port.h"

24 25
#include <stdarg.h>

26
#define COBJMACROS
Raphael Junqueira's avatar
Raphael Junqueira committed
27 28 29 30 31 32 33 34 35 36 37 38
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"
#include "wine/debug.h"

#include "d3d8.h"
#include "d3dx8core_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(d3d);

/* ID3DXBuffer IUnknown parts follow: */
39
static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(LPD3DXBUFFER iface, REFIID riid, LPVOID* ppobj) {
40
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
Raphael Junqueira's avatar
Raphael Junqueira committed
41 42 43
  
  if (IsEqualGUID(riid, &IID_IUnknown)
      || IsEqualGUID(riid, &IID_ID3DXBuffer)) {
44
    IUnknown_AddRef(iface);
Raphael Junqueira's avatar
Raphael Junqueira committed
45 46 47 48 49 50 51 52
    *ppobj = This;
    return D3D_OK;
  }

  WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
  return E_NOINTERFACE;
}

53
static ULONG WINAPI ID3DXBufferImpl_AddRef(LPD3DXBUFFER iface) {
54
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
55 56
  ULONG ref = InterlockedIncrement(&This->ref);

57
  TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58 59

  return ref;
Raphael Junqueira's avatar
Raphael Junqueira committed
60 61
}

62
static ULONG WINAPI ID3DXBufferImpl_Release(LPD3DXBUFFER iface) {
63
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
64 65
  ULONG ref = InterlockedDecrement(&This->ref);

66
  TRACE("(%p) : ReleaseRef to %d\n", This, ref);
67

Raphael Junqueira's avatar
Raphael Junqueira committed
68
  if (ref == 0) {
69
    HeapFree(GetProcessHeap(), 0, This->buffer);
Raphael Junqueira's avatar
Raphael Junqueira committed
70 71 72 73 74 75
    HeapFree(GetProcessHeap(), 0, This);
  }
  return ref;
}

/* ID3DXBuffer Interface follow: */
76
static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(LPD3DXBUFFER iface) {
77
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
Raphael Junqueira's avatar
Raphael Junqueira committed
78 79 80
  return This->buffer;
}

81
static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(LPD3DXBUFFER iface) {
82
  ID3DXBufferImpl *This = (ID3DXBufferImpl *)iface;
Raphael Junqueira's avatar
Raphael Junqueira committed
83 84 85
  return This->bufferSize;
}

86
const ID3DXBufferVtbl D3DXBuffer_Vtbl =
Raphael Junqueira's avatar
Raphael Junqueira committed
87 88 89 90 91 92 93
{
    ID3DXBufferImpl_QueryInterface,
    ID3DXBufferImpl_AddRef,
    ID3DXBufferImpl_Release,
    ID3DXBufferImpl_GetBufferPointer,
    ID3DXBufferImpl_GetBufferSize
};