Author: lewing
Date: 2008-01-16 14:00:04 -0500 (Wed, 16 Jan 2008)
New Revision: 93078

Modified:
   trunk/moon/examples/desklet/simpleclock/default.xaml
   trunk/moon/src/ChangeLog
   trunk/moon/src/Makefile.am
   trunk/moon/src/brush.cpp
   trunk/moon/src/media.cpp
   trunk/moon/src/media.h
   trunk/moon/src/mplayer.cpp
   trunk/moon/src/panel.cpp
   trunk/moon/src/rect.h
   trunk/moon/src/shape.cpp
   trunk/moon/src/text.cpp
   trunk/moon/src/uielement.cpp
   trunk/moon/src/uielement.h
Log:
2008-01-16 Larry Ewing <[EMAIL PROTECTED]>

        * uielement.cpp, uielement.h: Rework the way we handle opacity to
        operate like the reference platform by removing the concept of
        TotalOpacity and instead using push/pop group and paint_with
        alpha.  See test-sibling-opacity.xaml for an example.  Handle
        clipping in DoRender rather than in every subclass because we want
        the clip path active before calling push/pop so that the temporary
        surface is bounded.
        * brush.cpp, panel.cpp: remove GetTotalOpacity references.
        * media.cpp, media.h: cleanup the complicated render logic now
        that things are handled in uielement.
        * shape.cpp, text.cpp: remove RenderClipPath calls.

        * rect.cpp, rect.h: add draw methods.


Modified: trunk/moon/examples/desklet/simpleclock/default.xaml
===================================================================
--- trunk/moon/examples/desklet/simpleclock/default.xaml        2008-01-16 
18:21:36 UTC (rev 93077)
+++ trunk/moon/examples/desklet/simpleclock/default.xaml        2008-01-16 
19:00:04 UTC (rev 93078)
@@ -43,7 +43,7 @@
   <Canvas x:Name="clockcanvas" Width="310" Height="100">
       <TextBlock x:Name="hour" Text="12" FontSize="68" Foreground="#fff" 
Canvas.Left="28" Canvas.Top="15"/>
       <TextBlock x:Name="dotcover" Text=":" FontSize="68" Foreground="#fff" 
Canvas.Left="108" Canvas.Top="10"/>
-      <TextBlock x:Name="minute" Text="00" FontSize="68" Foreground="#fff" 
Canvas.Left="124 " Canvas.Top="15"/>
+      <TextBlock x:Name="minute" Text="00" FontSize="68" Foreground="#fff" 
Canvas.Left="124" Canvas.Top="15"/>
     
       <TextBlock x:Name="ampm" Text="am" FontSize="24" Foreground="#fff" 
Canvas.Left="240" Canvas.Top="25"/>
 

Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/ChangeLog    2008-01-16 19:00:04 UTC (rev 93078)
@@ -1,3 +1,19 @@
+2008-01-16  Larry Ewing  <[EMAIL PROTECTED]>
+
+       * uielement.cpp, uielement.h: Rework the way we handle opacity to
+       operate like the reference platform by removing the concept of
+       TotalOpacity and instead using push/pop group and paint_with
+       alpha.  See test-sibling-opacity.xaml for an example.  Handle
+       clipping in DoRender rather than in every subclass because we want
+       the clip path active before calling push/pop so that the temporary
+       surface is bounded.
+       * brush.cpp, panel.cpp: remove GetTotalOpacity references.
+       * media.cpp, media.h: cleanup the complicated render logic now
+       that things are handled in uielement.
+       * shape.cpp, text.cpp: remove RenderClipPath calls.
+
+       * rect.cpp, rect.h: add draw methods.
+
 2008-01-16  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * pipeline.cpp: Implemented mpeg seeking support for

Modified: trunk/moon/src/Makefile.am
===================================================================
--- trunk/moon/src/Makefile.am  2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/Makefile.am  2008-01-16 19:00:04 UTC (rev 93078)
@@ -5,7 +5,7 @@
 
 lib_LTLIBRARIES = libmoon.la
 
-INCLUDES = $(MOON_CFLAGS) -Wall
+INCLUDES = $(MOON_CFLAGS) -Wall -DUSE_OPT_RGB24
 
 libmooninclude_headers = \
        animation.h     \

Modified: trunk/moon/src/brush.cpp
===================================================================
--- trunk/moon/src/brush.cpp    2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/brush.cpp    2008-01-16 19:00:04 UTC (rev 93078)
@@ -161,13 +161,7 @@
 double
 Brush::GetTotalOpacity (UIElement *uielement)
 {
-       double opacity = uielement ? uielement->GetTotalOpacity () : 1.0;
-
-       double brush_opacity = brush_get_opacity (this);
-       if (brush_opacity < 1.0)
-               opacity *= brush_opacity;
-
-       return opacity;
+       return brush_get_opacity (this);
 }
 
 void
@@ -221,11 +215,8 @@
 {
        Color *color = solid_color_brush_get_color (this);
        
-       // apply UIElement opacity and Brush opacity on color's alpha
-       double alpha = color->a * GetTotalOpacity (uielement);
-       
-       cairo_set_source_rgba (cr, color->r, color->g, color->b, alpha);
-       
+       cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
+
        // [Relative]Transform do not apply to solid color brush
 }
 
@@ -386,9 +377,6 @@
        Collection::Node *node;
        
        // TODO - ColorInterpolationModeProperty is ignored (map to ?)
-
-       double opacity = GetTotalOpacity (uielement);
-
        if (single) {
                // if a single color is shown (e.g. start == end point) Cairo 
will,
                // by default, use the start color while SL use the end color
@@ -406,8 +394,7 @@
                double offset = gradient_stop_get_offset (stop);
                if (offset >= 0.0) {
                        Color *color = gradient_stop_get_color (stop);
-                       double alpha = (opacity < 1.0) ? color->a * opacity : 
color->a;
-                       cairo_pattern_add_color_stop_rgba (pattern, offset, 
color->r, color->g, color->b, alpha);
+                       cairo_pattern_add_color_stop_rgba (pattern, offset, 
color->r, color->g, color->b, color->a);
                        n++;
                } else if (n < 2) {
                        // we don't have enough stops so we might need the 
negative one
@@ -430,8 +417,7 @@
                // add it to the mix
                double offset = gradient_stop_get_offset (negative);
                Color *color = gradient_stop_get_color (negative);
-               double alpha = (opacity < 1.0) ? color->a * opacity : color->a;
-               cairo_pattern_add_color_stop_rgba (pattern, offset, color->r, 
color->g, color->b, alpha);
+               cairo_pattern_add_color_stop_rgba (pattern, offset, color->r, 
color->g, color->b, color->a);
        }
 }
 
@@ -900,34 +886,6 @@
 #endif
 }
 
-// ripped apart to be reusable for Image and VideoBrush classes
-cairo_pattern_t *
-image_brush_create_pattern (cairo_t *cairo, cairo_surface_t *surface, int sw, 
int sh, double opacity)
-{
-       cairo_pattern_t *pattern;
-
-       if (opacity < 1.0) {
-               cairo_surface_t *blending = image_brush_create_similar (cairo, 
sw, sh);
-
-               cairo_t *cr = cairo_create (blending);
-               cairo_set_source_surface (cr, surface, 0.0, 0.0);
-
-               //cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-               cairo_pattern_set_filter (cairo_get_source (cr), 
CAIRO_FILTER_FAST);
-
-               cairo_paint_with_alpha (cr, opacity);
-               cairo_destroy (cr);
-               
-               pattern = cairo_pattern_create_for_surface (blending);
-
-               cairo_surface_destroy (blending);
-       } else {
-               pattern = cairo_pattern_create_for_surface (surface);
-       }
-       
-       return pattern;
-}
-
 void
 image_brush_compute_pattern_matrix (cairo_matrix_t *matrix, double width, 
double height, int sw, int sh, 
        Stretch stretch, AlignmentX align_x, AlignmentY align_y, Transform 
*transform, Transform *relative_transform)
@@ -1020,21 +978,17 @@
                return;
        }
        
-// MS BUG ? the ImageBrush Opacity is ignored, only the Opacity from UIElement 
is considered
-       double opacity = (uielement ? uielement->GetTotalOpacity () : 1.0);
-       
        Stretch stretch = tile_brush_get_stretch (this);
        
        AlignmentX ax = tile_brush_get_alignment_x (this);
        AlignmentY ay = tile_brush_get_alignment_y (this);
        
        Transform *transform = brush_get_transform (this);
-
        Transform *relative_transform = brush_get_relative_transform (this);
-
-       cairo_pattern_t *pattern = image_brush_create_pattern (cr, surface, 
image->GetWidth (), image->GetHeight (), opacity);
-       
        cairo_matrix_t matrix;
+
+       cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface);
+
        image_brush_compute_pattern_matrix (&matrix, width, height, 
image->GetWidth (), image->GetHeight (), stretch, ax, ay, transform, 
relative_transform);
        cairo_pattern_set_matrix (pattern, &matrix);
        
@@ -1074,7 +1028,6 @@
        cairo_surface_t *surface;
        cairo_pattern_t *pattern;
        cairo_matrix_t matrix;
-       double opacity;
        
        if (media == NULL) {
                DependencyObject *obj;
@@ -1104,12 +1057,8 @@
                return;
        }
        
-       if (uielement)
-               opacity = uielement->GetTotalOpacity ();
-       else
-               opacity = 1.0;
-       
-       pattern = image_brush_create_pattern (cr, surface, mplayer->width, 
mplayer->height, opacity);
+       pattern = cairo_pattern_create_for_surface (surface);
+
        image_brush_compute_pattern_matrix (&matrix, width, height, 
mplayer->width, mplayer->height, stretch, ax, ay, transform, 
relative_transform);
        cairo_pattern_set_matrix (pattern, &matrix);
        
@@ -1212,9 +1161,6 @@
        ui->Render (surface_cr, 0, 0, (int)bounds.w , (int)bounds.h);
        cairo_destroy (surface_cr);
        
-// MS BUG ? the ImageBrush Opacity is ignored, only the Opacity from UIElement 
is considered
-       double opacity = (uielement ? uielement->GetTotalOpacity () : 1.0);
-       
        Stretch stretch = tile_brush_get_stretch (this);
        
        AlignmentX ax = tile_brush_get_alignment_x (this);
@@ -1223,8 +1169,7 @@
        Transform *transform = brush_get_transform (this);
        Transform *relative_transform = brush_get_relative_transform (this);
        
