File indexing completed on 2024-04-28 04:32:43
0001 /* 0002 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 0004 Work sponsored by the LiMux project of the city of Munich: 0005 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef OKULAR_THREADEDGENERATOR_P_H 0011 #define OKULAR_THREADEDGENERATOR_P_H 0012 0013 #include "area.h" 0014 0015 #include <QImage> 0016 #include <QMutex> 0017 #include <QSet> 0018 #include <QThread> 0019 0020 class QEventLoop; 0021 0022 #include "generator.h" 0023 #include "page.h" 0024 0025 namespace Okular 0026 { 0027 class DocumentObserver; 0028 class DocumentPrivate; 0029 class FontInfo; 0030 class Generator; 0031 class Page; 0032 class PixmapGenerationThread; 0033 class PixmapRequest; 0034 class TextPage; 0035 class TextPageGenerationThread; 0036 class TilesManager; 0037 0038 class GeneratorPrivate 0039 { 0040 public: 0041 GeneratorPrivate(); 0042 0043 virtual ~GeneratorPrivate(); 0044 0045 Q_DECLARE_PUBLIC(Generator) 0046 Generator *q_ptr; 0047 0048 PixmapGenerationThread *pixmapGenerationThread(); 0049 TextPageGenerationThread *textPageGenerationThread(); 0050 0051 void pixmapGenerationFinished(); 0052 void textpageGenerationFinished(); 0053 0054 QMutex *threadsLock(); 0055 0056 virtual QVariant metaData(const QString &key, const QVariant &option) const; 0057 virtual QImage image(PixmapRequest *); 0058 0059 DocumentPrivate *m_document; 0060 // NOTE: the following should be a QSet< GeneratorFeature >, 0061 // but it is not to avoid #include'ing generator.h 0062 QSet<int> m_features; 0063 PixmapGenerationThread *mPixmapGenerationThread; 0064 TextPageGenerationThread *mTextPageGenerationThread; 0065 mutable QMutex m_mutex; 0066 QMutex m_threadsMutex; 0067 bool mPixmapReady : 1; 0068 bool mTextPageReady : 1; 0069 bool m_closing : 1; 0070 QEventLoop *m_closingLoop; 0071 QSizeF m_dpi; 0072 }; 0073 0074 class PixmapRequestPrivate 0075 { 0076 public: 0077 void swap(); 0078 TilesManager *tilesManager() const; 0079 0080 static PixmapRequestPrivate *get(const PixmapRequest *req); 0081 0082 DocumentObserver *mObserver; 0083 int mPageNumber; 0084 int mWidth; 0085 int mHeight; 0086 int mPriority; 0087 int mFeatures; 0088 bool mForce : 1; 0089 bool mTile : 1; 0090 bool mPartialUpdatesWanted : 1; 0091 Page *mPage; 0092 NormalizedRect mNormalizedRect; 0093 QAtomicInt mShouldAbortRender; 0094 QImage mResultImage; 0095 }; 0096 0097 class TextRequestPrivate 0098 { 0099 public: 0100 static TextRequestPrivate *get(const TextRequest *req); 0101 0102 Page *mPage; 0103 QAtomicInt mShouldAbortExtraction; 0104 }; 0105 0106 class PixmapGenerationThread : public QThread 0107 { 0108 Q_OBJECT 0109 0110 public: 0111 explicit PixmapGenerationThread(Generator *generator); 0112 0113 void startGeneration(PixmapRequest *request, bool calcBoundingBox); 0114 0115 void endGeneration(); 0116 0117 PixmapRequest *request() const; 0118 0119 QImage image() const; 0120 bool calcBoundingBox() const; 0121 NormalizedRect boundingBox() const; 0122 0123 protected: 0124 void run() override; 0125 0126 private: 0127 Generator *mGenerator; 0128 PixmapRequest *mRequest; 0129 NormalizedRect mBoundingBox; 0130 bool mCalcBoundingBox : 1; 0131 }; 0132 0133 class TextPageGenerationThread : public QThread 0134 { 0135 Q_OBJECT 0136 0137 public: 0138 explicit TextPageGenerationThread(Generator *generator); 0139 0140 void endGeneration(); 0141 0142 void setPage(Page *page); 0143 Page *page() const; 0144 0145 TextPage *textPage() const; 0146 0147 void abortExtraction(); 0148 bool shouldAbortExtraction() const; 0149 0150 public Q_SLOTS: 0151 void startGeneration(); 0152 0153 protected: 0154 void run() override; 0155 0156 private: 0157 Generator *mGenerator; 0158 TextPage *mTextPage; 0159 TextRequest mTextRequest; 0160 }; 0161 0162 class FontExtractionThread : public QThread 0163 { 0164 Q_OBJECT 0165 0166 public: 0167 FontExtractionThread(Generator *generator, int pages); 0168 0169 void startExtraction(bool async); 0170 void stopExtraction(); 0171 0172 Q_SIGNALS: 0173 void gotFont(const Okular::FontInfo &); 0174 void progress(int page); 0175 0176 protected: 0177 void run() override; 0178 0179 private: 0180 Generator *mGenerator; 0181 int mNumOfPages; 0182 bool mGoOn; 0183 }; 0184 0185 } 0186 0187 Q_DECLARE_METATYPE(Okular::Page *) 0188 0189 #endif