MSOpenTech/angle — pull request #12 by omochi (2014-08-01 07:00:40+00:00)
Title: Windows8.1 SwapChainPanel Support, C# P/Invoke Support, Memory Leak Fix

Hello, stammen san.
Your ANGLE winrt supporting fork is very nice.
I got a lot of help for porting my iOS/Android OpenGL application to Windows8.1.
But a little troubles are there.
I solved them and introduce details in below.

# No SwapChainPanel support
In Windows8.1, Using SwapChainPanel is better than SwapChainBackgroundPanel.
I added support of it.

# It can't be called all functions from C# Managed Layer because of ComPtr class
I use this library for porting iOS/Android OpenGL Application.
I write Application, EAGL(something seems to be EGL for Apple platform) by ObjectiveC and OpenGL by C.
I write Application, EGL, OpenGL by java.
So I want to write application by C# and call EGL, OpenGL by C# too.
I made P/Invoke Static functions class in C# and call through corresponding C native function provided by this library.
This approach is same to Java. Java OpenGL is simple JNI glue codes to native.
But, only 2 function can't be call.
They are eglGetDisplay and eglCreateWindowSurface.
Because their arguments contains EGLNativeWindowType.
this is ComPtr in this WinRT support fork.
it is C++ class so it can not link to C# by P/Invoke interface.
So I added simple C version of them, eglGetDisplay_c, eglCreateWindowSurface_c.
but I think that this solution is bad.
EGL function should not be modified/added if there are any other way.
I think best approach is changing EGLNativeWindowType ComPtr to IUnknown*.
but it has many modification points and potential to happen memory management problem.
And I'm not familiar with COM programming, DirectX programming, My project time is finite.
So I gave up to do best and do bad out of need.

And I change some function to extern "C".

# Fix memory leak
I found that Xaml Page class never be destructed if it contains SwapChainPanel setup by ANGLE.
I try to fix it and finally i found bug in below.
IWinrtEglWindow::GetWindowInterface() returns ComObject that is called AddRef().
return value directly assign (using operator=) to ComPtr.
So it occurs memory leak by Over Retain.
I changed this to call ComPtr.Attach() method.