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

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

Merge "VR: Update VR HWC to use buffer metadata passed by SurfaceFlinger" into oc-dev

parents 4f6a79a8 1f42e3a0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ staticLibraries = [
]

sharedLibraries = [
    "android.frameworks.vr.composer@1.0",
    "android.hardware.graphics.allocator@2.0",
    "android.hardware.graphics.composer@2.1",
    "libbinder",
+3 −3
Original line number Diff line number Diff line
@@ -1416,7 +1416,7 @@ void Layer::CommonLayerSetup() {

void Layer::Prepare() {
  int right, bottom;
  buffer_handle_t handle;
  sp<GraphicBuffer> handle;

  if (surface_) {
    // Only update the acquired buffer when one is either available or this is
@@ -1465,14 +1465,14 @@ void Layer::Prepare() {
    }
    right = acquired_buffer_.buffer()->width();
    bottom = acquired_buffer_.buffer()->height();
    handle = acquired_buffer_.buffer()->native_handle();
    handle = acquired_buffer_.buffer()->buffer()->buffer();
    acquire_fence_fd_.Reset(acquired_buffer_.ClaimAcquireFence().Release());
  } else {
    // TODO(jwcai) Note: this is the GPU compositor's layer, and we need the
    // mechanism to accept distorted layers from VrCore.
    right = direct_buffer_->width();
    bottom = direct_buffer_->height();
    handle = direct_buffer_->handle();
    handle = direct_buffer_->buffer();
    acquire_fence_fd_.Close();
  }

+73 −6
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#undef LOG_TAG
#define LOG_TAG "HwcComposer"

#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
#include <inttypes.h>
#include <log/log.h>
#include <gui/BufferQueue.h>
@@ -26,7 +25,6 @@

namespace android {

using frameworks::vr::composer::V1_0::IVrComposerClient;
using hardware::Return;
using hardware::hidl_vec;
using hardware::hidl_handle;
@@ -124,6 +122,41 @@ void Composer::CommandWriter::setLayerInfo(uint32_t type, uint32_t appId)
    endCommand();
}

void Composer::CommandWriter::setClientTargetMetadata(
        const IVrComposerClient::BufferMetadata& metadata)
{
    constexpr uint16_t kSetClientTargetMetadataLength = 7;
    beginCommand(
        static_cast<IComposerClient::Command>(
            IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA),
        kSetClientTargetMetadataLength);
    writeBufferMetadata(metadata);
    endCommand();
}

void Composer::CommandWriter::setLayerBufferMetadata(
        const IVrComposerClient::BufferMetadata& metadata)
{
    constexpr uint16_t kSetLayerBufferMetadataLength = 7;
    beginCommand(
        static_cast<IComposerClient::Command>(
            IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA),
        kSetLayerBufferMetadataLength);
    writeBufferMetadata(metadata);
    endCommand();
}

void Composer::CommandWriter::writeBufferMetadata(
        const IVrComposerClient::BufferMetadata& metadata)
{
    write(metadata.width);
    write(metadata.height);
    write(metadata.stride);
    write(metadata.layerCount);
    writeSigned(static_cast<int32_t>(metadata.format));
    write64(metadata.usage);
}

Composer::Composer(bool useVrComposer)
    : mWriter(kWriterInitialSize),
      mIsUsingVrComposer(useVrComposer)
@@ -426,12 +459,29 @@ Error Composer::setActiveConfig(Display display, Config config)
}

Error Composer::setClientTarget(Display display, uint32_t slot,
        const native_handle_t* target,
        const sp<GraphicBuffer>& target,
        int acquireFence, Dataspace dataspace,
        const std::vector<IComposerClient::Rect>& damage)
{
    mWriter.selectDisplay(display);
    mWriter.setClientTarget(slot, target, acquireFence, dataspace, damage);
    if (mIsUsingVrComposer && target.get()) {
        IVrComposerClient::BufferMetadata metadata = {
            .width = target->getWidth(),
            .height = target->getHeight(),
            .stride = target->getStride(),
            .layerCount = target->getLayerCount(),
            .format = static_cast<PixelFormat>(target->getPixelFormat()),
            .usage = target->getUsage(),
        };
        mWriter.setClientTargetMetadata(metadata);
    }

    const native_handle_t* handle = nullptr;
    if (target.get()) {
        handle = target->getNativeBuffer()->handle;
    }

    mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage);
    return Error::NONE;
}

@@ -502,11 +552,28 @@ Error Composer::setCursorPosition(Display display, Layer layer,
}

Error Composer::setLayerBuffer(Display display, Layer layer,
        uint32_t slot, const native_handle_t* buffer, int acquireFence)
        uint32_t slot, const sp<GraphicBuffer>& buffer, int acquireFence)
{
    mWriter.selectDisplay(display);
    mWriter.selectLayer(layer);
    mWriter.setLayerBuffer(slot, buffer, acquireFence);
    if (mIsUsingVrComposer && buffer.get()) {
        IVrComposerClient::BufferMetadata metadata = {
            .width = buffer->getWidth(),
            .height = buffer->getHeight(),
            .stride = buffer->getStride(),
            .layerCount = buffer->getLayerCount(),
            .format = static_cast<PixelFormat>(buffer->getPixelFormat()),
            .usage = buffer->getUsage(),
        };
        mWriter.setLayerBufferMetadata(metadata);
    }

    const native_handle_t* handle = nullptr;
    if (buffer.get()) {
        handle = buffer->getNativeBuffer()->handle;
    }

    mWriter.setLayerBuffer(slot, handle, acquireFence);
    return Error::NONE;
}

+13 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <utility>
#include <vector>

#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
#include <android/hardware/graphics/composer/2.1/IComposer.h>
#include <utils/StrongPointer.h>
#include <IComposerCommandBuffer.h>
@@ -31,6 +32,8 @@ namespace android {

namespace Hwc2 {

using android::frameworks::vr::composer::V1_0::IVrComposerClient;

using android::hardware::graphics::common::V1_0::ColorMode;
using android::hardware::graphics::common::V1_0::ColorTransform;
using android::hardware::graphics::common::V1_0::Dataspace;
@@ -179,7 +182,7 @@ public:
     * When target is not nullptr, the cache is updated with the new target.
     */
    Error setClientTarget(Display display, uint32_t slot,
            const native_handle_t* target,
            const sp<GraphicBuffer>& target,
            int acquireFence, Dataspace dataspace,
            const std::vector<IComposerClient::Rect>& damage);
    Error setColorMode(Display display, ColorMode mode);
@@ -199,7 +202,7 @@ public:
            int32_t x, int32_t y);
    /* see setClientTarget for the purpose of slot */
    Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
            const native_handle_t* buffer, int acquireFence);
            const sp<GraphicBuffer>& buffer, int acquireFence);
    Error setLayerSurfaceDamage(Display display, Layer layer,
            const std::vector<IComposerClient::Rect>& damage);
    Error setLayerBlendMode(Display display, Layer layer,
@@ -232,6 +235,14 @@ private:
        ~CommandWriter() override;

        void setLayerInfo(uint32_t type, uint32_t appId);
        void setClientTargetMetadata(
                const IVrComposerClient::BufferMetadata& metadata);
        void setLayerBufferMetadata(
                const IVrComposerClient::BufferMetadata& metadata);

    private:
        void writeBufferMetadata(
                const IVrComposerClient::BufferMetadata& metadata);
    };

    // Many public functions above simply write a command into the command
+14 −4
Original line number Diff line number Diff line
@@ -961,14 +961,19 @@ Error Display::setActiveConfig(const std::shared_ptr<const Config>& config)
    return static_cast<Error>(intError);
}

Error Display::setClientTarget(uint32_t slot, buffer_handle_t target,
Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target,
        const sp<Fence>& acquireFence, android_dataspace_t dataspace)
{
    // TODO: Properly encode client target surface damage
    int32_t fenceFd = acquireFence->dup();
#ifdef BYPASS_IHWC
    (void) slot;
    int32_t intError = mDevice.mSetClientTarget(mDevice.mHwcDevice, mId, target,
    buffer_handle_t handle = nullptr;
    if (target.get() && target->getNativeBuffer()) {
        handle = target->getNativeBuffer()->handle;
    }

    int32_t intError = mDevice.mSetClientTarget(mDevice.mHwcDevice, mId, handle,
            fenceFd, static_cast<int32_t>(dataspace), {0, nullptr});
#else
    auto intError = mDevice.mComposer->setClientTarget(mId, slot, target,
@@ -1195,14 +1200,19 @@ Error Layer::setCursorPosition(int32_t x, int32_t y)
    return static_cast<Error>(intError);
}

Error Layer::setBuffer(uint32_t slot, buffer_handle_t buffer,
Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer,
        const sp<Fence>& acquireFence)
{
    int32_t fenceFd = acquireFence->dup();
#ifdef BYPASS_IHWC
    (void) slot;
    buffer_handle_t handle = nullptr;
    if (buffer.get() && buffer->getNativeBuffer()) {
        handle = buffer->getNativeBuffer()->handle;
    }

    int32_t intError = mDevice.mSetLayerBuffer(mDevice.mHwcDevice, mDisplayId,
            mId, buffer, fenceFd);
            mId, handle, fenceFd);
#else
    auto intError = mDevice.mComposer->setLayerBuffer(mDisplayId,
            mId, slot, buffer, fenceFd);
Loading