-       cairo_pattern_t *pattern = image_brush_create_pattern (cr, surface, 
(int)bounds.w, (int)bounds.h, opacity);
-
+       cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface);
        cairo_matrix_t matrix;
        image_brush_compute_pattern_matrix (&matrix, width, height,
                                            (int)bounds.w, (int)bounds.h,

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/media.cpp    2008-01-16 19:00:04 UTC (rev 93078)
@@ -10,9 +10,7 @@
  * See the LICENSE file included with the distribution for details.
  */
 
-#define USE_OPT_INDIRECT_COMPOSE 1
 #define USE_OPT_REGION_CLIP 1
-#define DRAW_INCORRECTLY 0
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -29,7 +27,6 @@
 #include "pipeline.h"
 
 // still too ugly to be exposed in the header files ;-)
-cairo_pattern_t *image_brush_create_pattern (cairo_t *cairo, cairo_surface_t 
*surface, int sw, int sh, double opacity);
 void image_brush_compute_pattern_matrix (cairo_matrix_t *matrix, double width, 
double height, int sw, int sh, 
                                         Stretch stretch, AlignmentX align_x, 
AlignmentY align_y, Transform *transform, Transform *relative_transform);
 
@@ -533,16 +530,9 @@
        Stretch stretch = media_base_get_stretch (this);
        double h = framework_element_get_height (this);
        double w = framework_element_get_width (this);
-       double pattern_opacity = 1.0;
-        double render_opacity = GetTotalOpacity ();
        cairo_surface_t *surface;
        cairo_pattern_t *pattern;
        
-#if USE_OPT_INDIRECT_COMPOSE
-       pattern_opacity = render_opacity;
-       render_opacity = 1.0;
-#endif
-       
        if (!(surface = mplayer->GetSurface ()))
                return;
        
@@ -556,11 +546,8 @@
                cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
        
        cairo_set_matrix (cr, &absolute_xform);
+       pattern = cairo_pattern_create_for_surface (surface);   
 
-       RenderClipPath (cr);
-       
-       pattern = image_brush_create_pattern (cr, surface, mplayer->width, 
mplayer->height, pattern_opacity);
-       
        if (recalculate_matrix) {
                image_brush_compute_pattern_matrix (&matrix, w, h, 
mplayer->width, mplayer->height, stretch,
                                                    AlignmentXCenter, 
AlignmentYCenter, NULL, NULL);
@@ -573,6 +560,7 @@
        cairo_pattern_destroy (pattern);
        
        cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_FAST);
+
 #if USE_OPT_REGION_CLIP        
        cairo_identity_matrix (cr);
        runtime_cairo_region (cr, region->gdkregion);
@@ -583,26 +571,10 @@
        cairo_pattern_set_matrix (pattern, &matrix);
        cairo_set_source (cr, pattern);
 
-       // NOTE: Some servers seem to have extreme perfomance issues
-       // when paint_with_alpha (cr, 1.0) is called even accidentally
-       if (render_opacity < 1.0) {
-               cairo_new_path (cr);
-               cairo_rectangle (cr, 0, 0, w, h);
-               cairo_clip (cr);
-               cairo_paint_with_alpha (cr, render_opacity);
-       } else {
-#if DRAW_INCORRECTLY
-               cairo_new_path (cr);
-               cairo_rectangle (cr, 0, 0, w, h);
-               cairo_clip (cr);
-               cairo_paint (cr);
-#else
-               cairo_new_path (cr);
-               cairo_rectangle (cr, 0, 0, w, h);
-               cairo_fill (cr);
-#endif
-       }
-       
+       cairo_new_path (cr);
+       cairo_rectangle (cr, 0, 0, w, h);
+       cairo_fill (cr);
+
        cairo_restore (cr);
 }
 
@@ -932,9 +904,6 @@
                recalculate_matrix = true;
        } else if (prop == MediaElement::PositionProperty) {
                if (mplayer->IsPlaying() && mplayer->HasVideo ()) {
-                       double opacity = GetTotalOpacity ();
-                       
-                       if (opacity > 0.0f)
                                Invalidate ();
                }
        } else if (prop == MediaElement::VolumeProperty) {
@@ -1208,8 +1177,6 @@
     surface (NULL),
     part_name(NULL),
     pattern (NULL),
-    pattern_opacity (1.0),
-    opacity_stability_count (0),
     brush (NULL)
 {
 }
@@ -1239,7 +1206,6 @@
                cairo_pattern_destroy (pattern);
                pattern = NULL;
        }
-       pattern_opacity = 1.0;
 }
 
 void
@@ -1545,90 +1511,17 @@
 
        cairo_save (cr);
 
-       cairo_set_matrix (cr, &absolute_xform);
-
-       RenderClipPath (cr);
-
        Stretch stretch = media_base_get_stretch (this);
-
        double w = framework_element_get_width (this);
        double h = framework_element_get_height (this);
 
+       if (!pattern)
+               pattern = cairo_pattern_create_for_surface (surface->cairo);
 
