Fix glFrustumf call.

Bug: 233094475
Test: glFustrumf exists. Added unit test passes.

Change-Id: Ic6b76e7a1db61e8e33ca34e6b895a4886737a354
diff --git a/stream-servers/CMakeLists.txt b/stream-servers/CMakeLists.txt
index 2de33dd..fefd4ee 100644
--- a/stream-servers/CMakeLists.txt
+++ b/stream-servers/CMakeLists.txt
@@ -67,6 +67,7 @@
 target_link_libraries(
         gfxstream_backend_static
         PUBLIC
+        GLES_CM_translator_static
         gfxstream-host-common
         gfxstream-base
         OpenGLESDispatch
@@ -142,6 +143,8 @@
     ${GFXSTREAM_REPO_ROOT}/base/testing
     ${GFXSTREAM_REPO_ROOT}/include
     ${GFXSTREAM_REPO_ROOT}/stream-servers
+    ${GFXSTREAM_REPO_ROOT}/stream-servers/glestranslator/GLES_CM
+    ${GFXSTREAM_REPO_ROOT}/stream-servers/glestranslator/include
     ${GFXSTREAM_REPO_ROOT}/stream-servers/apigen-codec-common
     ${GFXSTREAM_REPO_ROOT}/stream-servers/vulkan)
 target_link_libraries(
@@ -164,6 +167,7 @@
 add_executable(
     OpenglRender_unittests
     tests/FrameBuffer_unittest.cpp
+    tests/GLES1Dispatch_unittest.cpp
     tests/DefaultFramebufferBlit_unittest.cpp
     tests/TextureDraw_unittest.cpp
     tests/StalePtrRegistry_unittest.cpp)
diff --git a/stream-servers/OpenGLESDispatch/gles1_only.entries b/stream-servers/OpenGLESDispatch/gles1_only.entries
index d1c3e74..b77dc6f 100644
--- a/stream-servers/OpenGLESDispatch/gles1_only.entries
+++ b/stream-servers/OpenGLESDispatch/gles1_only.entries
@@ -18,7 +18,6 @@
 void glEnd(void);
 void glFogf(GLenum pname, GLfloat param);
 void glFogfv(GLenum pname, const GLfloat *params);
-void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
 void glGetClipPlane(GLenum plane, GLdouble *equation);
 void glGetDoublev( GLenum pname, GLdouble *params );
 void glGetLightfv(GLenum light, GLenum pname, GLfloat *params);
diff --git a/stream-servers/OpenGLESDispatch/gles1_only_functions.h b/stream-servers/OpenGLESDispatch/gles1_only_functions.h
index 5265e61..17c453d 100644
--- a/stream-servers/OpenGLESDispatch/gles1_only_functions.h
+++ b/stream-servers/OpenGLESDispatch/gles1_only_functions.h
@@ -20,7 +20,6 @@
   X(void, glEnd, (), ()) \
   X(void, glFogf, (GLenum pname, GLfloat param), (pname, param)) \
   X(void, glFogfv, (GLenum pname, const GLfloat * params), (pname, params)) \
-  X(void, glFrustum, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar), (left, right, bottom, top, zNear, zFar)) \
   X(void, glGetClipPlane, (GLenum plane, GLdouble * equation), (plane, equation)) \
   X(void, glGetDoublev, (GLenum pname, GLdouble * params), (pname, params)) \
   X(void, glGetLightfv, (GLenum light, GLenum pname, GLfloat * params), (light, pname, params)) \
diff --git a/stream-servers/glestranslator/GLES_CM/GLEScmContext.cpp b/stream-servers/glestranslator/GLES_CM/GLEScmContext.cpp
index d277714..4b7cf06 100644
--- a/stream-servers/glestranslator/GLES_CM/GLEScmContext.cpp
+++ b/stream-servers/glestranslator/GLES_CM/GLEScmContext.cpp
@@ -1002,7 +1002,7 @@
     if (m_coreProfileEngine) {
         core().frustumf(left, right, bottom, top, zNear, zFar);
     } else {
-        dispatcher().glFrustum(left,right,bottom,top,zNear,zFar);
+        dispatcher().glFrustumf(left,right,bottom,top,zNear,zFar);
     }
 }
 
diff --git a/stream-servers/tests/GLES1Dispatch_unittest.cpp b/stream-servers/tests/GLES1Dispatch_unittest.cpp
new file mode 100644
index 0000000..8163e9c
--- /dev/null
+++ b/stream-servers/tests/GLES1Dispatch_unittest.cpp
@@ -0,0 +1,30 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <gtest/gtest.h>
+
+#include "GLEScmContext.h"
+#include "GLTestUtils.h"
+#include "OpenGLTestContext.h"
+
+namespace emugl {
+// b/233094475: GLES1 frustumf crash on cmcontext should not crash when
+// core profile is not enabled.
+TEST_F(GLTest, TestGlFrustumNoCoreProfile) {
+    GLEScmContext context(1, 1, nullptr, nullptr);
+    context.setCoreProfile(false);
+    context.frustumf(0, 0, 0, 0, 0, 0);
+}
+
+}  // namespace emugl
\ No newline at end of file
diff --git a/stream-servers/tests/OpenGLTestContext.cpp b/stream-servers/tests/OpenGLTestContext.cpp
index 72025d4..b26d373 100644
--- a/stream-servers/tests/OpenGLTestContext.cpp
+++ b/stream-servers/tests/OpenGLTestContext.cpp
@@ -119,8 +119,10 @@
 
     const EGLDispatch* egl = LazyLoadedEGLDispatch::get();
     gl = LazyLoadedGLESv2Dispatch::get();
+    gles1 = LazyLoadedGLESv1Dispatch::get();
     EXPECT_TRUE(egl != nullptr);
     EXPECT_TRUE(gl != nullptr);
+    EXPECT_TRUE(gles1 != nullptr);
 
     m_display = getDisplay();
     m_config = createConfig(m_display, 8, 8, 8, 8, 24, 8, 0);
diff --git a/stream-servers/tests/OpenGLTestContext.h b/stream-servers/tests/OpenGLTestContext.h
index 24ffe5a..1d7697e 100644
--- a/stream-servers/tests/OpenGLTestContext.h
+++ b/stream-servers/tests/OpenGLTestContext.h
@@ -46,6 +46,7 @@
     virtual void SetUp();
     virtual void TearDown();
 
+    const GLESv1Dispatch* gles1;
     const GLESv2Dispatch* gl;
     EGLDisplay m_display;
     EGLConfig m_config;