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 #ifndef INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
21 #define INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
23 #include <osl/thread.hxx>
24 #include <osl/conditn.hxx>
25 #include <salinst.hxx>
26 #include <saltimer.hxx>
27 #include <salusereventlist.hxx>
28 #include <unx/geninst.h>
29 #include <unx/genprn.h>
31 #include <condition_variable>
36 #define SvpSalInstance AquaSalInstance
40 class SvpSalTimer final
: public SalTimer
42 SvpSalInstance
* m_pInstance
;
44 SvpSalTimer( SvpSalInstance
* pInstance
) : m_pInstance( pInstance
) {}
45 virtual ~SvpSalTimer() override
;
47 // override all pure virtual methods
48 virtual void Start( sal_uInt64 nMS
) override
;
49 virtual void Stop() override
;
58 MainThreadDispatchOneEvent
,
59 MainThreadDispatchAllEvents
,
62 class SvpSalYieldMutex final
: public SalYieldMutex
65 // note: these members might as well live in SvpSalInstance, but there is
66 // at least one subclass of SvpSalInstance (GTK3) that doesn't use them.
67 friend class SvpSalInstance
;
68 // members for communication from main thread to non-main thread
70 osl::Condition m_NonMainWaitingYieldCond
;
71 // members for communication from non-main thread to main thread
72 bool m_bNoYieldLock
= false; // accessed only on main thread
73 std::mutex m_WakeUpMainMutex
; // guard m_wakeUpMain & m_Request
74 std::condition_variable m_WakeUpMainCond
;
75 bool m_wakeUpMain
= false;
76 SvpRequest m_Request
= SvpRequest::NONE
;
78 virtual void doAcquire( sal_uInt32 nLockCount
) override
;
79 virtual sal_uInt32
doRelease( bool bUnlockAll
) override
;
83 virtual ~SvpSalYieldMutex() override
;
85 virtual bool IsCurrentThread() const override
;
88 // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of
89 // SvpSalYieldMutex; if a subclass uses something else it must override these
90 // (Wakeup is only called by SvpSalTimer and SvpSalFrame)
91 class VCL_DLLPUBLIC SvpSalInstance
: public SalGenericInstance
, public SalUserEventList
94 sal_uLong m_nTimeoutMS
;
95 oslThreadIdentifier m_MainThread
;
97 virtual void TriggerUserEventProcessing() override
;
98 virtual void ProcessEvent( SalUserEvent aEvent
) override
;
99 bool ImplYield(bool bWait
, bool bHandleAllCurrentEvents
);
102 static SvpSalInstance
* s_pDefaultInstance
;
104 SvpSalInstance( std::unique_ptr
<SalYieldMutex
> pMutex
);
105 virtual ~SvpSalInstance() override
;
107 void CloseWakeupPipe(bool log
);
108 void CreateWakeupPipe(bool log
);
109 void Wakeup(SvpRequest request
= SvpRequest::NONE
);
111 void StartTimer( sal_uInt64 nMS
);
114 inline void registerFrame( SalFrame
* pFrame
);
115 inline void deregisterFrame( SalFrame
* pFrame
);
117 bool CheckTimeout( bool bExecuteTimers
= true );
120 virtual SalFrame
* CreateChildFrame( SystemParentData
* pParent
, SalFrameStyleFlags nStyle
) override
;
121 virtual SalFrame
* CreateFrame( SalFrame
* pParent
, SalFrameStyleFlags nStyle
) override
;
122 virtual void DestroyFrame( SalFrame
* pFrame
) override
;
124 // Object (System Child Window)
125 virtual SalObject
* CreateObject( SalFrame
* pParent
, SystemWindowData
* pWindowData
, bool bShow
) override
;
126 virtual void DestroyObject( SalObject
* pObject
) override
;
129 // nDX and nDY in Pixel
130 // nBitCount: 0 == Default(=as window) / 1 == Mono
131 // pData allows for using a system dependent graphics or device context
132 virtual std::unique_ptr
<SalVirtualDevice
>
133 CreateVirtualDevice( SalGraphics
& rGraphics
,
134 tools::Long
&nDX
, tools::Long
&nDY
,
135 DeviceFormat eFormat
, const SystemGraphicsData
*pData
= nullptr ) override
;
138 // pSetupData->mpDriverData can be 0
139 // pSetupData must be updated with the current
141 virtual SalInfoPrinter
* CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
142 ImplJobSetup
* pSetupData
) override
;
143 virtual void DestroyInfoPrinter( SalInfoPrinter
* pPrinter
) override
;
144 virtual std::unique_ptr
<SalPrinter
> CreatePrinter( SalInfoPrinter
* pInfoPrinter
) override
;
146 virtual void GetPrinterQueueInfo( ImplPrnQueueList
* pList
) override
;
147 virtual void GetPrinterQueueState( SalPrinterQueueInfo
* pInfo
) override
;
148 virtual OUString
GetDefaultPrinter() override
;
149 virtual void PostPrintersChanged() override
;
152 virtual SalTimer
* CreateSalTimer() override
;
154 virtual SalSystem
* CreateSalSystem() override
;
156 virtual std::shared_ptr
<SalBitmap
> CreateSalBitmap() override
;
158 // wait next event and dispatch
159 // must returned by UserEvent (SalFrame::PostEvent)
161 virtual bool DoYield(bool bWait
, bool bHandleAllCurrentEvents
) override
;
162 virtual bool AnyInput( VclInputFlags nType
) override
;
163 virtual bool IsMainThread() const override
;
164 virtual void updateMainThread() override
;
166 virtual OUString
GetConnectionIdentifier() override
;
168 virtual void AddToRecentDocumentList(const OUString
& rFileUrl
, const OUString
& rMimeType
, const OUString
& rDocumentService
) override
;
170 virtual std::unique_ptr
<GenPspGraphics
> CreatePrintGraphics() override
;
172 virtual const cairo_font_options_t
* GetCairoFontOptions() override
;
175 inline void SvpSalInstance::registerFrame( SalFrame
* pFrame
)
177 insertFrame( pFrame
);
180 inline void SvpSalInstance::deregisterFrame( SalFrame
* pFrame
)
182 eraseFrame( pFrame
);
185 VCL_DLLPUBLIC cairo_surface_t
* get_underlying_cairo_surface(const VirtualDevice
& rDevice
);
187 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */