Changeset View
Changeset View
Standalone View
Standalone View
src/server/buffer_interface.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "buffer_interface.h" | 20 | #include "buffer_interface.h" | ||
21 | #include "display.h" | 21 | #include "display.h" | ||
22 | #include "logging_p.h" | 22 | #include "logging_p.h" | ||
23 | #include "surface_interface.h" | 23 | #include "surface_interface.h" | ||
24 | #include "linuxdmabuf_v1_interface.h" | ||||
24 | // Wayland | 25 | // Wayland | ||
25 | #include <wayland-server.h> | 26 | #include <wayland-server.h> | ||
26 | // EGL | 27 | // EGL | ||
27 | #include <EGL/egl.h> | 28 | #include <EGL/egl.h> | ||
28 | #include <QtGui/qopengl.h> | 29 | #include <QtGui/qopengl.h> | ||
29 | 30 | | |||
31 | #include "drm_fourcc.h" | ||||
32 | | ||||
30 | namespace KWayland | 33 | namespace KWayland | ||
31 | { | 34 | { | ||
32 | namespace Server | 35 | namespace Server | ||
33 | { | 36 | { | ||
34 | 37 | | |||
35 | namespace EGL | 38 | namespace EGL | ||
36 | { | 39 | { | ||
37 | typedef GLboolean(*eglQueryWaylandBufferWL_func)(EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value); | 40 | typedef GLboolean(*eglQueryWaylandBufferWL_func)(EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value); | ||
38 | eglQueryWaylandBufferWL_func eglQueryWaylandBufferWL = nullptr; | 41 | eglQueryWaylandBufferWL_func eglQueryWaylandBufferWL = nullptr; | ||
39 | } | 42 | } | ||
40 | 43 | | |||
41 | class BufferInterface::Private | 44 | class BufferInterface::Private | ||
42 | { | 45 | { | ||
43 | public: | 46 | public: | ||
44 | Private(BufferInterface *q, wl_resource *resource, SurfaceInterface *parent); | 47 | Private(BufferInterface *q, wl_resource *resource, SurfaceInterface *parent); | ||
45 | ~Private(); | 48 | ~Private(); | ||
46 | QImage::Format format() const; | 49 | QImage::Format format() const; | ||
47 | QImage createImage(); | 50 | QImage createImage(); | ||
48 | wl_resource *buffer; | 51 | wl_resource *buffer; | ||
49 | wl_shm_buffer *shmBuffer; | 52 | wl_shm_buffer *shmBuffer; | ||
53 | LinuxDmabuf::Buffer *dmabufBuffer; | ||||
50 | SurfaceInterface *surface; | 54 | SurfaceInterface *surface; | ||
51 | int refCount; | 55 | int refCount; | ||
52 | QSize size; | 56 | QSize size; | ||
53 | bool alpha; | 57 | bool alpha; | ||
54 | 58 | | |||
55 | static BufferInterface *get(wl_resource *r); | 59 | static BufferInterface *get(wl_resource *r); | ||
56 | 60 | | |||
57 | private: | 61 | private: | ||
Show All 40 Lines | 101 | if (s_accessCounter == 0) { | |||
98 | s_accessedBuffer = nullptr; | 102 | s_accessedBuffer = nullptr; | ||
99 | } | 103 | } | ||
100 | wl_shm_buffer_end_access(p->shmBuffer); | 104 | wl_shm_buffer_end_access(p->shmBuffer); | ||
101 | } | 105 | } | ||
102 | 106 | | |||
103 | BufferInterface::Private::Private(BufferInterface *q, wl_resource *resource, SurfaceInterface *parent) | 107 | BufferInterface::Private::Private(BufferInterface *q, wl_resource *resource, SurfaceInterface *parent) | ||
104 | : buffer(resource) | 108 | : buffer(resource) | ||
105 | , shmBuffer(wl_shm_buffer_get(resource)) | 109 | , shmBuffer(wl_shm_buffer_get(resource)) | ||
110 | , dmabufBuffer(nullptr) | ||||
106 | , surface(parent) | 111 | , surface(parent) | ||
107 | , refCount(0) | 112 | , refCount(0) | ||
108 | , alpha(false) | 113 | , alpha(false) | ||
109 | , q(q) | 114 | , q(q) | ||
110 | { | 115 | { | ||
116 | if (!shmBuffer && wl_resource_instance_of(resource, &wl_buffer_interface, LinuxDmabufUnstableV1Interface::bufferImplementation())) { | ||||
117 | dmabufBuffer = static_cast<LinuxDmabuf::Buffer *>(wl_resource_get_user_data(resource)); | ||||
118 | } | ||||
111 | s_buffers << this; | 119 | s_buffers << this; | ||
112 | listener.notify = destroyListenerCallback; | 120 | listener.notify = destroyListenerCallback; | ||
113 | listener.link.prev = nullptr; | 121 | listener.link.prev = nullptr; | ||
114 | listener.link.next = nullptr; | 122 | listener.link.next = nullptr; | ||
115 | wl_resource_add_destroy_listener(resource, &listener); | 123 | wl_resource_add_destroy_listener(resource, &listener); | ||
116 | if (shmBuffer) { | 124 | if (shmBuffer) { | ||
117 | size = QSize(wl_shm_buffer_get_width(shmBuffer), wl_shm_buffer_get_height(shmBuffer)); | 125 | size = QSize(wl_shm_buffer_get_width(shmBuffer), wl_shm_buffer_get_height(shmBuffer)); | ||
118 | // check alpha | 126 | // check alpha | ||
119 | switch (wl_shm_buffer_get_format(shmBuffer)) { | 127 | switch (wl_shm_buffer_get_format(shmBuffer)) { | ||
120 | case WL_SHM_FORMAT_ARGB8888: | 128 | case WL_SHM_FORMAT_ARGB8888: | ||
121 | alpha = true; | 129 | alpha = true; | ||
122 | break; | 130 | break; | ||
123 | case WL_SHM_FORMAT_XRGB8888: | 131 | case WL_SHM_FORMAT_XRGB8888: | ||
124 | default: | 132 | default: | ||
125 | alpha = false; | 133 | alpha = false; | ||
126 | break; | 134 | break; | ||
127 | } | 135 | } | ||
136 | } else if (dmabufBuffer) { | ||||
137 | switch (dmabufBuffer->format()) { | ||||
138 | case DRM_FORMAT_ARGB4444: | ||||
139 | case DRM_FORMAT_ABGR4444: | ||||
140 | case DRM_FORMAT_RGBA4444: | ||||
141 | case DRM_FORMAT_BGRA4444: | ||||
142 | | ||||
143 | case DRM_FORMAT_ARGB1555: | ||||
144 | case DRM_FORMAT_ABGR1555: | ||||
145 | case DRM_FORMAT_RGBA5551: | ||||
146 | case DRM_FORMAT_BGRA5551: | ||||
147 | | ||||
148 | case DRM_FORMAT_ARGB8888: | ||||
149 | case DRM_FORMAT_ABGR8888: | ||||
150 | case DRM_FORMAT_RGBA8888: | ||||
151 | case DRM_FORMAT_BGRA8888: | ||||
152 | | ||||
153 | case DRM_FORMAT_ARGB2101010: | ||||
154 | case DRM_FORMAT_ABGR2101010: | ||||
155 | case DRM_FORMAT_RGBA1010102: | ||||
156 | case DRM_FORMAT_BGRA1010102: | ||||
157 | | ||||
158 | case DRM_FORMAT_XRGB8888_A8: | ||||
159 | case DRM_FORMAT_XBGR8888_A8: | ||||
160 | case DRM_FORMAT_RGBX8888_A8: | ||||
161 | case DRM_FORMAT_BGRX8888_A8: | ||||
162 | case DRM_FORMAT_RGB888_A8: | ||||
163 | case DRM_FORMAT_BGR888_A8: | ||||
164 | case DRM_FORMAT_RGB565_A8: | ||||
165 | case DRM_FORMAT_BGR565_A8: | ||||
166 | alpha = true; | ||||
167 | break; | ||||
168 | default: | ||||
169 | alpha = false; | ||||
170 | break; | ||||
171 | } | ||||
172 | size = dmabufBuffer->size(); | ||||
128 | } else if (parent) { | 173 | } else if (parent) { | ||
129 | EGLDisplay eglDisplay = parent->global()->display()->eglDisplay(); | 174 | EGLDisplay eglDisplay = parent->global()->display()->eglDisplay(); | ||
130 | static bool resolved = false; | 175 | static bool resolved = false; | ||
131 | using namespace EGL; | 176 | using namespace EGL; | ||
132 | if (!resolved && eglDisplay != EGL_NO_DISPLAY) { | 177 | if (!resolved && eglDisplay != EGL_NO_DISPLAY) { | ||
133 | eglQueryWaylandBufferWL = (eglQueryWaylandBufferWL_func)eglGetProcAddress("eglQueryWaylandBufferWL"); | 178 | eglQueryWaylandBufferWL = (eglQueryWaylandBufferWL_func)eglGetProcAddress("eglQueryWaylandBufferWL"); | ||
134 | resolved = true; | 179 | resolved = true; | ||
135 | } | 180 | } | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 314 | { | |||
270 | return d->surface; | 315 | return d->surface; | ||
271 | } | 316 | } | ||
272 | 317 | | |||
273 | wl_shm_buffer *BufferInterface::shmBuffer() | 318 | wl_shm_buffer *BufferInterface::shmBuffer() | ||
274 | { | 319 | { | ||
275 | return d->shmBuffer; | 320 | return d->shmBuffer; | ||
276 | } | 321 | } | ||
277 | 322 | | |||
323 | LinuxDmabuf::Buffer *BufferInterface::linuxDmabufBuffer() | ||||
324 | { | ||||
325 | return d->dmabufBuffer; | ||||
326 | } | ||||
327 | | ||||
278 | wl_resource *BufferInterface::resource() const | 328 | wl_resource *BufferInterface::resource() const | ||
279 | { | 329 | { | ||
280 | return d->buffer; | 330 | return d->buffer; | ||
281 | } | 331 | } | ||
282 | 332 | | |||
283 | QSize BufferInterface::size() const | 333 | QSize BufferInterface::size() const | ||
284 | { | 334 | { | ||
285 | return d->size; | 335 | return d->size; | ||
Show All 18 Lines |