1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*c82f2877SAndrew Rist * distributed with this work for additional information
6*c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist * KIND, either express or implied. See the License for the
17*c82f2877SAndrew Rist * specific language governing permissions and limitations
18*c82f2877SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*c82f2877SAndrew Rist *************************************************************/
21*c82f2877SAndrew Rist
22*c82f2877SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vcl/sysdata.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <tools/prex.h>
30cdf0e10cSrcweir #include <X11/extensions/Xrender.h>
31cdf0e10cSrcweir #include <tools/postx.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <unx/salunx.h>
34cdf0e10cSrcweir #include <unx/saldata.hxx>
35cdf0e10cSrcweir #include <unx/saldisp.hxx>
36cdf0e10cSrcweir #include <unx/salgdi.h>
37cdf0e10cSrcweir #include <unx/salvd.h>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <salinst.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir // -=-= SalInstance =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
42cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CreateVirtualDevice(SalGraphics * pGraphics,long nDX,long nDY,sal_uInt16 nBitCount,const SystemGraphicsData * pData)43cdf0e10cSrcweir SalVirtualDevice* X11SalInstance::CreateVirtualDevice( SalGraphics* pGraphics,
44cdf0e10cSrcweir long nDX, long nDY,
45cdf0e10cSrcweir sal_uInt16 nBitCount, const SystemGraphicsData *pData )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir X11SalVirtualDevice *pVDev = new X11SalVirtualDevice();
48cdf0e10cSrcweir if( !nBitCount && pGraphics )
49cdf0e10cSrcweir nBitCount = pGraphics->GetBitCount();
50cdf0e10cSrcweir
51cdf0e10cSrcweir if( pData && pData->hDrawable != None )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir XLIB_Window aRoot;
54cdf0e10cSrcweir int x, y;
55cdf0e10cSrcweir unsigned int w = 0, h = 0, bw, d;
56cdf0e10cSrcweir Display* pDisp = GetX11SalData()->GetDisplay()->GetDisplay();
57cdf0e10cSrcweir XGetGeometry( pDisp, pData->hDrawable,
58cdf0e10cSrcweir &aRoot, &x, &y, &w, &h, &bw, &d );
59cdf0e10cSrcweir int nScreen = 0;
60cdf0e10cSrcweir while( nScreen < ScreenCount( pDisp ) )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir if( RootWindow( pDisp, nScreen ) == aRoot )
63cdf0e10cSrcweir break;
64cdf0e10cSrcweir nScreen++;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir nDX = (long)w;
67cdf0e10cSrcweir nDY = (long)h;
68cdf0e10cSrcweir if( !pVDev->Init( GetX11SalData()->GetDisplay(), nDX, nDY, nBitCount, nScreen, pData->hDrawable, pData->pRenderFormat ) )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir delete pVDev;
71cdf0e10cSrcweir return NULL;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir else if( !pVDev->Init( GetX11SalData()->GetDisplay(), nDX, nDY, nBitCount,
75cdf0e10cSrcweir pGraphics ? static_cast<X11SalGraphics*>(pGraphics)->GetScreenNumber() :
76cdf0e10cSrcweir GetX11SalData()->GetDisplay()->GetDefaultScreenNumber() ) )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir delete pVDev;
79cdf0e10cSrcweir return NULL;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir pVDev->InitGraphics( pVDev );
83cdf0e10cSrcweir return pVDev;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
DestroyVirtualDevice(SalVirtualDevice * pDevice)86cdf0e10cSrcweir void X11SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir delete pDevice;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir // -=-= SalGraphicsData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
92cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Init(X11SalVirtualDevice * pDevice,SalColormap * pColormap,bool bDeleteColormap)93cdf0e10cSrcweir void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap, bool bDeleteColormap )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir SalColormap *pOrigDeleteColormap = m_pDeleteColormap;
96cdf0e10cSrcweir
97cdf0e10cSrcweir SalDisplay *pDisplay = pDevice->GetDisplay();
98cdf0e10cSrcweir m_nScreen = pDevice->GetScreenNumber();
99cdf0e10cSrcweir
100cdf0e10cSrcweir int nVisualDepth = pDisplay->GetColormap( m_nScreen ).GetVisual().GetDepth();
101cdf0e10cSrcweir int nDeviceDepth = pDevice->GetDepth();
102cdf0e10cSrcweir
103cdf0e10cSrcweir if( pColormap )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir m_pColormap = pColormap;
106cdf0e10cSrcweir if( bDeleteColormap )
107cdf0e10cSrcweir m_pDeleteColormap = pColormap;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir else
110cdf0e10cSrcweir if( nDeviceDepth == nVisualDepth )
111cdf0e10cSrcweir m_pColormap = &pDisplay->GetColormap( m_nScreen );
112cdf0e10cSrcweir else
113cdf0e10cSrcweir if( nDeviceDepth == 1 )
114cdf0e10cSrcweir m_pColormap = m_pDeleteColormap = new SalColormap();
115cdf0e10cSrcweir
116cdf0e10cSrcweir if (m_pDeleteColormap != pOrigDeleteColormap)
117cdf0e10cSrcweir delete pOrigDeleteColormap;
118cdf0e10cSrcweir
119cdf0e10cSrcweir const Drawable aVdevDrawable = pDevice->GetDrawable();
120cdf0e10cSrcweir SetDrawable( aVdevDrawable, m_nScreen );
121cdf0e10cSrcweir
122cdf0e10cSrcweir m_pVDev = pDevice;
123cdf0e10cSrcweir m_pFrame = NULL;
124cdf0e10cSrcweir
125cdf0e10cSrcweir bWindow_ = pDisplay->IsDisplay();
126cdf0e10cSrcweir bVirDev_ = sal_True;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir // -=-= SalVirDevData / SalVirtualDevice -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
130cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Init(SalDisplay * pDisplay,long nDX,long nDY,sal_uInt16 nBitCount,int nScreen,Pixmap hDrawable,void * pRenderFormatVoid)131cdf0e10cSrcweir sal_Bool X11SalVirtualDevice::Init( SalDisplay *pDisplay,
132cdf0e10cSrcweir long nDX, long nDY,
133cdf0e10cSrcweir sal_uInt16 nBitCount,
134cdf0e10cSrcweir int nScreen,
135cdf0e10cSrcweir Pixmap hDrawable,
136cdf0e10cSrcweir void* pRenderFormatVoid )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir SalColormap* pColormap = NULL;
139cdf0e10cSrcweir bool bDeleteColormap = false;
140cdf0e10cSrcweir
141cdf0e10cSrcweir pDisplay_ = pDisplay;
142cdf0e10cSrcweir pGraphics_ = new X11SalGraphics();
143cdf0e10cSrcweir m_nScreen = nScreen;
144cdf0e10cSrcweir if( pRenderFormatVoid ) {
145cdf0e10cSrcweir XRenderPictFormat *pRenderFormat = ( XRenderPictFormat* )pRenderFormatVoid;
146cdf0e10cSrcweir pGraphics_->SetXRenderFormat( pRenderFormat );
147cdf0e10cSrcweir if( pRenderFormat->colormap )
148cdf0e10cSrcweir pColormap = new SalColormap( pDisplay, pRenderFormat->colormap, m_nScreen );
149cdf0e10cSrcweir else
150cdf0e10cSrcweir pColormap = new SalColormap( nBitCount );
151cdf0e10cSrcweir bDeleteColormap = true;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir else if( nBitCount != pDisplay->GetVisual( m_nScreen ).GetDepth() )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir pColormap = new SalColormap( nBitCount );
156cdf0e10cSrcweir bDeleteColormap = true;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir pGraphics_->SetLayout( 0 ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
159cdf0e10cSrcweir nDX_ = nDX;
160cdf0e10cSrcweir nDY_ = nDY;
161cdf0e10cSrcweir nDepth_ = nBitCount;
162cdf0e10cSrcweir
163cdf0e10cSrcweir if( hDrawable == None )
164cdf0e10cSrcweir hDrawable_ = XCreatePixmap( GetXDisplay(),
165cdf0e10cSrcweir pDisplay_->GetDrawable( m_nScreen ),
166cdf0e10cSrcweir nDX_, nDY_,
167cdf0e10cSrcweir GetDepth() );
168cdf0e10cSrcweir else
169cdf0e10cSrcweir {
170cdf0e10cSrcweir hDrawable_ = hDrawable;
171cdf0e10cSrcweir bExternPixmap_ = sal_True;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir pGraphics_->Init( this, pColormap, bDeleteColormap );
175cdf0e10cSrcweir
176cdf0e10cSrcweir return hDrawable_ != None ? sal_True : sal_False;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
X11SalVirtualDevice()180cdf0e10cSrcweir X11SalVirtualDevice::X11SalVirtualDevice()
181cdf0e10cSrcweir {
182cdf0e10cSrcweir pDisplay_ = (SalDisplay*)ILLEGAL_POINTER;
183cdf0e10cSrcweir pGraphics_ = NULL;
184cdf0e10cSrcweir hDrawable_ = None;
185cdf0e10cSrcweir nDX_ = 0;
186cdf0e10cSrcweir nDY_ = 0;
187cdf0e10cSrcweir nDepth_ = 0;
188cdf0e10cSrcweir bGraphics_ = sal_False;
189cdf0e10cSrcweir bExternPixmap_ = sal_False;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
~X11SalVirtualDevice()193cdf0e10cSrcweir X11SalVirtualDevice::~X11SalVirtualDevice()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir if( pGraphics_ )
196cdf0e10cSrcweir delete pGraphics_;
197cdf0e10cSrcweir pGraphics_ = NULL;
198cdf0e10cSrcweir
199cdf0e10cSrcweir if( GetDrawable() && !bExternPixmap_ )
200cdf0e10cSrcweir XFreePixmap( GetXDisplay(), GetDrawable() );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
GetGraphics()203cdf0e10cSrcweir SalGraphics* X11SalVirtualDevice::GetGraphics()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir if( bGraphics_ )
206cdf0e10cSrcweir return NULL;
207cdf0e10cSrcweir
208cdf0e10cSrcweir if( pGraphics_ )
209cdf0e10cSrcweir bGraphics_ = sal_True;
210cdf0e10cSrcweir
211cdf0e10cSrcweir return pGraphics_;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
ReleaseGraphics(SalGraphics *)214cdf0e10cSrcweir void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* )
215cdf0e10cSrcweir { bGraphics_ = sal_False; }
216cdf0e10cSrcweir
SetSize(long nDX,long nDY)217cdf0e10cSrcweir sal_Bool X11SalVirtualDevice::SetSize( long nDX, long nDY )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir if( bExternPixmap_ )
220cdf0e10cSrcweir return sal_False;
221cdf0e10cSrcweir
222cdf0e10cSrcweir // #144688#
223cdf0e10cSrcweir // the X protocol request CreatePixmap puts an upper bound
224cdf0e10cSrcweir // of 16 bit to the size. Beyond that there may be implementation
225cdf0e10cSrcweir // limits of the Xserver; which we should catch by a failed XCreatePixmap
226cdf0e10cSrcweir // call. However extra large values should be caught here since we'd run into
227cdf0e10cSrcweir // 16 bit truncation here without noticing.
228cdf0e10cSrcweir if( nDX < 0 || nDX > 65535 ||
229cdf0e10cSrcweir nDY < 0 || nDY > 65535 )
230cdf0e10cSrcweir return sal_False;
231cdf0e10cSrcweir
232cdf0e10cSrcweir if( !nDX ) nDX = 1;
233cdf0e10cSrcweir if( !nDY ) nDY = 1;
234cdf0e10cSrcweir
235cdf0e10cSrcweir Pixmap h = XCreatePixmap( GetXDisplay(),
236cdf0e10cSrcweir pDisplay_->GetDrawable( m_nScreen ),
237cdf0e10cSrcweir nDX, nDY, nDepth_ );
238cdf0e10cSrcweir
239cdf0e10cSrcweir if( !h )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir if( !GetDrawable() )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir hDrawable_ = XCreatePixmap( GetXDisplay(),
244cdf0e10cSrcweir pDisplay_->GetDrawable( m_nScreen ),
245cdf0e10cSrcweir 1, 1, nDepth_ );
246cdf0e10cSrcweir nDX_ = 1;
247cdf0e10cSrcweir nDY_ = 1;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir return sal_False;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir if( GetDrawable() )
253cdf0e10cSrcweir XFreePixmap( GetXDisplay(), GetDrawable() );
254cdf0e10cSrcweir hDrawable_ = h;
255cdf0e10cSrcweir
256cdf0e10cSrcweir nDX_ = nDX;
257cdf0e10cSrcweir nDY_ = nDY;
258cdf0e10cSrcweir
259cdf0e10cSrcweir if( pGraphics_ )
260cdf0e10cSrcweir InitGraphics( this );
261cdf0e10cSrcweir
262cdf0e10cSrcweir return sal_True;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
GetSize(long & rWidth,long & rHeight)265cdf0e10cSrcweir void X11SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir rWidth = GetWidth();
268cdf0e10cSrcweir rHeight = GetHeight();
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271