[cogl/wip/cogl-1.14: 80/177] sync cogl-blit and cogl-texture with master



commit 7f5efb737c0a608afc08e700efb29705479fc81f
Author: Robert Bragg <robert linux intel com>
Date:   Fri Jan 18 19:32:24 2013 +0000

    sync cogl-blit and cogl-texture with master
    
    This synchronizes parts of cogl-blit.c and cogl-texture.c with the
    master branch to help with cherry picking patches.

 cogl/cogl-blit.c    |   30 +++++++++++-----------
 cogl/cogl-blit.h    |    5 +++
 cogl/cogl-texture.c |   68 +++++++++++++++++++++++++-------------------------
 3 files changed, 54 insertions(+), 49 deletions(-)
---
diff --git a/cogl/cogl-blit.c b/cogl/cogl-blit.c
index 6e6ca88..50bdf9a 100644
--- a/cogl/cogl-blit.c
+++ b/cogl/cogl-blit.c
@@ -63,8 +63,7 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
       return FALSE;
     }
 
-  cogl_push_framebuffer (fb);
-  cogl_object_unref (fb);
+  data->fb = fb;
 
   dst_width = cogl_texture_get_width (data->dst_tex);
   dst_height = cogl_texture_get_height (data->dst_tex);
@@ -97,7 +96,7 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
 
   cogl_pipeline_set_layer_texture (pipeline, 0, data->src_tex);
 
-  _cogl_push_source (pipeline, FALSE);
+  data->pipeline = pipeline;
 
   return TRUE;
 }
@@ -111,15 +110,17 @@ _cogl_blit_texture_render_blit (CoglBlitData *data,
                                 unsigned int width,
                                 unsigned int height)
 {
-  cogl_rectangle_with_texture_coords (dst_x, dst_y,
-                                      dst_x + width,
-                                      dst_y + height,
-                                      src_x / (float) data->src_width,
-                                      src_y / (float) data->src_height,
-                                      (src_x + width) /
-                                      (float) data->src_width,
-                                      (src_y + height) /
-                                      (float) data->src_height);
+  cogl_framebuffer_draw_textured_rectangle (data->fb,
+                                            data->pipeline,
+                                            dst_x, dst_y,
+                                            dst_x + width,
+                                            dst_y + height,
+                                            src_x / (float) data->src_width,
+                                            src_y / (float) data->src_height,
+                                            (src_x + width) /
+                                            (float) data->src_width,
+                                            (src_y + height) /
+                                            (float) data->src_height);
 }
 
 static void
@@ -127,9 +128,6 @@ _cogl_blit_texture_render_end (CoglBlitData *data)
 {
   CoglContext *ctx = data->src_tex->context;
 
-  cogl_pop_source ();
-  cogl_pop_framebuffer ();
-
   /* Attach the target texture to the texture render pipeline so that
      we don't keep a reference to the source texture forever. This is
      assuming that the destination texture will live for a long time
@@ -140,6 +138,8 @@ _cogl_blit_texture_render_end (CoglBlitData *data)
      hash table key such as for the ARBfp program cache. */
   cogl_pipeline_set_layer_texture (ctx->blit_texture_pipeline, 0,
                                    data->dst_tex);
+
+  cogl_object_unref (data->fb);
 }
 
 static CoglBool
diff --git a/cogl/cogl-blit.h b/cogl/cogl-blit.h
index d56137a..364e9b1 100644
--- a/cogl/cogl-blit.h
+++ b/cogl/cogl-blit.h
@@ -27,6 +27,7 @@
 #include <glib.h>
 #include "cogl-object-private.h"
 #include "cogl-texture.h"
+#include "cogl-framebuffer.h"
 
 /* This structures and functions are used when a series of blits needs
    to be performed between two textures. In this case there are
@@ -67,7 +68,11 @@ struct _CoglBlitData
      complete texture data in */
   unsigned char *image_data;
   CoglPixelFormat format;
+
   int bpp;
+
+  CoglFramebuffer *fb;
+  CoglPipeline *pipeline;
 };
 
 void
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index e5fe460..d226a9d 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -761,19 +761,20 @@ cogl_texture_set_region (CoglTexture *texture,
  * glGetTexImage, but may be used as a fallback in some circumstances.
  */
 static void
-do_texture_draw_and_read (CoglTexture *texture,
-                          CoglBitmap  *target_bmp,
-                          float       *viewport)
+do_texture_draw_and_read (CoglFramebuffer *fb,
+                          CoglPipeline *pipeline,
+                          CoglTexture *texture,
+                          CoglBitmap *target_bmp,
+                          float *viewport)
 {
-  float       rx1, ry1;
-  float       rx2, ry2;
-  float       tx1, ty1;
-  float       tx2, ty2;
-  int         bw,  bh;
-  CoglBitmap  *rect_bmp;
-  unsigned int  tex_width, tex_height;
-
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+  float rx1, ry1;
+  float rx2, ry2;
+  float tx1, ty1;
+  float tx2, ty2;
+  int bw,  bh;
+  CoglBitmap *rect_bmp;
+  unsigned int tex_width, tex_height;
+  CoglContext *ctx = fb->context;
 
   tex_width = cogl_texture_get_width (texture);
   tex_height = cogl_texture_get_height (texture);
@@ -813,11 +814,13 @@ do_texture_draw_and_read (CoglTexture *texture,
           tx2 = (rx2 / (float) tex_width);
 
           /* Draw a portion of texture */
-          cogl_rectangle_with_texture_coords (0, 0,
-                                              rx2 - rx1,
-                                              ry2 - ry1,
-                                              tx1, ty1,
-                                              tx2, ty2);
+          cogl_framebuffer_draw_textured_rectangle (fb,
+                                                    pipeline,
+                                                    0, 0,
+                                                    rx2 - rx1,
+                                                    ry2 - ry1,
+                                                    tx1, ty1,
+                                                    tx2, ty2);
 
           /* Read into a temporary bitmap */
           rect_bmp = _cogl_bitmap_new_with_malloc_buffer
@@ -826,7 +829,7 @@ do_texture_draw_and_read (CoglTexture *texture,
                                                COGL_PIXEL_FORMAT_RGBA_8888_PRE);
 
           cogl_framebuffer_read_pixels_into_bitmap
-                                   (cogl_get_draw_framebuffer (),
+                                   (fb,
                                     viewport[0], viewport[1],
                                     COGL_READ_PIXELS_COLOR_BUFFER,
                                     rect_bmp);
@@ -853,23 +856,21 @@ do_texture_draw_and_read (CoglTexture *texture,
  */
 CoglBool
 _cogl_texture_draw_and_read (CoglTexture *texture,
-                             CoglBitmap  *target_bmp,
-                             GLuint       target_gl_format,
-                             GLuint       target_gl_type)
+                             CoglBitmap *target_bmp,
+                             GLuint target_gl_format,
+                             GLuint target_gl_type)
 {
-  int        bpp;
-  CoglFramebuffer *framebuffer;
+  int bpp;
+  CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
   float viewport[4];
   CoglBitmap *alpha_bmp;
   int target_width = cogl_bitmap_get_width (target_bmp);
   int target_height = cogl_bitmap_get_height (target_bmp);
   int target_rowstride = cogl_bitmap_get_rowstride (target_bmp);
-
-  _COGL_GET_CONTEXT (ctx, FALSE);
+  CoglContext *ctx = framebuffer->context;
 
   bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888);
 
-  framebuffer = cogl_get_draw_framebuffer ();
   /* Viewport needs to have some size and be inside the window for this */
   cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
   if (viewport[0] <  0 || viewport[1] <  0 ||
@@ -900,8 +901,6 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
                                NULL);
     }
 
-  _cogl_push_source (ctx->texture_download_pipeline, FALSE);
-
   cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, texture);
 
   cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
@@ -913,7 +912,9 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
                                    COGL_PIPELINE_FILTER_NEAREST,
                                    COGL_PIPELINE_FILTER_NEAREST);
 
-  do_texture_draw_and_read (texture, target_bmp, viewport);
+  do_texture_draw_and_read (framebuffer,
+                            ctx->texture_download_pipeline,
+                            texture, target_bmp, viewport);
 
   /* Check whether texture has alpha and framebuffer not */
   /* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
@@ -955,7 +956,9 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
                                        "RGBA = REPLACE (TEXTURE[A])",
                                        NULL);
 
-      do_texture_draw_and_read (texture, alpha_bmp, viewport);
+      do_texture_draw_and_read (framebuffer,
+                                ctx->texture_download_pipeline,
+                                texture, alpha_bmp, viewport);
 
       /* Copy temp R to target A */
 
@@ -986,9 +989,6 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
   cogl_framebuffer_pop_matrix (framebuffer);
   _cogl_framebuffer_pop_projection (framebuffer);
 
-  /* restore the original pipeline */
-  cogl_pop_source ();
-
   return TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]