コード例 #1
0
static void
set_texture (MetaScreenBackground *background,
             CoglHandle            texture)
{
  MetaDisplay *display = meta_screen_get_display (background->screen);
  GSList *l;

  /* This may trigger destruction of an old texture pixmap, which, if
   * the underlying X pixmap is already gone has the tendency to trigger
   * X errors inside DRI. For safety, trap errors */
  meta_error_trap_push (display);
  if (background->texture != COGL_INVALID_HANDLE)
    {
      cogl_handle_unref (background->texture);
      background->texture = COGL_INVALID_HANDLE;
    }
  meta_error_trap_pop (display);

  if (texture != COGL_INVALID_HANDLE)
    background->texture = cogl_handle_ref (texture);

  background->texture_width = cogl_texture_get_width (background->texture);
  background->texture_height = cogl_texture_get_height (background->texture);

  for (l = background->actors; l; l = l->next)
    set_texture_on_actor (l->data);

  update_wrap_mode (background);
}
コード例 #2
0
ファイル: cogl-program.c プロジェクト: spatulasnout/cogl
void
cogl_program_attach_shader (CoglHandle program_handle,
                            CoglHandle shader_handle)
{
  CoglProgram *program;
  CoglShader *shader;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle))
    return;

  program = _cogl_program_pointer_from_handle (program_handle);
  shader = _cogl_shader_pointer_from_handle (shader_handle);

  /* Only one shader is allowed if the type is ARBfp */
  if (shader->language == COGL_SHADER_LANGUAGE_ARBFP)
    g_return_if_fail (program->attached_shaders == NULL);
  else if (shader->language == COGL_SHADER_LANGUAGE_GLSL)
    g_return_if_fail (_cogl_program_get_language (program) ==
                      COGL_SHADER_LANGUAGE_GLSL);

  program->attached_shaders
    = g_slist_prepend (program->attached_shaders,
                       cogl_handle_ref (shader_handle));

  program->age++;
}
コード例 #3
0
ファイル: lights.c プロジェクト: eliasbakken/mash
static void
add_material_color_prop (ClutterActor *table,
                         const char *name,
                         CoglHandle material,
                         MaterialColorSetFunc set_func,
                         MaterialColorGetFunc get_func)
{
  ColorProp *prop = g_slice_new (ColorProp);
  ClutterColor value;
  CoglColor cogl_color;

  prop->prop_name = NULL;
  prop->material = cogl_handle_ref (material);
  prop->object = NULL;
  prop->set_func = set_func;
  prop->get_func = get_func;

  get_func (material, &cogl_color);
  value.red = cogl_color_get_red_byte (&cogl_color);
  value.green = cogl_color_get_green_byte (&cogl_color);
  value.blue = cogl_color_get_blue_byte (&cogl_color);
  value.alpha = cogl_color_get_alpha_byte (&cogl_color);

  add_color_prop_base (table, name, prop, &value);
}
コード例 #4
0
ファイル: images.cpp プロジェクト: cebu4u/Trickplay
Images::Cache::Entry::Entry( CoglHandle _handle , const JSON::Object & _tags )
:
    handle( cogl_handle_ref( _handle ) ),
    timestamp( ::timestamp() ),
    tags( _tags )
{
	// Size in MB

	size = ( cogl_texture_get_height( TP_COGL_TEXTURE( handle ) ) * cogl_texture_get_rowstride( TP_COGL_TEXTURE( handle ) ) ) / ( 1024.0 * 1024.0 );
}
コード例 #5
0
ファイル: cogl-texture.c プロジェクト: nobled/clutter
CoglHandle
cogl_texture_ref (CoglHandle handle)
{
  if (!cogl_is_texture (handle))
    return COGL_INVALID_HANDLE;

  _COGL_HANDLE_DEBUG_REF (CoglTexture, handle);

  cogl_handle_ref (handle);

  return handle;
}
コード例 #6
0
static void
on_pixbuf_loaded (GObject      *source,
                  GAsyncResult *result,
                  gpointer      user_data)
{
  GSList *iter;
  StTextureCache *cache;
  AsyncTextureLoadData *data;
  GdkPixbuf *pixbuf;
  GError *error = NULL;
  CoglHandle texdata = NULL;

  data = user_data;
  cache = ST_TEXTURE_CACHE (source);

  g_hash_table_remove (cache->priv->outstanding_requests, data->key);

  pixbuf = load_pixbuf_async_finish (cache, result, &error);
  if (pixbuf == NULL)
    goto out;

  texdata = pixbuf_to_cogl_handle (pixbuf, data->enforced_square);

  g_object_unref (pixbuf);

  if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
    {
      gpointer orig_key, value;

      if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                         &orig_key, &value))
        {
          cogl_handle_ref (texdata);
          g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
                               texdata);
        }
    }

  for (iter = data->textures; iter; iter = iter->next)
    {
      ClutterTexture *texture = iter->data;
      set_texture_cogl_texture (texture, texdata);
    }

out:
  if (texdata)
    cogl_handle_unref (texdata);

  texture_load_data_destroy (data);
  g_free (data);

  g_clear_error (&error);
}
コード例 #7
0
static CoglHandle
st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
                                                StTextureCachePolicy policy,
                                                const gchar    *uri,
                                                int             available_width,
                                                int             available_height,
                                                GError         **error)
{
  CoglHandle texdata;
  GdkPixbuf *pixbuf;
  char *key;

  key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);

  texdata = g_hash_table_lookup (cache->priv->keyed_cache, key);

  if (texdata == NULL)
    {
      pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, error);
      if (!pixbuf)
        goto out;

      texdata = pixbuf_to_cogl_handle (pixbuf, FALSE);
      g_object_unref (pixbuf);

      if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
        {
          cogl_handle_ref (texdata);
          g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
        }
    }
  else
    cogl_handle_ref (texdata);

  ensure_monitor_for_uri (cache, uri);

out:
  g_free (key);
  return texdata;
}
コード例 #8
0
ファイル: cogl-atlas-texture.c プロジェクト: nobled/clutter
static void
_cogl_atlas_texture_pre_reorganize_foreach_cb
                                         (const CoglRectangleMapEntry *entry,
                                          void *rectangle_data,
                                          void *user_data)
{
  CoglAtlasTexture *atlas_tex = rectangle_data;

  /* Keep a reference to the texture because we don't want it to be
     destroyed during the reorganization */
  cogl_handle_ref (atlas_tex);

  /* Notify cogl-pipeline.c that the texture's underlying GL texture
   * storage is changing so it knows it may need to bind a new texture
   * if the CoglTexture is reused with the same texture unit. */
  _cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (atlas_tex));
}
コード例 #9
0
ファイル: clutter-deform-effect.c プロジェクト: rib/clutter
/**
 * clutter_deform_effect_set_back_material:
 * @effect: a #ClutterDeformEffect
 * @material: (allow-none): a handle to a Cogl material
 *
 * Sets the material that should be used when drawing the back face
 * of the actor during a deformation
 *
 * The #ClutterDeformEffect will take a reference on the material's
 * handle
 *
 * Since: 1.4
 */
