|
| 1 | +/*==LICENSE==* |
| 2 | +
|
| 3 | +CyanWorlds.com Engine - MMOG client, server and tools |
| 4 | +Copyright (C) 2011 Cyan Worlds, Inc. |
| 5 | +
|
| 6 | +This program is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU General Public License as published by |
| 8 | +the Free Software Foundation, either version 3 of the License, or |
| 9 | +(at your option) any later version. |
| 10 | +
|
| 11 | +This program is distributed in the hope that it will be useful, |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +
|
| 19 | +Additional permissions under GNU GPL version 3 section 7 |
| 20 | +
|
| 21 | +If you modify this Program, or any covered work, by linking or |
| 22 | +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
| 23 | +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
| 24 | +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
| 25 | +(or a modified version of those libraries), |
| 26 | +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
| 27 | +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
| 28 | +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
| 29 | +licensors of this Program grant you additional |
| 30 | +permission to convey the resulting work. Corresponding Source for a |
| 31 | +non-source form of such a combination shall include the source code for |
| 32 | +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
| 33 | +work. |
| 34 | +
|
| 35 | +You can contact Cyan Worlds, Inc. by email legal@cyan.com |
| 36 | + or by snail mail at: |
| 37 | + Cyan Worlds, Inc. |
| 38 | + 14617 N Newport Hwy |
| 39 | + Mead, WA 99021 |
| 40 | +
|
| 41 | +*==LICENSE==*/ |
| 42 | + |
| 43 | +#include "plWaylandDisplayHelper.h" |
| 44 | + |
| 45 | +#include <cstring> |
| 46 | +#include "plWaylandFunctions.h" |
| 47 | + |
| 48 | +template <typename... Args> void ignore(Args...) {} |
| 49 | + |
| 50 | +void plWaylandDisplayHelper::output_handle_mode(void* data, wl_output* wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) |
| 51 | +{ |
| 52 | + plWaylandDisplayHelper* self = reinterpret_cast<plWaylandDisplayHelper*>(data); |
| 53 | + |
| 54 | + if (flags & WL_OUTPUT_MODE_CURRENT) { |
| 55 | + self->fDisplayModes.emplace_back(plDisplayMode { |
| 56 | + width, |
| 57 | + height, |
| 58 | + 32 |
| 59 | + }); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +void plWaylandDisplayHelper::global_handler(void* data, wl_registry* registry, uint32_t id, const char* interface, uint32_t version) |
| 64 | +{ |
| 65 | + plWaylandDisplayHelper* self = reinterpret_cast<plWaylandDisplayHelper*>(data); |
| 66 | + |
| 67 | + if (strcmp(interface, (*__wl_output_interface).name) == 0) { |
| 68 | + static const wl_output_listener output_listener = { |
| 69 | + &ignore, |
| 70 | + &plWaylandDisplayHelper::output_handle_mode, |
| 71 | + &ignore, |
| 72 | + &ignore, |
| 73 | + &ignore, |
| 74 | + &ignore |
| 75 | + }; |
| 76 | + |
| 77 | + self->fCurrentOutput = reinterpret_cast<wl_output*>(wl_registry_bind(registry, id, &__wl_output_interface, std::min<uint32_t>((*__wl_output_interface).version, version))); |
| 78 | + wl_output_add_listener(self->fCurrentOutput, &output_listener, data); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +plWaylandDisplayHelper::plWaylandDisplayHelper() : fCurrentDisplay(), fCurrentRegistry(), fCurrentOutput() |
| 83 | +{ |
| 84 | +} |
| 85 | + |
| 86 | +plWaylandDisplayHelper::~plWaylandDisplayHelper() |
| 87 | +{ |
| 88 | + if (fCurrentRegistry) |
| 89 | + wl_registry_destroy(fCurrentRegistry); |
| 90 | + |
| 91 | + if (fCurrentDisplay) |
| 92 | + __wl_display_disconnect(fCurrentDisplay); |
| 93 | +} |
| 94 | + |
| 95 | +void plWaylandDisplayHelper::SetCurrentScreen(wl_display* display) const |
| 96 | +{ |
| 97 | + if (fCurrentDisplay == display) |
| 98 | + return; |
| 99 | + else if (fCurrentDisplay) { |
| 100 | + if (fCurrentRegistry) |
| 101 | + wl_registry_destroy(fCurrentRegistry); |
| 102 | + |
| 103 | + __wl_display_disconnect(fCurrentDisplay); |
| 104 | + } |
| 105 | + |
| 106 | + fCurrentDisplay = display; |
| 107 | + if (!fCurrentDisplay) |
| 108 | + return; |
| 109 | + |
| 110 | + fCurrentRegistry = wl_display_get_registry(fCurrentDisplay); |
| 111 | + if (!fCurrentRegistry) |
| 112 | + return; |
| 113 | + |
| 114 | + fDisplayModes.clear(); |
| 115 | + |
| 116 | + static const wl_registry_listener registry_listener = { |
| 117 | + &plWaylandDisplayHelper::global_handler, |
| 118 | + &ignore |
| 119 | + }; |
| 120 | + |
| 121 | + wl_registry_add_listener(fCurrentRegistry, ®istry_listener, const_cast<plWaylandDisplayHelper*>(this)); |
| 122 | + |
| 123 | + __wl_display_roundtrip(fCurrentDisplay); |
| 124 | + __wl_display_roundtrip(fCurrentDisplay); |
| 125 | + |
| 126 | + if (fCurrentOutput) { |
| 127 | + wl_output_destroy(fCurrentOutput); |
| 128 | + fCurrentOutput = nullptr; |
| 129 | + } |
| 130 | + |
| 131 | + std::sort(fDisplayModes.begin(), fDisplayModes.end(), std::greater()); |
| 132 | + auto last = std::unique(fDisplayModes.begin(), fDisplayModes.end()); |
| 133 | + fDisplayModes.erase(last, fDisplayModes.end()); |
| 134 | +} |
| 135 | + |
| 136 | +std::vector<plDisplayMode> plWaylandDisplayHelper::GetSupportedDisplayModes(hsDisplayHndl display, int ColorDepth) const |
| 137 | +{ |
| 138 | + // Cache the current display so we can answer repeat requests quickly. |
| 139 | + // SetCurrentScreen will catch redundant sets. |
| 140 | + SetCurrentScreen(reinterpret_cast<wl_display*>(display)); |
| 141 | + return fDisplayModes; |
| 142 | +} |
| 143 | + |
| 144 | +hsDisplayHndl plWaylandDisplayHelper::DefaultDisplay() const |
| 145 | +{ |
| 146 | + if (!fCurrentDisplay) { |
| 147 | + wl_display* display = *__wl_display_connect(nullptr); |
| 148 | + SetCurrentScreen(display); |
| 149 | + } |
| 150 | + |
| 151 | + return reinterpret_cast<hsDisplayHndl>(fCurrentDisplay); |
| 152 | +} |
0 commit comments