2009-02-24 07:43:02 +01:00
|
|
|
/*
|
2011-04-05 19:01:32 +02:00
|
|
|
* Copyright 2009, 2011 Henri Verbeet for CodeWeavers
|
2009-02-24 07:43:02 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG CDECL wined3d_rendertarget_view_incref(struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&view->refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", view, refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG CDECL wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&view->refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", view, refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
if (!refcount)
|
2014-08-21 09:55:52 +02:00
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
/* Call wined3d_object_destroyed() before releasing the resource,
|
|
|
|
* since releasing the resource may end up destroying the parent. */
|
|
|
|
view->parent_ops->wined3d_object_destroyed(view->parent);
|
2014-08-21 09:55:52 +02:00
|
|
|
wined3d_resource_decref(view->resource);
|
2011-04-05 19:01:32 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, view);
|
2014-08-21 09:55:52 +02:00
|
|
|
}
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
void * CDECL wined3d_rendertarget_view_get_parent(const struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("view %p.\n", view);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
return view->parent;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
void * CDECL wined3d_rendertarget_view_get_sub_resource_parent(const struct wined3d_rendertarget_view *view)
|
|
|
|
{
|
2016-03-29 16:45:34 +02:00
|
|
|
struct wined3d_texture *texture;
|
2014-08-21 09:55:55 +02:00
|
|
|
|
|
|
|
TRACE("view %p.\n", view);
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
return wined3d_buffer_get_parent(buffer_from_resource(view->resource));
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
texture = wined3d_texture_from_resource(view->resource);
|
2014-08-21 09:55:55 +02:00
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
return wined3d_resource_get_parent(texture->sub_resources[view->sub_resource_idx].resource);
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL wined3d_rendertarget_view_set_parent(struct wined3d_rendertarget_view *view, void *parent)
|
|
|
|
{
|
|
|
|
TRACE("view %p, parent %p.\n", view, parent);
|
|
|
|
|
|
|
|
view->parent = parent;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
struct wined3d_resource * CDECL wined3d_rendertarget_view_get_resource(const struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("view %p.\n", view);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
return view->resource;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
static HRESULT wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view,
|
2014-08-21 09:55:55 +02:00
|
|
|
const struct wined3d_rendertarget_view_desc *desc, struct wined3d_resource *resource,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2010-04-13 20:46:24 +02:00
|
|
|
{
|
2014-08-21 09:55:53 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
|
|
|
|
|
2010-04-13 20:46:24 +02:00
|
|
|
view->refcount = 1;
|
|
|
|
view->parent = parent;
|
2014-08-21 09:55:55 +02:00
|
|
|
view->parent_ops = parent_ops;
|
2014-08-21 09:55:53 +02:00
|
|
|
|
|
|
|
view->format = wined3d_get_format(gl_info, desc->format_id);
|
2015-04-24 10:33:47 +02:00
|
|
|
view->format_flags = view->format->flags[resource->gl_type];
|
2014-08-21 09:55:53 +02:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
view->sub_resource_idx = 0;
|
|
|
|
view->buffer_offset = desc->u.buffer.start_idx;
|
|
|
|
view->width = desc->u.buffer.count;
|
|
|
|
view->height = 1;
|
|
|
|
view->depth = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
if (desc->u.texture.level_idx >= texture->level_count
|
|
|
|
|| desc->u.texture.layer_idx >= texture->layer_count
|
|
|
|
|| desc->u.texture.layer_count > texture->layer_count - desc->u.texture.layer_idx)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2014-08-21 09:55:53 +02:00
|
|
|
view->sub_resource_idx = desc->u.texture.layer_idx * texture->level_count + desc->u.texture.level_idx;
|
|
|
|
view->buffer_offset = 0;
|
2016-03-29 16:45:34 +02:00
|
|
|
view->width = wined3d_texture_get_level_width(texture, desc->u.texture.level_idx);
|
|
|
|
view->height = wined3d_texture_get_level_height(texture, desc->u.texture.level_idx);
|
2014-08-21 09:55:53 +02:00
|
|
|
view->depth = desc->u.texture.layer_count;
|
|
|
|
}
|
2016-03-29 16:45:34 +02:00
|
|
|
wined3d_resource_incref(view->resource = resource);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2010-04-13 20:46:24 +02:00
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2014-08-21 09:55:53 +02:00
|
|
|
HRESULT CDECL wined3d_rendertarget_view_create(const struct wined3d_rendertarget_view_desc *desc,
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_rendertarget_view **view)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_rendertarget_view *object;
|
2016-03-29 16:45:34 +02:00
|
|
|
HRESULT hr;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
desc, resource, parent, parent_ops, view);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2014-08-21 09:55:53 +02:00
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
2011-05-10 21:18:47 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_init(object, desc, resource, parent, parent_ops)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
WARN("Failed to initialise view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
TRACE("Created render target view %p.\n", object);
|
2014-08-21 09:55:53 +02:00
|
|
|
*view = object;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
return hr;
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
2014-08-21 09:55:55 +02:00
|
|
|
|
2015-10-28 14:02:10 +01:00
|
|
|
HRESULT CDECL wined3d_rendertarget_view_create_from_sub_resource(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_rendertarget_view **view)
|
|
|
|
{
|
2016-02-02 19:23:31 +01:00
|
|
|
struct wined3d_rendertarget_view_desc desc;
|
2015-10-28 14:02:10 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
texture, sub_resource_idx, parent, parent_ops, view);
|
|
|
|
|
2016-02-02 19:23:31 +01:00
|
|
|
desc.format_id = texture->resource.format->id;
|
|
|
|
desc.u.texture.level_idx = sub_resource_idx % texture->level_count;
|
|
|
|
desc.u.texture.layer_idx = sub_resource_idx / texture->level_count;
|
|
|
|
desc.u.texture.layer_count = 1;
|
2015-10-28 14:02:10 +01:00
|
|
|
|
2016-02-02 19:23:31 +01:00
|
|
|
return wined3d_rendertarget_view_create(&desc, &texture->resource, parent, parent_ops, view);
|
2015-10-28 14:02:10 +01:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:44:15 +02:00
|
|
|
ULONG CDECL wined3d_shader_resource_view_incref(struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedIncrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2014-12-01 08:45:43 +01:00
|
|
|
/* Call wined3d_object_destroyed() before releasing the resource,
|
|
|
|
* since releasing the resource may end up destroying the parent. */
|
2014-09-16 10:44:15 +02:00
|
|
|
view->parent_ops->wined3d_object_destroyed(view->parent);
|
2014-12-01 08:45:43 +01:00
|
|
|
wined3d_resource_decref(view->resource);
|
2014-09-16 10:44:15 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, view);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:27 +02:00
|
|
|
void * CDECL wined3d_shader_resource_view_get_parent(const struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("view %p.\n", view);
|
|
|
|
|
|
|
|
return view->parent;
|
|
|
|
}
|
|
|
|
|
2014-12-01 08:45:43 +01:00
|
|
|
HRESULT CDECL wined3d_shader_resource_view_create(struct wined3d_resource *resource, void *parent,
|
|
|
|
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader_resource_view **view)
|
2014-09-16 10:44:15 +02:00
|
|
|
{
|
|
|
|
struct wined3d_shader_resource_view *object;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("resource %p, parent %p, parent_ops %p, view %p.\n", resource, parent, parent_ops, view);
|
2014-09-16 10:44:15 +02:00
|
|
|
|
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->refcount = 1;
|
2014-12-01 08:45:43 +01:00
|
|
|
object->resource = resource;
|
|
|
|
wined3d_resource_incref(resource);
|
2014-09-16 10:44:15 +02:00
|
|
|
object->parent = parent;
|
|
|
|
object->parent_ops = parent_ops;
|
|
|
|
|
|
|
|
TRACE("Created shader resource view %p.\n", object);
|
|
|
|
*view = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|