Add Marathi autocorrect
[LibreOffice.git] / vcl / unx / generic / gdi / salvd.cxx
blob33ba19c95d5925b532b30d5fcf00e5edc5b212d5
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>
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>
32 #if HAVE_FEATURE_SKIA
33 #include <skia/x11/salvd.hxx>
34 #endif
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)
41 assert(pNewGraphics);
42 #if HAVE_FEATURE_SKIA
43 if (SkiaHelper::isVCLSkiaEnabled())
44 return std::unique_ptr<SalVirtualDevice>(new X11SkiaSalVirtualDevice(rGraphics, nDX, nDY, pData, std::move(pNewGraphics)));
45 else
46 #endif
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();
64 if( pColormap )
66 maX11Common.m_pColormap = pColormap;
67 if( bDeleteColormap )
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();
78 m_pVDev = pDevice;
79 m_pFrame = nullptr;
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)),
89 m_nXScreen(0),
90 bGraphics_(false)
92 SalColormap* pColormap = nullptr;
93 bool bDeleteColormap = false;
95 sal_uInt16 nBitCount = rGraphics.GetBitCount();
96 pDisplay_ = vcl_sal::getSalDisplay(GetGenericUnixSalData());
97 nDepth_ = nBitCount;
99 if( pData && pData->hDrawable != None )
101 ::Window aRoot;
102 int x, y;
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 );
107 int nScreen = 0;
108 while( nScreen < ScreenCount( pDisp ) )
110 if( RootWindow( pDisp, nScreen ) == aRoot )
111 break;
112 nScreen++;
114 nDX_ = static_cast<tools::Long>(w);
115 nDY_ = static_cast<tools::Long>(h);
116 nDX = nDX_;
117 nDY = nDY_;
118 m_nXScreen = SalX11Screen( nScreen );
119 hDrawable_ = pData->hDrawable;
120 bExternPixmap_ = true;
122 else
124 nDX_ = nDX;
125 nDY_ = nDY;
126 m_nXScreen = static_cast<const X11SalGraphics&>(rGraphics).GetScreenNumber();
127 hDrawable_ = limitXCreatePixmap( GetXDisplay(),
128 pDisplay_->GetDrawable( m_nXScreen ),
129 nDX_, nDY_,
130 GetDepth() );
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;
149 else
151 m_bOwnsSurface = true;
152 m_pSurface = cairo_xlib_surface_create(GetXDisplay(), hDrawable_,
153 pDisplay_->GetColormap(m_nXScreen).GetVisual().visual,
154 nDX_, nDY_);
157 pGraphics_->Init(this, pColormap, bDeleteColormap);
160 X11SalVirtualDevice::~X11SalVirtualDevice()
162 pGraphics_.reset();
164 if (m_bOwnsSurface)
165 cairo_surface_destroy(m_pSurface);
167 if( GetDrawable() && !bExternPixmap_ )
168 XFreePixmap( GetXDisplay(), GetDrawable() );
171 SalGraphics* X11SalVirtualDevice::AcquireGraphics()
173 if( bGraphics_ )
174 return nullptr;
176 if( pGraphics_ )
177 bGraphics_ = true;
179 return pGraphics_.get();
182 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* )
183 { bGraphics_ = false; }
185 bool X11SalVirtualDevice::SetSize( tools::Long nDX, tools::Long nDY )
187 if( bExternPixmap_ )
188 return false;
190 if( !nDX ) nDX = 1;
191 if( !nDY ) nDY = 1;
193 if (m_bOwnsSurface)
194 cairo_surface_destroy(m_pSurface);
196 Pixmap h = limitXCreatePixmap( GetXDisplay(),
197 pDisplay_->GetDrawable( m_nXScreen ),
198 nDX, nDY, nDepth_ );
200 if( !h )
202 if( !GetDrawable() )
204 hDrawable_ = limitXCreatePixmap( GetXDisplay(),
205 pDisplay_->GetDrawable( m_nXScreen ),
206 1, 1, nDepth_ );
207 nDX_ = 1;
208 nDY_ = 1;
211 if (m_bOwnsSurface)
213 m_pSurface = cairo_xlib_surface_create(GetXDisplay(), hDrawable_,
214 pDisplay_->GetColormap(m_nXScreen).GetVisual().visual,
215 nDX_, nDY_);
218 return false;
221 if( GetDrawable() )
222 XFreePixmap( GetXDisplay(), GetDrawable() );
223 hDrawable_ = h;
225 nDX_ = nDX;
226 nDY_ = nDY;
228 if (m_bOwnsSurface)
230 m_pSurface = cairo_xlib_surface_create(GetXDisplay(), hDrawable_,
231 pDisplay_->GetColormap(m_nXScreen).GetVisual().visual,
232 nDX_, nDY_);
235 if( pGraphics_ )
236 pGraphics_->Init( this );
238 return true;
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */