st/mesa: unify window-system renderbuffer initialization
authorMarek Olšák <marek.olsak@amd.com>
Tue, 8 Jan 2019 15:44:29 +0000 (10:44 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 9 Jan 2019 16:08:44 +0000 (11:08 -0500)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/state_tracker/st_cb_eglimage.c
src/mesa/state_tracker/st_manager.c
src/mesa/state_tracker/st_manager.h

index d6b93c3dbe8bdba18f161ff8f9c0140f81e7f48e..f79df5a38ca56285d0bd505d7c9d22a5687032b6 100644 (file)
@@ -159,20 +159,11 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
       if (!ps)
          return;
 
-      strb->Base.Width = ps->width;
-      strb->Base.Height = ps->height;
       strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
       strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format);
       strb->Base.InternalFormat = strb->Base._BaseFormat;
 
-      struct pipe_surface **psurf =
-         util_format_is_srgb(ps->format) ? &strb->surface_srgb :
-                                           &strb->surface_linear;
-
-      pipe_surface_reference(psurf, ps);
-      strb->surface = *psurf;
-      pipe_resource_reference(&strb->texture, ps->texture);
-
+      st_set_ws_renderbuffer_surface(strb, ps);
       pipe_surface_reference(&ps, NULL);
    }
 }
index 73729d745455916352ab0fa7f5c4d45c264b2198..7a3d9777101ce826f6519318b497bab013546d9c 100644 (file)
@@ -173,6 +173,26 @@ st_context_validate(struct st_context *st,
 }
 
 
+void
+st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb,
+                               struct pipe_surface *surf)
+{
+   pipe_surface_reference(&strb->surface_srgb, NULL);
+   pipe_surface_reference(&strb->surface_linear, NULL);
+
+   if (util_format_is_srgb(surf->format))
+      pipe_surface_reference(&strb->surface_srgb, surf);
+   else
+      pipe_surface_reference(&strb->surface_linear, surf);
+
+   strb->surface = surf; /* just assign, don't ref */
+   pipe_resource_reference(&strb->texture, surf->texture);
+
+   strb->Base.Width = surf->width;
+   strb->Base.Height = surf->height;
+}
+
+
 /**
  * Validate a framebuffer to make sure up-to-date pipe_textures are used.
  * The context is only used for creating pipe surfaces and for calling
@@ -234,21 +254,11 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
       u_surface_default_template(&surf_tmpl, textures[i]);
       ps = st->pipe->create_surface(st->pipe, textures[i], &surf_tmpl);
       if (ps) {
-         struct pipe_surface **psurf =
-            util_format_is_srgb(ps->format) ? &strb->surface_srgb :
-                                              &strb->surface_linear;
-
-         pipe_surface_reference(psurf, ps);
-         strb->surface = *psurf;
-         pipe_resource_reference(&strb->texture, ps->texture);
-         /* ownership transfered */
+         st_set_ws_renderbuffer_surface(strb, ps);
          pipe_surface_reference(&ps, NULL);
 
          changed = TRUE;
 
-         strb->Base.Width = strb->surface->width;
-         strb->Base.Height = strb->surface->height;
-
          width = strb->Base.Width;
          height = strb->Base.Height;
       }
index 162dcc2ca57bce33322623d17968566bd2a7ef52..581e858229b0bae164b6caea753d15696e977cc6 100644 (file)
@@ -35,6 +35,8 @@
 struct st_context;
 struct st_framebuffer;
 struct st_framebuffer_interface;
+struct st_renderbuffer;
+struct pipe_surface;
 
 void
 st_manager_flush_frontbuffer(struct st_context *st);
@@ -56,4 +58,8 @@ st_framebuffer_interface_destroy(struct st_framebuffer_interface *stfbi);
 void
 st_manager_flush_swapbuffers(void);
 
+void
+st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb,
+                               struct pipe_surface *surf);
+
 #endif /* ST_MANAGER_H */