Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 4 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 8 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 16 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef LAYER_DATA_H |
| 21 | #define LAYER_DATA_H |
| 22 | |
| 23 | #include <unordered_map> |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 24 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 25 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 26 | template <typename DATA_T> DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) { |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 27 | DATA_T *debug_data; |
| 28 | typename std::unordered_map<void *, DATA_T *>::const_iterator got; |
| 29 | |
Courtney Goeltzenleuchter | db9a96f | 2015-07-05 11:19:03 -0600 | [diff] [blame] | 30 | /* TODO: We probably should lock here, or have caller lock */ |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 31 | got = layer_data_map.find(data_key); |
| 32 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 33 | if (got == layer_data_map.end()) { |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 34 | debug_data = new DATA_T; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 35 | layer_data_map[(void *)data_key] = debug_data; |
Courtney Goeltzenleuchter | 0fef9fd | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 36 | } else { |
| 37 | debug_data = got->second; |
| 38 | } |
| 39 | |
| 40 | return debug_data; |
| 41 | } |
| 42 | |
| 43 | #endif // LAYER_DATA_H |