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 :
21 : #include <stdio.h>
22 : #include <poll.h>
23 :
24 : #include "vcl/salbtype.hxx"
25 :
26 : #include "unx/salunx.h"
27 : #include "unx/saldata.hxx"
28 : #include "unx/saldisp.hxx"
29 : #include "unx/salbmp.h"
30 : #include "unx/salgdi.h"
31 : #include "unx/salframe.h"
32 : #include "unx/salvd.h"
33 : #include <unx/x11/xlimits.hxx>
34 : #include "xrender_peer.hxx"
35 :
36 : #include "generic/printergfx.hxx"
37 :
38 : #include "vcl/bmpacc.hxx"
39 : #include <outdata.hxx>
40 :
41 : #undef SALGDI2_TESTTRANS
42 :
43 : #if (OSL_DEBUG_LEVEL > 1) && defined SALGDI2_TESTTRANS
44 : #define DBG_TESTTRANS( _def_drawable ) \
45 : { \
46 : XCopyArea( pXDisp, _def_drawable, aDrawable, GetCopyGC(), \
47 : 0, 0, \
48 : rPosAry.mnDestWidth, rPosAry.mnDestHeight, \
49 : 0, 0 ); \
50 : }
51 : #else // (OSL_DEBUG_LEVEL > 1) && defined SALGDI2_TESTTRANS
52 : #define DBG_TESTTRANS( _def_drawable )
53 : #endif // (OSL_DEBUG_LEVEL > 1) && defined SALGDI2_TESTTRANS
54 :
55 0 : void X11SalGraphics::CopyScreenArea( Display* pDisplay,
56 : Drawable aSrc, SalX11Screen nXScreenSrc, int nSrcDepth,
57 : Drawable aDest, SalX11Screen nXScreenDest, int nDestDepth,
58 : GC aDestGC,
59 : int src_x, int src_y,
60 : unsigned int w, unsigned int h,
61 : int dest_x, int dest_y )
62 : {
63 0 : if( nSrcDepth == nDestDepth )
64 : {
65 0 : if( nXScreenSrc == nXScreenDest )
66 : XCopyArea( pDisplay, aSrc, aDest, aDestGC,
67 0 : src_x, src_y, w, h, dest_x, dest_y );
68 : else
69 : {
70 0 : GetGenericData()->ErrorTrapPush();
71 : XImage* pImage = XGetImage( pDisplay, aSrc, src_x, src_y, w, h,
72 0 : AllPlanes, ZPixmap );
73 0 : if( pImage )
74 : {
75 0 : if( pImage->data )
76 : XPutImage( pDisplay, aDest, aDestGC, pImage,
77 0 : 0, 0, dest_x, dest_y, w, h );
78 0 : XDestroyImage( pImage );
79 : }
80 0 : GetGenericData()->ErrorTrapPop();
81 : }
82 : }
83 : else
84 : {
85 0 : X11SalBitmap aBM;
86 0 : aBM.ImplCreateFromDrawable( aSrc, nXScreenSrc, nSrcDepth, src_x, src_y, w, h );
87 : SalTwoRect aTwoRect;
88 0 : aTwoRect.mnSrcX = aTwoRect.mnSrcY = 0;
89 0 : aTwoRect.mnSrcWidth = aTwoRect.mnDestWidth = w;
90 0 : aTwoRect.mnSrcHeight = aTwoRect.mnDestHeight = h;
91 0 : aTwoRect.mnDestX = dest_x;
92 0 : aTwoRect.mnDestY = dest_y;
93 0 : aBM.ImplDraw( aDest, nXScreenDest, nDestDepth, aTwoRect,aDestGC );
94 : }
95 0 : }
96 :
97 0 : GC X11SalGraphics::CreateGC( Drawable hDrawable, unsigned long nMask )
98 : {
99 : XGCValues values;
100 :
101 0 : values.graphics_exposures = False;
102 0 : values.foreground = m_pColormap->GetBlackPixel()
103 0 : ^ m_pColormap->GetWhitePixel();
104 0 : values.function = GXxor;
105 0 : values.line_width = 1;
106 0 : values.fill_style = FillStippled;
107 0 : values.stipple = GetDisplay()->GetInvert50( m_nXScreen );
108 0 : values.subwindow_mode = ClipByChildren;
109 :
110 0 : return XCreateGC( GetXDisplay(), hDrawable, nMask | GCSubwindowMode, &values );
111 : }
112 :
113 : inline GC X11SalGraphics::GetMonoGC( Pixmap hPixmap )
114 : {
115 : if( !pMonoGC_ )
116 : pMonoGC_ = CreateGC( hPixmap );
117 :
118 : if( !bMonoGC_ )
119 : {
120 : SetClipRegion( pMonoGC_ );
121 : bMonoGC_ = sal_True;
122 : }
123 :
124 : return pMonoGC_;
125 : }
126 :
127 0 : inline GC X11SalGraphics::GetCopyGC()
128 : {
129 0 : if( bXORMode_ ) return GetInvertGC();
130 :
131 0 : if( !pCopyGC_ )
132 0 : pCopyGC_ = CreateGC( GetDrawable() );
133 :
134 0 : if( !bCopyGC_ )
135 : {
136 0 : SetClipRegion( pCopyGC_ );
137 0 : bCopyGC_ = sal_True;
138 : }
139 0 : return pCopyGC_;
140 : }
141 :
142 0 : GC X11SalGraphics::GetInvertGC()
143 : {
144 0 : if( !pInvertGC_ )
145 : pInvertGC_ = CreateGC( GetDrawable(),
146 : GCGraphicsExposures
147 : | GCForeground
148 : | GCFunction
149 0 : | GCLineWidth );
150 :
151 0 : if( !bInvertGC_ )
152 : {
153 0 : SetClipRegion( pInvertGC_ );
154 0 : bInvertGC_ = sal_True;
155 : }
156 0 : return pInvertGC_;
157 : }
158 :
159 0 : GC X11SalGraphics::GetInvert50GC()
160 : {
161 0 : if( !pInvert50GC_ )
162 : {
163 : XGCValues values;
164 :
165 0 : values.graphics_exposures = False;
166 0 : values.foreground = m_pColormap->GetWhitePixel();
167 0 : values.background = m_pColormap->GetBlackPixel();
168 0 : values.function = GXinvert;
169 0 : values.line_width = 1;
170 0 : values.line_style = LineSolid;
171 : unsigned long nValueMask =
172 : GCGraphicsExposures
173 : | GCForeground
174 : | GCBackground
175 : | GCFunction
176 : | GCLineWidth
177 : | GCLineStyle
178 : | GCFillStyle
179 0 : | GCStipple;
180 :
181 0 : char* pEnv = getenv( "SAL_DO_NOT_USE_INVERT50" );
182 0 : if( pEnv && ! strcasecmp( pEnv, "true" ) )
183 : {
184 0 : values.fill_style = FillSolid;
185 0 : nValueMask &= ~ GCStipple;
186 : }
187 : else
188 : {
189 0 : values.fill_style = FillStippled;
190 0 : values.stipple = GetDisplay()->GetInvert50( m_nXScreen );
191 : }
192 :
193 : pInvert50GC_ = XCreateGC( GetXDisplay(), GetDrawable(),
194 : nValueMask,
195 0 : &values );
196 : }
197 :
198 0 : if( !bInvert50GC_ )
199 : {
200 0 : SetClipRegion( pInvert50GC_ );
201 0 : bInvert50GC_ = sal_True;
202 : }
203 0 : return pInvert50GC_;
204 : }
205 :
206 0 : inline GC X11SalGraphics::GetStippleGC()
207 : {
208 0 : if( !pStippleGC_ )
209 : pStippleGC_ = CreateGC( GetDrawable(),
210 : GCGraphicsExposures
211 : | GCFillStyle
212 0 : | GCLineWidth );
213 :
214 0 : if( !bStippleGC_ )
215 : {
216 0 : XSetFunction( GetXDisplay(), pStippleGC_, bXORMode_ ? GXxor : GXcopy );
217 0 : SetClipRegion( pStippleGC_ );
218 0 : bStippleGC_ = sal_True;
219 : }
220 :
221 0 : return pStippleGC_;
222 : }
223 :
224 : extern "C"
225 : {
226 0 : static Bool GraphicsExposePredicate( Display*, XEvent* pEvent, XPointer pFrameWindow )
227 : {
228 0 : Bool bRet = False;
229 0 : if( (pEvent->type == GraphicsExpose || pEvent->type == NoExpose) &&
230 0 : pEvent->xnoexpose.drawable == (Drawable)pFrameWindow )
231 : {
232 0 : bRet = True;
233 : }
234 0 : return bRet;
235 : }
236 : }
237 :
238 :
239 0 : void X11SalGraphics::YieldGraphicsExpose()
240 : {
241 : // get frame if necessary
242 0 : SalFrame* pFrame = m_pFrame;
243 0 : Display* pDisplay = GetXDisplay();
244 0 : XLIB_Window aWindow = GetDrawable();
245 0 : if( ! pFrame )
246 : {
247 0 : const std::list< SalFrame* >& rFrames = GetGenericData()->GetSalDisplay()->getFrames();
248 0 : for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end() && ! pFrame; ++it )
249 : {
250 0 : const SystemEnvData* pEnvData = (*it)->GetSystemData();
251 0 : if( Drawable(pEnvData->aWindow) == aWindow )
252 0 : pFrame = *it;
253 : }
254 0 : if( ! pFrame )
255 0 : return;
256 : }
257 :
258 : XEvent aEvent;
259 0 : while( XCheckTypedWindowEvent( pDisplay, aWindow, Expose, &aEvent ) )
260 : {
261 0 : SalPaintEvent aPEvt( aEvent.xexpose.x, aEvent.xexpose.y, aEvent.xexpose.width+1, aEvent.xexpose.height+1 );
262 0 : pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
263 : }
264 :
265 0 : do
266 : {
267 0 : if( ! GetDisplay()->XIfEventWithTimeout( &aEvent, (XPointer)aWindow, GraphicsExposePredicate ) )
268 : // this should not happen at all; still sometimes it happens
269 0 : break;
270 :
271 0 : if( aEvent.type == NoExpose )
272 0 : break;
273 :
274 0 : if( pFrame )
275 : {
276 0 : SalPaintEvent aPEvt( aEvent.xgraphicsexpose.x, aEvent.xgraphicsexpose.y, aEvent.xgraphicsexpose.width+1, aEvent.xgraphicsexpose.height+1 );
277 0 : pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
278 : }
279 0 : } while( aEvent.xgraphicsexpose.count != 0 );
280 : }
281 :
282 0 : void X11SalGraphics::copyBits( const SalTwoRect& rPosAry,
283 : SalGraphics *pSSrcGraphics )
284 : {
285 : X11SalGraphics* pSrcGraphics = pSSrcGraphics
286 : ? static_cast<X11SalGraphics*>(pSSrcGraphics)
287 0 : : this;
288 :
289 0 : if( rPosAry.mnSrcWidth <= 0
290 0 : || rPosAry.mnSrcHeight <= 0
291 0 : || rPosAry.mnDestWidth <= 0
292 0 : || rPosAry.mnDestHeight <= 0 )
293 : {
294 0 : return;
295 : }
296 :
297 : int n;
298 0 : if( pSrcGraphics == this )
299 : {
300 0 : n = 2;
301 : }
302 0 : else if( pSrcGraphics->bWindow_ )
303 : {
304 : // window or compatible virtual device
305 0 : if( pSrcGraphics->GetDisplay() == GetDisplay() &&
306 0 : pSrcGraphics->m_nXScreen == m_nXScreen &&
307 0 : pSrcGraphics->GetVisual().GetDepth() == GetVisual().GetDepth()
308 : )
309 0 : n = 2; // same Display
310 : else
311 0 : n = 1; // printer or other display
312 : }
313 0 : else if( pSrcGraphics->bVirDev_ )
314 : {
315 : // printer compatible virtual device
316 0 : if( bPrinter_ )
317 0 : n = 2; // printer or compatible virtual device == same display
318 : else
319 0 : n = 1; // window or compatible virtual device
320 : }
321 : else
322 0 : n = 0;
323 :
324 0 : if( n == 2
325 0 : && rPosAry.mnSrcWidth == rPosAry.mnDestWidth
326 0 : && rPosAry.mnSrcHeight == rPosAry.mnDestHeight
327 : )
328 : {
329 : // #i60699# Need to generate graphics exposures (to repaint
330 : // obscured areas beneath overlapping windows), src and dest
331 : // are the same window.
332 0 : const bool bNeedGraphicsExposures( pSrcGraphics == this &&
333 0 : !bVirDev_ &&
334 0 : pSrcGraphics->bWindow_ );
335 :
336 : GC pCopyGC;
337 :
338 0 : if( bXORMode_
339 0 : && !pSrcGraphics->bVirDev_
340 0 : && (GetDisplay()->GetProperties() & PROPERTY_BUG_XCopyArea_GXxor) )
341 : {
342 : Pixmap hPixmap = limitXCreatePixmap( GetXDisplay(),
343 : pSrcGraphics->GetDrawable(), // source
344 : rPosAry.mnSrcWidth, rPosAry.mnSrcHeight,
345 0 : pSrcGraphics->GetBitCount() );
346 :
347 0 : pCopyGC = GetDisplay()->GetCopyGC( m_nXScreen );
348 :
349 0 : if( bNeedGraphicsExposures )
350 : XSetGraphicsExposures( GetXDisplay(),
351 : pCopyGC,
352 0 : True );
353 :
354 : XCopyArea( GetXDisplay(),
355 : pSrcGraphics->GetDrawable(), // source
356 : hPixmap, // destination
357 : pCopyGC, // no clipping
358 : rPosAry.mnSrcX, rPosAry.mnSrcY,
359 : rPosAry.mnSrcWidth, rPosAry.mnSrcHeight,
360 0 : 0, 0 ); // destination
361 : XCopyArea( GetXDisplay(),
362 : hPixmap, // source
363 : GetDrawable(), // destination
364 : GetInvertGC(), // destination clipping
365 : 0, 0, // source
366 : rPosAry.mnSrcWidth, rPosAry.mnSrcHeight,
367 0 : rPosAry.mnDestX, rPosAry.mnDestY );
368 0 : XFreePixmap( GetXDisplay(), hPixmap );
369 : }
370 : else
371 : {
372 0 : pCopyGC = GetCopyGC();
373 :
374 0 : if( bNeedGraphicsExposures )
375 : XSetGraphicsExposures( GetXDisplay(),
376 : pCopyGC,
377 0 : True );
378 :
379 : XCopyArea( GetXDisplay(),
380 : pSrcGraphics->GetDrawable(), // source
381 : GetDrawable(), // destination
382 : pCopyGC, // destination clipping
383 : rPosAry.mnSrcX, rPosAry.mnSrcY,
384 : rPosAry.mnSrcWidth, rPosAry.mnSrcHeight,
385 0 : rPosAry.mnDestX, rPosAry.mnDestY );
386 : }
387 :
388 0 : if( bNeedGraphicsExposures )
389 : {
390 0 : YieldGraphicsExpose();
391 :
392 0 : if( pCopyGC )
393 : XSetGraphicsExposures( GetXDisplay(),
394 : pCopyGC,
395 0 : False );
396 0 : }
397 : }
398 0 : else if( n )
399 : {
400 : // #i60699# No chance to handle graphics exposures - we copy
401 : // to a temp bitmap first, into which no repaints are
402 : // technically possible.
403 : SalBitmap *pDDB = pSrcGraphics->getBitmap( rPosAry.mnSrcX,
404 : rPosAry.mnSrcY,
405 : rPosAry.mnSrcWidth,
406 0 : rPosAry.mnSrcHeight );
407 :
408 0 : if( !pDDB )
409 : {
410 : stderr0( "SalGraphics::CopyBits !pSrcGraphics->GetBitmap()\n" );
411 0 : return;
412 : }
413 :
414 0 : SalTwoRect aPosAry( rPosAry );
415 :
416 0 : aPosAry.mnSrcX = 0, aPosAry.mnSrcY = 0;
417 0 : drawBitmap( aPosAry, *pDDB );
418 :
419 0 : delete pDDB;
420 : }
421 : else {
422 : stderr0( "X11SalGraphics::CopyBits from Printer not yet implemented\n" );
423 : }
424 : }
425 :
426 : // --------------------------------------------------------------------------
427 :
428 0 : void X11SalGraphics::copyArea ( long nDestX, long nDestY,
429 : long nSrcX, long nSrcY,
430 : long nSrcWidth, long nSrcHeight,
431 : sal_uInt16 )
432 : {
433 : SalTwoRect aPosAry;
434 :
435 0 : aPosAry.mnDestX = nDestX;
436 0 : aPosAry.mnDestY = nDestY;
437 0 : aPosAry.mnDestWidth = nSrcWidth;
438 0 : aPosAry.mnDestHeight = nSrcHeight;
439 :
440 0 : aPosAry.mnSrcX = nSrcX;
441 0 : aPosAry.mnSrcY = nSrcY;
442 0 : aPosAry.mnSrcWidth = nSrcWidth;
443 0 : aPosAry.mnSrcHeight = nSrcHeight;
444 :
445 0 : copyBits ( aPosAry, 0 );
446 0 : }
447 :
448 0 : void X11SalGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap )
449 : {
450 0 : const SalDisplay* pSalDisp = GetDisplay();
451 0 : Display* pXDisp = pSalDisp->GetDisplay();
452 0 : const Drawable aDrawable( GetDrawable() );
453 0 : const SalColormap& rColMap = pSalDisp->GetColormap( m_nXScreen );
454 0 : const long nDepth = GetDisplay()->GetVisual( m_nXScreen ).GetDepth();
455 0 : GC aGC( GetCopyGC() );
456 : XGCValues aOldVal, aNewVal;
457 0 : int nValues = GCForeground | GCBackground;
458 :
459 0 : if( rSalBitmap.GetBitCount() == 1 )
460 : {
461 : // set foreground/background values for 1Bit bitmaps
462 0 : XGetGCValues( pXDisp, aGC, nValues, &aOldVal );
463 :
464 0 : aNewVal.foreground = rColMap.GetWhitePixel();
465 0 : aNewVal.background = rColMap.GetBlackPixel();
466 :
467 : //fdo#33455 handle 1 bit depth pngs with palette entries
468 : //to set fore/back colors
469 0 : if (const BitmapBuffer* pBitmapBuffer = const_cast<SalBitmap&>(rSalBitmap).AcquireBuffer(true))
470 : {
471 0 : const BitmapPalette& rPalette = pBitmapBuffer->maPalette;
472 0 : if (rPalette.GetEntryCount() == 2)
473 : {
474 0 : const BitmapColor aBlack( rPalette[rPalette.GetBestIndex( Color( COL_BLACK ) )] );
475 0 : const BitmapColor aWhite( rPalette[rPalette.GetBestIndex( Color( COL_WHITE ) )] );
476 0 : aNewVal.foreground = rColMap.GetPixel(ImplColorToSal(aWhite));
477 0 : aNewVal.background = rColMap.GetPixel(ImplColorToSal(aBlack));
478 : }
479 : }
480 :
481 0 : XChangeGC( pXDisp, aGC, nValues, &aNewVal );
482 : }
483 :
484 0 : static_cast<const X11SalBitmap&>(rSalBitmap).ImplDraw( aDrawable, m_nXScreen, nDepth, rPosAry, aGC );
485 :
486 0 : if( rSalBitmap.GetBitCount() == 1 )
487 0 : XChangeGC( pXDisp, aGC, nValues, &aOldVal );
488 0 : XFlush( pXDisp );
489 0 : }
490 :
491 0 : void X11SalGraphics::drawBitmap( const SalTwoRect& rPosAry,
492 : const SalBitmap& rSrcBitmap,
493 : const SalBitmap& rMaskBitmap )
494 : {
495 : DBG_ASSERT( !bPrinter_, "Drawing of transparent bitmaps on printer devices is strictly forbidden" );
496 :
497 : // decide if alpha masking or transparency masking is needed
498 0 : BitmapBuffer* pAlphaBuffer = const_cast<SalBitmap&>(rMaskBitmap).AcquireBuffer( sal_True );
499 0 : if( pAlphaBuffer != NULL )
500 : {
501 0 : int nMaskFormat = pAlphaBuffer->mnFormat;
502 0 : const_cast<SalBitmap&>(rMaskBitmap).ReleaseBuffer( pAlphaBuffer, sal_True );
503 0 : if( nMaskFormat == BMP_FORMAT_8BIT_PAL )
504 0 : drawAlphaBitmap( rPosAry, rSrcBitmap, rMaskBitmap );
505 : }
506 :
507 0 : drawMaskedBitmap( rPosAry, rSrcBitmap, rMaskBitmap );
508 0 : }
509 :
510 0 : void X11SalGraphics::drawMaskedBitmap( const SalTwoRect& rPosAry,
511 : const SalBitmap& rSalBitmap,
512 : const SalBitmap& rTransBitmap )
513 : {
514 0 : const SalDisplay* pSalDisp = GetDisplay();
515 0 : Display* pXDisp = pSalDisp->GetDisplay();
516 0 : Drawable aDrawable( GetDrawable() );
517 :
518 : // figure work mode depth. If this is a VDev Drawable, use its
519 : // bitdepth to create pixmaps for, otherwise, XCopyArea will
520 : // refuse to work.
521 : const sal_uInt16 nDepth( m_pVDev ?
522 0 : m_pVDev->GetDepth() :
523 0 : pSalDisp->GetVisual( m_nXScreen ).GetDepth() );
524 : Pixmap aFG( limitXCreatePixmap( pXDisp, aDrawable, rPosAry.mnDestWidth,
525 0 : rPosAry.mnDestHeight, nDepth ) );
526 : Pixmap aBG( limitXCreatePixmap( pXDisp, aDrawable, rPosAry.mnDestWidth,
527 0 : rPosAry.mnDestHeight, nDepth ) );
528 :
529 0 : if( aFG && aBG )
530 : {
531 : GC aTmpGC;
532 : XGCValues aValues;
533 0 : const SalColormap& rColMap = pSalDisp->GetColormap( m_nXScreen );
534 0 : const int nBlack = rColMap.GetBlackPixel(), nWhite = rColMap.GetWhitePixel();
535 0 : const int nValues = GCFunction | GCForeground | GCBackground;
536 0 : SalTwoRect aTmpRect( rPosAry ); aTmpRect.mnDestX = aTmpRect.mnDestY = 0;
537 :
538 : // draw paint bitmap in pixmap #1
539 0 : aValues.function = GXcopy, aValues.foreground = nWhite, aValues.background = nBlack;
540 0 : aTmpGC = XCreateGC( pXDisp, aFG, nValues, &aValues );
541 0 : static_cast<const X11SalBitmap&>(rSalBitmap).ImplDraw( aFG, m_nXScreen, nDepth, aTmpRect, aTmpGC );
542 : DBG_TESTTRANS( aFG );
543 :
544 : // draw background in pixmap #2
545 : XCopyArea( pXDisp, aDrawable, aBG, aTmpGC,
546 : rPosAry.mnDestX, rPosAry.mnDestY,
547 : rPosAry.mnDestWidth, rPosAry.mnDestHeight,
548 0 : 0, 0 );
549 :
550 : DBG_TESTTRANS( aBG );
551 :
552 : // mask out paint bitmap in pixmap #1 (transparent areas 0)
553 0 : aValues.function = GXand, aValues.foreground = 0x00000000, aValues.background = 0xffffffff;
554 0 : XChangeGC( pXDisp, aTmpGC, nValues, &aValues );
555 0 : static_cast<const X11SalBitmap&>(rTransBitmap).ImplDraw( aFG, m_nXScreen, 1, aTmpRect, aTmpGC );
556 :
557 : DBG_TESTTRANS( aFG );
558 :
559 : // #105055# For XOR mode, keep background behind bitmap intact
560 0 : if( !bXORMode_ )
561 : {
562 : // mask out background in pixmap #2 (nontransparent areas 0)
563 0 : aValues.function = GXand, aValues.foreground = 0xffffffff, aValues.background = 0x00000000;
564 0 : XChangeGC( pXDisp, aTmpGC, nValues, &aValues );
565 0 : static_cast<const X11SalBitmap&>(rTransBitmap).ImplDraw( aBG, m_nXScreen, 1, aTmpRect, aTmpGC );
566 :
567 : DBG_TESTTRANS( aBG );
568 : }
569 :
570 : // merge pixmap #1 and pixmap #2 in pixmap #2
571 0 : aValues.function = GXxor, aValues.foreground = 0xffffffff, aValues.background = 0x00000000;
572 0 : XChangeGC( pXDisp, aTmpGC, nValues, &aValues );
573 : XCopyArea( pXDisp, aFG, aBG, aTmpGC,
574 : 0, 0,
575 : rPosAry.mnDestWidth, rPosAry.mnDestHeight,
576 0 : 0, 0 );
577 : DBG_TESTTRANS( aBG );
578 :
579 : // #105055# Disable XOR temporarily
580 0 : sal_Bool bOldXORMode( bXORMode_ );
581 0 : bXORMode_ = sal_False;
582 :
583 : // copy pixmap #2 (result) to background
584 : XCopyArea( pXDisp, aBG, aDrawable, GetCopyGC(),
585 : 0, 0,
586 : rPosAry.mnDestWidth, rPosAry.mnDestHeight,
587 0 : rPosAry.mnDestX, rPosAry.mnDestY );
588 :
589 : DBG_TESTTRANS( aBG );
590 :
591 0 : bXORMode_ = bOldXORMode;
592 :
593 0 : XFreeGC( pXDisp, aTmpGC );
594 0 : XFlush( pXDisp );
595 : }
596 : else
597 0 : drawBitmap( rPosAry, rSalBitmap );
598 :
599 0 : if( aFG )
600 0 : XFreePixmap( pXDisp, aFG );
601 :
602 0 : if( aBG )
603 0 : XFreePixmap( pXDisp, aBG );
604 0 : }
605 :
606 0 : bool X11SalGraphics::drawAlphaBitmap( const SalTwoRect& rTR,
607 : const SalBitmap& rSrcBitmap, const SalBitmap& rAlphaBmp )
608 : {
609 : // non 8-bit alpha not implemented yet
610 0 : if( rAlphaBmp.GetBitCount() != 8 )
611 0 : return false;
612 :
613 : // horizontal mirroring not implemented yet
614 0 : if( rTR.mnDestWidth < 0 )
615 0 : return false;
616 :
617 : // stretched conversion is not implemented yet
618 0 : if( rTR.mnDestWidth != rTR.mnSrcWidth )
619 0 : return false;
620 0 : if( rTR.mnDestHeight!= rTR.mnSrcHeight )
621 0 : return false;
622 :
623 : // create destination picture
624 0 : Picture aDstPic = GetXRenderPicture();
625 0 : if( !aDstPic )
626 0 : return false;
627 :
628 0 : const SalDisplay* pSalDisp = GetDisplay();
629 0 : const SalVisual& rSalVis = pSalDisp->GetVisual( m_nXScreen );
630 0 : Display* pXDisplay = pSalDisp->GetDisplay();
631 :
632 : // create source Picture
633 0 : int nDepth = m_pVDev ? m_pVDev->GetDepth() : rSalVis.GetDepth();
634 0 : const X11SalBitmap& rSrcX11Bmp = static_cast<const X11SalBitmap&>( rSrcBitmap );
635 0 : ImplSalDDB* pSrcDDB = rSrcX11Bmp.ImplGetDDB( hDrawable_, m_nXScreen, nDepth, rTR );
636 0 : if( !pSrcDDB )
637 0 : return false;
638 :
639 : //#i75249# workaround for ImplGetDDB() giving us back a different depth than
640 : // we requested. E.g. mask pixmaps are always compatible with the drawable
641 : // TODO: find an appropriate picture format for these cases
642 : // then remove the workaround below and the one for #i75531#
643 0 : if( nDepth != pSrcDDB->ImplGetDepth() )
644 0 : return false;
645 :
646 0 : Pixmap aSrcPM = pSrcDDB->ImplGetPixmap();
647 0 : if( !aSrcPM )
648 0 : return false;
649 :
650 : // create source picture
651 : // TODO: use scoped picture
652 0 : Visual* pSrcXVisual = rSalVis.GetVisual();
653 0 : XRenderPeer& rPeer = XRenderPeer::GetInstance();
654 0 : XRenderPictFormat* pSrcVisFmt = rPeer.FindVisualFormat( pSrcXVisual );
655 0 : if( !pSrcVisFmt )
656 0 : return false;
657 0 : Picture aSrcPic = rPeer.CreatePicture( aSrcPM, pSrcVisFmt, 0, NULL );
658 0 : if( !aSrcPic )
659 0 : return false;
660 :
661 : // create alpha Picture
662 :
663 : // TODO: use SalX11Bitmap functionality and caching for the Alpha Pixmap
664 : // problem is that they don't provide an 8bit Pixmap on a non-8bit display
665 0 : BitmapBuffer* pAlphaBuffer = const_cast<SalBitmap&>(rAlphaBmp).AcquireBuffer( sal_True );
666 :
667 : // an XImage needs its data top_down
668 : // TODO: avoid wrongly oriented images in upper layers!
669 0 : const int nImageSize = pAlphaBuffer->mnHeight * pAlphaBuffer->mnScanlineSize;
670 0 : const char* pSrcBits = (char*)pAlphaBuffer->mpBits;
671 0 : char* pAlphaBits = new char[ nImageSize ];
672 0 : if( BMP_SCANLINE_ADJUSTMENT( pAlphaBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
673 0 : memcpy( pAlphaBits, pSrcBits, nImageSize );
674 : else
675 : {
676 0 : char* pDstBits = pAlphaBits + nImageSize;
677 0 : const int nLineSize = pAlphaBuffer->mnScanlineSize;
678 0 : for(; (pDstBits -= nLineSize) >= pAlphaBits; pSrcBits += nLineSize )
679 0 : memcpy( pDstBits, pSrcBits, nLineSize );
680 : }
681 :
682 : // the alpha values need to be inverted for XRender
683 : // TODO: make upper layers use standard alpha
684 0 : long* pLDst = (long*)pAlphaBits;
685 0 : for( int i = nImageSize/sizeof(long); --i >= 0; ++pLDst )
686 0 : *pLDst = ~*pLDst;
687 :
688 0 : char* pCDst = (char*)pLDst;
689 0 : for( int i = nImageSize & (sizeof(long)-1); --i >= 0; ++pCDst )
690 0 : *pCDst = ~*pCDst;
691 :
692 0 : const XRenderPictFormat* pAlphaFormat = rPeer.GetStandardFormatA8();
693 : XImage* pAlphaImg = XCreateImage( pXDisplay, pSrcXVisual, 8, ZPixmap, 0,
694 : pAlphaBits, pAlphaBuffer->mnWidth, pAlphaBuffer->mnHeight,
695 0 : pAlphaFormat->depth, pAlphaBuffer->mnScanlineSize );
696 :
697 : Pixmap aAlphaPM = limitXCreatePixmap( pXDisplay, hDrawable_,
698 0 : rTR.mnDestWidth, rTR.mnDestHeight, 8 );
699 :
700 : XGCValues aAlphaGCV;
701 0 : aAlphaGCV.function = GXcopy;
702 0 : GC aAlphaGC = XCreateGC( pXDisplay, aAlphaPM, GCFunction, &aAlphaGCV );
703 : XPutImage( pXDisplay, aAlphaPM, aAlphaGC, pAlphaImg,
704 0 : rTR.mnSrcX, rTR.mnSrcY, 0, 0, rTR.mnDestWidth, rTR.mnDestHeight );
705 0 : XFreeGC( pXDisplay, aAlphaGC );
706 0 : XFree( pAlphaImg );
707 0 : if( pAlphaBits != (char*)pAlphaBuffer->mpBits )
708 0 : delete[] pAlphaBits;
709 :
710 0 : const_cast<SalBitmap&>(rAlphaBmp).ReleaseBuffer( pAlphaBuffer, sal_True );
711 :
712 : XRenderPictureAttributes aAttr;
713 0 : aAttr.repeat = true;
714 0 : Picture aAlphaPic = rPeer.CreatePicture( aAlphaPM, pAlphaFormat, CPRepeat, &aAttr );
715 0 : if( !aAlphaPic )
716 0 : return false;
717 :
718 : // set clipping
719 0 : if( mpClipRegion && !XEmptyRegion( mpClipRegion ) )
720 0 : rPeer.SetPictureClipRegion( aDstPic, mpClipRegion );
721 :
722 : // paint source * mask over destination picture
723 : rPeer.CompositePicture( PictOpOver, aSrcPic, aAlphaPic, aDstPic,
724 : rTR.mnSrcX, rTR.mnSrcY, 0, 0,
725 0 : rTR.mnDestX, rTR.mnDestY, rTR.mnDestWidth, rTR.mnDestHeight );
726 :
727 0 : rPeer.FreePicture( aAlphaPic );
728 0 : XFreePixmap(pXDisplay, aAlphaPM);
729 0 : rPeer.FreePicture( aSrcPic );
730 0 : return true;
731 : }
732 :
733 0 : bool X11SalGraphics::drawTransformedBitmap(
734 : const basegfx::B2DPoint& rNull,
735 : const basegfx::B2DPoint& rX,
736 : const basegfx::B2DPoint& rY,
737 : const SalBitmap& rSourceBitmap,
738 : const SalBitmap* pAlphaBitmap)
739 : {
740 : // here direct support for transformed bitmaps can be impemented
741 : (void)rNull; (void)rX; (void)rY; (void)rSourceBitmap; (void)pAlphaBitmap;
742 0 : return false;
743 : }
744 :
745 0 : bool X11SalGraphics::drawAlphaRect( long nX, long nY, long nWidth,
746 : long nHeight, sal_uInt8 nTransparency )
747 : {
748 0 : if( ! m_pFrame && ! m_pVDev )
749 0 : return false;
750 :
751 0 : if( bPenGC_ || !bBrushGC_ || bXORMode_ )
752 0 : return false; // can only perform solid fills without XOR.
753 :
754 0 : if( m_pVDev && m_pVDev->GetDepth() < 8 )
755 0 : return false;
756 :
757 0 : Picture aDstPic = GetXRenderPicture();
758 0 : if( !aDstPic )
759 0 : return false;
760 :
761 0 : const double fTransparency = (100 - nTransparency) * (1.0/100);
762 0 : const XRenderColor aRenderColor = GetXRenderColor( nBrushColor_ , fTransparency);
763 :
764 0 : XRenderPeer& rPeer = XRenderPeer::GetInstance();
765 : rPeer.FillRectangle( PictOpOver,
766 : aDstPic,
767 : &aRenderColor,
768 : nX, nY,
769 0 : nWidth, nHeight );
770 :
771 0 : return true;
772 : }
773 :
774 0 : void X11SalGraphics::drawBitmap( const SalTwoRect&,
775 : const SalBitmap&,
776 : SalColor )
777 : {
778 : OSL_FAIL( "::DrawBitmap with transparent color not supported" );
779 0 : }
780 :
781 0 : void X11SalGraphics::drawMask( const SalTwoRect& rPosAry,
782 : const SalBitmap &rSalBitmap,
783 : SalColor nMaskColor )
784 : {
785 0 : const SalDisplay* pSalDisp = GetDisplay();
786 0 : Display* pXDisp = pSalDisp->GetDisplay();
787 0 : Drawable aDrawable( GetDrawable() );
788 : Pixmap aStipple( limitXCreatePixmap( pXDisp, aDrawable,
789 : rPosAry.mnDestWidth,
790 0 : rPosAry.mnDestHeight, 1 ) );
791 :
792 0 : if( aStipple )
793 : {
794 0 : SalTwoRect aTwoRect( rPosAry ); aTwoRect.mnDestX = aTwoRect.mnDestY = 0;
795 : GC aTmpGC;
796 : XGCValues aValues;
797 :
798 : // create a stipple bitmap first (set bits are changed to unset bits and vice versa)
799 0 : aValues.function = GXcopyInverted;
800 0 : aValues.foreground = 1, aValues.background = 0;
801 0 : aTmpGC = XCreateGC( pXDisp, aStipple, GCFunction | GCForeground | GCBackground, &aValues );
802 0 : static_cast<const X11SalBitmap&>(rSalBitmap).ImplDraw( aStipple, m_nXScreen, 1, aTwoRect, aTmpGC );
803 :
804 0 : XFreeGC( pXDisp, aTmpGC );
805 :
806 : // Set stipple and draw rectangle
807 0 : GC aStippleGC( GetStippleGC() );
808 0 : int nX = rPosAry.mnDestX, nY = rPosAry.mnDestY;
809 :
810 0 : XSetStipple( pXDisp, aStippleGC, aStipple );
811 0 : XSetTSOrigin( pXDisp, aStippleGC, nX, nY );
812 0 : XSetForeground( pXDisp, aStippleGC, GetPixel( nMaskColor ) );
813 : XFillRectangle( pXDisp, aDrawable, aStippleGC,
814 : nX, nY,
815 0 : rPosAry.mnDestWidth, rPosAry.mnDestHeight );
816 0 : XFreePixmap( pXDisp, aStipple );
817 0 : XFlush( pXDisp );
818 : }
819 : else
820 0 : drawBitmap( rPosAry, rSalBitmap );
821 0 : }
822 :
823 0 : SalBitmap *X11SalGraphics::getBitmap( long nX, long nY, long nDX, long nDY )
824 : {
825 0 : if( bPrinter_ && !bVirDev_ )
826 0 : return NULL;
827 :
828 0 : bool bFakeWindowBG = false;
829 :
830 : // normalize
831 0 : if( nDX < 0 )
832 : {
833 0 : nX += nDX;
834 0 : nDX = -nDX;
835 : }
836 0 : if ( nDY < 0 )
837 : {
838 0 : nY += nDY;
839 0 : nDY = -nDY;
840 : }
841 :
842 0 : if( bWindow_ && !bVirDev_ )
843 : {
844 : XWindowAttributes aAttrib;
845 :
846 0 : XGetWindowAttributes( GetXDisplay(), GetDrawable(), &aAttrib );
847 0 : if( aAttrib.map_state != IsViewable )
848 0 : bFakeWindowBG = true;
849 : else
850 : {
851 0 : long nOrgDX = nDX, nOrgDY = nDY;
852 :
853 : // clip to window size
854 0 : if ( nX < 0 )
855 : {
856 0 : nDX += nX;
857 0 : nX = 0;
858 : }
859 0 : if ( nY < 0 )
860 : {
861 0 : nDY += nY;
862 0 : nY = 0;
863 : }
864 0 : if( nX + nDX > aAttrib.width )
865 0 : nDX = aAttrib.width - nX;
866 0 : if( nY + nDY > aAttrib.height )
867 0 : nDY = aAttrib.height - nY;
868 :
869 : // inside ?
870 0 : if( nDX <= 0 || nDY <= 0 )
871 : {
872 0 : bFakeWindowBG = true;
873 0 : nDX = nOrgDX;
874 0 : nDY = nOrgDY;
875 : }
876 : }
877 : }
878 :
879 0 : X11SalBitmap* pSalBitmap = new X11SalBitmap;
880 0 : sal_uInt16 nBitCount = GetBitCount();
881 :
882 0 : if( &GetDisplay()->GetColormap( m_nXScreen ) != &GetColormap() )
883 0 : nBitCount = 1;
884 :
885 0 : if( ! bFakeWindowBG )
886 0 : pSalBitmap->ImplCreateFromDrawable( GetDrawable(), m_nXScreen, nBitCount, nX, nY, nDX, nDY );
887 : else
888 0 : pSalBitmap->Create( Size( nDX, nDY ), (nBitCount > 8) ? 24 : nBitCount, BitmapPalette( nBitCount > 8 ? nBitCount : 0 ) );
889 :
890 0 : return pSalBitmap;
891 : }
892 :
893 0 : SalColor X11SalGraphics::getPixel( long nX, long nY )
894 : {
895 0 : if( bWindow_ && !bVirDev_ )
896 : {
897 : XWindowAttributes aAttrib;
898 :
899 0 : XGetWindowAttributes( GetXDisplay(), GetDrawable(), &aAttrib );
900 0 : if( aAttrib.map_state != IsViewable )
901 : {
902 : stderr0( "X11SalGraphics::GetPixel drawable not viewable\n" );
903 0 : return 0;
904 : }
905 : }
906 :
907 : XImage *pXImage = XGetImage( GetXDisplay(),
908 : GetDrawable(),
909 : nX, nY,
910 : 1, 1,
911 : AllPlanes,
912 0 : ZPixmap );
913 0 : if( !pXImage )
914 : {
915 : stderr0( "X11SalGraphics::GetPixel !XGetImage()\n" );
916 0 : return 0;
917 : }
918 :
919 : XColor aXColor;
920 :
921 0 : aXColor.pixel = XGetPixel( pXImage, 0, 0 );
922 0 : XDestroyImage( pXImage );
923 :
924 0 : return GetColormap().GetColor( aXColor.pixel );
925 : }
926 :
927 0 : void X11SalGraphics::invert( long nX,
928 : long nY,
929 : long nDX,
930 : long nDY,
931 : SalInvert nFlags )
932 : {
933 : GC pGC;
934 0 : if( SAL_INVERT_50 & nFlags )
935 : {
936 0 : pGC = GetInvert50GC();
937 0 : XFillRectangle( GetXDisplay(), GetDrawable(), pGC, nX, nY, nDX, nDY );
938 : }
939 : else
940 : {
941 0 : if ( SAL_INVERT_TRACKFRAME & nFlags )
942 : {
943 0 : pGC = GetTrackingGC();
944 0 : XDrawRectangle( GetXDisplay(), GetDrawable(), pGC, nX, nY, nDX, nDY );
945 : }
946 : else
947 : {
948 0 : pGC = GetInvertGC();
949 0 : XFillRectangle( GetXDisplay(), GetDrawable(), pGC, nX, nY, nDX, nDY );
950 : }
951 : }
952 0 : }
953 :
954 0 : bool X11SalGraphics::supportsOperation( OutDevSupportType eType ) const
955 : {
956 0 : bool bRet = false;
957 0 : switch( eType )
958 : {
959 : case OutDevSupport_TransparentRect:
960 : case OutDevSupport_B2DDraw:
961 : {
962 0 : XRenderPeer& rPeer = XRenderPeer::GetInstance();
963 0 : const SalDisplay* pSalDisp = GetDisplay();
964 0 : const SalVisual& rSalVis = pSalDisp->GetVisual( m_nXScreen );
965 :
966 0 : Visual* pDstXVisual = rSalVis.GetVisual();
967 0 : XRenderPictFormat* pDstVisFmt = rPeer.FindVisualFormat( pDstXVisual );
968 0 : if( pDstVisFmt )
969 0 : bRet = true;
970 : }
971 0 : break;
972 0 : default: break;
973 : }
974 0 : return bRet;
975 0 : }
976 :
977 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|