1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Android EGL platform.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuAndroidPlatform.hpp"
25 #include "gluRenderContext.hpp"
26 #include "egluNativeDisplay.hpp"
27 #include "egluNativeWindow.hpp"
28 #include "egluGLContextFactory.hpp"
29 #include "egluUtil.hpp"
36 static const eglu::NativeDisplay::Capability DISPLAY_CAPABILITIES = eglu::NativeDisplay::CAPABILITY_GET_DISPLAY_LEGACY;
37 static const eglu::NativeWindow::Capability WINDOW_CAPABILITIES = (eglu::NativeWindow::Capability)(eglu::NativeWindow::CAPABILITY_CREATE_SURFACE_LEGACY |
38 eglu::NativeWindow::CAPABILITY_SET_SURFACE_SIZE |
39 eglu::NativeWindow::CAPABILITY_GET_SCREEN_SIZE);
41 class NativeDisplay : public eglu::NativeDisplay
44 NativeDisplay (void) : eglu::NativeDisplay(DISPLAY_CAPABILITIES) {}
45 virtual ~NativeDisplay (void) {}
47 virtual EGLNativeDisplayType getLegacyNative (void) { return EGL_DEFAULT_DISPLAY; }
50 class NativeDisplayFactory : public eglu::NativeDisplayFactory
53 NativeDisplayFactory (Window& window);
54 ~NativeDisplayFactory (void) {}
56 virtual eglu::NativeDisplay* createDisplay (const EGLAttrib* attribList) const;
59 class NativeWindow : public eglu::NativeWindow
62 NativeWindow (Window& window, int width, int height, int32_t format);
63 virtual ~NativeWindow (void);
65 virtual EGLNativeWindowType getLegacyNative (void) { return m_window.getNativeWindow(); }
66 IVec2 getScreenSize (void) const { return m_window.getSize(); }
68 void setSurfaceSize (IVec2 size);
70 virtual void processEvents (void);
77 class NativeWindowFactory : public eglu::NativeWindowFactory
80 NativeWindowFactory (Window& window);
81 ~NativeWindowFactory (void);
83 virtual eglu::NativeWindow* createWindow (eglu::NativeDisplay* nativeDisplay, const eglu::WindowParams& params) const;
84 virtual eglu::NativeWindow* createWindow (eglu::NativeDisplay* nativeDisplay, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, const eglu::WindowParams& params) const;
92 NativeWindow::NativeWindow (Window& window, int width, int height, int32_t format)
93 : eglu::NativeWindow (WINDOW_CAPABILITIES)
97 // Try to acquire window.
98 if (!m_window.tryAcquire())
99 throw ResourceError("Native window is not available", "", __FILE__, __LINE__);
102 setSurfaceSize(IVec2(width, height));
105 NativeWindow::~NativeWindow (void)
110 void NativeWindow::processEvents (void)
114 void NativeWindow::setSurfaceSize (tcu::IVec2 size)
116 m_window.setBuffersGeometry(size.x() != eglu::WindowParams::SIZE_DONT_CARE ? size.x() : 0,
117 size.y() != eglu::WindowParams::SIZE_DONT_CARE ? size.y() : 0,
121 // NativeWindowFactory
123 NativeWindowFactory::NativeWindowFactory (Window& window)
124 : eglu::NativeWindowFactory ("default", "Default display", WINDOW_CAPABILITIES)
129 NativeWindowFactory::~NativeWindowFactory (void)
133 eglu::NativeWindow* NativeWindowFactory::createWindow (eglu::NativeDisplay* nativeDisplay, const eglu::WindowParams& params) const
135 DE_UNREF(nativeDisplay);
136 return new NativeWindow(m_window, params.width, params.height, WINDOW_FORMAT_RGBA_8888);
139 eglu::NativeWindow* NativeWindowFactory::createWindow (eglu::NativeDisplay* nativeDisplay, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, const eglu::WindowParams& params) const
141 const int32_t format = (int32_t)eglu::getConfigAttribInt(display, config, EGL_NATIVE_VISUAL_ID);
142 DE_UNREF(nativeDisplay && attribList);
143 return new NativeWindow(m_window, params.width, params.height, format);
146 // NativeDisplayFactory
148 NativeDisplayFactory::NativeDisplayFactory (Window& window)
149 : eglu::NativeDisplayFactory("default", "Default display", DISPLAY_CAPABILITIES)
151 m_nativeWindowRegistry.registerFactory(new NativeWindowFactory(window));
154 eglu::NativeDisplay* NativeDisplayFactory::createDisplay (const EGLAttrib* attribList) const
156 DE_UNREF(attribList);
157 return new NativeDisplay();
162 Platform::Platform (ANativeWindow* window)
165 m_nativeDisplayFactoryRegistry.registerFactory(new NativeDisplayFactory(m_window));
166 m_contextFactoryRegistry.registerFactory(new eglu::GLContextFactory(m_nativeDisplayFactoryRegistry));
169 Platform::~Platform (void)