[Mono-winforms-list] Thoughts on System.Drawing.

Miguel de Icaza miguel@ximian.com
04 Oct 2003 12:30:29 -0400


--=-EOVdoHmJJ58mO2e1VYEv
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello guys,

   These are some messages on a discussion we had on System.Drawing, and
we wanted to share with you.

Miguel.
-- 
Miguel de Icaza <miguel@ximian.com>

--=-EOVdoHmJJ58mO2e1VYEv
Content-Type: multipart/digest; boundary="=-D/JactZSdOAnvUdogjut"
Content-Description: Forwarded messages


--=-D/JactZSdOAnvUdogjut
Content-Disposition: inline
Content-Description: Forwarded message - More thoughts on Win32/Cairo
	integration.
Content-Type: message/rfc822

Subject: More thoughts on Win32/Cairo integration.
From: Miguel de Icaza <miguel@ximian.com>
To: Alexandre Pigolkine <pigolkine@gmx.de>, Jordi Mas <jmas@softcatala.org>,  duncan@ximian.com
In-Reply-To: <2356.1064243169@www56.gmx.net>
References: <1064189893.4732.102.camel@erandi.boston.ximian.com>
	 <2356.1064243169@www56.gmx.net>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1064434673.27951.60.camel@erandi.boston.ximian.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.3 
Date: 24 Sep 2003 16:17:53 -0400

Hello Alexandre,

> I am not  a Wine expert - so just my thoughts:
> 
> If I undestood things correclty, the main task is to force Wine to paint the
> 
> window decorations with Cairo functions. If so, we can try to provide our 
> own x11drv module (modify existing one) and load it on initialization time. 
> It will redirect all needed calls to Cairo dlls from Wine libraries and 
> System.Drawing will call Cairo directly.

This sounds like a good plan as well.  

Here are some extra data points, we should add these to the mix:

	* Ideally, we would be using GDIPLUS.DLL to implement 
	  the more advanced drawing features.

	* Maybe we should help the Wine folks implement GDIPLUS
	  by using Cairo as the engine for GDIPLUS.DLL

	* We still need to have the dual nature of rendering, unless
	  we can always use GDIPLUS.DLL, because System.Drawing can
	  be used without having a windowing system.

	* Even if we decide to only use GDIPLUS in the future, and drop
	  Cairo as a rendering mechanism, it would still be convenient
	  to have a Cairo backend while we sort this out.

Now, Cairo uses the X11 API to draw into X Drawables ("X11 Windows" are
"X11 Drawables").  Wine eventually also has to render into X drawable.  

In the file wine/include/x11drv.h, the following inline function is defined:

/* The return value is an X11 Window, ie, an X11 Drawable */
inline static Window get_client_window( WND *wnd )
{
    struct x11drv_win_data *data = wnd->pDriverData;
    return data->client_window;
}

/* The return value is an X11 Window, ie, an X11 Drawable */
inline static Window get_whole_window( WND *wnd )
{
    struct x11drv_win_data *data = wnd->pDriverData;
    return data->whole_window;
}

These return the actual Drawables where Cairo can render directly.

So we could keep the current bindings to Win32, but for advanced uses,
we use Cairo.  Sadly the code would look like this:

SomeDrawingOperation ()
{
	if (OnWindows)
		GDIPLUS_SomeDrawingOperation ();
	else {
		IntPtr drawable = get_window_from_hwnd (hwnd);

		cairo_do_operation (drawable)
	}
}

The only reason for the two code paths is that some developers (like
Jordi) are using the real Windows to contribute, and Cairo's rendering
would not work there.

Maybe I should send this to the list?

Miguel

--=-D/JactZSdOAnvUdogjut
Content-Disposition: inline
Content-Description: Forwarded message - Re: More thoughts on Win32/Cairo
	integration.
Content-Type: message/rfc822

Subject: Re: More thoughts on Win32/Cairo integration.
From: Miguel de Icaza <miguel@ximian.com>
To: Jordi Mas <jmas@softcatala.org>
Cc: Alexandre Pigolkine <pigolkine@gmx.de>, Duncan Mak <duncan@ximian.com>
In-Reply-To: <3F72FB69.3040003@softcatala.org>
References: <1064189893.4732.102.camel@erandi.boston.ximian.com>
	 <2356.1064243169@www56.gmx.net>
	 <1064434673.27951.60.camel@erandi.boston.ximian.com>
	 <3F72FB69.3040003@softcatala.org>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1064875687.23354.683.camel@erandi.boston.ximian.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.3 
Date: 29 Sep 2003 18:48:07 -0400

Hello, 

> 1) I'm not familiar with Cairo, then I do not have an opinion; but what I see 
> clear is that we should use the GDI+ API interface.

I agree, but there is no GDIPLUS.DLL implementation on Wine yet, so it
might have to wait for that.

But even if it did, we can not use this when Win32 is not in use, so we
would want to still have a code path like the one I described.

> 2) I know that some people do not like the Abiword's operating system 
> encapsulation approach but I my personal preference, if the code differences 
> are big, is having two classes: one for the win32 environment and other for 
> the *nix one instead of the 'if (OnWindows)' approach.

I agree, and to some extent we were doing that, the problem is that if
we do this for every class, we end up maintaining the code in 4 places,
and it can become quite cumbersome quickly. 

This is one of the things am trying to solve with this merger.

> 3) IMHO we need to keep win32 compatibly. For me the problem is not the fact 
> that we have some developers on win32 (I already have a Linux+winlib 
> enviornment working) the problem is that users of the WinForms API will expect 
> Mono winforms to look and behave as the Microsoft .Net implementation does. 
> It's very convenient to work on win32 for this reason.

Agreed.

> 4) I suggest to post a summary of this thread on the winforms list to get as 
> much feedback as possible.

Sounds good.  Should I just send my previous email to the list?

> 
> 5) I love Bonsai!

Someone mentioned they had a Bonsai for Mono on IRC, will ask again.

Miguel

--=-D/JactZSdOAnvUdogjut
Content-Disposition: inline
Content-Description: Forwarded message - Re: More thoughts on Win32/Cairo
	integration.
Content-Type: message/rfc822

Subject: Re: More thoughts on Win32/Cairo integration.
From: Miguel de Icaza <miguel@ximian.com>
To: Alexandre Pigolkine <pigolkine@gmx.de>
Cc: Jordi Mas <jmas@softcatala.org>, Duncan Mak <duncan@ximian.com>
In-Reply-To: <3F735923.6040502@gmx.de>
References: <1064189893.4732.102.camel@erandi.boston.ximian.com>
	 <2356.1064243169@www56.gmx.net>
	 <1064434673.27951.60.camel@erandi.boston.ximian.com>
	 <3F735923.6040502@gmx.de>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1064876739.23354.713.camel@erandi.boston.ximian.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.3 
Date: 29 Sep 2003 19:05:39 -0400

Hello!

> Looks like I thought in wrong direction :(
> Development with GDIPlus.dll (based on Cairo on Linux) seems to be much 
> better solution.

Do not worry Alexandre, I think that your initial work was fine, it is
just through experience that we learn that some design decisions might
be better than others.

That being said, working on GDIPLUS will take some time, and am not sure
what is more important to work on first.

> > AFAIK, the Graphics object from GDI+ can be initialized from HWND and
>  HDC (and created independently of course). So, for the Cairo bases
>  GDI+ implementation and on Windows we can pass HDC/HWND to initialize
>  objects for painting. In Cairo-based GDI+ we should ask Wine to
>  provide us with Drawable etc.,  but IMO System.Drawing code will be
>  identical for Windows and Linux.

It could be very close, yes.  Remember that we still need the Wine-less
version for things like ASP.NET using System.Drawing.

Miguel

--=-D/JactZSdOAnvUdogjut--


--=-EOVdoHmJJ58mO2e1VYEv--