GLibSharp / GtkSharp

.Net bindings for gtk+3 and above
Other
27 stars 21 forks source link

glib: GType: Allow G_TYPE_POINTER to IntPtr conversion #52

Closed seungha-yang closed 3 years ago

seungha-yang commented 3 years ago

... and remove duplicated GType.Pointer type registration.

thiblahute commented 3 years ago

In what case is that useful?

(Just ooc)

seungha-yang commented 3 years ago

In what case is that useful?

(Just ooc)

I'm working on d3d11 plugin so that C# application can consume d3d11 texture produced by gstreamer as an action signal way. MR is here fwiw (https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1873)

the shape of signal is

  /**
   * GstD3D11VideoSink:draw:
   * @videosink: the d3d11videosink
   * @shard_handle: a pointer to HANDLE
   * @texture_misc_flags: a D3D11_RESOURCE_MISC_FLAG value
   * @acquire_key: a key value used for IDXGIKeyedMutex::AcquireSync
   * @release_key: a key value used for IDXGIKeyedMutex::ReleaseSync
   *
   * Draws on shared texture. @shard_handle must be a valid pointer to HANDLE
   * which was obtained via IDXGIResource::GetSharedHandle or
   * IDXGIResource1::CreateSharedHandle.
   *
   * If texture was created with D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX flag,
   * caller must specify valid @acquire_key and @release_key.
   * Otherwise (i.e., created with D3D11_RESOURCE_MISC_SHARED flag),
   * @acquire_key and @release_key will be ignored.
   *
   * Since: 1.20
   */
  gst_d3d11_video_sink_signals[SIGNAL_DRAW] =
      g_signal_new ("draw", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
      G_STRUCT_OFFSET (GstD3D11VideoSinkClass, draw), NULL, NULL, NULL,
      G_TYPE_BOOLEAN, 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT64,
      G_TYPE_UINT64);

While testing the feature with C# application, I found an exception thrown for IntPtr passed to Emit("draw", myIntPtr, ...) here https://gitlab.freedesktop.org/gstreamer/gstreamer-sharp/-/blob/master/sources/custom/DynamicSignal.cs#L407 😉

This PR is to fix the exception

thiblahute commented 3 years ago

It is generally quite ugly to use pointers this way in bindings :-)

seungha-yang commented 3 years ago

It is generally quite ugly to use pointers this way in bindings :-)

I'm a bit agree with that point :) But IntPtr seems to be always converted to GType.Pointer and other C# types are not mapped with GType.Pointer, isn't it? I mean, I though this bi-directionally mapping between GType.Pointer and IntPtr should be safe enough

thiblahute commented 3 years ago

Yeah it makes sense I think