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

Commit a6a30b1a authored by Marissa Wall's avatar Marissa Wall
Browse files

mapper: add isSupported

Add a function to the mapper hal that checks if a BufferDescriptorInfo
is ever supported on a device. This value can be cached by the client.
The client can use this information to make decisions on what type of
buffers should attempt to allocate.

Bug: 120493579
Test: vts
Change-Id: I6bd7909e40d6462524bf49cf0d4e7af721e701ed
parent 69292faf
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -285,5 +285,20 @@ interface IMapper {
     */
    unlock(pointer buffer) generates (Error error, handle releaseFence);

    /**
     * Test whether the given BufferDescriptorInfo is allocatable.
     *
     * If this function returns true, it means that a buffer with the given
     * description can be allocated on this implementation, unless resource
     * exhaustion occurs. If this function returns false, it means that the
     * allocation of the given description will never succeed.
     *
     * @param description the description of the buffer
     * @return supported whether the description is supported
     */
    isSupported(BufferDescriptorInfo description)
            generates (Error error,
                       bool supported);

};
+12 −0
Original line number Diff line number Diff line
@@ -176,6 +176,9 @@ void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
        acquireFenceHandle = h;
    }

    *outBytesPerPixel = -1;
    *outBytesPerStride = -1;

    void* data = nullptr;
    mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
                  [&](const auto& tmpError, const auto& tmpData, int32_t tmpBytesPerPixel,
@@ -268,6 +271,15 @@ void Gralloc::getTransportSize(const native_handle_t* bufferHandle, uint32_t* ou
        });
}

bool Gralloc::isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo) {
    bool supported = false;
    mMapper->isSupported(descriptorInfo, [&](const auto& tmpError, const auto& tmpSupported) {
        ASSERT_EQ(Error::NONE, tmpError) << "failed to check is supported";
        supported = tmpSupported;
    });
    return supported;
}

}  // namespace vts
}  // namespace V3_0
}  // namespace mapper
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ class Gralloc {
    void getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
                          uint32_t* outNumInts);

    bool isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo);

   private:
    void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);
    const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
+34 −0
Original line number Diff line number Diff line
@@ -440,6 +440,40 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) {
#endif
}

/**
 * Test IMapper::isSupported with required format RGBA_8888
 */
TEST_F(GraphicsMapperHidlTest, IsSupportedRGBA8888) {
    const auto& info = mDummyDescriptorInfo;
    bool supported = false;

    ASSERT_NO_FATAL_FAILURE(supported = mGralloc->isSupported(info));
    ASSERT_TRUE(supported);
}

/**
 * Test IMapper::isSupported with required format YV12
 */
TEST_F(GraphicsMapperHidlTest, IsSupportedYV12) {
    auto info = mDummyDescriptorInfo;
    info.format = PixelFormat::YV12;
    bool supported = false;

    ASSERT_NO_FATAL_FAILURE(supported = mGralloc->isSupported(info));
    ASSERT_TRUE(supported);
}

/**
 * Test IMapper::isSupported with optional format Y16
 */
TEST_F(GraphicsMapperHidlTest, IsSupportedY16) {
    auto info = mDummyDescriptorInfo;
    info.format = PixelFormat::Y16;
    bool supported = false;

    ASSERT_NO_FATAL_FAILURE(supported = mGralloc->isSupported(info));
}

}  // namespace
}  // namespace vts
}  // namespace V3_0