Provide OpenGL textures
The main purpose of KWaylandServer is to hide all ugly Wayland bits from the compositor. However, not all those ugly bits are hidden right now, which diminish the whole point of the library.
The compositor has to create an OpenGL texture from a wl_buffer on its own. Such an approach has a lot of drawbacks. First of all, theoretically, we need to duplicate all OpenGL related code. Second, the compositor needs to track buffer size changes, which makes everything just clumsy.
It's probably better to move the burden of getting OpenGL textures from kwin to kwaylandserver. I belive that it's a good thing in long term.
From API point of view, we will have to expose the buffer format, some flags to indicate if y is flipped, maybe(?) the number of planes for convenience, and textures for all planes, e.g.
/**
* Returns the format of the buffer.
*/
Format format() const;
/**
* Returns the number of planes in the buffer.
*/
int planeCount() const;
/**
* Returns the OpenGL texture for the specified @a plane.
*/
QOpenGLTexture *toOpenGLTexture(int plane) const;
The tricky part is going to be the integration between the compositor and kwaylandserver. Perhaps, we could use QOpenGLContext::globalShareContext(), or maybe introduce a compositor integration class that allows to specify the OpenGL context
class KWaylandCompositorIntegration
{
public:
static void setGlobalShareContext(QOpenGLContext *context);
};
If KWaylandCompositorIntegration::setGlobalShareContext(nullptr);
is called, we will just destroy OpenGL textures and stuff.
Another tricky part is that we support software rendering in kwin. I would really love to drop it, and just make kwin bail out if OpenGL compositing is not possible. For the time being we could introduce similar API for raster buffers, e.g.
QImage toImage(int plane) const;
Implementation-wise, it would be really awesome if all this stuff were implemented as plugins. For example, if we don't really want to have EGLStreams buffer code in kwaylandserver, we could implement it somewhere else and just provide a plugin which will be eventually loaded by kwaylandserver.
This will be a big change, but it should be worth it in the end.