-#define OPACITY_STABILITY_MAX 5
-
-       double render_opacity = GetTotalOpacity ();
-       double opacity = 1.0;
-
-       // Here we count the number of times we've been called with the
-       // same opacity and if it is greater than OPACITY_STABILITY_MAX we
-       // render the image to a temporary surface at that opacity, otherwise
-       // we render directly.  The purpose here is to handle opacity animations
-       // with a fair amount of grace while avoiding the overhead of constantly
-       // adding another alpha pass when rendering stable scenes.
-
-       if (render_opacity != pattern_opacity) {
-               opacity_stability_count = 0;
-               pattern_opacity = render_opacity;
-               cairo_pattern_destroy (pattern);
-               pattern = NULL;
-       } else {
-               opacity_stability_count ++;
-               if (opacity_stability_count >= OPACITY_STABILITY_MAX) {
-                       opacity_stability_count = OPACITY_STABILITY_MAX;
-                       opacity = render_opacity;
-                       render_opacity = 1.0;
-               }
-       }
-
-       if (!pattern || (opacity_stability_count >= OPACITY_STABILITY_MAX && 
(floor (pattern_opacity * 255) != floor (opacity * 255)))) {
-               // don't share surfaces until they are of the correct type
-               if (pattern && !surface->xlib_surface_created) {
-                       cairo_pattern_destroy (pattern);
-                       pattern = NULL;
-               }
-               
-               if (pattern) {
-                       cairo_surface_t *dest = NULL;
-                       cairo_pattern_get_surface (pattern, &dest);
-                       
-                       // If the pattern holds a temporary surface that meets 
our needs use it.
-                       // It is safe to assume if the pattern is there that it 
is the right size
-                       // because changing the source will invalidate the 
cached surface.
-                       //
-                       // NOTE: the opacity stability check above means this 
case is essentially
-                       // never encountered it is left here future where we 
may use a different
-                       // method of testing for animated properties.
-                       if (surface->cairo != dest && opacity < 1.0) {
-                               //g_warning ("sharing (%f, %f)", opacity, 
pattern_opacity);
-                               cairo_t *temp = cairo_create (dest);
-                               cairo_set_source_surface (temp, surface->cairo, 
0, 0);
-
-                               cairo_set_operator (temp, 
CAIRO_OPERATOR_SOURCE);
-                               cairo_pattern_set_filter (cairo_get_source 
(temp), CAIRO_FILTER_FAST);
-                               
-                               cairo_paint_with_alpha (temp, opacity);
-
-                               cairo_destroy (temp);
-                       } else {
-                               cairo_pattern_destroy (pattern);
-                               pattern = NULL;
-                       }
-               }
-               
-               if (!pattern) {
-                       //g_warning ("new pattern %f", opacity);
-                       pattern = image_brush_create_pattern (cr, 
surface->cairo, surface->width, surface->height, opacity);
-               }
-               
-               if (opacity_stability_count >= OPACITY_STABILITY_MAX)
-                       pattern_opacity = opacity;
-       }
-
        cairo_matrix_t matrix;
        image_brush_compute_pattern_matrix (&matrix, w, h, surface->width, 
surface->height, stretch, 
                AlignmentXCenter, AlignmentYCenter, NULL, NULL);
-       
+
        cairo_pattern_set_matrix (pattern, &matrix);
        cairo_set_source (cr, pattern);
 
@@ -1638,15 +1531,10 @@
        cairo_clip (cr);
 #endif
        cairo_set_matrix (cr, &absolute_xform);
+       
+       cairo_rectangle (cr, 0, 0, w, h);
+       cairo_fill (cr);
 
-       if (render_opacity < 1.0) {
-               cairo_rectangle (cr, 0, 0, w, h);
-               cairo_clip (cr);
-               cairo_paint_with_alpha (cr, render_opacity);
-       } else {
-               cairo_rectangle (cr, 0, 0, w, h);
-               cairo_fill (cr);
-       }
        cairo_restore (cr);
 }
 
@@ -1659,7 +1547,6 @@
                                                                   
        bounds = bounding_rect_for_transformed_rect (&absolute_xform,
                                                     
IntersectBoundsWithClipPath (box, false));
-// no-op       bounds.GrowBy (1);
 }
 
 Point

Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h      2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/media.h      2008-01-16 19:00:04 UTC (rev 93078)
@@ -98,9 +98,6 @@
        
        // pattern caching
        cairo_pattern_t *pattern;
-       double pattern_opacity;
-       int opacity_stability_count;
-       
  public:
        Image ();
        virtual ~Image ();

Modified: trunk/moon/src/mplayer.cpp
===================================================================
--- trunk/moon/src/mplayer.cpp  2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/mplayer.cpp  2008-01-16 19:00:04 UTC (rev 93078)
@@ -377,7 +377,12 @@
                        
                        // rendering surface
                        video->surface = cairo_image_surface_create_for_data (
-                               video->rgb_buffer, CAIRO_FORMAT_ARGB32,
+                               video->rgb_buffer,
+#if USE_OPT_RGB24
+                               CAIRO_FORMAT_RGB24,
+#else
+                               CAIRO_FORMAT_ARGB32,
+#endif
                                width, height, width * 4);
                        
                        // starting time

Modified: trunk/moon/src/panel.cpp
===================================================================
--- trunk/moon/src/panel.cpp    2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/panel.cpp    2008-01-16 19:00:04 UTC (rev 93078)
@@ -161,7 +161,6 @@
            || !GetRenderVisible () 
            || GetValue (UIElement::ClipProperty) != NULL
            || uielement_get_opacity_mask (this) != NULL
-           || GetTotalOpacity () < .990
            )
                return -1;
 
@@ -170,13 +169,9 @@
                // if the exposed rectangle is completely within the bounds
                // of a child that has opacity == 1.0 and lacks an opacity
                // mask, we start rendering from there.
-               if (item->GetTotalOpacity () > GetTotalOpacity ())
-                       g_warning ("Moonlight bug: child opacity greater than 
parent");
-
                if (item->GetRenderVisible ()
                    && item->GetValue (UIElement::ClipProperty) == NULL
                    && (item->absolute_xform.yx == 0 && item->absolute_xform.xy 
== 0) /* no skew */
-                   && item->GetTotalOpacity () >= .990
                    && uielement_get_opacity_mask (item) == NULL
                    && clip.IntersectsWith (item->GetBounds ().RoundOut ())
                    && region->RectIn (item->GetBounds().RoundOut()) == 
GDK_OVERLAP_RECTANGLE_IN
@@ -229,15 +224,6 @@
 void
 Panel::UpdateTotalOpacity ()
 {
-#if 1
-       // this really shouldn't need to be here, but our dirty code is broken
-       VisualCollection *children = GetChildren ();
-       for (guint i = 0; i < children->z_sorted->len; i++) {
-               UIElement *item = (UIElement *) children->z_sorted->pdata[i];
-               item->UpdateTotalOpacity ();
-       }
-#endif
-
        FrameworkElement::UpdateTotalOpacity ();
 }
 
@@ -274,13 +260,11 @@
 void
 Panel::Render (cairo_t *cr, Region *region)
 {
-       //if (!GetRenderVisible () || GetTotalOpacity () <= 0.0)
-       //      return;
+       if (!GetRenderVisible ())
+               return;
 
        cairo_save (cr);  // for UIElement::ClipProperty
-
        cairo_set_matrix (cr, &absolute_xform);
-       RenderClipPath (cr);
 
        Value *value = GetValue (Panel::BackgroundProperty);
        if (value) {
@@ -299,7 +283,6 @@
        }
 
        RenderChildren (cr, region);
-
        cairo_restore (cr);
 }
 
@@ -324,12 +307,10 @@
                Region *region = new Region (item->GetSubtreeBounds());
                region->Intersect (clipped_region);
 
-               if (!item->GetRenderVisible() 
-                   || item->GetTotalOpacity () == 0.0 
-                   || gdk_region_empty (region->gdkregion)
-                   ) {
+               if (!item->GetRenderVisible ()
+                   || gdk_region_empty (region->gdkregion)) {
 #ifdef DEBUG_INVALIDATE
-                       printf ("skipping invisible object %s: %p (%s)\n", 
item->GetName (), item, item->GetTypeName());
+                       printf ("skipping offscreen object %s: %p (%s)\n", 
item->GetName (), item, item->GetTypeName());
 #endif
                        delete region;
                        continue;
@@ -357,18 +338,8 @@
                //                              item->GetBounds().x, 
item->GetBounds().y, item->GetBounds().w, item->GetBounds().h,
                //                              inter.x, inter.y, inter.w, 
inter.h);
                
+               item->DoRender (cr, region);
 
-               //Type::Kind type = item->GetObjectType();
-               //if (type == Type::PANEL || type == Type::CANVAS)
-                       item->DoRender (cr, region);
-                       //else {
-                       //cairo_save (cr);
-                       ////Region zone = Region (region->ClipBox ());
-                       //runtime_cairo_region (cr,region->gdkregion);
-                       //cairo_clip (cr);
-                       //item->DoRender (cr, region);
-                       //cairo_restore (cr);
-                       //}
 #if CAIRO_CLIP
 #if TIME_CLIP
                STARTTIMER(endclip, "cairo clip teardown");

Modified: trunk/moon/src/rect.h
===================================================================
--- trunk/moon/src/rect.h       2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/rect.h       2008-01-16 19:00:04 UTC (rev 93078)
@@ -120,6 +120,11 @@
        {
                return !(*this == rect);
        }
+
+       void Draw (cairo_t *cr) 
+       {
+               cairo_rectangle (cr, x, y, w, h);
+       }
 };
 
 class Region {
@@ -145,6 +150,19 @@
 
        Rect ClipBox ();
        GdkOverlapType RectIn (Rect rect);
+
+       void Draw (cairo_t *cr)
+       {
+               int i, count;
+               GdkRectangle *rects;
+       
+               gdk_region_get_rectangles (gdkregion, &rects, &i);
+               
+               for (count = 0; count < i; count++)
+                       cairo_rectangle (cr, rects [count].x, rects [count].y, 
rects [count].width, rects [count].height);
+               
+               g_free (rects);
+       }
 };
      
 G_BEGIN_DECLS

Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp    2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/shape.cpp    2008-01-16 19:00:04 UTC (rev 93078)
@@ -181,8 +181,6 @@
 
        cairo_set_matrix (cr, &absolute_xform);
 
-       RenderClipPath (cr);
-
 //     printf ("Draw, xform: %g %g %g %g %g %g\n", 
 //             absolute_xform.xy,
 //             absolute_xform.xx,

Modified: trunk/moon/src/text.cpp
===================================================================
--- trunk/moon/src/text.cpp     2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/text.cpp     2008-01-16 19:00:04 UTC (rev 93078)
@@ -467,7 +467,6 @@
 {
        cairo_save (cr);
        cairo_set_matrix (cr, &absolute_xform);
-       RenderClipPath (cr);
        Paint (cr);
        cairo_restore (cr);
 }
@@ -1554,7 +1553,6 @@
        
        cairo_save (cr);
        cairo_set_matrix (cr, &absolute_xform);
-       RenderClipPath (cr);
        
        fill->SetupBrush (cr, this);
        

Modified: trunk/moon/src/uielement.cpp
===================================================================
--- trunk/moon/src/uielement.cpp        2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/uielement.cpp        2008-01-16 19:00:04 UTC (rev 93078)
@@ -23,7 +23,16 @@
 #include "eventargs.h"
 
 //#define DEBUG_INVALIDATE 0
+#define QUANTUM_ALPHA 1
 
+#if QUANTUM_ALPHA
+#define IS_TRANSLUCENT(x) (x * 255 < 254.5)
+#define IS_INVISIBLE(x) (x * 255 < .5)
+#else
+#define IS_TRANSLUCENT(x) (x < 1.0)
+#define IS_INVISIBLE(x) (x <= 0.0)
+#endif
+
 extern guint32 moonlight_flags;
 
 
@@ -230,8 +239,9 @@
        if (GetVisualParent ())
                GetVisualParent ()->ComputeTotalOpacity ();
 
-       double local_opacity = GetValue 
(UIElement::OpacityProperty)->AsDouble();
-       total_opacity = local_opacity * (GetVisualParent () ? GetVisualParent 
()->GetTotalOpacity () : 1.0);
+       double local_opacity = GetValue (OpacityProperty)->AsDouble();
+       //total_opacity = local_opacity * (GetVisualParent () ? GetVisualParent 
()->GetTotalOpacity () : 1.0);
+       total_opacity = local_opacity;
 }
 
 void
@@ -387,7 +397,7 @@
 void
 UIElement::Invalidate (Rect r)
 {
-       if (!GetRenderVisible() || total_opacity <= 0.0)
+       if (!GetRenderVisible() || IS_INVISIBLE (total_opacity))
                return;
 
 #ifdef DEBUG_INVALIDATE
@@ -408,7 +418,7 @@
 void
 UIElement::Invalidate (Region *region)
 {
-       if (!GetRenderVisible() || total_opacity <= 0.0)
+       if (!GetRenderVisible() || IS_INVISIBLE (total_opacity))
                return;
 
        add_dirty_element (this, DirtyInvalidate);
@@ -522,34 +532,49 @@
 {
        cairo_pattern_t *mask = NULL;
 
-       if (!GetRenderVisible() || total_opacity == 0.0 || region->RectIn 
(GetSubtreeBounds()) == GDK_OVERLAP_RECTANGLE_OUT)
+       if (!GetRenderVisible() || IS_INVISIBLE (total_opacity) || 
region->RectIn (GetSubtreeBounds()) == GDK_OVERLAP_RECTANGLE_OUT)
                return;
        
        STARTTIMER (UIElement_render, Type::Find (GetObjectType())->name);
-       if (opacityMask != NULL) {
-               cairo_save (cr);
+       cairo_save (cr);
+
+       RenderClipPath (cr);
+
+       if (opacityMask || IS_TRANSLUCENT (total_opacity)) {
                Rect r = GetSubtreeBounds ();
                r.RoundOut ();
                cairo_identity_matrix (cr);
+               runtime_cairo_region (cr, region->gdkregion);
+               cairo_clip (cr);
                cairo_rectangle (cr, r.x, r.y, r.w, r.h);
                cairo_clip (cr);
-               RenderClipPath (cr);
-               
+       }
+
+       if (IS_TRANSLUCENT (total_opacity))
+               cairo_push_group (cr);
+
+       if (opacityMask != NULL) {
+               cairo_push_group (cr);
+               cairo_set_matrix (cr, &absolute_xform);
                opacityMask->SetupBrush (cr, this);
-               mask = cairo_get_source (cr);
-               cairo_pattern_reference (mask);
+               cairo_fill (cr);
+               mask = cairo_pop_group (cr);
                cairo_push_group (cr);
        }
-       
+
        Render (cr, region);
 
        if (opacityMask != NULL) {
                cairo_pop_group_to_source (cr);
                cairo_mask (cr, mask);
                cairo_pattern_destroy (mask);
-               cairo_restore (cr);
        }
-
+       if (IS_TRANSLUCENT (total_opacity)) {
+               cairo_pop_group_to_source (cr);
+               cairo_paint_with_alpha (cr, total_opacity);
+       }
+       cairo_restore (cr);
+       
        ENDTIMER (UIElement_render, Type::Find (GetObjectType())->name);
        
        if (moonlight_flags & RUNTIME_INIT_SHOW_CLIPPING) {

Modified: trunk/moon/src/uielement.h
===================================================================
--- trunk/moon/src/uielement.h  2008-01-16 18:21:36 UTC (rev 93077)
+++ trunk/moon/src/uielement.h  2008-01-16 19:00:04 UTC (rev 93078)
@@ -87,10 +87,6 @@
 
        void ComputeTotalOpacity ();
 
-       // GetTotalOpacity
-       //   Get the cumulative opacity of this element, including all it's 
parents
-       double GetTotalOpacity () { return total_opacity; }
-
        virtual void UpdateTotalRenderVisibility ();
        void ComputeTotalRenderVisibility ();
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to