1#ifndef _TCUIOSPLATFORM_HPP
2#define _TCUIOSPLATFORM_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief iOS Platform implementation.
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuDefs.hpp"
27#include "tcuPlatform.hpp"
28#include "gluPlatform.hpp"
29#include "gluRenderContext.hpp"
30#include "gluContextFactory.hpp"
31#include "gluObjectWrapper.hpp"
32#include "tcuRenderTarget.hpp"
33#include "glwFunctions.hpp"
34#include "deMutex.hpp"
35
36#import "tcuEAGLView.h"
37
38#import <OpenGLES/EAGL.h>
39
40namespace tcu
41{
42namespace ios
43{
44
45class ScreenManager
46{
47public:
48									ScreenManager			(tcuEAGLView* view);
49									~ScreenManager			(void);
50
51	CAEAGLLayer*					acquireScreen			(void);
52	void							releaseScreen			(CAEAGLLayer* layer);
53
54private:
55									ScreenManager			(const ScreenManager&);
56	ScreenManager&					operator=				(const ScreenManager&);
57
58	tcuEAGLView*					m_view;
59	de::Mutex						m_viewLock;
60};
61
62class ContextFactory : public glu::ContextFactory
63{
64public:
65									ContextFactory			(ScreenManager* screenManager);
66									~ContextFactory			(void);
67
68	glu::RenderContext*				createContext			(const glu::RenderConfig& config, const tcu::CommandLine& cmdLine) const;
69
70private:
71	ScreenManager* const			m_screenManager;
72};
73
74class Platform : public tcu::Platform, private glu::Platform
75{
76public:
77									Platform				(ScreenManager* screenManager);
78	virtual							~Platform				(void);
79
80	const glu::Platform&			getGLPlatform			(void) const { return static_cast<const glu::Platform&>(*this); }
81};
82
83//! EAGLContext-backed rendering context. Doesn't have default framebuffer.
84class RawContext : public glu::RenderContext
85{
86public:
87									RawContext				(glu::ContextType type);
88	virtual							~RawContext				(void);
89
90	virtual glu::ContextType		getType					(void) const { return m_type;							}
91	virtual const glw::Functions&	getFunctions			(void) const { return m_functions;						}
92	virtual const RenderTarget&		getRenderTarget			(void) const { return m_emptyTarget;					}
93	virtual deUint32				getDefaultFramebuffer	(void) const { DE_ASSERT(!"No framebuffer"); return 0;	}
94	virtual void					postIterate				(void);
95
96protected:
97	EAGLContext*					getEAGLContext			(void) const { return m_context; }
98
99private:
100	glu::ContextType				m_type;
101	EAGLContext*					m_context;
102	glw::Functions					m_functions;
103	tcu::RenderTarget				m_emptyTarget;
104};
105
106class ScreenContext : public RawContext
107{
108public:
109									ScreenContext			(ScreenManager* screenManager, const glu::RenderConfig& config);
110									~ScreenContext			(void);
111
112	virtual const RenderTarget&		getRenderTarget			(void) const { return m_renderTarget;	}
113	virtual deUint32				getDefaultFramebuffer	(void) const { return *m_framebuffer;	}
114	virtual void					postIterate				(void);
115
116private:
117	void							createFramebuffer		(const glu::RenderConfig& config);
118
119	ScreenManager*					m_screenManager;
120	CAEAGLLayer*					m_layer;
121
122	glu::Framebuffer				m_framebuffer;
123	glu::Renderbuffer				m_colorBuffer;
124	glu::Renderbuffer				m_depthStencilBuffer;
125	tcu::RenderTarget				m_renderTarget;
126};
127
128} // ios
129} // tcu
130
131#endif // _TCUIOSPLATFORM_H
132