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

Commit fe02df8c authored by Devin Moore's avatar Devin Moore Committed by Gerrit Code Review
Browse files

Merge "Create test with AImageReader_getWindow to IGBP" into main

parents 46f1046b 4f9217bc
Loading
Loading
Loading
Loading
+70 −52
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <media/NdkImage.h>
#include <mediautils/AImageReaderUtils.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
#include <NdkImagePriv.h>
#include <NdkImageReaderPriv.h>
@@ -112,14 +113,6 @@ class AImageReaderWindowHandleTest : public ::testing::Test {
    static void onBufferRemoved(void *, AImageReader *, AHardwareBuffer *) {
    }

    AImageReader *imageReader_ = nullptr;
    AImageReader_ImageListener imageReaderAvailableCb_{this, onImageAvailable};
    AImageReader_BufferRemovedListener imageReaderDetachedCb_{this, onBufferRemoved};
    std::mutex imageAvailableMutex_;
    std::condition_variable imageCondVar_;
    bool imageAvailable_ = false;
};

    static void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
        const size_t PIXEL_SIZE = 4;
        for (int x = 0; x < w; x++) {
@@ -134,29 +127,7 @@ static void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
        }
    }

TEST_F(AImageReaderWindowHandleTest, CreateWindowNativeHandle) {
    // Check that we can create a native_handle_t corresponding to the
    // AImageReader.
    native_handle_t *nh = nullptr;
    media_status_t status = AImageReader_getWindowNativeHandle(imageReader_, &nh);

    // On newer devices without the HIDL TokenManager service this API is
    // deprecated and will return an error.
    if (IServiceManager::Transport::EMPTY ==
        hardware::defaultServiceManager1_2()->getTransport(ITokenManager::descriptor, "default")) {
      EXPECT_EQ(status, AMEDIA_ERROR_UNKNOWN);
      return;
    }
    ASSERT_NE(nh, nullptr);

    // Check that there are only ints in the handle.
    ASSERT_EQ(nh->numFds, 0);
    ASSERT_NE(nh->numInts, 0);

    // Check that the HGBP can be retrieved from the handle.
    sp<HGraphicBufferProducer> hgbp =  AImageReader_getHGBPFromHandle(nh);
    ASSERT_NE(hgbp, nullptr);
    sp<IGraphicBufferProducer> igbp = new H2BGraphicBufferProducer(hgbp);
    void validateIGBP(sp<IGraphicBufferProducer>& igbp) {
        int dequeuedSlot = -1;
        sp<Fence> dequeuedFence;
        IGraphicBufferProducer::QueueBufferOutput output;
@@ -177,7 +148,7 @@ TEST_F(AImageReaderWindowHandleTest, CreateWindowNativeHandle) {
        uint8_t* img = nullptr;
        ASSERT_EQ(NO_ERROR, dequeuedBuffer->lock(kImageBufferUsage, (void**)(&img)));

    // Write in some dummy image data.
        // Write in some placeholder image data.
        fillRGBA8Buffer(img, dequeuedBuffer->getWidth(), dequeuedBuffer->getHeight(),
                        dequeuedBuffer->getStride());
        ASSERT_EQ(NO_ERROR, dequeuedBuffer->unlock());
@@ -198,6 +169,53 @@ TEST_F(AImageReaderWindowHandleTest, CreateWindowNativeHandle) {
        EXPECT_TRUE(imageAvailable_) <<  "Timed out waiting for image data to be handled!\n";
    }

    AImageReader *imageReader_ = nullptr;
    AImageReader_ImageListener imageReaderAvailableCb_{this, onImageAvailable};
    AImageReader_BufferRemovedListener imageReaderDetachedCb_{this, onBufferRemoved};
    std::mutex imageAvailableMutex_;
    std::condition_variable imageCondVar_;
    bool imageAvailable_ = false;
};


TEST_F(AImageReaderWindowHandleTest, CreateWindowNativeHandle) {
    // Check that we can create a native_handle_t corresponding to the
    // AImageReader.
    native_handle_t *nh = nullptr;
    media_status_t status = AImageReader_getWindowNativeHandle(imageReader_, &nh);

    // On newer devices without the HIDL TokenManager service this API is
    // deprecated and will return an error.
    if (IServiceManager::Transport::EMPTY ==
        hardware::defaultServiceManager1_2()->getTransport(ITokenManager::descriptor, "default")) {
      EXPECT_EQ(status, AMEDIA_ERROR_UNKNOWN);
      return;
    }
    ASSERT_NE(nh, nullptr);

    // Check that there are only ints in the handle.
    ASSERT_EQ(nh->numFds, 0);
    ASSERT_NE(nh->numInts, 0);

    // Check that the HGBP can be retrieved from the handle.
    sp<HGraphicBufferProducer> hgbp =  AImageReader_getHGBPFromHandle(nh);
    ASSERT_NE(hgbp, nullptr);
    sp<IGraphicBufferProducer> igbp = new H2BGraphicBufferProducer(hgbp);

    validateIGBP(igbp);
}

TEST_F(AImageReaderWindowHandleTest, CreateWindow) {
    ANativeWindow* window = nullptr;
    media_status_t status = AImageReader_getWindow(imageReader_, &window);

    ASSERT_NE(window, nullptr);

    sp<IGraphicBufferProducer> igbp = Surface::getIGraphicBufferProducer(window);

    validateIGBP(igbp);
}

class AImageReaderPrivateFormatTest : public ::testing::Test {
  public:
    void SetUp() override {