Plane helpers and a new plane options ioctl
Subsystems (2)
Here are the utility functions again. Rebased and updated slightly.
I adapted drm_framebuffer_check() to handle multiple handles, and I changed some of the error values it returns.
The plane options ioctl is a bit of an open question. I started by adding separate ioctls for some subsets of the fucntionality, but then I was just writing so much duplicated ioctl handling code that I decided it doesn't seem right. I'm not really happy with this monster ioctl either.
I would actually like to replace the whole KMS API with some tag-length-value (TLV) type of thing. Basically you'd just feed the ioctl a KMS object ID and bunch of attribute IDs + values. The ioctl could take multiple such "streams" for any number of KMS objects.
It would be easily extendible simply by adding new types of attributes.
It would also support atomic mode setting changes across an arbitrary set of KMS objects, without having to do some kind begin+set+set+set...+commit multi ioctl sequence with all the state management nightmares that it would entail.
It would also cleanly handle cases where some attributes would be somehow tied together in hardware (eg. you have to set one attribute to a specific value, before another atribute can be set). With a multi ioctl approach you would have to accept invalid intermediate states, and delay error checking until the commit ioctl.
Of course you'd need to parse the "stream" and feed the resulting state to the driver somehow. I'm think the common code would pass the stream to the driver attribute at a time, and the driver would build up the state, possibly doing some early error checking. Finally when the whole state is built up, it would would be passed to the driver for final error checking, and if everything looks good the driver could push the state to the hardware. The driver could then attempt to do its thing in an atomic fashion, if possible.
Well, that's my utopian idea. Would require quite a bit of work though. Anyone else thinking along similar lines?
RFC PATCH 1/8 drm: Add drm_format_num_planes() utility function
From: Ville Syrjälä <[email protected]>
This function returns the number of planes used by a specific pixel format.
--- drivers/gpu/drm/drm_crtc_helper.c | 33 +++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 3 +++ 2 files changed, 36 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +33 -0
@@ -979,3 +979,36 @@ void drm_helper_hpd_irq_event(struct drm_device *dev)queue_delayed_work (system_nrt_wq, &dev->mode_config.output_poll_work,0 ); }EXPORT_SYMBOL (drm_helper_hpd_irq_event); + + +/** +* drm_format_num_planes - get the number of planes for format +* @format: pixel format (DRM_FORMAT_*) +* +* RETURNS: +* The number of planes used by the specified pixel format. +*/ +int drm_format_num_planes (uint32_t format) +{ +switch (format) { +case DRM_FORMAT_YUV410 : +case DRM_FORMAT_YVU410 : +case DRM_FORMAT_YUV411 : +case DRM_FORMAT_YVU411 : +case DRM_FORMAT_YUV420 : +case DRM_FORMAT_YVU420 : +case DRM_FORMAT_YUV422 : +case DRM_FORMAT_YVU422 : +case DRM_FORMAT_YUV444 : +case DRM_FORMAT_YVU444 : +return 3 ; +case DRM_FORMAT_NV12 : +case DRM_FORMAT_NV21 : +case DRM_FORMAT_NV16 : +case DRM_FORMAT_NV61 : +return 2 ; +default : +return 1 ; + } +} +EXPORT_SYMBOL (drm_format_num_planes);
include/drm/drm_crtc_helper.h +3 -0
@@ -144,4 +144,7 @@ extern void drm_helper_hpd_irq_event(struct drm_device *dev);extern void drm_kms_helper_poll_disable (struct drm_device *dev);extern void drm_kms_helper_poll_enable (struct drm_device *dev); + +extern int drm_format_num_planes (uint32_t format); +#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC PATCH 1/8] drm: Add drm_format_num_planes() utility function
Quoted 4 lines · On Mon, Dec 19, 2011 at 4:33 PM, <[email protected]> wrote:
From: Ville Syrjälä <[email protected]>
This function returns the number of planes used by a specific pixel format.
btw, I end up with a very similar util fxn in omapdrm driver.. would be nice to have this in core to avoid duplicating in every driver supporting multi-planar
Quoted 66 lines
Signed-off-by Ville Syrjälä <[email protected]>---
drivers/gpu/drm/drm_crtc_helper.c | 33 +++++++++++++++++++++++++++++++++include/drm/drm_crtc_helper.h| 3 +++2 files changed, 36 insertions(+), 0 deletions(-)drivers/gpu/drm/drm_crtc_helper.c +33
-0@@ -979,3 +979,36 @@ void drm_helper_hpd_irq_event(struct drm_device *dev) queue_delayed_work(system_nrt_wq, &dev->mode_config.output_poll_work, 0); } EXPORT_SYMBOL(drm_helper_hpd_irq_event); + + +/** +* drm_format_num_planes - get the number of planes for format +* @format: pixel format (DRM_FORMAT_*) +* +* RETURNS: +* The number of planes used by the specified pixel format. +*/ +int drm_format_num_planes (uint32_t format) +{ + switch (format) { + case DRM_FORMAT_YUV410: + case DRM_FORMAT_YVU410: + case DRM_FORMAT_YUV411: + case DRM_FORMAT_YVU411: + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU444: + return 3; + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV61: + return 2; + default: + return 1; + } +} +EXPORT_SYMBOL (drm_format_num_planes);include/drm/drm_crtc_helper.h +3
-1@@ -144,4 +144,7 @@ extern void drm_helper_hpd_irq_event(struct drm_device *dev); extern void drm_kms_helper_poll_disable(struct drm_device *dev); extern void drm_kms_helper_poll_enable(struct drm_device *dev); + +extern int drm_format_num_planes (uint32_t format); + #endif --1.7.3.4
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC PATCH 1/8] drm: Add drm_format_num_planes() utility function
Quoted 11 lines · Rob Clark
Quoted 4 lines · On Mon, Dec 19, 2011 at 4:33 PM, <[email protected]> wrote:
From: Ville Syrjälä <[email protected]>
This function returns the number of planes used by a specific pixel format.
btw, I end up with a very similar util fxn in omapdrm driver.. would be nice to have this in core to avoid duplicating in every driver supporting multi-planar
Reviewed-by Rob Clark <[email protected]>
Applied to -next.
Dave.
RFC PATCH 2/8 drm: Add drm_format_plane_cpp() utility function
In reply to [email protected]From: Ville Syrjälä <[email protected]>
This function returns the bytes per pixel value based on the pixel format and plane index.
--- drivers/gpu/drm/drm_crtc_helper.c | 45 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 1 + 2 files changed, 46 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +45 -0
@@ -1012,3 +1012,48 @@ int drm_format_num_planes(uint32_t format) } }EXPORT_SYMBOL (drm_format_num_planes); + +/** +* drm_format_plane_cpp - determine the bytes per pixel value +* @format: pixel format (DRM_FORMAT_*) +* @plane: plane index +* +* RETURNS: +* The bytes per pixel value for the specified plane. +*/ +int drm_format_plane_cpp (uint32_t format,int plane) +{ +unsigned int depth; +int bpp; + +if (plane >=drm_format_num_planes (format)) +return 0 ; + +switch (format) { +case DRM_FORMAT_YUYV : +case DRM_FORMAT_YVYU : +case DRM_FORMAT_UYVY : +case DRM_FORMAT_VYUY : +return 2 ; +case DRM_FORMAT_NV12 : +case DRM_FORMAT_NV21 : +case DRM_FORMAT_NV16 : +case DRM_FORMAT_NV61 : +return plane ?2 :1 ; +case DRM_FORMAT_YUV410 : +case DRM_FORMAT_YVU410 : +case DRM_FORMAT_YUV411 : +case DRM_FORMAT_YVU411 : +case DRM_FORMAT_YUV420 : +case DRM_FORMAT_YVU420 : +case DRM_FORMAT_YUV422 : +case DRM_FORMAT_YVU422 : +case DRM_FORMAT_YUV444 : +case DRM_FORMAT_YVU444 : +return 1 ; +default : +drm_fb_get_bpp_depth (format, &depth, &bpp); +return bpp >>3 ; + } +} +EXPORT_SYMBOL (drm_format_plane_cpp);
include/drm/drm_crtc_helper.h +1 -0
@@ -146,5 +146,6 @@ extern void drm_kms_helper_poll_disable(struct drm_device *dev);extern void drm_kms_helper_poll_enable (struct drm_device *dev);extern int drm_format_num_planes (uint32_t format); +extern int drm_format_plane_cpp (uint32_t format,int plane);#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 3/8 drm: Add drm_format_{horz, vert}_chroma_subsampling() utility functions
In reply to [email protected]From: Ville Syrjälä <[email protected]>
These functions return the chroma subsampling factors for the specified pixel format.
--- drivers/gpu/drm/drm_crtc_helper.c | 60 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 2 + 2 files changed, 62 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +60 -0
@@ -1057,3 +1057,63 @@ int drm_format_plane_cpp(uint32_t format, int plane) } }EXPORT_SYMBOL (drm_format_plane_cpp); + +/** +* drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor +* @format: pixel format (DRM_FORMAT_*) +* +* RETURNS: +* The horizontal chroma subsampling factor for the +* specified pixel format. +*/ +int drm_format_horz_chroma_subsampling (uint32_t format) +{ +switch (format) { +case DRM_FORMAT_YUV411 : +case DRM_FORMAT_YVU411 : +case DRM_FORMAT_YUV410 : +case DRM_FORMAT_YVU410 : +return 4 ; +case DRM_FORMAT_YUYV : +case DRM_FORMAT_YVYU : +case DRM_FORMAT_UYVY : +case DRM_FORMAT_VYUY : +case DRM_FORMAT_NV12 : +case DRM_FORMAT_NV21 : +case DRM_FORMAT_NV16 : +case DRM_FORMAT_NV61 : +case DRM_FORMAT_YUV422 : +case DRM_FORMAT_YVU422 : +case DRM_FORMAT_YUV420 : +case DRM_FORMAT_YVU420 : +return 2 ; +default : +return 1 ; + } +} +EXPORT_SYMBOL (drm_format_horz_chroma_subsampling); + +/** +* drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor +* @format: pixel format (DRM_FORMAT_*) +* +* RETURNS: +* The vertical chroma subsampling factor for the +* specified pixel format. +*/ +int drm_format_vert_chroma_subsampling (uint32_t format) +{ +switch (format) { +case DRM_FORMAT_YUV410 : +case DRM_FORMAT_YVU410 : +return 4 ; +case DRM_FORMAT_YUV420 : +case DRM_FORMAT_YVU420 : +case DRM_FORMAT_NV12 : +case DRM_FORMAT_NV21 : +return 2 ; +default : +return 1 ; + } +} +EXPORT_SYMBOL (drm_format_vert_chroma_subsampling);
include/drm/drm_crtc_helper.h +2 -0
@@ -147,5 +147,7 @@ extern void drm_kms_helper_poll_enable(struct drm_device *dev);extern int drm_format_num_planes (uint32_t format);extern int drm_format_plane_cpp (uint32_t format,int plane); +extern int drm_format_horz_chroma_subsampling (uint32_t format); +extern int drm_format_vert_chroma_subsampling (uint32_t format);#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 4/8 drm: Add drm_framebuffer_check() utility function
In reply to [email protected]From: Ville Syrjälä <[email protected]>
This function performs a battery of sanity checks on the requested framebuffer layout. Drivers can call it from their fb_create hook.
--- drivers/gpu/drm/drm_crtc_helper.c | 85 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 2 + 2 files changed, 87 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +85 -0
@@ -1117,3 +1117,88 @@ int drm_format_vert_chroma_subsampling(uint32_t format) } }EXPORT_SYMBOL (drm_format_vert_chroma_subsampling); + +/** +* drm_framebuffer_check - check the framebuffer layout +* @r: cmd from ioctl +* @sizes: sizes of the used BOs +* +* For each handle in the handles[] array of @r, the size of the +* corresponding BO must be passed in @sizes using the same index. +* +* RETURNS: +* Zero on success, error code on failure. +*/ +int drm_framebuffer_check (const struct drm_mode_fb_cmd2 *r,const uint64_t sizes[4 ]) +{ +struct { +unsigned int start, end; + } ranges[4 ]; +unsigned int req_sizes[4 ] = {}; +int hsub =drm_format_horz_chroma_subsampling (r->pixel_format); +int vsub =drm_format_vert_chroma_subsampling (r->pixel_format); +int num_planes =drm_format_num_planes (r->pixel_format); +int i, j; + +if (r->width ==0 || r->height ==0 ) +return -EINVAL ; + +/* Keep things safe for s15.16 fixed point math. */ +if (r->width >0x7fff || r->height >0x7fff ) +return -ERANGE ; + +if (r->width % hsub || r->height % vsub) +return -EINVAL ; + +for (i =0 ; i < num_planes; i++) { +unsigned int height = r->height / (i !=0 ? vsub :1 ); +unsigned int width = r->width / (i !=0 ? hsub :1 ); +unsigned int size = r->pitches[i] * height; +unsigned int cpp =drm_format_plane_cpp (r->pixel_format, i); +unsigned int min_pitch = cpp * width; + +if (!r->handles[i]) +return -EINVAL ; + +if (size < r->pitches[i] || size < height) +return -ERANGE ; + +if (min_pitch < width || min_pitch < cpp) +return -ERANGE ; + +if (r->pitches[i] < min_pitch) +return -EINVAL ; + + ranges[i].start = r->offsets[i]; + ranges[i].end = ranges[i].start + size; + +if (ranges[i].end < ranges[i].start) +return -ERANGE ; + +/* update all indexes of req_sizes that match this handle */ +for (j =0 ; j < num_planes; j++) { +if (r->handles[i] == r->handles[j]) + req_sizes[j] =max (req_sizes[j], ranges[i].end); + } + } + +/* Check that the passed BO sizes are sufficient */ +for (i =0 ; i < num_planes; i++) { +if (sizes[i] < req_sizes[i]) +return -ENOSPC ; + } + +/* Check for overlapping ranges within the same BO */ +/* FIXME what about formats with interleaved planes (eg. IMC2/IMC4)? */ +for (i =0 ; i < num_planes; i++) { +for (j = i +1 ; j < num_planes; j++) { +if (r->handles[i] == r->handles[j] && + ranges[i].start < ranges[j].end && + ranges[j].start < ranges[i].end) +return -EINVAL ; + } + } + +return 0 ; +} +EXPORT_SYMBOL (drm_framebuffer_check);
include/drm/drm_crtc_helper.h +2 -0
@@ -149,5 +149,7 @@ extern int drm_format_num_planes(uint32_t format);extern int drm_format_plane_cpp (uint32_t format,int plane);extern int drm_format_horz_chroma_subsampling (uint32_t format);extern int drm_format_vert_chroma_subsampling (uint32_t format); +extern int drm_framebuffer_check (const struct drm_mode_fb_cmd2 *r, +const uint64_t sizes[4 ]);#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 5/8 drm: Add struct drm_region and assorted utility functions
In reply to [email protected]From: Ville Syrjälä <[email protected]>
struct drm_region represents a two dimensional region. The utility functions are there to help driver writers.
--- drivers/gpu/drm/drm_crtc_helper.c | 156 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 24 ++++++ 2 files changed, 180 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +156 -0
@@ -1202,3 +1202,159 @@ int drm_framebuffer_check(const struct drm_mode_fb_cmd2 *r, const uint64_t sizesreturn 0 ; }EXPORT_SYMBOL (drm_framebuffer_check); + + +/** +* drm_region_adjust_size - adjust the size of the region +* @r: region to be adjusted +* @x: horizontal adjustment +* @y: vertical adjustment +* +* Change the size of region @r by @x in the horizontal direction, +* and by @y in the vertical direction, while keeping the center +* of @r stationary. +* +* Positive @x and @y increase the size, negative values decrease it. +*/ +void drm_region_adjust_size (struct drm_region *r,int x,int y) +{ + r->x1 -= x >>1 ; + r->y1 -= y >>1 ; + r->x2 += (x +1 ) >>1 ; + r->y2 += (y +1 ) >>1 ; +} +EXPORT_SYMBOL (drm_region_adjust_size); + +/** +* drm_region_translate - translate the region +* @r: region to be tranlated +* @x: horizontal translation +* @y: vertical translation +* +* Move region @r by @x in the horizontal direction, +* and by @y in the vertical direction. +*/ +void drm_region_translate (struct drm_region *r,int x,int y) +{ + r->x1 += x; + r->y1 += y; + r->x2 += x; + r->y2 += y; +} +EXPORT_SYMBOL (drm_region_translate); + +/** +* drm_region_subsample - subsample a region +* @r: region to be subsampled +* @hsub: horizontal subsampling factor +* @vsub: vertical subsampling factor +* +* Divide the coordinates of region @r by @hsub and @vsub. +*/ +void drm_region_subsample (struct drm_region *r,int hsub,int vsub) +{ + r->x1 /= hsub; + r->y1 /= vsub; + r->x2 /= hsub; + r->y2 /= vsub; +} +EXPORT_SYMBOL (drm_region_subsample); + +/** +* drm_region_width - determine the region width +* @r: region whose width is returned +* +* RETURNS: +* The width of the region. +*/ +int drm_region_width (const struct drm_region *r) +{ +return r->x2 - r->x1; +} +EXPORT_SYMBOL (drm_region_width); + +/** +* drm_region_height - determine the region height +* @r: region whose height is returned +* +* RETURNS: +* The height of the region. +*/ +int drm_region_height (const struct drm_region *r) +{ +return r->y2 - r->y1; +} +EXPORT_SYMBOL (drm_region_height); + +/** +* drm_region_visible - determine if the the region is visible +* @r: region whose visibility is returned +* +* RETURNS: +* @true if the region is visible, @false otherwise. +*/ +bool drm_region_visible (const struct drm_region *r) +{ +return drm_region_width (r) >0 &&drm_region_height (r) >0 ; +} +EXPORT_SYMBOL (drm_region_visible); + +/** +* drm_region_clip - clip one region by another region +* @r: region to be clipped +* @clip: clip region +* +* Clip region @r by region @clip. +* +* RETURNS: +* @true if the region is still visible after being clipped, +* @false otherwise. +*/ +bool drm_region_clip (struct drm_region *r,const struct drm_region *clip) +{ + r->x1 =max (r->x1, clip->x1); + r->y1 =max (r->y1, clip->y1); + r->x2 =min (r->x2, clip->x2); + r->y2 =min (r->y2, clip->y2); + +return drm_region_visible (r); +} +EXPORT_SYMBOL (drm_region_clip); + +/** +* drm_region_clip_scaled - perform a scaled clip operation +* @src: source window region +* @dst: destination window region +* @clip: clip region +* @hscale: horizontal scaling factor +* @vscale: vertical scaling factor +* +* Clip region @dst by region @clip. Clip region @src by the same +* amounts multiplied by @hscale and @vscale. +* +* RETUTRNS: +* @true if region @dst is still visible after being clipped, +* @false otherwise +*/ +bool drm_region_clip_scaled (struct drm_region *src,struct drm_region *dst, +const struct drm_region *clip, +int hscale,int vscale) +{ +int diff; + + diff = clip->x1 - dst->x1; +if (diff >0 ) + src->x1 += diff * hscale; + diff = clip->y1 - dst->y1; +if (diff >0 ) + src->y1 += diff * vscale; + diff = dst->x2 - clip->x2; +if (diff >0 ) + src->x2 -= diff * hscale; + diff = dst->y2 - clip->y2; +if (diff >0 ) + src->y2 -= diff * vscale; + +return drm_region_clip (dst, clip); +} +EXPORT_SYMBOL (drm_region_clip_scaled);
include/drm/drm_crtc_helper.h +24 -0
@@ -152,4 +152,28 @@ extern int drm_format_vert_chroma_subsampling(uint32_t format);extern int drm_framebuffer_check (const struct drm_mode_fb_cmd2 *r,const uint64_t sizes[4 ]); +/** +* drm_region - two dimensional region +* @x1: horizontal starting coordinate (inclusive) +* @x2: horizontal ending coordinate (exclusive) +* @y1: vertical starting coordinate (inclusive) +* @y2: vertical ending coordinate (exclusive) +*/ +struct drm_region { +int x1, y1, x2, y2; +}; + +extern void drm_region_adjust_size (struct drm_region *r,int x,int y); +extern void drm_region_translate (struct drm_region *r,int x,int y); +extern void drm_region_subsample (struct drm_region *r,int hsub,int vsub); +extern int drm_region_width (const struct drm_region *r); +extern int drm_region_height (const struct drm_region *r); +extern bool drm_region_visible (const struct drm_region *r); +extern bool drm_region_clip (struct drm_region *r, +const struct drm_region *clip); +extern bool drm_region_clip_scaled (struct drm_region *src, +struct drm_region *dst, +const struct drm_region *clip, +int hscale,int vscale); +#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 6/8 drm: Add drm_calc_{hscale, vscale}() utility functions
In reply to [email protected]From: Ville Syrjälä <[email protected]>
--- drivers/gpu/drm/drm_crtc_helper.c | 102 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 4 ++ 2 files changed, 106 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +102 -0
@@ -1358,3 +1358,105 @@ bool drm_region_clip_scaled(struct drm_region *src, struct drm_region *dst,return drm_region_clip (dst, clip); }EXPORT_SYMBOL (drm_region_clip_scaled); + +/** +* drm_calc_hscale - calculate the horizontal scaling factor +* @src: source window region +* @dst: destination window region +* @min_hscale: minimum allowed horizontal scaling factor +* @max_hscale: maximum allowed horizontal scaling factor +* +* Calculate the horizontal scaling factor as +* (@src width) / (@dst width). +* +* If the calculated scaling factor is below @min_hscale, +* decrease the width of region @dst to compensate. +* +* If the calculcated scaling factor is above @max_hscale, +* decrease the width of region @src to compensate. +* +* RETURNS: +* The horizontal scaling factor. +*/ +int drm_calc_hscale (struct drm_region *src,struct drm_region *dst, +int min_hscale,int max_hscale) +{ +int src_w =drm_region_width (src); +int dst_w =drm_region_width (dst); +int hscale; + +if (dst_w <=0 ) +return 0 ; + + hscale = src_w / dst_w; + +if (hscale < min_hscale) { +int max_dst_w = src_w / min_hscale; + +drm_region_adjust_size (dst, max_dst_w - dst_w,0 ); + +return min_hscale; + } + +if (hscale > max_hscale) { +int max_src_w = dst_w * max_hscale; + +drm_region_adjust_size (src, max_src_w - src_w,0 ); + +return max_hscale; + } + +return hscale; +} +EXPORT_SYMBOL (drm_calc_hscale); + +/** +* drm_calc_vscale - calculate the vertical scaling factor +* @src: source window region +* @dst: destination window region +* @min_vscale: minimum allowed vertical scaling factor +* @max_vscale: maximum allowed vertical scaling factor +* +* Calculate the vertical scaling factor as +* (@src height) / (@dst height). +* +* If the calculated scaling factor is below @min_vscale, +* decrease the height of region @dst to compensate. +* +* If the calculcated scaling factor is above @max_vscale, +* decrease the height of region @src to compensate. +* +* RETURNS: +* The vertical scaling factor. +*/ +int drm_calc_vscale (struct drm_region *src,struct drm_region *dst, +int min_vscale,int max_vscale) +{ +int src_h =drm_region_height (src); +int dst_h =drm_region_height (dst); +int vscale; + +if (dst_h <=0 ) +return 0 ; + + vscale = src_h / dst_h; + +if (vscale < min_vscale) { +int max_dst_h = src_h / min_vscale; + +drm_region_adjust_size (dst,0 , max_dst_h - dst_h); + +return min_vscale; + } + +if (vscale > max_vscale) { +int max_src_h = dst_h * max_vscale; + +drm_region_adjust_size (src,0 , max_src_h - src_h); + +return max_vscale; + } + +return vscale; +} +EXPORT_SYMBOL (drm_calc_vscale);
include/drm/drm_crtc_helper.h +4 -0
@@ -175,5 +175,9 @@ extern bool drm_region_clip_scaled(struct drm_region *src,struct drm_region *dst, const struct drm_region *clip, int hscale, int vscale); +extern int drm_calc_hscale (struct drm_region *src,struct drm_region *dst, +int min_hscale,int max_hscale); +extern int drm_calc_vscale (struct drm_region *src,struct drm_region *dst, +int min_vscale,int max_vscale);#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 7/8 drm: plane: Add plane options ioctl
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Add a new ioctl DRM_IOCTL_MODE_PLANE_OPTS which is used to configure various settings for the plane.
I left out gamma correction thinking that it could be added using a separate ioctl, since there's already a gamma ioctl for CRTCs.
--- drivers/gpu/drm/drm_crtc.c | 168 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_crtc_helper.c | 19 ++++ drivers/gpu/drm/drm_drv.c | 3 +- include/drm/drm.h | 2 + include/drm/drm_crtc.h | 60 +++++++++++++ include/drm/drm_crtc_helper.h | 1 + include/drm/drm_mode.h | 111 ++++++++++++++++++++++++ 7 files changed, 363 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +168 -0
@@ -1772,6 +1772,174 @@ out: }/** +* drm_mode_plane_opts - set and get plane options +* @dev: DRM device +* @data: ioctl data* +* @file_prive: DRM file info +* +*/ +int drm_mode_plane_opts (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_mode_plane_opts_cmd *req = data; +struct drm_mode_object *obj; +struct drm_plane *plane; +int ret =0 ; + +if (!drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + +mutex_lock (&dev->mode_config.mutex); + +/* +* First, find the plane object. If not available, +* we don't bother to call the driver. +*/ + obj =drm_mode_object_find (dev, req->plane_id, +DRM_MODE_OBJECT_PLANE ); +if (!obj) { +DRM_DEBUG_KMS ("Unknown plane ID %d\n" , + req->plane_id); + ret = -ENOENT ; + goto out; + } + plane =obj_to_plane (obj); + +if (req->flags & ~plane->opts_flags) { + ret = -ENOTSUPP ; + goto out; + } + +if (req->flags) { +/* Start with the current values. */ +struct drm_plane_opts opts = plane->opts; +uint32_t flags =0 ; + +/* Overwrite with user provided values. */ +if (req->flags &DRM_MODE_PLANE_BRIGHTNESS && + opts.brightness != req->brightness) { + flags |=DRM_MODE_PLANE_BRIGHTNESS ; + opts.brightness = req->brightness; + } +if (req->flags &DRM_MODE_PLANE_CONTRAST && + opts.contrast != req->contrast) { + flags |=DRM_MODE_PLANE_CONTRAST ; + opts.contrast = req->contrast; + } +if (req->flags &DRM_MODE_PLANE_HUE && + opts.hue != req->hue) { + flags |=DRM_MODE_PLANE_HUE ; + opts.hue = req->hue; + } +if (req->flags &DRM_MODE_PLANE_SATURATION && + opts.saturation != req->saturation) { + flags |=DRM_MODE_PLANE_SATURATION ; + opts.saturation = req->saturation; + } +if (req->flags &DRM_MODE_PLANE_SRC_KEY && + (opts.src_key_low != req->src_key_low || + opts.src_key_high != req->src_key_high)) { + flags |=DRM_MODE_PLANE_SRC_KEY ; + opts.src_key_low = req->src_key_low; + opts.src_key_high = req->src_key_high; + } +if (req->flags &DRM_MODE_PLANE_DST_KEY && + (opts.dst_key_value != req->dst_key_value || + opts.dst_key_mask != req->dst_key_mask)) { + flags |=DRM_MODE_PLANE_DST_KEY ; + opts.dst_key_value = req->dst_key_value; + opts.dst_key_mask = req->dst_key_mask; + } +if (req->flags &DRM_MODE_PLANE_CONST_ALPHA && + opts.const_alpha != req->const_alpha) { + flags |=DRM_MODE_PLANE_CONST_ALPHA ; + opts.const_alpha = req->const_alpha; + } +if (req->flags &DRM_MODE_PLANE_ZORDER && + opts.zorder != req->zorder) { +if (req->zorder ==0 ) { + ret = -EINVAL ; + goto out; + } + flags |=DRM_MODE_PLANE_ZORDER ; + opts.zorder = req->zorder; + } +if (req->flags &DRM_MODE_PLANE_CSC_MATRIX && + opts.csc_matrix != req->csc_matrix) { + flags |=DRM_MODE_PLANE_CSC_MATRIX ; + opts.csc_matrix = req->csc_matrix; + } +if (req->flags &DRM_MODE_PLANE_CSC_RANGE && + opts.csc_range != req->csc_range) { + flags |=DRM_MODE_PLANE_CSC_RANGE ; + opts.csc_range = req->csc_range; + } +if (req->flags &DRM_MODE_PLANE_CHROMA_SITING && + opts.chroma_siting != req->chroma_siting) { + flags |=DRM_MODE_PLANE_CHROMA_SITING ; + opts.chroma_siting = req->chroma_siting; + } +if (req->flags &DRM_MODE_PLANE_VC1_RANGE_MAPY && + opts.vc1_range_mapy != req->vc1_range_mapy) { + flags |=DRM_MODE_PLANE_VC1_RANGE_MAPY ; + opts.vc1_range_mapy = req->vc1_range_mapy; + } +if (req->flags &DRM_MODE_PLANE_VC1_RANGE_MAPUV && + opts.vc1_range_mapuv != req->vc1_range_mapuv) { + flags |=DRM_MODE_PLANE_VC1_RANGE_MAPUV ; + opts.vc1_range_mapuv = req->vc1_range_mapuv; + } + +if (flags) { + ret = plane->funcs->set_plane_opts (plane, flags, &opts); +if (ret) + goto out; + + plane->opts = opts; + } + } + +/* Copy the current values back to the user. */ + req->flags = plane->opts_flags; + +if (req->flags &DRM_MODE_PLANE_BRIGHTNESS ) + req->brightness = plane->opts.brightness; +if (req->flags &DRM_MODE_PLANE_CONTRAST ) + req->contrast = plane->opts.contrast; +if (req->flags &DRM_MODE_PLANE_HUE ) + req->hue = plane->opts.hue; +if (req->flags &DRM_MODE_PLANE_SATURATION ) + req->saturation = plane->opts.saturation; +if (req->flags &DRM_MODE_PLANE_SRC_KEY ) { + req->src_key_low = plane->opts.src_key_low; + req->src_key_high = plane->opts.src_key_high; + } +if (req->flags &DRM_MODE_PLANE_DST_KEY ) { + req->dst_key_value = plane->opts.dst_key_value; + req->dst_key_mask = plane->opts.dst_key_mask; + } +if (req->flags &DRM_MODE_PLANE_CONST_ALPHA ) + req->const_alpha = plane->opts.const_alpha; +if (req->flags &DRM_MODE_PLANE_ZORDER ) + req->zorder = plane->opts.zorder; +if (req->flags &DRM_MODE_PLANE_CSC_MATRIX ) + req->csc_matrix = plane->opts.csc_matrix; +if (req->flags &DRM_MODE_PLANE_CSC_RANGE ) + req->csc_range = plane->opts.csc_range; +if (req->flags &DRM_MODE_PLANE_CHROMA_SITING ) + req->chroma_siting = plane->opts.chroma_siting; +if (req->flags &DRM_MODE_PLANE_VC1_RANGE_MAPY ) + req->vc1_range_mapy = plane->opts.vc1_range_mapy; +if (req->flags &DRM_MODE_PLANE_VC1_RANGE_MAPUV ) + req->vc1_range_mapuv = plane->opts.vc1_range_mapuv; + + out: +mutex_unlock (&dev->mode_config.mutex); + +return ret; +} + +/** * drm_mode_setcrtc - set CRTC configuration * @inode: inode from the ioctl * @filp: file * from the ioctl
drivers/gpu/drm/drm_crtc_helper.c +19 -0
@@ -1460,3 +1460,22 @@ int drm_calc_vscale(struct drm_region *src, struct drm_region *dst,return vscale; }EXPORT_SYMBOL (drm_calc_vscale); + +/** +* drm_plane_opts_defaults - fill the plane opts with default values +*/ +void drm_plane_opts_defaults (struct drm_plane_opts *opts) +{ +memset (opts,0 ,sizeof *opts); + + opts->brightness =0x8000 ; + opts->contrast =0x8000 ; + opts->hue =0x8000 ; + opts->saturation =0x8000 ; + +/* disable source color keying */ + opts->src_key_low = ~0ULL ; + + opts->const_alpha =0xffff ; +} +EXPORT_SYMBOL (drm_plane_opts_defaults);
drivers/gpu/drm/drm_drv.c +2 -1
@@ -159,7 +159,8 @@ static struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), - DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) +DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_PLANE_OPTS, drm_mode_plane_opts, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
include/drm/drm.h +2 -0
@@ -718,6 +718,8 @@ struct drm_get_cap {#define DRM_IOCTL_MODE_GETPLANE DRM_IOWR(0xB6, struct drm_mode_get_plane)#define DRM_IOCTL_MODE_SETPLANE DRM_IOWR(0xB7, struct drm_mode_set_plane)#define DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, struct drm_mode_fb_cmd2) +#define DRM_IOCTL_MODE_PLANE_OPTS DRM_IOWR(0xB9, struct drm_mode_plane_opts_cmd) +/** * Device specific ioctls should only be in their respective headers
include/drm/drm_crtc.h +60 -0
88 lines not on this page · raw message
include/drm/drm_crtc_helper.h +1 -0
@@ -179,5 +179,6 @@ extern int drm_calc_hscale(struct drm_region *src, struct drm_region *dst, int min_hscale, int max_hscale);extern int drm_calc_vscale (struct drm_region *src,struct drm_region *dst,int min_vscale,int max_vscale); +extern void drm_plane_opts_defaults (struct drm_plane_opts *opts);#endif
include/drm/drm_mode.h +111 -0
117 lines not on this page · raw message
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 8/8 drm: Add drm_chroma_phase_offsets() utility function
In reply to [email protected]From: Ville Syrjälä <[email protected]>
This function is is there to help driver writers.
--- drivers/gpu/drm/drm_crtc_helper.c | 47 +++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc_helper.h | 3 ++ 2 files changed, 50 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +47 -0
@@ -1479,3 +1479,50 @@ void drm_plane_opts_defaults(struct drm_plane_opts *opts) opts->const_alpha =0xffff ; }EXPORT_SYMBOL (drm_plane_opts_defaults); + +/** +* drm_chroma_phase_offsets - calculate the chroma phase offsets +* @ret_xoff: returned horizontal offset (16.16) +* @ret_yoff: returned vertical offset (16.16) +* @hsub: horizontal chroma subsampling factor +* @vsub: vertical chroma subsampling factor +* @chroma: chroma siting information +* @second_chroma_plane: first or second chroma plane? +* +* Calculates the phase offset between chroma and luma pixel centers, +* based on infromation provided in @chroma, @hsub, @vsub, and +* @second_chroma_plane. +* +* RETURNS: +* The chroma phase offsets in 16.16 format. The returned +* phase offsets are in chroma (ie. subsampled) coordinate space. +*/ +void drm_chroma_phase_offsets (int *ret_xoff,int *ret_yoff, +int hsub,int vsub,uint8_t chroma_siting, +bool second_chroma_plane) +{ + *ret_xoff =0 ; + *ret_yoff =0 ; + +switch (chroma_siting &0x3 ) { +case DRM_CHROMA_SITING_HORZ_LEFT : +break ; +case DRM_CHROMA_SITING_HORZ_CENTER : + *ret_xoff -= (hsub -1 ) *0x8000 / hsub; +break ; + } + +switch (chroma_siting &0xc0 ) { +case DRM_CHROMA_SITING_VERT_TOP : +break ; +case DRM_CHROMA_SITING_VERT_CENTER : + *ret_yoff -= (vsub -1 ) *0x8000 / vsub; +break ; + } + +/* Chroma planes out of phase by 0.5 chroma lines? */ +if (second_chroma_plane && + (chroma_siting &DRM_CHROMA_SITING_MISALIGNED_PLANES )) + *ret_yoff -=0x8000 ; +} +EXPORT_SYMBOL (drm_chroma_phase_offsets);
include/drm/drm_crtc_helper.h +3 -0
@@ -180,5 +180,8 @@ extern int drm_calc_hscale(struct drm_region *src, struct drm_region *dst,extern int drm_calc_vscale (struct drm_region *src,struct drm_region *dst,int min_vscale,int max_vscale);extern void drm_plane_opts_defaults (struct drm_plane_opts *opts); +extern void drm_chroma_phase_offsets (int *ret_xoff,int *ret_yoff, +int hsub,int vsub,uint8_t chroma_siting, +bool second_chroma_plane);#endif
Signature · 6 lines
1.7.3.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel