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

Commit d2cd2d1a authored by Carlos Martinez Romero's avatar Carlos Martinez Romero
Browse files

Use new view::Surface API.

Remove IGBP from SessionConfigurationUtils.

Most places calling this function are using a SurfaceType so we can do
the same here.

We are currently limitig the use of IGBPs outside of libgui to allow for
further development of bufferqueues without external breakages. More
information at go/warren-buffers.

BYPASS_IGBP_IGBC_API_REASON: this CL is part of the migration.
Bug: 342197849
Test: atest android.hardware.cts.CameraTest
Flag: com.android.graphics.libgui.flags.wb_libcameraservice

Change-Id: Id5738dde563122f6ba8882103d8fa776a5ef43ab
parent 81c93b6d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/view/Surface.h>
#include <gui/Flags.h>  // remove with WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
#include "camera2common.h"

using namespace std;
@@ -90,9 +91,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
                sp<Surface> surface = surfaceControl->getSurface();
                captureRequest->mSurfaceList.push_back(surface);
                if (fdp.ConsumeBool()) {
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
                    view::Surface surfaceShim = view::Surface::fromSurface(surface);
#else
                    view::Surface surfaceShim;
                    surfaceShim.name = String16((fdp.ConsumeRandomLengthString()).c_str());
                    surfaceShim.graphicBufferProducer = surface->getIGraphicBufferProducer();
#endif
                    surfaceShim.name = String16((fdp.ConsumeRandomLengthString()).c_str());
                    surfaceShim.writeToParcel(&parcelCamCaptureReq);
                }
                surface.clear();
+9 −21
Original line number Diff line number Diff line
@@ -1019,12 +1019,9 @@ binder::Status CameraDeviceClient::createStream(

        int mirrorMode = outputConfiguration.getMirrorMode(surface);
        sp<Surface> outSurface;
        res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
                isStreamInfoValid, outSurface, surface
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
                .graphicBufferProducer
#endif
                , mCameraIdStr,
        res = SessionConfigurationUtils::createConfiguredSurface(streamInfo,
                isStreamInfoValid, outSurface,
                flagtools::convertParcelableSurfaceTypeToSurface(surface), mCameraIdStr,
                mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
                streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);

@@ -1410,15 +1407,10 @@ binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
        OutputStreamInfo outInfo;
        sp<Surface> outSurface;
        int mirrorMode = outputConfiguration.getMirrorMode(newOutputsMap.valueAt(i));
        res = SessionConfigurationUtils::createSurfaceFromGbp(
        res = SessionConfigurationUtils::createConfiguredSurface(
                outInfo,
                /*isStreamInfoValid*/ false, outSurface,
                newOutputsMap
                        .valueAt(i)
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
                        .graphicBufferProducer
#endif
                ,
                flagtools::convertParcelableSurfaceTypeToSurface(newOutputsMap.valueAt(i)),
                mCameraIdStr, mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed,
                dynamicRangeProfile, streamUseCase, timestampBase, mirrorMode, colorSpace,
                /*respectSurfaceSize*/ false);
@@ -1815,15 +1807,11 @@ binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId

        sp<Surface> outSurface;
        int mirrorMode = outputConfiguration.getMirrorMode(surface);
        res = SessionConfigurationUtils::createSurfaceFromGbp(
        res = SessionConfigurationUtils::createConfiguredSurface(
                mStreamInfoMap[streamId], true /*isStreamInfoValid*/, outSurface,
                surface
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
                .graphicBufferProducer
#endif
                , mCameraIdStr, mDevice->infoPhysical(physicalId),
                sensorPixelModesUsed, dynamicRangeProfile, streamUseCase, timestampBase, mirrorMode,
                colorSpace, /*respectSurfaceSize*/ false);
                flagtools::convertParcelableSurfaceTypeToSurface(surface), mCameraIdStr,
                mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
                streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/ false);

        if (!res.isOk()) return res;

+12 −15
Original line number Diff line number Diff line
@@ -442,15 +442,15 @@ bool isStreamUseCaseSupported(int64_t streamUseCase,
    return false;
}

binder::Status createSurfaceFromGbp(
binder::Status createConfiguredSurface(
        OutputStreamInfo& streamInfo, bool isStreamInfoValid,
        sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp,
        sp<Surface>& out_surface, const sp<SurfaceType>& surface,
        const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
        const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile,
        int64_t streamUseCase, int timestampBase, int mirrorMode,
        int32_t colorSpace, bool respectSurfaceSize) {
    // bufferProducer must be non-null
    if (gbp == nullptr) {
    if ( flagtools::isSurfaceTypeValid(surface) == false ) {
        std::string msg = fmt::sprintf("Camera %s: Surface is NULL", logicalCameraId.c_str());
        ALOGW("%s: %s", __FUNCTION__, msg.c_str());
        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
@@ -461,7 +461,7 @@ binder::Status createSurfaceFromGbp(
    bool useAsync = false;
    uint64_t consumerUsage = 0;
    status_t err;
    if ((err = gbp->getConsumerUsage(&consumerUsage)) != OK) {
    if ((err = surface->getConsumerUsage(&consumerUsage)) != OK) {
        std::string msg = fmt::sprintf("Camera %s: Failed to query Surface consumer usage: %s (%d)",
                logicalCameraId.c_str(), strerror(-err), err);
        ALOGE("%s: %s", __FUNCTION__, msg.c_str());
@@ -481,8 +481,9 @@ binder::Status createSurfaceFromGbp(
    bool flexibleConsumer = (consumerUsage & disallowedFlags) == 0 &&
            (consumerUsage & allowedFlags) != 0;

    surface = new Surface(gbp, useAsync);
    ANativeWindow *anw = surface.get();
    out_surface = new Surface(flagtools::surfaceTypeToIGBP(surface), useAsync);

    ANativeWindow *anw = out_surface.get();

    int width, height, format;
    android_dataspace dataSpace;
@@ -921,15 +922,11 @@ convertToHALStreamCombination(
        for (auto& surface_type : surfaces) {
            sp<Surface> surface;
            int mirrorMode = it.getMirrorMode(surface_type);
            res = createSurfaceFromGbp(streamInfo, isStreamInfoValid, surface,
                                       surface_type
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
                                       .graphicBufferProducer
#endif
                                       , logicalCameraId,
                                       metadataChosen, sensorPixelModesUsed, dynamicRangeProfile,
                                       streamUseCase, timestampBase, mirrorMode, colorSpace,
                                       /*respectSurfaceSize*/ true);
            res = createConfiguredSurface(streamInfo, isStreamInfoValid, surface,
                                    flagtools::convertParcelableSurfaceTypeToSurface(surface_type),
                                    logicalCameraId,  metadataChosen, sensorPixelModesUsed,
                                    dynamicRangeProfile, streamUseCase, timestampBase, mirrorMode,
                                    colorSpace, /*respectSurfaceSize*/ true);

            if (!res.isOk()) return res;

+4 −4
Original line number Diff line number Diff line
@@ -104,11 +104,11 @@ bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format,
// check if format is not custom format
bool isPublicFormat(int32_t format);

// Create a Surface from an IGraphicBufferProducer. Returns error if
// IGraphicBufferProducer's property doesn't match with streamInfo
binder::Status createSurfaceFromGbp(
// Recreates a Surface from another Surface setting the controlledByApp correctly. Returns error if
// previous Surface property doesn't match with streamInfo
binder::Status createConfiguredSurface(
        camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid,
        sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp,
        sp<Surface>& out_surface, const sp<SurfaceType>& surface,
        const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
        const std::vector<int32_t> &sensorPixelModesUsed,  int64_t dynamicRangeProfile,
        int64_t streamUseCase, int timestampBase, int mirrorMode,