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 <vcl/sysdata.hxx>
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>
37 #include <skia/x11/salvd.hxx>
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
)
46 if (SkiaHelper::isVCLSkiaEnabled())
47 return std::unique_ptr
<SalVirtualDevice
>(new X11SkiaSalVirtualDevice( pGraphics
, nDX
, nDY
, pData
, std::move(pNewGraphics
) ));
50 if (OpenGLHelper::isVCLOpenGLEnabled())
51 return std::unique_ptr
<SalVirtualDevice
>(new X11OpenGLSalVirtualDevice( pGraphics
, nDX
, nDY
, pData
, std::move(pNewGraphics
) ));
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();
73 m_pColormap
= pColormap
;
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();
88 bWindow_
= pDisplay
->IsDisplay();
91 SetDrawable(pDevice
->GetDrawable(), pPreExistingTarget
, m_nXScreen
);
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
)),
102 SalColormap
* pColormap
= nullptr;
103 bool bDeleteColormap
= false;
105 sal_uInt16 nBitCount
;
108 case DeviceFormat::BITMASK
:
112 nBitCount
= pGraphics
->GetBitCount();
117 pDisplay_
= vcl_sal::getSalDisplay(GetGenericUnixSalData());
120 if( pData
&& pData
->hDrawable
!= None
)
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
);
129 while( nScreen
< ScreenCount( pDisp
) )
131 if( RootWindow( pDisp
, nScreen
) == aRoot
)
135 nDX_
= static_cast<tools::Long
>(w
);
136 nDY_
= static_cast<tools::Long
>(h
);
139 m_nXScreen
= SalX11Screen( nScreen
);
140 hDrawable_
= pData
->hDrawable
;
141 bExternPixmap_
= true;
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
),
153 bExternPixmap_
= false;
156 XRenderPictFormat
* pXRenderFormat
= pData
? static_cast<XRenderPictFormat
*>(pData
->pXRenderFormat
) : nullptr;
159 pGraphics_
->SetXRenderFormat( pXRenderFormat
);
160 if( pXRenderFormat
->colormap
)
161 pColormap
= new SalColormap( pDisplay_
, pXRenderFormat
->colormap
, m_nXScreen
);
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()
184 if( GetDrawable() && !bExternPixmap_
)
185 XFreePixmap( GetXDisplay(), GetDrawable() );
188 SalGraphics
* X11SalVirtualDevice::AcquireGraphics()
196 return pGraphics_
.get();
199 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics
* )
200 { bGraphics_
= false; }
202 bool X11SalVirtualDevice::SetSize( tools::Long nDX
, tools::Long nDY
)
210 Pixmap h
= limitXCreatePixmap( GetXDisplay(),
211 pDisplay_
->GetDrawable( m_nXScreen
),
218 hDrawable_
= limitXCreatePixmap( GetXDisplay(),
219 pDisplay_
->GetDrawable( m_nXScreen
),
228 XFreePixmap( GetXDisplay(), GetDrawable() );
235 pGraphics_
->Init( this );
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */