nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / gtk3 / cairo_gtk3_cairo.cxx
blob2e882ded6231421dc74a1c89f61a16972b7b8982
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 "cairo_gtk3_cairo.hxx"
12 #include <vcl/sysdata.hxx>
13 #include <vcl/virdev.hxx>
15 #include <unx/gtk/gtkgdi.hxx>
17 namespace
19 Size get_surface_size(cairo_surface_t *surface)
21 cairo_t *cr = cairo_create(surface);
22 double x1, x2, y1, y2;
23 cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
24 cairo_destroy(cr);
25 return Size(x2 - x1, y2 - y1);
29 namespace cairo
31 /**
32 * Surface::Surface: Create generic Canvas surface using given Cairo Surface
34 * @param pSurface Cairo Surface
36 * This constructor only stores data, it does no processing.
37 * It is used with e.g. cairo_image_surface_create_for_data()
39 * Set the mpSurface as pSurface
40 **/
41 Gtk3Surface::Gtk3Surface(const CairoSurfaceSharedPtr& pSurface)
42 : mpGraphics(nullptr)
43 , cr(nullptr)
44 , mpSurface(pSurface)
47 /**
48 * Surface::Surface: Create Canvas surface from Window reference.
49 * @param x horizontal location of the new surface
50 * @param y vertical location of the new surface
51 * @param width width of the new surface
52 * @param height height of the new surface
54 * Set the mpSurface to the new surface or NULL
55 **/
56 Gtk3Surface::Gtk3Surface(const GtkSalGraphics* pGraphics, int x, int y, int width, int height)
57 : mpGraphics(pGraphics)
58 , cr(pGraphics->getCairoContext(false))
60 cairo_surface_t* surface = cairo_get_target(cr);
61 mpSurface.reset(
62 cairo_surface_create_for_rectangle(surface, x, y, width, height),
63 &cairo_surface_destroy);
66 Gtk3Surface::~Gtk3Surface()
68 if (cr)
69 cairo_destroy(cr);
72 /**
73 * Surface::getCairo: Create Cairo (drawing object) for the Canvas surface
75 * @return new Cairo or NULL
76 **/
77 CairoSharedPtr Gtk3Surface::getCairo() const
79 return CairoSharedPtr( cairo_create(mpSurface.get()),
80 &cairo_destroy );
83 /**
84 * Surface::getSimilar: Create new similar Canvas surface
85 * @param cairo_content_type format of the new surface (cairo_content_t from cairo/src/cairo.h)
86 * @param width width of the new surface
87 * @param height height of the new surface
89 * Creates a new Canvas surface. This normally creates platform native surface, even though
90 * generic function is used.
92 * Cairo surface from cairo_content_type (cairo_content_t)
94 * @return new surface or NULL
95 **/
96 SurfaceSharedPtr Gtk3Surface::getSimilar(int cairo_content_type, int width, int height ) const
98 return std::make_shared<Gtk3Surface>(
99 CairoSurfaceSharedPtr(
100 cairo_surface_create_similar( mpSurface.get(),
101 static_cast<cairo_content_t>(cairo_content_type), width, height ),
102 &cairo_surface_destroy ));
105 void Gtk3Surface::flush() const
107 cairo_surface_flush(mpSurface.get());
108 //Wonder if there is any benefit in using cairo_fill/stroke extents on
109 //every canvas call and only redrawing the union of those in a
110 //poor-mans-damage tracking
111 if (mpGraphics)
112 mpGraphics->WidgetQueueDraw();
115 VclPtr<VirtualDevice> Gtk3Surface::createVirtualDevice() const
117 SystemGraphicsData aSystemGraphicsData;
119 aSystemGraphicsData.nSize = sizeof(SystemGraphicsData);
120 aSystemGraphicsData.pSurface = mpSurface.get();
122 return VclPtr<VirtualDevice>::Create(aSystemGraphicsData,
123 get_surface_size(mpSurface.get()),
124 DeviceFormat::DEFAULT);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */