Skip to content

Commit

Permalink
Fix GDI return values and other fixes
Browse files Browse the repository at this point in the history
* top level GDI functions return 0 on error and != 0 otherwise but the
  low level functions (16bpp.c, 8bpp.c 32bpp.c) which are called did it
	exactly the other way around. Those were adapted.
* change gdi_InvalidateRegion to BOOL and check calls where appropriate
* integrate comments from pull request
  • Loading branch information
bmiklautz committed Apr 21, 2015
1 parent 515502f commit 2c072d3
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 235 deletions.
112 changes: 61 additions & 51 deletions client/X11/xf_gdi.c

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions client/X11/xf_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
XImage* image;
int width, height;
xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE;

width = bitmap->right - bitmap->left + 1;
height = bitmap->bottom - bitmap->top + 1;
Expand All @@ -127,7 +128,7 @@ BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)

XFree(image);

gdi_InvalidateRegion(xfc->hdc, bitmap->left, bitmap->top, width, height);
ret = gdi_InvalidateRegion(xfc->hdc, bitmap->left, bitmap->top, width, height);

xf_unlock_x11(xfc, FALSE);
return TRUE;
Expand Down Expand Up @@ -451,16 +452,15 @@ BOOL xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height
BOOL xf_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor)
{
xfContext* xfc = (xfContext*) context;
BOOL ret = TRUE;

xf_lock_x11(xfc, FALSE);

if (xfc->drawing == xfc->primary)
{
gdi_InvalidateRegion(xfc->hdc, x, y, width, height);
}
ret = gdi_InvalidateRegion(xfc->hdc, x, y, width, height);

xf_unlock_x11(xfc, FALSE);
return TRUE;
return ret;
}

/* Graphics Module */
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym)
}
#endif /* WITH_XRENDER defined */
#endif /* pinch/zoom/pan simulation */
return TRUE;
return FALSE;
}

BOOL xf_keyboard_set_indicators(rdpContext* context, UINT16 led_flags)
Expand Down
2 changes: 1 addition & 1 deletion include/freerdp/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@

#define IFCALL(_cb, ...) do { if (_cb != NULL) { _cb( __VA_ARGS__ ); } } while (0)
#define IFCALLRET(_cb, _ret, ...) do { if (_cb != NULL) { _ret = _cb( __VA_ARGS__ ); } } while (0)
#define IFCALLRETURN(_default_return, _cb, ...) do { if (_cb != NULL) { return _cb( __VA_ARGS__ ); } else { return _default_return;} } while (0)
#define IFCALLRESULT(_default_return, _cb, ...) (_cb != NULL) ? _cb( __VA_ARGS__ ) : (_default_return)

#endif /* FREERDP_API */
2 changes: 1 addition & 1 deletion include/freerdp/gdi/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FREERDP_API int gdi_SetRectRgn(HGDI_RGN hRgn, int nLeftRect, int nTopRect, int n
FREERDP_API int gdi_EqualRgn(HGDI_RGN hSrcRgn1, HGDI_RGN hSrcRgn2);
FREERDP_API int gdi_CopyRect(HGDI_RECT dst, HGDI_RECT src);
FREERDP_API int gdi_PtInRect(HGDI_RECT rc, int x, int y);
FREERDP_API int gdi_InvalidateRegion(HGDI_DC hdc, int x, int y, int w, int h);
FREERDP_API BOOL gdi_InvalidateRegion(HGDI_DC hdc, int x, int y, int w, int h);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/cache/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
return TRUE;

memblt->bitmap = bitmap;
IFCALLRETURN(TRUE, cache->bitmap->MemBlt, context, memblt);
return IFCALLRESULT(TRUE, cache->bitmap->MemBlt, context, memblt);
}

BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/cache/brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
BOOL update_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc)
{
rdpCache* cache = context->cache;
IFCALLRETURN(TRUE, cache->brush->PolygonSC, context, polygon_sc);
return IFCALLRESULT(TRUE, cache->brush->PolygonSC, context, polygon_sc);
}

BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/cache/nine_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
BOOL update_gdi_draw_nine_grid(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid)
{
rdpCache* cache = context->cache;
IFCALLRETURN(TRUE, cache->nine_grid->DrawNineGrid, context, draw_nine_grid);
return IFCALLRESULT(TRUE, cache->nine_grid->DrawNineGrid, context, draw_nine_grid);
}

BOOL update_gdi_multi_draw_nine_grid(rdpContext* context, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid)
{
rdpCache* cache = context->cache;
IFCALLRETURN(TRUE, cache->nine_grid->MultiDrawNineGrid, context, multi_draw_nine_grid);
return IFCALLRESULT(TRUE, cache->nine_grid->MultiDrawNineGrid, context, multi_draw_nine_grid);
}

void nine_grid_cache_register_callbacks(rdpUpdate* update)
Expand Down
4 changes: 4 additions & 0 deletions libfreerdp/core/fastpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath)
rdp = fastpath->rdp;

s = transport_send_stream_init(rdp->transport, 256);
if (!s)
return NULL;

Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */

Expand All @@ -757,6 +759,8 @@ wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE ev
rdp = fastpath->rdp;

s = fastpath_input_pdu_init_header(fastpath);
if (!s)
return NULL;
Stream_Write_UINT8(s, eventFlags | (eventCode << 5)); /* eventHeader (1 byte) */

return s;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/core/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ BOOL Pointer_SetDefault(rdpContext* context)

BOOL Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
{
IFCALLRETURN(TRUE, context->graphics->Pointer_Prototype->SetPosition, context, x, y);
return IFCALLRESULT(TRUE, context->graphics->Pointer_Prototype->SetPosition, context, x, y);
}

void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
Expand Down
24 changes: 12 additions & 12 deletions libfreerdp/core/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static BOOL input_recv_sync_event(rdpInput* input, wStream* s)
Stream_Seek(s, 2); /* pad2Octets (2 bytes) */
Stream_Read_UINT32(s, toggleFlags); /* toggleFlags (4 bytes) */

IFCALLRETURN(TRUE, input->SynchronizeEvent, input, toggleFlags);
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, toggleFlags);
}

static BOOL input_recv_keyboard_event(rdpInput* input, wStream* s)
Expand Down Expand Up @@ -376,7 +376,7 @@ static BOOL input_recv_keyboard_event(rdpInput* input, wStream* s)
else
keyboardFlags |= KBD_FLAGS_DOWN;

IFCALLRETURN(TRUE, input->KeyboardEvent, input, keyboardFlags, keyCode);
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, keyboardFlags, keyCode);
}

static BOOL input_recv_unicode_keyboard_event(rdpInput* input, wStream* s)
Expand All @@ -397,7 +397,7 @@ static BOOL input_recv_unicode_keyboard_event(rdpInput* input, wStream* s)
else
keyboardFlags |= KBD_FLAGS_DOWN;

IFCALLRETURN(TRUE, input->UnicodeKeyboardEvent, input, keyboardFlags, unicodeCode);
return IFCALLRESULT(TRUE, input->UnicodeKeyboardEvent, input, keyboardFlags, unicodeCode);
}

static BOOL input_recv_mouse_event(rdpInput* input, wStream* s)
Expand All @@ -411,7 +411,7 @@ static BOOL input_recv_mouse_event(rdpInput* input, wStream* s)
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */

IFCALLRETURN(TRUE, input->MouseEvent, input, pointerFlags, xPos, yPos);
return IFCALLRESULT(TRUE, input->MouseEvent, input, pointerFlags, xPos, yPos);
}

static BOOL input_recv_extended_mouse_event(rdpInput* input, wStream* s)
Expand All @@ -425,7 +425,7 @@ static BOOL input_recv_extended_mouse_event(rdpInput* input, wStream* s)
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */

IFCALLRETURN(TRUE, input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
}

static BOOL input_recv_event(rdpInput* input, wStream* s)
Expand Down Expand Up @@ -533,12 +533,12 @@ void input_register_client_callbacks(rdpInput* input)

BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags)
{
IFCALLRETURN(TRUE, input->SynchronizeEvent, input, flags);
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, flags);
}

BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
IFCALLRETURN(TRUE, input->KeyboardEvent, input, flags, code);
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, flags, code);
}

BOOL freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down, UINT32 rdp_scancode)
Expand All @@ -551,27 +551,27 @@ BOOL freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down, UINT32 rdp

BOOL freerdp_input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
IFCALLRETURN(TRUE, input->UnicodeKeyboardEvent, input, flags, code);
return IFCALLRESULT(TRUE, input->UnicodeKeyboardEvent, input, flags, code);
}

BOOL freerdp_input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
IFCALLRETURN(TRUE, input->MouseEvent, input, flags, x, y);
return IFCALLRESULT(TRUE, input->MouseEvent, input, flags, x, y);
}

BOOL freerdp_input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
IFCALLRETURN(TRUE, input->ExtendedMouseEvent, input, flags, x, y);
return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, flags, x, y);
}

BOOL freerdp_input_send_focus_in_event(rdpInput* input, UINT16 toggleStates)
{
IFCALLRETURN(TRUE, input->FocusInEvent, input, toggleStates);
return IFCALLRESULT(TRUE, input->FocusInEvent, input, toggleStates);
}

BOOL freerdp_input_send_keyboard_pause_event(rdpInput* input)
{
IFCALLRETURN(TRUE, input->KeyboardPauseEvent, input);
return IFCALLRESULT(TRUE, input->KeyboardPauseEvent, input);
}

int input_process_events(rdpInput* input)
Expand Down
5 changes: 3 additions & 2 deletions libfreerdp/core/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ static BOOL update_send_surface_frame_bits(rdpContext* context, SURFACE_BITS_COM
s = fastpath_update_pdu_init(rdp->fastpath);
if (!s)
return FALSE;

if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) cmd->bitmapDataLength + 16))
goto out_fail;

Expand All @@ -986,7 +987,7 @@ static BOOL update_send_surface_frame_bits(rdpContext* context, SURFACE_BITS_COM
if (last)
{
if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_END, frameId))
return FALSE;
goto out_fail;
}

ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, cmd->skipCompression);
Expand Down Expand Up @@ -1748,7 +1749,7 @@ static BOOL update_send_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE*
if (!s)
return FALSE;

if (!update_write_pointer_color(s, pointer_color))
if (!update_write_pointer_color(s, pointer_color))
goto out_fail;

ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s, FALSE);
Expand Down
Loading

0 comments on commit 2c072d3

Please sign in to comment.