/// <summary> /// Handle a new shared memory format being detected from the compositor. /// </summary> /// <param name="data"></param> /// <param name="sharedMemory"></param> /// <param name="format"></param> private void OnSharedMemoryFormat(IntPtr data, IntPtr sharedMemory, SharedMemoryFormat format) { List <SharedMemoryFormat> sharedMemoryFormats = new List <SharedMemoryFormat>(); if (SharedMemoryFormats != null) { sharedMemoryFormats.AddRange(SharedMemoryFormats); } if (!sharedMemoryFormats.Contains(format)) { sharedMemoryFormats.Add(format); } SharedMemoryFormats = sharedMemoryFormats.ToArray(); }
public Buffer CreateBuffer(int width, int height) { // Get a handle to our shared memory location SharedMemoryFormat sharedMemoryFormat = SharedMemoryFormat.ARGB8888; int stride = width * 4; int size = height * stride; int fileDescriptor = SharedMemoryFileDescriptorAllocate(size); if (fileDescriptor < 0) { throw new Exception("Error generating file descriptor for shared memory of size " + size); } IntPtr sharedMemoryPointer = SharedMemoryMap(size, fileDescriptor); if (sharedMemoryPointer == IntPtr.Zero) { throw new Exception("Failed to generate shared memory mapping for " + width + " x " + height + " / " + stride + " = " + size); } // Now create a pool for this shared memory SharedMemoryPool pool = new SharedMemoryPool(SharedMemoryPoolCreate(Handle, size, fileDescriptor)); return(pool.CreateBuffer(width, height, stride, sharedMemoryFormat, sharedMemoryPointer)); }
private static extern IntPtr SharedMemoryPoolBufferCreate(IntPtr pool, int width, int height, int stride, SharedMemoryFormat sharedMemoryFormat);
internal Buffer CreateBuffer(int width, int height, int stride, SharedMemoryFormat sharedMemoryFormat, IntPtr sharedMemoryPointer) { return(new Buffer(SharedMemoryPoolBufferCreate(Handle, width, height, stride, sharedMemoryFormat), width, height, stride, sharedMemoryPointer)); }