[Intel-gfx] [PATCH] i-g-t: Adding test case to test background color.

Thomas Wood thomas.wood at intel.com
Mon Feb 23 07:40:01 PST 2015


On 21 February 2015 at 00:12, Chandra Konduru <chandra.konduru at intel.com> wrote:
> From: chandra konduru <chandra.konduru at intel.com>
>
> Adding i-g-t test case to test display crtc background color.
>
> Signed-off-by: chandra konduru <chandra.konduru at intel.com>
> ---
>  lib/igt_kms.c                     |  60 +++++++++++
>  lib/igt_kms.h                     |   4 +
>  tests/Android.mk                  |   1 +
>  tests/Makefile.sources            |   1 +
>  tests/kms_crtc_background_color.c | 220 ++++++++++++++++++++++++++++++++++++++
>  5 files changed, 286 insertions(+)
>  create mode 100644 tests/kms_crtc_background_color.c

Please could you also add the test to .gitignore and include a short
description using the IGT_TEST_DESCRIPTION macro?

>
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index d0c3690..7246e59 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -926,6 +926,22 @@ igt_plane_set_property(igt_plane_t *plane, uint32_t prop_id, uint64_t value)
>                                  DRM_MODE_OBJECT_PLANE, prop_id, value);
>  }
>
> +static bool
> +get_crtc_property(int drm_fd, uint32_t crtc_id, const char *name,
> +                  uint32_t *prop_id /* out */, uint64_t *value /* out */,
> +                  drmModePropertyPtr *prop /* out */)
> +{
> +       return kmstest_get_property(drm_fd, crtc_id, DRM_MODE_OBJECT_CRTC,
> +                                   name, prop_id, value, prop);
> +}
> +
> +static void
> +igt_crtc_set_property(igt_output_t *output, uint32_t prop_id, uint64_t value)
> +{
> +       drmModeObjectSetProperty(output->display->drm_fd,
> +               output->config.crtc->crtc_id, DRM_MODE_OBJECT_CRTC, prop_id, value);
> +}
> +
>  /*
>   * Walk a plane's property list to determine its type.  If we don't
>   * find a type property, then the kernel doesn't support universal
> @@ -1083,6 +1099,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
>         igt_assert(display->outputs);
>
>         for (i = 0; i < display->n_outputs; i++) {
> +               int j;
>                 igt_output_t *output = &display->outputs[i];
>
>                 /*
> @@ -1094,6 +1111,19 @@ void igt_display_init(igt_display_t *display, int drm_fd)
>                 output->display = display;
>
>                 igt_output_refresh(output);
> +
> +               for (j = 0; j < display->n_pipes; j++) {
> +                       uint64_t prop_value;
> +                       igt_pipe_t *pipe = &display->pipes[j];
> +                       if (output->config.crtc) {
> +                               get_crtc_property(display->drm_fd, output->config.crtc->crtc_id,
> +                                                  "background_color",
> +                                                  &pipe->background_property,
> +                                                  &prop_value,
> +                                                  NULL);
> +                               pipe->background = (uint32_t)prop_value;
> +                       }
> +               }
>         }
>
>         drmModeFreePlaneResources(plane_resources);
> @@ -1513,6 +1543,13 @@ static int igt_output_commit(igt_output_t *output,
>
>         pipe = igt_output_get_driving_pipe(output);
>
> +       if (pipe->background_changed) {
> +               igt_crtc_set_property(output, pipe->background_property,
> +                       pipe->background);
> +
> +               pipe->background_changed = false;
> +       }
> +
>         for (i = 0; i < pipe->n_planes; i++) {
>                 igt_plane_t *plane = &pipe->planes[i];
>
> @@ -1765,6 +1802,29 @@ void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation)
>         plane->rotation_changed = true;
>  }
>
> +/**
> + * igt_crtc_set_background:
> + * @pipe: pipe pointer to which background color to be set
> + * @background: background color value
> + *
> + * Sets background color for requested pipe. Color value provided here
> + * will be actually submitted at output commit time via "background_color"
> + * property.

it might be helpful to describe the format for "background_color" here too.

> + */
> +void igt_crtc_set_background(igt_pipe_t *pipe, uint64_t background)
> +{
> +       igt_display_t *display = pipe->display;
> +
> +       LOG(display, "%s.%d: crtc_set_background(%lu)\n",
> +           kmstest_pipe_name(pipe->pipe),
> +           pipe->pipe, background);
> +
> +       pipe->background = background;
> +
> +       pipe->background_changed = true;
> +}
> +
> +
>  void igt_wait_for_vblank(int drm_fd, enum pipe pipe)
>  {
>         drmVBlank wait_vbl;
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index a1483a4..4fada1b 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -206,6 +206,9 @@ struct igt_pipe {
>  #define IGT_MAX_PLANES 4
>         int n_planes;
>         igt_plane_t planes[IGT_MAX_PLANES];
> +       uint64_t background; /* Background color MSB BGR 16bpc LSB */
> +       uint32_t background_changed : 1;
> +       uint32_t background_property;
>  };
>
>  typedef struct {
> @@ -251,6 +254,7 @@ void igt_plane_set_position(igt_plane_t *plane, int x, int y);
>  void igt_plane_set_size(igt_plane_t *plane, int w, int h);
>  void igt_plane_set_panning(igt_plane_t *plane, int x, int y);
>  void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
> +void igt_crtc_set_background(igt_pipe_t *pipe, uint64_t background);
>
>  void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
>
> diff --git a/tests/Android.mk b/tests/Android.mk
> index 814b846..96a32b9 100644
> --- a/tests/Android.mk
> +++ b/tests/Android.mk
> @@ -75,6 +75,7 @@ else
>      kms_rotation_crc \
>      kms_force_connector \
>      kms_flip_event_leak \
> +    kms_crtc_background_color \
>      kms_pwrite_crc
>      IGT_LOCAL_CFLAGS += -DANDROID_HAS_CAIRO=0
>  endif
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 74deec3..4f612e6 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -77,6 +77,7 @@ TESTS_progs_M = \
>         kms_rotation_crc \
>         kms_setmode \
>         kms_universal_plane \
> +       kms_crtc_background_color \
>         pm_lpsp \
>         pm_rpm \
>         pm_rps \
> diff --git a/tests/kms_crtc_background_color.c b/tests/kms_crtc_background_color.c
> new file mode 100644
> index 0000000..e73e097
> --- /dev/null
> +++ b/tests/kms_crtc_background_color.c
> @@ -0,0 +1,220 @@
> +/*
> + * Copyright © 2013,2014 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + */
> +
> +#include <math.h>
> +
> +#include "drmtest.h"
> +#include "igt_debugfs.h"
> +#include "igt_kms.h"
> +#include "igt_core.h"
> +
> +typedef struct {
> +       int gfx_fd;
> +       igt_display_t display;
> +       struct igt_fb fb;
> +       igt_crc_t ref_crc;
> +       igt_pipe_crc_t *pipe_crc;
> +} data_t;
> +
> +#define BLACK      0x000000           /* BGR 8bpc */
> +#define CYAN       0xFFFF00           /* BGR 8bpc */
> +#define PURPLE     0xFF00FF           /* BGR 8bpc */
> +#define WHITE      0xFFFFFF           /* BGR 8bpc */
> +
> +#define BLACK64    0x000000000000     /* BGR 16bpc */
> +#define CYAN64     0xFFFFFFFF0000     /* BGR 16bpc */
> +#define PURPLE64   0xFFFF0000FFFF     /* BGR 16bpc */
> +#define YELLOW64   0x0000FFFFFFFF     /* BGR 16bpc */
> +#define WHITE64    0xFFFFFFFFFFFF     /* BGR 16bpc */
> +#define RED64      0x00000000FFFF     /* BGR 16bpc */
> +#define GREEN64    0x0000FFFF0000     /* BGR 16bpc */
> +#define BLUE64     0xFFFF00000000     /* BGR 16bpc */
> +
> +int kms_crtc_background_crc_check = 0;

Is this supposed to be assigned to another value at some point?

> +
> +static void
> +paint_background(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
> +               uint32_t background, double alpha)
> +{
> +       cairo_t *cr;
> +       int w, h;
> +       double r, g, b;
> +
> +       w = mode->hdisplay;
> +       h = mode->vdisplay;
> +
> +       cr = igt_get_cairo_ctx(data->gfx_fd, &data->fb);
> +
> +       /* Paint with background color */
> +       r = (double) (background & 0xFF) / 255.0;
> +       g = (double) ((background & 0xFF00) >> 8) / 255.0;
> +       b = (double) ((background & 0xFF0000) >> 16) / 255.0;
> +       igt_paint_color_alpha(cr, 0, 0, w, h, r, g, b, alpha);
> +
> +       cairo_destroy(cr);
> +}
> +
> +static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
> +                       igt_plane_t *plane, int opaque_buffer, int plane_color,
> +                       uint64_t pipe_background_color)
> +{
> +       drmModeModeInfo *mode;
> +       igt_display_t *display = &data->display;
> +       int fb_id;
> +       double alpha;
> +
> +       igt_output_set_pipe(output, pipe);
> +
> +       /* create the pipe_crc object for this pipe */
> +       igt_pipe_crc_free(data->pipe_crc);
> +       data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
> +
> +       mode = igt_output_get_mode(output);
> +
> +       fb_id = igt_create_fb(data->gfx_fd,
> +                       mode->hdisplay, mode->vdisplay,
> +                       DRM_FORMAT_XRGB8888,
> +                       false, /* tiled */
> +                       &data->fb);
> +       igt_assert(fb_id);
> +
> +       /* To make FB pixel win with background color, set alpha as full opaque */
> +       igt_crtc_set_background(plane->pipe, pipe_background_color);
> +       if (opaque_buffer)
> +               alpha = 1.0;    /* alpha 1 is fully opque */
> +       else
> +               alpha = 0.0;    /* alpha 0 is fully transparent */
> +       paint_background(data, &data->fb, mode, plane_color, alpha);
> +
> +       igt_plane_set_fb(plane, &data->fb);
> +       igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +       /* Capture crc background using a full plane. i.e., without hw feature */
> +       if (kms_crtc_background_crc_check)
> +               igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
> +}
> +
> +static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane)
> +{
> +       igt_display_t *display = &data->display;
> +
> +       igt_pipe_crc_free(data->pipe_crc);
> +       data->pipe_crc = NULL;
> +
> +       igt_remove_fb(data->gfx_fd, &data->fb);
> +
> +       igt_crtc_set_background(plane->pipe, BLACK64);
> +       igt_plane_set_fb(plane, NULL);
> +       igt_output_set_pipe(output, PIPE_ANY);
> +
> +       igt_display_commit2(display, COMMIT_UNIVERSAL);
> +}
> +
> +static void test_crtc_background(data_t *data)
> +{
> +       igt_display_t *display = &data->display;
> +       igt_output_t *output;
> +       enum pipe pipe;
> +       int valid_tests = 0;
> +       igt_crc_t crc_output1;
> +
> +       igt_require(data->display.has_universal_planes);
> +
> +       for_each_connected_output(display, output) {
> +               igt_plane_t *plane;
> +
> +               pipe = output->config.pipe;
> +               igt_output_set_pipe(output, pipe);
> +
> +               plane = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
> +               igt_require(plane->pipe->background_property);
> +
> +               prepare_crtc(data, output, pipe, plane, 1, PURPLE, BLACK64);
> +
> +               /* Now set background without using a plane, i.e.,
> +                * Disable the plane to let hw background color win blend. */
> +               igt_plane_set_fb(plane, NULL);
> +               igt_crtc_set_background(plane->pipe, PURPLE64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               /* collect CRC for hw feature */
> +               if (kms_crtc_background_crc_check) {
> +                       igt_pipe_crc_collect_crc(data->pipe_crc, &crc_output1);
> +                       igt_assert(igt_crc_equal(&data->ref_crc, &crc_output1));
> +               }
> +
> +               /* Try few other background colors */
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, CYAN64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, YELLOW64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, RED64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, GREEN64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, BLUE64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               sleep(1);
> +               igt_crtc_set_background(plane->pipe, WHITE64);
> +               igt_display_commit2(display, COMMIT_UNIVERSAL);
> +
> +               valid_tests++;
> +               cleanup_crtc(data, output, plane);
> +       }
> +       igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
> +}
> +
> +igt_main
> +{
> +       data_t data = {};
> +
> +       igt_skip_on_simulation();
> +
> +       igt_fixture {
> +               data.gfx_fd = drm_open_any();
> +
> +               kmstest_set_vt_graphics_mode();
> +
> +               igt_require_pipe_crc();
> +
> +               igt_display_init(&data.display, data.gfx_fd);
> +       }
> +
> +       igt_subtest_f("pipe-background")

This could just use igt_subtest(), although unless more subtests are
planned, the test could use igt_simple_test instead, removing the need
for igt_fixture and igt_subtest.

> +               test_crtc_background(&data);
> +
> +       igt_fixture {
> +               igt_display_fini(&data.display);
> +       }
> +}
> --
> 1.9.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx


More information about the Intel-gfx mailing list