codec2: set crop window of C2GraphicBlock passed to framework

Crop window (a.k.a. visible size) is a parameter of output pictures which is
different than coded size (the real size of a graphic buffer). For a encoded
stream, crop window is fixed while coded size could vary by codec driver (crop
window must be not larger than coded size)).

Crop window information should be filled when the component shared
C2ConstGraphicBlock instance and passed to framework.

Bug: 77941729
Test: native tests on eve-arcnext
Test: adb shell /data/local/tmp/C2VDAComponent_test/C2VDAComponent_test -i /data/local/tmp/C2VDAComponent_test/bear.mp4:c2.vda.avc.decoder:640:360:82:84
Change-Id: I3fd33f66e95df569fd4d35b66179f9d4de7adc33
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index 7718229..8a25388 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -458,7 +458,7 @@
 
 class C2VDAGraphicBuffer : public C2Buffer {
 public:
-    C2VDAGraphicBuffer(const std::shared_ptr<C2GraphicBlock>& block,
+    C2VDAGraphicBuffer(const std::shared_ptr<C2GraphicBlock>& block, const media::Rect& visibleRect,
                        const base::Closure& releaseCB);
     ~C2VDAGraphicBuffer() override;
 
@@ -467,8 +467,9 @@
 };
 
 C2VDAGraphicBuffer::C2VDAGraphicBuffer(const std::shared_ptr<C2GraphicBlock>& block,
+                                       const media::Rect& visibleRect,
                                        const base::Closure& releaseCB)
-      : C2Buffer({block->share(C2Rect(block->width(), block->height()), C2Fence())}),
+      : C2Buffer({block->share(C2Rect(visibleRect.width(), visibleRect.height()), C2Fence())}),
         mReleaseCB(releaseCB) {}
 
 C2VDAGraphicBuffer::~C2VDAGraphicBuffer() {
@@ -703,8 +704,9 @@
 
     // Attach output buffer to the work corresponded to bitstreamId.
     work->worklets.front()->output.buffers.emplace_back(std::make_shared<C2VDAGraphicBuffer>(
-            info->mGraphicBlock, base::Bind(&C2VDAComponent::returnOutputBuffer,
-                                            mWeakThisFactory.GetWeakPtr(), pictureBufferId)));
+            info->mGraphicBlock, mOutputFormat.mVisibleRect,
+            base::Bind(&C2VDAComponent::returnOutputBuffer, mWeakThisFactory.GetWeakPtr(),
+                       pictureBufferId)));
 
     // TODO: this does not work for timestamps as they can wrap around
     int64_t currentTimestamp = base::checked_cast<int64_t>(work->input.ordinal.timestamp.peek());
