Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / headless / svpvd.cxx
blobb5ab755a0d1bf50902fde1b9bc755d5cde538f92
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>
29 #include <cairo.h>
31 using namespace basegfx;
33 SvpSalVirtualDevice::~SvpSalVirtualDevice()
35 cairo_surface_destroy(m_pSurface);
38 SalGraphics* SvpSalVirtualDevice::AcquireGraphics()
40 SvpSalGraphics* pGraphics = new SvpSalGraphics();
41 pGraphics->setSurface(m_pSurface, m_aFrameSize);
42 m_aGraphics.push_back( pGraphics );
43 return pGraphics;
46 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
48 m_aGraphics.remove( dynamic_cast<SvpSalGraphics*>(pGraphics) );
49 delete pGraphics;
52 bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
54 return SetSizeUsingBuffer(nNewDX, nNewDY, nullptr);
57 bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
58 sal_uInt8 *const pBuffer)
60 if (nNewDX == 0)
61 nNewDX = 1;
62 if (nNewDY == 0)
63 nNewDY = 1;
65 if (!m_pSurface || m_aFrameSize.getX() != nNewDX ||
66 m_aFrameSize.getY() != nNewDY )
68 m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY);
70 nNewDX *= m_fScale;
71 nNewDY *= m_fScale;
73 if (m_pSurface)
75 cairo_surface_destroy(m_pSurface);
78 if (m_eFormat == DeviceFormat::BITMASK)
80 m_pSurface = cairo_image_surface_create(CAIRO_FORMAT_A1,
81 nNewDX, nNewDY);
83 else
85 m_pSurface = pBuffer ?
86 cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32,
87 nNewDX, nNewDY,
88 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX))
90 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
91 nNewDX, nNewDY);
94 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
95 cairo_surface_set_device_scale(m_pSurface, m_fScale, m_fScale);
96 #endif
98 // update device in existing graphics
99 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
100 it != m_aGraphics.end(); ++it )
101 (*it)->setSurface(m_pSurface, m_aFrameSize);
103 return true;
106 long SvpSalVirtualDevice::GetWidth() const
108 return m_pSurface ? m_aFrameSize.getX() : 0;
111 long SvpSalVirtualDevice::GetHeight() const
113 return m_pSurface ? m_aFrameSize.getY() : 0;
116 #endif
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */