Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / inc / headless / svpinst.hxx
blob04e4de84cad7d9e30641a0f6affc82e156b213c9
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 #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>
33 #include <sys/time.h>
35 #define VIRTUAL_DESKTOP_WIDTH 1024
36 #define VIRTUAL_DESKTOP_HEIGHT 768
38 #ifdef IOS
39 #define SvpSalInstance AquaSalInstance
40 #endif
42 class SvpSalInstance;
43 class SvpSalTimer : public SalTimer
45 SvpSalInstance* m_pInstance;
46 public:
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;
55 class SvpSalFrame;
56 class GenPspGraphics;
58 enum class SvpRequest
60 NONE,
61 MainThreadDispatchOneEvent,
62 MainThreadDispatchAllEvents,
65 class SvpSalYieldMutex : public SalYieldMutex
67 private:
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
72 int m_FeedbackFDs[2];
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 protected:
82 virtual void doAcquire( sal_uInt32 nLockCount ) override;
83 virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
85 public:
86 SvpSalYieldMutex();
87 virtual ~SvpSalYieldMutex() override;
89 virtual bool IsCurrentThread() const override;
92 SalInstance* svp_create_SalInstance();
94 // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of
95 // SvpSalYieldMutex; if a subclass uses something else it must override these
96 // (Wakeup is only called by SvpSalTimer and SvpSalFrame)
97 class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEventList
99 timeval m_aTimeout;
100 sal_uLong m_nTimeoutMS;
101 oslThreadIdentifier m_MainThread;
103 virtual void TriggerUserEventProcessing() override;
104 virtual void ProcessEvent( SalUserEvent aEvent ) override;
106 public:
107 static SvpSalInstance* s_pDefaultInstance;
109 SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
110 virtual ~SvpSalInstance() override;
112 void CloseWakeupPipe(bool log);
113 void CreateWakeupPipe(bool log);
114 void Wakeup(SvpRequest request = SvpRequest::NONE);
116 void StartTimer( sal_uInt64 nMS );
117 void StopTimer();
119 inline void registerFrame( SalFrame* pFrame );
120 inline void deregisterFrame( SalFrame* pFrame );
122 bool CheckTimeout( bool bExecuteTimers = true );
124 // Frame
125 virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
126 virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
127 virtual void DestroyFrame( SalFrame* pFrame ) override;
129 // Object (System Child Window)
130 virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
131 virtual void DestroyObject( SalObject* pObject ) override;
133 // VirtualDevice
134 // nDX and nDY in Pixel
135 // nBitCount: 0 == Default(=as window) / 1 == Mono
136 // pData allows for using a system dependent graphics or device context
137 virtual std::unique_ptr<SalVirtualDevice>
138 CreateVirtualDevice( SalGraphics* pGraphics,
139 long &nDX, long &nDY,
140 DeviceFormat eFormat, const SystemGraphicsData *pData = nullptr ) override;
142 // Printer
143 // pSetupData->mpDriverData can be 0
144 // pSetupData must be updated with the current
145 // JobSetup
146 virtual SalInfoPrinter* CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
147 ImplJobSetup* pSetupData ) override;
148 virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ) override;
149 virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
151 virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
152 virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
153 virtual OUString GetDefaultPrinter() override;
154 virtual void PostPrintersChanged() override;
156 // SalTimer
157 virtual SalTimer* CreateSalTimer() override;
158 // SalSystem
159 virtual SalSystem* CreateSalSystem() override;
160 // SalBitmap
161 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
163 std::shared_ptr<vcl::BackendCapabilities> GetBackendCapabilities() override;
165 // wait next event and dispatch
166 // must returned by UserEvent (SalFrame::PostEvent)
167 // and timer
168 virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
169 virtual bool AnyInput( VclInputFlags nType ) override;
170 virtual bool IsMainThread() const override;
171 virtual void updateMainThread() override;
173 virtual OpenGLContext* CreateOpenGLContext() override;
175 virtual OUString GetConnectionIdentifier() override;
177 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
179 virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
182 inline void SvpSalInstance::registerFrame( SalFrame* pFrame )
184 insertFrame( pFrame );
187 inline void SvpSalInstance::deregisterFrame( SalFrame* pFrame )
189 eraseFrame( pFrame );
192 VCL_DLLPUBLIC cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice& rDevice);
194 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */