/src/libreoffice/vcl/inc/headless/svpinst.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <osl/thread.hxx> |
23 | | #include <osl/conditn.hxx> |
24 | | #include <SalYieldMutex.hxx> |
25 | | #include <salinst.hxx> |
26 | | #include <saltimer.hxx> |
27 | | #include <salusereventlist.hxx> |
28 | | #include <unx/geninst.h> |
29 | | #include <unx/genprn.h> |
30 | | |
31 | | #include <condition_variable> |
32 | | #include <mutex> |
33 | | #include <queue> |
34 | | |
35 | | #ifdef IOS |
36 | | #define SvpSalInstance AquaSalInstance |
37 | | #endif |
38 | | |
39 | | class SvpSalInstance; |
40 | | class SvpSalTimer final : public SalTimer |
41 | | { |
42 | | SvpSalInstance* m_pInstance; |
43 | | public: |
44 | 31 | SvpSalTimer( SvpSalInstance* pInstance ) : m_pInstance( pInstance ) {} |
45 | | virtual ~SvpSalTimer() override; |
46 | | |
47 | | // override all pure virtual methods |
48 | | virtual void Start( sal_uInt64 nMS ) override; |
49 | | virtual void Stop() override; |
50 | | }; |
51 | | |
52 | | enum class SvpRequest |
53 | | { |
54 | | NONE, |
55 | | MainThreadDispatchOneEvent, |
56 | | MainThreadDispatchAllEvents, |
57 | | }; |
58 | | |
59 | | class SvpSalYieldMutex final : public SalYieldMutex |
60 | | { |
61 | | private: |
62 | | // note: these members might as well live in SvpSalInstance, but there is |
63 | | // at least one subclass of SvpSalInstance (GTK3) that doesn't use them. |
64 | | friend class SvpSalInstance; |
65 | | // members for communication from main thread to non-main thread |
66 | | std::mutex m_FeedbackMutex; |
67 | | std::queue<bool> m_FeedbackPipe; |
68 | | std::condition_variable m_FeedbackCV; |
69 | | osl::Condition m_NonMainWaitingYieldCond; |
70 | | // members for communication from non-main thread to main thread |
71 | | bool m_bNoYieldLock = false; // accessed only on main thread |
72 | | std::mutex m_WakeUpMainMutex; // guard m_wakeUpMain & m_Request |
73 | | std::condition_variable m_WakeUpMainCond; |
74 | | bool m_wakeUpMain = false; |
75 | | SvpRequest m_Request = SvpRequest::NONE; |
76 | | |
77 | | virtual void doAcquire( sal_uInt32 nLockCount ) override; |
78 | | virtual sal_uInt32 doRelease( bool bUnlockAll ) override; |
79 | | |
80 | | public: |
81 | | SvpSalYieldMutex(); |
82 | | virtual ~SvpSalYieldMutex() override; |
83 | | |
84 | | virtual bool IsCurrentThread() const override; |
85 | | }; |
86 | | |
87 | | // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of |
88 | | // SvpSalYieldMutex; if a subclass uses something else it must override these |
89 | | // (Wakeup is only called by SvpSalTimer and SvpSalFrame) |
90 | | class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEventList |
91 | | { |
92 | | sal_uInt64 m_nTimeout; // in microseconds |
93 | | sal_uLong m_nTimeoutMS; |
94 | | oslThreadIdentifier m_MainThread; |
95 | | |
96 | | virtual void TriggerUserEventProcessing() override; |
97 | | virtual void ProcessEvent( SalUserEvent aEvent ) override; |
98 | | |
99 | | #if defined EMSCRIPTEN |
100 | | bool DoExecute(int &nExitCode) override; |
101 | | void DoQuit() override; |
102 | | #endif |
103 | | |
104 | | public: |
105 | | static SvpSalInstance* s_pDefaultInstance; |
106 | | |
107 | | SvpSalInstance(std::unique_ptr<SalYieldMutex> pMutex, SalData* pSalData); |
108 | | virtual void AfterAppInit() override; |
109 | | virtual ~SvpSalInstance() override; |
110 | | |
111 | | SAL_DLLPRIVATE bool ImplYield(bool bWait, bool bHandleAllCurrentEvents); |
112 | | |
113 | | SAL_DLLPRIVATE void CloseWakeupPipe(); |
114 | | SAL_DLLPRIVATE void Wakeup(SvpRequest request = SvpRequest::NONE); |
115 | | |
116 | | SAL_DLLPRIVATE void StartTimer( sal_uInt64 nMS ); |
117 | | SAL_DLLPRIVATE void StopTimer(); |
118 | | |
119 | | SAL_DLLPRIVATE bool CheckTimeout( bool bExecuteTimers = true ); |
120 | | |
121 | | // Frame |
122 | | SAL_DLLPRIVATE virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override; |
123 | | SAL_DLLPRIVATE virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override; |
124 | | virtual void DestroyFrame( SalFrame* pFrame ) override; |
125 | | |
126 | | // Object (System Child Window) |
127 | | SAL_DLLPRIVATE virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override; |
128 | | virtual void DestroyObject( SalObject* pObject ) override; |
129 | | |
130 | | // VirtualDevice |
131 | | // nDX and nDY in Pixel |
132 | | SAL_DLLPRIVATE virtual std::unique_ptr<SalVirtualDevice> |
133 | | CreateVirtualDevice( SalGraphics& rGraphics, |
134 | | tools::Long nDX, tools::Long nDY, |
135 | | DeviceFormat eFormat, |
136 | | bool bAlphaMaskTransparent = false ) override; |
137 | | |
138 | | // VirtualDevice |
139 | | // nDX and nDY in Pixel |
140 | | // pData allows for using a system dependent graphics or device context |
141 | | SAL_DLLPRIVATE virtual std::unique_ptr<SalVirtualDevice> |
142 | | CreateVirtualDevice( SalGraphics& rGraphics, |
143 | | tools::Long &nDX, tools::Long &nDY, |
144 | | DeviceFormat eFormat, |
145 | | const SystemGraphicsData& rData ) override; |
146 | | |
147 | | // Printer |
148 | | // pSetupData->mpDriverData can be 0 |
149 | | // pSetupData must be updated with the current |
150 | | // JobSetup |
151 | | SAL_DLLPRIVATE virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo& rQueueInfo, |
152 | | ImplJobSetup& rSetupData) override; |
153 | | SAL_DLLPRIVATE virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override; |
154 | | |
155 | | virtual void GetPrinterQueueInfo(ImplPrnQueueList& rList) override; |
156 | | virtual OUString GetDefaultPrinter() override; |
157 | | virtual void PostPrintersChanged() override; |
158 | | |
159 | | // SalTimer |
160 | | SAL_DLLPRIVATE virtual SalTimer* CreateSalTimer() override; |
161 | | // SalSystem |
162 | | SAL_DLLPRIVATE virtual SalSystem* CreateSalSystem() override; |
163 | | // SalBitmap |
164 | | virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override; |
165 | | |
166 | | // wait next event and dispatch |
167 | | // must returned by UserEvent (SalFrame::PostEvent) |
168 | | // and timer |
169 | | SAL_DLLPRIVATE virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override; |
170 | | SAL_DLLPRIVATE virtual bool AnyInput( VclInputFlags nType ) override; |
171 | | SAL_DLLPRIVATE virtual bool IsMainThread() const override; |
172 | | virtual void updateMainThread() override; |
173 | | |
174 | | SAL_DLLPRIVATE virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override; |
175 | | |
176 | | SAL_DLLPRIVATE virtual const cairo_font_options_t* GetCairoFontOptions() override; |
177 | | }; |
178 | | |
179 | | VCL_DLLPUBLIC cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice& rDevice); |
180 | | |
181 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |