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