Imported Debian patch 0.1.0+git20131207+e452e83-0ubuntu12
[deb_libhybris.git] / hybris / egl / platforms / wayland / wayland_window.h
... / ...
CommitLineData
1/****************************************************************************************
2 **
3 ** Copyright (C) 2013 Jolla Ltd.
4 ** Contact: Carsten Munk <carsten.munk@jollamobile.com>
5 ** All rights reserved.
6 **
7 ** This file is part of Wayland enablement for libhybris
8 **
9 ** You may use this file under the terms of the GNU Lesser General
10 ** Public License version 2.1 as published by the Free Software Foundation
11 ** and appearing in the file license.lgpl included in the packaging
12 ** of this file.
13 **
14 ** This library is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU Lesser General Public
16 ** License version 2.1 as published by the Free Software Foundation
17 ** and appearing in the file license.lgpl included in the packaging
18 ** of this file.
19 **
20 ** This library is distributed in the hope that it will be useful,
21 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ** Lesser General Public License for more details.
24 **
25 ****************************************************************************************/
26
27
28#ifndef Wayland_WINDOW_H
29#define Wayland_WINDOW_H
30#include "nativewindowbase.h"
31#include <linux/fb.h>
32#include <android/hardware/gralloc.h>
33extern "C" {
34
35#include <wayland-client.h>
36#include <wayland-egl.h>
37#include "wayland-android-client-protocol.h"
38#include <pthread.h>
39}
40#include <list>
41
42class WaylandNativeWindowBuffer : public BaseNativeWindowBuffer
43{
44friend class WaylandNativeWindow;
45protected:
46 WaylandNativeWindowBuffer(alloc_device_t* alloc_device,
47 unsigned int width,
48 unsigned int height,
49 unsigned int format,
50 unsigned int usage)
51 {
52 // Base members
53 ANativeWindowBuffer::width = width;
54 ANativeWindowBuffer::height = height;
55 ANativeWindowBuffer::format = format;
56 ANativeWindowBuffer::usage = usage;
57 this->wlbuffer = NULL;
58 this->busy = 0;
59 this->other = NULL;
60 this->m_alloc = alloc_device;
61 int alloc_ok = this->m_alloc->alloc(this->m_alloc,
62 this->width ? this->width : 1, this->height ? this->height : 1,
63 this->format, this->usage,
64 &this->handle, &this->stride);
65 assert(alloc_ok == 0);
66 this->youngest = 0;
67 }
68 WaylandNativeWindowBuffer(ANativeWindowBuffer *other)
69 {
70 ANativeWindowBuffer::width = other->width;
71 ANativeWindowBuffer::height = other->height;
72 ANativeWindowBuffer::format = other->format;
73 ANativeWindowBuffer::usage = other->usage;
74 ANativeWindowBuffer::handle = other->handle;
75 ANativeWindowBuffer::stride = other->stride;
76 this->wlbuffer = NULL;
77 this->busy = 0;
78 this->other = other;
79 this->m_alloc = NULL;
80 this->youngest = 0;
81 }
82 ~WaylandNativeWindowBuffer()
83 {
84 if (this->m_alloc)
85 m_alloc->free(m_alloc, this->handle);
86 }
87 void wlbuffer_from_native_handle(struct android_wlegl *android_wlegl);
88
89protected:
90 void* vaddr;
91 alloc_device_t* m_alloc;
92
93public:
94 struct wl_buffer *wlbuffer;
95 int busy;
96 int youngest;
97 ANativeWindowBuffer *other;
98};
99
100
101class WaylandNativeWindow : public BaseNativeWindow {
102public:
103 WaylandNativeWindow(struct wl_egl_window *win, struct wl_display *display, const gralloc_module_t* gralloc, alloc_device_t* alloc_device);
104 ~WaylandNativeWindow();
105
106 void lock();
107 void unlock();
108 void frame();
109 void releaseBuffer(struct wl_buffer *buffer);
110 int postBuffer(ANativeWindowBuffer *buffer);
111
112 static void sync_callback(void *data, struct wl_callback *callback, uint32_t serial);
113 static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
114 const char *interface, uint32_t version);
115 static void resize_callback(struct wl_egl_window *egl_window, void *);
116 struct wl_event_queue *wl_queue;
117
118protected:
119 // overloads from BaseNativeWindow
120 virtual int setSwapInterval(int interval);
121 virtual int dequeueBuffer(BaseNativeWindowBuffer **buffer, int *fenceFd);
122 virtual int lockBuffer(BaseNativeWindowBuffer* buffer);
123 virtual int queueBuffer(BaseNativeWindowBuffer* buffer, int fenceFd);
124 virtual int cancelBuffer(BaseNativeWindowBuffer* buffer, int fenceFd);
125 virtual unsigned int type() const;
126 virtual unsigned int width() const;
127 virtual unsigned int height() const;
128 virtual unsigned int format() const;
129 virtual unsigned int defaultWidth() const;
130 virtual unsigned int defaultHeight() const;
131 virtual unsigned int queueLength() const;
132 virtual unsigned int transformHint() const;
133 // perform calls
134 virtual int setUsage(int usage);
135 virtual int setBuffersFormat(int format);
136 virtual int setBuffersDimensions(int width, int height);
137 virtual int setBufferCount(int cnt);
138
139private:
140 WaylandNativeWindowBuffer *addBuffer();
141 void destroyBuffer(WaylandNativeWindowBuffer *);
142 void destroyBuffers();
143 std::list<WaylandNativeWindowBuffer *> m_bufList;
144 std::list<WaylandNativeWindowBuffer *> fronted;
145 std::list<WaylandNativeWindowBuffer *> posted;
146 std::list<WaylandNativeWindowBuffer *> post_registered;
147 struct wl_egl_window *m_window;
148 struct wl_display *m_display;
149 unsigned int m_width;
150 unsigned int m_height;
151 unsigned int m_format;
152 unsigned int m_defaultWidth;
153 unsigned int m_defaultHeight;
154 unsigned int m_usage;
155 struct android_wlegl *m_android_wlegl;
156 alloc_device_t* m_alloc;
157 struct wl_registry *registry;
158 const gralloc_module_t* m_gralloc;
159 pthread_mutex_t mutex;
160 pthread_cond_t cond;
161 int m_freeBufs;
162 struct wl_callback *frame_callback;
163 static int wayland_roundtrip(WaylandNativeWindow *display);
164};
165
166#endif
167// vim: noai:ts=4:sw=4:ss=4:expandtab