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

Commit 926b4d8b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add ExtendableType to allocate" am: 0a9430ad am: efa98b10

parents df623aa6 efa98b10
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,9 @@ cc_defaults {
    static_libs: [
    static_libs: [
        "android.hardware.graphics.allocator-V2-ndk",
        "android.hardware.graphics.allocator-V2-ndk",
    ],
    ],
    defaults: [
        "android.hardware.graphics.common-ndk_static",
    ],
}
}


cc_defaults {
cc_defaults {
@@ -28,6 +31,9 @@ cc_defaults {
    shared_libs: [
    shared_libs: [
        "android.hardware.graphics.allocator-V2-ndk",
        "android.hardware.graphics.allocator-V2-ndk",
    ],
    ],
    defaults: [
        "android.hardware.graphics.common-ndk_shared",
    ],
}
}


cc_defaults {
cc_defaults {
+1 −0
Original line number Original line Diff line number Diff line
@@ -41,4 +41,5 @@ parcelable BufferDescriptorInfo {
  android.hardware.graphics.common.PixelFormat format = android.hardware.graphics.common.PixelFormat.UNSPECIFIED;
  android.hardware.graphics.common.PixelFormat format = android.hardware.graphics.common.PixelFormat.UNSPECIFIED;
  android.hardware.graphics.common.BufferUsage usage = android.hardware.graphics.common.BufferUsage.CPU_READ_NEVER;
  android.hardware.graphics.common.BufferUsage usage = android.hardware.graphics.common.BufferUsage.CPU_READ_NEVER;
  long reservedSize;
  long reservedSize;
  android.hardware.graphics.common.ExtendableType[] additionalOptions;
}
}
+16 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.graphics.allocator;
package android.hardware.graphics.allocator;


import android.hardware.graphics.common.BufferUsage;
import android.hardware.graphics.common.BufferUsage;
import android.hardware.graphics.common.ExtendableType;
import android.hardware.graphics.common.PixelFormat;
import android.hardware.graphics.common.PixelFormat;


@VintfStability
@VintfStability
@@ -54,6 +55,9 @@ parcelable BufferDescriptorInfo {
    /**
    /**
     * Buffer usage mask; valid flags can be found in the definition of
     * Buffer usage mask; valid flags can be found in the definition of
     * BufferUsage.aidl in graphics/common
     * BufferUsage.aidl in graphics/common
     *
     * The allocator must report isSupported() == false and reject any allocations
     * with unrecognized buffer usages.
     */
     */
    BufferUsage usage = BufferUsage.CPU_READ_NEVER;
    BufferUsage usage = BufferUsage.CPU_READ_NEVER;


@@ -62,4 +66,16 @@ parcelable BufferDescriptorInfo {
     * See getReservedRegion for more information.
     * See getReservedRegion for more information.
     */
     */
    long reservedSize;
    long reservedSize;

    /**
     * Extensible additional options that can be set.
     *
     * This is intended for options that do not change the overall usage, but which do impact
     * how a buffer is allocated. An example of this is compression level, such as for
     * the EGL_EXT_surface_compression extension.
     *
     * The allocator must report isSupported() == false and reject any allocations
     * with unrecognized options.
     */
    ExtendableType[] additionalOptions;
}
}
+58 −0
Original line number Original line Diff line number Diff line
@@ -217,6 +217,8 @@ class GraphicsTestsBase {
        }
        }
        return ret;
        return ret;
    }
    }

    int32_t allocatorVersion() const { return mIAllocatorVersion; }
};
};


BufferHandle::~BufferHandle() {
BufferHandle::~BufferHandle() {
@@ -309,6 +311,62 @@ TEST_P(GraphicsAllocatorAidlTests, CanAllocate) {
    EXPECT_GE(buffer->stride(), 64);
    EXPECT_GE(buffer->stride(), 64);
}
}


TEST_P(GraphicsAllocatorAidlTests, RejectsUnknownUsages) {
    if (allocatorVersion() < 2) {
        GTEST_SKIP() << "Must be version 2+";
        return;
    }

    constexpr auto FirstInvalidV2Usage = static_cast<BufferUsage>(1LL << 33);

    BufferUsage invalidUsage;
    if (allocatorVersion() == 2) {
        invalidUsage = FirstInvalidV2Usage;
    } else {
        GTEST_FAIL() << "Unknown version " << allocatorVersion();
    }

    BufferDescriptorInfo info{
            .name = {"CPU_8888"},
            .width = 64,
            .height = 64,
            .layerCount = 1,
            .format = PixelFormat::RGBA_8888,
            .usage = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN,
            .reservedSize = 0,
    };

    // First make sure we can allocate a known usage buffer as expected
    EXPECT_TRUE(isSupported(info));
    EXPECT_TRUE(allocate(info));

    // Now add the unknown bit and verify it's rejected
    info.usage |= invalidUsage;
    EXPECT_FALSE(isSupported(info)) << "isSupported() returned true for unknown-to-HAL usage";
    EXPECT_FALSE(allocate(info)) << "allocate succeeded for unknown-to-HAL usage";
}

TEST_P(GraphicsAllocatorAidlTests, RejectsUnknownOptions) {
    if (allocatorVersion() < 2) {
        GTEST_SKIP() << "Must be version 2+";
        return;
    }

    BufferDescriptorInfo info{
            .name = {"CPU_8888"},
            .width = 64,
            .height = 64,
            .layerCount = 1,
            .format = PixelFormat::RGBA_8888,
            .usage = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN,
            .reservedSize = 0,
    };
    info.additionalOptions.push_back({"android.hardware.graphics.common.NotARealOption", 1});

    EXPECT_FALSE(isSupported(info)) << "isSupported() returned true for unknown-to-HAL option";
    EXPECT_FALSE(allocate(info)) << "allocate succeeded for unknown-to-HAL option";
}

TEST_P(GraphicsFrontBufferTests, FrontBufferGpuToCpu) {
TEST_P(GraphicsFrontBufferTests, FrontBufferGpuToCpu) {
    BufferDescriptorInfo info{
    BufferDescriptorInfo info{
            .name = {"CPU_8888"},
            .name = {"CPU_8888"},