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
30const wxEventType wxEVT_OCPN_COMPRESSIONTHREAD = wxNewEventType();
31
32class JobTicket;
33class wxGenericProgressDialog;
34
35WX_DECLARE_LIST(JobTicket, JobList);
36
38WX_DECLARE_LIST(ProgressInfoItem, ProgressInfoList);
39
41public:
44
45 wxString file_path;
46 wxString msgx;
47};
48
49class CompressionPoolThread : public wxThread {
50public:
51 CompressionPoolThread(JobTicket *ticket, wxEvtHandler *message_target);
52 void *Entry();
53
54 wxEvtHandler *m_pMessageTarget;
55 JobTicket *m_ticket;
56};
57
58class OCPN_CompressionThreadEvent : public wxEvent {
59public:
60 OCPN_CompressionThreadEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
62
63 // accessors
64 void SetTicket(JobTicket *ticket) { m_ticket = ticket; }
65 JobTicket *GetTicket(void) { return m_ticket; }
66
67 // required for sending with wxPostEvent()
68 wxEvent *Clone() const;
69
70 int type;
71 int nstat;
72 int nstat_max;
73
74private:
75 JobTicket *m_ticket;
76};
77
79class JobTicket {
80public:
81 JobTicket();
82 ~JobTicket() { free(level0_bits); }
83 bool DoJob();
84 bool DoJob(const wxRect &rect);
85
86 glTexFactory *pFact;
87 wxRect m_rect;
88 int level_min_request;
89 int ident;
90 bool b_throttle;
91
92 CompressionPoolThread *pthread;
93 unsigned char *level0_bits;
94 unsigned char *comp_bits_array[10];
95 wxString m_ChartPath;
96 bool b_abort;
97 bool b_isaborted;
98 bool bpost_zip_compress;
99 bool binplace;
100 unsigned char *compcomp_bits_array[10];
101 int compcomp_size_array[10];
102 bool b_inCompressAll;
103};
104
105// This is a hashmap with Chart full path as key, and glTexFactory as value
106WX_DECLARE_STRING_HASH_MAP(glTexFactory *, ChartPathHashTexfactType);
107
108// glTextureManager Definition
109class glTextureManager : public wxEvtHandler {
110public:
113
114 void OnEvtThread(OCPN_CompressionThreadEvent &event);
115 void OnTimer(wxTimerEvent &event);
116 bool ScheduleJob(glTexFactory *client, const wxRect &rect, int level_min,
117 bool b_throttle_thread, bool b_nolimit, bool b_postZip,
118 bool b_inplace);
119
120 int GetRunningJobCount() { return running_list.GetCount(); }
121 int GetJobCount() { return GetRunningJobCount() + todo_list.GetCount(); }
122 bool AsJob(wxString const &chart_path) const;
123 void PurgeJobList(wxString chart_path = wxEmptyString);
124 void ClearJobList();
125 void ClearAllRasterTextures(void);
126 bool PurgeChartTextures(ChartBase *pc, bool b_purge_factory = false);
127 bool TextureCrunch(double factor);
128 bool FactoryCrunch(double factor);
129 void BuildCompressedCache();
130
131 // This is a hash table
132 // key is Chart full path
133 // Value is glTexFactory*
134 ChartPathHashTexfactType m_chart_texfactory_hash;
135
136private:
137 bool DoJob(JobTicket *pticket);
138 bool DoThreadJob(JobTicket *pticket);
139 bool StartTopJob();
140
141 JobList running_list;
142 JobList todo_list;
143 int m_max_jobs;
144
145 int m_prevMemUsed;
146
147 wxTimer m_timer;
148 size_t m_ticks;
149 wxGenericProgressDialog *m_progDialog;
150 wxString m_progMsg;
151 unsigned int m_jcnt;
152 ProgressInfoList progList;
153 bool m_skip;
154 bool m_skipout;
155 bool m_bcompact;
156};
157
159void GetFullMap(glTextureDescriptor *ptd, const wxRect &rect,
160 wxString chart_path, int level);
161int TextureDim(int level);
162int TextureTileSize(int level, bool compressed);
163
164#endif