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

Commit 4802d350 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "libui: add support for android.hardware.graphics"

parents 5e18e96e 9ba189dc
Loading
Loading
Loading
Loading
+66 −0
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.
 */

#ifndef ANDROID_UI_GRALLOC_ALLOCATOR_H
#define ANDROID_UI_GRALLOC_ALLOCATOR_H

#include <string>

#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <utils/StrongPointer.h>

namespace android {

namespace Gralloc2 {

using hardware::graphics::allocator::V2_0::Error;
using hardware::graphics::allocator::V2_0::PixelFormat;
using hardware::graphics::allocator::V2_0::ProducerUsage;
using hardware::graphics::allocator::V2_0::ConsumerUsage;
using hardware::graphics::allocator::V2_0::BufferDescriptor;
using hardware::graphics::allocator::V2_0::Buffer;
using hardware::graphics::allocator::V2_0::IAllocator;

// Allocator is a wrapper to IAllocator, a proxy to server-side allocator.
class Allocator {
public:
    Allocator();

    // this will be removed and Allocator will be always valid
    bool valid() const { return (mService != nullptr); }

    std::string dumpDebugInfo() const;

    Error createBufferDescriptor(
            const IAllocator::BufferDescriptorInfo& descriptorInfo,
            BufferDescriptor& descriptor) const;
    void destroyBufferDescriptor(BufferDescriptor descriptor) const;

    Error allocate(BufferDescriptor descriptor, Buffer& buffer) const;
    void free(Buffer buffer) const;

    Error exportHandle(BufferDescriptor descriptor, Buffer buffer,
            native_handle_t*& bufferHandle) const;

private:
    sp<IAllocator> mService;
};

} // namespace Gralloc2

} // namespace android

#endif // ANDROID_UI_GRALLOC_ALLOCATOR_H
+127 −0
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.
 */

#ifndef ANDROID_UI_GRALLOC_MAPPER_H
#define ANDROID_UI_GRALLOC_MAPPER_H

#include <memory>

#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <system/window.h>

namespace android {

namespace Gralloc2 {

using hardware::graphics::allocator::V2_0::Error;
using hardware::graphics::allocator::V2_0::PixelFormat;
using hardware::graphics::allocator::V2_0::ProducerUsage;
using hardware::graphics::allocator::V2_0::ConsumerUsage;
using hardware::graphics::mapper::V2_0::FlexLayout;
using hardware::graphics::mapper::V2_0::BackingStore;
using hardware::graphics::mapper::V2_0::Device;
using hardware::graphics::mapper::V2_0::IMapper;

// Mapper is a wrapper to IMapper, a client-side graphics buffer mapper.
class Mapper {
public:
    Mapper();
    ~Mapper();

    // this will be removed and Mapper will be always valid
    bool valid() const { return (mMapper != nullptr); }

    Error retain(buffer_handle_t handle) const
    {
        return mMapper->retain(mDevice, handle);
    }

    void release(buffer_handle_t handle) const;

    Error getDimensions(buffer_handle_t handle,
            uint32_t& width, uint32_t& height) const
    {
        return mMapper->getDimensions(mDevice, handle, &width, &height);
    }

    Error getFormat(buffer_handle_t handle,
            PixelFormat& format) const
    {
        return mMapper->getFormat(mDevice, handle, &format);
    }

    Error getProducerUsageMask(buffer_handle_t handle,
            uint64_t& usageMask) const
    {
        return mMapper->getProducerUsageMask(mDevice, handle, &usageMask);
    }

    Error getConsumerUsageMask(buffer_handle_t handle,
            uint64_t& usageMask) const
    {
        return mMapper->getConsumerUsageMask(mDevice, handle, &usageMask);
    }

    Error getBackingStore(buffer_handle_t handle,
            BackingStore& store) const
    {
        return mMapper->getBackingStore(mDevice, handle, &store);
    }

    Error getStride(buffer_handle_t handle, uint32_t& stride) const
    {
        return mMapper->getStride(mDevice, handle, &stride);
    }

    Error getNumFlexPlanes(buffer_handle_t handle, uint32_t& numPlanes) const
    {
        return mMapper->getNumFlexPlanes(mDevice, handle, &numPlanes);
    }

    Error lock(buffer_handle_t handle,
            uint64_t producerUsageMask,
            uint64_t consumerUsageMask,
            const Device::Rect& accessRegion,
            int acquireFence, void*& data) const
    {
        return mMapper->lock(mDevice, handle,
                producerUsageMask, consumerUsageMask,
                &accessRegion, acquireFence, &data);
    }

    Error lock(buffer_handle_t handle,
            uint64_t producerUsageMask,
            uint64_t consumerUsageMask,
            const Device::Rect& accessRegion,
            int acquireFence, FlexLayout& flexLayout) const
    {
        return mMapper->lockFlex(mDevice, handle,
                producerUsageMask, consumerUsageMask,
                &accessRegion, acquireFence, &flexLayout);
    }

    int unlock(buffer_handle_t handle) const;

private:
    const IMapper* mMapper;
    Device* mDevice;
};

} // namespace Gralloc2

} // namespace android

#endif // ANDROID_UI_GRALLOC_MAPPER_H
+8 −0
Original line number Diff line number Diff line
@@ -32,7 +32,12 @@

namespace android {

namespace Gralloc2 {
class Allocator;
}

class Gralloc1Loader;
class GraphicBufferMapper;
class String8;

class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
@@ -86,6 +91,9 @@ private:
    GraphicBufferAllocator();
    ~GraphicBufferAllocator();

    const std::unique_ptr<const Gralloc2::Allocator> mAllocator;
    GraphicBufferMapper& mMapper;

    std::unique_ptr<Gralloc1::Loader> mLoader;
    std::unique_ptr<Gralloc1::Device> mDevice;
};
+11 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ namespace android {

// ---------------------------------------------------------------------------

namespace Gralloc2 {
class Mapper;
}

class Rect;

class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
@@ -57,11 +61,18 @@ public:

    status_t unlockAsync(buffer_handle_t handle, int *fenceFd);

    const Gralloc2::Mapper& getGrallocMapper() const
    {
        return *mMapper;
    }

private:
    friend class Singleton<GraphicBufferMapper>;

    GraphicBufferMapper();

    const std::unique_ptr<const Gralloc2::Mapper> mMapper;

    std::unique_ptr<Gralloc1::Loader> mLoader;
    std::unique_ptr<Gralloc1::Device> mDevice;
};
+9 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ cc_library_shared {
        "FrameStats.cpp",
        "Gralloc1.cpp",
        "Gralloc1On0Adapter.cpp",
        "GrallocAllocator.cpp",
        "GrallocMapper.cpp",
        "GraphicBuffer.cpp",
        "GraphicBufferAllocator.cpp",
        "GraphicBufferMapper.cpp",
@@ -55,10 +57,17 @@ cc_library_shared {
        "UiConfig.cpp",
    ],

    static_libs: [
        "android.hardware.graphics.mapper@2.0",
    ],

    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "libbinder",
        "libcutils",
        "libhardware",
        "libhidl",
        "libhwbinder",
        "libsync",
        "libutils",
        "liblog",
Loading