[PATCH 2/5] wined3d: Move the "swapchain" field from struct wined3d_surface to struct wined3d_texture.
Henri Verbeet
hverbeet at codeweavers.com
Wed Aug 20 06:20:00 CDT 2014
---
dlls/wined3d/arb_program_shader.c | 5 ++--
dlls/wined3d/context.c | 10 +++----
dlls/wined3d/device.c | 2 +-
dlls/wined3d/resource.c | 10 +++----
dlls/wined3d/surface.c | 55 ++++++++++++++-----------------------
dlls/wined3d/swapchain.c | 12 ++++----
dlls/wined3d/texture.c | 29 +++++++++++++++++--
dlls/wined3d/wined3d_private.h | 5 ++--
8 files changed, 70 insertions(+), 58 deletions(-)
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 9e1de57..9105f67 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -7280,10 +7280,10 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
/* Context activation is done by the caller. */
static void upload_palette(const struct wined3d_surface *surface, struct wined3d_context *context)
{
+ const struct wined3d_palette *palette = surface->container->swapchain ? surface->container->swapchain->palette : NULL;
struct wined3d_device *device = surface->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
struct arbfp_blit_priv *priv = device->blit_priv;
- const struct wined3d_palette *palette = surface->swapchain ? surface->swapchain->palette : NULL;
if (!priv->palette_texture)
gl_info->gl_ops.gl.p_glGenTextures(1, &priv->palette_texture);
@@ -7674,7 +7674,8 @@ HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter,
arbfp_blit_unset(context->gl_info);
if (wined3d_settings.strict_draw_ordering
- || (dst_surface->swapchain && (dst_surface->swapchain->front_buffer == dst_surface)))
+ || (dst_surface->container->swapchain
+ && (dst_surface->container->swapchain->front_buffer == dst_surface)))
context->gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index fc10a57..18a0e87 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1826,7 +1826,7 @@ static void context_get_rt_size(const struct wined3d_context *context, SIZE *siz
{
const struct wined3d_surface *rt = context->current_rt;
- if (rt->swapchain && rt->swapchain->front_buffer == rt)
+ if (rt->container->swapchain && rt->container->swapchain->front_buffer == rt)
{
RECT window_size;
@@ -2204,7 +2204,7 @@ static void context_validate_onscreen_formats(struct wined3d_context *context,
const struct wined3d_surface *depth_stencil)
{
/* Onscreen surfaces are always in a swapchain */
- struct wined3d_swapchain *swapchain = context->current_rt->swapchain;
+ struct wined3d_swapchain *swapchain = context->current_rt->container->swapchain;
if (context->render_offscreen || !depth_stencil) return;
if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->resource.format)) return;
@@ -2225,7 +2225,7 @@ static DWORD context_generate_rt_mask_no_fbo(const struct wined3d_device *device
{
if (!rt || rt->resource.format->id == WINED3DFMT_NULL)
return 0;
- else if (rt->swapchain)
+ else if (rt->container->swapchain)
return context_generate_rt_mask_from_surface(rt);
else
return context_generate_rt_mask(device->offscreenBuffer);
@@ -3112,11 +3112,11 @@ struct wined3d_context *context_acquire(const struct wined3d_device *device, str
{
context = current_context;
}
- else if (target->swapchain)
+ else if (target->container->swapchain)
{
TRACE("Rendering onscreen.\n");
- context = swapchain_get_context(target->swapchain);
+ context = swapchain_get_context(target->container->swapchain);
}
else
{
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index b7d02bf..1c3f811 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -460,7 +460,7 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c
}
if (wined3d_settings.strict_draw_ordering || (flags & WINED3DCLEAR_TARGET
- && target->swapchain && target->swapchain->front_buffer == target))
+ && target->container->swapchain && target->container->swapchain->front_buffer == target))
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index cb7ee9e..c7a5ada 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -304,15 +304,15 @@ BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
{
struct wined3d_swapchain *swapchain;
- if (resource->type == WINED3D_RTYPE_TEXTURE)
- resource = wined3d_texture_get_sub_resource(wined3d_texture_from_resource(resource), 0);
+ if (resource->type == WINED3D_RTYPE_SURFACE)
+ resource = &surface_from_resource(resource)->container->resource;
- /* Only surface resources can be onscreen. */
- if (resource->type != WINED3D_RTYPE_SURFACE)
+ /* Only texture resources can be onscreen. */
+ if (resource->type != WINED3D_RTYPE_TEXTURE)
return TRUE;
/* Not on a swapchain - must be offscreen */
- if (!(swapchain = wined3d_surface_from_resource(resource)->swapchain))
+ if (!(swapchain = wined3d_texture_from_resource(resource)->swapchain))
return TRUE;
/* The front buffer is always onscreen */
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 6603d46..695afc0 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -115,7 +115,7 @@ void wined3d_surface_destroy(struct wined3d_surface *surface)
void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
unsigned int *width, unsigned int *height)
{
- if (surface->swapchain)
+ if (surface->container->swapchain)
{
/* The drawable size of an onscreen drawable is the surface size.
* (Actually: The window size, but the surface is created in window
@@ -142,14 +142,6 @@ void surface_get_drawable_size(const struct wined3d_surface *surface, const stru
}
}
-void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapchain *swapchain)
-{
- TRACE("surface %p, swapchain %p.\n", surface, swapchain);
-
- surface->swapchain = swapchain;
- wined3d_resource_update_draw_binding(&surface->resource);
-}
-
struct blt_info
{
GLenum binding;
@@ -757,7 +749,7 @@ static void surface_unmap(struct wined3d_surface *surface)
return;
}
- if (surface->swapchain && surface->swapchain->front_buffer == surface)
+ if (surface->container->swapchain && surface->container->swapchain->front_buffer == surface)
surface_load_location(surface, surface->resource.draw_binding);
else if (surface->resource.format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
FIXME("Depth / stencil buffer locking is not implemented.\n");
@@ -976,7 +968,7 @@ static void surface_blt_fbo(const struct wined3d_device *device, enum wined3d_te
if (wined3d_settings.strict_draw_ordering
|| (dst_location == WINED3D_LOCATION_DRAWABLE
- && dst_surface->swapchain->front_buffer == dst_surface))
+ && dst_surface->container->swapchain->front_buffer == dst_surface))
gl_info->gl_ops.gl.p_glFlush();
context_release(context);
@@ -1030,7 +1022,7 @@ static BOOL surface_convert_color_to_float(const struct wined3d_surface *surface
switch (format->id)
{
case WINED3DFMT_P8_UINT:
- palette = surface->swapchain ? surface->swapchain->palette : NULL;
+ palette = surface->container->swapchain ? surface->container->swapchain->palette : NULL;
if (palette)
{
@@ -1299,8 +1291,8 @@ static void gdi_surface_unmap(struct wined3d_surface *surface)
TRACE("surface %p.\n", surface);
/* Tell the swapchain to update the screen. */
- if (surface->swapchain && surface == surface->swapchain->front_buffer)
- x11_copy_to_screen(surface->swapchain, &surface->lockedRect);
+ if (surface->container->swapchain && surface == surface->container->swapchain->front_buffer)
+ x11_copy_to_screen(surface->container->swapchain, &surface->lockedRect);
memset(&surface->lockedRect, 0, sizeof(RECT));
}
@@ -1614,7 +1606,8 @@ static HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
* conflicts with this.
*/
- if (!((blit_supported && surface->swapchain && surface == surface->swapchain->front_buffer))
+ if (!((blit_supported && surface->container->swapchain
+ && surface == surface->container->swapchain->front_buffer))
|| colorkey_active || !use_texturing)
{
format->glFormat = GL_RGBA;
@@ -1982,7 +1975,7 @@ void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, const
GLenum surface_get_gl_buffer(const struct wined3d_surface *surface)
{
- const struct wined3d_swapchain *swapchain = surface->swapchain;
+ const struct wined3d_swapchain *swapchain = surface->container->swapchain;
TRACE("surface %p.\n", surface);
@@ -2122,22 +2115,14 @@ static inline unsigned short float_32_to_16(const float *in)
ULONG CDECL wined3d_surface_incref(struct wined3d_surface *surface)
{
- TRACE("surface %p, swapchain %p, container %p.\n",
- surface, surface->swapchain, surface->container);
-
- if (surface->swapchain)
- return wined3d_swapchain_incref(surface->swapchain);
+ TRACE("surface %p, container %p.\n", surface, surface->container);
return wined3d_texture_incref(surface->container);
}
ULONG CDECL wined3d_surface_decref(struct wined3d_surface *surface)
{
- TRACE("surface %p, swapchain %p, container %p.\n",
- surface, surface->swapchain, surface->container);
-
- if (surface->swapchain)
- return wined3d_swapchain_decref(surface->swapchain);
+ TRACE("surface %p, container %p.\n", surface, surface->container);
return wined3d_texture_decref(surface->container);
}
@@ -3244,10 +3229,10 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI
}
case WINED3D_CT_PALETTED:
- if (surface->swapchain && surface->swapchain->palette)
+ if (surface->container->swapchain && surface->container->swapchain->palette)
{
unsigned int x, y;
- const struct wined3d_palette *palette = surface->swapchain->palette;
+ const struct wined3d_palette *palette = surface->container->swapchain->palette;
for (y = 0; y < height; y++)
{
source = src + pitch * y;
@@ -3691,7 +3676,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
wined3d_gl_min_mip_filter(minMipLookup, filter, WINED3D_TEXF_NONE));
checkGLcall("glTexParameteri");
- if (!src_surface->swapchain || src_surface == src_surface->swapchain->back_buffers[0])
+ if (!src_surface->container->swapchain || src_surface == src_surface->container->swapchain->back_buffers[0])
{
src = backup ? backup : src_surface->container->texture_rgb.name;
}
@@ -3870,7 +3855,7 @@ void surface_translate_drawable_coords(const struct wined3d_surface *surface, HW
{
UINT drawable_height;
- if (surface->swapchain && surface == surface->swapchain->front_buffer)
+ if (surface->container->swapchain && surface == surface->container->swapchain->front_buffer)
{
POINT offset = {0, 0};
RECT windowsize;
@@ -3951,7 +3936,7 @@ static void surface_blt_to_drawable(const struct wined3d_device *device,
device->blitter->unset_shader(context->gl_info);
if (wined3d_settings.strict_draw_ordering
- || (dst_surface->swapchain && dst_surface->swapchain->front_buffer == dst_surface))
+ || (dst_surface->container->swapchain && dst_surface->container->swapchain->front_buffer == dst_surface))
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
@@ -3992,7 +3977,7 @@ static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RE
return WINED3DERR_INVALIDCALL;
}
- dst_swapchain = dst_surface->swapchain;
+ dst_swapchain = dst_surface->container->swapchain;
if (src_surface)
{
@@ -4002,7 +3987,7 @@ static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RE
return WINED3DERR_INVALIDCALL;
}
- src_swapchain = src_surface->swapchain;
+ src_swapchain = src_surface->container->swapchain;
}
else
{
@@ -5728,11 +5713,11 @@ HRESULT CDECL wined3d_surface_blt(struct wined3d_surface *dst_surface, const REC
}
if (src_surface)
- src_swapchain = src_surface->swapchain;
+ src_swapchain = src_surface->container->swapchain;
else
src_swapchain = NULL;
- dst_swapchain = dst_surface->swapchain;
+ dst_swapchain = dst_surface->container->swapchain;
/* This isn't strictly needed. FBO blits for example could deal with
* cross-swapchain blits by first downloading the source to a texture
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 1582193..609b862 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -40,7 +40,7 @@ static void swapchain_cleanup(struct wined3d_swapchain *swapchain)
* is the last buffer to be destroyed, FindContext() depends on that. */
if (swapchain->front_buffer)
{
- surface_set_swapchain(swapchain->front_buffer, NULL);
+ wined3d_texture_set_swapchain(swapchain->front_buffer->container, NULL);
if (wined3d_surface_decref(swapchain->front_buffer))
WARN("Something's still holding the front buffer (%p).\n", swapchain->front_buffer);
swapchain->front_buffer = NULL;
@@ -52,7 +52,7 @@ static void swapchain_cleanup(struct wined3d_swapchain *swapchain)
while (i--)
{
- surface_set_swapchain(swapchain->back_buffers[i], NULL);
+ wined3d_texture_set_swapchain(swapchain->back_buffers[i]->container, NULL);
if (wined3d_surface_decref(swapchain->back_buffers[i]))
WARN("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
}
@@ -854,7 +854,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
goto err;
}
- surface_set_swapchain(swapchain->front_buffer, swapchain);
+ wined3d_texture_set_swapchain(swapchain->front_buffer->container, swapchain);
if (!(device->wined3d->flags & WINED3D_NO3D))
{
surface_validate_location(swapchain->front_buffer, WINED3D_LOCATION_DRAWABLE);
@@ -964,7 +964,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
swapchain->desc.backbuffer_count = i;
goto err;
}
- surface_set_swapchain(swapchain->back_buffers[i], swapchain);
+ wined3d_texture_set_swapchain(swapchain->back_buffers[i]->container, swapchain);
}
}
@@ -1005,7 +1005,7 @@ err:
{
if (swapchain->back_buffers[i])
{
- surface_set_swapchain(swapchain->back_buffers[i], NULL);
+ wined3d_texture_set_swapchain(swapchain->back_buffers[i]->container, NULL);
wined3d_surface_decref(swapchain->back_buffers[i]);
}
}
@@ -1025,7 +1025,7 @@ err:
if (swapchain->front_buffer)
{
- surface_set_swapchain(swapchain->front_buffer, NULL);
+ wined3d_texture_set_swapchain(swapchain->front_buffer->container, NULL);
wined3d_surface_decref(swapchain->front_buffer);
}
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 060dabc..b90a80f 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -145,6 +145,19 @@ static void wined3d_texture_cleanup(struct wined3d_texture *texture)
resource_cleanup(&texture->resource);
}
+void wined3d_texture_set_swapchain(struct wined3d_texture *texture, struct wined3d_swapchain *swapchain)
+{
+ unsigned int i, count;
+
+ texture->swapchain = swapchain;
+
+ count = texture->level_count * texture->layer_count;
+ for (i = 0; i < count; ++i)
+ {
+ wined3d_resource_update_draw_binding(wined3d_texture_get_sub_resource(texture, i));
+ }
+}
+
void wined3d_texture_set_dirty(struct wined3d_texture *texture)
{
texture->flags &= ~(WINED3D_TEXTURE_RGB_VALID | WINED3D_TEXTURE_SRGB_VALID);
@@ -476,8 +489,14 @@ void wined3d_texture_apply_state_changes(struct wined3d_texture *texture,
ULONG CDECL wined3d_texture_incref(struct wined3d_texture *texture)
{
- ULONG refcount = InterlockedIncrement(&texture->resource.ref);
+ ULONG refcount;
+
+ TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
+
+ if (texture->swapchain)
+ return wined3d_swapchain_incref(texture->swapchain);
+ refcount = InterlockedIncrement(&texture->resource.ref);
TRACE("%p increasing refcount to %u.\n", texture, refcount);
return refcount;
@@ -485,8 +504,14 @@ ULONG CDECL wined3d_texture_incref(struct wined3d_texture *texture)
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
{
- ULONG refcount = InterlockedDecrement(&texture->resource.ref);
+ ULONG refcount;
+
+ TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
+
+ if (texture->swapchain)
+ return wined3d_swapchain_decref(texture->swapchain);
+ refcount = InterlockedDecrement(&texture->resource.ref);
TRACE("%p decreasing refcount to %u.\n", texture, refcount);
if (!refcount)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 086d13c..3832815 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2113,6 +2113,7 @@ struct wined3d_texture
const struct wined3d_texture_ops *texture_ops;
struct gl_texture texture_rgb, texture_srgb;
struct wined3d_resource **sub_resources;
+ struct wined3d_swapchain *swapchain;
UINT layer_count;
UINT level_count;
float pow2_matrix[16];
@@ -2153,6 +2154,8 @@ void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
void wined3d_texture_load(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_set_dirty(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
+void wined3d_texture_set_swapchain(struct wined3d_texture *texture,
+ struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
#define WINED3D_VFLAG_ALLOCATED 0x00000001
#define WINED3D_VFLAG_SRGB_ALLOCATED 0x00000002
@@ -2234,7 +2237,6 @@ struct wined3d_surface
struct wined3d_resource resource;
const struct wined3d_surface_ops *surface_ops;
struct wined3d_texture *container;
- struct wined3d_swapchain *swapchain;
void *user_memory;
DWORD locations;
@@ -2303,7 +2305,6 @@ void surface_prepare_texture(struct wined3d_surface *surface,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
const struct wined3d_surface *rt) DECLSPEC_HIDDEN;
-void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN;
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
--
1.7.10.4
More information about the wine-patches
mailing list