make beginDraw return a boolean so can abort

When a gtk3 window's shutting down it appears we can't get a cairo_t*
for it. This change makes it possible to turn that fact into aborting
the whole draw operation.
This commit is contained in:
Eric House 2016-08-04 15:12:05 -07:00
parent 3c7af0023e
commit df6c1e0d3a
5 changed files with 46 additions and 32 deletions

View file

@ -349,7 +349,7 @@ and_draw_drawTimer( DrawCtx* dctx, const XP_Rect* rect, XP_U16 player,
} }
/* Not used on android yet */ /* Not used on android yet */
static void and_draw_beginDraw( DrawCtx* XP_UNUSED(dctx) ) {} static XP_Bool and_draw_beginDraw( DrawCtx* XP_UNUSED(dctx) ) {return XP_TRUE;}
static void and_draw_endDraw( DrawCtx* XP_UNUSED(dctx) ) {} static void and_draw_endDraw( DrawCtx* XP_UNUSED(dctx) ) {}
static XP_Bool static XP_Bool

View file

@ -624,7 +624,7 @@ XP_Bool
board_draw( BoardCtxt* board ) board_draw( BoardCtxt* board )
{ {
if ( !!board->draw && board->boardBounds.width > 0 ) { if ( !!board->draw && board->boardBounds.width > 0 ) {
draw_beginDraw( board->draw ); if ( draw_beginDraw( board->draw ) ) {
drawScoreBoard( board ); drawScoreBoard( board );
drawTray( board ); drawTray( board );
@ -632,6 +632,7 @@ board_draw( BoardCtxt* board )
draw_endDraw( board->draw ); draw_endDraw( board->draw );
} }
}
return !board->needsDrawing && 0 == board->trayInvalBits; return !board->needsDrawing && 0 == board->trayInvalBits;
} /* board_draw */ } /* board_draw */

View file

@ -116,7 +116,7 @@ typedef struct DrawCtxVTable {
void DRAW_VTABLE_NAME(dictChanged)( DrawCtx* dctx, XP_S16 playerNum, void DRAW_VTABLE_NAME(dictChanged)( DrawCtx* dctx, XP_S16 playerNum,
const DictionaryCtxt* dict ); const DictionaryCtxt* dict );
void DRAW_VTABLE_NAME(beginDraw) ( DrawCtx* dctx ); XP_Bool DRAW_VTABLE_NAME(beginDraw) ( DrawCtx* dctx );
void DRAW_VTABLE_NAME(endDraw) ( DrawCtx* dctx ); void DRAW_VTABLE_NAME(endDraw) ( DrawCtx* dctx );
XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx, XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx,

View file

@ -78,6 +78,12 @@ curses_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
{ {
} }
static XP_Bool
curses_draw_beginDraw( DrawCtx* XP_UNUSED(p_dctx) )
{
return XP_TRUE;
}
static XP_Bool static XP_Bool
curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx), curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx),
const XP_Rect* XP_UNUSED(rect), const XP_Rect* XP_UNUSED(rect),
@ -582,6 +588,7 @@ curses_draw_frameTray( DrawCtx* p_dctx, XP_Rect* rect )
static XP_Bool static XP_Bool
draw_doNothing( DrawCtx* XP_UNUSED(dctx), ... ) draw_doNothing( DrawCtx* XP_UNUSED(dctx), ... )
{ {
LOG_FUNC();
return XP_FALSE; return XP_FALSE;
} /* draw_doNothing */ } /* draw_doNothing */
@ -593,7 +600,7 @@ cursesDrawCtxtMake( WINDOW* boardWin )
dctx->vtable = malloc( sizeof(*(((CursesDrawCtx*)dctx)->vtable)) ); dctx->vtable = malloc( sizeof(*(((CursesDrawCtx*)dctx)->vtable)) );
for ( int ii = 0; for ( int ii = 0;
ii < sizeof(*dctx->vtable)/sizeof(draw_doNothing); ii < sizeof(*dctx->vtable)/sizeof(dctx->vtable->m_draw_destroyCtxt);
++ii ) { ++ii ) {
((void**)(dctx->vtable))[ii] = draw_doNothing; ((void**)(dctx->vtable))[ii] = draw_doNothing;
} }
@ -601,10 +608,11 @@ cursesDrawCtxtMake( WINDOW* boardWin )
SET_VTABLE_ENTRY( dctx->vtable, draw_destroyCtxt, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_destroyCtxt, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_dictChanged, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_dictChanged, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_beginDraw, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_boardBegin, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_boardBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_trayBegin, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_trayBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_scoreBegin, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_scoreBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, curses );
#ifdef XWFEATURE_SCOREONEPASS #ifdef XWFEATURE_SCOREONEPASS
SET_VTABLE_ENTRY( dctx->vtable, draw_drawRemText, curses ); SET_VTABLE_ENTRY( dctx->vtable, draw_drawRemText, curses );

View file

@ -82,15 +82,20 @@ gtkInsetRect( XP_Rect* r, short i )
# define GDKCOLORMAP GdkColormap # define GDKCOLORMAP GdkColormap
#endif #endif
static void static XP_Bool
initCairo( GtkDrawCtx* dctx ) initCairo( GtkDrawCtx* dctx )
{ {
/* XP_LOGF( "%s(dctx=%p)", __func__, dctx ); */ /* XP_LOGF( "%s(dctx=%p)", __func__, dctx ); */
XP_ASSERT( !dctx->_cairo ); XP_ASSERT( !dctx->_cairo );
dctx->_cairo = gdk_cairo_create( gtk_widget_get_window(dctx->drawing_area) ); cairo_t* cairo = gdk_cairo_create( gtk_widget_get_window(dctx->drawing_area) );
XP_Bool inited = !!cairo;
if ( inited ) {
dctx->_cairo = cairo;
/* XP_LOGF( "dctx->cairo=%p", dctx->_cairo ); */ /* XP_LOGF( "dctx->cairo=%p", dctx->_cairo ); */
cairo_set_line_width( dctx->_cairo, 1.0 ); cairo_set_line_width( cairo, 1.0 );
cairo_set_line_cap( dctx->_cairo, CAIRO_LINE_CAP_SQUARE ); cairo_set_line_cap( cairo, CAIRO_LINE_CAP_SQUARE );
}
return inited;
} }
static void static void
@ -435,12 +440,12 @@ gtk_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
{ {
} }
static void static XP_Bool
gtk_draw_beginDraw( DrawCtx* p_dctx ) gtk_draw_beginDraw( DrawCtx* p_dctx )
{ {
#ifdef USE_CAIRO #ifdef USE_CAIRO
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
initCairo( dctx ); return initCairo( dctx );
#endif #endif
} }
@ -1482,8 +1487,7 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkGameGlobals* globals )
void void
draw_gtk_status( GtkDrawCtx* dctx, char ch ) draw_gtk_status( GtkDrawCtx* dctx, char ch )
{ {
initCairo( dctx ); if ( initCairo( dctx ) ) {
GtkGameGlobals* globals = dctx->globals; GtkGameGlobals* globals = dctx->globals;
XP_Rect rect = { XP_Rect rect = {
@ -1501,6 +1505,7 @@ draw_gtk_status( GtkDrawCtx* dctx, char ch )
destroyCairo( dctx ); destroyCairo( dctx );
} }
}
void void
frame_active_rect( GtkDrawCtx* dctx, const XP_Rect* rect ) frame_active_rect( GtkDrawCtx* dctx, const XP_Rect* rect )