bump product version to 6.3.0.0.beta1
[LibreOffice.git] / vcl / headless / svpvd.cxx
blobeeccf2c014a913142f9c87cabe9a96d4c73d2bef
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/.
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 .
20 #ifndef IOS
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>
30 #include <cairo.h>
32 using namespace basegfx;
34 SvpSalVirtualDevice::SvpSalVirtualDevice(DeviceFormat eFormat, cairo_surface_t* pRefSurface)
35 : m_eFormat(eFormat)
36 , m_pRefSurface(pRefSurface)
37 , m_pSurface(nullptr)
39 cairo_surface_reference(m_pRefSurface);
42 SvpSalVirtualDevice::~SvpSalVirtualDevice()
44 cairo_surface_destroy(m_pSurface);
45 cairo_surface_destroy(m_pRefSurface);
48 SalGraphics* SvpSalVirtualDevice::AcquireGraphics()
50 SvpSalGraphics* pGraphics = new SvpSalGraphics();
51 pGraphics->setSurface(m_pSurface, m_aFrameSize);
52 m_aGraphics.push_back( pGraphics );
53 return pGraphics;
56 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
58 m_aGraphics.erase(std::remove(m_aGraphics.begin(), m_aGraphics.end(), dynamic_cast<SvpSalGraphics*>(pGraphics)), m_aGraphics.end());
59 delete pGraphics;
62 bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
64 return SetSizeUsingBuffer(nNewDX, nNewDY, nullptr);
67 bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
68 sal_uInt8 *const pBuffer)
70 if (nNewDX == 0)
71 nNewDX = 1;
72 if (nNewDY == 0)
73 nNewDY = 1;
75 if (!m_pSurface || m_aFrameSize.getX() != nNewDX ||
76 m_aFrameSize.getY() != nNewDY )
78 m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY);
80 if (m_pSurface)
82 cairo_surface_destroy(m_pSurface);
85 if (m_eFormat == DeviceFormat::BITMASK)
87 m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_ALPHA,
88 nNewDX, nNewDY);
90 else if (pBuffer)
92 double fXScale, fYScale;
93 if (comphelper::LibreOfficeKit::isActive())
95 // Force scaling of the painting
96 fXScale = fYScale = comphelper::LibreOfficeKit::getDPIScale();
98 else
100 dl_cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale);
101 nNewDX *= fXScale;
102 nNewDY *= fYScale;
105 m_pSurface = cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32,
106 nNewDX, nNewDY, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX));
108 dl_cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale);
110 else
112 m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_COLOR_ALPHA, nNewDX, nNewDY);
115 // update device in existing graphics
116 for (auto const& graphic : m_aGraphics)
117 graphic->setSurface(m_pSurface, m_aFrameSize);
119 return true;
122 long SvpSalVirtualDevice::GetWidth() const
124 return m_pSurface ? m_aFrameSize.getX() : 0;
127 long SvpSalVirtualDevice::GetHeight() const
129 return m_pSurface ? m_aFrameSize.getY() : 0;
132 #endif
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */