Author: miguel
Date: 2007-06-06 20:51:51 -0400 (Wed, 06 Jun 2007)
New Revision: 78799
Added:
trunk/moon/src/cutil.cpp
trunk/moon/src/cutil.h
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/Makefile.am
trunk/moon/src/demo.cpp
trunk/moon/src/ffvideo.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/shape.cpp
Log:
2007-06-06 Miguel de Icaza <[EMAIL PROTECTED]>
Correct computation of the bounding box for shapes and videos.
* shape.cpp: Do not pop the cairo state after draw and then call
extents as the computation on extents is done with the current
cairo context, not the cairo context that drew the data before
popping (this would show up with thick brushes).
* runtime.cpp: Add 2 instead of 1, as double to integer rounding
can take two values (negative and positive).
* cutil.cpp: Cut and paste cairo code here, it computes the proper
bounding box from the extents using the current absolute matrix.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/ChangeLog 2007-06-07 00:51:51 UTC (rev 78799)
@@ -1,3 +1,20 @@
+2007-06-06 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ Correct computation of the bounding box for shapes and videos.
+
+ * shape.cpp: Do not pop the cairo state after draw and then call
+ extents as the computation on extents is done with the current
+ cairo context, not the cairo context that drew the data before
+ popping (this would show up with thick brushes).
+
+ * runtime.cpp: Add 2 instead of 1, as double to integer rounding
+ can take two values (negative and positive).
+
+ * cutil.cpp: Cut and paste cairo code here, it computes the proper
+ bounding box from the extents using the current absolute matrix.
+
+ * ffvideo.cpp (queue_data): Memory leak gone.
+
2007-06-06 Jackson Harper <[EMAIL PROTECTED]>
* xaml.cpp: Set brush attributes.
Modified: trunk/moon/src/Makefile.am
===================================================================
--- trunk/moon/src/Makefile.am 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/Makefile.am 2007-06-07 00:51:51 UTC (rev 78799)
@@ -5,6 +5,7 @@
INCLUDES = $(MOON_CFLAGS)
libmoon_la_SOURCES = \
+ cutil.cpp \
brush.cpp \
animation.cpp \
animation.h \
Added: trunk/moon/src/cutil.cpp
===================================================================
--- trunk/moon/src/cutil.cpp 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/cutil.cpp 2007-06-07 00:51:51 UTC (rev 78799)
@@ -0,0 +1,90 @@
+//
+// Code in this file are internal Cairo utilities that are not
+// exposed by Cairo.
+//
+// This code is licensed under these terms:
+/* Copyright © 2002 University of Southern California
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is University of Southern
+ * California.
+ *
+ * Contributor(s):
+ * Carl D. Worth <[EMAIL PROTECTED]>
+ * Robert O'Callahan <[EMAIL PROTECTED]>
+ */
+#include <config.h>
+#include <glib.h>
+#include <cairo.h>
+#include "cutil.h"
+
+void
+x_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
+ double *x1, double *y1,
+ double *x2, double *y2)
+{
+ int i;
+ double quad_x[4], quad_y[4];
+ double min_x, max_x;
+ double min_y, max_y;
+
+ quad_x[0] = *x1;
+ quad_y[0] = *y1;
+ cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]);
+
+ quad_x[1] = *x2;
+ quad_y[1] = *y1;
+ cairo_matrix_transform_point (matrix, &quad_x[1], &quad_y[1]);
+
+ quad_x[2] = *x1;
+ quad_y[2] = *y2;
+ cairo_matrix_transform_point (matrix, &quad_x[2], &quad_y[2]);
+
+ quad_x[3] = *x2;
+ quad_y[3] = *y2;
+ cairo_matrix_transform_point (matrix, &quad_x[3], &quad_y[3]);
+
+ min_x = max_x = quad_x[0];
+ min_y = max_y = quad_y[0];
+
+ for (i=1; i < 4; i++) {
+ if (quad_x[i] < min_x)
+ min_x = quad_x[i];
+ if (quad_x[i] > max_x)
+ max_x = quad_x[i];
+
+ if (quad_y[i] < min_y)
+ min_y = quad_y[i];
+ if (quad_y[i] > max_y)
+ max_y = quad_y[i];
+ }
+
+ *x1 = min_x;
+ *y1 = min_y;
+ *x2 = max_x;
+ *y2 = max_y;
+}
Property changes on: trunk/moon/src/cutil.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/moon/src/cutil.h
===================================================================
--- trunk/moon/src/cutil.h 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/cutil.h 2007-06-07 00:51:51 UTC (rev 78799)
@@ -0,0 +1,13 @@
+#ifndef __CUTIL_H__
+#define __CUTIL_H__
+
+G_BEGIN_DECLS
+
+void
+x_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
+ double *x1, double *y1,
+ double *x2, double *y2);
+
+G_END_DECLS
+
+#endif
Property changes on: trunk/moon/src/cutil.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/demo.cpp 2007-06-07 00:51:51 UTC (rev 78799)
@@ -87,7 +87,7 @@
r = rectangle_new ();
framework_element_set_width (r, 50.0);
framework_element_set_height (r, 50.0);
- shape_set_stroke_thickness (r, 5.0);
+ shape_set_stroke_thickness (r, 10.0);
r->SetValue (Canvas::LeftProperty, Value (50.0));
r->SetValue (Canvas::TopProperty, Value (50.0));
@@ -135,8 +135,8 @@
v2->SetValue (Canvas::TopProperty, Value (100.0));
item_set_render_transform (v2, s_trans);
panel_child_add (t, v2);
+#endif
gtk_timeout_add (60, animate, NULL);
-#endif
}
gtk_widget_set_usize (w, 600, 400);
gtk_widget_show_all (w);
Modified: trunk/moon/src/ffvideo.cpp
===================================================================
--- trunk/moon/src/ffvideo.cpp 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/ffvideo.cpp 2007-06-07 00:51:51 UTC (rev 78799)
@@ -42,6 +42,7 @@
// Alsa
#include <asoundlib.h>
+#include "cutil.h"
typedef enum {
// When a new frame is ready
@@ -121,6 +122,7 @@
static GMutex *video_lock;
+
void
VideoFfmpeg::getbounds ()
{
@@ -144,8 +146,11 @@
cairo_set_matrix (s->cairo, &absolute_xform);
cairo_rectangle (s->cairo, 0, 0, cc->width, cc->height);
- cairo_fill_extents (s->cairo, &x1, &y1, &x2, &y2);
+ cairo_stroke_extents (s->cairo, &x1, &y1, &x2, &y2);
+ // The extents are in the coordinates of the transform, translate to
device coordinates
+ x_cairo_matrix_transform_bounding_box (&absolute_xform, &x1, &y1, &x2,
&y2);
+
cairo_restore (s->cairo);
}
@@ -308,7 +313,14 @@
frame++;
g_mutex_lock (video->video_mutex);
- if (video->pcm != NULL && pkt->stream_index ==
audio_stream_idx) {
+ if (pkt->stream_index == video_stream_idx){
+ g_async_queue_push (video->video_frames, pkt);
+ video->video_frames_size += pkt->size;
+ if (g_async_queue_length (video->video_frames) == 1)
+ send_command (video, CMD_NEWFRAME);
+ pkt = NULL;
+
+ } else if (video->pcm != NULL && pkt->stream_index ==
audio_stream_idx) {
int align = audio_left & 0x1;
char *audio_buffer = ((char *) video->audio_buffer) +
audio_left;
int16_t *decode_buffer = (int16_t *) (audio_buffer +
align);
@@ -320,6 +332,8 @@
ndecoded = avcodec_decode_audio2 (audio_codec,
decode_buffer, &decode_size,
pkt->data,
pkt->size);
printf ("decoded %d bytes\n", ndecoded);
+ g_free (pkt);
+ pkt = NULL;
}
if (ndecoded > 0) {
@@ -359,12 +373,9 @@
snd_pcm_prepare (video->pcm);
}
}
- } if (pkt->stream_index == video_stream_idx){
- g_async_queue_push (video->video_frames, pkt);
- video->video_frames_size += pkt->size;
- if (g_async_queue_length (video->video_frames) == 1)
- send_command (video, CMD_NEWFRAME);
- }
+ }
+ if (pkt != NULL)
+ g_free (pkt);
g_mutex_unlock (video->video_mutex);
}
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/runtime.cpp 2007-06-07 00:51:51 UTC (rev 78799)
@@ -117,10 +117,11 @@
if (s == NULL)
return;
+//#define DEBUG_INVALIDATE
#ifdef DEBUG_INVALIDATE
printf ("Requesting invalidate for %d %d %d %d\n",
(int) item->x1, (int)item->y1,
- (int)(item->x2-item->x1),
(int)(item->y2-item->y1));
+ (int)(item->x2-item->x1+1),
(int)(item->y2-item->y1+1));
#endif
//
// Note: this is buggy: why do we need to queue the redraw on the
toplevel
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-06-07 00:40:13 UTC (rev 78798)
+++ trunk/moon/src/shape.cpp 2007-06-07 00:51:51 UTC (rev 78799)
@@ -18,6 +18,7 @@
#include <cairo.h>
#include "shape.h"
+#include "cutil.h"
//
// SL-Cairo convertion routines
@@ -85,7 +86,6 @@
void
Shape::DoDraw (Surface *s, bool do_op)
{
- cairo_save (s->cairo);
cairo_set_matrix (s->cairo, &absolute_xform);
Brush *fill = shape_get_fill (this);
@@ -112,30 +112,33 @@
if (do_op)
cairo_stroke (s->cairo);
}
- cairo_restore (s->cairo);
}
void
Shape::render (Surface *s, int x, int y, int width, int height)
{
+ cairo_save (s->cairo);
DoDraw (s, TRUE);
+ cairo_restore (s->cairo);
}
void
Shape::getbounds ()
{
- double res [6];
-
Surface *s = item_get_surface (this);
// not yet attached
if (s == NULL)
return;
+ cairo_save (s->cairo);
DoDraw (s, FALSE);
cairo_stroke_extents (s->cairo, &x1, &y1, &x2, &y2);
+ cairo_new_path (s->cairo);
+ cairo_restore (s->cairo);
- cairo_new_path (s->cairo);
+ // The extents are in the coordinates of the transform, translate to
device coordinates
+ x_cairo_matrix_transform_bounding_box (&absolute_xform, &x1, &y1, &x2,
&y2);
}
Brush*
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches