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

Commit 0a0e31c4 authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'hals-should-use-mapper' into oc-dev

* changes:
  graphics: use mapper from the composer
  graphics: clarify importBuffer and passthrough HALs
parents 1fd47b29 2ae85702
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -103,7 +103,7 @@ b3aac6c3817f039964fcd62268274b3039e17bd7d0d5b40b4d1d1c7b19a1f866 android.hardwar
b19d00eb8a8b3b0034a0321f22e8f32162bf4c2aebbce6da22c025f56e459ea2 android.hardware.graphics.composer@2.1::IComposerCallback
b19d00eb8a8b3b0034a0321f22e8f32162bf4c2aebbce6da22c025f56e459ea2 android.hardware.graphics.composer@2.1::IComposerCallback
e992684e690dfe67a8cbeab5005bfa3fa9c2bf3d4b0b75657fb1f0c2d5dd2bae android.hardware.graphics.composer@2.1::IComposerClient
e992684e690dfe67a8cbeab5005bfa3fa9c2bf3d4b0b75657fb1f0c2d5dd2bae android.hardware.graphics.composer@2.1::IComposerClient
1c98c2f5154345312ec054871792a2982ec5f3e2bc2abfb61a10c0b517978e20 android.hardware.graphics.composer@2.1::types
1c98c2f5154345312ec054871792a2982ec5f3e2bc2abfb61a10c0b517978e20 android.hardware.graphics.composer@2.1::types
04fbe91f2a860d463fa6287fbcfa05a8cc4f17848cabcd2aa9eef0f2aa1fedc0 android.hardware.graphics.mapper@2.0::IMapper
a695898589e1ef15b2b2510f11edd6aafac9918d9cf8d74b4b6143b309dee542 android.hardware.graphics.mapper@2.0::IMapper
28507d385a3dd224bf3c32f1bfd9f96092c4701b9c1cc66caa578fc3efc97877 android.hardware.graphics.mapper@2.0::types
28507d385a3dd224bf3c32f1bfd9f96092c4701b9c1cc66caa578fc3efc97877 android.hardware.graphics.mapper@2.0::types
91e2ba3805c923f01fc1231ec9ff838942aee3346f2d7614ecc0caeadbe57ed4 android.hardware.health@1.0::IHealth
91e2ba3805c923f01fc1231ec9ff838942aee3346f2d7614ecc0caeadbe57ed4 android.hardware.health@1.0::IHealth
1275aa2e8732909101b26aec49ed2285489e89d97b8610a8908b7868e35a3cc5 android.hardware.health@1.0::types
1275aa2e8732909101b26aec49ed2285489e89d97b8610a8908b7868e35a3cc5 android.hardware.health@1.0::types
+2 −3
Original line number Original line Diff line number Diff line
@@ -5,8 +5,8 @@ cc_library_static {
    export_include_dirs: ["."],
    export_include_dirs: ["."],
    srcs: ["ComposerClient.cpp"],
    srcs: ["ComposerClient.cpp"],
    shared_libs: [
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0",
        "libbase",
        "libbase",
        "libcutils",
        "libcutils",
        "libfmq",
        "libfmq",
@@ -27,8 +27,8 @@ cc_library_shared {
    srcs: ["Hwc.cpp"],
    srcs: ["Hwc.cpp"],
    static_libs: ["libhwcomposer-client"],
    static_libs: ["libhwcomposer-client"],
    shared_libs: [
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0",
        "libbase",
        "libbase",
        "libcutils",
        "libcutils",
        "libfmq",
        "libfmq",
@@ -51,7 +51,6 @@ cc_binary {
    init_rc: ["android.hardware.graphics.composer@2.1-service.rc"],
    init_rc: ["android.hardware.graphics.composer@2.1-service.rc"],
    static_libs: ["libhwcomposer-client"],
    static_libs: ["libhwcomposer-client"],
    shared_libs: [
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.1",
        "libbase",
        "libbase",
        "libbinder",
        "libbinder",
+20 −108
Original line number Original line Diff line number Diff line
@@ -16,8 +16,7 @@


#define LOG_TAG "HwcPassthrough"
#define LOG_TAG "HwcPassthrough"


#include <hardware/gralloc.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <hardware/gralloc1.h>
#include <log/log.h>
#include <log/log.h>


#include "ComposerClient.h"
#include "ComposerClient.h"
@@ -33,10 +32,11 @@ namespace implementation {


namespace {
namespace {


using MapperError = android::hardware::graphics::mapper::V2_0::Error;
using android::hardware::graphics::mapper::V2_0::IMapper;

class HandleImporter {
class HandleImporter {
public:
public:
    HandleImporter() : mInitialized(false) {}

    bool initialize()
    bool initialize()
    {
    {
        // allow only one client
        // allow only one client
@@ -44,9 +44,7 @@ public:
            return false;
            return false;
        }
        }


        if (!openGralloc()) {
        mMapper = IMapper::getService();
            return false;
        }


        mInitialized = true;
        mInitialized = true;
        return true;
        return true;
@@ -54,11 +52,7 @@ public:


    void cleanup()
    void cleanup()
    {
    {
        if (!mInitialized) {
        mMapper.clear();
            return;
        }

        closeGralloc();
        mInitialized = false;
        mInitialized = false;
    }
    }


@@ -76,12 +70,20 @@ public:
            return true;
            return true;
        }
        }


        buffer_handle_t clone = cloneBuffer(handle);
        MapperError error;
        if (!clone) {
        buffer_handle_t importedHandle;
        mMapper->importBuffer(
            hidl_handle(handle),
            [&](const auto& tmpError, const auto& tmpBufferHandle) {
                error = tmpError;
                importedHandle = static_cast<buffer_handle_t>(tmpBufferHandle);
            });
        if (error != MapperError::NONE) {
            return false;
            return false;
        }
        }


        handle = clone;
        handle = importedHandle;

        return true;
        return true;
    }
    }


@@ -91,102 +93,12 @@ public:
            return;
            return;
        }
        }


        releaseBuffer(handle);
        mMapper->freeBuffer(const_cast<native_handle_t*>(handle));
    }
    }


private:
private:
    bool mInitialized;
 bool mInitialized = false;

 sp<IMapper> mMapper;
    // Some existing gralloc drivers do not support retaining more than once,
    // when we are in passthrough mode.
    bool openGralloc()
    {
        const hw_module_t* module = nullptr;
        int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
        if (err) {
            ALOGE("failed to get gralloc module");
            return false;
        }

        uint8_t major = (module->module_api_version >> 8) & 0xff;
        if (major > 1) {
            ALOGE("unknown gralloc module major version %d", major);
            return false;
        }

        if (major == 1) {
            err = gralloc1_open(module, &mDevice);
            if (err) {
                ALOGE("failed to open gralloc1 device");
                return false;
            }

            mRetain = reinterpret_cast<GRALLOC1_PFN_RETAIN>(
                    mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RETAIN));
            mRelease = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
                    mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RELEASE));
            if (!mRetain || !mRelease) {
                ALOGE("invalid gralloc1 device");
                gralloc1_close(mDevice);
                return false;
            }
        } else {
            mModule = reinterpret_cast<const gralloc_module_t*>(module);
        }

        return true;
    }

    void closeGralloc()
    {
        if (mDevice) {
            gralloc1_close(mDevice);
        }
    }

    buffer_handle_t cloneBuffer(buffer_handle_t handle)
    {
        native_handle_t* clone = native_handle_clone(handle);
        if (!clone) {
            ALOGE("failed to clone buffer %p", handle);
            return nullptr;
        }

        bool err;
        if (mDevice) {
            err = (mRetain(mDevice, clone) != GRALLOC1_ERROR_NONE);
        } else {
            err = (mModule->registerBuffer(mModule, clone) != 0);
        }

        if (err) {
            ALOGE("failed to retain/register buffer %p", clone);
            native_handle_close(clone);
            native_handle_delete(clone);
            return nullptr;
        }

        return clone;
    }

    void releaseBuffer(buffer_handle_t handle)
    {
        if (mDevice) {
            mRelease(mDevice, handle);
        } else {
            mModule->unregisterBuffer(mModule, handle);
        }
        native_handle_close(handle);
        native_handle_delete(const_cast<native_handle_t*>(handle));
    }

    // gralloc1
    gralloc1_device_t* mDevice;
    GRALLOC1_PFN_RETAIN mRetain;
    GRALLOC1_PFN_RELEASE mRelease;

    // gralloc0
    const gralloc_module_t* mModule;
};
};


HandleImporter sHandleImporter;
HandleImporter sHandleImporter;
+11 −4
Original line number Original line Diff line number Diff line
@@ -85,10 +85,11 @@ interface IMapper {
     * Imports a raw buffer handle to create an imported buffer handle for use
     * Imports a raw buffer handle to create an imported buffer handle for use
     * with the rest of the mapper or with other in-process libraries.
     * with the rest of the mapper or with other in-process libraries.
     *
     *
     * A buffer handle is considered raw when it is cloned or when it is
     * A buffer handle is considered raw when it is cloned (e.g., with
     * received from another HAL or another process. A raw buffer handle must
     * native_handle_clone) from another buffer handle locally, or when it is
     * not be used to access the underlying graphics buffer. It must be
     * received from another HAL server/client or another process. A raw
     * imported to create an imported handle first.
     * buffer handle must not be used to access the underlying graphics
     * buffer. It must be imported to create an imported handle first.
     *
     *
     * This function must at least validate the raw handle before creating the
     * This function must at least validate the raw handle before creating the
     * imported handle. It must also support importing the same raw handle
     * imported handle. It must also support importing the same raw handle
@@ -96,6 +97,12 @@ interface IMapper {
     * must be considered valid everywhere in the process, including in
     * must be considered valid everywhere in the process, including in
     * another instance of the mapper.
     * another instance of the mapper.
     *
     *
     * Because of passthrough HALs, a raw buffer handle received from a HAL
     * may actually have been imported in the process. importBuffer must treat
     * such a handle as if it is raw and must not return BAD_BUFFER. The
     * returned handle is independent from the input handle as usual, and
     * freeBuffer must be called on it when it is no longer needed.
     *
     * @param rawHandle is the raw buffer handle to import.
     * @param rawHandle is the raw buffer handle to import.
     * @return error is NONE upon success. Otherwise,
     * @return error is NONE upon success. Otherwise,
     *                  BAD_BUFFER when the raw handle is invalid.
     *                  BAD_BUFFER when the raw handle is invalid.
+2 −5
Original line number Original line Diff line number Diff line
@@ -125,11 +125,8 @@ Return<void> GrallocMapper::createDescriptor(


Return<void> GrallocMapper::importBuffer(const hidl_handle& rawHandle,
Return<void> GrallocMapper::importBuffer(const hidl_handle& rawHandle,
                                         importBuffer_cb hidl_cb) {
                                         importBuffer_cb hidl_cb) {
    // importing an already imported handle rather than a raw handle
    // because of passthrough HALs, we must not generate an error when
    if (gRegisteredHandles->get(rawHandle.getNativeHandle())) {
    // rawHandle has been imported
        hidl_cb(Error::BAD_BUFFER, nullptr);
        return Void();
    }


    if (!rawHandle.getNativeHandle()) {
    if (!rawHandle.getNativeHandle()) {
        hidl_cb(Error::BAD_BUFFER, nullptr);
        hidl_cb(Error::BAD_BUFFER, nullptr);
Loading