Re: [RFC PATCH 08/11] exynos4-is: convert g/s_crop to g/s_selection

2018-11-02 Thread Sylwester Nawrocki
On Fri, 5 Oct 2018 at 09:49, Hans Verkuil  wrote:
>
> From: Hans Verkuil 
>
> Replace g/s_crop by g/s_selection and set the V4L2_FL_QUIRK_INVERTED_CROP
> flag since this is one of the old drivers that predates the selection
> API. Those old drivers allowed g_crop when it really shouldn't have since
> g_crop returns a compose rectangle instead of a crop rectangle for the
> CAPTURE stream, and vice versa for the OUTPUT stream.
>
> Also drop the now unused vidioc_cropcap.
>
> Signed-off-by: Hans Verkuil 

Reviewed-by: Sylwester Nawrocki 


[RFC PATCH 08/11] exynos4-is: convert g/s_crop to g/s_selection

2018-10-05 Thread Hans Verkuil
From: Hans Verkuil 

Replace g/s_crop by g/s_selection and set the V4L2_FL_QUIRK_INVERTED_CROP
flag since this is one of the old drivers that predates the selection
API. Those old drivers allowed g_crop when it really shouldn't have since
g_crop returns a compose rectangle instead of a crop rectangle for the
CAPTURE stream, and vice versa for the OUTPUT stream.

Also drop the now unused vidioc_cropcap.

Signed-off-by: Hans Verkuil 
---
 drivers/media/platform/exynos4-is/fimc-core.h |   6 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c  | 130 ++
 2 files changed, 79 insertions(+), 57 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-core.h 
b/drivers/media/platform/exynos4-is/fimc-core.h
index 82d514df97f0..9f751a5efd64 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.h
+++ b/drivers/media/platform/exynos4-is/fimc-core.h
@@ -596,12 +596,14 @@ static inline struct fimc_frame *ctx_get_frame(struct 
fimc_ctx *ctx,
 {
struct fimc_frame *frame;
 
-   if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
+   if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
+   type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
if (fimc_ctx_state_is_set(FIMC_CTX_M2M, ctx))
frame = >s_frame;
else
return ERR_PTR(-EINVAL);
-   } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
+   } else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
+  type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
frame = >d_frame;
} else {
v4l2_err(ctx->fimc_dev->v4l2_dev,
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c 
b/drivers/media/platform/exynos4-is/fimc-m2m.c
index a19f8b164a47..61c8177409cf 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -383,60 +383,80 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void 
*fh,
return 0;
 }
 
-static int fimc_m2m_cropcap(struct file *file, void *fh,
-   struct v4l2_cropcap *cr)
+static int fimc_m2m_g_selection(struct file *file, void *fh,
+   struct v4l2_selection *s)
 {
struct fimc_ctx *ctx = fh_to_ctx(fh);
struct fimc_frame *frame;
 
-   frame = ctx_get_frame(ctx, cr->type);
+   frame = ctx_get_frame(ctx, s->type);
if (IS_ERR(frame))
return PTR_ERR(frame);
 
-   cr->bounds.left = 0;
-   cr->bounds.top = 0;
-   cr->bounds.width = frame->o_width;
-   cr->bounds.height = frame->o_height;
-   cr->defrect = cr->bounds;
-
-   return 0;
-}
-
-static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
-{
-   struct fimc_ctx *ctx = fh_to_ctx(fh);
-   struct fimc_frame *frame;
-
-   frame = ctx_get_frame(ctx, cr->type);
-   if (IS_ERR(frame))
-   return PTR_ERR(frame);
-
-   cr->c.left = frame->offs_h;
-   cr->c.top = frame->offs_v;
-   cr->c.width = frame->width;
-   cr->c.height = frame->height;
+   switch (s->target) {
+   case V4L2_SEL_TGT_CROP:
+   case V4L2_SEL_TGT_CROP_DEFAULT:
+   case V4L2_SEL_TGT_CROP_BOUNDS:
+   if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+   return -EINVAL;
+   break;
+   case V4L2_SEL_TGT_COMPOSE:
+   case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+   case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+   if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+   break;
+   default:
+   return -EINVAL;
+   }
 
+   switch (s->target) {
+   case V4L2_SEL_TGT_CROP:
+   case V4L2_SEL_TGT_COMPOSE:
+   s->r.left = frame->offs_h;
+   s->r.top = frame->offs_v;
+   s->r.width = frame->width;
+   s->r.height = frame->height;
+   break;
+   case V4L2_SEL_TGT_CROP_DEFAULT:
+   case V4L2_SEL_TGT_CROP_BOUNDS:
+   case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+   case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+   s->r.left = 0;
+   s->r.top = 0;
+   s->r.width = frame->o_width;
+   s->r.height = frame->o_height;
+   break;
+   default:
+   return -EINVAL;
+   }
return 0;
 }
 
-static int fimc_m2m_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
+static int fimc_m2m_try_selection(struct fimc_ctx *ctx,
+ struct v4l2_selection *s)
 {
struct fimc_dev *fimc = ctx->fimc_dev;
struct fimc_frame *f;
u32 min_size, halign, depth = 0;
int i;
 
-   if (cr->c.top < 0 || cr->c.left < 0) {
+   if (s->r.top < 0 || s->r.left < 0) {
v4l2_err(>m2m.vfd,
"doesn't support negative values for top & left\n");
return -EINVAL;
}
-   if (cr->type ==