Change copyrights from Nokia to Digia
[profile/ivi/qtwayland.git] / src / compositor / wayland_wrapper / wlextendedoutput.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 "wlextendedoutput.h"
42
43 #include "wlcompositor.h"
44 #include "wlsurface.h"
45 #include "wloutput.h"
46
47 namespace Wayland {
48
49 OutputExtensionGlobal::OutputExtensionGlobal(Compositor *compositor)
50     : m_compositor(compositor)
51 {
52     wl_display_add_global(compositor->wl_display(),
53                           &wl_output_extension_interface,
54                           this,
55                           OutputExtensionGlobal::bind_func);
56 }
57
58 void OutputExtensionGlobal::bind_func(wl_client *client, void *data, uint32_t version, uint32_t id)
59 {
60     Q_UNUSED(version);
61     wl_client_add_object(client,&wl_output_extension_interface,&output_extension_interface,id,data);
62 }
63
64 void OutputExtensionGlobal::get_extended_output(wl_client *client, wl_resource *output_extension_resource, uint32_t id, wl_resource *output_resource)
65 {
66     OutputExtensionGlobal *output_extension = static_cast<OutputExtensionGlobal *>(output_extension_resource->data);
67     Output *output = static_cast<Output *>(output_resource->data);
68     new ExtendedOutput(client,id,output,output_extension->m_compositor);
69 }
70
71 const struct wl_output_extension_interface OutputExtensionGlobal::output_extension_interface = {
72     OutputExtensionGlobal::get_extended_output
73 };
74
75 ExtendedOutput::ExtendedOutput(struct wl_client *client, uint32_t id, Output *output, Compositor *compositor)
76     : m_output(output)
77     , m_compositor(compositor)
78 {
79     static const struct wl_extended_output_interface extended_output_interface = {
80         set_orientation_update_mask
81     };
82     Q_ASSERT(m_output->extendedOutput() == 0);
83     m_output->setExtendedOutput(this);
84     m_extended_output_resource = wl_client_add_object(client,&wl_extended_output_interface,&extended_output_interface,id,this);
85     m_extended_output_resource->destroy = ExtendedOutput::destroy_resource;
86
87     sendOutputOrientation(m_compositor->screenOrientation());
88 }
89
90 void ExtendedOutput::destroy_resource(wl_resource *resource)
91 {
92     ExtendedOutput *output = static_cast<ExtendedOutput *>(resource->data);
93     delete output;
94     free(resource);
95 }
96
97 void ExtendedOutput::set_orientation_update_mask(struct wl_client *client,
98                                                  struct wl_resource *resource,
99                                                  int32_t orientation_update_mask)
100 {
101     ExtendedOutput *output = static_cast<ExtendedOutput *>(resource->data);
102
103     Qt::ScreenOrientations mask = 0;
104     if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION)
105         mask |= Qt::PortraitOrientation;
106     if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION)
107         mask |= Qt::LandscapeOrientation;
108     if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION)
109         mask |= Qt::InvertedPortraitOrientation;
110     if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION)
111         mask |= Qt::InvertedLandscapeOrientation;
112
113     Qt::ScreenOrientations oldMask = output->m_orientationUpdateMask;
114     output->m_orientationUpdateMask = mask;
115
116     if (mask != oldMask) {
117         QList<Surface*> surfaces = output->m_compositor->surfacesForClient(client);
118         foreach (Surface *surface, surfaces) {
119             if (surface->waylandSurface())
120                 emit surface->waylandSurface()->orientationUpdateMaskChanged();
121         }
122     }
123 }
124
125 void ExtendedOutput::sendOutputOrientation(Qt::ScreenOrientation orientation)
126 {
127     int sendOpperation;
128     switch (orientation) {
129         case Qt::PortraitOrientation:
130             sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
131             break;
132     case Qt::LandscapeOrientation:
133             sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION;
134             break;
135     case Qt::InvertedPortraitOrientation:
136             sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION;
137             break;
138     case Qt::InvertedLandscapeOrientation:
139             sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION;
140             break;
141     default:
142         sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
143     }
144     wl_extended_output_send_set_screen_rotation(m_extended_output_resource, sendOpperation);
145 }
146
147
148 }