@@ -1093,9 +1095,9 @@
 
 void C2VDAComponent::setOutputFormatCrop(const media::Rect& cropRect) {
     ALOGV("setOutputFormatCrop(%dx%d)", cropRect.width(), cropRect.height());
+    // This visible rect should be set as crop window for each C2ConstGraphicBlock passed to
+    // framework.
     mOutputFormat.mVisibleRect = cropRect;
-    // TODO(johnylin): what else do we need to do? crop rect could be an info requested from
-    // framework by requestedInfos in worklets.
 }
 
 c2_status_t C2VDAComponent::queue_nb(std::list<std::unique_ptr<C2Work>>* const items) {
diff --git a/tests/C2VDAComponent_test.cpp b/tests/C2VDAComponent_test.cpp
index efbba6e..ca4f476 100644
--- a/tests/C2VDAComponent_test.cpp
+++ b/tests/C2VDAComponent_test.cpp
@@ -111,9 +111,9 @@
 // - |width| and |height| are for video size (in pixels).
 // - |numFrames| is the number of picture frames.
 // - |numFragments| is the NALU (h264) or frame (VP8/9) count by MediaExtractor.
-const char* gTestVideoData = "bear.mp4:c2.vda.avc.decoder:640:368:82:84";
-//const char* gTestVideoData = "bear-vp8.webm:c2.vda.vp8.decoder:640:368:82:82";
-//const char* gTestVideoData = "bear-vp9.webm:c2.vda.vp9.decoder:320:256:82:82";
+const char* gTestVideoData = "bear.mp4:c2.vda.avc.decoder:640:360:82:84";
+//const char* gTestVideoData = "bear-vp8.webm:c2.vda.vp8.decoder:640:360:82:82";
+//const char* gTestVideoData = "bear-vp9.webm:c2.vda.vp9.decoder:320:240:82:82";
 
 // Record decoded output frames as raw YUV format.
 // The recorded file will be named as "<video_name>_output_<width>x<height>.yuv" under the same
@@ -506,8 +506,16 @@
             if (work->worklets.front()->output.buffers.size() == 1u) {
                 std::shared_ptr<C2Buffer> output = work->worklets.front()->output.buffers[0];
                 C2ConstGraphicBlock graphicBlock = output->data().graphicBlocks().front();
-                ASSERT_EQ(mTestVideoFile->mWidth, static_cast<int>(graphicBlock.width()));
-                ASSERT_EQ(mTestVideoFile->mHeight, static_cast<int>(graphicBlock.height()));
+
+                // check graphic buffer size (coded size) is not less than given video size.
+                ASSERT_LE(mTestVideoFile->mWidth, static_cast<int>(graphicBlock.width()));
+                ASSERT_LE(mTestVideoFile->mHeight, static_cast<int>(graphicBlock.height()));
+
+                // check visible rect equals to given video size.
+                ASSERT_EQ(mTestVideoFile->mWidth, static_cast<int>(graphicBlock.crop().width));
+                ASSERT_EQ(mTestVideoFile->mHeight, static_cast<int>(graphicBlock.crop().height));
+                ASSERT_EQ(0u, graphicBlock.crop().left);
+                ASSERT_EQ(0u, graphicBlock.crop().top);
 
                 const C2GraphicView& constGraphicView = graphicBlock.map().get();
                 ASSERT_EQ(C2_OK, constGraphicView.error());
diff --git a/tests/data/bear-vp8.webm.md5 b/tests/data/bear-vp8.webm.md5
index 58ce33f..658ad86 100644
--- a/tests/data/bear-vp8.webm.md5
+++ b/tests/data/bear-vp8.webm.md5
@@ -1,3 +1,3 @@
-# gTestVideoData = "bear-vp8.webm:v4l2.vp8.decode:640:368:82:82"
+# gTestVideoData = "bear-vp8.webm:c2.vda.vp8.decoder:640:360:82:82"
 # ARM - Mali
 056a2484b34bc78637b37b36481027c6
diff --git a/tests/data/bear-vp9.webm.md5 b/tests/data/bear-vp9.webm.md5
index 093f40e..8b06682 100644
--- a/tests/data/bear-vp9.webm.md5
+++ b/tests/data/bear-vp9.webm.md5
@@ -1,3 +1,3 @@
-# gTestVideoData = "bear-vp9.webm:v4l2.vp9.decode:320:256:82:82"
+# gTestVideoData = "bear-vp9.webm:c2.vda.vp9.decoder:320:240:82:82"
 # ARM - Mali
 7228c16473724e4dff2fc55edcf94683
diff --git a/tests/data/bear.mp4.md5 b/tests/data/bear.mp4.md5
index 388da15..027da77 100644
--- a/tests/data/bear.mp4.md5
+++ b/tests/data/bear.mp4.md5
@@ -1,3 +1,3 @@
-# gTestVideoData = "bear.mp4:v4l2.h264.decode:640:368:82:84"
+# gTestVideoData = "bear.mp4:c2.vda.avc.decoder:640:360:82:84"
 # ARM - Mali
 a3ea733a472e222608d690e91e6c88cc