<commit_before>#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <string.h>

#include "test-conform-common.h"

static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };

/* Non-power-of-two sized texture that should cause slicing */
#define TEXTURE_SIZE        257
/* Number of times to split the texture up on each axis */
#define PARTS               2
/* The texture is split into four parts, each with a different colour */
#define PART_SIZE           (TEXTURE_SIZE / PARTS)

/* Amount of pixels to skip off the top, bottom, left and right of the
   texture when reading back the stage */
#define TEST_INSET          4

/* Size to actually render the texture at */
#define TEXTURE_RENDER_SIZE 128
/* The size of a part once rendered */
#define PART_RENDER_SIZE    (TEXTURE_RENDER_SIZE / PARTS)

static const ClutterColor corner_colors[PARTS * PARTS] =
  {
    /* Top left     - red */    { 255, 0,   0,   255 },
    /* Top right    - green */  { 0,   255, 0,   255 },
    /* Bottom left  - blue */   { 0,   0,   255, 255 },
    /* Bottom right - yellow */ { 255, 255, 0,   255 }
  };

typedef struct _TestState
{
  guint frame;
  CoglHandle texture;
} TestState;

static gboolean
validate_part (int xnum, int ynum, const ClutterColor *color)
{
  guchar *pixels, *p;
  ClutterActor *stage = clutter_stage_get_default ();
  gboolean ret = TRUE;

  /* Read the appropriate part but skip out a few pixels around the
     edges */
  pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage),
                                      xnum * PART_RENDER_SIZE + TEST_INSET,
                                      ynum * PART_RENDER_SIZE + TEST_INSET,
                                      PART_RENDER_SIZE - TEST_INSET * 2,
                                      PART_RENDER_SIZE - TEST_INSET * 2);

  /* Make sure every pixels is the appropriate color */
  for (p = pixels;
       p < pixels + ((PART_RENDER_SIZE - TEST_INSET * 2)
                     * (PART_RENDER_SIZE - TEST_INSET * 2));
       p += 4)
    {
      if (p[0] != color->red)
        ret = FALSE;
      if (p[1] != color->green)
        ret = FALSE;
      if (p[2] != color->blue)
        ret = FALSE;
    }

  g_free (pixels);

  return ret;
}

static void
validate_result (TestState *state)
{
  /* Validate that all four corners of the texture are drawn in the
     right color */
  g_assert (validate_part (0, 0, corner_colors + 0));
  g_assert (validate_part (1, 0, corner_colors + 1));
  g_assert (validate_part (0, 1, corner_colors + 2));
  g_assert (validate_part (1, 1, corner_colors + 3));

  /* Comment this out if you want visual feedback of what this test
   * paints.
   */
  clutter_main_quit ();
}

static void
on_paint (ClutterActor *actor, TestState *state)
{
  int frame_num;

  /* Just render the texture in the top left corner */
  cogl_set_source_texture (state->texture);
  cogl_rectangle (0, 0, TEXTURE_RENDER_SIZE, TEXTURE_RENDER_SIZE);

  /* XXX: validate_result calls clutter_stage_read_pixels which will result in
   * another paint run so to avoid infinite recursion we only aim to validate
   * the first frame. */
  frame_num = state->frame++;
  if (frame_num == 1)
    validate_result (state);
}

static gboolean
queue_redraw (gpointer stage)
{
  clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));

  return TRUE;
}

static CoglHandle
make_texture (void)
{
  guchar *tex_data, *p;
  CoglHandle tex;
  int partx, party, width, height;

  p = tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);

  /* Make a texture with a different color for each part */<commit_msg>Make test-cogl-npot-texture a bit more extensive<commit_after>#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <string.h>

#include "test-conform-common.h"

static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };

/* Non-power-of-two sized texture that should cause slicing */
#define TEXTURE_SIZE        384
/* Number of times to split the texture up on each axis */
#define PARTS               2
/* The texture is split into four parts, each with a different colour */
#define PART_SIZE           (TEXTURE_SIZE / PARTS)

/* Amount of pixels to skip off the top, bottom, left and right of the
   texture when reading back the stage */
#define TEST_INSET          4

/* Size to actually render the texture at */
#define TEXTURE_RENDER_SIZE TEXTURE_SIZE
/* The size of a part once rendered */
#define PART_RENDER_SIZE    (TEXTURE_RENDER_SIZE / PARTS)

static const ClutterColor corner_colors[PARTS * PARTS] =
  {
    /* Top left     - red */    { 255, 0,   0,   255 },
    /* Top right    - green */  { 0,   255, 0,   255 },
    /* Bottom left  - blue */   { 0,   0,   255, 255 },
    /* Bottom right - yellow */ { 255, 255, 0,   255 }
  };

typedef struct _TestState
{
  guint frame;
  CoglHandle texture;
} TestState;

static gboolean
validate_part (int xnum, int ynum, const ClutterColor *color)
{
  guchar *pixels, *p;
  ClutterActor *stage = clutter_stage_get_default ();
  gboolean ret = TRUE;

  /* Read the appropriate part but skip out a few pixels around the
     edges */
  pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage),
                                      xnum * PART_RENDER_SIZE + TEST_INSET,
                                      ynum * PART_RENDER_SIZE + TEST_INSET,
                                      PART_RENDER_SIZE - TEST_INSET * 2,
                                      PART_RENDER_SIZE - TEST_INSET * 2);

  /* Make sure every pixels is the appropriate color */
  for (p = pixels;
       p < pixels + ((PART_RENDER_SIZE - TEST_INSET * 2)
                     * (PART_RENDER_SIZE - TEST_INSET * 2));
       p += 4)
    {
      if (p[0] != color->red)
        ret = FALSE;
      if (p[1] != color->green)
        ret = FALSE;
      if (p[2] != color->blue)
        ret = FALSE;
    }

  g_free (pixels);

  return ret;
}

static void
validate_result (TestState *state)
{
  /* Validate that all four corners of the texture are drawn in the
     right color */
  g_assert (validate_part (0, 0, corner_colors + 0));
  g_assert (validate_part (1, 0, corner_colors + 1));
  g_assert (validate_part (0, 1, corner_colors + 2));
  g_assert (validate_part (1, 1, corner_colors + 3));

  /* Comment this out if you want visual feedback of what this test
   * paints.
   */
  clutter_main_quit ();
}

static void
on_paint (ClutterActor *actor, TestState *state)
{
  int frame_num;
  int y, x;

  /* Just render the texture in the top left corner */
  cogl_set_source_texture (state->texture);
  /* Render the texture using four separate rectangles */
  for (y = 0; y < 2; y++)
    for (x = 0; x < 2; x++)
      cogl_rectangle_with_texture_coords (x * TEXTURE_RENDER_SIZE / 2,
                                          y * TEXTURE_RENDER_SIZE / 2,
                                          (x + 1) * TEXTURE_RENDER_SIZE / 2,
                                          (y + 1) * TEXTURE_RENDER_SIZE / 2,
                                          x / 2.0f,
                                          y / 2.0f,
                                          (x + 1) / 2.0f,
                                          (y + 1) / 2.0f);

  /* XXX: validate_result calls clutter_stage_read_pixels which will result in
   * another paint run so to avoid infinite recursion we only aim to validate
   * the first frame. */
  frame_num = state->frame++;
  if (frame_num == 1)
    validate_result (state);
}

static gboolean
queue_redraw (gpointer stage)
{
  clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));

  return TRUE;
}

static CoglHandle
make_texture (void)
{
  guchar *tex_data, *p;
  CoglHandle tex;
  int partx, party, width, height;

  p = tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);

  /* Make a texture with a different color for each part */
{'fraction_non_alphanumeric': 0.09845559845559845, 'fraction_numerical': 0.02072072072072072, 'mean_word_length': 2.2582809224318656, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3732949', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2460, 'n_words': 811}