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 
42 class SvpSalInstance;
43 class SvpSalTimer final : public SalTimer
44 {
46 public:
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 
55 class SvpSalFrame;
56 class GenPspGraphics;
57 
58 enum class SvpRequest
59 {
60  NONE,
63 };
64 
65 class SvpSalYieldMutex final : public SalYieldMutex
66 {
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;
80 
81  virtual void doAcquire( sal_uInt32 nLockCount ) override;
82  virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
83 
84 public:
86  virtual ~SvpSalYieldMutex() override;
87 
88  virtual bool IsCurrentThread() const override;
89 };
90 
92 
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)
97 {
98  timeval m_aTimeout;
100  oslThreadIdentifier m_MainThread;
101 
102  virtual void TriggerUserEventProcessing() override;
103  virtual void ProcessEvent( SalUserEvent aEvent ) override;
104 
105 public:
107 
108  SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
109  virtual ~SvpSalInstance() override;
110 
111  void CloseWakeupPipe(bool log);
112  void CreateWakeupPipe(bool log);
113  void Wakeup(SvpRequest request = SvpRequest::NONE);
114 
115  void StartTimer( sal_uInt64 nMS );
116  void StopTimer();
117 
118  inline void registerFrame( SalFrame* pFrame );
119  inline void deregisterFrame( SalFrame* pFrame );
120 
121  bool CheckTimeout( bool bExecuteTimers = true );
122 
123  // Frame
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;
127 
128  // Object (System Child Window)
129  virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
130  virtual void DestroyObject( SalObject* pObject ) override;
131 
132  // VirtualDevice
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* pGraphics,
138  long &nDX, long &nDY,
139  DeviceFormat eFormat, const SystemGraphicsData *pData = nullptr ) override;
140 
141  // Printer
142  // pSetupData->mpDriverData can be 0
143  // pSetupData must be updated with the current
144  // JobSetup
146  ImplJobSetup* pSetupData ) override;
147  virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ) override;
148  virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
149 
150  virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
151  virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
152  virtual OUString GetDefaultPrinter() override;
153  virtual void PostPrintersChanged() override;
154 
155  // SalTimer
156  virtual SalTimer* CreateSalTimer() override;
157  // SalSystem
158  virtual SalSystem* CreateSalSystem() override;
159  // SalBitmap
160  virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
161 
162  std::shared_ptr<vcl::BackendCapabilities> GetBackendCapabilities() override;
163 
164  // wait next event and dispatch
165  // must returned by UserEvent (SalFrame::PostEvent)
166  // and timer
167  virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
168  virtual bool AnyInput( VclInputFlags nType ) override;
169  virtual bool IsMainThread() const override;
170  virtual void updateMainThread() override;
171 
172  virtual OpenGLContext* CreateOpenGLContext() override;
173 
174  virtual OUString GetConnectionIdentifier() override;
175 
176  virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
177 
178  virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
179 };
180 
182 {
183  insertFrame( pFrame );
184 }
185 
187 {
188  eraseFrame( pFrame );
189 }
190 
192 
193 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
194 
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Start(sal_uInt64 nMS) override
virtual OpenGLContext * CreateOpenGLContext()=0
void deregisterFrame(SalFrame *pFrame)
Definition: svpinst.hxx:186
bool m_bNoYieldLock
Definition: svpinst.hxx:75
virtual SalFrame * CreateChildFrame(SystemParentData *pParent, SalFrameStyleFlags nStyle)=0
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
virtual bool IsMainThread() const =0
virtual std::unique_ptr< SalPrinter > CreatePrinter(SalInfoPrinter *pInfoPrinter) override
void insertFrame(SalFrame *pFrame)
virtual bool AnyInput(VclInputFlags nType)=0
virtual void GetPrinterQueueInfo(ImplPrnQueueList *pList) override
virtual ~SvpSalTimer() override
VclInputFlags
Definition: inputtypes.hxx:25
void registerFrame(SalFrame *pFrame)
Definition: svpinst.hxx:181
timeval m_aTimeout
Definition: svpinst.hxx:98
virtual SalTimer * CreateSalTimer()=0
static SvpSalInstance * s_pDefaultInstance
Definition: svpinst.hxx:106
virtual void DestroyObject(SalObject *pObject)=0
virtual void updateMainThread()
Set the app's (somewhat) magic/main-thread to this one.
Definition: salinst.hxx:200
osl::Condition m_NonMainWaitingYieldCond
Definition: svpinst.hxx:73
virtual void Stop() override
oslThreadIdentifier m_MainThread
Definition: svpinst.hxx:100
std::mutex m_WakeUpMainMutex
Definition: svpinst.hxx:76
virtual bool IsCurrentThread() const override
virtual SalFrame * CreateFrame(SalFrame *pParent, SalFrameStyleFlags nStyle)=0
virtual SalSystem * CreateSalSystem()=0
virtual std::unique_ptr< SalVirtualDevice > CreateVirtualDevice(SalGraphics *pGraphics, long &rDX, long &rDY, DeviceFormat eFormat, const SystemGraphicsData *pData=nullptr)=0
SvpRequest m_Request
Definition: svpinst.hxx:79
virtual std::unique_ptr< GenPspGraphics > CreatePrintGraphics()=0
virtual std::shared_ptr< vcl::BackendCapabilities > GetBackendCapabilities()
Definition: salinst.hxx:135
sal_uLong m_nTimeoutMS
Definition: svpinst.hxx:99
SvpRequest
Definition: svpinst.hxx:58
virtual void DestroyFrame(SalFrame *pFrame)=0
virtual void ProcessEvent(SalUserEvent aEvent)=0
SalInstance * svp_create_SalInstance()
virtual void doAcquire(sal_uInt32 nLockCount) override
SvpSalInstance * m_pInstance
Definition: svpinst.hxx:45
DeviceFormat
Definition: salgtype.hxx:28
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
virtual SalInfoPrinter * CreateInfoPrinter(SalPrinterQueueInfo *pQueueInfo, ImplJobSetup *pSetupData) override
void eraseFrame(SalFrame *pFrame)
virtual OUString GetDefaultPrinter() override
virtual std::shared_ptr< SalBitmap > CreateSalBitmap()=0
VCL_DLLPUBLIC cairo_surface_t * get_underlying_cairo_surface(const VirtualDevice &rDevice)
virtual void TriggerUserEventProcessing()=0
SalFrameStyleFlags
Definition: salframe.hxx:64
virtual void GetPrinterQueueState(SalPrinterQueueInfo *pInfo) override
SvpSalTimer(SvpSalInstance *pInstance)
Definition: svpinst.hxx:47
virtual void AddToRecentDocumentList(const OUString &rFileUrl, const OUString &rMimeType, const OUString &rDocumentService)=0
virtual sal_uInt32 doRelease(bool bUnlockAll) override
virtual OUString GetConnectionIdentifier()=0
virtual void DestroyInfoPrinter(SalInfoPrinter *pPrinter) override
virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents)=0
Wait for the next event (if bWait) and dispatch it, includes posted events, and timers.
virtual ~SvpSalYieldMutex() override
std::condition_variable m_WakeUpMainCond
Definition: svpinst.hxx:77
struct _cairo_surface cairo_surface_t
Definition: svpgdi.hxx:71
virtual void PostPrintersChanged()=0
int m_FeedbackFDs[2]
Definition: svpinst.hxx:72
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow)=0