058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is free software; you can redistribute it and/or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * modify it under the terms of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License as published by the Free Software Foundation; either
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * version 2.1 of the License, or (at your option) any later version.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is distributed in the hope that it will be useful,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Lesser General Public License for more details.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * You should have received a copy of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License along with this library; if not, write to the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync/*
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * a choice of LGPL license versions is made available with the language indicating
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * of the LGPL is applied is otherwise unspecified.
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync */
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "config.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "d3d8_private.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d8);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline struct d3d8_vertexbuffer *impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CONTAINING_RECORD(iface, struct d3d8_vertexbuffer, IDirect3DVertexBuffer8_iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *iface, REFIID riid, void **object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || IsEqualGUID(riid, &IID_IDirect3DResource8)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || IsEqualGUID(riid, &IID_IUnknown))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DVertexBuffer8_AddRef(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *object = iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return S_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *object = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_NOINTERFACE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&buffer->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (refcount == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(buffer->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&buffer->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8 *device = buffer->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the device last, as it may cause the device to be destroyed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_Release(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8 **device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, device %p.\n", iface, device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *device = buffer->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(*device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning device %p.\n", *device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync REFGUID guid, const void *data, DWORD data_size, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, debugstr_guid(guid), data, data_size, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync REFGUID guid, void *data, DWORD *data_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s, data %p, data_size %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, debugstr_guid(guid), data, data_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_free_private_data(resource, guid);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD previous;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, priority %u.\n", iface, priority);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync previous = wined3d_buffer_set_priority(buffer->wined3d_buffer, priority);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return previous;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD priority;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priority = wined3d_buffer_get_priority(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return priority;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void WINAPI d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_preload(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic D3DRESOURCETYPE WINAPI d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3DRTYPE_VERTEXBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT offset, UINT size,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE **data, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, offset, size, data, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_buffer_map(buffer->wined3d_buffer, offset, size, data, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_unmap(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync D3DVERTEXBUFFER_DESC *desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource_desc wined3d_desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *wined3d_resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, desc %p.\n", iface, desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Type = D3DRTYPE_VERTEXBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Pool = wined3d_desc.pool;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Size = wined3d_desc.size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->FVF = buffer->fvf;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Format = D3DFMT_VERTEXDATA;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IUnknown */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_QueryInterface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_AddRef,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_Release,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IDirect3DResource8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_GetDevice,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_SetPrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_GetPrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_FreePrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_SetPriority,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_GetPriority,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_PreLoad,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_GetType,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IDirect3DVertexBuffer8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_Lock,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_Unlock,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_GetDesc,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_vertexbuffer_wined3d_object_destroyed,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->refcount = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->fvf = fvf;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (enum wined3d_pool)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->parent_device = &device->IDirect3DDevice8_iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(buffer->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct d3d8_vertexbuffer *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync assert(iface->lpVtbl == &Direct3DVertexBuffer8_Vtbl);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return impl_from_IDirect3DVertexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline struct d3d8_indexbuffer *impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return CONTAINING_RECORD(iface, struct d3d8_indexbuffer, IDirect3DIndexBuffer8_iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *iface, REFIID riid, void **object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || IsEqualGUID(riid, &IID_IDirect3DResource8)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || IsEqualGUID(riid, &IID_IUnknown))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DIndexBuffer8_AddRef(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *object = iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return S_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *object = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_NOINTERFACE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&buffer->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (refcount == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(buffer->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_incref(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&buffer->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8 *device = buffer->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_decref(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the device last, as it may cause the device to be destroyed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_Release(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8 **device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, device %p.\n", iface, device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *device = buffer->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(*device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning device %p.\n", *device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync REFGUID guid, const void *data, DWORD data_size, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, debugstr_guid(guid), data, data_size, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync REFGUID guid, void *data, DWORD *data_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s, data %p, data_size %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, debugstr_guid(guid), data, data_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_resource_free_private_data(resource, guid);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD previous;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, priority %u.\n", iface, priority);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync previous = wined3d_buffer_set_priority(buffer->wined3d_buffer, priority);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return previous;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD priority;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priority = wined3d_buffer_get_priority(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return priority;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void WINAPI d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_preload(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic D3DRESOURCETYPE WINAPI d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3DRTYPE_INDEXBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT offset, UINT size,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE **data, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, offset, size, data, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_buffer_map(buffer->wined3d_buffer, offset, size, data, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p.\n", iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_buffer_unmap(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync D3DINDEXBUFFER_DESC *desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource_desc wined3d_desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_resource *wined3d_resource;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, desc %p.\n", iface, desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Format = d3dformat_from_wined3dformat(buffer->format);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Type = D3DRTYPE_INDEXBUFFER;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Pool = wined3d_desc.pool;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync desc->Size = wined3d_desc.size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IUnknown */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_QueryInterface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_AddRef,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_Release,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IDirect3DResource8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_GetDevice,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_SetPrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_GetPrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_FreePrivateData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_SetPriority,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_GetPriority,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_PreLoad,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_GetType,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* IDirect3DIndexBuffer8 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_Lock,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_Unlock,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_GetDesc,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d8_indexbuffer_wined3d_object_destroyed,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->refcount = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->format = wined3dformat_from_d3dformat(format);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (enum wined3d_pool)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->parent_device = &device->IDirect3DDevice8_iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice8_AddRef(buffer->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct d3d8_indexbuffer *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync assert(iface->lpVtbl == &d3d8_indexbuffer_vtbl);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return impl_from_IDirect3DIndexBuffer8(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}