summaryrefslogtreecommitdiff
path: root/canvas
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-03-18 14:23:52 +0000
committerCaolán McNamara <caolanm@redhat.com>2015-03-18 17:24:04 +0000
commitdce032e3ac528cfe3b2199a7998ddc349b4a2eb4 (patch)
treee6372967bd353c27f90339fd6491de2f3d8afd47 /canvas
parent98d2e1aaa22fb5e9aeb86750038b6a0bf96bdaf2 (diff)
thinking
Change-Id: Ib1a086bed7f70e244db2a0bd32819560c6949d51
Diffstat (limited to 'canvas')
-rw-r--r--canvas/source/cairo/cairo_xlib_cairo.cxx98
-rw-r--r--canvas/source/cairo/cairo_xlib_cairo.hxx22
2 files changed, 112 insertions, 8 deletions
diff --git a/canvas/source/cairo/cairo_xlib_cairo.cxx b/canvas/source/cairo/cairo_xlib_cairo.cxx
index a4665e14aa04..24063a47b24e 100644
--- a/canvas/source/cairo/cairo_xlib_cairo.cxx
+++ b/canvas/source/cairo/cairo_xlib_cairo.cxx
@@ -324,17 +324,99 @@ namespace cairo
return X11SysData( rVirDev.GetSystemGfxData() );
}
+ /**
+ * Surface::Surface: Create Canvas surface from Window reference.
+ * @param x horizontal location of the new surface
+ * @param y vertical location of the new surface
+ * @param width width of the new surface
+ * @param height height of the new surface
+ *
+ * Set the mpSurface to the new surface or NULL
+ **/
+ Gtk3Surface::Gtk3Surface(const OutputDevice& rRefDevice, int x, int y, int width, int height)
+ : mpSurface(cairo_get_target(rRefDevice.GetCairoContext()), &cairo_surface_flush)
+ , mnWidth(width)
+ , mnHeight(height)
+ {
+ cairo_surface_set_device_offset(mpSurface.get(), x, y );
+ }
+
+ /**
+ * Surface::Surface: Create generic Canvas surface using given Cairo Surface
+ *
+ * @param pSurface Cairo Surface
+ *
+ * This constructor only stores data, it does no processing.
+ * It is used with e.g. cairo_image_surface_create_for_data()
+ *
+ * Set the mpSurface as pSurface
+ **/
+ Gtk3Surface::Gtk3Surface(const CairoSurfaceSharedPtr& pSurface, int width, int height)
+ : mpSurface(pSurface)
+ , mnWidth(width)
+ , mnHeight(height)
+ {
+ }
+
+ /**
+ * Surface::getCairo: Create Cairo (drawing object) for the Canvas surface
+ *
+ * @return new Cairo or NULL
+ **/
+ CairoSharedPtr Gtk3Surface::getCairo() const
+ {
+ return CairoSharedPtr(cairo_create(mpSurface.get()),
+ &cairo_destroy);
+ }
+
+ /**
+ * Surface::getSimilar: Create new similar Canvas surface
+ * @param aContent format of the new surface (cairo_content_t from cairo/src/cairo.h)
+ * @param width width of the new surface
+ * @param height height of the new surface
+ *
+ * Creates a new Canvas surface.
+ *
+ * Cairo surface from aContent (cairo_content_t)
+ *
+ * @return new surface or NULL
+ **/
+ SurfaceSharedPtr Gtk3Surface::getSimilar( Content aContent, int width, int height ) const
+ {
+ return SurfaceSharedPtr(
+ new Gtk3Surface(CairoSurfaceSharedPtr(
+ cairo_surface_create_similar( mpSurface.get(), aContent, width, height ),
+ &cairo_surface_destroy ), width, height));
+ }
+
+ /**
+ * Surface::Resize: Resizes the Canvas surface.
+ * @param width new width of the surface
+ * @param height new height of the surface
+ *
+ * Only used on X11.
+ *
+ * @return The new surface or NULL
+ **/
+ void Gtk3Surface::Resize( int /*width*/, int /*height*/ )
+ {
+ assert(false && "not supposed to be called!");
+ }
+
+ void Gtk3Surface::flush() const
+ {
+ cairo_surface_flush(mpSurface.get());
+ }
+
+ boost::shared_ptr<VirtualDevice> Gtk3Surface::createVirtualDevice() const
+ {
+ return boost::shared_ptr<VirtualDevice>(new VirtualDevice(NULL, Size(mnWidth, mnHeight), 0));
+ }
+
SurfaceSharedPtr createSurface( const OutputDevice& rRefDevice,
int x, int y, int width, int height )
{
- if( rRefDevice.GetOutDevType() == OUTDEV_WINDOW )
- return SurfaceSharedPtr(new X11Surface(getSysData(static_cast<const vcl::Window&>(rRefDevice)),
- x,y,width,height));
- else if( rRefDevice.GetOutDevType() == OUTDEV_VIRDEV )
- return SurfaceSharedPtr(new X11Surface(getSysData(static_cast<const VirtualDevice&>(rRefDevice)),
- x,y,width,height));
- else
- return SurfaceSharedPtr();
+ return SurfaceSharedPtr(new Gtk3Surface(rRefDevice, x, y, width, height));
}
SurfaceSharedPtr createBitmapSurface( const OutputDevice& rRefDevice,
diff --git a/canvas/source/cairo/cairo_xlib_cairo.hxx b/canvas/source/cairo/cairo_xlib_cairo.hxx
index f040b9bc0ced..babebde8ab8a 100644
--- a/canvas/source/cairo/cairo_xlib_cairo.hxx
+++ b/canvas/source/cairo/cairo_xlib_cairo.hxx
@@ -97,6 +97,28 @@ namespace cairo {
void* getRenderFormat() const { return maSysData.pRenderFormat; }
long getDrawable() const { return mpPixmap ? mpPixmap->mhDrawable : maSysData.hDrawable; }
};
+
+ class Gtk3Surface : public Surface
+ {
+ CairoSurfaceSharedPtr mpSurface;
+ int mnWidth;
+ int mnHeight;
+ public:
+ /// takes over ownership of passed cairo_surface
+ explicit Gtk3Surface(const CairoSurfaceSharedPtr& pSurface, int width, int height);
+ /// create surface on subarea of given drawable
+ explicit Gtk3Surface(const OutputDevice& rRefDevice, int x, int y, int width, int height);
+
+ // Surface interface
+ virtual CairoSharedPtr getCairo() const SAL_OVERRIDE;
+ virtual CairoSurfaceSharedPtr getCairoSurface() const SAL_OVERRIDE { return mpSurface; }
+ virtual SurfaceSharedPtr getSimilar( Content aContent, int width, int height ) const SAL_OVERRIDE;
+
+ virtual boost::shared_ptr<VirtualDevice> createVirtualDevice() const SAL_OVERRIDE;
+
+ virtual void Resize(int width, int height) SAL_OVERRIDE;
+ virtual void flush() const SAL_OVERRIDE;
+ };
}
#endif