1 /****************************************************************************************
3 ** Copyright (C) 2013 Jolla Ltd.
4 ** Contact: Carsten Munk <carsten.munk@jollamobile.com>
5 ** All rights reserved.
7 ** This file is part of Wayland enablement for libhybris
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
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
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.
25 ****************************************************************************************/
28 #ifndef Wayland_WINDOW_H
29 #define Wayland_WINDOW_H
30 #include "nativewindowbase.h"
32 #include <android/hardware/gralloc.h>
35 #include <wayland-client.h>
36 #include <wayland-egl.h>
37 #include "wayland-android-client-protocol.h"
42 class WaylandNativeWindowBuffer
: public BaseNativeWindowBuffer
44 friend class WaylandNativeWindow
;
46 WaylandNativeWindowBuffer(alloc_device_t
* alloc_device
,
53 ANativeWindowBuffer::width
= width
;
54 ANativeWindowBuffer::height
= height
;
55 ANativeWindowBuffer::format
= format
;
56 ANativeWindowBuffer::usage
= usage
;
57 this->wlbuffer
= 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);
68 WaylandNativeWindowBuffer(ANativeWindowBuffer
*other
)
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
;
82 ~WaylandNativeWindowBuffer()
85 m_alloc
->free(m_alloc
, this->handle
);
87 void wlbuffer_from_native_handle(struct android_wlegl
*android_wlegl
);
91 alloc_device_t
* m_alloc
;
94 struct wl_buffer
*wlbuffer
;
97 ANativeWindowBuffer
*other
;
101 class WaylandNativeWindow
: public BaseNativeWindow
{
103 WaylandNativeWindow(struct wl_egl_window
*win
, struct wl_display
*display
, const gralloc_module_t
* gralloc
, alloc_device_t
* alloc_device
);
104 ~WaylandNativeWindow();
109 void releaseBuffer(struct wl_buffer
*buffer
);
110 int postBuffer(ANativeWindowBuffer
*buffer
);
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
;
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;
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
);
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
;
162 struct wl_callback
*frame_callback
;
163 static int wayland_roundtrip(WaylandNativeWindow
*display
);
167 // vim: noai:ts=4:sw=4:ss=4:expandtab