Created
May 14, 2013 12:53
-
-
Save kkristof/5575636 to your computer and use it in GitHub Desktop.
gles buildfix for nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp | |
index 21cbd1a..4361f1d 100644 | |
--- a/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp | |
+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp | |
@@ -75,6 +75,7 @@ PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri | |
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) | |
: m_currentWidth(0) | |
, m_currentHeight(0) | |
+ , m_compiler(isGLES2Compliant() ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT) | |
, m_attrs(attributes) | |
, m_texture(0) | |
, m_fbo(0) | |
diff --git a/Tools/CMakeLists.txt b/Tools/CMakeLists.txt | |
index 0882d00..6f7b407 100644 | |
--- a/Tools/CMakeLists.txt | |
+++ b/Tools/CMakeLists.txt | |
@@ -17,7 +17,7 @@ if ("${PORT}" STREQUAL "Efl") | |
add_subdirectory(DumpRenderTree/TestNetscapePlugIn) | |
elseif ("${PORT}" STREQUAL "WinCE") | |
add_subdirectory(WinCELauncher) | |
-elseif ("${PORT}" STREQUAL "Nix" AND NOT WTF_USE_OPENGL_ES_2) | |
+elseif ("${PORT}" STREQUAL "Nix" ) | |
add_subdirectory(MiniBrowser/nix) | |
endif () | |
diff --git a/Tools/MiniBrowser/nix/CMakeLists.txt b/Tools/MiniBrowser/nix/CMakeLists.txt | |
index 136d18e..5368bd3 100644 | |
--- a/Tools/MiniBrowser/nix/CMakeLists.txt | |
+++ b/Tools/MiniBrowser/nix/CMakeLists.txt | |
@@ -46,6 +46,11 @@ else () | |
list(APPEND MiniBrowser_SOURCES ${MiniBrowser_DIR}/LinuxWindowGLX.cpp) | |
endif () | |
+if (WTF_USE_OPENGL_ES_2) | |
+ list(APPEND MiniBrowser_LIBRARIES ${OPENGLES2_LIBRARIES}) | |
+ add_definitions(-DUSE_OPENGL_ES_2=1) | |
+endif () | |
+ | |
include_directories(${MiniBrowser_INCLUDE_DIRECTORIES}) | |
add_executable(MiniBrowser ${MiniBrowser_SOURCES}) | |
diff --git a/Tools/MiniBrowser/nix/LinuxWindow.cpp b/Tools/MiniBrowser/nix/LinuxWindow.cpp | |
index dbd31d6..43342c0 100644 | |
--- a/Tools/MiniBrowser/nix/LinuxWindow.cpp | |
+++ b/Tools/MiniBrowser/nix/LinuxWindow.cpp | |
@@ -122,8 +122,9 @@ Window LinuxWindow::createXWindow(VisualID visualID) | |
XSetWindowAttributes setAttributes; | |
setAttributes.colormap = XCreateColormap(m_display, rootWindow, visualInfo->visual, AllocNone); | |
setAttributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask; | |
+ setAttributes.border_pixel = 0; | |
- Window window = XCreateWindow(m_display, rootWindow, 0, 0, m_width, m_height, 0, visualInfo->depth, InputOutput, visualInfo->visual, CWColormap | CWEventMask, &setAttributes); | |
+ Window window = XCreateWindow(m_display, rootWindow, 0, 0, m_width, m_height, 0, visualInfo->depth, InputOutput, visualInfo->visual, CWColormap | CWEventMask | CWBorderPixel, &setAttributes); | |
XFree(visualInfo); | |
wmDeleteMessageAtom = XInternAtom(m_display, "WM_DELETE_WINDOW", False); | |
diff --git a/Tools/MiniBrowser/nix/LinuxWindowEGL.cpp b/Tools/MiniBrowser/nix/LinuxWindowEGL.cpp | |
index 9c377b6..1df3339 100644 | |
--- a/Tools/MiniBrowser/nix/LinuxWindowEGL.cpp | |
+++ b/Tools/MiniBrowser/nix/LinuxWindowEGL.cpp | |
@@ -26,7 +26,11 @@ | |
#include "LinuxWindow.h" | |
#include <EGL/egl.h> | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+#include <GLES2/gl2.h> | |
+#else | |
#include <GL/gl.h> | |
+#endif | |
struct LinuxWindow::GLContextData { | |
EGLDisplay eglDisplay; | |
@@ -48,7 +52,11 @@ VisualID LinuxWindow::setupXVisualID() | |
static const EGLint attributes[] = { | |
EGL_DEPTH_SIZE, 24, | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
+#else | |
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, | |
+#endif | |
EGL_NONE | |
}; | |
@@ -65,8 +73,16 @@ VisualID LinuxWindow::setupXVisualID() | |
void LinuxWindow::createGLContext() | |
{ | |
+ static const EGLint attributes[] = { | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+ // Identify OpenGL 2 ES context | |
+ EGL_CONTEXT_CLIENT_VERSION, 2, | |
+#endif | |
+ EGL_NONE, | |
+ }; | |
+ | |
eglBindAPI(EGL_OPENGL_API); | |
- m_glContextData->context = eglCreateContext(m_glContextData->eglDisplay, m_glContextData->config, EGL_NO_CONTEXT, 0); | |
+ m_glContextData->context = eglCreateContext(m_glContextData->eglDisplay, m_glContextData->config, EGL_NO_CONTEXT, attributes); | |
if (!m_glContextData->context) | |
fatalError("eglCreateContext failed\n"); | |
diff --git a/Tools/MiniBrowser/nix/TouchMocker.cpp b/Tools/MiniBrowser/nix/TouchMocker.cpp | |
index 3d6c784..63deb48 100644 | |
--- a/Tools/MiniBrowser/nix/TouchMocker.cpp | |
+++ b/Tools/MiniBrowser/nix/TouchMocker.cpp | |
@@ -25,7 +25,12 @@ | |
#include "TouchMocker.h" | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+#include <GLES2/gl2.h> | |
+#else | |
#include <GL/gl.h> | |
+#endif | |
+ | |
#include <cassert> | |
#include "touchTexture.h" | |
@@ -61,47 +66,74 @@ TouchMocker::~TouchMocker() | |
void TouchMocker::paintTouchPoints(const WKSize& size) | |
{ | |
- static float vertexData[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |
+ static float vertexData[8]; | |
static const float texCoords[] = { 0, 0, 1, 0, 0, 1, 1, 1}; | |
if (m_touchPoints.empty()) | |
return; | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+ static GLuint shaderProgram = 0; | |
+ GLint intValue; | |
+ | |
+ compileShader(shaderProgram); | |
+ | |
+ if (!shaderProgram) | |
+ return; | |
+ | |
+ glViewport(0, 0, size.width, size.height); | |
+ | |
+ glUseProgram(shaderProgram); | |
+ | |
+ intValue = glGetUniformLocation(shaderProgram, "u_texture"); | |
+ glUniform1i(intValue, 0); | |
+ glActiveTexture(GL_TEXTURE0); | |
+ | |
+ intValue = glGetAttribLocation(shaderProgram, "a_textureCoord"); | |
+ glEnableVertexAttribArray(intValue); | |
+ glVertexAttribPointer(intValue, 2, GL_FLOAT, GL_FALSE, 0, texCoords); | |
+ | |
+ intValue = glGetAttribLocation(shaderProgram, "a_position"); | |
+ glEnableVertexAttribArray(intValue); | |
+ glVertexAttribPointer(intValue, 2, GL_FLOAT, GL_FALSE, 0, vertexData); | |
+#else | |
glPushMatrix(); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
- glOrtho(0, size.width, size.height, 0, -1, 1); | |
- | |
- glEnable(GL_TEXTURE_2D); | |
- glEnable(GL_BLEND); | |
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glEnableClientState(GL_TEXTURE_COORD_ARRAY_EXT); | |
glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | |
- glVertexPointer(3, GL_FLOAT, 0, vertexData); | |
+ glVertexPointer(2, GL_FLOAT, 0, vertexData); | |
+#endif | |
+ glEnable(GL_TEXTURE_2D); | |
+ glEnable(GL_BLEND); | |
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
glBindTexture(GL_TEXTURE_2D, m_touchTextureId); | |
TouchMap::const_iterator it; | |
for (it = m_touchPoints.begin(); it != m_touchPoints.end(); ++it) { | |
const MockedTouchPoint& touch = it->second; | |
- double x1 = touch.windowX - touch.horizontalRadius; | |
- double y1 = touch.windowY - touch.verticalRadius; | |
- double x2 = touch.windowX + touch.horizontalRadius; | |
- double y2 = touch.windowY + touch.verticalRadius; | |
+ double x1 = (touch.windowX - touch.horizontalRadius) / (size.width / 2) - 1; | |
+ double y1 = (size.height - touch.windowY - touch.verticalRadius) / (size.height / 2) - 1; | |
+ double x2 = (touch.windowX + touch.horizontalRadius) / (size.width / 2) - 1; | |
+ double y2 = (size.height - touch.windowY + touch.verticalRadius) / (size.height / 2) - 1; | |
vertexData[0] = x1; | |
vertexData[1] = y1; | |
- vertexData[3] = x2; | |
- vertexData[4] = y1; | |
- vertexData[6] = x1; | |
+ vertexData[2] = x2; | |
+ vertexData[3] = y1; | |
+ vertexData[4] = x1; | |
+ vertexData[5] = y2; | |
+ vertexData[6] = x2; | |
vertexData[7] = y2; | |
- vertexData[9] = x2; | |
- vertexData[10] = y2; | |
+ | |
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |
} | |
+#if !(defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2) | |
glPopMatrix(); | |
+#endif | |
} | |
bool TouchMocker::handleMousePress(const NIXMouseEvent& event, const WKPoint& windowPos) | |
@@ -226,3 +258,33 @@ void TouchMocker::loadTouchPointTexture() | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); | |
} | |
+ | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+void TouchMocker::compileShader(unsigned int& shaderProgram) | |
+{ | |
+ static bool done = false; | |
+ if (done) | |
+ return; | |
+ | |
+ GLuint vertexShader = 0; | |
+ GLuint fragmentShader = 0; | |
+ | |
+ vertexShader = glCreateShader(GL_VERTEX_SHADER); | |
+ glShaderSource(vertexShader, 1, &vertexShaderSource, 0); | |
+ glCompileShader(vertexShader); | |
+ | |
+ fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); | |
+ glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0); | |
+ glCompileShader(fragmentShader); | |
+ | |
+ shaderProgram = glCreateProgram(); | |
+ glAttachShader(shaderProgram, vertexShader); | |
+ glAttachShader(shaderProgram, fragmentShader); | |
+ glLinkProgram(shaderProgram); | |
+ | |
+ glDeleteShader(vertexShader); | |
+ glDeleteShader(fragmentShader); | |
+ | |
+ done = true; | |
+} | |
+#endif | |
diff --git a/Tools/MiniBrowser/nix/TouchMocker.h b/Tools/MiniBrowser/nix/TouchMocker.h | |
index 80e94d1..585e818 100644 | |
--- a/Tools/MiniBrowser/nix/TouchMocker.h | |
+++ b/Tools/MiniBrowser/nix/TouchMocker.h | |
@@ -62,6 +62,10 @@ private: | |
void loadTouchPointTexture(); | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+ void compileShader(unsigned int&); | |
+#endif | |
+ | |
NIXView m_view; | |
NIXInputEventType m_touchType; | |
typedef std::map<WKEventMouseButton, MockedTouchPoint> TouchMap; | |
@@ -70,5 +74,34 @@ private: | |
unsigned m_touchTextureId; | |
}; | |
+#if defined USE_OPENGL_ES_2 and USE_OPENGL_ES_2 | |
+static const char* vertexShaderSource = "\n\ | |
+ attribute vec2 a_textureCoord;\n\ | |
+ attribute vec2 a_position;\n\ | |
+ \n\ | |
+ varying vec2 v_textureCoord;\n\ | |
+ \n\ | |
+ void main(void)\n\ | |
+ {\n\ | |
+ v_textureCoord = a_textureCoord;\n\ | |
+ gl_Position = vec4(a_position.xy, 0.0, 1.0);\n\ | |
+ }\n\ | |
+ "; | |
+ | |
+static const char* fragmentShaderSource = "\n\ | |
+ #ifdef GL_ES\n\ | |
+ precision mediump float;\n\ | |
+ #endif\n\ | |
+ \n\ | |
+ uniform sampler2D u_texture;\n\ | |
+ \n\ | |
+ varying vec2 v_textureCoord;\n\ | |
+ \n\ | |
+ void main(void)\n\ | |
+ {\n\ | |
+ gl_FragColor = texture2D(u_texture, v_textureCoord);\n\ | |
+ }\n\ | |
+ "; | |
+#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment