Пример #1
0
static inline int
calculate_alignment (int rowstride)
{
  int alignment = 1 << (_cogl_util_ffs (rowstride) - 1);

  return MIN (alignment, 8);
}
static CoglBitmap *
prepare_bitmap_alignment_for_upload (CoglContext *ctx,
                                     CoglBitmap *src_bmp,
                                     CoglError **error)
{
  CoglPixelFormat format = cogl_bitmap_get_format (src_bmp);
  int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
  int src_rowstride = cogl_bitmap_get_rowstride (src_bmp);
  int width = cogl_bitmap_get_width (src_bmp);
  int alignment = 1;

  if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) ||
      src_rowstride == 0)
    return cogl_object_ref (src_bmp);

  /* Work out the alignment of the source rowstride */
  alignment = 1 << (_cogl_util_ffs (src_rowstride) - 1);
  alignment = MIN (alignment, 8);

  /* If the aligned data equals the rowstride then we can upload from
     the bitmap directly using GL_UNPACK_ALIGNMENT */
  if (((width * bpp + alignment - 1) & ~(alignment - 1)) == src_rowstride)
    return cogl_object_ref (src_bmp);
  /* Otherwise we need to copy the bitmap to pack the alignment
     because GLES has no GL_ROW_LENGTH */
  else
    return _cogl_bitmap_copy (src_bmp, error);
}
Пример #3
0
static CoglBitmap *
prepare_bitmap_alignment_for_upload (CoglBitmap *src_bmp)
{
    CoglPixelFormat format = _cogl_bitmap_get_format (src_bmp);
    int bpp = _cogl_get_format_bpp (format);
    int src_rowstride = _cogl_bitmap_get_rowstride (src_bmp);
    int width = _cogl_bitmap_get_width (src_bmp);
    int alignment = 1;

    if (src_rowstride == 0)
        return cogl_object_ref (src_bmp);

    /* Work out the alignment of the source rowstride */
    alignment = 1 << (_cogl_util_ffs (src_rowstride) - 1);
    alignment = MIN (alignment, 8);

    /* If the aligned data equals the rowstride then we can upload from
       the bitmap directly using GL_UNPACK_ALIGNMENT */
    if (((width * bpp + alignment - 1) & ~(alignment - 1)) == src_rowstride)
        return cogl_object_ref (src_bmp);
    /* Otherwise we need to copy the bitmap to pack the alignment
       because GLES has no GL_ROW_LENGTH */
    else
        return _cogl_bitmap_copy (src_bmp);
}