From 499be274f5828169fb18a9958e5f2eb3cd9f975d Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Mon, 7 Feb 2005 23:22:15 +0000 Subject: [PATCH] Bug 279967 - allow cairo to be used as the svg render on OS-X. --- layout/svg/renderer/src/cairo/Makefile.in | 19 ++++-- .../renderer/src/cairo/nsSVGCairoCanvas.cpp | 59 ++++++++++++++++++- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/layout/svg/renderer/src/cairo/Makefile.in b/layout/svg/renderer/src/cairo/Makefile.in index 3785b1673da1..2cc096fda9b2 100644 --- a/layout/svg/renderer/src/cairo/Makefile.in +++ b/layout/svg/renderer/src/cairo/Makefile.in @@ -88,13 +88,24 @@ include $(topsrcdir)/config/rules.mk CFLAGS += $(MOZ_CAIRO_CFLAGS) CXXFLAGS += $(MOZ_CAIRO_CFLAGS) -CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) -CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) - LOCAL_INCLUDES = \ -I$(topsrcdir)/gfx/src \ - -I$(topsrcdir)/gfx/src/gtk \ $(NULL) +ifdef MOZ_ENABLE_GTK +LOCAL_INCLUDES += -I$(topsrcdir)/gfx/src/gtk +CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) +CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) +endif + +ifdef MOZ_ENABLE_GTK2 +LOCAL_INCLUDES += -I$(topsrcdir)/gfx/src/gtk +CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) +CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS) +endif + +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +LOCAL_INCLUDES += -I$(topsrcdir)/gfx/src/mac +endif diff --git a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp index 56d66b0bd489..65c06bd97a7e 100644 --- a/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp +++ b/layout/svg/renderer/src/cairo/nsSVGCairoCanvas.cpp @@ -48,13 +48,21 @@ #include "nsTransform2D.h" #include "nsPresContext.h" #include "nsRect.h" -#include "nsRenderingContextGTK.h" #include "nsISVGCairoSurface.h" -#include #include + +#ifdef XP_MACOSX +#include "nsIDrawingSurfaceMac.h" +extern "C" { +#include +} +#else +#include "nsRenderingContextGTK.h" +#include extern "C" { #include } +#endif /** * \addtogroup cairo_renderer Cairo Rendering Engine @@ -88,6 +96,11 @@ private: PRUint32 mWidth, mHeight; nsVoidArray mSurfaceStack; PRUint16 mRenderMode; + +#ifdef XP_MACOSX + nsCOMPtr mSurface; + CGContextRef mQuartzRef; +#endif }; @@ -117,15 +130,40 @@ nsSVGCairoCanvas::Init(nsIRenderingContext *ctx, mMozContext = ctx; NS_ASSERTION(mMozContext, "empty rendering context"); + mCR = cairo_create(); + +#ifdef XP_MACOSX + nsIDrawingSurface *surface; + ctx->GetDrawingSurface(&surface); + mSurface = do_QueryInterface(surface); + surface->GetDimensions(&mWidth, &mHeight); + mQuartzRef = mSurface->StartQuartzDrawing(); + + CGrafPtr port; + mSurface->GetGrafPtr(&port); + Rect portRect; + ::GetPortBounds(port, &portRect); + +#ifdef DEBUG_tor + fprintf(stderr, "CAIRO: DS=0x%08x port x=%d y=%d w=%d h=%d\n", + mSurface.get(), portRect.right, portRect.top, + portRect.right - portRect.left, portRect.bottom - portRect.top); +#endif + + ::SyncCGContextOriginWithPort(mQuartzRef, port); + cairo_set_target_quartz_context(mCR, mQuartzRef, + portRect.right - portRect.left, + portRect.bottom - portRect.top); +#else nsDrawingSurfaceGTK *surface; ctx->GetDrawingSurface((nsIDrawingSurface**)&surface); surface->GetSize(&mWidth, &mHeight); GdkDrawable *drawable = surface->GetDrawable(); - mCR = cairo_create(); cairo_set_target_drawable(mCR, GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable)); +#endif // get the translation set on the rendering context. It will be in // displayunits (i.e. pixels*scale), *not* pixels: @@ -135,12 +173,23 @@ nsSVGCairoCanvas::Init(nsIRenderingContext *ctx, xform->GetTranslation(&dx, &dy); cairo_translate(mCR, dx, dy); +#ifdef DEBUG_tor + fprintf(stderr, "cairo translate: %f %f\n", dx, dy); + + fprintf(stderr, "cairo dirty: %d %d %d %d\n", + dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height); +#endif + +// the following should be done for all platforms, but clipping +// is broken in the cairo quartz backend as of cairo-0.3.0 +#ifndef XP_MACOSX // clip to dirtyRect cairo_new_path(mCR); cairo_rectangle(mCR, dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height); cairo_clip(mCR); cairo_new_path(mCR); +#endif mRenderMode = SVG_RENDER_MODE_NORMAL; @@ -231,6 +280,10 @@ nsSVGCairoCanvas::Clear(nscolor color) NS_IMETHODIMP nsSVGCairoCanvas::Flush() { +#ifdef XP_MACOSX + if (mSurface) + mSurface->EndQuartzDrawing(mQuartzRef); +#endif return NS_OK; }