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

Commit dc3f0270 authored by Chia-I Wu's avatar Chia-I Wu Committed by android-build-merger
Browse files

graphics: add allocator HAL support library am: d6daa8dd am: 8615b567

am: 53cd26c8

Change-Id: I8af338181cc1bf4c7740e8fa63db4d733b27d3c1
parents 7c19ef13 53cd26c8
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
cc_library_headers {
    name: "android.hardware.graphics.allocator@2.0-hal",
    defaults: ["hidl_defaults"],
    vendor: true,
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",
    ],
    export_shared_lib_headers: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",
    ],
    export_include_dirs: ["include"],
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#ifndef LOG_TAG
#warning "Allocator.h included without LOG_TAG"
#endif

#include <memory>

#include <allocator-hal/2.0/AllocatorHal.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <log/log.h>

namespace android {
namespace hardware {
namespace graphics {
namespace allocator {
namespace V2_0 {
namespace hal {

using mapper::V2_0::BufferDescriptor;
using mapper::V2_0::Error;

namespace detail {

// AllocatorImpl implements IAllocator on top of AllocatorHal
template <typename IALLOCATOR, typename ALLOCATOR_HAL>
class AllocatorImpl : public IALLOCATOR {
   public:
    bool init(std::unique_ptr<ALLOCATOR_HAL> hal) {
        mHal = std::move(hal);
        return true;
    }

    // IAllocator 2.0 interface
    Return<void> dumpDebugInfo(IAllocator::dumpDebugInfo_cb hidl_cb) override {
        hidl_cb(mHal->dumpDebugInfo());
        return Void();
    }

    Return<void> allocate(const BufferDescriptor& descriptor, uint32_t count,
                          IAllocator::allocate_cb hidl_cb) override {
        uint32_t stride;
        std::vector<const native_handle_t*> buffers;
        Error error = mHal->allocateBuffers(descriptor, count, &stride, &buffers);
        if (error != Error::NONE) {
            hidl_cb(error, 0, hidl_vec<hidl_handle>());
            return Void();
        }

        hidl_vec<hidl_handle> hidlBuffers(buffers.cbegin(), buffers.cend());
        hidl_cb(Error::NONE, stride, hidlBuffers);

        // free the local handles
        mHal->freeBuffers(buffers);

        return Void();
    }

   protected:
    std::unique_ptr<ALLOCATOR_HAL> mHal;
};

}  // namespace detail

using Allocator = detail::AllocatorImpl<IAllocator, AllocatorHal>;

}  // namespace hal
}  // namespace V2_0
}  // namespace allocator
}  // namespace graphics
}  // namespace hardware
}  // namespace android
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <string>
#include <vector>

#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>

namespace android {
namespace hardware {
namespace graphics {
namespace allocator {
namespace V2_0 {
namespace hal {

using mapper::V2_0::BufferDescriptor;
using mapper::V2_0::Error;

class AllocatorHal {
   public:
    virtual ~AllocatorHal() = default;

    // dump the debug information
    virtual std::string dumpDebugInfo() = 0;

    // allocate buffers
    virtual Error allocateBuffers(const BufferDescriptor& descriptor, uint32_t count,
                                  uint32_t* outStride,
                                  std::vector<const native_handle_t*>* outBuffers) = 0;

    // free buffers
    virtual void freeBuffers(const std::vector<const native_handle_t*>& buffers) = 0;
};

}  // namespace hal
}  // namespace V2_0
}  // namespace allocator
}  // namespace graphics
}  // namespace hardware
}  // namespace android