Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d508b13 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "codec2: fix graphic buffer copy" into qt-dev

parents b69bbb60 7d966311
Loading
Loading
Loading
Loading
+40 −36
Original line number Diff line number Diff line
@@ -201,9 +201,10 @@ public:
     * \param colorFormat desired SDK color format for the MediaImage (if this is a flexible format,
     *        an attempt is made to simply represent the graphic view as a flexible SDK format
     *        without a memcpy)
     * \param copy whether the converter is used for copy or not
     */
    GraphicView2MediaImageConverter(
            const C2GraphicView &view, int32_t colorFormat)
            const C2GraphicView &view, int32_t colorFormat, bool copy)
        : mInitCheck(NO_INIT),
          mView(view),
          mWidth(view.width()),
@@ -255,7 +256,8 @@ public:
                }
                switch (mColorFormat) {
                    case COLOR_FormatYUV420Flexible:
                    {  // try to map directly. check if the planes are near one another
                        if (!copy) {
                            // try to map directly. check if the planes are near one another
                            const uint8_t *minPtr = mView.data()[0];
                            const uint8_t *maxPtr = mView.data()[0];
                            int32_t planeSize = 0;
@@ -270,13 +272,14 @@ public:
                                    maxPtr = mView.data()[i] + maxOffset;
                                }
                                planeSize += std::abs(plane.rowInc) * align(mHeight, 64)
                                    / plane.rowSampling / plane.colSampling * divUp(mAllocatedDepth, 8u);
                                        / plane.rowSampling / plane.colSampling
                                        * divUp(mAllocatedDepth, 8u);
                            }

                            if ((maxPtr - minPtr + 1) <= planeSize) {
                            // FIXME: this is risky as reading/writing data out of bound results in
                            //        an undefined behavior, but gralloc does assume a contiguous
                            //        mapping
                                // FIXME: this is risky as reading/writing data out of bound results
                                //        in an undefined behavior, but gralloc does assume a
                                //        contiguous mapping
                                for (uint32_t i = 0; i < layout.numPlanes; ++i) {
                                    const C2PlaneInfo &plane = layout.planes[i];
                                    mediaImage->mPlane[i].mOffset = mView.data()[i] - minPtr;
@@ -285,7 +288,8 @@ public:
                                    mediaImage->mPlane[i].mHorizSubsampling = plane.colSampling;
                                    mediaImage->mPlane[i].mVertSubsampling = plane.rowSampling;
                                }
                            mWrapped = new ABuffer(const_cast<uint8_t *>(minPtr), maxPtr - minPtr + 1);
                                mWrapped = new ABuffer(const_cast<uint8_t *>(minPtr),
                                                       maxPtr - minPtr + 1);
                                break;
                            }
                        }
@@ -503,7 +507,7 @@ sp<GraphicBlockBuffer> GraphicBlockBuffer::Allocate(
    int32_t colorFormat = COLOR_FormatYUV420Flexible;
    (void)format->findInt32("color-format", &colorFormat);

    GraphicView2MediaImageConverter converter(view, colorFormat);
    GraphicView2MediaImageConverter converter(view, colorFormat, false /* copy */);
    if (converter.initCheck() != OK) {
        ALOGD("Converter init failed: %d", converter.initCheck());
        return nullptr;
@@ -615,7 +619,7 @@ sp<ConstGraphicBlockBuffer> ConstGraphicBlockBuffer::Allocate(
    int32_t colorFormat = COLOR_FormatYUV420Flexible;
    (void)format->findInt32("color-format", &colorFormat);

    GraphicView2MediaImageConverter converter(*view, colorFormat);
    GraphicView2MediaImageConverter converter(*view, colorFormat, false /* copy */);
    if (converter.initCheck() != OK) {
        ALOGD("Converter init failed: %d", converter.initCheck());
        return nullptr;
@@ -708,7 +712,7 @@ bool ConstGraphicBlockBuffer::canCopy(const std::shared_ptr<C2Buffer> &buffer) c
    const_cast<ConstGraphicBlockBuffer *>(this)->format()->findInt32("color-format", &colorFormat);

    GraphicView2MediaImageConverter converter(
            buffer->data().graphicBlocks()[0].map().get(), colorFormat);
            buffer->data().graphicBlocks()[0].map().get(), colorFormat, true /* copy */);
    if (converter.initCheck() != OK) {
        ALOGD("ConstGraphicBlockBuffer::canCopy: converter init failed: %d", converter.initCheck());
        return false;
@@ -730,7 +734,7 @@ bool ConstGraphicBlockBuffer::copy(const std::shared_ptr<C2Buffer> &buffer) {
    format()->findInt32("color-format", &colorFormat);

    GraphicView2MediaImageConverter converter(
            buffer->data().graphicBlocks()[0].map().get(), colorFormat);
            buffer->data().graphicBlocks()[0].map().get(), colorFormat, true /* copy */);
    if (converter.initCheck() != OK) {
        ALOGD("ConstGraphicBlockBuffer::copy: converter init failed: %d", converter.initCheck());
        return false;
+4 −4
Original line number Diff line number Diff line
@@ -137,14 +137,14 @@ status_t ImageCopy(uint8_t *imgBase, const MediaImage2 *img, const C2GraphicView
        int32_t dst_stride_v = img->mPlane[2].mRowInc;
        if (IsNV12(view) && IsI420(img)) {
            if (!libyuv::NV12ToI420(src_y, src_stride_y, src_u, src_stride_u, dst_y, dst_stride_y,
                                    dst_u, dst_stride_u, dst_v, dst_stride_v, view.width(),
                                    view.height())) {
                                    dst_u, dst_stride_u, dst_v, dst_stride_v, view.crop().width,
                                    view.crop().height)) {
                return OK;
            }
        } else {
            if (!libyuv::I420ToNV12(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
                                    dst_y, dst_stride_y, dst_u, dst_stride_u, view.width(),
                                    view.height())) {
                                    dst_y, dst_stride_y, dst_u, dst_stride_u, view.crop().width,
                                    view.crop().height)) {
                return OK;
            }
        }