Skip to content

Missing method HardwareBuffer.Create(...) #8703

Description

@Steph55

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

VS 2022

Description

I have been trying for a while to figure out how to create an Android HardwareBuffer with Xamarin. With Android, it is easy, we simply need to call HardwareBuffer.Create(), but I cannot find the equivalent in Xamarin. How should I proceed or is this function missing?

Steps to Reproduce

Create a Net 8 Xamarin project using Android.Hardware. Then try to figure out how to call HardwareBuffer.Create()

Did you find any workaround?

No

Relevant log output

No response

Activity

  1. jonpryor commented on Feb 7, 2024

    @jonpryor
    Contributor

    @jpobst: looking at the build log for Mono.Android.csproj, I see:

    bj/Debug/net9.0/android-34/mcw/api-34.xml(32327,10): warning BG8800: Unknown parameter type 'Android.Hardware.HardwareBufferUsage' for member 'Android.Hardware.HardwareBuffer.Create (int, int, Android.Hardware.HardwareBufferFormat, int, Android.Hardware.HardwareBufferUsage)'
    

    Looks like a "bad enumification" prevented HardwareBuffer.create() from being bound. :-/

  2. added
    Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).
    and removed
    needs-triageIssues that need to be assigned.
    on Feb 7, 2024
  3. jpobst commented on Feb 7, 2024

    @jpobst
    Contributor

    This will be fixed by #8707, however we cannot add new API to the shipped "contract" net8.0-android. Thus, this will not be available until .NET 9.

    In the meantime, you should be able to copy the binding for HardwareBuffer.Create (...) into your project to be able to use it:

    static readonly JniPeerMembers _members = new XAPeerMembers ("android/hardware/HardwareBuffer", typeof (HardwareBuffer));
    
    public static unsafe Android.Hardware.HardwareBuffer Create (int width, int height, Android.Hardware.HardwareBufferFormat format, int layers, long usage)
    {
    	const string __id = "create.(IIIIJ)Landroid/hardware/HardwareBuffer;";
    	try {
    		JniArgumentValue* __args = stackalloc JniArgumentValue [5];
    		__args [0] = new JniArgumentValue (width);
    		__args [1] = new JniArgumentValue (height);
    		__args [2] = new JniArgumentValue ((int) format);
    		__args [3] = new JniArgumentValue (layers);
    		__args [4] = new JniArgumentValue (usage);
    		var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
    		return global::Java.Lang.Object.GetObject<Android.Hardware.HardwareBuffer> (__rm.Handle, JniHandleOwnership.TransferLocalRef)!;
    	} finally {
    	}
    }
  4. added this to the .NET 9 milestone on Feb 7, 2024
  5. changed the title [-]Where is the static function HardwareBuffer.Create()[/-] [+]Missing method `HardwareBuffer.Create(...)`[/+] on Feb 9, 2024
  6. added
    bugComponent does not function as intended.
    on Feb 9, 2024
  7. locked and limited conversation to collaborators on Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).bugComponent does not function as intended.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions