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>
24 #include <unx/saldisp.hxx>
25 #include <unx/salinst.h>
26 #include <unx/salgdi.h>
27 #include <unx/salvd.h>
28 #include <unx/x11/xlimits.hxx>
30 #include <config_features.h>
31 #include <vcl/skia/SkiaHelper.hxx>
33 #include <skia/x11/salvd.hxx>
35 #include <cairo-xlib.h>
37 std::unique_ptr
<SalVirtualDevice
> X11SalInstance::CreateX11VirtualDevice(const SalGraphics
& rGraphics
,
38 tools::Long
&nDX
, tools::Long
&nDY
, DeviceFormat eFormat
, const SystemGraphicsData
*pData
,
39 std::unique_ptr
<X11SalGraphics
> pNewGraphics
)
43 if (SkiaHelper::isVCLSkiaEnabled())
44 return std::unique_ptr
<SalVirtualDevice
>(new X11SkiaSalVirtualDevice(rGraphics
, nDX
, nDY
, pData
, std::move(pNewGraphics
)));
47 return std::unique_ptr
<SalVirtualDevice
>(new X11SalVirtualDevice(rGraphics
, nDX
, nDY
, eFormat
, pData
, std::move(pNewGraphics
)));
50 std::unique_ptr
<SalVirtualDevice
> X11SalInstance::CreateVirtualDevice(SalGraphics
& rGraphics
,
51 tools::Long
&nDX
, tools::Long
&nDY
, DeviceFormat eFormat
, const SystemGraphicsData
*pData
)
53 return CreateX11VirtualDevice(rGraphics
, nDX
, nDY
, eFormat
, pData
, std::make_unique
<X11SalGraphics
>());
56 void X11SalGraphics::Init(X11SalVirtualDevice
*pDevice
, SalColormap
* pColormap
, bool bDeleteColormap
)
58 SalDisplay
*pDisplay
= pDevice
->GetDisplay();
59 m_nXScreen
= pDevice
->GetXScreenNumber();
61 int nVisualDepth
= pDisplay
->GetColormap( m_nXScreen
).GetVisual().GetDepth();
62 int nDeviceDepth
= pDevice
->GetDepth();
66 maX11Common
.m_pColormap
= pColormap
;
68 m_pDeleteColormap
.reset(pColormap
);
70 else if( nDeviceDepth
== nVisualDepth
)
71 maX11Common
.m_pColormap
= &pDisplay
->GetColormap( m_nXScreen
);
72 else if( nDeviceDepth
== 1 )
74 m_pDeleteColormap
.reset(new SalColormap());
75 maX11Common
.m_pColormap
= m_pDeleteColormap
.get();
81 SetDrawable(pDevice
->GetDrawable(), pDevice
->GetSurface(), m_nXScreen
);
82 mxImpl
->UpdateX11GeometryProvider();
85 X11SalVirtualDevice::X11SalVirtualDevice(const SalGraphics
& rGraphics
, tools::Long
&nDX
, tools::Long
&nDY
,
86 DeviceFormat
/*eFormat*/, const SystemGraphicsData
*pData
,
87 std::unique_ptr
<X11SalGraphics
> pNewGraphics
) :
88 pGraphics_(std::move(pNewGraphics
)),
92 SalColormap
* pColormap
= nullptr;
93 bool bDeleteColormap
= false;
95 sal_uInt16 nBitCount
= rGraphics
.GetBitCount();
96 pDisplay_
= vcl_sal::getSalDisplay(GetGenericUnixSalData());
99 if( pData
&& pData
->hDrawable
!= None
)
103 unsigned int w
= 0, h
= 0, bw
, d
;
104 Display
* pDisp
= pDisplay_
->GetDisplay();
105 XGetGeometry( pDisp
, pData
->hDrawable
,
106 &aRoot
, &x
, &y
, &w
, &h
, &bw
, &d
);
108 while( nScreen
< ScreenCount( pDisp
) )
110 if( RootWindow( pDisp
, nScreen
) == aRoot
)
114 nDX_
= static_cast<tools::Long
>(w
);
115 nDY_
= static_cast<tools::Long
>(h
);
118 m_nXScreen
= SalX11Screen( nScreen
);
119 hDrawable_
= pData
->hDrawable
;
120 bExternPixmap_
= true;
126 m_nXScreen
= static_cast<const X11SalGraphics
&>(rGraphics
).GetScreenNumber();
127 hDrawable_
= limitXCreatePixmap( GetXDisplay(),
128 pDisplay_
->GetDrawable( m_nXScreen
),
131 bExternPixmap_
= false;
134 if( nBitCount
!= pDisplay_
->GetVisual( m_nXScreen
).GetDepth() )
136 pColormap
= new SalColormap( nBitCount
);
137 bDeleteColormap
= true;
140 pGraphics_
->SetLayout( SalLayoutFlags::NONE
); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
142 // tdf#127529 see SvpSalInstance::CreateVirtualDevice for the rare case of a non-null pPreExistingTarget
143 cairo_surface_t
* pPreExistingTarget
= pData
? static_cast<cairo_surface_t
*>(pData
->pSurface
) : nullptr;
144 if (pPreExistingTarget
)
146 m_bOwnsSurface
= false;
147 m_pSurface
= pPreExistingTarget
;
151 m_bOwnsSurface
= true;
152 m_pSurface
= cairo_xlib_surface_create(GetXDisplay(), hDrawable_
,
153 pDisplay_
->GetColormap(m_nXScreen
).GetVisual().visual
,
157 pGraphics_
->Init(this, pColormap
, bDeleteColormap
);
160 X11SalVirtualDevice::~X11SalVirtualDevice()
165 cairo_surface_destroy(m_pSurface
);
167 if( GetDrawable() && !bExternPixmap_
)
168 XFreePixmap( GetXDisplay(), GetDrawable() );
171 SalGraphics
* X11SalVirtualDevice::AcquireGraphics()
179 return pGraphics_
.get();
182 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics
* )
183 { bGraphics_
= false; }
185 bool X11SalVirtualDevice::SetSize( tools::Long nDX
, tools::Long nDY
)
194 cairo_surface_destroy(m_pSurface
);
196 Pixmap h
= limitXCreatePixmap( GetXDisplay(),
197 pDisplay_
->GetDrawable( m_nXScreen
),
204 hDrawable_
= limitXCreatePixmap( GetXDisplay(),
205 pDisplay_
->GetDrawable( m_nXScreen
),
213 m_pSurface
= cairo_xlib_surface_create(GetXDisplay(), hDrawable_
,
214 pDisplay_
->GetColormap(m_nXScreen
).GetVisual().visual
,
222 XFreePixmap( GetXDisplay(), GetDrawable() );
230 m_pSurface
= cairo_xlib_surface_create(GetXDisplay(), hDrawable_
,
231 pDisplay_
->GetColormap(m_nXScreen
).GetVisual().visual
,
236 pGraphics_
->Init( this );
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */