[PATCH 5/5] wined3d: Replace surface_is_offscreen() with wined3d_resource_is_offscreen().

Henri Verbeet hverbeet at codeweavers.com
Tue Aug 19 02:22:29 CDT 2014


Introducing rendertarget views will (eventually) allow rendering to 3D
textures and buffers.
---
 dlls/wined3d/arb_program_shader.c |    4 ++--
 dlls/wined3d/context.c            |    8 +++----
 dlls/wined3d/resource.c           |   24 +++++++++++++++++++
 dlls/wined3d/surface.c            |   47 +++++++++++--------------------------
 dlls/wined3d/wined3d_private.h    |    5 ++--
 5 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 9755ffb..9e1de57 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -7645,7 +7645,7 @@ HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter,
     if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
             && (src_surface->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_DRAWABLE))
             == WINED3D_LOCATION_DRAWABLE
-            && !surface_is_offscreen(src_surface))
+            && !wined3d_resource_is_offscreen(&src_surface->resource))
     {
         /* Without FBO blits transferring from the drawable to the texture is
          * expensive, because we have to flip the data in sysmem. Since we can
@@ -7662,7 +7662,7 @@ HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter,
 
     context_apply_blit_state(context, device);
 
-    if (!surface_is_offscreen(dst_surface))
+    if (!wined3d_resource_is_offscreen(&dst_surface->resource))
         surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect);
 
     arbfp_blit_set(device->blit_priv, context, src_surface);
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 9c04cd2..fc10a57 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1590,7 +1590,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
     ret->current_rt = target;
     ret->tid = GetCurrentThreadId();
 
-    ret->render_offscreen = surface_is_offscreen(target);
+    ret->render_offscreen = wined3d_resource_is_offscreen(&target->resource);
     ret->draw_buffers_mask = context_generate_rt_mask(GL_BACK);
     ret->valid = 1;
 
@@ -2316,7 +2316,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
         {
             context_validate_onscreen_formats(context, fb->depth_stencil);
 
-            if (!rt_count || surface_is_offscreen(rts[0]))
+            if (!rt_count || wined3d_resource_is_offscreen(&rts[0]->resource))
             {
                 for (i = 0; i < rt_count; ++i)
                 {
@@ -2349,7 +2349,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
         }
     }
     else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
-            && (!rt_count || surface_is_offscreen(rts[0])))
+            && (!rt_count || wined3d_resource_is_offscreen(&rts[0]->resource)))
     {
         for (i = 0; i < rt_count; ++i)
         {
@@ -3030,7 +3030,7 @@ static void context_setup_target(struct wined3d_context *context, struct wined3d
 {
     BOOL old_render_offscreen = context->render_offscreen, render_offscreen;
 
-    render_offscreen = surface_is_offscreen(target);
+    render_offscreen = wined3d_resource_is_offscreen(&target->resource);
     if (context->current_rt == target && render_offscreen == old_render_offscreen) return;
 
     /* To compensate the lack of format switching with some offscreen rendering methods and on onscreen buffers
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 2f44d36..dd31cb6 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -299,3 +299,27 @@ GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags)
         return GL_WRITE_ONLY_ARB;
     return GL_READ_WRITE_ARB;
 }
+
+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);
+
+    /* Only surface resources can be onscreen. */
+    if (resource->type != WINED3D_RTYPE_SURFACE)
+        return TRUE;
+
+    /* Not on a swapchain - must be offscreen */
+    if (!(swapchain = wined3d_surface_from_resource(resource)->swapchain))
+        return TRUE;
+
+    /* The front buffer is always onscreen */
+    if (resource == &swapchain->front_buffer->container->resource)
+        return FALSE;
+
+    /* If the swapchain is rendered to an FBO, the backbuffer is
+     * offscreen, otherwise onscreen */
+    return swapchain->render_to_fbo;
+}
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 14d9133..3110e56 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -114,7 +114,7 @@ void wined3d_surface_destroy(struct wined3d_surface *surface)
 
 void surface_update_draw_binding(struct wined3d_surface *surface)
 {
-    if (!surface_is_offscreen(surface) || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
+    if (!wined3d_resource_is_offscreen(&surface->resource) || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
         surface->resource.draw_binding = WINED3D_LOCATION_DRAWABLE;
     else if (surface->resource.multisample_type)
         surface->resource.draw_binding = WINED3D_LOCATION_RB_MULTISAMPLE;
@@ -1516,7 +1516,8 @@ static void surface_upload_data(struct wined3d_surface *surface, const struct wi
 
         if (srgb)
             internal = format->glGammaInternal;
-        else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(surface))
+        else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET
+                && wined3d_resource_is_offscreen(&surface->resource))
             internal = format->rtInternal;
         else
             internal = format->glInternal;
@@ -1858,17 +1859,12 @@ static void surface_allocate_surface(struct wined3d_surface *surface, const stru
     GLenum internal;
 
     if (srgb)
-    {
         internal = format->glGammaInternal;
-    }
-    else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(surface))
-    {
+    else if (surface->resource.usage & WINED3DUSAGE_RENDERTARGET
+            && wined3d_resource_is_offscreen(&surface->resource))
         internal = format->rtInternal;
-    }
     else
-    {
         internal = format->glInternal;
-    }
 
     if (!internal)
         FIXME("No GL internal format for format %s.\n", debug_d3dformat(format->id));
@@ -3056,7 +3052,7 @@ static void read_from_framebuffer(struct wined3d_surface *surface, DWORD dst_loc
      * There is no need to keep track of the current read buffer or reset it, every part of the code
      * that reads sets the read buffer as desired.
      */
-    if (surface_is_offscreen(surface))
+    if (wined3d_resource_is_offscreen(&surface->resource))
     {
         /* Mapping the primary render target which is not on a swapchain.
          * Read from the back buffer. */
@@ -3155,7 +3151,7 @@ void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb)
 
     TRACE("Reading back offscreen render target %p.\n", surface);
 
-    if (surface_is_offscreen(surface))
+    if (wined3d_resource_is_offscreen(&surface->resource))
         gl_info->gl_ops.gl.p_glReadBuffer(device->offscreenBuffer);
     else
         gl_info->gl_ops.gl.p_glReadBuffer(surface_get_gl_buffer(surface));
@@ -3522,7 +3518,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc
 
     /* Bind the target texture */
     context_bind_texture(context, dst_surface->container->target, dst_surface->container->texture_rgb.name);
-    if (surface_is_offscreen(src_surface))
+    if (wined3d_resource_is_offscreen(&src_surface->resource))
     {
         TRACE("Reading from an offscreen target\n");
         upsidedown = !upsidedown;
@@ -3628,7 +3624,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
     context_apply_blit_state(context, device);
     wined3d_texture_load(dst_surface->container, context, FALSE);
 
-    src_offscreen = surface_is_offscreen(src_surface);
+    src_offscreen = wined3d_resource_is_offscreen(&src_surface->resource);
     noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
     if (!noBackBufferBackup && !src_surface->container->texture_rgb.name)
     {
@@ -3927,7 +3923,7 @@ static void surface_blt_to_drawable(const struct wined3d_device *device,
     /* Activate the destination context, set it up for blitting */
     context_apply_blit_state(context, device);
 
-    if (!surface_is_offscreen(dst_surface))
+    if (!wined3d_resource_is_offscreen(&dst_surface->resource))
         surface_translate_drawable_coords(dst_surface, context->win_handle, &dst_rect);
 
     device->blitter->set_shader(device->blit_priv, context, src_surface);
@@ -4527,7 +4523,8 @@ static HRESULT surface_load_drawable(struct wined3d_surface *surface,
 {
     RECT r;
 
-    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && surface_is_offscreen(surface))
+    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
+            && wined3d_resource_is_offscreen(&surface->resource))
     {
         ERR("Trying to load offscreen surface into WINED3D_LOCATION_DRAWABLE.\n");
         return WINED3DERR_INVALIDCALL;
@@ -4555,7 +4552,7 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
     BYTE *mem = NULL;
 
     if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
-            && surface_is_offscreen(surface)
+            && wined3d_resource_is_offscreen(&surface->resource)
             && (surface->locations & WINED3D_LOCATION_DRAWABLE))
     {
         surface_load_fb_texture(surface, srgb);
@@ -4819,22 +4816,6 @@ HRESULT surface_load_location(struct wined3d_surface *surface, DWORD location)
     return WINED3D_OK;
 }
 
-BOOL surface_is_offscreen(const struct wined3d_surface *surface)
-{
-    struct wined3d_swapchain *swapchain;
-
-    /* Not on a swapchain - must be offscreen */
-    if (!(swapchain = surface->swapchain))
-        return TRUE;
-
-    /* The front buffer is always onscreen */
-    if (surface == swapchain->front_buffer) return FALSE;
-
-    /* If the swapchain is rendered to an FBO, the backbuffer is
-     * offscreen, otherwise onscreen */
-    return swapchain->render_to_fbo;
-}
-
 static HRESULT ffp_blit_alloc(struct wined3d_device *device) { return WINED3D_OK; }
 /* Context activation is done by the caller. */
 static void ffp_blit_free(struct wined3d_device *device) { }
@@ -5857,7 +5838,7 @@ HRESULT CDECL wined3d_surface_blt(struct wined3d_surface *dst_surface, const REC
 
                     if (SUCCEEDED(surface_upload_from_surface(dst_surface, &dst_point, src_surface, &src_rect)))
                     {
-                        if (!surface_is_offscreen(dst_surface))
+                        if (!wined3d_resource_is_offscreen(&dst_surface->resource))
                             surface_load_location(dst_surface, dst_surface->resource.draw_binding);
                         return WINED3D_OK;
                     }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9566066..118b5c8 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2061,10 +2061,10 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
-DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource,
-        DWORD flags) DECLSPEC_HIDDEN;
 GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
 GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
+BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
+DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource, DWORD flags) DECLSPEC_HIDDEN;
 
 /* Tests show that the start address of resources is 32 byte aligned */
 #define RESOURCE_ALIGNMENT 16
@@ -2290,7 +2290,6 @@ GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) DECLSPEC_HID
 void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
         unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
 void surface_invalidate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
-BOOL surface_is_offscreen(const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
 void surface_load(struct wined3d_surface *surface, BOOL srgb) DECLSPEC_HIDDEN;
 void surface_load_ds_location(struct wined3d_surface *surface,
         struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
-- 
1.7.10.4




More information about the wine-patches mailing list