nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / gdi / salvd.cxx
blobeeb4e73fe62d5adb10e448ca410f618e94be55e0
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 #include <vcl/sysdata.hxx>
22 #include <X11/Xlib.h>
23 #include <X11/extensions/Xrender.h>
25 #include <unx/saldisp.hxx>
26 #include <unx/salinst.h>
27 #include <unx/salgdi.h>
28 #include <unx/salvd.h>
29 #include <unx/x11/xlimits.hxx>
31 #include <vcl/opengl/OpenGLHelper.hxx>
32 #include <opengl/x11/salvd.hxx>
34 #include <config_features.h>
35 #include <vcl/skia/SkiaHelper.hxx>
36 #if HAVE_FEATURE_SKIA
37 #include <skia/x11/salvd.hxx>
38 #endif
40 std::unique_ptr<SalVirtualDevice> X11SalInstance::CreateX11VirtualDevice(SalGraphics const * pGraphics,
41 tools::Long &nDX, tools::Long &nDY, DeviceFormat eFormat, const SystemGraphicsData *pData,
42 std::unique_ptr<X11SalGraphics> pNewGraphics)
44 assert(pNewGraphics);
45 #if HAVE_FEATURE_SKIA
46 if (SkiaHelper::isVCLSkiaEnabled())
47 return std::unique_ptr<SalVirtualDevice>(new X11SkiaSalVirtualDevice( pGraphics, nDX, nDY, pData, std::move(pNewGraphics) ));
48 else
49 #endif
50 if (OpenGLHelper::isVCLOpenGLEnabled())
51 return std::unique_ptr<SalVirtualDevice>(new X11OpenGLSalVirtualDevice( pGraphics, nDX, nDY, pData, std::move(pNewGraphics) ));
52 else
53 return std::unique_ptr<SalVirtualDevice>(new X11SalVirtualDevice(pGraphics, nDX, nDY, eFormat, pData, std::move(pNewGraphics)));
56 std::unique_ptr<SalVirtualDevice> X11SalInstance::CreateVirtualDevice(SalGraphics* pGraphics,
57 tools::Long &nDX, tools::Long &nDY, DeviceFormat eFormat, const SystemGraphicsData *pData)
59 return CreateX11VirtualDevice(pGraphics, nDX, nDY, eFormat, pData, std::make_unique<X11SalGraphics>());
62 void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, cairo_surface_t* pPreExistingTarget, SalColormap* pColormap,
63 bool bDeleteColormap )
65 SalDisplay *pDisplay = pDevice->GetDisplay();
66 m_nXScreen = pDevice->GetXScreenNumber();
68 int nVisualDepth = pDisplay->GetColormap( m_nXScreen ).GetVisual().GetDepth();
69 int nDeviceDepth = pDevice->GetDepth();
71 if( pColormap )
73 m_pColormap = pColormap;
74 if( bDeleteColormap )
75 m_pDeleteColormap.reset(pColormap);
77 else if( nDeviceDepth == nVisualDepth )
78 m_pColormap = &pDisplay->GetColormap( m_nXScreen );
79 else if( nDeviceDepth == 1 )
81 m_pDeleteColormap.reset(new SalColormap());
82 m_pColormap = m_pDeleteColormap.get();
85 m_pVDev = pDevice;
86 m_pFrame = nullptr;
88 bWindow_ = pDisplay->IsDisplay();
89 bVirDev_ = true;
91 SetDrawable(pDevice->GetDrawable(), pPreExistingTarget, m_nXScreen);
92 mxImpl->Init();
95 X11SalVirtualDevice::X11SalVirtualDevice(SalGraphics const * pGraphics, tools::Long &nDX, tools::Long &nDY,
96 DeviceFormat eFormat, const SystemGraphicsData *pData,
97 std::unique_ptr<X11SalGraphics> pNewGraphics) :
98 pGraphics_(std::move(pNewGraphics)),
99 m_nXScreen(0),
100 bGraphics_(false)
102 SalColormap* pColormap = nullptr;
103 bool bDeleteColormap = false;
105 sal_uInt16 nBitCount;
106 switch (eFormat)
108 case DeviceFormat::BITMASK:
109 nBitCount = 1;
110 break;
111 default:
112 nBitCount = pGraphics->GetBitCount();
113 break;
117 pDisplay_ = vcl_sal::getSalDisplay(GetGenericUnixSalData());
118 nDepth_ = nBitCount;
120 if( pData && pData->hDrawable != None )
122 ::Window aRoot;
123 int x, y;
124 unsigned int w = 0, h = 0, bw, d;
125 Display* pDisp = pDisplay_->GetDisplay();
126 XGetGeometry( pDisp, pData->hDrawable,
127 &aRoot, &x, &y, &w, &h, &bw, &d );
128 int nScreen = 0;
129 while( nScreen < ScreenCount( pDisp ) )
131 if( RootWindow( pDisp, nScreen ) == aRoot )
132 break;
133 nScreen++;
135 nDX_ = static_cast<tools::Long>(w);
136 nDY_ = static_cast<tools::Long>(h);
137 nDX = nDX_;
138 nDY = nDY_;
139 m_nXScreen = SalX11Screen( nScreen );
140 hDrawable_ = pData->hDrawable;
141 bExternPixmap_ = true;
143 else
145 nDX_ = nDX;
146 nDY_ = nDY;
147 m_nXScreen = pGraphics ? static_cast<X11SalGraphics const *>(pGraphics)->GetScreenNumber() :
148 vcl_sal::getSalDisplay(GetGenericUnixSalData())->GetDefaultXScreen();
149 hDrawable_ = limitXCreatePixmap( GetXDisplay(),
150 pDisplay_->GetDrawable( m_nXScreen ),
151 nDX_, nDY_,
152 GetDepth() );
153 bExternPixmap_ = false;
156 XRenderPictFormat* pXRenderFormat = pData ? static_cast<XRenderPictFormat*>(pData->pXRenderFormat) : nullptr;
157 if( pXRenderFormat )
159 pGraphics_->SetXRenderFormat( pXRenderFormat );
160 if( pXRenderFormat->colormap )
161 pColormap = new SalColormap( pDisplay_, pXRenderFormat->colormap, m_nXScreen );
162 else
163 pColormap = new SalColormap( nBitCount );
164 bDeleteColormap = true;
166 else if( nBitCount != pDisplay_->GetVisual( m_nXScreen ).GetDepth() )
168 pColormap = new SalColormap( nBitCount );
169 bDeleteColormap = true;
172 pGraphics_->SetLayout( SalLayoutFlags::NONE ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
174 // tdf#127529 see SvpSalInstance::CreateVirtualDevice for the rare case of a non-null pPreExistingTarget
175 cairo_surface_t* pPreExistingTarget = pData ? static_cast<cairo_surface_t*>(pData->pSurface) : nullptr;
177 pGraphics_->Init( this, pPreExistingTarget, pColormap, bDeleteColormap );
180 X11SalVirtualDevice::~X11SalVirtualDevice()
182 pGraphics_.reset();
184 if( GetDrawable() && !bExternPixmap_ )
185 XFreePixmap( GetXDisplay(), GetDrawable() );
188 SalGraphics* X11SalVirtualDevice::AcquireGraphics()
190 if( bGraphics_ )
191 return nullptr;
193 if( pGraphics_ )
194 bGraphics_ = true;
196 return pGraphics_.get();
199 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* )
200 { bGraphics_ = false; }
202 bool X11SalVirtualDevice::SetSize( tools::Long nDX, tools::Long nDY )
204 if( bExternPixmap_ )
205 return false;
207 if( !nDX ) nDX = 1;
208 if( !nDY ) nDY = 1;
210 Pixmap h = limitXCreatePixmap( GetXDisplay(),
211 pDisplay_->GetDrawable( m_nXScreen ),
212 nDX, nDY, nDepth_ );
214 if( !h )
216 if( !GetDrawable() )
218 hDrawable_ = limitXCreatePixmap( GetXDisplay(),
219 pDisplay_->GetDrawable( m_nXScreen ),
220 1, 1, nDepth_ );
221 nDX_ = 1;
222 nDY_ = 1;
224 return false;
227 if( GetDrawable() )
228 XFreePixmap( GetXDisplay(), GetDrawable() );
229 hDrawable_ = h;
231 nDX_ = nDX;
232 nDY_ = nDY;
234 if( pGraphics_ )
235 pGraphics_->Init( this );
237 return true;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */