Author: miguel
Date: 2007-06-06 17:00:17 -0400 (Wed, 06 Jun 2007)
New Revision: 78784
Modified:
trunk/moon/README
trunk/moon/src/ChangeLog
trunk/moon/src/ffvideo.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
Log:
2007-06-06 Miguel de Icaza <[EMAIL PROTECTED]>
* ffvideo.cpp (convert_to_rgb): We no longer need the loop to swap
channels.
Move to cairo to render to the screen the contents
of the buffer. ffmpeg and cairo do have the same RGBA format, it
was actually the copy from this format to the screen using
gdk_draw_pixbuf that failed: pixbuf expected the data in another
format and there is no way to configure it.
* runtime.cpp (surface_clear): use the cairo api as the surface is
no longer living on the client buffer.
(surface_destroy): update
(create_xlib, realized_callback, unrealized_callback): When the
widget is realized, create a cairo context
Modified: trunk/moon/README
===================================================================
--- trunk/moon/README 2007-06-06 20:43:36 UTC (rev 78783)
+++ trunk/moon/README 2007-06-06 21:00:17 UTC (rev 78784)
@@ -206,3 +206,24 @@
cd src
make debug
+
+* Cairo Considerations
+
+ surface_clear: should we use something like this?
+
+ cairo_set_source_rgba (s->cairo, 1.0, 1.0, 1.0, 1.0);
+ cairo_set_operator (s->cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (s->cairo);
+
+ But with a rectangle to set the region to clear?
+
+* Rendering Considerations
+
+ Currently we draw in an off-screen cairo surface when the
+ widget is not realized, seems like a waste of power, but its
+ used for bounding box computations.
+
+ Should we have a if (!realized) return in those places and
+ merely have a single cairo context that we paint to?
+
+
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-06 20:43:36 UTC (rev 78783)
+++ trunk/moon/src/ChangeLog 2007-06-06 21:00:17 UTC (rev 78784)
@@ -1,3 +1,22 @@
+2007-06-06 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * ffvideo.cpp (convert_to_rgb): We no longer need the loop to swap
+ channels.
+
+ Move to cairo to render to the screen the contents
+ of the buffer. ffmpeg and cairo do have the same RGBA format, it
+ was actually the copy from this format to the screen using
+ gdk_draw_pixbuf that failed: pixbuf expected the data in another
+ format and there is no way to configure it.
+
+ * runtime.cpp (surface_clear): use the cairo api as the surface is
+ no longer living on the client buffer.
+
+ (surface_destroy): update
+
+ (create_xlib, realized_callback, unrealized_callback): When the
+ widget is realized, create a cairo context
+
2007-06-06 Sebastien Pouliot <[EMAIL PROTECTED]>
* runtime.h: Add Value support for Point and Rect
Modified: trunk/moon/src/ffvideo.cpp
===================================================================
--- trunk/moon/src/ffvideo.cpp 2007-06-06 20:43:36 UTC (rev 78783)
+++ trunk/moon/src/ffvideo.cpp 2007-06-06 21:00:17 UTC (rev 78784)
@@ -389,27 +389,6 @@
sws_scale (video->video_scale_context, frame->data, frame->linesize, 0,
video->video_stream->codec->height, rgb_dest, rgb_stride);
-
- //
- // This is horrible, the ffmpeg scaler wont produce a usable
- // format (RGB32_1, BGR32_1 hang), so we have to manually swap
- // some values here
- //
- unsigned char *p = video->video_rgb_buffer;
-
-// the stupid scaler gives us RGBA
-// we need BGRA (CAIRO_FORMAT_ARGB32)
-
- for (int l = 0; l < cc->height; l++){
- for (int c = 0; c < cc->width; c += 1){
- unsigned char t;
-
- t = p [2];
- p [2] = p [0];
- p [0] = t;
- p += 4;
- }
- }
}
static gboolean
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-06 20:43:36 UTC (rev 78783)
+++ trunk/moon/src/runtime.cpp 2007-06-06 21:00:17 UTC (rev 78784)
@@ -15,6 +15,7 @@
#include <malloc.h>
#include <glib.h>
#include <stdlib.h>
+#include <gdk/gdkx.h>
#if AGG
# include <agg_rendering_buffer.h>
# include "Agg2D.h"
@@ -22,6 +23,7 @@
# define CAIRO 1
#endif
+#include <cairo-xlib.h>
#include "runtime.h"
#include "transform.h"
@@ -340,28 +342,17 @@
surface_clear (Surface *s, int x, int y, int width, int height)
{
static unsigned char n;
+ cairo_matrix_t identity;
- if (x < 0){
- width -= x;
- x = 0;
- }
+ cairo_matrix_init_identity (&identity);
- if (y < 0){
- height -= y;
- y = 0;
- }
- width = MAX (0, MIN (width, s->width));
- height = MAX (0, MIN (height, s->height));
+ cairo_set_matrix (s->cairo, &identity);
- int stride = s->width * 4;
- unsigned char *dest = s->buffer + (y * stride) + (x * 4);
-
- while (height--){
- memset (dest, 70, width * 4);
- dest += stride;
- }
+ cairo_set_source_rgb (s->cairo, 1.0, 1.0, 1.0);
+ cairo_rectangle (s->cairo, 0, 0, 1000, 1000);
+ cairo_fill (s->cairo);
}
-
+
void
surface_clear_all (Surface *s)
{
@@ -371,32 +362,75 @@
static void
surface_realloc (Surface *s)
{
- if (s->buffer){
+ if (s->buffer)
free (s->buffer);
- gdk_pixbuf_unref (s->pixbuf);
- }
int size = s->width * s->height * 4;
s->buffer = (unsigned char *) malloc (size);
surface_clear_all (s);
- s->pixbuf = gdk_pixbuf_new_from_data (s->buffer, GDK_COLORSPACE_RGB,
TRUE, 8,
- s->width, s->height, s->width *
4, NULL, NULL);
-
- s->cairo_surface = cairo_image_surface_create_for_data (
+ s->cairo_buffer_surface = cairo_image_surface_create_for_data (
s->buffer, CAIRO_FORMAT_ARGB32, s->width, s->height, s->width *
4);
- s->cairo = cairo_create (s->cairo_surface);
+ s->cairo_buffer = cairo_create (s->cairo_buffer_surface);
+ s->cairo = s->cairo_buffer;
}
void
surface_destroy (Surface *s)
{
- cairo_surface_destroy (s->cairo_surface);
+ cairo_destroy (s->cairo_buffer);
+ if (s->cairo_xlib)
+ cairo_destroy (s->cairo_xlib);
+
+ if (s->pixmap != NULL)
+ gdk_pixmap_unref (s->pixmap);
+
+ cairo_surface_destroy (s->cairo_buffer_surface);
+ if (s->xlib_surface)
+ cairo_surface_destroy (s->xlib_surface);
+
+ // TODO: add everything
delete s;
}
+void
+create_xlib (Surface *s, GtkWidget *widget)
+{
+ s->pixmap = gdk_pixmap_new (GDK_DRAWABLE (widget->window), s->width,
s->height, -1);
+
+ s->xlib_surface = cairo_xlib_surface_create (
+ GDK_WINDOW_XDISPLAY(widget->window),
+ GDK_WINDOW_XWINDOW(GDK_DRAWABLE (s->pixmap)),
+ GDK_VISUAL_XVISUAL (gdk_window_get_visual(widget->window)),
+ s->width, s->height);
+
+ s->cairo_xlib = cairo_create (s->xlib_surface);
+}
+
gboolean
+realized_callback (GtkWidget *widget, gpointer data)
+{
+ Surface *s = (Surface *) data;
+ cairo_surface_t *xlib;
+
+ create_xlib (s, widget);
+
+ s->cairo = s->cairo_xlib;
+}
+
+gboolean
+unrealized_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ Surface *s = (Surface *) data;
+
+ cairo_surface_destroy(s->xlib_surface);
+ s->xlib_surface = NULL;
+
+ s->cairo = s->cairo_buffer;
+}
+
+gboolean
expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
Surface *s = (Surface *) data;
@@ -412,20 +446,19 @@
cairo_status_to_string (cairo_status (s->cairo)));
}
+//#define DEBUG_INVALIDATE
#ifdef DEBUG_INVALIDATE
printf ("Got a request to repaint at %d %d %d %d\n", event->area.x,
event->area.y, event->area.width, event->area.height);
#endif
+
surface_repaint (s, event->area.x, event->area.y, event->area.width,
event->area.height);
- gdk_draw_pixbuf (widget->window,
- NULL,
- s->pixbuf,
- event->area.x, event->area.y, // gint src_x, gint
src_y,
- event->area.x, event->area.y, // gint dest_x, gint
dest_y,
- MIN (event->area.width, s->width),
- MIN (event->area.height, s->height),
- GDK_RGB_DITHER_NORMAL,
- 0, 0 // gint x_dither, gint y_dither
- );
+ gdk_draw_drawable (
+ widget->window, gtk_widget_get_style (widget)->white_gc,
s->pixmap,
+ event->area.x, event->area.y, // gint src_x, gint src_y,
+ event->area.x, event->area.y, // gint dest_x, gint dest_y,
+ MIN (event->area.width, s->width),
+ MIN (event->area.height, s->height));
+
return TRUE;
}
@@ -454,7 +487,10 @@
Surface *s = new Surface ();
s->drawing_area = gtk_drawing_area_new ();
+ gtk_widget_set_double_buffered (s->drawing_area, FALSE);
+
gtk_widget_show (s->drawing_area);
+
gtk_widget_set_usize (s->drawing_area, width, height);
s->buffer = NULL;
s->flags |= UIElement::IS_SURFACE;
@@ -465,6 +501,12 @@
gtk_signal_connect (GTK_OBJECT (s->drawing_area), "expose_event",
G_CALLBACK (expose_event_callback), s);
+ gtk_signal_connect (GTK_OBJECT (s->drawing_area), "realize",
+ G_CALLBACK (realized_callback), s);
+
+ gtk_signal_connect (GTK_OBJECT (s->drawing_area), "unrealize",
+ G_CALLBACK (unrealized_callback), s);
+
return s;
}
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-06 20:43:36 UTC (rev 78783)
+++ trunk/moon/src/runtime.h 2007-06-06 21:00:17 UTC (rev 78784)
@@ -643,30 +643,38 @@
//
class Surface : public Canvas {
public:
- Surface () : width (0), height (0), buffer (0), pixbuf (NULL),
cairo_surface (NULL), cairo (NULL), data(NULL) {}
+ Surface () : width (0), height (0), buffer (0),
+ cairo_buffer_surface (NULL), cairo_buffer(NULL),
+ xlib_surface(NULL), cairo_xlib(NULL), pixmap(NULL),
+ cairo (NULL) {}
int width, height;
// The data lives here
unsigned char *buffer;
- // Representations:
-
- SurfacePrivate *priv;
+ cairo_surface_t *cairo_buffer_surface;
+ cairo_t *cairo_buffer;
+ cairo_surface_t *xlib_surface;
+ cairo_t *cairo_xlib;
- // The same buffer, but this one is the pixbuf representation.
- GdkPixbuf *pixbuf;
+ //
+ // This is what code uses, and its equal to either:
+ // cairo_buffer: when the widget has not been realized
+ // cairo_xlib: when the widget has been realized
+ //
+ cairo_t *cairo;
- // The same buffer, but this one is for cairo.
- cairo_surface_t *cairo_surface;
- cairo_t *cairo;
+ // The pixmap used for the backing storage for xlib_surface
+ GdkPixmap *pixmap;
+ // The widget where we draw.
GtkWidget *drawing_area;
//
// Consumer-defined data, we use it to pass the handle to invalidate
//
- void *data;
+// void *data;
};
Surface *surface_new (int width, int height);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches