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 : 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 
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 protected:
82  virtual void doAcquire( sal_uInt32 nLockCount ) override;
83  virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
84 
85 public:
87  virtual ~SvpSalYieldMutex() override;
88 
89  virtual bool IsCurrentThread() const override;
90 };
91 
93 
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)
98 {
99  timeval m_aTimeout;
101  oslThreadIdentifier m_MainThread;
102 
103  virtual void TriggerUserEventProcessing() override;
104  virtual void ProcessEvent( SalUserEvent aEvent ) override;
105 
106 public:
108 
109  SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
110  virtual ~SvpSalInstance() override;
111 
112  void CloseWakeupPipe(bool log);
113  void CreateWakeupPipe(bool log);
114  void Wakeup(SvpRequest request = SvpRequest::NONE);
115 
116  void StartTimer( sal_uInt64 nMS );
117  void StopTimer();
118 
119  inline void registerFrame( SalFrame* pFrame );
120  inline void deregisterFrame( SalFrame* pFrame );
121 
122  bool CheckTimeout( bool bExecuteTimers = true );
123 
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;
128 
129  // Object (System Child Window)
130  virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
131  virtual void DestroyObject( SalObject* pObject ) override;
132 
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;
141 
142  // Printer
143  // pSetupData->mpDriverData can be 0
144  // pSetupData must be updated with the current
145  // JobSetup
147  ImplJobSetup* pSetupData ) override;
148  virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ) override;
149  virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
150 
151  virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
152  virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
153  virtual OUString GetDefaultPrinter() override;
154  virtual void PostPrintersChanged() override;
155 
156  // SalTimer
157  virtual SalTimer* CreateSalTimer() override;
158  // SalSystem
159  virtual SalSystem* CreateSalSystem() override;
160  // SalBitmap
161  virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
162 
163  std::shared_ptr<vcl::BackendCapabilities> GetBackendCapabilities() override;
164 
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;
172 
173  virtual OpenGLContext* CreateOpenGLContext() override;
174 
175  virtual OUString GetConnectionIdentifier() override;
176 
177  virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
178 
179  virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
180 };
181 
183 {
184  insertFrame( pFrame );
185 }
186 
188 {
189  eraseFrame( pFrame );
190 }
191 
193 
194 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
195 
196 /* 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:187
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:182
timeval m_aTimeout
Definition: svpinst.hxx:99
virtual SalTimer * CreateSalTimer()=0
static SvpSalInstance * s_pDefaultInstance
Definition: svpinst.hxx:107
virtual void DestroyObject(SalObject *pObject)=0
virtual void updateMainThread()
Definition: salinst.hxx:199
osl::Condition m_NonMainWaitingYieldCond
Definition: svpinst.hxx:73
virtual void Stop() override
oslThreadIdentifier m_MainThread
Definition: svpinst.hxx:101
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:100
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:70
virtual void PostPrintersChanged()=0
int m_FeedbackFDs[2]
Definition: svpinst.hxx:72
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow)=0