summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2017-03-21 20:12:14 +0200
committerVille Syrjälä <ville.syrjala@linux.intel.com>2017-03-22 19:37:17 +0200
commit568c5e453666fd8e0a8b11b440291f59e4da28c8 (patch)
tree4f27e5e04429a36fe56f27f51e4d4a196c3b7b00 /drivers/gpu/drm
parenteea54ed46edd42cf703be752d21731567142aa28 (diff)
drm: Share the code to compute color plane dimesions
framebuffer_check() has some hand rolled code to compute the color plane dimensions based on the subsampled information. Let's share the code between framebuffer_check() and drm_framebuffer_plane_{width,height}(). Cc: Ben Widawsky <ben@bwidawsk.net> Cc: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/20170321181218.10042-2-ville.syrjala@linux.intel.com Reviewed-by: Ben Widawsky <ben@bwidawsk.net>
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r--drivers/gpu/drm/drm_framebuffer.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index e4909aef75d7..1138f90a7d5d 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -126,6 +126,24 @@ int drm_mode_addfb(struct drm_device *dev,
return 0;
}
+static int fb_plane_width(int width,
+ const struct drm_format_info *format, int plane)
+{
+ if (plane == 0)
+ return width;
+
+ return width / format->hsub;
+}
+
+static int fb_plane_height(int height,
+ const struct drm_format_info *format, int plane)
+{
+ if (plane == 0)
+ return height;
+
+ return height / format->vsub;
+}
+
static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
{
const struct drm_format_info *info;
@@ -151,8 +169,8 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
}
for (i = 0; i < info->num_planes; i++) {
- unsigned int width = r->width / (i != 0 ? info->hsub : 1);
- unsigned int height = r->height / (i != 0 ? info->vsub : 1);
+ unsigned int width = fb_plane_width(r->width, info, i);
+ unsigned int height = fb_plane_height(r->height, info, i);
unsigned int cpp = info->cpp[i];
if (!r->handles[i]) {
@@ -816,10 +834,7 @@ int drm_framebuffer_plane_width(int width,
if (plane >= fb->format->num_planes)
return 0;
- if (plane == 0)
- return width;
-
- return width / fb->format->hsub;
+ return fb_plane_width(width, fb->format, plane);
}
EXPORT_SYMBOL(drm_framebuffer_plane_width);
@@ -838,9 +853,6 @@ int drm_framebuffer_plane_height(int height,
if (plane >= fb->format->num_planes)
return 0;
- if (plane == 0)
- return height;
-
- return height / fb->format->vsub;
+ return fb_plane_height(height, fb->format, plane);
}
EXPORT_SYMBOL(drm_framebuffer_plane_height);