DrawableViewNativeRenderer for Direct Rendering
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / toolkit-direct-rendering-egl.cpp
1 /*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
18 #include <EGL/egl.h>
19 #include <GLES3/gl3.h>
20 extern "C"
21 {
22
23 // Flag to be set when we want shader compilation fail
24 bool gDirectRenderingFailCreateShader = false;
25
26 // Flag to be set when we want program linking fail
27 bool gDirectRenderingFailCreateProgram = false;
28
29 /**
30  * To test the multithreaded variant we need override EGL api
31  *
32  * The Direct Rendering uses GL directly and it's needed to override certain funtions in order
33  * to force code execution.
34  */
35 EGLContext eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
36 {
37  return EGLContext(0x12345678);
38 }
39
40 EGLBoolean eglGetConfigs (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
41 {
42   static EGLConfig config;
43   if(num_config)
44   {
45     *num_config = 1;
46   }
47   if(configs)
48   {
49     configs[0] = config;
50   }
51
52   return EGL_TRUE;
53 }
54
55 GLuint glCreateProgram (void)
56 {
57   static uint32_t programId = 1;
58   return programId++;
59 }
60
61 GLuint glCreateShader(GLenum type)
62 {
63   static uint32_t shaderId = 1;
64   return shaderId++;
65 }
66
67 void glCompileShader(GLuint shader)
68 {
69 }
70
71 void glLinkProgram (GLuint program)
72 {
73 }
74
75 void glGenTextures(GLsizei n, GLuint *textures)
76 {
77   static GLuint texId = 1u;
78   for(auto i = 0; i < n; ++i)
79   {
80     textures[i] = texId++;
81   }
82 }
83
84 void glGetShaderiv(GLuint shader, GLenum pname, GLint *params)
85 {
86   if(pname == GL_COMPILE_STATUS)
87   {
88     params[0] = gDirectRenderingFailCreateShader ? GL_FALSE : GL_TRUE;
89   }
90   else if(pname == GL_INFO_LOG_LENGTH)
91   {
92     params[0] = 4;
93   }
94 }
95
96 void glGetProgramiv(GLuint shader, GLenum pname, GLint *params)
97 {
98   if(pname == GL_LINK_STATUS)
99   {
100     params[0] = gDirectRenderingFailCreateProgram ? GL_FALSE : GL_TRUE;
101   }
102   else if(pname == GL_INFO_LOG_LENGTH)
103   {
104     params[0] = 4;
105   }
106 }
107
108 void glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
109 {
110   infoLog[0] = '0';
111   infoLog[1] = '\n';
112 }
113
114 void glGetProgramInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
115 {
116   infoLog[0] = '0';
117   infoLog[1] = '\n';
118 }
119
120 void glDeleteSync (GLsync sync)
121 {
122 }
123
124 GLenum glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout)
125 {
126   return GL_CONDITION_SATISFIED;
127 }
128
129 GLsync glFenceSync (GLenum condition, GLbitfield flags)
130 {
131   static uint32_t syncId = 0;
132   return reinterpret_cast<GLsync>(++syncId);
133 }
134
135 GLenum glCheckFramebufferStatus (GLenum target)
136 {
137   return GL_FRAMEBUFFER_COMPLETE;
138 }
139
140 }