void
clutter_deform_effect_set_back_material (ClutterDeformEffect *effect,
                                         CoglHandle           material)
{
  ClutterDeformEffectPrivate *priv;

  g_return_if_fail (CLUTTER_IS_DEFORM_EFFECT (effect));
  g_return_if_fail (material == COGL_INVALID_HANDLE || cogl_is_material (material));

  priv = effect->priv;

  clutter_deform_effect_free_back_material (effect);

  priv->back_material = material;
  if (priv->back_material != COGL_INVALID_HANDLE)
    cogl_handle_ref (priv->back_material);

  clutter_deform_effect_invalidate (effect);
}
コード例 #10
0
ファイル: cogl-program.c プロジェクト: spatulasnout/cogl
void
cogl_program_use (CoglHandle handle)
{
  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  g_return_if_fail (handle == COGL_INVALID_HANDLE ||
                    cogl_is_program (handle));

  if (ctx->current_program == 0 && handle != 0)
    ctx->legacy_state_set++;
  else if (handle == 0 && ctx->current_program != 0)
    ctx->legacy_state_set--;

  if (handle != COGL_INVALID_HANDLE)
    cogl_handle_ref (handle);
  if (ctx->current_program != COGL_INVALID_HANDLE)
    cogl_handle_unref (ctx->current_program);
  ctx->current_program = handle;
}
コード例 #11
0
static void
finish_texture_load (AsyncTextureLoadData *data,
                     GdkPixbuf            *pixbuf)
{
  GSList *iter;
  StTextureCache *cache;
  CoglHandle texdata = NULL;

  cache = data->cache;

  g_hash_table_remove (cache->priv->outstanding_requests, data->key);

  if (pixbuf == NULL)
    goto out;

  texdata = pixbuf_to_cogl_handle (pixbuf, data->enforced_square);

  if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
    {
      gpointer orig_key, value;

      if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                         &orig_key, &value))
        {
          cogl_handle_ref (texdata);
          g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
                               texdata);
        }
    }

  for (iter = data->textures; iter; iter = iter->next)
    {
      ClutterTexture *texture = iter->data;
      set_texture_cogl_texture (texture, texdata);
    }

out:
  if (texdata)
    cogl_handle_unref (texdata);

  texture_load_data_free (data);
}
コード例 #12
0
ファイル: glide-image.c プロジェクト: racarr/Glide
void
glide_image_set_cogl_texture (GlideImage *image,
			      CoglHandle new_texture)
{
  guint width, height;
  
  width = cogl_texture_get_width (new_texture);
  height = cogl_texture_get_height (new_texture);
  
  cogl_handle_ref (new_texture);
  
  image_free_gl_resources (image);
  
  cogl_material_set_layer (image->priv->material, 0, new_texture);
  
  image->priv->image_width = width;
  image->priv->image_height = height;
  
  cogl_handle_unref (new_texture);
}
コード例 #13
0
static void
st_scroll_view_fade_init (StScrollViewFade *self)
{
  static CoglHandle shader = COGL_INVALID_HANDLE;

  if (shader == COGL_INVALID_HANDLE)
    {
      if (clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL))
        {
          shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT);
          cogl_shader_source (shader, fade_glsl_shader);
          cogl_shader_compile (shader);
          if (!cogl_shader_is_compiled (shader))
            {
              gchar *log_buf = cogl_shader_get_info_log (shader);

              g_warning (G_STRLOC ": Unable to compile the fade shader: %s",
                         log_buf);
              g_free (log_buf);

              cogl_handle_unref (shader);
              shader = COGL_INVALID_HANDLE;
          }
        }
    }

  self->shader = shader;
  self->is_attached = FALSE;
  self->tex_uniform = -1;
  self->height_uniform = -1;
  self->width_uniform = -1;
  self->scrollbar_width_uniform = -1;
  self->scrollbar_height_uniform = -1;
  self->rtl_uniform = -1;
  self->offset_top_uniform = -1;
  self->offset_bottom_uniform = -1;
  self->fade_offset = DEFAULT_FADE_OFFSET;

  if (shader != COGL_INVALID_HANDLE)
    cogl_handle_ref (self->shader);
}
コード例 #14
0
ファイル: cogl-program.c プロジェクト: Docworld/chromiumos
void
cogl_program_attach_shader (CoglHandle program_handle,
                            CoglHandle shader_handle)
{
  CoglProgram *program;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle))
    return;

  program = _cogl_program_pointer_from_handle (program_handle);
  program->attached_shaders
    = g_slist_prepend (program->attached_shaders,
		       cogl_handle_ref (shader_handle));

  /* Whenever the shader changes we will need to relink the program
     with the fixed functionality shaders so we should forget the
     cached programs */
  _cogl_gles2_clear_cache_for_program (program);
}
コード例 #15
0
/**
 * st_texture_cache_load: (skip)
 * @cache: A #StTextureCache
 * @key: Arbitrary string used to refer to item
 * @policy: Caching policy
 * @load: Function to create the texture, if not already cached
 * @data: User data passed to @load
 * @error: A #GError
 *
 * Load an arbitrary texture, caching it.  The string chosen for @key
 * should be of the form "type-prefix:type-uuid".  For example,
 * "url:file:///usr/share/icons/hicolor/48x48/apps/firefox.png", or
 * "stock-icon:gtk-ok".
 *
 * Returns: (transfer full): A newly-referenced handle to the texture
 */
CoglHandle
st_texture_cache_load (StTextureCache       *cache,
                       const char           *key,
                       StTextureCachePolicy  policy,
                       StTextureCacheLoader  load,
                       void                 *data,
                       GError              **error)
{
  CoglHandle texture;

  texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
  if (!texture)
    {
      texture = load (cache, key, data, error);
      if (texture)
        g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
      else
        return COGL_INVALID_HANDLE;
    }
  cogl_handle_ref (texture);
  return texture;
}
コード例 #16
0
ファイル: lights.c プロジェクト: eliasbakken/mash
static void
add_material_float_prop (ClutterActor *table,
                         const char *name,
                         CoglHandle material,
                         float min,
                         float max,
                         MaterialFloatSetFunc set_func,
                         MaterialFloatGetFunc get_func)
{
  FloatProp *prop = g_slice_new (FloatProp);
  float value;

  prop->prop_name = NULL;
  prop->object = NULL;
  prop->material = cogl_handle_ref (material);
  prop->min = min;
  prop->max = max;
  prop->set_func = set_func;
  prop->get_func = get_func;

  value = get_func (material);

  add_float_prop_base (table, name, prop, value);
}
コード例 #17
0
static void
on_pixbuf_loaded (GObject      *source,
                  GAsyncResult *result,
                  gpointer      user_data)
{
  GSList *iter;
  StTextureCache *cache;
  AsyncTextureLoadData *data;
  GdkPixbuf *pixbuf;
  GError *error = NULL;
  CoglHandle texdata = NULL;

  data = user_data;
  cache = ST_TEXTURE_CACHE (source);

  g_hash_table_remove (cache->priv->outstanding_requests, data->key);

  pixbuf = load_pixbuf_async_finish (cache, result, &error);
  if (pixbuf == NULL)
    pixbuf = load_pixbuf_fallback (data);
  if (pixbuf == NULL)
    goto out;

  texdata = pixbuf_to_cogl_handle (pixbuf);

  g_object_unref (pixbuf);

  if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
    {
      gpointer orig_key, value;

      if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                         &orig_key, &value))
        {
          cogl_handle_ref (texdata);
          g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
                               texdata);
        }
    }

  for (iter = data->textures; iter; iter = iter->next)
    {
      ClutterTexture *texture = iter->data;
      set_texture_cogl_texture (texture, texdata);
    }

out:
  if (texdata)
    cogl_handle_unref (texdata);
  g_free (data->key);

  if (data->icon)
    {
      gtk_icon_info_free (data->icon_info);
      g_object_unref (data->icon);
    }
  else if (data->uri)
    g_free (data->uri);

  if (data->recent_info)
    gtk_recent_info_unref (data->recent_info);
  if (data->mimetype)
    g_free (data->mimetype);

  /* Alternatively we could weakref and just do nothing if the texture
     is destroyed */
  for (iter = data->textures; iter; iter = iter->next)
    {
      ClutterTexture *texture = iter->data;
      g_object_unref (texture);
    }

  g_clear_error (&error);
  g_free (data);
}
コード例 #18
0
ファイル: cogl-clip-stack.c プロジェクト: gramozeka/GSB-NEW
void
add_stencil_clip_rectangle (float x_1,
                            float y_1,
                            float x_2,
                            float y_2,
                            gboolean first)
{
  CoglHandle current_source;
  CoglHandle framebuffer = _cogl_get_framebuffer ();

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  /* We don't log changes to the stencil buffer so need to flush any
   * batched geometry before we start... */
  _cogl_journal_flush ();

  _cogl_framebuffer_flush_state (framebuffer, 0);

  /* temporarily swap in our special stenciling material */
  current_source = cogl_handle_ref (ctx->source_material);
  cogl_set_source (ctx->stencil_material);

  if (first)
    {
      GE( glEnable (GL_STENCIL_TEST) );

      /* Initially disallow everything */
      GE( glClearStencil (0) );
      GE( glClear (GL_STENCIL_BUFFER_BIT) );

      /* Punch out a hole to allow the rectangle */
      GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
      GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );

      cogl_rectangle (x_1, y_1, x_2, y_2);
    }
  else
    {
      CoglMatrixStack *modelview_stack =
        _cogl_framebuffer_get_modelview_stack (framebuffer);
      CoglMatrixStack *projection_stack =
        _cogl_framebuffer_get_projection_stack (framebuffer);

      /* Add one to every pixel of the stencil buffer in the
	 rectangle */
      GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
      GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
      cogl_rectangle (x_1, y_1, x_2, y_2);

      /* make sure our rectangle hits the stencil buffer before we
       * change the stencil operation */
      _cogl_journal_flush ();

      /* Subtract one from all pixels in the stencil buffer so that
	 only pixels where both the original stencil buffer and the
	 rectangle are set will be valid */
      GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );

      _cogl_matrix_stack_push (projection_stack);
      _cogl_matrix_stack_load_identity (projection_stack);

      _cogl_matrix_stack_push (modelview_stack);
      _cogl_matrix_stack_load_identity (modelview_stack);

      cogl_rectangle (-1.0, -1.0, 1.0, 1.0);

      _cogl_matrix_stack_pop (modelview_stack);
      _cogl_matrix_stack_pop (projection_stack);
    }

  /* make sure our rectangles hit the stencil buffer before we restore
   * the stencil function / operation */
  _cogl_journal_flush ();

  /* Restore the stencil mode */
  GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
  GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );

  /* restore the original source material */
  cogl_set_source (current_source);
  cogl_handle_unref (current_source);
}
コード例 #19
0
void
_cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
                                      CoglHandle texture,
                                      float x_1, float y_1,
                                      float x_2, float y_2,
                                      float tx_1, float ty_1,
                                      float tx_2, float ty_2)
{
  CoglPangoDisplayListNode *node;
  CoglPangoDisplayListVertex *verts;

  /* Add to the last node if it is a texture node with the same
     target texture */
  if (dl->last_node
      && (node = dl->last_node->data)->type == COGL_PANGO_DISPLAY_LIST_TEXTURE
      && node->d.texture.texture == texture
      && (dl->color_override
          ? (node->color_override && cogl_color_equal (&dl->color, &node->color))
          : !node->color_override))
    {
      /* Get rid of the vertex buffer so that it will be recreated */
      if (node->d.texture.vertex_buffer != COGL_INVALID_HANDLE)
        {
          cogl_handle_unref (node->d.texture.vertex_buffer);
          node->d.texture.vertex_buffer = COGL_INVALID_HANDLE;
        }
    }
  else
    {
      /* Otherwise create a new node */
      node = g_slice_new (CoglPangoDisplayListNode);

      node->type = COGL_PANGO_DISPLAY_LIST_TEXTURE;
      node->color_override = dl->color_override;
      node->color = dl->color;
      node->pipeline = NULL;
      node->d.texture.texture = cogl_handle_ref (texture);
      node->d.texture.verts
        = g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListVertex));
      node->d.texture.vertex_buffer = COGL_INVALID_HANDLE;

      _cogl_pango_display_list_append_node (dl, node);
    }

  g_array_set_size (node->d.texture.verts,
                    node->d.texture.verts->len + 4);
  verts = &g_array_index (node->d.texture.verts,
                          CoglPangoDisplayListVertex,
                          node->d.texture.verts->len - 4);

  verts->x = x_1;
  verts->y = y_1;
  verts->t_x = tx_1;
  verts->t_y = ty_1;
  verts++;
  verts->x = x_1;
  verts->y = y_2;
  verts->t_x = tx_1;
  verts->t_y = ty_2;
  verts++;
  verts->x = x_2;
  verts->y = y_2;
  verts->t_x = tx_2;
  verts->t_y = ty_2;
  verts++;
  verts->x = x_2;
  verts->y = y_1;
  verts->t_x = tx_2;
  verts->t_y = ty_1;
}