Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / headless / svpvd.cxx
blob1e4050a639cfa2eaaa397bdb2c247926966bde29
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 <vcl/svpforlokit.hxx>
24 #include "headless/svpbmp.hxx"
25 #include "headless/svpinst.hxx"
26 #include "headless/svpvd.hxx"
27 #include "headless/svpgdi.hxx"
29 #include <basegfx/vector/b2ivector.hxx>
30 #include <basebmp/scanlineformats.hxx>
32 #include "stdio.h"
34 using namespace basegfx;
35 using namespace basebmp;
37 SvpSalVirtualDevice::~SvpSalVirtualDevice()
41 SalGraphics* SvpSalVirtualDevice::AcquireGraphics()
43 SvpSalGraphics* pGraphics = new SvpSalGraphics();
44 pGraphics->setDevice( m_aDevice );
45 m_aGraphics.push_back( pGraphics );
46 return pGraphics;
49 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
51 m_aGraphics.remove( dynamic_cast<SvpSalGraphics*>(pGraphics) );
52 delete pGraphics;
55 bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
57 return SetSizeUsingBuffer( nNewDX, nNewDY, basebmp::RawMemorySharedArray(), false );
60 bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
61 const basebmp::RawMemorySharedArray &pBuffer,
62 const bool bTopDown )
64 B2IVector aDevSize( nNewDX, nNewDY );
65 if( aDevSize.getX() == 0 )
66 aDevSize.setX( 1 );
67 if( aDevSize.getY() == 0 )
68 aDevSize.setY( 1 );
69 if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
71 SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
72 assert( pInst );
73 basebmp::Format nFormat = pInst->getFormatForBitCount( m_nBitCount );
74 sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(nFormat, aDevSize.getX());
76 if ( m_nBitCount == 1 )
78 std::vector< basebmp::Color > aDevPal(2);
79 aDevPal[0] = basebmp::Color( 0, 0, 0 );
80 aDevPal[1] = basebmp::Color( 0xff, 0xff, 0xff );
81 m_aDevice = createBitmapDevice( aDevSize, bTopDown, nFormat, nStride,
82 PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
84 else
86 m_aDevice = pBuffer ?
87 createBitmapDevice( aDevSize, bTopDown, nFormat, nStride, pBuffer, PaletteMemorySharedVector() )
88 : createBitmapDevice( aDevSize, bTopDown, nFormat, nStride );
91 // update device in existing graphics
92 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
93 it != m_aGraphics.end(); ++it )
94 (*it)->setDevice( m_aDevice );
97 return true;
100 void InitSvpForLibreOfficeKit()
102 ImplSVData* pSVData = ImplGetSVData();
103 SvpSalInstance* pSalInstance = static_cast< SvpSalInstance* >(pSVData->mpDefInst);
104 pSalInstance->setBitCountFormatMapping( 32, ::basebmp::FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA );
107 #endif
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */