Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <tools/debug.hxx>
21 :
22 : #include <vcl/settings.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/wrkwin.hxx>
25 : #include <vcl/virdev.hxx>
26 :
27 : #include <salinst.hxx>
28 : #include <salgdi.hxx>
29 : #include <salframe.hxx>
30 : #include <salvd.hxx>
31 : #include <outdev.h>
32 : #include "PhysicalFontCollection.hxx"
33 : #include <svdata.hxx>
34 :
35 : using namespace ::com::sun::star::uno;
36 :
37 0 : bool VirtualDevice::ImplInitGraphics() const
38 : {
39 : DBG_TESTSOLARMUTEX();
40 :
41 0 : if ( mpGraphics )
42 0 : return true;
43 :
44 0 : mbInitLineColor = true;
45 0 : mbInitFillColor = true;
46 0 : mbInitFont = true;
47 0 : mbInitTextColor = true;
48 0 : mbInitClipRegion = true;
49 :
50 0 : ImplSVData* pSVData = ImplGetSVData();
51 :
52 0 : if ( mpVirDev )
53 : {
54 0 : mpGraphics = mpVirDev->AcquireGraphics();
55 : // if needed retry after releasing least recently used virtual device graphics
56 0 : while ( !mpGraphics )
57 : {
58 0 : if ( !pSVData->maGDIData.mpLastVirGraphics )
59 0 : break;
60 0 : pSVData->maGDIData.mpLastVirGraphics->ImplReleaseGraphics();
61 0 : mpGraphics = mpVirDev->AcquireGraphics();
62 : }
63 : // update global LRU list of virtual device graphics
64 0 : if ( mpGraphics )
65 : {
66 0 : mpNextGraphics = pSVData->maGDIData.mpFirstVirGraphics;
67 0 : pSVData->maGDIData.mpFirstVirGraphics = const_cast<VirtualDevice*>(this);
68 0 : if ( mpNextGraphics )
69 0 : mpNextGraphics->mpPrevGraphics = const_cast<VirtualDevice*>(this);
70 0 : if ( !pSVData->maGDIData.mpLastVirGraphics )
71 0 : pSVData->maGDIData.mpLastVirGraphics = const_cast<VirtualDevice*>(this);
72 : }
73 : }
74 :
75 0 : if ( mpGraphics )
76 : {
77 0 : mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp );
78 0 : mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW);
79 : }
80 :
81 0 : return mpGraphics ? true : false;
82 : }
83 :
84 0 : void VirtualDevice::ImplReleaseGraphics( bool bRelease )
85 : {
86 : DBG_TESTSOLARMUTEX();
87 :
88 0 : if ( !mpGraphics )
89 0 : return;
90 :
91 : // release the fonts of the physically released graphics device
92 0 : if ( bRelease )
93 0 : ImplReleaseFonts();
94 :
95 0 : ImplSVData* pSVData = ImplGetSVData();
96 :
97 0 : VirtualDevice* pVirDev = (VirtualDevice*)this;
98 :
99 0 : if ( bRelease )
100 0 : pVirDev->mpVirDev->ReleaseGraphics( mpGraphics );
101 : // remove from global LRU list of virtual device graphics
102 0 : if ( mpPrevGraphics )
103 0 : mpPrevGraphics->mpNextGraphics = mpNextGraphics;
104 : else
105 0 : pSVData->maGDIData.mpFirstVirGraphics = mpNextGraphics;
106 0 : if ( mpNextGraphics )
107 0 : mpNextGraphics->mpPrevGraphics = mpPrevGraphics;
108 : else
109 0 : pSVData->maGDIData.mpLastVirGraphics = mpPrevGraphics;
110 :
111 0 : mpGraphics = NULL;
112 0 : mpPrevGraphics = NULL;
113 0 : mpNextGraphics = NULL;
114 : }
115 :
116 0 : void VirtualDevice::ImplInitVirDev( const OutputDevice* pOutDev,
117 : long nDX, long nDY, sal_uInt16 nBitCount, const SystemGraphicsData *pData )
118 : {
119 : SAL_INFO( "vcl.virdev", "ImplInitVirDev(" << nDX << "," << nDY << "," << nBitCount << ")" );
120 :
121 0 : if ( nDX < 1 )
122 0 : nDX = 1;
123 :
124 0 : if ( nDY < 1 )
125 0 : nDY = 1;
126 :
127 0 : ImplSVData* pSVData = ImplGetSVData();
128 :
129 0 : if ( !pOutDev )
130 0 : pOutDev = ImplGetDefaultWindow();
131 0 : if( !pOutDev )
132 0 : return;
133 :
134 : SalGraphics* pGraphics;
135 0 : if ( !pOutDev->mpGraphics )
136 0 : ((OutputDevice*)pOutDev)->ImplGetGraphics();
137 0 : pGraphics = pOutDev->mpGraphics;
138 0 : if ( pGraphics )
139 0 : mpVirDev = pSVData->mpDefInst->CreateVirtualDevice( pGraphics, nDX, nDY, nBitCount, pData );
140 : else
141 0 : mpVirDev = NULL;
142 0 : if ( !mpVirDev )
143 : {
144 : // do not abort but throw an exception, may be the current thread terminates anyway (plugin-scenario)
145 : throw ::com::sun::star::uno::RuntimeException(
146 : OUString( "Could not create system bitmap!" ),
147 0 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
148 : }
149 :
150 0 : mnBitCount = ( nBitCount ? nBitCount : pOutDev->GetBitCount() );
151 0 : mnOutWidth = nDX;
152 0 : mnOutHeight = nDY;
153 0 : mbScreenComp = true;
154 0 : mnAlphaDepth = -1;
155 :
156 : // #i59315# init vdev size from system object, when passed a
157 : // SystemGraphicsData. Otherwise, output size will always
158 : // incorrectly stay at (1,1)
159 0 : if( pData && mpVirDev )
160 0 : mpVirDev->GetSize(mnOutWidth,mnOutHeight);
161 :
162 0 : if( mnBitCount < 8 )
163 0 : SetAntialiasing( ANTIALIASING_DISABLE_TEXT );
164 :
165 0 : if ( pOutDev->GetOutDevType() == OUTDEV_PRINTER )
166 0 : mbScreenComp = false;
167 0 : else if ( pOutDev->GetOutDevType() == OUTDEV_VIRDEV )
168 0 : mbScreenComp = ((VirtualDevice*)pOutDev)->mbScreenComp;
169 :
170 0 : meOutDevType = OUTDEV_VIRDEV;
171 0 : mbDevOutput = true;
172 0 : mpFontCollection = pSVData->maGDIData.mpScreenFontList;
173 0 : mpFontCache = pSVData->maGDIData.mpScreenFontCache;
174 0 : mnDPIX = pOutDev->mnDPIX;
175 0 : mnDPIY = pOutDev->mnDPIY;
176 0 : mnDPIScaleFactor = pOutDev->mnDPIScaleFactor;
177 0 : maFont = pOutDev->maFont;
178 :
179 0 : if( maTextColor != pOutDev->maTextColor )
180 : {
181 0 : maTextColor = pOutDev->maTextColor;
182 0 : mbInitTextColor = true;
183 : }
184 :
185 : // virtual devices have white background by default
186 0 : SetBackground( Wallpaper( Color( COL_WHITE ) ) );
187 :
188 : // #i59283# don't erase user-provided surface
189 0 : if( !pData )
190 0 : Erase();
191 :
192 : // register VirDev in the list
193 0 : mpNext = pSVData->maGDIData.mpFirstVirDev;
194 0 : mpPrev = NULL;
195 0 : if ( mpNext )
196 0 : mpNext->mpPrev = this;
197 : else
198 0 : pSVData->maGDIData.mpLastVirDev = this;
199 0 : pSVData->maGDIData.mpFirstVirDev = this;
200 : }
201 :
202 0 : VirtualDevice::VirtualDevice( sal_uInt16 nBitCount )
203 : : mpVirDev( NULL ),
204 0 : meRefDevMode( REFDEV_NONE )
205 : {
206 : SAL_WARN_IF( nBitCount > 1 && nBitCount != 8, "vcl.gdi",
207 : "VirtualDevice::VirtualDevice(): Only 0, 1 or 8 allowed for BitCount, not " << nBitCount );
208 : SAL_INFO( "vcl.gdi", "VirtualDevice::VirtualDevice( " << nBitCount << " )" );
209 :
210 0 : ImplInitVirDev( Application::GetDefaultDevice(), 1, 1, nBitCount );
211 0 : }
212 :
213 0 : VirtualDevice::VirtualDevice( const OutputDevice& rCompDev, sal_uInt16 nBitCount )
214 : : mpVirDev( NULL ),
215 0 : meRefDevMode( REFDEV_NONE )
216 : {
217 : SAL_WARN_IF( nBitCount > 1 && nBitCount != 8, "vcl.gdi",
218 : "VirtualDevice::VirtualDevice(): Only 0, 1 or 8 allowed for BitCount, not " << nBitCount );
219 : SAL_INFO( "vcl.gdi", "VirtualDevice::VirtualDevice( " << nBitCount << " )" );
220 :
221 0 : ImplInitVirDev( &rCompDev, 1, 1, nBitCount );
222 0 : }
223 :
224 0 : VirtualDevice::VirtualDevice( const OutputDevice& rCompDev, sal_uInt16 nBitCount, sal_uInt16 nAlphaBitCount )
225 : : mpVirDev( NULL ),
226 0 : meRefDevMode( REFDEV_NONE )
227 : {
228 : SAL_WARN_IF( nBitCount > 1 && nBitCount != 8, "vcl.gdi",
229 : "VirtualDevice::VirtualDevice(): Only 0, 1 or 8 allowed for BitCount, not " << nBitCount );
230 : SAL_INFO( "vcl.gdi",
231 : "VirtualDevice::VirtualDevice( " << nBitCount << ", " << nAlphaBitCount << " )" );
232 :
233 0 : ImplInitVirDev( &rCompDev, 1, 1, nBitCount );
234 :
235 : // Enable alpha channel
236 0 : mnAlphaDepth = sal::static_int_cast<sal_Int8>(nAlphaBitCount);
237 0 : }
238 :
239 0 : VirtualDevice::VirtualDevice( const SystemGraphicsData *pData, sal_uInt16 nBitCount )
240 : : mpVirDev( NULL ),
241 0 : meRefDevMode( REFDEV_NONE )
242 : {
243 : SAL_INFO( "vcl.gdi", "VirtualDevice::VirtualDevice( " << nBitCount << " )" );
244 :
245 0 : ImplInitVirDev( Application::GetDefaultDevice(), 1, 1, nBitCount, pData );
246 0 : }
247 :
248 0 : VirtualDevice::~VirtualDevice()
249 : {
250 : SAL_INFO( "vcl.gdi", "VirtualDevice::~VirtualDevice()" );
251 :
252 0 : ImplSVData* pSVData = ImplGetSVData();
253 :
254 0 : ImplReleaseGraphics();
255 :
256 0 : delete mpVirDev;
257 :
258 : // remove this VirtualDevice from the double-linked global list
259 0 : if( mpPrev )
260 0 : mpPrev->mpNext = mpNext;
261 : else
262 0 : pSVData->maGDIData.mpFirstVirDev = mpNext;
263 :
264 0 : if( mpNext )
265 0 : mpNext->mpPrev = mpPrev;
266 : else
267 0 : pSVData->maGDIData.mpLastVirDev = mpPrev;
268 0 : }
269 :
270 0 : bool VirtualDevice::InnerImplSetOutputSizePixel( const Size& rNewSize, bool bErase, const basebmp::RawMemorySharedArray &pBuffer )
271 : {
272 : SAL_INFO( "vcl.gdi",
273 : "VirtualDevice::InnerImplSetOutputSizePixel( " << rNewSize.Width() << ", "
274 : << rNewSize.Height() << ", " << int(bErase) << " )" );
275 :
276 0 : if ( !mpVirDev )
277 0 : return false;
278 0 : else if ( rNewSize == GetOutputSizePixel() )
279 : {
280 0 : if ( bErase )
281 0 : Erase();
282 : // Yeah, so trying to re-use a VirtualDevice but this time using a
283 : // pre-allocated buffer won't work. Big deal.
284 0 : return true;
285 : }
286 :
287 : bool bRet;
288 0 : long nNewWidth = rNewSize.Width(), nNewHeight = rNewSize.Height();
289 :
290 0 : if ( nNewWidth < 1 )
291 0 : nNewWidth = 1;
292 :
293 0 : if ( nNewHeight < 1 )
294 0 : nNewHeight = 1;
295 :
296 0 : if ( bErase )
297 : {
298 0 : if ( pBuffer )
299 0 : bRet = mpVirDev->SetSizeUsingBuffer( nNewWidth, nNewHeight, pBuffer );
300 : else
301 0 : bRet = mpVirDev->SetSize( nNewWidth, nNewHeight );
302 :
303 0 : if ( bRet )
304 : {
305 0 : mnOutWidth = rNewSize.Width();
306 0 : mnOutHeight = rNewSize.Height();
307 0 : Erase();
308 : }
309 : }
310 : else
311 : {
312 : SalVirtualDevice* pNewVirDev;
313 0 : ImplSVData* pSVData = ImplGetSVData();
314 :
315 : // we need a graphics
316 0 : if ( !mpGraphics )
317 : {
318 0 : if ( !ImplGetGraphics() )
319 0 : return false;
320 : }
321 :
322 0 : pNewVirDev = pSVData->mpDefInst->CreateVirtualDevice( mpGraphics, nNewWidth, nNewHeight, mnBitCount );
323 0 : if ( pNewVirDev )
324 : {
325 0 : SalGraphics* pGraphics = pNewVirDev->AcquireGraphics();
326 0 : if ( pGraphics )
327 : {
328 : SalTwoRect aPosAry;
329 : long nWidth;
330 : long nHeight;
331 0 : if ( mnOutWidth < nNewWidth )
332 0 : nWidth = mnOutWidth;
333 : else
334 0 : nWidth = nNewWidth;
335 0 : if ( mnOutHeight < nNewHeight )
336 0 : nHeight = mnOutHeight;
337 : else
338 0 : nHeight = nNewHeight;
339 0 : aPosAry.mnSrcX = 0;
340 0 : aPosAry.mnSrcY = 0;
341 0 : aPosAry.mnSrcWidth = nWidth;
342 0 : aPosAry.mnSrcHeight = nHeight;
343 0 : aPosAry.mnDestX = 0;
344 0 : aPosAry.mnDestY = 0;
345 0 : aPosAry.mnDestWidth = nWidth;
346 0 : aPosAry.mnDestHeight = nHeight;
347 :
348 0 : pGraphics->CopyBits( aPosAry, mpGraphics, this, this );
349 0 : pNewVirDev->ReleaseGraphics( pGraphics );
350 0 : ImplReleaseGraphics();
351 0 : delete mpVirDev;
352 0 : mpVirDev = pNewVirDev;
353 0 : mnOutWidth = rNewSize.Width();
354 0 : mnOutHeight = rNewSize.Height();
355 0 : bRet = true;
356 : }
357 : else
358 : {
359 0 : bRet = false;
360 0 : delete pNewVirDev;
361 : }
362 : }
363 : else
364 0 : bRet = false;
365 : }
366 :
367 0 : return bRet;
368 : }
369 :
370 : // #i32109#: Fill opaque areas correctly (without relying on
371 : // fill/linecolor state)
372 0 : void VirtualDevice::ImplFillOpaqueRectangle( const Rectangle& rRect )
373 : {
374 : // Set line and fill color to black (->opaque),
375 : // fill rect with that (linecolor, too, because of
376 : // those pesky missing pixel problems)
377 0 : Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
378 0 : SetLineColor( COL_BLACK );
379 0 : SetFillColor( COL_BLACK );
380 0 : DrawRect( rRect );
381 0 : Pop();
382 0 : }
383 :
384 0 : bool VirtualDevice::ImplSetOutputSizePixel( const Size& rNewSize, bool bErase, const basebmp::RawMemorySharedArray &pBuffer )
385 : {
386 0 : if( InnerImplSetOutputSizePixel(rNewSize, bErase, pBuffer) )
387 : {
388 0 : if( mnAlphaDepth != -1 )
389 : {
390 : // #110958# Setup alpha bitmap
391 0 : if(mpAlphaVDev && mpAlphaVDev->GetOutputSizePixel() != rNewSize)
392 : {
393 0 : delete mpAlphaVDev;
394 0 : mpAlphaVDev = 0L;
395 : }
396 :
397 0 : if( !mpAlphaVDev )
398 : {
399 0 : mpAlphaVDev = new VirtualDevice( *this, mnAlphaDepth );
400 0 : mpAlphaVDev->InnerImplSetOutputSizePixel(rNewSize, bErase, basebmp::RawMemorySharedArray() );
401 : }
402 :
403 : // TODO: copy full outdev state to new one, here. Also needed in outdev2.cxx:DrawOutDev
404 0 : if( GetLineColor() != Color( COL_TRANSPARENT ) )
405 0 : mpAlphaVDev->SetLineColor( COL_BLACK );
406 :
407 0 : if( GetFillColor() != Color( COL_TRANSPARENT ) )
408 0 : mpAlphaVDev->SetFillColor( COL_BLACK );
409 :
410 0 : mpAlphaVDev->SetMapMode( GetMapMode() );
411 : }
412 :
413 0 : return true;
414 : }
415 :
416 0 : return false;
417 : }
418 :
419 0 : void VirtualDevice::EnableRTL( bool bEnable )
420 : {
421 : // virdevs default to not mirroring, they will only be set to mirroring
422 : // under rare circumstances in the UI, eg the valueset control
423 : // because each virdev has its own SalGraphics we can safely switch the SalGraphics here
424 : // ...hopefully
425 0 : if( ImplGetGraphics() )
426 0 : mpGraphics->SetLayout( bEnable ? SAL_LAYOUT_BIDI_RTL : 0 );
427 :
428 0 : OutputDevice::EnableRTL(bEnable);
429 0 : }
430 :
431 0 : bool VirtualDevice::SetOutputSizePixel( const Size& rNewSize, bool bErase )
432 : {
433 0 : return ImplSetOutputSizePixel( rNewSize, bErase, basebmp::RawMemorySharedArray() );
434 : }
435 :
436 0 : bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer( const Size& rNewSize, const Fraction& rScale, const Point& rNewOffset, const basebmp::RawMemorySharedArray &pBuffer )
437 : {
438 0 : if (pBuffer) {
439 0 : MapMode mm = GetMapMode();
440 0 : mm.SetOrigin( rNewOffset );
441 0 : mm.SetScaleX( rScale );
442 0 : mm.SetScaleY( rScale );
443 0 : SetMapMode( mm );
444 : }
445 0 : return ImplSetOutputSizePixel( rNewSize, true, pBuffer);
446 : }
447 :
448 0 : void VirtualDevice::SetReferenceDevice( RefDevMode i_eRefDevMode )
449 : {
450 0 : sal_Int32 nDPIX = 600, nDPIY = 600;
451 0 : switch( i_eRefDevMode )
452 : {
453 : case REFDEV_NONE:
454 : default:
455 : DBG_ASSERT( false, "VDev::SetRefDev illegal argument!" );
456 0 : break;
457 : case REFDEV_MODE06:
458 0 : nDPIX = nDPIY = 600;
459 0 : break;
460 : case REFDEV_MODE_MSO1:
461 0 : nDPIX = nDPIY = 6*1440;
462 0 : break;
463 : case REFDEV_MODE_PDF1:
464 0 : nDPIX = nDPIY = 720;
465 0 : break;
466 : }
467 0 : ImplSetReferenceDevice( i_eRefDevMode, nDPIX, nDPIY );
468 0 : }
469 :
470 0 : void VirtualDevice::SetReferenceDevice( sal_Int32 i_nDPIX, sal_Int32 i_nDPIY )
471 : {
472 0 : ImplSetReferenceDevice( REFDEV_CUSTOM, i_nDPIX, i_nDPIY );
473 0 : }
474 :
475 0 : void VirtualDevice::ImplSetReferenceDevice( RefDevMode i_eRefDevMode, sal_Int32 i_nDPIX, sal_Int32 i_nDPIY )
476 : {
477 0 : mnDPIX = i_nDPIX;
478 0 : mnDPIY = i_nDPIY;
479 0 : mnDPIScaleFactor = 1;
480 :
481 0 : EnableOutput( false ); // prevent output on reference device
482 0 : mbScreenComp = false;
483 :
484 : // invalidate currently selected fonts
485 0 : mbInitFont = true;
486 0 : mbNewFont = true;
487 :
488 : // avoid adjusting font lists when already in refdev mode
489 0 : sal_uInt8 nOldRefDevMode = meRefDevMode;
490 0 : sal_uInt8 nOldCompatFlag = (sal_uInt8)meRefDevMode & REFDEV_FORCE_ZERO_EXTLEAD;
491 0 : meRefDevMode = (sal_uInt8)(i_eRefDevMode | nOldCompatFlag);
492 0 : if( (nOldRefDevMode ^ nOldCompatFlag) != REFDEV_NONE )
493 0 : return;
494 :
495 : // the reference device should have only scalable fonts
496 : // => clean up the original font lists before getting new ones
497 0 : if ( mpFontEntry )
498 : {
499 0 : mpFontCache->Release( mpFontEntry );
500 0 : mpFontEntry = NULL;
501 : }
502 0 : if ( mpGetDevFontList )
503 : {
504 0 : delete mpGetDevFontList;
505 0 : mpGetDevFontList = NULL;
506 : }
507 0 : if ( mpGetDevSizeList )
508 : {
509 0 : delete mpGetDevSizeList;
510 0 : mpGetDevSizeList = NULL;
511 : }
512 :
513 : // preserve global font lists
514 0 : ImplSVData* pSVData = ImplGetSVData();
515 0 : if( mpFontCollection && (mpFontCollection != pSVData->maGDIData.mpScreenFontList) )
516 0 : delete mpFontCollection;
517 0 : if( mpFontCache && (mpFontCache != pSVData->maGDIData.mpScreenFontCache) )
518 0 : delete mpFontCache;
519 :
520 : // get font list with scalable fonts only
521 0 : ImplGetGraphics();
522 0 : mpFontCollection = pSVData->maGDIData.mpScreenFontList->Clone( true, false );
523 :
524 : // prepare to use new font lists
525 0 : mpFontCache = new ImplFontCache();
526 : }
527 :
528 0 : sal_uInt16 VirtualDevice::GetBitCount() const
529 : {
530 0 : return mnBitCount;
531 : }
532 :
533 0 : sal_uInt16 VirtualDevice::GetAlphaBitCount() const
534 : {
535 0 : if (mpAlphaVDev)
536 0 : return mpAlphaVDev->GetBitCount();
537 :
538 0 : return 0;
539 : }
540 :
541 0 : bool VirtualDevice::UsePolyPolygonForComplexGradient()
542 : {
543 0 : return true;
544 : }
545 :
546 0 : void VirtualDevice::Compat_ZeroExtleadBug()
547 : {
548 0 : meRefDevMode = (sal_uInt8)meRefDevMode | REFDEV_FORCE_ZERO_EXTLEAD;
549 3 : }
550 :
551 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|