All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Kshitij Suri <kshitij.suri@nutanix.com>
Cc: soham.ghosh@nutanix.com, thuth@redhat.com, berrange@redhat.com,
	prerna.saxena@nutanix.com, qemu-devel@nongnu.org,
	dgilbert@redhat.com, philippe.mathieu.daude@gmail.com,
	kraxel@redhat.com, prachatos.mitra@nutanix.com,
	eblake@redhat.com
Subject: Re: [PATCH v2 2/2] Added parameter to take screenshot with screendump as
Date: Thu, 17 Mar 2022 07:20:38 +0100	[thread overview]
Message-ID: <87v8wdqevd.fsf@pond.sub.org> (raw)
In-Reply-To: <98a777da-4ff5-784f-78ca-790dd3064a7b@nutanix.com> (Kshitij Suri's message of "Wed, 16 Mar 2022 23:45:03 +0530")

Kshitij Suri <kshitij.suri@nutanix.com> writes:

> On 16/03/22 6:55 pm, Markus Armbruster wrote:
>> Kshitij Suri <kshitij.suri@nutanix.com> writes:
>>
>>> From: "kshitij.suri" <kshitij.suri@nutanix.com>
>>>
>>> Currently screendump only supports PPM format, which is un-compressed and not
>>> standard. Added a "format" parameter to qemu monitor screendump capabilites
>>> to support PNG image capture using libpng. The param was added in QAPI schema
>>> of screendump present in ui.json along with png_save() function which converts
>>> pixman_image to PNG. HMP command equivalent was also modified to support the
>>> feature.
>>>
>>> Example usage:
>>> { "execute": "screendump", "arguments": { "filename": "/tmp/image",
>>> "format":"png" } }
>>>
>>> Resolves: https://urldefense.proofpoint.com/v2/url?u=https-3A__gitlab.com_qemu-2Dproject_qemu_-2D_issues_718&d=DwIBAg&c=s883GpUCOChKOHiocYtGcg&r=utjv19Ej9Fb0TB7_DX0o3faQ-OAm2ypPniPyqVSoj_w&m=UZZDywEeidD1LndEhKddMf_0v-jePIgMYErGImjYyvjYRJFdnv6LAHgRmZ0IpvIL&s=jc09kdvD1ULKCC9RgwWcsK6eweue3ZkyD8F9kCx5yUs&e=
>>>
>>> Signed-off-by: Kshitij Suri <kshitij.suri@nutanix.com>
>>> ---
>>> diff to v1:
>>>    - Removed repeated alpha conversion operation.
>>>    - Modified logic to mirror png conversion in vnc-enc-tight.c file.
>>>    - Added a new CONFIG_PNG parameter for libpng support.
>>>    - Changed input format to enum instead of string.
>>>    - Improved error handling.
>>>   hmp-commands.hx    |  11 ++---
>>>   monitor/hmp-cmds.c |  19 ++++++++-
>>>   qapi/ui.json       |  24 +++++++++--
>>>   ui/console.c       | 102 +++++++++++++++++++++++++++++++++++++++++++--
>>>   4 files changed, 144 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>>> index 70a9136ac2..5eda4eeb24 100644
>>> --- a/hmp-commands.hx
>>> +++ b/hmp-commands.hx
>>> @@ -244,17 +244,18 @@ ERST
>>>   
>>>       {
>>>           .name       = "screendump",
>>> -        .args_type  = "filename:F,device:s?,head:i?",
>>> -        .params     = "filename [device [head]]",
>>> -        .help       = "save screen from head 'head' of display device 'device' "
>>> -                      "into PPM image 'filename'",
>>> +        .args_type  = "filename:F,device:s?,head:i?,format:f?",
>>> +        .params     = "filename [device [head]] [format]",
>>> +        .help       = "save screen from head 'head' of display device 'device'"
>>> +                      "in specified format 'format' as image 'filename'."
>>> +                      "Currently only 'png' and 'ppm' formats are supported.",
>>>           .cmd        = hmp_screendump,
>>>           .coroutine  = true,
>>>       },
>>>   
>>>   SRST
>>>   ``screendump`` *filename*
>>> -  Save screen into PPM image *filename*.
>>> +  Save screen as an image *filename*, with default format of PPM.
>>>   ERST
>>>   
>>>       {
>>> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
>>> index 8c384dc1b2..9a640146eb 100644
>>> --- a/monitor/hmp-cmds.c
>>> +++ b/monitor/hmp-cmds.c
>>> @@ -1677,9 +1677,26 @@ hmp_screendump(Monitor *mon, const QDict *qdict)
>>>       const char *filename = qdict_get_str(qdict, "filename");
>>>       const char *id = qdict_get_try_str(qdict, "device");
>>>       int64_t head = qdict_get_try_int(qdict, "head", 0);
>>> +    const char *input_format  = qdict_get_str(qdict, "format");
>>>       Error *err = NULL;
>>> +    ImageFormat format;
>>>   
>>> -    qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
>>
>> The second id != NULL looks wrong.  Shouldn't it be head != NULL?

Can't: @head is not a pointer.

>> Not your patch's fault, of course.
>
> As per hmp-commands.hx input is of format [device [head]] so maybe
> works as a pair.

I looked: no, it works because it duplicates qmp_screendump()'s default.

qmp_screendump()'s behavior:

* If neither @device nor @head are present, default to console #0.

* If only @device is present, default to head 0 of the specified device.

* If both are present, default to the specified head of the specified
  device.

* If only @head is present, error out.

Ideally, we'd have hmp_screendump() pass its arguments unadulterated to
qmp_screendump(), so logic isn't duplicated.

Unfortunately, this turns out to be a bit troublesome.
qdict_get_try_int() *forces* us to supply a default value, and doesn't
tell us whether argument is present.  We'd have to use qdict_haskey()
for that:

    qmp_screendump(filename, id != NULL, id, qdict_haskey("head"), head,
                   &err);

The current code instead replaces case "only @device is present" by
"both are present".  Works, because the default it uses matches the one
in qmp_screendump().

I find this less obvious, but I'm not sure it's worth patching.

Note that case "only @head is present" isn't possible because the
arguments are positional.

>                  Is it alright if I investigate and send in another patch
> after this?

Let's not bother.



  reply	other threads:[~2022-03-17  6:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15  4:47 [PATCH v2 1/2] Replacing CONFIG_VNC_PNG with CONFIG_PNG Kshitij Suri
2022-03-15  4:47 ` [PATCH v2 2/2] Added parameter to take screenshot with screendump as Kshitij Suri
2022-03-16 13:25   ` Markus Armbruster
2022-03-16 18:15     ` Kshitij Suri
2022-03-17  6:20       ` Markus Armbruster [this message]
2022-03-15  9:17 ` [PATCH v2 1/2] Replacing CONFIG_VNC_PNG with CONFIG_PNG Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8wdqevd.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kshitij.suri@nutanix.com \
    --cc=philippe.mathieu.daude@gmail.com \
    --cc=prachatos.mitra@nutanix.com \
    --cc=prerna.saxena@nutanix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=soham.ghosh@nutanix.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.