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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <headless/svpbmp.hxx>
23 #include <headless/svpinst.hxx>
24 #include <headless/svpvd.hxx>
25 #include <headless/svpgdi.hxx>
27 #include <basegfx/vector/b2ivector.hxx>
28 #include <comphelper/lok.hxx>
32 using namespace basegfx
;
34 SvpSalVirtualDevice::SvpSalVirtualDevice(DeviceFormat eFormat
, cairo_surface_t
* pRefSurface
, cairo_surface_t
* pPreExistingTarget
)
36 , m_pRefSurface(pRefSurface
)
37 , m_pSurface(pPreExistingTarget
)
38 , m_bOwnsSurface(!pPreExistingTarget
)
40 cairo_surface_reference(m_pRefSurface
);
43 SvpSalVirtualDevice::~SvpSalVirtualDevice()
46 cairo_surface_destroy(m_pSurface
);
47 cairo_surface_destroy(m_pRefSurface
);
50 SvpSalGraphics
* SvpSalVirtualDevice::AddGraphics(SvpSalGraphics
* pGraphics
)
52 pGraphics
->setSurface(m_pSurface
, m_aFrameSize
);
53 m_aGraphics
.push_back(pGraphics
);
57 SalGraphics
* SvpSalVirtualDevice::AcquireGraphics()
59 return AddGraphics(new SvpSalGraphics());
62 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics
* pGraphics
)
64 m_aGraphics
.erase(std::remove(m_aGraphics
.begin(), m_aGraphics
.end(), dynamic_cast<SvpSalGraphics
*>(pGraphics
)), m_aGraphics
.end());
68 bool SvpSalVirtualDevice::SetSize( tools::Long nNewDX
, tools::Long nNewDY
)
70 return SetSizeUsingBuffer(nNewDX
, nNewDY
, nullptr);
73 void SvpSalVirtualDevice::CreateSurface(tools::Long nNewDX
, tools::Long nNewDY
, sal_uInt8
*const pBuffer
)
77 cairo_surface_destroy(m_pSurface
);
80 if (m_eFormat
== DeviceFormat::BITMASK
)
82 m_pSurface
= cairo_surface_create_similar(m_pRefSurface
, CAIRO_CONTENT_ALPHA
,
87 double fXScale
, fYScale
;
88 if (comphelper::LibreOfficeKit::isActive())
90 // Force scaling of the painting
91 fXScale
= fYScale
= comphelper::LibreOfficeKit::getDPIScale();
95 dl_cairo_surface_get_device_scale(m_pRefSurface
, &fXScale
, &fYScale
);
100 m_pSurface
= cairo_image_surface_create_for_data(pBuffer
, CAIRO_FORMAT_ARGB32
,
101 nNewDX
, nNewDY
, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32
, nNewDX
));
103 dl_cairo_surface_set_device_scale(m_pSurface
, fXScale
, fYScale
);
107 m_pSurface
= cairo_surface_create_similar(m_pRefSurface
, CAIRO_CONTENT_COLOR_ALPHA
, nNewDX
, nNewDY
);
111 bool SvpSalVirtualDevice::SetSizeUsingBuffer( tools::Long nNewDX
, tools::Long nNewDY
,
112 sal_uInt8
*const pBuffer
)
119 if (!m_pSurface
|| m_aFrameSize
.getX() != nNewDX
||
120 m_aFrameSize
.getY() != nNewDY
)
122 m_aFrameSize
= basegfx::B2IVector(nNewDX
, nNewDY
);
125 CreateSurface(nNewDX
, nNewDY
, pBuffer
);
129 // update device in existing graphics
130 for (auto const& graphic
: m_aGraphics
)
131 graphic
->setSurface(m_pSurface
, m_aFrameSize
);
136 tools::Long
SvpSalVirtualDevice::GetWidth() const
138 return m_pSurface
? m_aFrameSize
.getX() : 0;
141 tools::Long
SvpSalVirtualDevice::GetHeight() const
143 return m_pSurface
? m_aFrameSize
.getY() : 0;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */