Esempio n. 1
0
static void
update_wrap_mode_of_actor (MetaBackgroundActor *self)
{
  MetaBackgroundActorPrivate *priv = self->priv;

  cogl_material_set_layer_wrap_mode (priv->material, 0, priv->background->wrap_mode);
}
Esempio n. 2
0
void
meta_background_set_layer_wrap_mode (MetaBackground       *self,
                                     CoglMaterialWrapMode  wrap_mode)
{
  MetaBackgroundPrivate *priv = self->priv;

  cogl_material_set_layer_wrap_mode (priv->material, 0, wrap_mode);
}
static void
mnb_toolbar_background_paint_background (MxWidget           *self,
                                         ClutterActor       *background,
                                         const ClutterColor *color)
{
  MnbToolbarBackgroundPrivate *priv = TOOLBAR_BACKGROUND_PRIVATE (self);
  ClutterActor *actor = (ClutterActor *) self;
  CoglHandle cogl_texture, cogl_material;
  ClutterActorBox box = { 0, };
  gfloat width, height;
  gfloat tex_width, tex_height;
  gfloat ex, ey;
  gfloat tx1, ty1, tx2, ty2;
  guint8 opacity;

  /* Copied from MxWidget:
   *
   * Default implementation just draws the background
   * colour and the image on top
   */
  if (color && color->alpha != 0)
    {
      ClutterColor bg_color = *color;

      bg_color.alpha = clutter_actor_get_paint_opacity (actor)
                       * bg_color.alpha
                       / 255;

      clutter_actor_get_allocation_box (actor, &box);

      width = box.x2 - box.x1;
      height = box.y2 - box.y1;

      cogl_set_source_color4ub (bg_color.red,
                                bg_color.green,
                                bg_color.blue,
                                bg_color.alpha);
      cogl_rectangle (0, 0, width, height);
    }

  /*
   * Copied from MxTextureFrame
   */

  /* no need to paint stuff if we don't have a texture */
  if (G_UNLIKELY (priv->parent_texture == NULL))
    return;

  cogl_texture = clutter_texture_get_cogl_texture (priv->parent_texture);
  if (cogl_texture == COGL_INVALID_HANDLE)
    return;
  cogl_material = clutter_texture_get_cogl_material (priv->parent_texture);
  if (cogl_material == COGL_INVALID_HANDLE)
    return;

  tex_width  = cogl_texture_get_width (cogl_texture);
  tex_height = cogl_texture_get_height (cogl_texture);

  clutter_actor_get_allocation_box (actor, &box);
  width = box.x2 - box.x1;
  height = box.y2 - box.y1;

  opacity = clutter_actor_get_paint_opacity (actor);

  /* Paint using the parent texture's material. It should already have
     the cogl texture set as the first layer */
  /* NB: for correct blending we need set a preumultiplied color here: */
  cogl_material_set_color4ub (cogl_material,
                              opacity, opacity, opacity, opacity);

  selector_texture = mnb_toolbar_get_selector_texture (priv->toolbar);

  cogl_material_set_layer (cogl_material, 1, selector_texture);
  cogl_material_set_layer_wrap_mode (cogl_material, 1,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  if (!cogl_material_set_layer_combine (cogl_material, 1,
                                        "RGBA = MODULATE(PREVIOUS,TEXTURE)",
                                        &error))
    {
      g_warning (G_STRLOC ": Error setting layer combine blend string: %s",
                 error->message);
      g_error_free (error);
    }

  cogl_set_source (cogl_material);

  /* simple stretch */
  if (priv->left == 0 && priv->right == 0 && priv->top == 0
      && priv->bottom == 0)
    {
      float spot_width, spot_height;
      float coords[8] = {
        0, 0, 1, 1,
        0, 0, 0, 0
      };

      mnb_toolbar_get_selector_allocation_box (priv->toolbar, &box);
      spot_width = box.x2 - box.x1;
      spot_height = box.y2 - box.y1;
      coords[4] = -(box.x1 / width) * (width / spot_width);
      coords[5] = -(box.y1 / height) * (height / spot_height);
      coords[6] = width / spot_width - (box.x1 / width) * (width / spot_width);
      coords[7] = height / spot_height - (box.y1 / height) * (height / spot_height);
      cogl_rectangle_with_multitexture_coords (0, 0, width, height, coords, 8);
      return;
    }

  tx1 = priv->left / tex_width;
  tx2 = (tex_width - priv->right) / tex_width;
  ty1 = priv->top / tex_height;
  ty2 = (tex_height - priv->bottom) / tex_height;

  ex = width - priv->right;
  if (ex < priv->left)
    ex = priv->left;

  ey = height - priv->bottom;
  if (ey < priv->top)
    ey = priv->top;

  {
    GLfloat rectangles[] =
    {
      /* top left corner */
      0, 0,
      priv->left, priv->top,
      0.0, 0.0,
      tx1, ty1,

      /* top middle */
      priv->left, 0,
      MAX (priv->left, ex), priv->top,
      tx1, 0.0,
      tx2, ty1,

      /* top right */
      ex, 0,
      MAX (ex + priv->right, width), priv->top,
      tx2, 0.0,
      1.0, ty1,

      /* mid left */
      0, priv->top,
      priv->left,  ey,
      0.0, ty1,
      tx1, ty2,

      /* center */
      priv->left, priv->top,
      ex, ey,
      tx1, ty1,
      tx2, ty2,

      /* mid right */
      ex, priv->top,
      MAX (ex + priv->right, width), ey,
      tx2, ty1,
      1.0, ty2,

      /* bottom left */
      0, ey,
      priv->left, MAX (ey + priv->bottom, height),
      0.0, ty2,
      tx1, 1.0,

      /* bottom center */
      priv->left, ey,
      ex, MAX (ey + priv->bottom, height),
      tx1, ty2,
      tx2, 1.0,

      /* bottom right */
      ex, ey,
      MAX (ex + priv->right, width), MAX (ey + priv->bottom, height),
      tx2, ty2,
      1.0, 1.0
    };

    cogl_rectangles_with_texture_coords (rectangles, 9);
  }
}
Esempio n. 4
0
static void
mnb_toolbar_shadow_paint (ClutterActor *self)
{
  MnbToolbarShadowPrivate *priv = MNB_TOOLBAR_SHADOW (self)->priv;
  CoglHandle cogl_texture = COGL_INVALID_HANDLE;
  CoglHandle cogl_material = COGL_INVALID_HANDLE;
  ClutterActorBox box = { 0, };
  gfloat width, height;
  gfloat tex_width, tex_height;
  gfloat ex, ey;
  gfloat tx1, ty1, tx2, ty2;
  guint8 opacity;

  /* no need to paint stuff if we don't have a texture */
  if (G_UNLIKELY (priv->parent_texture == NULL))
    return;

  /* parent texture may have been hidden, so need to make sure it gets
   * realized
   */
  if (!CLUTTER_ACTOR_IS_REALIZED (priv->parent_texture))
    clutter_actor_realize (CLUTTER_ACTOR (priv->parent_texture));

  cogl_texture = clutter_texture_get_cogl_texture (priv->parent_texture);
  if (cogl_texture == COGL_INVALID_HANDLE)
    return;
  cogl_material = clutter_texture_get_cogl_material (priv->parent_texture);
  if (cogl_material == COGL_INVALID_HANDLE)
    return;

  tex_width  = cogl_texture_get_width (cogl_texture);
  tex_height = cogl_texture_get_height (cogl_texture);

  clutter_actor_get_allocation_box (self, &box);
  width = box.x2 - box.x1;
  height = box.y2 - box.y1;


  opacity = clutter_actor_get_paint_opacity (self);

  /* Paint using the parent texture's material. It should already have
     the cogl texture set as the first layer */
  /* NB: for correct blending we need set a preumultiplied color here: */
  cogl_material_set_color4ub (cogl_material,
                              opacity, opacity, opacity, opacity);

#if TOOLBAR_CUT_OUT
  selector_texture = mnb_toolbar_get_selector_texture (priv->toolbar);
  cogl_material_set_layer (cogl_material, 1, selector_texture);
  cogl_material_set_layer_wrap_mode (cogl_material, 1,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  if (!cogl_material_set_layer_combine (cogl_material, 1,
                                        "RGBA = MODULATE(PREVIOUS,TEXTURE)",
                                        &error))
    {
      g_warning (G_STRLOC ": Error setting layer combine blend string: %s",
                 error->message);
      g_error_free (error);
    }
#endif

  cogl_set_source (cogl_material);

  /* simple stretch */
  if (priv->left == 0 && priv->right == 0 && priv->top == 0
      && priv->bottom == 0)
    {
#if TOOLBAR_CUT_OUT
      float spot_width, spot_height;
      float coords[8] = {
        0, 0, 1, 1,
        0, 0, 0, 0
      };

      mnb_toolbar_get_selector_allocation_box (priv->toolbar, &box);
      spot_width = box.x2 - box.x1;
      spot_height = box.y2 - box.y1;
      coords[4] = -(box.x1 / width) * (width / spot_width);
      coords[5] = -(box.y1 + SHADOW_CUT_OUT_OFFSET / height) * (height / spot_height);
      coords[6] = width / spot_width - (box.x1 / width) * (width / spot_width);
      coords[7] = height / spot_height -
        (box.y1 + SHADOW_CUT_OUT_OFFSET / height) * (height / spot_height);
      cogl_rectangle_with_multitexture_coords (0, 0, width, height, coords, 8);
#else
      cogl_rectangle (0, 0, width, height);
#endif /* TOOLBAR_CUT_OUT */
      return;
    }

  tx1 = priv->left / tex_width;
  tx2 = (tex_width - priv->right) / tex_width;
  ty1 = priv->top / tex_height;
  ty2 = (tex_height - priv->bottom) / tex_height;

  ex = width - priv->right;
  if (ex < priv->left)
    ex = priv->left;

  ey = height - priv->bottom;
  if (ey < priv->top)
    ey = priv->top;


  {
    GLfloat rectangles[] =
    {
      /* top left corner */
      0, 0,
      priv->left, priv->top,
      0.0, 0.0,
      tx1, ty1,

      /* top middle */
      priv->left, 0,
      MAX (priv->left, ex), priv->top,
      tx1, 0.0,
      tx2, ty1,

      /* top right */
      ex, 0,
      MAX (ex + priv->right, width), priv->top,
      tx2, 0.0,
      1.0, ty1,

      /* mid left */
      0, priv->top,
      priv->left,  ey,
      0.0, ty1,
      tx1, ty2,

      /* center */
      priv->left, priv->top,
      ex, ey,
      tx1, ty1,
      tx2, ty2,

      /* mid right */
      ex, priv->top,
      MAX (ex + priv->right, width), ey,
      tx2, ty1,
      1.0, ty2,

      /* bottom left */
      0, ey,
      priv->left, MAX (ey + priv->bottom, height),
      0.0, ty2,
      tx1, 1.0,

      /* bottom center */
      priv->left, ey,
      ex, MAX (ey + priv->bottom, height),
      tx1, ty2,
      tx2, 1.0,

      /* bottom right */
      ex, ey,
      MAX (ex + priv->right, width), MAX (ey + priv->bottom, height),
      tx2, ty2,
      1.0, 1.0
    };

    cogl_rectangles_with_texture_coords (rectangles, 9);
  }
}
Esempio n. 5
0
static void
cd_icc_effect_paint_target (ClutterOffscreenEffect *effect)
{
  CdIccEffect *self = CD_ICC_EFFECT (effect);
  ClutterOffscreenEffectClass *parent;
  CoglHandle material;
  CoglHandle color_data;
  CoglHandle indirect_texture;
  GError *error = NULL;

  if (self->program == COGL_INVALID_HANDLE)
    goto out;

  if (self->main_texture_uniform > -1)
    cogl_program_set_uniform_1i (self->program,
                                 self->main_texture_uniform,
                                 0);

  if (self->color_data1_uniform > -1)
    cogl_program_set_uniform_1i (self->program,
                                 self->color_data1_uniform,
                                 1); /* not the layer number, just co-incidence */
  if (self->color_data2_uniform > -1)
    cogl_program_set_uniform_1i (self->program,
                                 self->color_data2_uniform,
                                 2);

  if (self->indirect_texture_uniform > -1)
    cogl_program_set_uniform_1i (self->program,
                                 self->indirect_texture_uniform,
                                 3);

  material = clutter_offscreen_effect_get_target (effect);




  /* get the color textures */
  color_data = cd_icc_effect_generate_cogl_color_data ("/usr/share/color/icc/FakeBRG.icc",
                                                       &error);
  if (color_data == COGL_INVALID_HANDLE)
    {
      g_warning ("Error creating lookup texture: %s", error->message);
      g_error_free (error);
      goto out;
    }

  /* add the texture into the second layer of the material */
  cogl_material_set_layer (material, GCM_FSCM_LAYER_COLOR1, color_data);

  /* we want to use linear interpolation for the texture */
  cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_COLOR1,
                                   COGL_MATERIAL_FILTER_LINEAR,
                                   COGL_MATERIAL_FILTER_LINEAR);

  /* clamp to the maximum values */
  cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_COLOR1,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_handle_unref (color_data);





  /* get the color textures */
  color_data = cd_icc_effect_generate_cogl_color_data ("/usr/share/color/icc/FakeRBG.icc",
                                                        &error);
  if (color_data == COGL_INVALID_HANDLE)
    {
      g_warning ("Error creating lookup texture: %s", error->message);
      g_error_free (error);
      goto out;
    }

  /* add the texture into the second layer of the material */
  cogl_material_set_layer (material, GCM_FSCM_LAYER_COLOR2, color_data);

  /* we want to use linear interpolation for the texture */
  cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_COLOR2,
                                   COGL_MATERIAL_FILTER_LINEAR,
                                   COGL_MATERIAL_FILTER_LINEAR);

  /* clamp to the maximum values */
  cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_COLOR2,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_handle_unref (color_data);





  /* get the indirect texture */
  indirect_texture = cd_icc_effect_generate_indirect_data (self, &error);
  if (indirect_texture == COGL_INVALID_HANDLE)
    {
      g_warning ("Error creating indirect texture: %s", error->message);
      g_error_free (error);
      goto out;
    }

  /* add the texture into the second layer of the material */
  cogl_material_set_layer (material, GCM_FSCM_LAYER_INDIRECT, indirect_texture);

  /* we want to use linear interpolation for the texture */
  cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_INDIRECT,
                                   COGL_MATERIAL_FILTER_LINEAR,
                                   COGL_MATERIAL_FILTER_LINEAR);

  /* clamp to the maximum values */
  cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_INDIRECT,
                                     COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);

  cogl_handle_unref (indirect_texture);

  cogl_material_set_user_program (material, self->program);

out:
  parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (cd_icc_effect_parent_class);
  parent->paint_target (effect);
}