[{"id":32681,"web_url":"https://patchwork.libcamera.org/comment/32681/","msgid":"<20241211164045.GC24546@pendragon.ideasonboard.com>","date":"2024-12-11T16:40:45","subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Wed, Dec 11, 2024 at 03:25:45PM +0000, Barnabás Pőcze wrote:\n> There is no reason make copies, these functions return\n> const lvalue references, access the data through those.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nwith one comment below.\n\n> ---\n>  src/libcamera/pipeline/virtual/image_frame_generator.cpp  | 2 +-\n>  src/libcamera/pipeline/virtual/test_pattern_generator.cpp | 2 +-\n>  src/libcamera/pipeline/virtual/virtual.cpp                | 3 +--\n>  3 files changed, 3 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> index 277efbb09..d1545b5d9 100644\n> --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> @@ -129,7 +129,7 @@ int ImageFrameGenerator::generateFrame(const Size &size, const FrameBuffer *buff\n>  \n>  \tMappedFrameBuffer mappedFrameBuffer(buffer, MappedFrameBuffer::MapFlag::Write);\n>  \n> -\tauto planes = mappedFrameBuffer.planes();\n> +\tconst auto &planes = mappedFrameBuffer.planes();\n>  \n>  \t/* Loop only around the number of images available */\n>  \tframeIndex_ %= imageFrameDatas_.size();\n> diff --git a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> index 7bc2b338c..47d341919 100644\n> --- a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> +++ b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> @@ -25,7 +25,7 @@ int TestPatternGenerator::generateFrame(const Size &size,\n>  \tMappedFrameBuffer mappedFrameBuffer(buffer,\n>  \t\t\t\t\t    MappedFrameBuffer::MapFlag::Write);\n>  \n> -\tauto planes = mappedFrameBuffer.planes();\n> +\tconst auto &planes = mappedFrameBuffer.planes();\n>  \n>  \tshiftLeft(size);\n>  \n> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> index 1b7cd5cb3..3126bdd7d 100644\n> --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> @@ -275,8 +275,7 @@ int PipelineHandlerVirtual::exportFrameBuffers([[maybe_unused]] Camera *camera,\n>  \t\treturn -ENOBUFS;\n>  \n>  \tconst StreamConfiguration &config = stream->configuration();\n> -\n> -\tauto info = PixelFormatInfo::info(config.pixelFormat);\n> +\tconst PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat);\n\nThere's also a similar issue in src/libcamera/pipeline/imx8-isi/imx8-isi.cpp:\n\n\tconst PixelFormatInfo info = PixelFormatInfo::info(config_[0].pixelFormat);\n\nIt would be nice to disable the PixelFormatInfo copy constructor (using\nLIBCAMERA_DISABLE_COPY() or even LIBCAMERA_DISABLE_COPY_AND_MOVE()), but\nthat interferes with the designated initializer syntax we use in\nformats.cpp to populate the pixelFormatInfo array as aggregate\ninitialization is disabled for types that have user-declared\nconstructors (even if deleted). One option would be to define a\nconstructor for the class, but we then lose the ability to use\ndesignated initializers. Maybe that's not a big issue ?\n\nCould you have a look at this ?\n\n>  \n>  \tstd::vector<unsigned int> planeSizes;\n>  \tfor (size_t i = 0; i < info.planes.size(); ++i)","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B0AAAC32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Dec 2024 16:41:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B21A67EB2;\n\tWed, 11 Dec 2024 17:41:03 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 23F1D618AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Dec 2024 17:41:02 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D03579FF;\n\tWed, 11 Dec 2024 17:40:28 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"h+AKv4eQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1733935229;\n\tbh=/snWDc8fnwfCHPyK0yIgEDiugqFWv5XjLhWMjqsOeIU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=h+AKv4eQ409pgLxblRe9Ite5IC2NClHCYsXKez5K+HplcercBnIw36Uno/WAU0iEP\n\tegryEJdP3RuPNeanP5krt6SUsrfu4XMqhGmErA+5O2DO8rvHoMCnGiApV9qVS+S5ZB\n\tT5tKPKMXQzQK+XSh1uIB0hvmc697pZUeEPUVtSG4=","Date":"Wed, 11 Dec 2024 18:40:45 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","Message-ID":"<20241211164045.GC24546@pendragon.ideasonboard.com>","References":"<20241211152542.1095857-1-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20241211152542.1095857-1-pobrn@protonmail.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":32685,"web_url":"https://patchwork.libcamera.org/comment/32685/","msgid":"<UQdS2Gurpb6ZmnqCwZhN9xh_diuiEwo7qGQi3rH9j_AyJl7fwCjkwixRJ2OLn5ECQOBUxZ_tOx5zLSmfXLB36pIFi3Szt5t7M4rRSGuzJ_c=@protonmail.com>","date":"2024-12-11T17:10:23","subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"Hi\n\n\n2024. december 11., szerda 17:40 keltezéssel, Laurent Pinchart <laurent.pinchart@ideasonboard.com> írta:\n\n> Hi Barnabás,\n> \n> Thank you for the patch.\n> \n> On Wed, Dec 11, 2024 at 03:25:45PM +0000, Barnabás Pőcze wrote:\n> > There is no reason make copies, these functions return\n> > const lvalue references, access the data through those.\n> >\n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> with one comment below.\n> \n> > ---\n> >  src/libcamera/pipeline/virtual/image_frame_generator.cpp  | 2 +-\n> >  src/libcamera/pipeline/virtual/test_pattern_generator.cpp | 2 +-\n> >  src/libcamera/pipeline/virtual/virtual.cpp                | 3 +--\n> >  3 files changed, 3 insertions(+), 4 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > index 277efbb09..d1545b5d9 100644\n> > --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > @@ -129,7 +129,7 @@ int ImageFrameGenerator::generateFrame(const Size &size, const FrameBuffer *buff\n> >\n> >  \tMappedFrameBuffer mappedFrameBuffer(buffer, MappedFrameBuffer::MapFlag::Write);\n> >\n> > -\tauto planes = mappedFrameBuffer.planes();\n> > +\tconst auto &planes = mappedFrameBuffer.planes();\n> >\n> >  \t/* Loop only around the number of images available */\n> >  \tframeIndex_ %= imageFrameDatas_.size();\n> > diff --git a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > index 7bc2b338c..47d341919 100644\n> > --- a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > +++ b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > @@ -25,7 +25,7 @@ int TestPatternGenerator::generateFrame(const Size &size,\n> >  \tMappedFrameBuffer mappedFrameBuffer(buffer,\n> >  \t\t\t\t\t    MappedFrameBuffer::MapFlag::Write);\n> >\n> > -\tauto planes = mappedFrameBuffer.planes();\n> > +\tconst auto &planes = mappedFrameBuffer.planes();\n> >\n> >  \tshiftLeft(size);\n> >\n> > diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> > index 1b7cd5cb3..3126bdd7d 100644\n> > --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> > +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> > @@ -275,8 +275,7 @@ int PipelineHandlerVirtual::exportFrameBuffers([[maybe_unused]] Camera *camera,\n> >  \t\treturn -ENOBUFS;\n> >\n> >  \tconst StreamConfiguration &config = stream->configuration();\n> > -\n> > -\tauto info = PixelFormatInfo::info(config.pixelFormat);\n> > +\tconst PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat);\n> \n> There's also a similar issue in src/libcamera/pipeline/imx8-isi/imx8-isi.cpp:\n> \n> \tconst PixelFormatInfo info = PixelFormatInfo::info(config_[0].pixelFormat);\n> \n> It would be nice to disable the PixelFormatInfo copy constructor (using\n> LIBCAMERA_DISABLE_COPY() or even LIBCAMERA_DISABLE_COPY_AND_MOVE()), but\n> that interferes with the designated initializer syntax we use in\n> formats.cpp to populate the pixelFormatInfo array as aggregate\n> initialization is disabled for types that have user-declared\n> constructors (even if deleted). One option would be to define a\n> constructor for the class, but we then lose the ability to use\n> designated initializers. Maybe that's not a big issue ?\n> \n> Could you have a look at this ?\n> [...]\n\nThat map is initialized from an `std::initializer_list` and that provides a `const`\nview of the data, so the map copy constructs the elements from the list. Deleting\nthe copy constructor would make that not work. I think using an array and `std::move_iterator`\ncould maybe work around that.\n\nReturning a pointer from `PixelFormatInfo::info()` would also eliminate this kind of issue.\n\nAlso, there is the \"performance-unnecessary-copy-initialization\" clang-tidy check,\nbut it seems it does not want to diagnose this situation. (Seemingly because\nthe reference is returned by a static member function.)\n\n\nRegards,\nBarnabás Pőcze","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9367EBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Dec 2024 17:10:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAE7C67EBF;\n\tWed, 11 Dec 2024 18:10:28 +0100 (CET)","from mail-40134.protonmail.ch (mail-40134.protonmail.ch\n\t[185.70.40.134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 658AC67EBC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Dec 2024 18:10:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"tNO638vT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1733937025; x=1734196225;\n\tbh=tcP4weMHx29zk6EffCbf5RMy/7BQU3IDgscbMM0mxGI=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=tNO638vTc1bo+U3fY+C/wJxQehaFsG1+p15DdlJTzjvr6VsL/5B4cbuwCodqZKf54\n\tgjrxYP22wvceYD0nHQ+pdGO9UCX7lC9upVdUUdZFll2+DQm4FpjoHEMAdWmD4nTekY\n\t/KIm5RoiDtdOfq2bdNfnsEKC/iaCOD1khlKOq2P4ne03a2SJQLoPted3ZrTPaj+ZCi\n\tTc33cvb+B1uU3i+g+093Ve7sPkkW5whhervwW2/UGt4uIr1aVoxMG8UhmEkDqF5NuW\n\tQLMsdrdUn5wtSfhZYz22552MeeN76cgCo3tc++xCpncQvTLK0O4KnkoQcY99U7sPou\n\tqacWx/qif7bnQ==","Date":"Wed, 11 Dec 2024 17:10:23 +0000","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","Message-ID":"<UQdS2Gurpb6ZmnqCwZhN9xh_diuiEwo7qGQi3rH9j_AyJl7fwCjkwixRJ2OLn5ECQOBUxZ_tOx5zLSmfXLB36pIFi3Szt5t7M4rRSGuzJ_c=@protonmail.com>","In-Reply-To":"<20241211164045.GC24546@pendragon.ideasonboard.com>","References":"<20241211152542.1095857-1-pobrn@protonmail.com>\n\t<20241211164045.GC24546@pendragon.ideasonboard.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"67d9baea5ccec033b815a05dbc6e5ccd4ab3f93d","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":32822,"web_url":"https://patchwork.libcamera.org/comment/32822/","msgid":"<173445168203.32744.6503675900919586097@ping.linuxembedded.co.uk>","date":"2024-12-17T16:08:02","subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2024-12-11 15:25:45)\n> There is no reason make copies, these functions return\n> const lvalue references, access the data through those.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/libcamera/pipeline/virtual/image_frame_generator.cpp  | 2 +-\n>  src/libcamera/pipeline/virtual/test_pattern_generator.cpp | 2 +-\n>  src/libcamera/pipeline/virtual/virtual.cpp                | 3 +--\n>  3 files changed, 3 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> index 277efbb09..d1545b5d9 100644\n> --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> @@ -129,7 +129,7 @@ int ImageFrameGenerator::generateFrame(const Size &size, const FrameBuffer *buff\n>  \n>         MappedFrameBuffer mappedFrameBuffer(buffer, MappedFrameBuffer::MapFlag::Write);\n>  \n> -       auto planes = mappedFrameBuffer.planes();\n> +       const auto &planes = mappedFrameBuffer.planes();\n>  \n>         /* Loop only around the number of images available */\n>         frameIndex_ %= imageFrameDatas_.size();\n> diff --git a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> index 7bc2b338c..47d341919 100644\n> --- a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> +++ b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> @@ -25,7 +25,7 @@ int TestPatternGenerator::generateFrame(const Size &size,\n>         MappedFrameBuffer mappedFrameBuffer(buffer,\n>                                             MappedFrameBuffer::MapFlag::Write);\n>  \n> -       auto planes = mappedFrameBuffer.planes();\n> +       const auto &planes = mappedFrameBuffer.planes();\n>  \n>         shiftLeft(size);\n>  \n> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> index 1b7cd5cb3..3126bdd7d 100644\n> --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> @@ -275,8 +275,7 @@ int PipelineHandlerVirtual::exportFrameBuffers([[maybe_unused]] Camera *camera,\n>                 return -ENOBUFS;\n>  \n>         const StreamConfiguration &config = stream->configuration();\n> -\n> -       auto info = PixelFormatInfo::info(config.pixelFormat);\n> +       const PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat);\n>  \n>         std::vector<unsigned int> planeSizes;\n>         for (size_t i = 0; i < info.planes.size(); ++i)\n> -- \n> 2.47.1\n> \n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3CDB9C32F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 17 Dec 2024 16:08:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2DA0767FDF;\n\tTue, 17 Dec 2024 17:08:06 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B526D67FD3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Dec 2024 17:08:04 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D3E64C7;\n\tTue, 17 Dec 2024 17:07:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YgjnS245\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734451647;\n\tbh=xXyGbP96i9pwcSzIkmFWBkY9Q7Y2zace5O4W/NrXwaA=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=YgjnS245LBl6uq9SZS8oix3vHwuhsiRJo+dkeUI8KiQCQaTXhSZYr2ZW2VtAaLZSH\n\tXi8R88TvJpQHe/52LN4q/CB7rNvNJxX9sQvlx3kOn3e8euf6qiEBW13Nt6BmnUXeCf\n\tcCyJ3GOS2wYCj+nvGY0lCCktJQvkZF7t2X9AS99I=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241211152542.1095857-1-pobrn@protonmail.com>","References":"<20241211152542.1095857-1-pobrn@protonmail.com>","Subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 17 Dec 2024 16:08:02 +0000","Message-ID":"<173445168203.32744.6503675900919586097@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":32837,"web_url":"https://patchwork.libcamera.org/comment/32837/","msgid":"<20241217165440.GI20432@pendragon.ideasonboard.com>","date":"2024-12-17T16:54:40","subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nOn Wed, Dec 11, 2024 at 05:10:23PM +0000, Barnabás Pőcze wrote:\n> 2024. december 11., szerda 17:40 keltezéssel, Laurent Pinchart írta:\n> > On Wed, Dec 11, 2024 at 03:25:45PM +0000, Barnabás Pőcze wrote:\n> > > There is no reason make copies, these functions return\n> > > const lvalue references, access the data through those.\n> > >\n> > > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> > \n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > \n> > with one comment below.\n> > \n> > > ---\n> > >  src/libcamera/pipeline/virtual/image_frame_generator.cpp  | 2 +-\n> > >  src/libcamera/pipeline/virtual/test_pattern_generator.cpp | 2 +-\n> > >  src/libcamera/pipeline/virtual/virtual.cpp                | 3 +--\n> > >  3 files changed, 3 insertions(+), 4 deletions(-)\n> > >\n> > > diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > > index 277efbb09..d1545b5d9 100644\n> > > --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > > +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n> > > @@ -129,7 +129,7 @@ int ImageFrameGenerator::generateFrame(const Size &size, const FrameBuffer *buff\n> > >\n> > >  \tMappedFrameBuffer mappedFrameBuffer(buffer, MappedFrameBuffer::MapFlag::Write);\n> > >\n> > > -\tauto planes = mappedFrameBuffer.planes();\n> > > +\tconst auto &planes = mappedFrameBuffer.planes();\n> > >\n> > >  \t/* Loop only around the number of images available */\n> > >  \tframeIndex_ %= imageFrameDatas_.size();\n> > > diff --git a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > > index 7bc2b338c..47d341919 100644\n> > > --- a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > > +++ b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp\n> > > @@ -25,7 +25,7 @@ int TestPatternGenerator::generateFrame(const Size &size,\n> > >  \tMappedFrameBuffer mappedFrameBuffer(buffer,\n> > >  \t\t\t\t\t    MappedFrameBuffer::MapFlag::Write);\n> > >\n> > > -\tauto planes = mappedFrameBuffer.planes();\n> > > +\tconst auto &planes = mappedFrameBuffer.planes();\n> > >\n> > >  \tshiftLeft(size);\n> > >\n> > > diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> > > index 1b7cd5cb3..3126bdd7d 100644\n> > > --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> > > +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> > > @@ -275,8 +275,7 @@ int PipelineHandlerVirtual::exportFrameBuffers([[maybe_unused]] Camera *camera,\n> > >  \t\treturn -ENOBUFS;\n> > >\n> > >  \tconst StreamConfiguration &config = stream->configuration();\n> > > -\n> > > -\tauto info = PixelFormatInfo::info(config.pixelFormat);\n> > > +\tconst PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat);\n> > \n> > There's also a similar issue in src/libcamera/pipeline/imx8-isi/imx8-isi.cpp:\n> > \n> > \tconst PixelFormatInfo info = PixelFormatInfo::info(config_[0].pixelFormat);\n> > \n> > It would be nice to disable the PixelFormatInfo copy constructor (using\n> > LIBCAMERA_DISABLE_COPY() or even LIBCAMERA_DISABLE_COPY_AND_MOVE()), but\n> > that interferes with the designated initializer syntax we use in\n> > formats.cpp to populate the pixelFormatInfo array as aggregate\n> > initialization is disabled for types that have user-declared\n> > constructors (even if deleted). One option would be to define a\n> > constructor for the class, but we then lose the ability to use\n> > designated initializers. Maybe that's not a big issue ?\n> > \n> > Could you have a look at this ?\n> > [...]\n> \n> That map is initialized from an `std::initializer_list` and that provides a `const`\n> view of the data, so the map copy constructs the elements from the list. Deleting\n> the copy constructor would make that not work. I think using an array and `std::move_iterator`\n> could maybe work around that.\n> \n> Returning a pointer from `PixelFormatInfo::info()` would also eliminate this kind of issue.\n> \n> Also, there is the \"performance-unnecessary-copy-initialization\" clang-tidy check,\n> but it seems it does not want to diagnose this situation. (Seemingly because\n> the reference is returned by a static member function.)\n\nOK, let's ignore this for the time being then.","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id DE5D2C32F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 17 Dec 2024 16:54:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 274FC67FEF;\n\tTue, 17 Dec 2024 17:54:44 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 73E9567FD3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Dec 2024 17:54:42 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E93BC4C7;\n\tTue, 17 Dec 2024 17:54:04 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"U5MfRaf3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734454445;\n\tbh=ekNILlVVK9BzfRMz7aBBZL4KpbcsNkR4Is4Ky2x9Geo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=U5MfRaf3iVWVxyqsdgOtnCdez6al0JOfdun11KeAZAdqX9drglcw6KlbKmxhM7CSM\n\tOw462Q9napxiO099XTkzf0p3rDaOcPuWRzGblOrQOlyFeiwer9mDhUdwU5V6iSAz6v\n\tuIYOikBZa4aPM1Oxs/mqpvW6E0j4jk8aw+luXIv8=","Date":"Tue, 17 Dec 2024 18:54:40 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/3] libcamera: virtual: Avoid some copies","Message-ID":"<20241217165440.GI20432@pendragon.ideasonboard.com>","References":"<20241211152542.1095857-1-pobrn@protonmail.com>\n\t<20241211164045.GC24546@pendragon.ideasonboard.com>\n\t<UQdS2Gurpb6ZmnqCwZhN9xh_diuiEwo7qGQi3rH9j_AyJl7fwCjkwixRJ2OLn5ECQOBUxZ_tOx5zLSmfXLB36pIFi3Szt5t7M4rRSGuzJ_c=@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<UQdS2Gurpb6ZmnqCwZhN9xh_diuiEwo7qGQi3rH9j_AyJl7fwCjkwixRJ2OLn5ECQOBUxZ_tOx5zLSmfXLB36pIFi3Szt5t7M4rRSGuzJ_c=@protonmail.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]