Rect Image::GetCoverageBounds () { // FIXME: SL3 final only supports PixelFormatPbgra32 which makes this optimization // obsolete - unless we keep an "has_alpha" flag with each image ?!? return Rect (); #if FALSE ImageSource *source = GetSource (); if (!source || source->GetPixelFormat () == PixelFormatPbgra32) return Rect (); Stretch stretch = GetStretch (); if (stretch == StretchFill || stretch == StretchUniformToFill) return bounds; cairo_matrix_t matrix; Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ()); Rect paint = Rect (0, 0, GetActualWidth (), GetActualHeight ()); image_brush_compute_pattern_matrix (&matrix, paint.width, paint.height, image.width, image.height, stretch, AlignmentXCenter, AlignmentYCenter, NULL, NULL); cairo_matrix_invert (&matrix); cairo_matrix_multiply (&matrix, &matrix, &absolute_xform); image = image.Transform (&matrix); image = image.Intersection (bounds); return image; #endif }
void Context::Push (Clip clip) { cairo_matrix_t matrix; Rect box; Top ()->GetMatrix (&matrix); Top ()->GetClip (&box); box = box.Intersection (clip.r); Stack::Push (new Context::Node (Top ()->GetSurface (), &matrix, &box)); }
cairo_t * MoonEGLContext::Push (Cairo extents) { Target *target = Top ()->GetTarget (); Target *cairo = target->GetCairoTarget (); Rect box; Top ()->GetClip (&box); box = box.Intersection (extents.r); if (box.IsEmpty ()) return Context::Push (extents); if (cairo) { Rect r = cairo->GetData (NULL); Region *region = new Region (r); if (region->RectIn (box) != CAIRO_REGION_OVERLAP_IN) { ForceCurrent (); SyncDrawable (); } delete region; } if (!target->GetCairoTarget ()) { MoonSurface *ms; Rect r = target->GetData (&ms); if (HasDrawable ()) { MoonEGLSurface *surface = new MoonEGLSurface (box.width, box.height); Target *cairo = new Target (surface, box); target->SetCairoTarget (cairo); cairo->unref (); surface->unref (); } else { // mark target contents as initialized target->SetInit (ms); } ms->unref (); } return Context::Push (extents); }
void RenderManager::ClipRect(const Rect &rect) { Rect r = currentClip; if(r.dx < 0) { r.dx = (float32)retScreenWidth; } if(r.dy < 0) { r.dy = (float32)retScreenHeight; } r = r.Intersection(rect); SetHWClip(rect); }
void Image::Render (cairo_t *cr, Region *region, bool path_only) { ImageSource *source = GetSource (); cairo_pattern_t *pattern = NULL; cairo_matrix_t matrix; if (!source) return; source->Lock (); cairo_save (cr); Size specified (GetActualWidth (), GetActualHeight ()); Size stretched = ApplySizeConstraints (specified); bool adjust = specified != GetRenderSize (); if (GetStretch () != StretchUniformToFill) specified = specified.Min (stretched); Rect paint = Rect (0, 0, specified.width, specified.height); if (!path_only) { Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ()); if (GetStretch () == StretchNone) paint = paint.Union (image); if (image.width == 0.0 && image.height == 0.0) goto cleanup; pattern = cairo_pattern_create_for_surface (source->GetSurface (cr)); image_brush_compute_pattern_matrix (&matrix, paint.width, paint.height, image.width, image.height, GetStretch (), AlignmentXCenter, AlignmentYCenter, NULL, NULL); cairo_pattern_set_matrix (pattern, &matrix); #if MAKE_EVERYTHING_SLOW_AND_BUGGY cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); #endif if (cairo_pattern_status (pattern) == CAIRO_STATUS_SUCCESS) { cairo_set_source (cr, pattern); } cairo_pattern_destroy (pattern); } if (adjust) { // FIXME: Propagate error properly MoonError error; specified = MeasureOverrideWithError (specified, &error); paint = Rect ((stretched.width - specified.width) * 0.5, (stretched.height - specified.height) * 0.5, specified.width, specified.height); } if (!path_only) RenderLayoutClip (cr); paint = paint.Intersection (Rect (0, 0, stretched.width, stretched.height)); paint.Draw (cr); if (!path_only) cairo_fill (cr); cleanup: cairo_restore (cr); source->Unlock (); }