Trim trailing white spaces.
[geeqie.git] / src / renderer-clutter.c
index 7dd0b2d..0369980 100644 (file)
@@ -29,6 +29,7 @@
 
 /* for 3d texture */
 #define COGL_ENABLE_EXPERIMENTAL_API
+#define CLUTTER_ENABLE_EXPERIMENTAL_API
 
 #include <clutter/clutter.h>
 
@@ -128,7 +129,7 @@ static void rc_set_shader(CoglHandle material)
   cogl_shader_source (shader,
   "vec3 checker(vec2 texc, vec3 color0, vec3 color1)                                           \n"
   "{                                                                                           \n"
-  "  if (mod(int(floor(texc.x) + floor(texc.y)), 2) == 0)                                      \n"
+  "  if (mod(floor(texc.x) + floor(texc.y), 2.0) == 0.0)                                       \n"
   "    return color0;                                                                          \n"
   "  else                                                                                      \n"
   "    return color1;                                                                          \n"
@@ -141,11 +142,11 @@ static void rc_set_shader(CoglHandle material)
   "                                                                                            \n"
   "void main(void)                                                                             \n"
   "{                                                                                           \n"
-  "    vec3 bg = checker(gl_FragCoord.xy / 16, vec3(0.6, 0.6, 0.6), vec3(0.4, 0.4, 0.4));      \n"
+  "    vec3 bg = checker(gl_FragCoord.xy / 16.0, vec3(0.6, 0.6, 0.6), vec3(0.4, 0.4, 0.4));    \n"
   "    vec4 img4 = texture2D(tex, gl_TexCoord[0].xy);                                          \n"
-  "    vec3 img3 = img4.rgb;                                                                   \n"
+  "    vec3 img3 = img4.bgr;                                                                   \n"
   "    img3 = img3 * scale + offset;                                                           \n"
-  "    img3 = texture3D(clut, img3);                                                           \n"
+  "    img3 = texture3D(clut, img3).rgb;                                                               \n"
   "                                                                                            \n"
   "    gl_FragColor = vec4(img3 * img4.a + bg * (1.0 - img4.a), 1.0);                          \n"
   "}                                                                                           \n"
@@ -188,11 +189,11 @@ static void rc_prepare_post_process_lut(RendererClutter *rc)
        
        DEBUG_0("%s clut start", get_exec_time());
 
-       for (r = 0; r < CLUT_SIZE; r++) 
+       for (r = 0; r < CLUT_SIZE; r++)
                {
-               for (g = 0; g < CLUT_SIZE; g++) 
+               for (g = 0; g < CLUT_SIZE; g++)
                        {
-                       for (b = 0; b < CLUT_SIZE; b++) 
+                       for (b = 0; b < CLUT_SIZE; b++)
                                {
                                guchar *ptr = clut + ((b * CLUT_SIZE + g) * CLUT_SIZE + r) * 3;
                                ptr[0] = floor ((double) r / (CLUT_SIZE - 1) * 255.0 + 0.5);
@@ -213,7 +214,20 @@ static void rc_prepare_post_process_lut(RendererClutter *rc)
        g_object_unref(tmp_pixbuf);
 
        DEBUG_0("%s clut upload start", get_exec_time());
-       
+#if CLUTTER_CHECK_VERSION(1,10,0)
+       {
+       CoglContext *ctx = clutter_backend_get_cogl_context(clutter_get_default_backend ());
+
+       tex3d = cogl_texture_3d_new_from_data(ctx,
+                                             CLUT_SIZE, CLUT_SIZE, CLUT_SIZE,
+                                             COGL_PIXEL_FORMAT_RGB_888,
+                                             COGL_PIXEL_FORMAT_RGB_888,
+                                             CLUT_SIZE * 3,
+                                             CLUT_SIZE * CLUT_SIZE * 3,
+                                             clut,
+                                             NULL);
+       }
+#else
        tex3d = cogl_texture_3d_new_from_data(CLUT_SIZE, CLUT_SIZE, CLUT_SIZE,
                                              COGL_TEXTURE_NONE,
                                              COGL_PIXEL_FORMAT_RGB_888,
@@ -222,6 +236,7 @@ static void rc_prepare_post_process_lut(RendererClutter *rc)
                                              CLUT_SIZE * CLUT_SIZE * 3,
                                              clut,
                                              NULL);
+#endif
        material = clutter_texture_get_cogl_material(CLUTTER_TEXTURE(rc->texture));
        cogl_material_set_layer(material, 1, tex3d);
        cogl_handle_unref(tex3d);
@@ -242,7 +257,7 @@ static void rc_sync_actor(RendererClutter *rc)
        DEBUG_0("scale %d %d", rc->pr->width, rc->pr->height);
        DEBUG_0("pos   %d %d", rc->pr->x_offset, rc->pr->y_offset);
        
-       clutter_actor_set_scale(CLUTTER_ACTOR(rc->texture), 
+       clutter_actor_set_scale(CLUTTER_ACTOR(rc->texture),
                                (gfloat)pr->width / pr->image_width,
                                (gfloat)pr->height / pr->image_height);
                                
@@ -339,8 +354,8 @@ static void rc_sync_actor(RendererClutter *rc)
                        break;
                }
        
-       clutter_actor_set_position(CLUTTER_ACTOR(rc->texture), 
-                               pr->x_offset - pr->x_scroll + anchor_x, 
+       clutter_actor_set_position(CLUTTER_ACTOR(rc->texture),
+                               pr->x_offset - pr->x_scroll + anchor_x,
                                pr->y_offset - pr->y_scroll + anchor_y);
 
 }
@@ -378,13 +393,16 @@ static void rc_schedule_texture_upload(RendererClutter *rc)
 {
        if (g_get_monotonic_time() - rc->last_pixbuf_change < 50000)
                {
-               /* delay clutter redraw until the texture has some data 
+               /* delay clutter redraw until the texture has some data
                   set priority between gtk redraw and clutter redraw */
+               DEBUG_0("%s tex upload high prio", get_exec_time());
                rc->idle_update = g_idle_add_full(CLUTTER_PRIORITY_REDRAW - 10, rc_area_changed_cb, rc, NULL);
                }
        else
                {
                /* higher prio than histogram */
+               DEBUG_0("%s tex upload low prio", get_exec_time());
+
                rc->idle_update = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 5, rc_area_changed_cb, rc, NULL);
                }
 }
@@ -415,7 +433,7 @@ static gboolean rc_area_changed_cb(gpointer data)
                                        h,
                                        par->w,
                                        h,
-                                       gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
+                                       gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
                                        gdk_pixbuf_get_rowstride(pr->pixbuf),
                                        gdk_pixbuf_get_pixels(pr->pixbuf));
                }
@@ -457,7 +475,7 @@ static void rc_area_changed(void *renderer, gint src_x, gint src_y, gint src_w,
        gint width = gdk_pixbuf_get_width(pr->pixbuf);
        gint height = gdk_pixbuf_get_height(pr->pixbuf);
                
-       if (pr->stereo_data == STEREO_PIXBUF_SBS || pr->stereo_data == STEREO_PIXBUF_CROSS) 
+       if (pr->stereo_data == STEREO_PIXBUF_SBS || pr->stereo_data == STEREO_PIXBUF_CROSS)
                        {
                        width /= 2;
                        }
@@ -473,7 +491,7 @@ static void rc_area_changed(void *renderer, gint src_x, gint src_y, gint src_w,
        par->w = src_w;
        par->h = src_h;
        rc->pending_updates = g_list_append(rc->pending_updates, par);
-       if (!rc->idle_update) 
+       if (!rc->idle_update)
                {
                rc_schedule_texture_upload(rc);
                }
@@ -499,15 +517,20 @@ static void rc_update_pixbuf(void *renderer, gboolean lazy)
        DEBUG_0("rc_update_pixbuf");
 
        rc_remove_pending_updates(rc);
+
+       rc->last_pixbuf_change = g_get_monotonic_time();
+       DEBUG_0("%s change time reset", get_exec_time());
        
        if (pr->pixbuf)
                {
                gint width = gdk_pixbuf_get_width(pr->pixbuf);
                gint height = gdk_pixbuf_get_height(pr->pixbuf);
+
+               DEBUG_0("pixbuf size %d x %d (%d)", width, height, gdk_pixbuf_get_has_alpha(pr->pixbuf) ? 32 : 24);
                
                gint prev_width, prev_height;
                
-               if (pr->stereo_data == STEREO_PIXBUF_SBS || pr->stereo_data == STEREO_PIXBUF_CROSS) 
+               if (pr->stereo_data == STEREO_PIXBUF_SBS || pr->stereo_data == STEREO_PIXBUF_CROSS)
                        {
                        width /= 2;
                        }
@@ -520,8 +543,8 @@ static void rc_update_pixbuf(void *renderer, gboolean lazy)
                        /* FIXME use CoglMaterial with multiple textures for background, color management, anaglyph, ... */
                        CoglHandle texture = cogl_texture_new_with_size(width,
                                                                        height,
-                                                                       COGL_TEXTURE_NO_AUTO_MIPMAP,
-                                                                       gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888);
+                                                                       COGL_TEXTURE_NO_AUTO_MIPMAP | COGL_TEXTURE_NO_SLICING,
+                                                                       gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888);
 
                        if (texture != COGL_INVALID_HANDLE)
                                {
@@ -537,8 +560,6 @@ static void rc_update_pixbuf(void *renderer, gboolean lazy)
                }
 
        rc->clut_updated = FALSE;
-       rc->last_pixbuf_change = g_get_monotonic_time();
-       rc_sync_actor(rc);
 }
 
 
@@ -716,22 +737,22 @@ static gboolean rc_overlay_get(void *renderer, gint id, GdkPixbuf **pixbuf, gint
 static void rc_update_viewport(void *renderer)
 {
        RendererClutter *rc = (RendererClutter *)renderer;
-       ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; 
+       ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
 
        rc->stereo_off_x = 0;
        rc->stereo_off_y = 0;
        
-       if (rc->stereo_mode & PR_STEREO_RIGHT) 
+       if (rc->stereo_mode & PR_STEREO_RIGHT)
                {
-               if (rc->stereo_mode & PR_STEREO_HORIZ) 
+               if (rc->stereo_mode & PR_STEREO_HORIZ)
                        {
                        rc->stereo_off_x = rc->pr->viewport_width;
                        }
-               else if (rc->stereo_mode & PR_STEREO_VERT) 
+               else if (rc->stereo_mode & PR_STEREO_VERT)
                        {
                        rc->stereo_off_y = rc->pr->viewport_height;
                        }
-               else if (rc->stereo_mode & PR_STEREO_FIXED) 
+               else if (rc->stereo_mode & PR_STEREO_FIXED)
                        {
                        rc->stereo_off_x = rc->pr->stereo_fixed_x_right;
                        rc->stereo_off_y = rc->pr->stereo_fixed_y_right;
@@ -739,7 +760,7 @@ static void rc_update_viewport(void *renderer)
                }
        else
                {
-               if (rc->stereo_mode & PR_STEREO_FIXED) 
+               if (rc->stereo_mode & PR_STEREO_FIXED)
                        {
                        rc->stereo_off_x = rc->pr->stereo_fixed_x_left;
                        rc->stereo_off_y = rc->pr->stereo_fixed_y_left;
@@ -755,7 +776,7 @@ static void rc_update_viewport(void *renderer)
        
        clutter_actor_set_rotation(CLUTTER_ACTOR(rc->group),
                                                CLUTTER_Y_AXIS,
-                                               (rc->stereo_mode & PR_STEREO_MIRROR) ? 180 : 0, 
+                                               (rc->stereo_mode & PR_STEREO_MIRROR) ? 180 : 0,
                                                rc->pr->viewport_width / 2.0, 0, 0);
 
        clutter_actor_set_rotation(CLUTTER_ACTOR(rc->group),
@@ -850,7 +871,7 @@ RendererFuncs *renderer_clutter_new(PixbufRenderer *pr)
                        return NULL;
                        }
                }
-       else 
+       else
                {
                rc->widget = gtk_clutter_embed_new();
                gtk_container_add(GTK_CONTAINER(rc->pr), rc->widget);
@@ -872,5 +893,5 @@ RendererFuncs *renderer_clutter_new(PixbufRenderer *pr)
        return (RendererFuncs *) rc;
 }
 
-#endif 
+#endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */