bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / unx / gtk3 / gtkcairo.cxx
blobf389f4d087c170f310b27c61f3c0224ee6ee6bbd
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 "gtkcairo.hxx"
12 #include <utility>
13 #include <vcl/sysdata.hxx>
14 #include <vcl/virdev.hxx>
16 #include <unx/gtk/gtkgdi.hxx>
18 namespace
20 Size get_surface_size(cairo_surface_t *surface)
22 cairo_t *cr = cairo_create(surface);
23 double x1, x2, y1, y2;
24 cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
25 cairo_destroy(cr);
26 return Size(x2 - x1, y2 - y1);
30 namespace cairo
32 /**
33 * Surface::Surface: Create generic Canvas surface using given Cairo Surface
35 * @param pSurface Cairo Surface
37 * This constructor only stores data, it does no processing.
38 * It is used with e.g. cairo_image_surface_create_for_data()
40 * Set the mpSurface as pSurface
41 **/
42 Gtk3Surface::Gtk3Surface(CairoSurfaceSharedPtr pSurface)
43 : mpGraphics(nullptr)
44 , cr(nullptr)
45 , mpSurface(std::move(pSurface))
48 /**
49 * Surface::Surface: Create Canvas surface from Window reference.
50 * @param x horizontal location of the new surface
51 * @param y vertical location of the new surface
52 * @param width width of the new surface
53 * @param height height of the new surface
55 * Set the mpSurface to the new surface or NULL
56 **/
57 Gtk3Surface::Gtk3Surface(const GtkSalGraphics* pGraphics, int x, int y, int width, int height)
58 : mpGraphics(pGraphics)
59 , cr(pGraphics->getCairoContext())
61 cairo_surface_t* surface = cairo_get_target(cr);
62 mpSurface.reset(
63 cairo_surface_create_for_rectangle(surface, x, y, width, height),
64 &cairo_surface_destroy);
67 Gtk3Surface::~Gtk3Surface()
69 if (cr)
70 cairo_destroy(cr);
73 /**
74 * Surface::getCairo: Create Cairo (drawing object) for the Canvas surface
76 * @return new Cairo or NULL
77 **/
78 CairoSharedPtr Gtk3Surface::getCairo() const
80 return CairoSharedPtr( cairo_create(mpSurface.get()),
81 &cairo_destroy );
84 /**
85 * Surface::getSimilar: Create new similar Canvas surface
86 * @param cairo_content_type format of the new surface (cairo_content_t from cairo/src/cairo.h)
87 * @param width width of the new surface
88 * @param height height of the new surface
90 * Creates a new Canvas surface. This normally creates platform native surface, even though
91 * generic function is used.
93 * Cairo surface from cairo_content_type (cairo_content_t)
95 * @return new surface or NULL
96 **/
97 SurfaceSharedPtr Gtk3Surface::getSimilar(int cairo_content_type, int width, int height ) const
99 return std::make_shared<Gtk3Surface>(
100 CairoSurfaceSharedPtr(
101 cairo_surface_create_similar( mpSurface.get(),
102 static_cast<cairo_content_t>(cairo_content_type), width, height ),
103 &cairo_surface_destroy ));
106 void Gtk3Surface::flush() const
108 cairo_surface_flush(mpSurface.get());
109 //Wonder if there is any benefit in using cairo_fill/stroke extents on
110 //every canvas call and only redrawing the union of those in a
111 //poor-mans-damage tracking
112 if (mpGraphics)
113 mpGraphics->WidgetQueueDraw();
116 VclPtr<VirtualDevice> Gtk3Surface::createVirtualDevice() const
118 SystemGraphicsData aSystemGraphicsData;
120 aSystemGraphicsData.nSize = sizeof(SystemGraphicsData);
121 aSystemGraphicsData.pSurface = mpSurface.get();
123 return VclPtr<VirtualDevice>::Create(aSystemGraphicsData,
124 get_surface_size(mpSurface.get()),
125 DeviceFormat::WITHOUT_ALPHA);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */