Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / unx / gtk3 / gdi / cairo_gtk3_cairo.cxx
blobb9a2751fc4aa0c9bbdad29804b284782181b6dda
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <utility>
12 #include "cairo_cairo.hxx"
13 #include "cairo_gtk3_cairo.hxx"
15 #include <vcl/sysdata.hxx>
16 #include <vcl/bitmap.hxx>
17 #include <vcl/virdev.hxx>
18 #include <vcl/window.hxx>
19 #include <basegfx/vector/b2isize.hxx>
21 #include "unx/gtk/gtkgdi.hxx"
23 namespace cairo
25 /**
26 * Surface::Surface: Create generic Canvas surface using given Cairo Surface
28 * @param pSurface Cairo Surface
30 * This constructor only stores data, it does no processing.
31 * It is used with e.g. cairo_image_surface_create_for_data()
33 * Set the mpSurface as pSurface
34 **/
35 Gtk3Surface::Gtk3Surface(const CairoSurfaceSharedPtr& pSurface)
36 : mpGraphics(NULL)
37 , cr(NULL)
38 , mpSurface(pSurface)
41 /**
42 * Surface::Surface: Create Canvas surface from Window reference.
43 * @param x horizontal location of the new surface
44 * @param y vertical location of the new surface
45 * @param width width of the new surface
46 * @param height height of the new surface
48 * Set the mpSurface to the new surface or NULL
49 **/
50 Gtk3Surface::Gtk3Surface(const GtkSalGraphics* pGraphics, int x, int y, int width, int height)
51 : mpGraphics(pGraphics)
52 , cr(pGraphics->getCairoContext())
54 cairo_surface_t* surface = cairo_get_target(cr);
55 mpSurface.reset(
56 cairo_surface_create_for_rectangle(surface, x, y, width, height),
57 &cairo_surface_destroy);
60 Gtk3Surface::~Gtk3Surface()
62 if (cr)
63 cairo_destroy(cr);
66 /**
67 * Surface::getCairo: Create Cairo (drawing object) for the Canvas surface
69 * @return new Cairo or NULL
70 **/
71 CairoSharedPtr Gtk3Surface::getCairo() const
73 return CairoSharedPtr( cairo_create(mpSurface.get()),
74 &cairo_destroy );
77 /**
78 * Surface::getSimilar: Create new similar Canvas surface
79 * @param cairo_content_type format of the new surface (cairo_content_t from cairo/src/cairo.h)
80 * @param width width of the new surface
81 * @param height height of the new surface
83 * Creates a new Canvas surface. This normally creates platform native surface, even though
84 * generic function is used.
86 * Cairo surface from cairo_content_type (cairo_content_t)
88 * @return new surface or NULL
89 **/
90 SurfaceSharedPtr Gtk3Surface::getSimilar(int cairo_content_type, int width, int height ) const
92 return SurfaceSharedPtr(
93 new Gtk3Surface(
94 CairoSurfaceSharedPtr(
95 cairo_surface_create_similar( mpSurface.get(),
96 static_cast<cairo_content_t>(cairo_content_type), width, height ),
97 &cairo_surface_destroy )));
100 void Gtk3Surface::flush() const
102 cairo_surface_flush(mpSurface.get());
103 //Wonder if there is any benefit in using cairo_fill/stroke extents on
104 //every canvas call and only redrawing the union of those in a
105 //poor-mans-damage tracking
106 if (mpGraphics)
107 mpGraphics->WidgetQueueDraw();
110 VclPtr<VirtualDevice> Gtk3Surface::createVirtualDevice() const
112 return VclPtrInstance<VirtualDevice>(nullptr, Size(1, 1), 0);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */