LibreOffice Module vcl (master) 1
svpinst.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
21#define INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
22
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>
30
31#include <condition_variable>
32
33#include <sys/time.h>
34
35#define VIRTUAL_DESKTOP_WIDTH 1024
36#define VIRTUAL_DESKTOP_HEIGHT 768
37
38#ifdef IOS
39#define SvpSalInstance AquaSalInstance
40#endif
41
42class SvpSalInstance;
43class SvpSalTimer final : public SalTimer
44{
46public:
47 SvpSalTimer( SvpSalInstance* pInstance ) : m_pInstance( pInstance ) {}
48 virtual ~SvpSalTimer() override;
49
50 // override all pure virtual methods
51 virtual void Start( sal_uInt64 nMS ) override;
52 virtual void Stop() override;
53};
54
55class SvpSalFrame;
56class GenPspGraphics;
57
58enum class SvpRequest
59{
60 NONE,
63};
64
65class SvpSalYieldMutex final : public SalYieldMutex
66{
67private:
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
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;
80
81 virtual void doAcquire( sal_uInt32 nLockCount ) override;
82 virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
83
84public:
86 virtual ~SvpSalYieldMutex() override;
87
88 virtual bool IsCurrentThread() const override;
89};
90
91// NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of
92// SvpSalYieldMutex; if a subclass uses something else it must override these
93// (Wakeup is only called by SvpSalTimer and SvpSalFrame)
95{
96 timeval m_aTimeout;
98 oslThreadIdentifier m_MainThread;
99
100 virtual void TriggerUserEventProcessing() override;
101 virtual void ProcessEvent( SalUserEvent aEvent ) override;
102 bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
103
104public:
106
107 SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
108 virtual ~SvpSalInstance() override;
109
110 void CloseWakeupPipe(bool log);
111 void CreateWakeupPipe(bool log);
113
114 void StartTimer( sal_uInt64 nMS );
115 void StopTimer();
116
117 inline void registerFrame( SalFrame* pFrame );
118 inline void deregisterFrame( SalFrame* pFrame );
119
120 bool CheckTimeout( bool bExecuteTimers = true );
121
122 // Frame
123 virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
124 virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
125 virtual void DestroyFrame( SalFrame* pFrame ) override;
126
127 // Object (System Child Window)
128 virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
129 virtual void DestroyObject( SalObject* pObject ) override;
130
131 // VirtualDevice
132 // nDX and nDY in Pixel
133 // nBitCount: 0 == Default(=as window) / 1 == Mono
134 // pData allows for using a system dependent graphics or device context
135 virtual std::unique_ptr<SalVirtualDevice>
137 tools::Long &nDX, tools::Long &nDY,
138 DeviceFormat eFormat, const SystemGraphicsData *pData = nullptr ) override;
139
140 // Printer
141 // pSetupData->mpDriverData can be 0
142 // pSetupData must be updated with the current
143 // JobSetup
145 ImplJobSetup* pSetupData ) override;
146 virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ) override;
147 virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
148
149 virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
150 virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
151 virtual OUString GetDefaultPrinter() override;
152 virtual void PostPrintersChanged() override;
153
154 // SalTimer
155 virtual SalTimer* CreateSalTimer() override;
156 // SalSystem
157 virtual SalSystem* CreateSalSystem() override;
158 // SalBitmap
159 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
160
161 // wait next event and dispatch
162 // must returned by UserEvent (SalFrame::PostEvent)
163 // and timer
164 virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
165 virtual bool AnyInput( VclInputFlags nType ) override;
166 virtual bool IsMainThread() const override;
167 virtual void updateMainThread() override;
168
169 virtual OUString GetConnectionIdentifier() override;
170
171 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
172
173 virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
174
175 virtual const cairo_font_options_t* GetCairoFontOptions() override;
176};
177
179{
180 insertFrame( pFrame );
181}
182
184{
185 eraseFrame( pFrame );
186}
187
189
190#endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _cairo_surface cairo_surface_t
Definition: CairoCommon.hxx:72
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
void eraseFrame(SalFrame *pFrame)
void insertFrame(SalFrame *pFrame)
sal_uLong m_nTimeoutMS
Definition: svpinst.hxx:97
void Wakeup(SvpRequest request=SvpRequest::NONE)
virtual SalFrame * CreateChildFrame(SystemParentData *pParent, SalFrameStyleFlags nStyle) override
virtual void GetPrinterQueueInfo(ImplPrnQueueList *pList) override
SvpSalInstance(std::unique_ptr< SalYieldMutex > pMutex)
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow) override
virtual SalInfoPrinter * CreateInfoPrinter(SalPrinterQueueInfo *pQueueInfo, ImplJobSetup *pSetupData) override
virtual std::shared_ptr< SalBitmap > CreateSalBitmap() override
virtual std::unique_ptr< GenPspGraphics > CreatePrintGraphics() override
virtual OUString GetConnectionIdentifier() override
virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override
Wait for the next event (if bWait) and dispatch it, includes posted events, and timers.
void deregisterFrame(SalFrame *pFrame)
Definition: svpinst.hxx:183
virtual void DestroyObject(SalObject *pObject) override
virtual SalSystem * CreateSalSystem() override
virtual std::unique_ptr< SalVirtualDevice > CreateVirtualDevice(SalGraphics &rGraphics, tools::Long &nDX, tools::Long &nDY, DeviceFormat eFormat, const SystemGraphicsData *pData=nullptr) override
oslThreadIdentifier m_MainThread
Definition: svpinst.hxx:98
virtual void updateMainThread() override
Set the app's (somewhat) magic/main-thread to this one.
void CreateWakeupPipe(bool log)
void StartTimer(sal_uInt64 nMS)
void registerFrame(SalFrame *pFrame)
Definition: svpinst.hxx:178
void CloseWakeupPipe(bool log)
static SvpSalInstance * s_pDefaultInstance
Definition: svpinst.hxx:105
timeval m_aTimeout
Definition: svpinst.hxx:96
virtual const cairo_font_options_t * GetCairoFontOptions() override
virtual void DestroyFrame(SalFrame *pFrame) override
bool CheckTimeout(bool bExecuteTimers=true)
virtual void DestroyInfoPrinter(SalInfoPrinter *pPrinter) override
virtual OUString GetDefaultPrinter() override
virtual bool AnyInput(VclInputFlags nType) override
virtual ~SvpSalInstance() override
virtual void TriggerUserEventProcessing() override
virtual void PostPrintersChanged() override
virtual bool IsMainThread() const override
bool ImplYield(bool bWait, bool bHandleAllCurrentEvents)
virtual std::unique_ptr< SalPrinter > CreatePrinter(SalInfoPrinter *pInfoPrinter) override
virtual void GetPrinterQueueState(SalPrinterQueueInfo *pInfo) override
virtual void ProcessEvent(SalUserEvent aEvent) override
virtual SalFrame * CreateFrame(SalFrame *pParent, SalFrameStyleFlags nStyle) override
virtual SalTimer * CreateSalTimer() override
virtual void AddToRecentDocumentList(const OUString &rFileUrl, const OUString &rMimeType, const OUString &rDocumentService) override
SvpSalTimer(SvpSalInstance *pInstance)
Definition: svpinst.hxx:47
virtual ~SvpSalTimer() override
virtual void Stop() override
virtual void Start(sal_uInt64 nMS) override
SvpSalInstance * m_pInstance
Definition: svpinst.hxx:45
bool m_bNoYieldLock
Definition: svpinst.hxx:75
virtual ~SvpSalYieldMutex() override
virtual bool IsCurrentThread() const override
virtual sal_uInt32 doRelease(bool bUnlockAll) override
std::condition_variable m_WakeUpMainCond
Definition: svpinst.hxx:77
SvpRequest m_Request
Definition: svpinst.hxx:79
osl::Condition m_NonMainWaitingYieldCond
Definition: svpinst.hxx:73
int m_FeedbackFDs[2]
Definition: svpinst.hxx:72
std::mutex m_WakeUpMainMutex
Definition: svpinst.hxx:76
virtual void doAcquire(sal_uInt32 nLockCount) override
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
VclInputFlags
Definition: inputtypes.hxx:25
NONE
long Long
SalFrameStyleFlags
Definition: salframe.hxx:65
DeviceFormat
Definition: salgtype.hxx:28
struct _cairo_font_options cairo_font_options_t
Definition: salinst.hxx:73
sal_uIntPtr sal_uLong
VCL_DLLPUBLIC cairo_surface_t * get_underlying_cairo_surface(const VirtualDevice &rDevice)
SvpRequest
Definition: svpinst.hxx:59
@ MainThreadDispatchOneEvent
@ MainThreadDispatchAllEvents