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>
35 #define VIRTUAL_DESKTOP_WIDTH 1024
36 #define VIRTUAL_DESKTOP_HEIGHT 768
39 #define SvpSalInstance AquaSalInstance
43 class SvpSalTimer final
: public SalTimer
45 SvpSalInstance
* m_pInstance
;
47 SvpSalTimer( SvpSalInstance
* pInstance
) : m_pInstance( pInstance
) {}
48 virtual ~SvpSalTimer() override
;
50 // override all pure virtual methods
51 virtual void Start( sal_uInt64 nMS
) override
;
52 virtual void Stop() override
;
61 MainThreadDispatchOneEvent
,
62 MainThreadDispatchAllEvents
,
65 class SvpSalYieldMutex final
: public SalYieldMutex
68 // note: these members might as well live in SvpSalInstance, but there is
69 // at least one subclass of SvpSalInstance (GTK3) that doesn't use them.
70 friend class SvpSalInstance
;
71 // members for communication from main thread to non-main thread
73 osl::Condition m_NonMainWaitingYieldCond
;
74 // members for communication from non-main thread to main thread
75 bool m_bNoYieldLock
= false; // accessed only on main thread
76 std::mutex m_WakeUpMainMutex
; // guard m_wakeUpMain & m_Request
77 std::condition_variable m_WakeUpMainCond
;
78 bool m_wakeUpMain
= false;
79 SvpRequest m_Request
= SvpRequest::NONE
;
81 virtual void doAcquire( sal_uInt32 nLockCount
) override
;
82 virtual sal_uInt32
doRelease( bool bUnlockAll
) override
;
86 virtual ~SvpSalYieldMutex() override
;
88 virtual bool IsCurrentThread() const override
;
91 SalInstance
* svp_create_SalInstance();
93 // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of
94 // SvpSalYieldMutex; if a subclass uses something else it must override these
95 // (Wakeup is only called by SvpSalTimer and SvpSalFrame)
96 class VCL_DLLPUBLIC SvpSalInstance
: public SalGenericInstance
, public SalUserEventList
99 sal_uLong m_nTimeoutMS
;
100 oslThreadIdentifier m_MainThread
;
102 virtual void TriggerUserEventProcessing() override
;
103 virtual void ProcessEvent( SalUserEvent aEvent
) override
;
106 static SvpSalInstance
* s_pDefaultInstance
;
108 SvpSalInstance( std::unique_ptr
<SalYieldMutex
> pMutex
);
109 virtual ~SvpSalInstance() override
;
111 void CloseWakeupPipe(bool log
);
112 void CreateWakeupPipe(bool log
);
113 void Wakeup(SvpRequest request
= SvpRequest::NONE
);
115 void StartTimer( sal_uInt64 nMS
);
118 inline void registerFrame( SalFrame
* pFrame
);
119 inline void deregisterFrame( SalFrame
* pFrame
);
121 bool CheckTimeout( bool bExecuteTimers
= true );
124 virtual SalFrame
* CreateChildFrame( SystemParentData
* pParent
, SalFrameStyleFlags nStyle
) override
;
125 virtual SalFrame
* CreateFrame( SalFrame
* pParent
, SalFrameStyleFlags nStyle
) override
;
126 virtual void DestroyFrame( SalFrame
* pFrame
) override
;
128 // Object (System Child Window)
129 virtual SalObject
* CreateObject( SalFrame
* pParent
, SystemWindowData
* pWindowData
, bool bShow
) override
;
130 virtual void DestroyObject( SalObject
* pObject
) override
;
133 // nDX and nDY in Pixel
134 // nBitCount: 0 == Default(=as window) / 1 == Mono
135 // pData allows for using a system dependent graphics or device context
136 virtual std::unique_ptr
<SalVirtualDevice
>
137 CreateVirtualDevice( SalGraphics
& rGraphics
,
138 tools::Long
&nDX
, tools::Long
&nDY
,
139 DeviceFormat eFormat
, const SystemGraphicsData
*pData
= nullptr ) override
;
142 // pSetupData->mpDriverData can be 0
143 // pSetupData must be updated with the current
145 virtual SalInfoPrinter
* CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
146 ImplJobSetup
* pSetupData
) override
;
147 virtual void DestroyInfoPrinter( SalInfoPrinter
* pPrinter
) override
;
148 virtual std::unique_ptr
<SalPrinter
> CreatePrinter( SalInfoPrinter
* pInfoPrinter
) override
;
150 virtual void GetPrinterQueueInfo( ImplPrnQueueList
* pList
) override
;
151 virtual void GetPrinterQueueState( SalPrinterQueueInfo
* pInfo
) override
;
152 virtual OUString
GetDefaultPrinter() override
;
153 virtual void PostPrintersChanged() override
;
156 virtual SalTimer
* CreateSalTimer() override
;
158 virtual SalSystem
* CreateSalSystem() override
;
160 virtual std::shared_ptr
<SalBitmap
> CreateSalBitmap() override
;
162 // wait next event and dispatch
163 // must returned by UserEvent (SalFrame::PostEvent)
165 virtual bool DoYield(bool bWait
, bool bHandleAllCurrentEvents
) override
;
166 virtual bool AnyInput( VclInputFlags nType
) override
;
167 virtual bool IsMainThread() const override
;
168 virtual void updateMainThread() override
;
170 virtual OUString
GetConnectionIdentifier() override
;
172 virtual void AddToRecentDocumentList(const OUString
& rFileUrl
, const OUString
& rMimeType
, const OUString
& rDocumentService
) override
;
174 virtual std::unique_ptr
<GenPspGraphics
> CreatePrintGraphics() override
;
176 virtual const cairo_font_options_t
* GetCairoFontOptions() override
;
179 inline void SvpSalInstance::registerFrame( SalFrame
* pFrame
)
181 insertFrame( pFrame
);
184 inline void SvpSalInstance::deregisterFrame( SalFrame
* pFrame
)
186 eraseFrame( pFrame
);
189 VCL_DLLPUBLIC cairo_surface_t
* get_underlying_cairo_surface(const VirtualDevice
& rDevice
);
191 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */