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

Commit be80b606 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "c2aidl"

* changes:
  Make ANativeWindow available over stable AIDL
  Support AHB in AIDL
parents 80170d5f 19055a2e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,4 +17,4 @@

package android.view;

parcelable Surface cpp_header "gui/view/Surface.h";
@JavaOnlyStableParcelable @NdkOnlyStableParcelable parcelable Surface cpp_header "gui/view/Surface.h" ndk_header "android/native_window_aidl.h";
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ typedef struct ARect {
} ARect;

#ifdef __cplusplus
};
}
#endif

#endif // ANDROID_RECT_H
+18 −0
Original line number Diff line number Diff line
@@ -111,6 +111,24 @@ public:
        return surface != nullptr && surface->getIGraphicBufferProducer() != nullptr;
    }

    static sp<IGraphicBufferProducer> getIGraphicBufferProducer(ANativeWindow* window) {
        int val;
        if (window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &val) >= 0 &&
            val == NATIVE_WINDOW_SURFACE) {
            return ((Surface*) window)->mGraphicBufferProducer;
        }
        return nullptr;
    }

    static sp<IBinder> getSurfaceControlHandle(ANativeWindow* window) {
        int val;
        if (window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &val) >= 0 &&
            val == NATIVE_WINDOW_SURFACE) {
            return ((Surface*) window)->mSurfaceControlHandle;
        }
        return nullptr;
    }

    /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
     *
     * A sideband stream is a device-specific mechanism for passing buffers
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#define LOG_TAG "AHardwareBuffer"

#include <android/hardware_buffer.h>
#include <android/hardware_buffer_aidl.h>
#include <vndk/hardware_buffer.h>

#include <errno.h>
@@ -32,6 +34,9 @@
#include <android/hardware/graphics/common/1.1/types.h>
#include <aidl/android/hardware/graphics/common/PixelFormat.h>

// TODO: Better way to handle this
#include "../binder/ndk/parcel_internal.h"

static constexpr int kFdBufferSize = 128 * sizeof(int);  // 128 ints

using namespace android;
@@ -412,6 +417,25 @@ int AHardwareBuffer_getId(const AHardwareBuffer* buffer, uint64_t* outId) {
    return OK;
}

binder_status_t AHardwareBuffer_readFromParcel(const AParcel* _Nonnull parcel,
        AHardwareBuffer* _Nullable* _Nonnull outBuffer) {
    if (!parcel || !outBuffer) return STATUS_BAD_VALUE;
    auto buffer = sp<GraphicBuffer>::make();
    status_t status = parcel->get()->read(*buffer);
    if (status != STATUS_OK) return status;
    *outBuffer = AHardwareBuffer_from_GraphicBuffer(buffer.get());
    AHardwareBuffer_acquire(*outBuffer);
    return STATUS_OK;
}

binder_status_t AHardwareBuffer_writeToParcel(const AHardwareBuffer* _Nonnull buffer,
        AParcel* _Nonnull parcel) {
    const GraphicBuffer* gb = AHardwareBuffer_to_GraphicBuffer(buffer);
    if (!gb) return STATUS_BAD_VALUE;
    if (!parcel) return STATUS_BAD_VALUE;
    return parcel->get()->write(*gb);
}

// ----------------------------------------------------------------------------
// VNDK functions
// ----------------------------------------------------------------------------
+48 −0
Original line number Diff line number Diff line
@@ -20,10 +20,15 @@
// from nativewindow/includes/system/window.h
// (not to be confused with the compatibility-only window.h from system/core/includes)
#include <system/window.h>
#include <android/native_window_aidl.h>

#include <private/android/AHardwareBufferHelpers.h>

#include <log/log.h>
#include <ui/GraphicBuffer.h>
#include <gui/Surface.h>
#include <gui/view/Surface.h>
#include <android/binder_libbinder.h>

using namespace android;

@@ -59,6 +64,13 @@ static bool isDataSpaceValid(ANativeWindow* window, int32_t dataSpace) {
            return false;
    }
}
static sp<IGraphicBufferProducer> IGraphicBufferProducer_from_ANativeWindow(ANativeWindow* window) {
    return Surface::getIGraphicBufferProducer(window);
}

static sp<IBinder> SurfaceControlHandle_from_ANativeWindow(ANativeWindow* window) {
    return Surface::getSurfaceControlHandle(window);
}

/**************************************************************************************************
 * NDK
@@ -334,6 +346,42 @@ int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation
    return native_window_set_auto_prerotation(window, autoPrerotation);
}

binder_status_t ANativeWindow_readFromParcel(
        const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) {
    const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);

    // Use a android::view::Surface to unparcel the window
    std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
    status_t ret = shimSurface->readFromParcel(nativeParcel);
    if (ret != OK) {
        ALOGE("%s: Error: Failed to create android::view::Surface from AParcel", __FUNCTION__);
        return STATUS_BAD_VALUE;
    }
    sp<Surface> surface = sp<Surface>::make(
            shimSurface->graphicBufferProducer, false, shimSurface->surfaceControlHandle);
    ANativeWindow* anw = surface.get();
    ANativeWindow_acquire(anw);
    *outWindow = anw;
    return STATUS_OK;
}

binder_status_t ANativeWindow_writeToParcel(
        ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) {
    int value;
    int err = (*window->query)(window, NATIVE_WINDOW_CONCRETE_TYPE, &value);
    if (err != OK || value != NATIVE_WINDOW_SURFACE) {
        ALOGE("Error: ANativeWindow is not backed by Surface");
        return STATUS_BAD_VALUE;
    }
    // Use a android::view::Surface to parcelize the window
    std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
    shimSurface->graphicBufferProducer = IGraphicBufferProducer_from_ANativeWindow(window);
    shimSurface->surfaceControlHandle = SurfaceControlHandle_from_ANativeWindow(window);

    Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
    return shimSurface->writeToParcel(nativeParcel);
}

/**************************************************************************************************
 * apex-stable
 **************************************************************************************************/
Loading