aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Barker <jesse.barker@linaro.org>2012-12-17 11:11:54 -0800
committerJesse Barker <jesse.barker@linaro.org>2012-12-17 11:11:54 -0800
commit002f81e3db992c8edd41436cc7010e1c58abc0ef (patch)
tree14392ee1c07eb49bab3f2bb10af14f3b58527708
parentfadb8f7d792d49b900b0397903ab67140e72f209 (diff)
downloadglmark2-002f81e3db992c8edd41436cc7010e1c58abc0ef.tar.gz
CanvasDRM: Fix handling of Ctrl-C. Because the Ctrl-C was being handled by
CanvasDRM directly, DRMState had no knowledge of the event, and wasn't able to detect it properly when select() came back with an error. Move the quit handler into DRMState, and give it a public should_quit() method that CanvasDRM can call. This is better encapsulation, and allows DRMState to properly detect the user interrupt and release the GBM resources so the console isn't hung when the application exits.
-rw-r--r--src/canvas-drm.cpp35
-rw-r--r--src/canvas-drm.h6
2 files changed, 27 insertions, 14 deletions
diff --git a/src/canvas-drm.cpp b/src/canvas-drm.cpp
index f24d315..e3a81f7 100644
--- a/src/canvas-drm.cpp
+++ b/src/canvas-drm.cpp
@@ -223,6 +223,8 @@ DRMState::init()
return false;
}
+ signal(SIGINT, &DRMState::quit_handler);
+
return true;
}
@@ -246,6 +248,15 @@ DRMState::reset()
return true;
}
+
+bool DRMState::should_quit_ = false;
+
+void
+DRMState::quit_handler(int signo)
+{
+ Log::debug("Got SIGINT (%d).\n", signo);
+ should_quit_ = true;
+}
void
DRMState::page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void* data)
{
@@ -282,7 +293,15 @@ DRMState::do_flip()
while (waiting) {
status = select(fd_ + 1, &fds, 0, 0, 0);
if (status < 0) {
- Log::error("Error in select: %d\n", status);
+ // Most of the time, select() will return an error because the
+ // user pressed Ctrl-C. So, only print out a message in debug
+ // mode, and just check for the likely condition and release
+ // the current buffer object before getting out.
+ Log::debug("Error in select\n");
+ if (should_quit()) {
+ gbm_surface_release_buffer(surface_, bo_);
+ bo_ = next;
+ }
return;
}
else if (status == 0) {
@@ -344,7 +363,9 @@ DRMState::cleanup()
bool
CanvasDRM::init()
{
- signal(SIGINT, &CanvasDRM::quit_handler);
+ Log::info("NOTE: The DRM canvas is still experimental and its behavior\n");
+ Log::info(" is subject to change as GBM and modesetting behavior\n");
+ Log::info(" evolves\n");
if (!drm_.init()) {
Log::error("Failed to initialize the DRM canvas\n");
@@ -460,7 +481,7 @@ CanvasDRM::write_to_file(std::string &filename)
bool
CanvasDRM::should_quit()
{
- return should_quit_;
+ return drm_.should_quit();
}
void
@@ -573,11 +594,3 @@ CanvasDRM::resize_no_viewport(int width, int height)
LibMatrix::Mat4::perspective(60.0, width_ / static_cast<float>(height_),
1.0, 1024.0);
}
-
-bool CanvasDRM::should_quit_ = false;
-
-void
-CanvasDRM::quit_handler(int /* signum */)
-{
- should_quit_ = true;
-}
diff --git a/src/canvas-drm.h b/src/canvas-drm.h
index e5dde15..e355131 100644
--- a/src/canvas-drm.h
+++ b/src/canvas-drm.h
@@ -44,6 +44,8 @@ class DRMState
static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
unsigned int usec, void* data);
static void fb_destroy_callback(gbm_bo* bo, void* data);
+ static void quit_handler(int signum);
+ static bool should_quit_;
DRMFBState* fb_get_from_bo(gbm_bo* bo);
bool init_gbm();
int fd_;
@@ -73,6 +75,7 @@ public:
bool init();
bool reset();
void do_flip();
+ bool should_quit() const { return should_quit_; }
gbm_device* device() const { return dev_; }
gbm_surface* surface() const { return surface_; }
unsigned int mode_width() const
@@ -124,9 +127,6 @@ private:
void resize_no_viewport(int width, int height);
void init_gl_extensions();
-
- static void quit_handler(int signum);
- static bool should_quit_;
};
#endif