OpenCPN Partial API docs
Loading...
Searching...
No Matches
glTextureManager.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Authors: David Register
5 * Sean D'Epagnier
6 *
7 ***************************************************************************
8 * Copyright (C) 2016 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25 */
26
27#ifndef __GLTEXTUREMANAGER_H__
28#define __GLTEXTUREMANAGER_H__
29
30#include <list>
31
32#include <wx/event.h>
33#include <wx/string.h>
34#include <wx/thread.h>
35#include <wx/timer.h>
36
37const wxEventType wxEVT_OCPN_COMPRESSIONTHREAD = wxNewEventType();
38
39class JobTicket;
40class wxGenericProgressDialog;
41
43using ProgressInfoList = std::list<ProgressInfoItem *>;
44
46public:
49
50 wxString file_path;
51 wxString msgx;
52};
53
54class CompressionPoolThread : public wxThread {
55public:
56 CompressionPoolThread(JobTicket *ticket, wxEvtHandler *message_target);
57 void *Entry();
58
59 wxEvtHandler *m_pMessageTarget;
60 JobTicket *m_ticket;
61};
62
63class OCPN_CompressionThreadEvent : public wxEvent {
64public:
65 OCPN_CompressionThreadEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
67
68 // accessors
69 void SetTicket(JobTicket *ticket) { m_ticket = ticket; }
70 JobTicket *GetTicket(void) { return m_ticket; }
71
72 // required for sending with wxPostEvent()
73 wxEvent *Clone() const;
74
75 int type;
76 int nstat;
77 int nstat_max;
78
79private:
80 JobTicket *m_ticket;
81};
82
84class JobTicket {
85public:
86 JobTicket();
87 ~JobTicket() { free(level0_bits); }
88 bool DoJob();
89 bool DoJob(const wxRect &rect);
90
91 glTexFactory *pFact;
92 wxRect m_rect;
93 int level_min_request;
94 int ident;
95 bool b_throttle;
96
97 CompressionPoolThread *pthread;
98 unsigned char *level0_bits;
99 unsigned char *comp_bits_array[10];
100 wxString m_ChartPath;
101 bool b_abort;
102 bool b_isaborted;
103 bool bpost_zip_compress;
104 bool binplace;
105 unsigned char *compcomp_bits_array[10];
106 int compcomp_size_array[10];
107 bool b_inCompressAll;
108};
109
110// This is a hashmap with Chart full path as key, and glTexFactory as value
111WX_DECLARE_STRING_HASH_MAP(glTexFactory *, ChartPathHashTexfactType);
112
113// glTextureManager Definition
114class glTextureManager : public wxEvtHandler {
115public:
118
119 void OnEvtThread(OCPN_CompressionThreadEvent &event);
120 void OnTimer(wxTimerEvent &event);
121 bool ScheduleJob(glTexFactory *client, const wxRect &rect, int level_min,
122 bool b_throttle_thread, bool b_nolimit, bool b_postZip,
123 bool b_inplace);
124
125 int GetRunningJobCount() { return running_list.size(); }
126 int GetJobCount() { return GetRunningJobCount() + todo_list.size(); }
127 bool AsJob(wxString const &chart_path) const;
128 void PurgeJobList(wxString chart_path = wxEmptyString);
129 void ClearJobList();
130 void ClearAllRasterTextures(void);
131 bool PurgeChartTextures(ChartBase *pc, bool b_purge_factory = false);
132 bool TextureCrunch(double factor);
133 bool FactoryCrunch(double factor);
134 void BuildCompressedCache();
135
136 // This is a hash table
137 // key is Chart full path
138 // Value is glTexFactory*
139 ChartPathHashTexfactType m_chart_texfactory_hash;
140
141private:
142 bool DoJob(JobTicket *pticket);
143 bool DoThreadJob(JobTicket *pticket);
144 bool StartTopJob();
145
146 std::list<JobTicket *> running_list;
147 std::list<JobTicket *> todo_list;
148 int m_max_jobs;
149
150 int m_prevMemUsed;
151
152 wxTimer m_timer;
153 size_t m_ticks;
154 wxGenericProgressDialog *m_progDialog;
155 wxString m_progMsg;
156 unsigned int m_jcnt;
157 ProgressInfoList progList;
158 bool m_skip;
159 bool m_skipout;
160 bool m_bcompact;
161};
162
164void GetFullMap(glTextureDescriptor *ptd, const wxRect &rect,
165 wxString chart_path, int level);
166int TextureDim(int level);
167int TextureTileSize(int level, bool compressed);
168
169#endif
Base class for all chart types.
Definition chartbase.h:125