Skip to content

Commit

Permalink
out-of-band redraw via the glib idle timer. this should make drawing …
Browse files Browse the repository at this point in the history
…a bit more efficient and safe in mixed-thread environments (=ardour)
  • Loading branch information
sampo.savolainen committed Jan 6, 2010
1 parent a855082 commit 410cc58
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/schmooz_ui.cpp
Expand Up @@ -21,6 +21,7 @@
#include <cassert>
#include <iostream>
#include <list>
#include <set>


// These need to match the indexes in manifest.ttl
Expand Down Expand Up @@ -58,6 +59,9 @@
#define WDGT_THRESH_CONTROL_CLIP_X1 94
#define WDGT_THRESH_CONTROL_CLIP_X2 292

//#define IDENTIFY_THREAD(func) { std::cerr << "Thread at " func "() is: " << pthread_self() << std::endl; }
#define IDENTIFY_THREAD(func) { }

bool
check_cairo_png(cairo_surface_t *s)
{
Expand Down Expand Up @@ -150,6 +154,8 @@ class SchmoozMonoUI
bool button_press_event(GdkEventButton *);
bool button_release_event(GdkEventButton *);

bool draw_queue();

Wdgt::Object *identifyWdgt(GdkEventMotion *);

Wdgt::Object *_hoverWdgt;
Expand All @@ -161,7 +167,8 @@ class SchmoozMonoUI

std::list<Wdgt::Object *> wdgts;


std::set<Wdgt::Object *> redraw_queue;
sigc::connection redraw_timer_connection;
};

SchmoozMonoUI::SchmoozMonoUI(const struct _LV2UI_Descriptor *descriptor,
Expand Down Expand Up @@ -192,6 +199,7 @@ SchmoozMonoUI::SchmoozMonoUI(const struct _LV2UI_Descriptor *descriptor,
_drawingArea.signal_button_press_event().connect ( sigc::mem_fun (*this, &SchmoozMonoUI::button_press_event));
_drawingArea.signal_button_release_event().connect( sigc::mem_fun (*this, &SchmoozMonoUI::button_release_event));


Gdk::EventMask mask = _drawingArea.get_events();

mask |= Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK;
Expand Down Expand Up @@ -287,6 +295,12 @@ SchmoozMonoUI::SchmoozMonoUI(const struct _LV2UI_Descriptor *descriptor,
hover_label ->setPosition(0, 442, 355, 36);
// Set widget for host
*(GtkWidget **)(widget) = GTK_WIDGET(_drawingArea.gobj());

redraw_timer_connection = Glib::signal_timeout().connect( sigc::mem_fun(*this, &SchmoozMonoUI::draw_queue), 50 );
/*
_redrawTimer = Glib::TimeoutSource::create(1);
_redrawTimer->connect( sigc::mem_fun (*this, &SchmoozMonoUI::draw_queue));
*/
}

void
Expand All @@ -299,6 +313,8 @@ SchmoozMonoUI::size_request(Gtk::Requisition *req)
bool
SchmoozMonoUI::motion_notify_event(GdkEventMotion *evt)
{
IDENTIFY_THREAD("motion_notify_event");

if (_dragWdgt != NULL) {
if (_dragWdgt == threshold_control) {
threshold_control->setValueFromHorizontalDrag(_predrag_value, _dragStartX, evt->x);
Expand Down Expand Up @@ -359,6 +375,8 @@ SchmoozMonoUI::motion_notify_event(GdkEventMotion *evt)
bool
SchmoozMonoUI::button_press_event(GdkEventButton *evt)
{
IDENTIFY_THREAD("button_press_event");

//std::cerr << "button press" << std::endl;

_buttonPressWdgt = _hoverWdgt;
Expand All @@ -380,6 +398,8 @@ SchmoozMonoUI::button_press_event(GdkEventButton *evt)
bool
SchmoozMonoUI::button_release_event(GdkEventButton *evt)
{
IDENTIFY_THREAD("button_release_event");

//std::cerr << "button release" << std::endl;

Wdgt::Object *exposeObj = NULL;
Expand Down Expand Up @@ -407,6 +427,25 @@ SchmoozMonoUI::button_release_event(GdkEventButton *evt)
return true;
}

bool
SchmoozMonoUI::draw_queue()
{
IDENTIFY_THREAD("draw_queue");

if (!_ready_to_draw || redraw_queue.empty()) {
return TRUE;
}

// TODO: this is in desperate need of synchronization
for (std::set<Wdgt::Object *>::iterator i = redraw_queue.begin(); i != redraw_queue.end(); ++i)
{
exposeWdgt(*i);
}
redraw_queue.erase( redraw_queue.begin(), redraw_queue.end() );

return TRUE;
}

bool
SchmoozMonoUI::exposeWdgt(Wdgt::Object *obj)
{
Expand Down Expand Up @@ -605,6 +644,7 @@ SchmoozMonoUI::~SchmoozMonoUI()
++i;
}
cairo_surface_destroy(_image_background);
redraw_timer_connection.disconnect();
// TODO: lots'n'lots of unallocation
// cairo, wdgt stuff
}
Expand All @@ -613,6 +653,8 @@ void
SchmoozMonoUI::port_event(uint32_t port_index, uint32_t buffer_size,
uint32_t format, const void *buffer)
{
IDENTIFY_THREAD("port_event");

Wdgt::Object *exposeObj = NULL;
Wdgt::SlidingControl *slider = NULL;

Expand Down Expand Up @@ -698,7 +740,7 @@ SchmoozMonoUI::port_event(uint32_t port_index, uint32_t buffer_size,
}

if (_ready_to_draw && exposeObj != NULL) {
exposeWdgt(exposeObj);
redraw_queue.insert(exposeObj);
}
}

Expand Down

0 comments on commit 410cc58

Please sign in to comment.