| 1 | |
| 2 | /* |
| 3 | * Copyright (c) 2013 Jolla Ltd. |
| 4 | * Contact: Thomas Perl <thomas.perl@jollamobile.com> |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include "helper.h" |
| 22 | |
| 23 | #include <assert.h> |
| 24 | #include <map> |
| 25 | |
| 26 | |
| 27 | /* Keep track of active EGL window surfaces */ |
| 28 | static std::map<EGLSurface,EGLNativeWindowType> _surface_window_map; |
| 29 | |
| 30 | |
| 31 | void egl_helper_push_mapping(EGLSurface surface, EGLNativeWindowType window) |
| 32 | { |
| 33 | assert(!egl_helper_has_mapping(surface)); |
| 34 | |
| 35 | _surface_window_map[surface] = window; |
| 36 | } |
| 37 | |
| 38 | int egl_helper_has_mapping(EGLSurface surface) |
| 39 | { |
| 40 | return (_surface_window_map.find(surface) != _surface_window_map.end()); |
| 41 | } |
| 42 | |
| 43 | EGLNativeWindowType egl_helper_pop_mapping(EGLSurface surface) |
| 44 | { |
| 45 | std::map<EGLSurface,EGLNativeWindowType>::iterator it; |
| 46 | it = _surface_window_map.find(surface); |
| 47 | |
| 48 | /* Caller must check with egl_helper_has_mapping() before */ |
| 49 | assert(it != _surface_window_map.end()); |
| 50 | |
| 51 | EGLNativeWindowType result = it->second; |
| 52 | _surface_window_map.erase(it); |
| 53 | return result; |
| 54 | } |