Wednesday, October 13, 2010

plasma in 18-24 months?

In my last blog entry, I mentioned QtComponents, QML and the new Qt scene graph and then vaguely alluded to profound implications for Plasma. I will not tease you, dear reader, for longer than necessary: this blog entry contains my current preliminary thinking on the what this could all mean for Plasma going forward.

First, I'd like to note that none of this would be possible without the fantastic work going on at Nokia's Qt development offices. They are tackling hard and interesting problems with gusto and producing some very nice results in the process. QtComponents is being developed very much in the open right from the start: an open mailing list for all dev discussion, a public git repo that even contains experiments and early code sketches, a set of use cases and open tasks in Jira. Outreach to community members such as myself, which allowed me to join their design sessions last week, is just one more piece of this. This open from end-to-end, right from the beginning development model is part of the "new Qt" ecosystem that is the culmination of years of consistent effort on the part of many individuals involved with Qt. It's paying off now, and I hope that all new Qt components undertake a similar, or even the exact same, type of approach.

Enough about that, however... what does all this new stuff mean for Plasma?

There are two things that I'm really not very happy with when it comes to Plasma right now:


  • libplasma provides some very elementary UI components that really belong in Qt, but because they aren't in Qt have ended up in libplasma out of necessity where they are more of a distraction (in terms of code clarity and design) than anything else

  • QGraphicsView, particularly QGraphicsProxyWidget, is not nearly as performant as it could be. It's gotten pretty good in terms of being quite usable even on modest hardware with Qt 4.7 and KDE Platform 4.5, but it could be so much better.



The new scene graph would allow every paint operation in Plasma to be hardware accelerated on the GPU using OpenGL. Not only would effects like blur become cheap (the expense is why we don't use blur on the canvas itself, but only on top level window backgrounds where we can use KWin's OpenGL driven compositing effects to achieve blurring) but things like nice halos around text should be able to be rendered at high quality and low cost. Pixmap usage should drop, framerates skyrocket and client-side image manipulations all but disappear.

This implies moving away from QPainter, which only gets in the way of proper acceleration since the painter can do "anything" in "any" order. Which means moving all of our user interface to the declarative model, specifically QML. In turn that means needing proper declarative style widgets, specifically QtComponents. Finally, it means leaving QGraphicsView behind and moving to a scene graph only system.

This is not a small amount of work: every Plasmoid, Containment, popup and window dressing (e.g. the add widgets interface, the panel controller, the activity manager ..) that does direct painting needs to be moved over to QML. Thankfully we can do these one at a time with the results working very nicely with the current QGraphicsView based libplasma. This means we don't need to do a "massive porting effort with a huge pause between releases"; each release can contain more and more QML driven elements and fewer and fewer uses of QPainter. The result for the user while this happens is likely to be nicer looking interfaces, as QML usually makes this easier to achieve.

Marco has been working extremely hard on the first thing we need to make this process possible: Plasma <-> QML integration. This work is being merged into trunk right now and will debut in KDE Platform 4.6. This means we can start the process of QML-ification of Plasma now. Plasmoids written in C++ can create Plasma::DeclarativeWidgets, Javascript Plasmoids can load QML files from their package and Plasmoids can be written entirely in QML (using the Plasma Javascript API from within the QML).

We will also need to replace our current QGraphicsProxyWidget based pushbuttons, sliders, etc. with QtComponent based ones. This is mostly an issue for Plasmoids written in C++; Plasmoids written using Javascript should shielded from this set of changes. Other scripting languages such as Ruby and Python expose more of the implementation details and so those Plasmoids may require some adjustments. However, moving to QtComponents means waiting for QtComponents to be "ready" and dealing with the baggage of our existing C++ QGraphicsProxyWidget subclasses in libplasma.

Of course, we're not simply waiting for QtComponents to magically mature on their own. Several of us (Artur, Marco, myself) are engaged with the QtComponents project and its team already. Marco has also already provided the first QtComponent push button whose text is set using a source from a Plasma::DataEngine, all done in QML. So we know the basic ideas work in a very practical manner.

Here's the big bomb-shell, however: to fully complete the migration process, we'll need to create a "libplasma2" which is binary and source incompatible to the current libplasma. Corona will cease to be a QGraphicsScene subclass and instead become a scene graph manager; Containment and Applet will become some kind of QML item; the QGraphicsProxyWidget subclasses will be dropped.

The good news is that this is an almost completely internal set of changes. The design of Plasma lends itself very nicely to this set of changes, and the C++ classes in libplasma are nicely aligned as well. For instance, Corona right now is the QGraphicsScene and manages Containments and provides "global" management of things like configuration data, screen geometry hooks, etc. None of that would change, except it being a QGraphicsScene. DataEngines, Plasma::Services, Plasma::Svg, etc. would not change in the least, either. So the external impact looks like it will be surprisingly small for anything written in Javascript or which uses QML for its user interface. Note that Plasma Mobile is already 100% QML, modulo the components it inherited from other Plasma workspaces, consisting mostly of individual Plasmoids.

All of this means that it isn't going to happen in the next release, or even in the release after that. It will be a measured set of changes over the course of many releases to reach the final goal of "going scene graph". User disturbance will therefore be kept to a minimum and we'll be able to continue to make regular releases with noticeable improvements while we do this.

The end result of full hardware acceleration, a fully QML driven user experience and a much improved resource footprint are, in my estimations, worth all of this effort.

There are some potentially very exciting things this could mean beyond simply improving what we already do, though. One of the main ones involves threading. The scene graph is capable of rendering the scene in multiple threads. QML needs some adjustments to take advantage of this, but if/when that work gets done it would allow Plasma to run each Plasmoid in its own thread. (Note: this is different from multi-process.) That would mean that any pausing in a given Plasmoid or other user interface components would cause no annoyances in the rendering or interaction with any other part of the user interface. It would also enable fairly trivial resource management: we could then track per-Plasmoid memory and CPU consumption, for instance. Achieving such a multi-threaded Plasma will require some additional work on top of everything already discussed above, including things such as DataEngine access (which is not currently designed for multi-threaded access) and sharing of Svg renderers between Plasma::Svg objects (something that lets us gain significant performance benefits right now). My initial scan over things says that it isn't insurmountable: we can make rules about things like Plasma::Svg (can only be used in the same thread as the Plasmoid; so no sharing Plasma::Svg's between different instances of Plasmoids) and probably adjust things like DataEngine successfully (the idea of putting the DataEngines out of process, something I've toyed with conceptually since the 4.0 release, becomes even more attractive under this scheme).

It's an exciting set of possibilities, though none of this is certain yet. It's all still "work in process" research and none of the above may happen. I'm hoping it will, however, and the pieces are actually falling into place. Huzzah.

26 comments:

piacentini said...

Wow, great post. When I started reading it I was thinking "Oh, no... ", but closer to the end I realized that the smart decision of building the desktop layer on top of the Plasma API instead of going straight for QGV will now make it possible to "save" most plasmoids very easily.

Wish the same was true for most kdegames, but it looks like all QGV-based porting efforts is not immediately convertible to the QML word.

Yves said...

Plasma-applets in threads... cool!

This would probably fix https://bugs.kde.org/show_bug.cgi?id=224899

Spockfish said...

Just on the airport returning from Qt10DD. Very, no, extremely inpressed by QML. Great to read KDE starting to use this!

ezjd said...

I am curious that if graph-scene will be fully used in KDE, KDE will need OpenGL all the time, just like clutter based GNOME3. If so, I will miss QPaint based KDE, with which OpenGL is still optional.

thegzeus said...

while I'm not quite what I'd call a KDE user, I'm a big backer of it.
If nothing else, Plasma is NeWS-revisited.

Diego said...

Is there a plan for porting other KDE apps to QML?

josericardo said...

@ezjd:
Aaron said "allow" not "force" so I'm guessing openGL would remain an option even for QGraphicsScene. Nevertheless it would be interesting to know for sure, though I don't think opènGL will become mandatory. KDE devs are good software architects and wouldn't pull a "Gnome Shell" on us.

Ramsees said...

@josericardo

Well,I hate to rain on your parade but OpenGL will be mandatory, this is a requirement for Qt.

josericardo said...

@Ramsees:
You are right! Oh boy we are going the Gnome Shell route! My IGP supports openGL 1.4 and QGraphicsScene will require openGL 2.0, bummer.
I guess I still have a year and a half to enjoy KDE while I still can.

Aaron J. Seigo said...

regarding OpenGL, we talked about this last week as well. right now, the scene graph backed QML can also render to QGraphicsScene, though it really loses most/all of its benefits when doing so. i believe this may require an OpenGL QWidget backed QGraphicsScene, as well.

in any case, i don't think it is settled at all yet whether QML will only end up with a scene graph based backend, or whether it will be switchable at runtime, much as QPainter is right now.

this is all still work-in-progress and the plain CPU-rendered path is valuable to us in many use cases. i'm hoping that we'll end up with a proper openGL path (scene graph; openGL backend for QPainter just isn't a full solution) as well as a QGrapicsScene fallback.

at some point in the future, however, everything will end up going through OpenGL. we're not there yet (in part because of toolkits not being ready for it, in part because of drivers not being ready, in part because of apps not being ready) but it's something we need to be making things ready for. doing painting on the CPU just isn't a long term viable option.

shamaz said...

This is indeed a big change for plasma. Maybe it would be the right opportunity to crete a kde 5.x branch :)
it would be something more evolutionnary than Revolutionnary
(a lesson learned from the experience of kde3->kde4 transition and the gnome2->gnome3 one?)

Aaron J. Seigo said...

@shamaz: "Maybe it would be the right opportunity to crete a kde 5.x branch :)"

there isn't a need for that yet. when we get to the point where we can benefit from a libplasma2 (e.g. all Plasma components are migrated to QML, the scene graph in Qt is settled into place, etc) then maybe we will think about it. but even then it may not be called for.

"it would be something more evolutionnary than Revolutionnary"

i've always expected that KDE Platform 5 is likely be an evolutionary development, since the most likely reason to do so is to polish API issues that require binary or source incompatible changes. this is in contrast to KDE 4 or KDE 2 where huge amounts of new API were added to address entirely new kinds of problems.

we're still a ways from needing a KDE 5, though. a Qt 5 would change that (since it would mean Qt is breaking BC), but there are no concrete plans for a Qt 5 either at this point.

"(a lesson learned from the experience of kde3->kde4 transition and the gnome2->gnome3 one?)"

we did an evolutionary major number releases in KDE 3.0. it was evolutionary over KDE 2.x and that was quite intentional. 2.x and 4.x were big leaps, by contrast. when it comes to major version changes of the platform, i honestly don't think we learned anything new in the last 2 years we didn't already know from our experience with 2.0 and 3.0.

we learned things about dealing with our downstream partners, project management (with timelines going too fuzzy in the first half of 4.0 devel) and rolling out major UI changes. but platform API process wasn't a surprise, it was more of an application of things we'd learned previously.

damian said...

There there are thing I don't understand, suppose I have a sis totally unaccelerated card, would I be able to run plamsa at all? or will it just be slow. (I know I wouldn't be able to use plasma in this card its current state either)
And what about llvm-pipe is it supposed to give opengl through cpu, so if it gets implemented it shouldn't be a problem right?

TemporalBeing said...

@aseigo,

How does the performance difference between native Qt components (e.g. QWidget in C++) and QML factor in?
As I understand it, using QML takes a bit of a performance hit, not much, but you can't do what you could using native widget.
Is there enough performance gain via OpenGL, etc to make up the performance loss of QML?

Notmart said...

@TemporalBeing: How does the performance difference between native Qt components (e.g. QWidget in C++) and QML factor in?

the graphics speed looks about the same, it's dealing with exactly the same qgrapicsitems we were dealing in the past, qml is just a way to define their creation...
one thing that would affect the speed is if javascript is used in a non wise way, i.e. beware of hot paths (but this is true in any language and well documented in the Qt qml docs)
as far i seen right now of scene-graph, the performance improvement is so ridiculous that isn't even worth posing the question: it's light years ahead :)

Andrew said...

Hi Aaron,
Not really sure how to word this. I understand that i'm just a user and not a developer and so i don't really have a say on anything.

As a humble user, i am worried that a change to use openGL will end up slower on some peoples desktop.

I have an 7300GT NVidia card, 46xx ATI card and a laptop with an GM 4500 Intel GP and some operations, i.e resizing windows are quite slow in comparison to the same operation on KDE 3.5. Correct me if i'm wrong but 3.5 didn't use hardware acceleration at all ? And iirc Kwin uses openGL in 4.5 to perform these operations?

As i understand it, the problem here is the drivers which although not you're problem, does mean that something that would otherwise be fast could be very slow until they fix the drivers.

If openGL is wanted / required for plasma and other parts of KDE is it possible to create a kde 3.5 style drawing option ? Where by users could sacrifice the beautiful effects for limited but fast drawing ?

KenP said...

Hi Aaron,

KDE on the interface front is going from strength to strength and this latest piece from you proves that it will continue to do so in future.

However, there is an area worth looking into: Corporate/Work/Office desktop. Unfortunately, this also implies support for all things Microsoft like, Exchange, Samba, Proxies (yes, this is true of almost every office out there) and other protocols such as "office communicator" protocol for instant messaging within an organization.

Finally, one cannot emphasise enough about support for MS Office document formats.

What I am getting at is this:

At my workplace, I use KDE (4.5.2 now) but I find that I am using KDE only as a desktop shell and mostly all 'office-friendly' apps are non-KDE ones. Although I am stubborn enough to continue to use KDE ;) I list here things which can do with some love:
1. Full Exchange integration for Kontact
2. Office Communicator support for Kopete (it is currently available as a plug-in for pidgin called pidgin-sipe)
3. Improved proxy support. My workplace as a automatic proxy URL and most KDE apps grind to a halt when faced with it, frankly.
4. Better (than openoffice.org) support for MS Office in KOffice.
5. Windows Network support in Dolphin. It is flaky at best, at present.

Now I do understand that your core area may not be applications but as a 'senior' member of the KDE development community, you have a louder voice than most, in particular a humble KDE user such as me :)

Most of the above requirements exist as bugs on bugs.kde.org but have seen little traction over the years (yes, some of them are around for years!) However, I forget the actual bug numbers here.

IMO, getting KDE firmly in the 'average' workplace is key to world domination :)

redm said...

This sounds indeed very exiting! However I'm a bit concerned about the reality on the users computers... I just did an upgrade from KDE 4.3 to 4.5 and well... it was a rather suboptimal experience! This includes Plasma as well as the graphics driver (and other things). E.g. buggy Plasmoids that come with KDE SC, some of which crashing Plasma. I had to clean up plasma config by hand to get it starting at all. Also the radeon driver I'm using: Since I started using compositing two years ago it hasn't really improved. It changed yes, but improved no. The current version crashes regularly with compositing and a second xserver gives just a distorted image with KMS... just to give examples.

What I want to say: As great as the ideas might be, it might be wise to slow down a bit, polish Plasma and let the reality catch up (in terms of kernel, driver, xserver)!

Ingomar Wesp said...

I'm shocked and excited at the same time (though the excitement is certainly the stronger emotion of the two). I must say that I know close to nothing about QML, so maybe this question is naive: Will this have any impact on our abilities to do advanced layouting?

Although we still haven't gotten everything right in this regard, the possibility of creating custom QGraphicsLayouts right now is pretty sweet. Will this be lost in the transition?

André said...

I am just back from the QtDD10. While I found the presentations on QML to be impressive, it also strikes me as still very much an inmature piece of Qt. We are only just beginning to see what is possible, and it seems the Trolls themselves are not sure yet where it will end up. The Components are only in a research stage, and so far we're not even close of being able to theme them in any usable way.

The Scenegraph backend for Qt looked extremely cool, and the multithreaded rendering it allows is way impressive. But the developer of this - again - research project did not even know it would pop up in the keynotes as a plan for - perhaps - Qt 4.8. The way that the scene graph approach basically seems to make the integration of C++ rendered components impossible (if I understood the presentation correctly) seems to be a big risk.

All in all, I think the QML project is very interesting indeed, and I think it is a good idea to allow and stimulate good integration with Plasma and to make sure that a possible future transition would be smooth. It is wise to interact intensively with the QtComponents developers to make sure KDE's and plasma's needs are met. But I think it is too early to start betting everything on it yet. It is simply not mature, not set in stone that components demo-ed and researched now will ever surface in an official Qt. Unexpected snags may pop up. Last year I visited some labs sessions on projects that have been terminated only months after the presentation...

Stefan said...

OpenGL, QML. Is it going to be as painful as it was with 3.5 --> 4.x?

Notmart said...

@André: "seems to make the integration of C++ rendered components impossible"

probably not, as far i understood should still be possible to render to pixmap and feed those to the scenegraph

"components demo-ed and researched now will ever surface in an official Qt. Unexpected snags may pop up."

what i hope can will change this time, they are developing it -with us- this will hopefully help to have results in a pretty short time

@Stefan: "OpenGL, QML. Is it going to be as painful as it was with 3.5 --> 4.x?"

nope, it will be a very gradual process this time, no big revolutions fro one release to the other

Ignat said...

Finally we're getting there - model/view for plasma. Now I wish it had been all done in time with kde 4.0 or at least started back then in 4.0 times, so we'd have had it done by now... It's time to unify all those lists in krunner, device notifier, folder view and rss and tthousands of other plasmoids that use itemviews. However, how are plasmoids going to be written using this new tech? The interface is QML, data layer is C++, now where's the plasmoid logic and what language is it written in?

All in all, let's hope this gets done... fingers crossed. Now it's probably time to mention that this whole thing is essentially Clutter - as far as I know Clutter. Scene graph, that is.

Nitin Kanwal said...

graet article thanx for sharing information

Ian Monroe said...

Why not have the applets in different processes? Maemo 5 applets use GL compositing to do this I think.

Anyways I always thought of QML as using QGraphicsScene. Is this 'scene graph' just a new unnamed class?

Aaron J. Seigo said...

@Ian: "Why not have the applets in different processes?"

aside from memory overhead, doing this is significantly (probably unrealistically) more complicated if any sort of interaction is desired. if you want a set of windows painted around each other, it's fine. otherwise, not so much.

"Maemo 5 applets use GL compositing to do this I think."

yes, and it sucks.

"Anyways I always thought of QML as using QGraphicsScene."

it does right now.

"Is this 'scene graph' just a new unnamed class?"

QSceneGraph, which on labs for download. it includes a modified QML that uses that instead of QGraphicsScene.