1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <map>
21 
22 #include <EGL/egl.h>
23 #include <EGL/eglext.h>
24 
25 typedef EGLBoolean (*PFNEGLDESTROYIMAGEKHR)(EGLDisplay, EGLImageKHR);
26 
27 struct EglImage {
28     static std::map<uint32_t, EglImage*> map;
29     static uint32_t nextId;
30 
EglImageEglImage31     EglImage(EGLDisplay dpy_, EGLImageKHR image_, PFNEGLDESTROYIMAGEKHR pfnEglDestroyImageKHR_)
32         : pfnEglDestroyImageKHR(pfnEglDestroyImageKHR_), image(image_), dpy(dpy_), id(nextId++) {
33         map.emplace(id, this);
34     }
35 
~EglImageEglImage36     ~EglImage() {
37         pfnEglDestroyImageKHR(dpy, image);
38         map.erase(id);
39     }
40 
41     PFNEGLDESTROYIMAGEKHR pfnEglDestroyImageKHR;
42     EGLImageKHR image;
43     EGLDisplay dpy;
44     uint32_t id;
45 };
46