Skip to content

Commit

Permalink
libgui: Improved window refresh and GUI app event loop
Browse files Browse the repository at this point in the history
Window refresh is now the primary trigger for GUI app event loop
iteration. The event loop uses a timer for low-frequency non-visual
updates.

GLWindow keeps refreshing itself as quickly as possible.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent abdb215 commit d49d1fb
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 228 deletions.
6 changes: 3 additions & 3 deletions doomsday/libs/appfw/include/de/framework/basewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class LIBAPPFW_PUBLIC BaseWindow : public LIBAPPFW_BASEWINDOW_SUPER
/**
* Request drawing the contents of the window as soon as possible.
*/
virtual void requestDraw();
// virtual void requestDraw();

void draw() override;

Expand All @@ -93,14 +93,14 @@ class LIBAPPFW_PUBLIC BaseWindow : public LIBAPPFW_BASEWINDOW_SUPER
#endif

protected:
/**
/*
* Called when a draw request has been received. This method should carry out any
* preparations necessary before the frame can be drawn. It can also cancel the
* frame is needed.
*
* @return @c true to continue drawing the frame, @c false to abort the frame.
*/
virtual bool prepareForDraw();
// virtual bool prepareForDraw();

virtual void preDraw();
virtual void postDraw();
Expand Down
32 changes: 15 additions & 17 deletions doomsday/libs/appfw/src/basewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ WindowTransform &BaseWindow::transform()
return *d->xf;
}

#if 0
bool BaseWindow::prepareForDraw()
{
if (isGLReady())
Expand All @@ -144,23 +145,8 @@ void BaseWindow::requestDraw()
// Not right now, please.
return;
}

// Initialize Oculus Rift if needed.
auto &vr = DE_BASE_GUI_APP->vr();
if (vr.mode() == VRConfig::OculusRift)
{
if (isGLReady())
{
makeCurrent();
vr.oculusRift().init();
}
}
else
{
makeCurrent();
vr.oculusRift().deinit();
}
}
#endif

void BaseWindow::draw()
{
Expand All @@ -172,9 +158,21 @@ void BaseWindow::draw()
void BaseWindow::preDraw()
{
auto &vr = DE_BASE_GUI_APP->vr();

// Initialize Oculus Rift if needed.
if (vr.mode() == VRConfig::OculusRift)
{
vr.oculusRift().beginFrame();
if (isGLReady())
{
makeCurrent();
vr.oculusRift().init();
vr.oculusRift().beginFrame();
}
}
else
{
makeCurrent();
vr.oculusRift().deinit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/appfw/src/guirootwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void GuiRootWidget::update()
}

// Request a window draw so that the updated content becomes visible.
window().as<BaseWindow>().requestDraw();
// window().as<BaseWindow>().requestDraw();
}

void GuiRootWidget::draw()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/gui/include/de/gui/glwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class LIBGUI_PUBLIC GLWindow : public Asset
*/
bool ownsEventHandler(WindowEventHandler *handler) const;

void checkNativeEvents();

enum GrabMode { GrabNormal, GrabHalfSized };

/**
Expand Down Expand Up @@ -210,8 +212,6 @@ class LIBGUI_PUBLIC GLWindow : public Asset

virtual void draw() = 0;

void handleSDLEvent(const void *);

public:
static bool mainExists();
static GLWindow &main();
Expand Down
4 changes: 0 additions & 4 deletions doomsday/libs/gui/include/de/gui/guiapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class Thread;
* @ingroup gui
*/
class LIBGUI_PUBLIC GuiApp : public App
, DE_OBSERVES(Loop, Iteration)
{
public:
enum MouseCursor { None, Arrow, ResizeHorizontal, ResizeVertical };
Expand Down Expand Up @@ -103,9 +102,6 @@ class LIBGUI_PUBLIC GuiApp : public App
protected:
NativePath appDataPath() const override;

// Observes Loop iteration.
void loopIteration() override;

private:
DE_PRIVATE(d)
};
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gui/include/de/gui/guiloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace de {
class GLWindow;

/**
* Continually triggered loop that activates a window when triggering iterations.
* Loop that gets triggered after each time GLWindow contents have been refreshed.
*/
class GuiLoop : public Loop
{
Expand Down
Loading

0 comments on commit d49d1fb

Please sign in to comment.