[TTVD] Fix calculation of geometry when crop is applied 00/314700/4
authorJakub Gajownik <j.gajownik2@samsung.com>
Fri, 5 Jul 2024 15:19:06 +0000 (17:19 +0200)
committerBot Blink <blinkbot@samsung.com>
Wed, 17 Jul 2024 15:10:44 +0000 (15:10 +0000)
When video frame visible rect is cropped (e.g video
capture), we should also apply this during overlay
rendering. At the rendering level crop rect also determines
what region of source image should be rendered, however
additional damage might be applied. To properly calculate
what is the target region, we should resize it according
to how much crop rect is affected by given damage.

Before this patch geometry was calculated wrongly, it
resulted at video capture that had crop applied was too
small and in incorrect possition on screen.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-532
Change-Id: I3f1390c6e76932063fb70def7c601bfa3acf8ea3
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
tizen_src/chromium_impl/ui/ozone/platform/efl/output_surface_impl.cc

index e3b00d7d6f3dcb45ea3fab04d8d376c3257ee16c..e7fd54800b680bea80a99cec6e8f30b14bb0bdaa 100644 (file)
@@ -58,24 +58,27 @@ gfx::RectF ScaleRect(const gfx::RectF& source, const gfx::RectF& scaling) {
 
 gfx::RectF ApplyDamageToBoundsRect(const gfx::RectF& bounds_rect,
                                    const gfx::Rect& damage_rect,
-                                   const gfx::Size& image_size,
+                                   const gfx::Rect& crop_rect,
                                    gfx::OverlayTransform overlay_transform) {
   auto bounds_damage = damage_rect;
+  bounds_damage.set_x(damage_rect.x() - crop_rect.x());
+  bounds_damage.set_y(damage_rect.y() - crop_rect.y());
+
   if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_180 ||
       overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_270 ||
       overlay_transform == gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL) {
-    bounds_damage.set_x(image_size.width() - bounds_damage.x() -
+    bounds_damage.set_x(crop_rect.width() - bounds_damage.x() -
                         bounds_damage.width());
   }
 
   if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
       overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_180 ||
       overlay_transform == gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL) {
-    bounds_damage.set_y(image_size.height() - bounds_damage.y() -
+    bounds_damage.set_y(crop_rect.height() - bounds_damage.y() -
                         bounds_damage.height());
   }
 
-  auto scaling = NormalizedRect(bounds_damage, image_size);
+  auto scaling = NormalizedRect(bounds_damage, crop_rect.size());
   if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
       overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_270) {
     scaling.Transpose();
@@ -99,7 +102,13 @@ gfx::RectF ApplyDamageToCropRect(const gfx::RectF& crop_rect,
                         bounds_damage.height());
   }
 
-  auto scaling = NormalizedRect(bounds_damage, image_size);
+  const gfx::Rect cropped_rect_in_pixels(gfx::ToNearestRect(
+      gfx::ScaleRect(crop_rect, image_size.width(), image_size.height())));
+
+  bounds_damage.set_x(bounds_damage.x() - cropped_rect_in_pixels.x());
+  bounds_damage.set_y(bounds_damage.y() - cropped_rect_in_pixels.y());
+
+  auto scaling = NormalizedRect(bounds_damage, cropped_rect_in_pixels.size());
   return ScaleRect(crop_rect, scaling);
 }
 
@@ -112,12 +121,16 @@ Geometry CalculateGeometry(gfx::Size image_size,
                            gfx::Rect damage_rect,
                            gfx::OverlayTransform overlay_transform,
                            bool inverse_clip_damage_for_180_rotation) {
+  const gfx::Rect cropped_rect_in_pixels(gfx::ToNearestRect(
+      gfx::ScaleRect(crop_rect, image_size.width(), image_size.height())));
+
   // Step 1. Fix damage so it fits with the image coordinates.
-  damage_rect.Intersect(gfx::Rect(image_size));
+  damage_rect.Intersect(cropped_rect_in_pixels);
 
-  // Step 2. Apply damage for bounds rect.
-  bounds_rect = ApplyDamageToBoundsRect(bounds_rect, damage_rect, image_size,
-                                        overlay_transform);
+  // Step 2. Apply damage for bounds rect. Bounds rect should be resized
+  //         according how much of |picture_rect| is affected by damage.
+  bounds_rect = ApplyDamageToBoundsRect(
+      bounds_rect, damage_rect, cropped_rect_in_pixels, overlay_transform);
 
   // Step 3. Apply damage to the crop rect.
   crop_rect = ApplyDamageToCropRect(crop_rect, damage_rect, image_size,