1 /*
2 * Copyright (C) 2011 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 #include "EglWindowSurface.h"
17 #include "EglGlobalInfo.h"
18 #include "EglOsApi.h"
19
20 // this static member is accessed from a function registered in onexit()
21 // for the emulator cleanup. As all static C++ objects are also being freed
22 // from a system handler registered in onexit(), we can't have a class object
23 // by value here - it would be prone to unstable deinitialization order issue;
s_associatedWins()24 static std::set<EGLNativeWindowType>* s_associatedWins() {
25 static std::set<EGLNativeWindowType>* ws = new std::set<EGLNativeWindowType>;
26 return ws;
27 }
28
alreadyAssociatedWithConfig(EGLNativeWindowType win)29 bool EglWindowSurface::alreadyAssociatedWithConfig(EGLNativeWindowType win) {
30 return s_associatedWins()->find(win) != s_associatedWins()->end();
31 }
32
EglWindowSurface(EglDisplay * dpy,EGLNativeWindowType win,EglConfig * config,unsigned int width,unsigned int height)33 EglWindowSurface::EglWindowSurface(EglDisplay* dpy,
34 EGLNativeWindowType win,
35 EglConfig* config,
36 unsigned int width,
37 unsigned int height) :
38 EglSurface(dpy, WINDOW, config, width, height),
39 m_win(win) {
40 s_associatedWins()->insert(win);
41 EglOS::Engine* engine = EglGlobalInfo::getInstance()->getOsEngine();
42 m_native = engine->createWindowSurface(config->nativeFormat(), win);
43 }
44
~EglWindowSurface()45 EglWindowSurface::~EglWindowSurface() {
46 s_associatedWins()->erase(m_win);
47 }
48
getAttrib(EGLint attrib,EGLint * val)49 bool EglWindowSurface::getAttrib(EGLint attrib,EGLint* val) {
50 switch(attrib) {
51 case EGL_CONFIG_ID:
52 *val = m_config->id();
53 break;
54 case EGL_WIDTH:
55 *val = m_width;
56 break;
57 case EGL_HEIGHT:
58 *val = m_height;
59 break;
60 case EGL_LARGEST_PBUFFER:
61 case EGL_TEXTURE_FORMAT:
62 case EGL_TEXTURE_TARGET:
63 case EGL_MIPMAP_TEXTURE:
64 break;
65 default:
66 return false;
67 }
68 return true;
69 }
70