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 .
20 #include "headless/svpbmp.hxx"
21 #include "headless/svpvd.hxx"
22 #include "headless/svpgdi.hxx"
24 #include <basegfx/vector/b2ivector.hxx>
25 #include <basebmp/scanlineformats.hxx>
29 using namespace basegfx
;
30 using namespace basebmp
;
32 SvpSalVirtualDevice::~SvpSalVirtualDevice()
36 SalGraphics
* SvpSalVirtualDevice::GetGraphics()
38 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
39 pGraphics
->setDevice( m_aDevice
);
40 m_aGraphics
.push_back( pGraphics
);
44 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics
* pGraphics
)
46 m_aGraphics
.remove( dynamic_cast<SvpSalGraphics
*>(pGraphics
) );
50 sal_Bool
SvpSalVirtualDevice::SetSize( long nNewDX
, long nNewDY
)
52 return SetSizeUsingBuffer( nNewDX
, nNewDY
, basebmp::RawMemorySharedArray() );
55 sal_Bool
SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX
, long nNewDY
, const basebmp::RawMemorySharedArray
&pBuffer
)
57 B2IVector
aDevSize( nNewDX
, nNewDY
);
58 if( aDevSize
.getX() == 0 )
60 if( aDevSize
.getY() == 0 )
62 if( ! m_aDevice
.get() || m_aDevice
->getSize() != aDevSize
)
64 basebmp::Format nFormat
= SVP_DEFAULT_BITMAP_FORMAT
;
65 std::vector
< basebmp::Color
> aDevPal
;
68 case 1: nFormat
= FORMAT_ONE_BIT_MSB_PAL
;
70 aDevPal
.push_back( basebmp::Color( 0, 0, 0 ) );
71 aDevPal
.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
73 case 4: nFormat
= FORMAT_FOUR_BIT_MSB_PAL
; break;
74 case 8: nFormat
= FORMAT_EIGHT_BIT_PAL
; break;
76 case 16: nFormat
= FORMAT_SIXTEEN_BIT_MSB_TC_MASK
; break;
78 case 16: nFormat
= FORMAT_SIXTEEN_BIT_LSB_TC_MASK
; break;
80 case 24: nFormat
= FORMAT_TWENTYFOUR_BIT_TC_MASK
; break;
81 case 32: nFormat
= FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA
; break;
82 #if defined(ANDROID) || defined(IOS)
83 case 0: nFormat
= FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA
; break;
85 case 0: nFormat
= FORMAT_TWENTYFOUR_BIT_TC_MASK
; break;
88 m_aDevice
= aDevPal
.empty()
90 ? createBitmapDevice( aDevSize
, false, nFormat
, pBuffer
, PaletteMemorySharedVector() )
91 : createBitmapDevice( aDevSize
, false, nFormat
)
93 : createBitmapDevice( aDevSize
, false, nFormat
, PaletteMemorySharedVector( new std::vector
< basebmp::Color
>(aDevPal
) ) );
95 // update device in existing graphics
96 for( std::list
< SvpSalGraphics
* >::iterator it
= m_aGraphics
.begin();
97 it
!= m_aGraphics
.end(); ++it
)
98 (*it
)->setDevice( m_aDevice
);
104 void SvpSalVirtualDevice::GetSize( long& rWidth
, long& rHeight
)
106 if( m_aDevice
.get() )
108 B2IVector
aDevSize( m_aDevice
->getSize() );
109 rWidth
= aDevSize
.getX();
110 rHeight
= aDevSize
.getY();
113 rWidth
= rHeight
= 0;
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */