From 036d1a616005751413e7ee10d9f25bcd06be07f4 Mon Sep 17 00:00:00 2001 From: Chen Jie Date: Thu, 9 May 2013 16:48:10 +0800 Subject: [PATCH] dx9screencapsrc: add show-pointer property --- sys/winscreencap/gstdx9screencapsrc.c | 47 ++++++++++++++++++++++++++++++++++- sys/winscreencap/gstdx9screencapsrc.h | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/sys/winscreencap/gstdx9screencapsrc.c b/sys/winscreencap/gstdx9screencapsrc.c index 029053d..9f8669f 100644 --- a/sys/winscreencap/gstdx9screencapsrc.c +++ b/sys/winscreencap/gstdx9screencapsrc.c @@ -68,7 +68,8 @@ enum PROP_X_POS, PROP_Y_POS, PROP_WIDTH, - PROP_HEIGHT + PROP_HEIGHT, + PROP_SHOW_POINTER }; static IDirect3D9 *g_d3d9 = NULL; @@ -154,6 +155,11 @@ gst_dx9screencapsrc_class_init (GstDX9ScreenCapSrcClass * klass) "Height of screen capture area (0 = maximum)", 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (go_class, PROP_SHOW_POINTER, + g_param_spec_boolean ("show-pointer", "Show Mouse Pointer", + "Show mouse pointer", TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + GST_DEBUG_CATEGORY_INIT (dx9screencapsrc_debug, "dx9screencapsrc", 0, "DirectX 9 screen capture source"); } @@ -174,6 +180,7 @@ gst_dx9screencapsrc_init (GstDX9ScreenCapSrc * src, src->capture_y = 0; src->capture_w = 0; src->capture_h = 0; + src->show_pointer = TRUE; src->monitor = 0; @@ -233,6 +240,9 @@ gst_dx9screencapsrc_set_property (GObject * object, case PROP_HEIGHT: src->capture_h = g_value_get_int (value); break; + case PROP_SHOW_POINTER: + src->show_pointer = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -261,6 +271,9 @@ gst_dx9screencapsrc_get_property (GObject * object, guint prop_id, case PROP_HEIGHT: g_value_set_int (value, src->capture_h); break; + case PROP_SHOW_POINTER: + g_value_set_boolean (value, src->show_pointer); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -559,6 +572,38 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf) return GST_FLOW_UNEXPECTED; } + if (src->show_pointer) { + CURSORINFO ci = { .cbSize = sizeof(CURSORINFO) }; + + /* Get cursor position & Draw it */ + if (!GetCursorInfo (&ci)) + GST_DEBUG_OBJECT (src, "GetCursorInfo failed."); + else if (ci.flags == CURSOR_SHOWING) { + ICONINFO ii = {0,}; + HDC dc = {0,}; + + if (!GetIconInfo (ci.hCursor, &ii)) + GST_WARNING_OBJECT (src, "GetIconInfo failed."); + else if (IDirect3DSurface9_GetDC (src->surface, &dc) != D3D_OK) + GST_WARNING_OBJECT (src, "IDirect3DSurface9::GetDC failed."); + else { + DeleteObject (ii.hbmColor); + DeleteObject (ii.hbmMask); + /* + * The explanation of IDirect3DDevice9_GetFrontBufferData from MSDN: + * Generates a copy of the device's front buffer and places that copy + * in a system memory buffer provided by the application. + * So drawing on it should be save. + */ + DrawIcon (dc, + ci.ptScreenPos.x - ii.xHotspot - src->src_rect.left, + ci.ptScreenPos.y - ii.yHotspot - src->src_rect.top, + ci.hCursor); + IDirect3DSurface9_ReleaseDC (src->surface, dc); + } + } + } + hres = IDirect3DSurface9_LockRect (src->surface, &locked_rect, &(src->src_rect), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY); diff --git a/sys/winscreencap/gstdx9screencapsrc.h b/sys/winscreencap/gstdx9screencapsrc.h index 31ffb30..2f42753 100644 --- a/sys/winscreencap/gstdx9screencapsrc.h +++ b/sys/winscreencap/gstdx9screencapsrc.h @@ -54,6 +54,7 @@ struct _GstDX9ScreenCapSrc gint capture_w; gint capture_h; guint monitor; + gboolean show_pointer; /* Source pad frame rate */ gint rate_numerator; -- 1.8.1.4