bump product version to 6.4.0.3
[LibreOffice.git] / vcl / qt5 / Qt5SvpSurface.cxx
blob21e0ca03b5b2c31c3f28a94aa78141d0ab4d2e63
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 <Qt5SvpSurface.hxx>
14 #include <Qt5SvpGraphics.hxx>
16 #include <vcl/sysdata.hxx>
17 #include <vcl/bitmap.hxx>
18 #include <vcl/virdev.hxx>
19 #include <vcl/window.hxx>
20 #include <basegfx/vector/b2isize.hxx>
22 namespace
24 Size get_surface_size(cairo_surface_t* surface)
26 cairo_t* cr = cairo_create(surface);
27 double x1, x2, y1, y2;
28 cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
29 cairo_destroy(cr);
30 return Size(x2 - x1, y2 - y1);
34 namespace cairo
36 Qt5SvpSurface::Qt5SvpSurface(const CairoSurfaceSharedPtr& pSurface)
37 : m_pGraphics(nullptr)
38 , m_pCairoContext(nullptr)
39 , m_pSurface(pSurface)
43 Qt5SvpSurface::Qt5SvpSurface(const Qt5SvpGraphics* pGraphics, int x, int y, int width, int height)
44 : m_pGraphics(pGraphics)
45 , m_pCairoContext(pGraphics->getCairoContext(false))
47 cairo_surface_t* surface = cairo_get_target(m_pCairoContext);
48 m_pSurface.reset(cairo_surface_create_for_rectangle(surface, x, y, width, height),
49 &cairo_surface_destroy);
52 Qt5SvpSurface::~Qt5SvpSurface()
54 if (m_pCairoContext)
55 cairo_destroy(m_pCairoContext);
58 CairoSharedPtr Qt5SvpSurface::getCairo() const
60 return CairoSharedPtr(cairo_create(m_pSurface.get()), &cairo_destroy);
63 SurfaceSharedPtr Qt5SvpSurface::getSimilar(int cairo_content_type, int width, int height) const
65 return SurfaceSharedPtr(new Qt5SvpSurface(CairoSurfaceSharedPtr(
66 cairo_surface_create_similar(
67 m_pSurface.get(), static_cast<cairo_content_t>(cairo_content_type), width, height),
68 &cairo_surface_destroy)));
71 void Qt5SvpSurface::flush() const
73 cairo_surface_flush(m_pSurface.get());
74 if (m_pGraphics)
75 m_pGraphics->updateQWidget();
78 VclPtr<VirtualDevice> Qt5SvpSurface::createVirtualDevice() const
80 SystemGraphicsData aSystemGraphicsData;
82 aSystemGraphicsData.nSize = sizeof(SystemGraphicsData);
83 aSystemGraphicsData.pSurface = m_pSurface.get();
85 return VclPtr<VirtualDevice>::Create(aSystemGraphicsData, get_surface_size(m_pSurface.get()),
86 DeviceFormat::DEFAULT);
89 } // namespace cairo
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */