Player: send back screenshot data when remotely requested

When the external injection is used (scenario injected by an external
tool via Eina Debug) and a screenshot is required, the data is sent
to the injector.
This commit is contained in:
Daniel Zaoui 2018-08-22 21:56:51 +03:00
parent 1551b5358f
commit 5ffc8ec640
1 changed files with 34 additions and 3 deletions

View File

@ -101,6 +101,13 @@ foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
__s; \
})
#define STORE_INT(_buf, __i) \
({ \
int __si = SWAP_32(__i); \
memcpy(_buf, &__si, sizeof(int)); \
_buf += sizeof(int); \
})
typedef enum
{
FTYPE_UNKNOWN,
@ -130,6 +137,10 @@ static int _cur_shot_id = 0;
static Eina_Bool _shot_needed = EINA_FALSE;
static Eina_Bool _scan_objects = EINA_FALSE, _disable_shots = EINA_FALSE;
static Eina_Debug_Session *_last_debug_session = NULL;
static int _last_debug_src_cid = 0;
static int _take_shot_op = EINA_DEBUG_OPCODE_INVALID;
static Eina_Bool _stabilization_timer_cb(void *);
static Eina_Bool _exit_required = EINA_FALSE;
@ -222,6 +233,16 @@ _evas_render_post_cb(void *data EINA_UNUSED, const Efl_Event *event)
ex_shot->pixels = NULL;
_printf(1, "Shot taken (in %s).\n", _dest);
}
else if (_dest_type == FTYPE_REMOTE)
{
int len = sizeof(int) + sizeof(int) + ex_shot->w * ex_shot->h * 4;
char *buf = alloca(len);
char *tmp = buf;
STORE_INT(tmp, ex_shot->w);
STORE_INT(tmp, ex_shot->h);
memcpy(tmp, ex_shot->pixels, ex_shot->w * ex_shot->h * 4);
eina_debug_session_send(_last_debug_session, _last_debug_src_cid, _take_shot_op, buf, len);
}
}
exactness_image_free(ex_shot);
efl_key_data_set(event->object, "_shot", NULL);
@ -262,6 +283,10 @@ _shot_do(Evas *e)
_dest_unit->nb_shots++;
e_data = ex_img;
}
else if (_dest_type == FTYPE_REMOTE)
{
e_data = e;
}
}
efl_key_data_set(e, "_shot", e_data);
_shot_needed = EINA_TRUE;
@ -687,11 +712,13 @@ _main_loop_key_up_cb(Eina_Debug_Session *session EINA_UNUSED, int srcid EINA_UNU
}
static void
_main_loop_take_shot_cb(Eina_Debug_Session *session EINA_UNUSED, int srcid EINA_UNUSED, void *buffer, int size EINA_UNUSED)
_main_loop_take_shot_cb(Eina_Debug_Session *session, int srcid, void *buffer, int size EINA_UNUSED)
{
char *buf = buffer;
int n_evas = EXTRACT_INT(buf);
_feed_event(EXACTNESS_ACTION_TAKE_SHOT, n_evas, NULL);
_last_debug_session = session;
_last_debug_src_cid = srcid;
}
static void
@ -738,7 +765,7 @@ EINA_DEBUG_OPCODES_ARRAY_DEFINE(_debug_ops,
{"Exactness/Actions/Multi Move", NULL, &_multi_move_cb},
{"Exactness/Actions/Key Down", NULL, &_key_down_cb},
{"Exactness/Actions/Key Up", NULL, &_key_up_cb},
{"Exactness/Actions/Take Shot", NULL, &_take_shot_cb},
{"Exactness/Actions/Take Shot", &_take_shot_op, &_take_shot_cb},
{"Exactness/Actions/EFL Event", NULL, &_efl_event_cb},
{"Exactness/Actions/Stabilize", NULL, &_stabilize_cb},
{"Exactness/Actions/Finish", NULL, &_finish_cb},
@ -1034,7 +1061,11 @@ int main(int argc, char **argv)
fprintf(stderr, "Cannot inject events from a source file and from outside simultaneously\n");
goto end;
}
if (external_injection) _src_type = FTYPE_REMOTE;
if (external_injection)
{
_src_type = FTYPE_REMOTE;
if (_dest_type == FTYPE_UNKNOWN) _dest_type = FTYPE_REMOTE;
}
if (src)
{
_src_filename = eina_stringshare_add(src);