OpenCPN Partial API docs
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 const wxEventType wxEVT_OCPN_COMPRESSIONTHREAD = wxNewEventType();
31 
32 class JobTicket;
33 class wxGenericProgressDialog;
34 
35 WX_DECLARE_LIST(JobTicket, JobList);
36 
37 class ProgressInfoItem;
38 WX_DECLARE_LIST(ProgressInfoItem, ProgressInfoList);
39 
41 public:
42  ProgressInfoItem(){};
43  ~ProgressInfoItem(){};
44 
45  wxString file_path;
46  wxString msgx;
47 };
48 
49 class CompressionPoolThread : public wxThread {
50 public:
51  CompressionPoolThread(JobTicket *ticket, wxEvtHandler *message_target);
52  void *Entry();
53 
54  wxEvtHandler *m_pMessageTarget;
55  JobTicket *m_ticket;
56 };
57 
58 class OCPN_CompressionThreadEvent : public wxEvent {
59 public:
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 
74 private:
75  JobTicket *m_ticket;
76 };
77 
79 class JobTicket {
80 public:
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
106 WX_DECLARE_STRING_HASH_MAP(glTexFactory *, ChartPathHashTexfactType);
107 
108 // glTextureManager Definition
109 class glTextureManager : public wxEvtHandler {
110 public:
112  ~glTextureManager();
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 
136 private:
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 
158 class glTextureDescriptor;
159 void GetFullMap(glTextureDescriptor *ptd, const wxRect &rect,
160  wxString chart_path, int level);
161 int TextureDim(int level);
162 int TextureTileSize(int level, bool compressed);
163 
164 #endif