File: glTextureManager.h

package info (click to toggle)
opencpn 5.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 101,540 kB
  • sloc: ansic: 414,598; cpp: 253,008; xml: 83,748; sh: 409; python: 353; makefile: 110; javascript: 87; perl: 83
file content (172 lines) | stat: -rw-r--r-- 5,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/******************************************************************************
 *
 * Project:  OpenCPN
 * Authors:  David Register
 *           Sean D'Epagnier
 *
 ***************************************************************************
 *   Copyright (C) 2016 by David S. Register                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
 ***************************************************************************
 */

#ifndef __GLTEXTUREMANAGER_H__
#define __GLTEXTUREMANAGER_H__

const wxEventType wxEVT_OCPN_COMPRESSIONTHREAD = wxNewEventType();

class JobTicket;
class wxGenericProgressDialog;

WX_DECLARE_LIST(JobTicket, JobList);

class ProgressInfoItem;
WX_DECLARE_LIST(ProgressInfoItem, ProgressInfoList);

class ProgressInfoItem
{
public:
    ProgressInfoItem(){};
    ~ProgressInfoItem(){};
    
    wxString file_path;
    wxString msgx;
};



class CompressionPoolThread : public wxThread
{
public:
    CompressionPoolThread(JobTicket *ticket, wxEvtHandler *message_target);
    void *Entry();
    
    wxEvtHandler        *m_pMessageTarget;
    JobTicket           *m_ticket;
};



class OCPN_CompressionThreadEvent: public wxEvent
{
public:
    OCPN_CompressionThreadEvent( wxEventType commandType = wxEVT_NULL, int id = 0 );
    ~OCPN_CompressionThreadEvent( );
    
    // accessors
    void SetTicket( JobTicket *ticket ){m_ticket = ticket;}
    JobTicket *GetTicket(void){ return m_ticket; }
    
    // required for sending with wxPostEvent()
    wxEvent *Clone() const;

    int        type;
    int        nstat;
    int        nstat_max;
    
private:
    JobTicket  * m_ticket;
};

class CompressionPoolThread;
class JobTicket
{
public:
    JobTicket();
    ~JobTicket() { free(level0_bits); }
    bool DoJob();
    bool DoJob(const wxRect &rect);
    
    glTexFactory *pFact;
    wxRect      m_rect;
    int         level_min_request;
    int         ident;
    bool        b_throttle;
    
    CompressionPoolThread *pthread;
    unsigned char *level0_bits;
    unsigned char *comp_bits_array[10];
    wxString    m_ChartPath;
    bool        b_abort;
    bool        b_isaborted;
    bool        bpost_zip_compress;
    bool        binplace;
    unsigned char *compcomp_bits_array[10];
    int         compcomp_size_array[10];
    bool        b_inCompressAll;
};


//      This is a hashmap with Chart full path as key, and glTexFactory as value
WX_DECLARE_STRING_HASH_MAP( glTexFactory*, ChartPathHashTexfactType );

//      glTextureManager Definition
class glTextureManager : public wxEvtHandler
{
public:
    glTextureManager();
    ~glTextureManager();

    void OnEvtThread( OCPN_CompressionThreadEvent & event );
    void OnTimer(wxTimerEvent &event);
    bool ScheduleJob( glTexFactory *client, const wxRect &rect, int level_min,
                      bool b_throttle_thread, bool b_nolimit, bool b_postZip, bool b_inplace);

    int GetRunningJobCount(){ return running_list.GetCount(); }
    int GetJobCount(){ return GetRunningJobCount() + todo_list.GetCount(); }
    bool AsJob( wxString const &chart_path ) const;
    void PurgeJobList( wxString chart_path = wxEmptyString );
    void ClearJobList();
    void ClearAllRasterTextures(void);
    bool PurgeChartTextures(ChartBase *pc, bool b_purge_factory = false);
    bool TextureCrunch(double factor);
    bool FactoryCrunch(double factor);
    void BuildCompressedCache();
    
    //    This is a hash table
    //    key is Chart full path
    //    Value is glTexFactory*
    ChartPathHashTexfactType   m_chart_texfactory_hash;

private:    
    bool DoJob( JobTicket *pticket );
    bool DoThreadJob(JobTicket* pticket);
    bool StartTopJob();
    
    JobList             running_list;
    JobList             todo_list;
    int                 m_max_jobs;

    int		m_prevMemUsed;

    wxTimer     m_timer;
    size_t      m_ticks;
    wxGenericProgressDialog *m_progDialog;
    wxString    m_progMsg;
    unsigned int  m_jcnt;
    ProgressInfoList    progList;
    bool        m_skip;
    bool        m_skipout;
    bool        m_bcompact;
};

class glTextureDescriptor;
void GetFullMap( glTextureDescriptor *ptd,  const wxRect &rect, wxString chart_path, int level);
int TextureDim(int level);
int TextureTileSize(int level, bool compressed);

#endif