Change copyrights from Nokia to Digia
[profile/ivi/qtwayland.git] / src / compositor / wayland_wrapper / wlsubsurface.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt Compositor.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 **     of its contributors may be used to endorse or promote products derived
22 **     from this software without specific prior written permission.
23 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #include "wlsubsurface.h"
42
43 #include "wlcompositor.h"
44 #include "waylandsurface.h"
45
46 namespace Wayland {
47
48 SubSurfaceExtensionGlobal::SubSurfaceExtensionGlobal(Compositor *compositor)
49     : m_compositor(compositor)
50 {
51     wl_display_add_global(m_compositor->wl_display(),
52                           &wl_sub_surface_extension_interface,
53                           this,
54                           SubSurfaceExtensionGlobal::bind_func);
55 }
56
57 void SubSurfaceExtensionGlobal::bind_func(wl_client *client, void *data, uint32_t version, uint32_t id)
58 {
59     Q_UNUSED(version);
60     wl_client_add_object(client, &wl_sub_surface_extension_interface,&sub_surface_extension_interface,id,data);
61 }
62
63 void SubSurfaceExtensionGlobal::get_sub_surface_aware_surface(wl_client *client, wl_resource *sub_surface_extension_resource, uint32_t id, wl_resource *surface_resource)
64 {
65     Q_UNUSED(sub_surface_extension_resource);
66     Surface *surface = resolve<Surface>(surface_resource);
67     new SubSurface(client,id,surface);
68 }
69
70 const struct wl_sub_surface_extension_interface SubSurfaceExtensionGlobal::sub_surface_extension_interface = {
71     SubSurfaceExtensionGlobal::get_sub_surface_aware_surface
72 };
73
74 SubSurface::SubSurface(wl_client *client, uint32_t id, Surface *surface)
75     : m_surface(surface)
76     , m_parent(0)
77 {
78     surface->setSubSurface(this);
79     m_sub_surface_resource = wl_client_add_object(client,
80                                                        &wl_sub_surface_interface,
81                                                        &sub_surface_interface,
82                                                        id,
83                                                        this);
84 }
85
86 SubSurface::~SubSurface()
87 {
88     if (m_parent) {
89         m_parent->removeSubSurface(this);
90     }
91     QLinkedList<WaylandSurface *>::iterator it;
92     for (it = m_sub_surfaces.begin(); it != m_sub_surfaces.end(); ++it) {
93         (*it)->handle()->subSurface()->parentDestroyed();
94     }
95 }
96
97 void SubSurface::setSubSurface(SubSurface *subSurface, int x, int y)
98 {
99     if (!m_sub_surfaces.contains(subSurface->m_surface->waylandSurface())) {
100         m_sub_surfaces.append(subSurface->m_surface->waylandSurface());
101         subSurface->setParent(this);
102     }
103     subSurface->m_surface->setPos(QPointF(x,y));
104 }
105
106 void SubSurface::removeSubSurface(SubSurface *subSurfaces)
107 {
108     Q_ASSERT(m_sub_surfaces.contains(subSurfaces->m_surface->waylandSurface()));
109     m_sub_surfaces.removeOne(subSurfaces->m_surface->waylandSurface());
110 }
111
112 SubSurface *SubSurface::parent() const
113 {
114     return m_parent;
115 }
116
117 void SubSurface::setParent(SubSurface *parent)
118 {
119     if (m_parent == parent)
120         return;
121
122     WaylandSurface *oldParent = 0;
123     WaylandSurface *newParent = 0;
124
125     if (m_parent) {
126         oldParent = m_parent->m_surface->waylandSurface();
127         m_parent->removeSubSurface(this);
128     }
129     if (parent) {
130         newParent = parent->m_surface->waylandSurface();
131     }
132     m_parent = parent;
133
134     m_surface->waylandSurface()->parentChanged(newParent,oldParent);
135 }
136
137 QLinkedList<WaylandSurface *> SubSurface::subSurfaces() const
138 {
139     return m_sub_surfaces;
140 }
141
142 void SubSurface::parentDestroyed()
143 {
144     m_parent = 0;
145 }
146 void SubSurface::attach_sub_surface(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource, int32_t x, int32_t y)
147 {
148     Q_UNUSED(client);
149     SubSurface *parent_sub_surface = static_cast<SubSurface *>(sub_surface_parent_resource->data);
150     SubSurface *child_sub_surface = static_cast<SubSurface *>(sub_surface_child_resource->data);
151     parent_sub_surface->setSubSurface(child_sub_surface,x,y);
152 }
153
154 void SubSurface::move_sub_surface(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource, int32_t x, int32_t y)
155 {
156     Q_UNUSED(client);
157     Q_UNUSED(x);
158     Q_UNUSED(y);
159     SubSurface *parent_sub_surface = static_cast<SubSurface *>(sub_surface_parent_resource->data);
160     SubSurface *child_sub_surface = static_cast<SubSurface *>(sub_surface_child_resource->data);
161     Q_UNUSED(parent_sub_surface);
162     Q_UNUSED(child_sub_surface);
163 }
164
165 void SubSurface::raise(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource)
166 {
167     Q_UNUSED(client);
168     Q_UNUSED(sub_surface_parent_resource);
169     Q_UNUSED(sub_surface_child_resource);
170 }
171
172 void SubSurface::lower(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource)
173 {
174     Q_UNUSED(client);
175     Q_UNUSED(sub_surface_parent_resource);
176     Q_UNUSED(sub_surface_child_resource);
177 }
178
179 const struct wl_sub_surface_interface SubSurface::sub_surface_interface = {
180     SubSurface::attach_sub_surface,
181     SubSurface::move_sub_surface,
182     SubSurface::raise,
183     SubSurface::lower
184 };
185
186 }