1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
24 Qt5SvpSurface::Qt5SvpSurface(const CairoSurfaceSharedPtr
& m_pSurface
)
25 : m_pGraphics(nullptr)
26 , m_pCairoContext(nullptr)
27 , m_pSurface(m_pSurface
)
31 Qt5SvpSurface::Qt5SvpSurface(const Qt5SvpGraphics
* pGraphics
, int x
, int y
, int width
, int height
)
32 : m_pGraphics(pGraphics
)
33 , m_pCairoContext(pGraphics
->getCairoContext(false))
35 cairo_surface_t
* surface
= cairo_get_target(m_pCairoContext
);
36 m_pSurface
.reset(cairo_surface_create_for_rectangle(surface
, x
, y
, width
, height
),
37 &cairo_surface_destroy
);
40 Qt5SvpSurface::~Qt5SvpSurface()
43 cairo_destroy(m_pCairoContext
);
46 CairoSharedPtr
Qt5SvpSurface::getCairo() const
48 return CairoSharedPtr(cairo_create(m_pSurface
.get()), &cairo_destroy
);
51 SurfaceSharedPtr
Qt5SvpSurface::getSimilar(int cairo_content_type
, int width
, int height
) const
53 return SurfaceSharedPtr(new Qt5SvpSurface(CairoSurfaceSharedPtr(
54 cairo_surface_create_similar(
55 m_pSurface
.get(), static_cast<cairo_content_t
>(cairo_content_type
), width
, height
),
56 &cairo_surface_destroy
)));
59 void Qt5SvpSurface::flush() const
61 cairo_surface_flush(m_pSurface
.get());
63 m_pGraphics
->updateQWidget();
66 VclPtr
<VirtualDevice
> Qt5SvpSurface::createVirtualDevice() const
68 return VclPtrInstance
<VirtualDevice
>(nullptr, Size(1, 1), DeviceFormat::DEFAULT
);
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */