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

Commit 821c4c4a authored by Chia-I Wu's avatar Chia-I Wu
Browse files

graphics: make mapper default impl a header library

Reimplement the default impl as a header-only library,
android.hardware.graphics.mapper@2.0-passthrough, based on the HAL
support library.

Effectively, this renames Gralloc[01]Mapper to Gralloc[01]Hal, and
make adjustments here and there to meet the requirements of the HAL
support library.  This also adds GrallocLoader to load either of
Gralloc[01]Hal and create an IMapper instance.

libgrallocmapperincludes is renamed to follow the new naming and
include path conventions.

Test: boots and VTS
Change-Id: I924cadce9a10a6e544f99ceba63aadc38ec431ac
parent fd1924f6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -14,11 +14,11 @@ cc_library_headers {
    ],
    header_libs: [
        "android.hardware.graphics.allocator@2.0-hal",
        "libgrallocmapperincludes",
        "android.hardware.graphics.mapper@2.0-passthrough_headers",
    ],
    export_header_lib_headers: [
        "android.hardware.graphics.allocator@2.0-hal",
        "libgrallocmapperincludes",
        "android.hardware.graphics.mapper@2.0-passthrough_headers",
    ],
    export_include_dirs: ["include"],
}
+2 −2
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@

#include <cstring>  // for strerror

#include <GrallocBufferDescriptor.h>
#include <allocator-hal/2.0/AllocatorHal.h>
#include <hardware/gralloc.h>
#include <log/log.h>
#include <mapper-passthrough/2.0/GrallocBufferDescriptor.h>

namespace android {
namespace hardware {
@@ -38,7 +38,7 @@ namespace detail {

using mapper::V2_0::BufferDescriptor;
using mapper::V2_0::Error;
using mapper::V2_0::implementation::grallocDecodeBufferDescriptor;
using mapper::V2_0::passthrough::grallocDecodeBufferDescriptor;

// Gralloc0HalImpl implements V2_*::hal::AllocatorHal on top of gralloc0
template <typename Hal>
+2 −2
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@

#include <cstring>  // for strerror

#include <GrallocBufferDescriptor.h>
#include <allocator-hal/2.0/AllocatorHal.h>
#include <hardware/gralloc1.h>
#include <log/log.h>
#include <mapper-passthrough/2.0/GrallocBufferDescriptor.h>

namespace android {
namespace hardware {
@@ -39,7 +39,7 @@ namespace detail {
using common::V1_0::BufferUsage;
using mapper::V2_0::BufferDescriptor;
using mapper::V2_0::Error;
using mapper::V2_0::implementation::grallocDecodeBufferDescriptor;
using mapper::V2_0::passthrough::grallocDecodeBufferDescriptor;

// Gralloc1HalImpl implements V2_*::hal::AllocatorHal on top of gralloc1
template <typename Hal>
+5 −8
Original line number Diff line number Diff line
@@ -18,8 +18,10 @@ cc_library_shared {
    defaults: ["hidl_defaults"],
    vendor: true,
    relative_install_path: "hw",
    srcs: ["GrallocMapper.cpp", "Gralloc0Mapper.cpp", "Gralloc1Mapper.cpp"],
    cppflags: ["-Wall", "-Wextra"],
    srcs: ["passthrough.cpp"],
    header_libs: [
        "android.hardware.graphics.mapper@2.0-passthrough"
    ],
    shared_libs: [
        "android.hardware.graphics.mapper@2.0",
        "libbase",
@@ -31,10 +33,5 @@ cc_library_shared {
        "libsync",
        "libutils",
    ],
}

cc_library_headers {
    name: "libgrallocmapperincludes",
    vendor: true,
    export_include_dirs: ["."],
    cflags: ["-DLOG_TAG=\"MapperHal\""],
}
+0 −156
Original line number Diff line number Diff line
/*
 * Copyright 2016 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.
 */

#define LOG_TAG "Gralloc0Mapper"

#include "Gralloc0Mapper.h"

#include <log/log.h>

namespace android {
namespace hardware {
namespace graphics {
namespace mapper {
namespace V2_0 {
namespace implementation {

Gralloc0Mapper::Gralloc0Mapper(const hw_module_t* module)
    : mModule(reinterpret_cast<const gralloc_module_t*>(module)),
      mMinor(module->module_api_version & 0xff) {
    mCapabilities.highUsageBits = false;
    mCapabilities.layeredBuffers = false;
    mCapabilities.unregisterImplyDelete = false;
}

Error Gralloc0Mapper::registerBuffer(buffer_handle_t bufferHandle) {
    int result = mModule->registerBuffer(mModule, bufferHandle);
    return result ? Error::BAD_BUFFER : Error::NONE;
}

void Gralloc0Mapper::unregisterBuffer(buffer_handle_t bufferHandle) {
    mModule->unregisterBuffer(mModule, bufferHandle);
}

Error Gralloc0Mapper::lockBuffer(buffer_handle_t bufferHandle,
                                 uint64_t cpuUsage,
                                 const IMapper::Rect& accessRegion, int fenceFd,
                                 void** outData) {
    int result;
    void* data = nullptr;
    if (mMinor >= 3 && mModule->lockAsync) {
        // Dup fenceFd as it is going to be owned by gralloc.  Note that it is
        // gralloc's responsibility to close it, even on locking errors.
        if (fenceFd >= 0) {
            fenceFd = dup(fenceFd);
            if (fenceFd < 0) {
                return Error::NO_RESOURCES;
            }
        }

        result = mModule->lockAsync(mModule, bufferHandle, cpuUsage,
                                    accessRegion.left, accessRegion.top,
                                    accessRegion.width, accessRegion.height,
                                    &data, fenceFd);
    } else {
        waitFenceFd(fenceFd, "Gralloc0Mapper::lock");

        result = mModule->lock(mModule, bufferHandle, cpuUsage,
                               accessRegion.left, accessRegion.top,
                               accessRegion.width, accessRegion.height, &data);
    }

    if (result) {
        return Error::BAD_VALUE;
    } else {
        *outData = data;
        return Error::NONE;
    }
}

Error Gralloc0Mapper::lockBuffer(buffer_handle_t bufferHandle,
                                 uint64_t cpuUsage,
                                 const IMapper::Rect& accessRegion, int fenceFd,
                                 YCbCrLayout* outLayout) {
    int result;
    android_ycbcr ycbcr = {};
    if (mMinor >= 3 && mModule->lockAsync_ycbcr) {
        // Dup fenceFd as it is going to be owned by gralloc.  Note that it is
        // gralloc's responsibility to close it, even on locking errors.
        if (fenceFd >= 0) {
            fenceFd = dup(fenceFd);
            if (fenceFd < 0) {
                return Error::NO_RESOURCES;
            }
        }

        result = mModule->lockAsync_ycbcr(mModule, bufferHandle, cpuUsage,
                                          accessRegion.left, accessRegion.top,
                                          accessRegion.width,
                                          accessRegion.height, &ycbcr, fenceFd);
    } else {
        waitFenceFd(fenceFd, "Gralloc0Mapper::lockYCbCr");

        if (mModule->lock_ycbcr) {
            result = mModule->lock_ycbcr(mModule, bufferHandle, cpuUsage,
                                         accessRegion.left, accessRegion.top,
                                         accessRegion.width,
                                         accessRegion.height, &ycbcr);
        } else {
            result = -EINVAL;
        }
    }

    if (result) {
        return Error::BAD_VALUE;
    } else {
        outLayout->y = ycbcr.y;
        outLayout->cb = ycbcr.cb;
        outLayout->cr = ycbcr.cr;
        outLayout->yStride = ycbcr.ystride;
        outLayout->cStride = ycbcr.cstride;
        outLayout->chromaStep = ycbcr.chroma_step;
        return Error::NONE;
    }
}

Error Gralloc0Mapper::unlockBuffer(buffer_handle_t bufferHandle,
                                   int* outFenceFd) {
    int result;
    int fenceFd = -1;
    if (mMinor >= 3 && mModule->unlockAsync) {
        result = mModule->unlockAsync(mModule, bufferHandle, &fenceFd);
    } else {
        result = mModule->unlock(mModule, bufferHandle);
    }

    if (result) {
        // we always own the fenceFd even when unlock failed
        if (fenceFd >= 0) {
            close(fenceFd);
        }

        return Error::BAD_VALUE;
    } else {
        *outFenceFd = fenceFd;
        return Error::NONE;
    }
}

}  // namespace implementation
}  // namespace V2_0
}  // namespace mapper
}  // namespace graphics
}  // namespace hardware
}  // namespace android
Loading