Update to wx 3.1.0 gl attributes, simplify GLFont cache and GC

This commit is contained in:
Charles J. Cliffe 2016-03-22 20:49:15 -04:00
parent 855a6f7f15
commit f4b7baebfa
21 changed files with 51 additions and 83 deletions

View File

@ -55,7 +55,9 @@ AppFrame::AppFrame() :
wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *demodTunerTray = new wxBoxSizer(wxHORIZONTAL);
int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
wxGLAttributes attribList;
attribList.PlatformDefaults().RGBA().DoubleBuffer().EndList();
mainSplitter = new wxSplitterWindow( this, wxID_MAIN_SPLITTER, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH | wxSP_LIVE_UPDATE );
mainSplitter->SetSashGravity(10.0/37.0);

View File

@ -24,8 +24,8 @@ EVT_LEAVE_WINDOW(UITestCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(UITestCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
UITestCanvas::UITestCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList) {
UITestCanvas::UITestCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs) {
glContext = new UITestContext(this, &wxGetApp().GetContext(this));
}

View File

@ -14,7 +14,7 @@
class UITestCanvas: public InteractiveCanvas {
public:
UITestCanvas(wxWindow *parent, int *attribList = NULL);
UITestCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~UITestCanvas();
private:

View File

@ -452,30 +452,24 @@ void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, A
GLFontStringCache *fc = nullptr;
std::map<int, std::map<int, std::map<int, std::map<std::string, GLFontStringCache * > > > >::iterator i1;
std::map<int, std::map<int, std::map<std::string, GLFontStringCache * > > >::iterator i2;
std::map<int, std::map<std::string, GLFontStringCache * > >::iterator i3;
std::map<std::string, GLFontStringCache * >::iterator i4;
std::map<std::string, GLFontStringCache * >::iterator cache_iter;
i1 = stringCache.find(vpx);
if (i1 != stringCache.end()) {
i2 = i1->second.find(vpy);
if (i2 != i1->second.end()) {
i3 = i2->second.find(pxHeight);
if (i3 != i2->second.end()) {
i4 = i3->second.find(str);
if (i4 != i3->second.end()) {
fc = i4->second;
fc->gc = 0;
}
}
}
std::stringstream sscacheIdx;
sscacheIdx << vpx << "." << vpy << "." << pxHeight << "." << str;
std::string cacheIdx(sscacheIdx.str());
cache_iter = stringCache.find(cacheIdx);
if (cache_iter != stringCache.end()) {
fc = cache_iter->second;
fc->gc = 0;
}
if (fc == nullptr) {
// std::cout << "cache miss" << std::endl;
fc = cacheString(str, pxHeight, vpx, vpy);
stringCache[vpx][vpy][pxHeight][str] = fc;
stringCache[cacheIdx] = fc;
}
drawCacheString(fc, xpos, ypos, hAlign, vAlign);
@ -680,43 +674,14 @@ GLFontStringCache *GLFont::cacheString(std::string str, int pxHeight, int vpx, i
}
void GLFont::doCacheGC() {
std::map<int, std::map<int, std::map<int, std::map<std::string, GLFontStringCache * > > > >::iterator i1;
std::map<int, std::map<int, std::map<std::string, GLFontStringCache * > > >::iterator i2;
std::map<int, std::map<std::string, GLFontStringCache * > >::iterator i3;
std::map<std::string, GLFontStringCache * >::iterator i4;
std::map<std::string, GLFontStringCache * >::iterator cache_iter;
std::vector<std::map<std::string, GLFontStringCache * >::iterator> removals;
std::vector<std::map<std::string, GLFontStringCache * >::iterator>::iterator removals_i;
for (i1 = stringCache.begin(); i1 != stringCache.end(); i1++) {
for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) {
for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) {
for (i4 = i3->second.begin(); i4 != i3->second.end(); i4++) {
i4->second->gc--;
if (i4->second->gc < -10) {
removals.push_back(i4);
}
}
}
}
}
if (removals.size()) {
for (removals_i = removals.begin(); removals_i != removals.end(); removals_i++) {
// std::cout << "gc'd " << (*removals_i)->first << std::endl;
GLFontStringCache *fc = (*removals_i)->second;
stringCache[fc->vpx][fc->vpy][fc->pxHeight].erase(*removals_i);
delete (*removals_i)->second;
if (!stringCache[fc->vpx][fc->vpy][fc->pxHeight].size()) {
stringCache[fc->vpx][fc->vpy].erase(stringCache[fc->vpx][fc->vpy].find(fc->pxHeight));
if (!stringCache[fc->vpx][fc->vpy].size()) {
stringCache[fc->vpx].erase(stringCache[fc->vpx].find(fc->vpy));
if (!stringCache[fc->vpx].size()) {
stringCache.erase(stringCache.find(fc->vpx));
}
}
}
for (cache_iter = stringCache.begin(); cache_iter != stringCache.end(); cache_iter++) {
cache_iter->second->gc--;
if (cache_iter->second->gc < -10) {
// std::cout << "gc'd " << cache_iter->first << std::endl;
stringCache.erase(cache_iter);
return;
}
}
}

View File

@ -4,6 +4,7 @@
#include <string>
#include <sstream>
#include <mutex>
#include <atomic>
#include "lodepng.h"
#include "wx/glcanvas.h"
#include "wx/filename.h"
@ -16,7 +17,7 @@ public:
int vpx, vpy;
int pxHeight;
float msgWidth;
int gc;
std::atomic_int gc;
std::vector<float> gl_vertices;
std::vector<float> gl_uv;
};
@ -89,7 +90,7 @@ public:
void doCacheGC();
private:
std::map<int, std::map<int, std::map<int, std::map<std::string, GLFontStringCache * > > > > stringCache;
std::map<std::string, GLFontStringCache * > stringCache;
std::string nextParam(std::istringstream &str);
std::string getParamKey(std::string param_str);

View File

@ -24,8 +24,8 @@ EVT_LEAVE_WINDOW(GainCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(GainCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
GainCanvas::GainCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList) {
GainCanvas::GainCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs) {
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
bgPanel.setCoordinateSystem(GLPanel::GLPANEL_Y_UP);

View File

@ -27,7 +27,7 @@ public:
class GainCanvas: public InteractiveCanvas {
public:
GainCanvas(wxWindow *parent, int *attribList = NULL);
GainCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~GainCanvas();
void setHelpTip(std::string tip);

View File

@ -17,8 +17,8 @@
#include <wx/numformatter.h>
InteractiveCanvas::InteractiveCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
InteractiveCanvas::InteractiveCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
wxGLCanvas(parent, dispAttrs ,wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), parent(parent), shiftDown(false), altDown(false), ctrlDown(false), centerFreq(0), bandwidth(0), lastBandwidth(0), isView(
false) {
mouseTracker.setTarget(this);

View File

@ -8,7 +8,7 @@
class InteractiveCanvas: public wxGLCanvas {
public:
InteractiveCanvas(wxWindow *parent, int *attribList = NULL);
InteractiveCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~InteractiveCanvas();
long long getFrequencyAt(float x);

View File

@ -27,8 +27,8 @@ EVT_LEAVE_WINDOW(MeterCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(MeterCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
MeterCanvas::MeterCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), level(0), level_min(0), level_max(1), inputValue(0), userInputValue(0), showUserInput(true) {
MeterCanvas::MeterCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs), level(0), level_min(0), level_max(1), inputValue(0), userInputValue(0), showUserInput(true) {
glContext = new MeterContext(this, &wxGetApp().GetContext(this));
}

View File

@ -14,7 +14,7 @@
class MeterCanvas: public InteractiveCanvas {
public:
MeterCanvas(wxWindow *parent, int *attribList = NULL);
MeterCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~MeterCanvas();
void setLevel(float level_in);

View File

@ -24,8 +24,8 @@ EVT_LEAVE_WINDOW(ModeSelectorCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(ModeSelectorCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
ModeSelectorCanvas::ModeSelectorCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), numChoices(0), currentSelection(-1), toggleMode(false), inputChanged(false), padX(4.0), padY(4.0), highlightOverride(false) {
ModeSelectorCanvas::ModeSelectorCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs), numChoices(0), currentSelection(-1), toggleMode(false), inputChanged(false), padX(4.0), padY(4.0), highlightOverride(false) {
glContext = new ModeSelectorContext(this, &wxGetApp().GetContext(this));

View File

@ -24,7 +24,7 @@ public:
class ModeSelectorCanvas: public InteractiveCanvas {
public:
ModeSelectorCanvas(wxWindow *parent, int *attribList = NULL);
ModeSelectorCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~ModeSelectorCanvas();
int getHoveredSelection();

View File

@ -28,7 +28,7 @@ EVT_LEAVE_WINDOW(ScopeCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(ScopeCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) : InteractiveCanvas(parent, attribList), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0), helpTip("") {
ScopeCanvas::ScopeCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) : InteractiveCanvas(parent, dispAttrs), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0), helpTip("") {
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
inputData.set_max_num_items(2);

View File

@ -14,7 +14,7 @@
class ScopeCanvas: public InteractiveCanvas {
public:
ScopeCanvas(wxWindow *parent, int *attribList = NULL);
ScopeCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~ScopeCanvas();
void setDeviceName(std::string device_name);

View File

@ -29,8 +29,8 @@ EVT_RIGHT_DOWN(SpectrumCanvas::OnMouseRightDown)
EVT_RIGHT_UP(SpectrumCanvas::OnMouseRightReleased)
wxEND_EVENT_TABLE()
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), waterfallCanvas(NULL) {
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs), waterfallCanvas(NULL) {
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));

View File

@ -13,7 +13,7 @@ class WaterfallCanvas;
class SpectrumCanvas: public InteractiveCanvas {
public:
SpectrumCanvas(wxWindow *parent, int *attribList = NULL);
SpectrumCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~SpectrumCanvas();
void attachWaterfallCanvas(WaterfallCanvas *canvas_in);

View File

@ -30,8 +30,8 @@ EVT_MOUSEWHEEL(TuningCanvas::OnMouseWheelMoved)
//EVT_KEY_UP(TuningCanvas::OnKeyUp)
wxEND_EVENT_TABLE()
TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragAccum(0), uxDown(0), top(false), bottom(false), freq(-1), bw(-1), center(-1), halfBand(false) {
TuningCanvas::TuningCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs), dragAccum(0), uxDown(0), top(false), bottom(false), freq(-1), bw(-1), center(-1), halfBand(false) {
glContext = new TuningContext(this, &wxGetApp().GetContext(this));

View File

@ -17,7 +17,7 @@ public:
enum ActiveState {
TUNING_HOVER_NONE, TUNING_HOVER_FREQ, TUNING_HOVER_BW, TUNING_HOVER_PPM, TUNING_HOVER_CENTER
};
TuningCanvas(wxWindow *parent, int *attribList = NULL);
TuningCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
~TuningCanvas();
void setHelpTip(std::string tip);

View File

@ -34,8 +34,8 @@ EVT_ENTER_WINDOW(WaterfallCanvas::OnMouseEnterWindow)
EVT_MOUSEWHEEL(WaterfallCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), new_fft_size(0), waterfall_lines(0),
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs) :
InteractiveCanvas(parent, dispAttrs), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), new_fft_size(0), waterfall_lines(0),
dragOfs(0), mouseZoom(1), zoom(1), freqMoving(false), freqMove(0.0), hoverAlpha(1.0) {
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));

View File

@ -18,7 +18,7 @@ public:
WF_DRAG_NONE, WF_DRAG_BANDWIDTH_LEFT, WF_DRAG_BANDWIDTH_RIGHT, WF_DRAG_FREQUENCY, WF_DRAG_RANGE
};
WaterfallCanvas(wxWindow *parent, int *attribList = NULL);
WaterfallCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs);
void setup(unsigned int fft_size_in, int waterfall_lines_in);
void setFFTSize(unsigned int fft_size_in);
~WaterfallCanvas();