[Bf-blender-cvs] [7fed213ba40] master: Revert "Compositor: Support backdrop offset for the Viewer node"

Brecht Van Lommel noreply at git.blender.org
Sat Mar 19 00:42:16 CET 2022


Commit: 7fed213ba40d6f36282b09245ea459b22d4f6c5b
Author: Brecht Van Lommel
Date:   Sat Mar 19 00:36:07 2022 +0100
Branches: master
https://developer.blender.org/rB7fed213ba40d6f36282b09245ea459b22d4f6c5b

Revert "Compositor: Support backdrop offset for the Viewer node"

This reverts commit 33409f9f1cd42e899f2706fe7878e5e89b50d617, as it breaks
panning in the image editor.

Fixes T96543

===================================================================

M	source/blender/compositor/operations/COM_ViewerOperation.cc
M	source/blender/compositor/operations/COM_ViewerOperation.h
M	source/blender/draw/engines/image/image_drawing_mode.hh
M	source/blender/draw/engines/image/image_engine.cc
M	source/blender/draw/engines/image/image_instance_data.hh
M	source/blender/draw/engines/image/image_space.hh
M	source/blender/draw/engines/image/image_space_image.hh
M	source/blender/draw/engines/image/image_space_node.hh
M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_gizmo.cc
M	source/blender/editors/space_node/space_node.cc
M	source/blender/makesdna/DNA_image_types.h

===================================================================

diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cc b/source/blender/compositor/operations/COM_ViewerOperation.cc
index 7f0eaecfff7..bc7e08ee98a 100644
--- a/source/blender/compositor/operations/COM_ViewerOperation.cc
+++ b/source/blender/compositor/operations/COM_ViewerOperation.cc
@@ -10,10 +10,10 @@
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
-#include "DNA_node_types.h"
-
 namespace blender::compositor {
 
+static int MAX_VIEWER_TRANSLATION_PADDING = 12000;
+
 ViewerOperation::ViewerOperation()
 {
   this->set_image(nullptr);
@@ -137,12 +137,23 @@ void ViewerOperation::init_image()
     return;
   }
 
-  if (ibuf->x != get_width() || ibuf->y != get_height()) {
+  int padding_x = abs(canvas_.xmin) * 2;
+  int padding_y = abs(canvas_.ymin) * 2;
+  if (padding_x > MAX_VIEWER_TRANSLATION_PADDING) {
+    padding_x = MAX_VIEWER_TRANSLATION_PADDING;
+  }
+  if (padding_y > MAX_VIEWER_TRANSLATION_PADDING) {
+    padding_y = MAX_VIEWER_TRANSLATION_PADDING;
+  }
+
+  display_width_ = get_width() + padding_x;
+  display_height_ = get_height() + padding_y;
+  if (ibuf->x != display_width_ || ibuf->y != display_height_) {
     imb_freerectImBuf(ibuf);
     imb_freerectfloatImBuf(ibuf);
     IMB_freezbuffloatImBuf(ibuf);
-    ibuf->x = get_width();
-    ibuf->y = get_height();
+    ibuf->x = display_width_;
+    ibuf->y = display_height_;
     /* zero size can happen if no image buffers exist to define a sensible resolution */
     if (ibuf->x > 0 && ibuf->y > 0) {
       imb_addrectfloatImBuf(ibuf);
@@ -176,13 +187,11 @@ void ViewerOperation::update_image(const rcti *rect)
     return;
   }
 
-  image_->display_offset_x = canvas_.xmin;
-  image_->display_offset_y = canvas_.ymin;
   float *buffer = output_buffer_;
   IMB_partial_display_buffer_update(ibuf_,
                                     buffer,
                                     nullptr,
-                                    get_width(),
+                                    display_width_,
                                     0,
                                     0,
                                     view_settings_,
@@ -215,23 +224,32 @@ void ViewerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output),
     return;
   }
 
+  const int offset_x = area.xmin + (canvas_.xmin > 0 ? canvas_.xmin * 2 : 0);
+  const int offset_y = area.ymin + (canvas_.ymin > 0 ? canvas_.ymin * 2 : 0);
   MemoryBuffer output_buffer(
-      output_buffer_, COM_DATA_TYPE_COLOR_CHANNELS, get_width(), get_height());
+      output_buffer_, COM_DATA_TYPE_COLOR_CHANNELS, display_width_, display_height_);
   const MemoryBuffer *input_image = inputs[0];
-  output_buffer.copy_from(input_image, area);
+  output_buffer.copy_from(input_image, area, offset_x, offset_y);
   if (use_alpha_input_) {
     const MemoryBuffer *input_alpha = inputs[1];
-    output_buffer.copy_from(input_alpha, area, 0, COM_DATA_TYPE_VALUE_CHANNELS, 3);
+    output_buffer.copy_from(
+        input_alpha, area, 0, COM_DATA_TYPE_VALUE_CHANNELS, offset_x, offset_y, 3);
   }
 
   if (depth_buffer_) {
     MemoryBuffer depth_buffer(
-        depth_buffer_, COM_DATA_TYPE_VALUE_CHANNELS, get_width(), get_height());
+        depth_buffer_, COM_DATA_TYPE_VALUE_CHANNELS, display_width_, display_height_);
     const MemoryBuffer *input_depth = inputs[2];
-    depth_buffer.copy_from(input_depth, area);
+    depth_buffer.copy_from(input_depth, area, offset_x, offset_y);
   }
 
-  update_image(&area);
+  rcti display_area;
+  BLI_rcti_init(&display_area,
+                offset_x,
+                offset_x + BLI_rcti_size_x(&area),
+                offset_y,
+                offset_y + BLI_rcti_size_y(&area));
+  update_image(&display_area);
 }
 
 void ViewerOperation::clear_display_buffer()
diff --git a/source/blender/compositor/operations/COM_ViewerOperation.h b/source/blender/compositor/operations/COM_ViewerOperation.h
index ed9e5871eae..1ad6cc51269 100644
--- a/source/blender/compositor/operations/COM_ViewerOperation.h
+++ b/source/blender/compositor/operations/COM_ViewerOperation.h
@@ -35,6 +35,9 @@ class ViewerOperation : public MultiThreadedOperation {
   SocketReader *alpha_input_;
   SocketReader *depth_input_;
 
+  int display_width_;
+  int display_height_;
+
  public:
   ViewerOperation();
   void init_execution() override;
diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh
index af3ec24d085..46482ab6668 100644
--- a/source/blender/draw/engines/image/image_drawing_mode.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode.hh
@@ -129,6 +129,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
   {
     GPUShader *shader = IMAGE_shader_depth_get();
     DRWShadingGroup *shgrp = DRW_shgroup_create(shader, instance_data.passes.depth_pass);
+
     float image_mat[4][4];
     unit_m4(image_mat);
 
diff --git a/source/blender/draw/engines/image/image_engine.cc b/source/blender/draw/engines/image/image_engine.cc
index 09efaea3e71..e972d21cda4 100644
--- a/source/blender/draw/engines/image/image_engine.cc
+++ b/source/blender/draw/engines/image/image_engine.cc
@@ -99,11 +99,8 @@ class ImageEngine {
     /* Setup the matrix to go from screen UV coordinates to UV texture space coordinates. */
     float image_resolution[2] = {image_buffer ? image_buffer->x : 1024.0f,
                                  image_buffer ? image_buffer->y : 1024.0f};
-    float image_display_offset[2] = {(float)instance_data->image->display_offset_x,
-                                     (float)instance_data->image->display_offset_y};
-    space->init_ss_to_texture_matrix(draw_ctx->region,
-                                     image_display_offset,
-                                     image_resolution, instance_data->ss_to_texture);
+    space->init_ss_to_texture_matrix(
+        draw_ctx->region, image_resolution, instance_data->ss_to_texture);
 
     const Scene *scene = DRW_context_state_get()->scene;
     instance_data->sh_params.update(space.get(), scene, instance_data->image, image_buffer);
diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh
index 02ca86312c6..682b93a80b3 100644
--- a/source/blender/draw/engines/image/image_instance_data.hh
+++ b/source/blender/draw/engines/image/image_instance_data.hh
@@ -21,7 +21,7 @@
 /**
  * \brief max allowed textures to use by the ScreenSpaceDrawingMode.
  *
- * 1 texture is used to reduce uploading screen space textures when translating the image.
+ * 4 textures are used to reduce uploading screen space textures when translating the image.
  */
 constexpr int SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN = 1;
 
diff --git a/source/blender/draw/engines/image/image_space.hh b/source/blender/draw/engines/image/image_space.hh
index a2f923a7118..7a11d14b567 100644
--- a/source/blender/draw/engines/image/image_space.hh
+++ b/source/blender/draw/engines/image/image_space.hh
@@ -77,7 +77,6 @@ class AbstractSpaceAccessor {
    * (0..1) to texture space UV coordinates.
    */
   virtual void init_ss_to_texture_matrix(const ARegion *region,
-                                         const float image_display_offset[2],
                                          const float image_resolution[2],
                                          float r_uv_to_texture[4][4]) const = 0;
 
diff --git a/source/blender/draw/engines/image/image_space_image.hh b/source/blender/draw/engines/image/image_space_image.hh
index 264129e0728..40aa117514c 100644
--- a/source/blender/draw/engines/image/image_space_image.hh
+++ b/source/blender/draw/engines/image/image_space_image.hh
@@ -148,8 +148,7 @@ class SpaceImageAccessor : public AbstractSpaceAccessor {
   }
 
   void init_ss_to_texture_matrix(const ARegion *region,
-                                 const float image_display_offset[2],
-                                 const float image_resolution[2],
+                                 const float UNUSED(image_resolution[2]),
                                  float r_uv_to_texture[4][4]) const override
   {
     unit_m4(r_uv_to_texture);
diff --git a/source/blender/draw/engines/image/image_space_node.hh b/source/blender/draw/engines/image/image_space_node.hh
index 4057f7b78cf..6f38dcb86aa 100644
--- a/source/blender/draw/engines/image/image_space_node.hh
+++ b/source/blender/draw/engines/image/image_space_node.hh
@@ -99,7 +99,6 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
    * screen.
    */
   void init_ss_to_texture_matrix(const ARegion *region,
-                                 const float image_display_offset[2],
                                  const float image_resolution[2],
                                  float r_uv_to_texture[4][4]) const override
   {
@@ -108,10 +107,10 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
     mul_v2_v2fl(display_resolution, image_resolution, snode->zoom);
     const float scale_x = display_resolution[0] / region->winx;
     const float scale_y = display_resolution[1] / region->winy;
-    const float translate_x = ((region->winx - display_resolution[0]) * 0.5f + snode->xof + image_display_offset[0]) /
-                          region->winx ;
-    const float translate_y = ((region->winy - display_resolution[1]) * 0.5f + snode->yof + image_display_offset[1]) /
-                          region->winy;
+    const float translate_x = ((region->winx - display_resolution[0]) * 0.5f + snode->xof) /
+                              region->winx;
+    const float translate_y = ((region->winy - display_resolution[1]) * 0.5f + snode->yof) /
+                              region->winy;
 
     r_uv_to_texture[0][0] = scale_x;
     r_uv_to_texture[1][1] = scale_y;
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index ad647cf019d..365a17c0a04 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -1499,10 +1499,8 @@ void draw_nodespace_back_pix(const bContext &C,
   if (ibuf) {
     /* somehow the offset has to be calculated inverse */
     wmOrtho2_region_pixelspace(&region);
-    c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list