Diff
Modified: trunk/Source/WebCore/ChangeLog (106814 => 106815)
--- trunk/Source/WebCore/ChangeLog 2012-02-06 17:33:55 UTC (rev 106814)
+++ trunk/Source/WebCore/ChangeLog 2012-02-06 17:49:59 UTC (rev 106815)
@@ -1,3 +1,67 @@
+2012-02-06 ChangSeok Oh <[email protected]>
+
+ Initial implementation of GraphicsContext3DOpenGLES.cpp
+ https://bugs.webkit.org/show_bug.cgi?id=76248
+
+ Reviewed by Martin Robinson.
+
+ Implemented APIs in GraphicsContext3DOpenGLES.cpp according to the GLES spec. roughly.
+ But no way to run these codes right now, because they need an extra port
+ specific implementation to work. I plan to add these extra codes for the GTK port
+ in the next patch. And also this patch doesn't support anti-aliasing yet. Another bug
+ will deal with it.
+ Moved some APIs in GraphicsContext3DOpenGLES.cpp to GraphicsContext3DCommon.cpp.
+ It looks it could be shared between gl and gles.
+ Two helper functions are added to avoid code duplication in GraphicsContext3D.
+ Added a missing period at the end of comment lines.
+
+ No new tests required.
+ We'll be able to verify this patch by using the existing webgl test cases.
+
+ * platform/graphics/GraphicsContext3D.h: Add build flag to access stencilBuffer & depthBuffer for gles.
+ (WebCore):
+ * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
+ (WebCore::GraphicsContext3D::reshapeFBOs): Helper function extracted from GC3D::reshape to resize regular & multisampled FBOs.
+ (WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): Helper function to resolve multisampling.
+ * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+ (WebCore::GraphicsContext3D::validateAttributes): Add condition to disable antialiasing & packedDepthStencilExtension for GLES.
+ (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
+ (WebCore::GraphicsContext3D::paintRenderingResultsToImageData):
+
+ Following APIs looked shareable so that moved into GC3DOpenGLCommon.cpp.
+ (WebCore::GraphicsContext3D::prepareTexture):
+ (WebCore):
+ (WebCore::GraphicsContext3D::readRenderingResults):
+ (WebCore::GraphicsContext3D::reshape):
+ (WebCore::GraphicsContext3D::bindFramebuffer):
+ (WebCore::GraphicsContext3D::copyTexImage2D):
+ (WebCore::GraphicsContext3D::copyTexSubImage2D):
+ (WebCore::GraphicsContext3D::getActiveUniform):
+ (WebCore::GraphicsContext3D::readPixels):
+
+ Added a missing period at the end of comment line.
+ (WebCore::GraphicsContext3D::compileShader):
+ (WebCore::GraphicsContext3D::getActiveAttrib):
+ (WebCore::GraphicsContext3D::uniform2fv):
+ (WebCore::GraphicsContext3D::uniform3fv):
+ (WebCore::GraphicsContext3D::uniform4fv):
+ (WebCore::GraphicsContext3D::uniform2iv):
+ (WebCore::GraphicsContext3D::uniform3iv):
+ (WebCore::GraphicsContext3D::uniform4iv):
+ (WebCore::GraphicsContext3D::uniformMatrix2fv):
+ (WebCore::GraphicsContext3D::uniformMatrix3fv):
+ (WebCore::GraphicsContext3D::uniformMatrix4fv):
+ (WebCore::GraphicsContext3D::texSubImage2D):
+
+ * platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp:
+ (WebCore::GraphicsContext3D::reshapeFBOs): Same with the above.
+ (WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): Same with the above.
+
+ Brief explanation about what the differences are between gl and gles.
+ (WebCore::GraphicsContext3D::renderbufferStorage): Removed codes for converting GLES parameter to GL parameter.
+ (WebCore::GraphicsContext3D::getIntegerv): Removed codes that emulate GLES.
+ (WebCore::GraphicsContext3D::texImage2D): Removed codes for converting GLES parameter to GL parameter.
+
2012-02-06 Alexander Pavlov <[email protected]>
Web Inspector: [Meta] Allow emulation of touch events
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (106814 => 106815)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2012-02-06 17:33:55 UTC (rev 106814)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2012-02-06 17:49:59 UTC (rev 106815)
@@ -26,7 +26,6 @@
#ifndef GraphicsContext3D_h
#define GraphicsContext3D_h
-#include "IntSize.h"
#include "GraphicsLayer.h"
#include "GraphicsTypes3D.h"
#include "PlatformString.h"
@@ -93,6 +92,8 @@
class Image;
class ImageBuffer;
class ImageData;
+class IntRect;
+class IntSize;
#if USE(CAIRO)
class PlatformContextCairo;
#endif
@@ -908,6 +909,9 @@
void readRenderingResults(unsigned char* pixels, int pixelsSize);
#endif
+ bool reshapeFBOs(const IntSize&);
+ void resolveMultisamplingIfNecessary(const IntRect&);
+
int m_currentWidth, m_currentHeight;
bool isResourceSafe();
@@ -942,6 +946,10 @@
GC3Duint m_depthBuffer;
GC3Duint m_stencilBuffer;
#else
+#if USE(OPENGL_ES_2)
+ GC3Duint m_depthBuffer;
+ GC3Duint m_stencilBuffer;
+#endif
GC3Duint m_depthStencilBuffer;
#endif
bool m_layerComposited;
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp (106814 => 106815)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp 2012-02-06 17:33:55 UTC (rev 106814)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp 2012-02-06 17:49:59 UTC (rev 106815)
@@ -30,6 +30,8 @@
#include "GraphicsContext3D.h"
#include "Extensions3DOpenGL.h"
+#include "IntRect.h"
+#include "IntSize.h"
#include "NotImplemented.h"
#if PLATFORM(MAC)
@@ -43,58 +45,10 @@
namespace WebCore {
-void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSize)
+bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
{
- if (pixelsSize < m_currentWidth * m_currentHeight * 4)
- return;
-
- makeContextCurrent();
-
- bool mustRestoreFBO = false;
- if (m_attrs.antialias) {
- ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
- ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
- ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- mustRestoreFBO = true;
- } else {
- if (m_boundFBO != m_fbo) {
- mustRestoreFBO = true;
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- }
- }
-
- GLint packAlignment = 4;
- bool mustRestorePackAlignment = false;
- ::glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
- if (packAlignment > 4) {
- ::glPixelStorei(GL_PACK_ALIGNMENT, 4);
- mustRestorePackAlignment = true;
- }
-
- ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
-
- if (mustRestorePackAlignment)
- ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
-
- if (mustRestoreFBO)
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
-}
-
-void GraphicsContext3D::reshape(int width, int height)
-{
- if (!platformGraphicsContext3D())
- return;
-
- if (width == m_currentWidth && height == m_currentHeight)
- return;
-
- m_currentWidth = width;
- m_currentHeight = height;
-
- makeContextCurrent();
- validateAttributes();
-
+ const int width = size.width();
+ const int height = size.height();
GLuint colorFormat, internalDepthStencilFormat = 0;
if (m_attrs.alpha) {
m_internalColorFormat = GL_RGBA8;
@@ -108,7 +62,7 @@
// See GraphicsContext3D::validateAttributes.
Extensions3D* extensions = getExtensions();
- // Use a 24 bit depth buffer where we know we have it
+ // Use a 24 bit depth buffer where we know we have it.
if (extensions->supports("GL_EXT_packed_depth_stencil"))
internalDepthStencilFormat = GL_DEPTH24_STENCIL8_EXT;
else
@@ -117,7 +71,7 @@
bool mustRestoreFBO = false;
- // resize multisample FBO
+ // Resize multisample FBO.
if (m_attrs.antialias) {
GLint maxSampleCount;
::glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSampleCount);
@@ -177,168 +131,16 @@
mustRestoreFBO = false;
}
- // Initialize renderbuffers to 0.
- GLfloat clearColor[] = {0, 0, 0, 0}, clearDepth = 0;
- GLint clearStencil = 0;
- GLboolean colorMask[] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}, depthMask = GL_TRUE;
- GLuint stencilMask = 0xffffffff;
- GLboolean isScissorEnabled = GL_FALSE;
- GLboolean isDitherEnabled = GL_FALSE;
- GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
- ::glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
- ::glClearColor(0, 0, 0, 0);
- ::glGetBooleanv(GL_COLOR_WRITEMASK, colorMask);
- ::glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- if (m_attrs.depth) {
- ::glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth);
- ::glClearDepth(1);
- ::glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
- ::glDepthMask(GL_TRUE);
- clearMask |= GL_DEPTH_BUFFER_BIT;
- }
- if (m_attrs.stencil) {
- ::glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil);
- ::glClearStencil(0);
- ::glGetIntegerv(GL_STENCIL_WRITEMASK, reinterpret_cast<GLint*>(&stencilMask));
- ::glStencilMaskSeparate(GL_FRONT, 0xffffffff);
- clearMask |= GL_STENCIL_BUFFER_BIT;
- }
- isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
- ::glDisable(GL_SCISSOR_TEST);
- isDitherEnabled = ::glIsEnabled(GL_DITHER);
- ::glDisable(GL_DITHER);
-
- ::glClear(clearMask);
-
- ::glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
- ::glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
- if (m_attrs.depth) {
- ::glClearDepth(clearDepth);
- ::glDepthMask(depthMask);
- }
- if (m_attrs.stencil) {
- ::glClearStencil(clearStencil);
- ::glStencilMaskSeparate(GL_FRONT, stencilMask);
- }
- if (isScissorEnabled)
- ::glEnable(GL_SCISSOR_TEST);
- else
- ::glDisable(GL_SCISSOR_TEST);
- if (isDitherEnabled)
- ::glEnable(GL_DITHER);
- else
- ::glDisable(GL_DITHER);
-
- if (mustRestoreFBO)
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
-
- ::glFlush();
+ return mustRestoreFBO;
}
-void GraphicsContext3D::prepareTexture()
+void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect& rect)
{
- if (m_layerComposited)
- return;
- makeContextCurrent();
- if (m_attrs.antialias) {
- ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
- ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
- ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
- }
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- ::glActiveTexture(GL_TEXTURE0);
- ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
- ::glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, 0, 0, m_currentWidth, m_currentHeight, 0);
- ::glBindTexture(GL_TEXTURE_2D, m_boundTexture0);
- ::glActiveTexture(m_activeTexture);
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
- ::glFinish();
- m_layerComposited = true;
+ ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
+ ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
+ ::glBlitFramebufferEXT(rect.x(), rect.y(), rect.maxX(), rect.maxY(), rect.x(), rect.y(), rect.maxX(), rect.maxY(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
-void GraphicsContext3D::bindFramebuffer(GC3Denum target, Platform3DObject buffer)
-{
- makeContextCurrent();
- GLuint fbo;
- if (buffer)
- fbo = buffer;
- else
- fbo = (m_attrs.antialias ? m_multisampleFBO : m_fbo);
- if (fbo != m_boundFBO) {
- ::glBindFramebufferEXT(target, fbo);
- m_boundFBO = fbo;
- }
-}
-
-void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
-{
- makeContextCurrent();
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
- ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
- ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
- ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- }
- ::glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
-}
-
-void GraphicsContext3D::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
-{
- makeContextCurrent();
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
- ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
- ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
- ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- }
- ::glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
-}
-
-bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
-{
- if (!program) {
- synthesizeGLError(INVALID_VALUE);
- return false;
- }
- makeContextCurrent();
- GLint maxUniformSize = 0;
- ::glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
- GLchar name[maxUniformSize]; // GL_ACTIVE_UNIFORM_MAX_LENGTH includes null termination
- GLsizei nameLength = 0;
- GLint size = 0;
- GLenum type = 0;
- ::glGetActiveUniform(program, index, maxUniformSize, &nameLength, &size, &type, name);
- if (!nameLength)
- return false;
- info.name = String(name, nameLength);
- info.type = type;
- info.size = size;
- return true;
-}
-
-
-void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
-{
- // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
- // all previous rendering calls should be done before reading pixels.
- makeContextCurrent();
- ::glFlush();
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
- ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
- ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
- ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- ::glFlush();
- }
- ::glReadPixels(x, y, width, height, format, type, data);
- if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
-}
-
void GraphicsContext3D::renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height)
{
makeContextCurrent();
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (106814 => 106815)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2012-02-06 17:33:55 UTC (rev 106814)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2012-02-06 17:49:59 UTC (rev 106815)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 ChangSeok Oh <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,6 +36,8 @@
#include "HTMLCanvasElement.h"
#include "ImageBuffer.h"
#include "ImageData.h"
+#include "IntRect.h"
+#include "IntSize.h"
#include "NotImplemented.h"
#include "WebGLObject.h"
#include <cstring>
@@ -61,8 +64,9 @@
{
Extensions3D* extensions = getExtensions();
if (m_attrs.stencil) {
- if (extensions->supports("GL_EXT_packed_depth_stencil")) {
- extensions->ensureEnabled("GL_EXT_packed_depth_stencil");
+ const char* packedDepthStencilExtension = isGLES2Compliant() ? "GL_OES_packed_depth_stencil" : "GL_EXT_packed_depth_stencil";
+ if (extensions->supports(packedDepthStencilExtension)) {
+ extensions->ensureEnabled(packedDepthStencilExtension);
// Force depth if stencil is true.
m_attrs.depth = true;
} else
@@ -74,7 +78,7 @@
const char* vendor = reinterpret_cast<const char*>(::glGetString(GL_VENDOR));
if (!std::strstr(vendor, "NVIDIA"))
isValidVendor = false;
- if (!isValidVendor || !extensions->supports("GL_ANGLE_framebuffer_multisample"))
+ if (!isValidVendor || !extensions->supports("GL_ANGLE_framebuffer_multisample") || isGLES2Compliant())
m_attrs.antialias = false;
else
extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample");
@@ -103,7 +107,7 @@
if (!m_attrs.premultipliedAlpha) {
for (int i = 0; i < totalBytes; i += 4) {
- // Premultiply alpha
+ // Premultiply alpha.
pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255);
pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255);
pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255);
@@ -124,7 +128,7 @@
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer*)
{
// Reading premultiplied alpha would involve unpremultiplying, which is
- // lossy
+ // lossy.
if (m_attrs.premultipliedAlpha)
return 0;
@@ -134,13 +138,148 @@
readRenderingResults(pixels, totalBytes);
- // Convert to RGBA
+ // Convert to RGBA.
for (int i = 0; i < totalBytes; i += 4)
std::swap(pixels[i], pixels[i + 2]);
return imageData.release();
}
+void GraphicsContext3D::prepareTexture()
+{
+ if (m_layerComposited)
+ return;
+
+ makeContextCurrent();
+ if (m_attrs.antialias)
+ resolveMultisamplingIfNecessary(IntRect(0, 0, m_currentWidth, m_currentHeight));
+
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ ::glActiveTexture(GL_TEXTURE0);
+ ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
+ ::glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, 0, 0, m_currentWidth, m_currentHeight, 0);
+ ::glBindTexture(GL_TEXTURE_2D, m_boundTexture0);
+ ::glActiveTexture(m_activeTexture);
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
+ ::glFinish();
+ m_layerComposited = true;
+}
+
+void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSize)
+{
+ int totalBytes = m_currentWidth * m_currentHeight * 4;
+ if (pixelsSize < totalBytes)
+ return;
+
+ makeContextCurrent();
+
+ bool mustRestoreFBO = false;
+ if (m_attrs.antialias) {
+ resolveMultisamplingIfNecessary(IntRect(0, 0, m_currentWidth, m_currentHeight));
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ mustRestoreFBO = true;
+ } else {
+ if (m_boundFBO != m_fbo) {
+ mustRestoreFBO = true;
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ }
+ }
+
+ GLint packAlignment = 4;
+ bool mustRestorePackAlignment = false;
+ ::glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
+ if (packAlignment > 4) {
+ ::glPixelStorei(GL_PACK_ALIGNMENT, 4);
+ mustRestorePackAlignment = true;
+ }
+
+ ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
+ if (isGLES2Compliant()) {
+ for (int i = 0; i < totalBytes; i += 4)
+ std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA.
+ }
+
+ if (mustRestorePackAlignment)
+ ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
+
+ if (mustRestoreFBO)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
+}
+
+void GraphicsContext3D::reshape(int width, int height)
+{
+ if (!platformGraphicsContext3D())
+ return;
+
+ if (width == m_currentWidth && height == m_currentHeight)
+ return;
+
+ m_currentWidth = width;
+ m_currentHeight = height;
+
+ makeContextCurrent();
+ validateAttributes();
+
+ bool mustRestoreFBO = reshapeFBOs(IntSize(width, height));
+
+ // Initialize renderbuffers to 0.
+ GLfloat clearColor[] = {0, 0, 0, 0}, clearDepth = 0;
+ GLint clearStencil = 0;
+ GLboolean colorMask[] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}, depthMask = GL_TRUE;
+ GLuint stencilMask = 0xffffffff;
+ GLboolean isScissorEnabled = GL_FALSE;
+ GLboolean isDitherEnabled = GL_FALSE;
+ GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
+ ::glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
+ ::glClearColor(0, 0, 0, 0);
+ ::glGetBooleanv(GL_COLOR_WRITEMASK, colorMask);
+ ::glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ if (m_attrs.depth) {
+ ::glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth);
+ ::glClearDepth(1);
+ ::glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
+ ::glDepthMask(GL_TRUE);
+ clearMask |= GL_DEPTH_BUFFER_BIT;
+ }
+ if (m_attrs.stencil) {
+ ::glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil);
+ ::glClearStencil(0);
+ ::glGetIntegerv(GL_STENCIL_WRITEMASK, reinterpret_cast<GLint*>(&stencilMask));
+ ::glStencilMaskSeparate(GL_FRONT, 0xffffffff);
+ clearMask |= GL_STENCIL_BUFFER_BIT;
+ }
+ isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
+ ::glDisable(GL_SCISSOR_TEST);
+ isDitherEnabled = ::glIsEnabled(GL_DITHER);
+ ::glDisable(GL_DITHER);
+
+ ::glClear(clearMask);
+
+ ::glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+ ::glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
+ if (m_attrs.depth) {
+ ::glClearDepth(clearDepth);
+ ::glDepthMask(depthMask);
+ }
+ if (m_attrs.stencil) {
+ ::glClearStencil(clearStencil);
+ ::glStencilMaskSeparate(GL_FRONT, stencilMask);
+ }
+ if (isScissorEnabled)
+ ::glEnable(GL_SCISSOR_TEST);
+ else
+ ::glDisable(GL_SCISSOR_TEST);
+ if (isDitherEnabled)
+ ::glEnable(GL_DITHER);
+ else
+ ::glDisable(GL_DITHER);
+
+ if (mustRestoreFBO)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
+
+ ::glFlush();
+}
+
IntSize GraphicsContext3D::getInternalFramebufferSize() const
{
return IntSize(m_currentWidth, m_currentHeight);
@@ -174,6 +313,20 @@
::glBindBuffer(target, buffer);
}
+void GraphicsContext3D::bindFramebuffer(GC3Denum target, Platform3DObject buffer)
+{
+ makeContextCurrent();
+ GLuint fbo;
+ if (buffer)
+ fbo = buffer;
+ else
+ fbo = (m_attrs.antialias ? m_multisampleFBO : m_fbo);
+ if (fbo != m_boundFBO) {
+ ::glBindFramebufferEXT(target, fbo);
+ m_boundFBO = fbo;
+ }
+}
+
void GraphicsContext3D::bindRenderbuffer(GC3Denum target, Platform3DObject renderbuffer)
{
makeContextCurrent();
@@ -307,7 +460,7 @@
entry.isValid = isValid;
if (!isValid)
- return; // Shader didn't validate, don't move forward with compiling translated source
+ return; // Shader didn't validate, don't move forward with compiling translated source.
int translatedShaderLength = translatedShaderSource.length();
@@ -322,10 +475,34 @@
::glGetShaderiv(shader, COMPILE_STATUS, &GLCompileSuccess);
- // ASSERT that ANGLE generated GLSL will be accepted by OpenGL
+ // ASSERT that ANGLE generated GLSL will be accepted by OpenGL.
ASSERT(GLCompileSuccess == GL_TRUE);
}
+void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
+{
+ makeContextCurrent();
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
+ resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ }
+ ::glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
+}
+
+void GraphicsContext3D::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
+{
+ makeContextCurrent();
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
+ resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ }
+ ::glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
+}
+
void GraphicsContext3D::cullFace(GC3Denum mode)
{
makeContextCurrent();
@@ -439,7 +616,7 @@
makeContextCurrent();
GLint maxAttributeSize = 0;
::glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize);
- GLchar name[maxAttributeSize]; // GL_ACTIVE_ATTRIBUTE_MAX_LENGTH includes null termination
+ GLchar name[maxAttributeSize]; // GL_ACTIVE_ATTRIBUTE_MAX_LENGTH includes null termination.
GLsizei nameLength = 0;
GLint size = 0;
GLenum type = 0;
@@ -451,6 +628,32 @@
info.size = size;
return true;
}
+
+bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
+{
+ if (!program) {
+ synthesizeGLError(INVALID_VALUE);
+ return false;
+ }
+
+ makeContextCurrent();
+ GLint maxUniformSize = 0;
+ ::glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
+
+ OwnArrayPtr<GLchar> name = adoptArrayPtr(new GLchar[maxUniformSize]); // GL_ACTIVE_UNIFORM_MAX_LENGTH includes null termination.
+ GLsizei nameLength = 0;
+ GLint size = 0;
+ GLenum type = 0;
+ ::glGetActiveUniform(program, index, maxUniformSize, &nameLength, &size, &type, name.get());
+ if (!nameLength)
+ return false;
+
+ info.name = String(name.get(), nameLength);
+ info.type = type;
+ info.size = size;
+
+ return true;
+}
void GraphicsContext3D::getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders)
{
@@ -586,6 +789,22 @@
::glPolygonOffset(factor, units);
}
+void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
+{
+ // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
+ // all previous rendering calls should be done before reading pixels.
+ makeContextCurrent();
+ ::glFlush();
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
+ resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ ::glFlush();
+ }
+ ::glReadPixels(x, y, width, height, format, type, data);
+ if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
+}
+
void GraphicsContext3D::releaseShaderCompiler()
{
// FIXME: This is not implemented on desktop OpenGL. We need to have ifdefs for the different GL variants.
@@ -686,7 +905,7 @@
void GraphicsContext3D::uniform2fv(GC3Dint location, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 2
+ // FIXME: length needs to be a multiple of 2.
makeContextCurrent();
::glUniform2fv(location, size, array);
}
@@ -699,7 +918,7 @@
void GraphicsContext3D::uniform3fv(GC3Dint location, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 3
+ // FIXME: length needs to be a multiple of 3.
makeContextCurrent();
::glUniform3fv(location, size, array);
}
@@ -712,7 +931,7 @@
void GraphicsContext3D::uniform4fv(GC3Dint location, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 4
+ // FIXME: length needs to be a multiple of 4.
makeContextCurrent();
::glUniform4fv(location, size, array);
}
@@ -737,7 +956,7 @@
void GraphicsContext3D::uniform2iv(GC3Dint location, GC3Dint* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 2
+ // FIXME: length needs to be a multiple of 2.
makeContextCurrent();
::glUniform2iv(location, size, array);
}
@@ -750,7 +969,7 @@
void GraphicsContext3D::uniform3iv(GC3Dint location, GC3Dint* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 3
+ // FIXME: length needs to be a multiple of 3.
makeContextCurrent();
::glUniform3iv(location, size, array);
}
@@ -763,28 +982,28 @@
void GraphicsContext3D::uniform4iv(GC3Dint location, GC3Dint* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 4
+ // FIXME: length needs to be a multiple of 4.
makeContextCurrent();
::glUniform4iv(location, size, array);
}
void GraphicsContext3D::uniformMatrix2fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 4
+ // FIXME: length needs to be a multiple of 4.
makeContextCurrent();
::glUniformMatrix2fv(location, size, transpose, array);
}
void GraphicsContext3D::uniformMatrix3fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 9
+ // FIXME: length needs to be a multiple of 9.
makeContextCurrent();
::glUniformMatrix3fv(location, size, transpose, array);
}
void GraphicsContext3D::uniformMatrix4fv(GC3Dint location, GC3Dboolean transpose, GC3Dfloat* array, GC3Dsizei size)
{
- // FIXME: length needs to be a multiple of 16
+ // FIXME: length needs to be a multiple of 16.
makeContextCurrent();
::glUniformMatrix4fv(location, size, transpose, array);
}
@@ -1050,7 +1269,7 @@
{
makeContextCurrent();
- // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
+ // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size.
::glTexSubImage2D(target, level, xoff, yoff, width, height, format, type, pixels);
}
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp (106814 => 106815)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp 2012-02-06 17:33:55 UTC (rev 106814)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp 2012-02-06 17:49:59 UTC (rev 106815)
@@ -30,6 +30,8 @@
#include "GraphicsContext3D.h"
+#include "IntRect.h"
+#include "IntSize.h"
#include "NotImplemented.h"
#if PLATFORM(GTK)
@@ -38,63 +40,102 @@
namespace WebCore {
-void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSize)
+bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
{
- notImplemented();
-}
+ const int width = size.width();
+ const int height = size.height();
+ GLuint colorFormat = 0, pixelDataType = 0;
+ if (m_attrs.alpha) {
+ m_internalColorFormat = GL_RGBA;
+ colorFormat = GL_RGBA;
+ pixelDataType = GL_UNSIGNED_BYTE;
+ } else {
+ m_internalColorFormat = GL_RGB;
+ colorFormat = GL_RGB;
+ pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
+ }
-void GraphicsContext3D::reshape(int width, int height)
-{
- notImplemented();
-}
+ // We don't allow the logic where stencil is required and depth is not.
+ // See GraphicsContext3D::validateAttributes.
+ bool supportPackedDepthStencilBuffer = (m_attrs.stencil || m_attrs.depth) && getExtensions()->supports("GL_OES_packed_depth_stencil");
-void GraphicsContext3D::prepareTexture()
-{
- notImplemented();
-}
+ // Resize regular FBO.
+ bool mustRestoreFBO = false;
+ if (m_boundFBO != m_fbo) {
+ mustRestoreFBO = true;
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ }
-void GraphicsContext3D::bindFramebuffer(GC3Denum target, Platform3DObject buffer)
-{
- notImplemented();
-}
+ ::glBindTexture(GL_TEXTURE_2D, m_texture);
+ ::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, pixelDataType, 0);
+ ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0);
-void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
-{
- notImplemented();
-}
+ ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
+ ::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+ ::glBindTexture(GL_TEXTURE_2D, 0);
-void GraphicsContext3D::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
-{
- notImplemented();
-}
+ // We don't support antialiasing yet. See GraphicsContext3D::validateAttributes.
+ ASSERT(!m_attrs.antialias);
-bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
-{
- notImplemented();
+ if (m_attrs.stencil || m_attrs.depth) {
+ // Use a 24 bit depth buffer where we know we have it.
+ if (supportPackedDepthStencilBuffer) {
+ ::glBindTexture(GL_TEXTURE_2D, m_depthStencilBuffr);
+ ::glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, width, height, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, 0);
+ if (m_attrs.stencil)
+ ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0);
+ if (m_attrs.depth)
+ ::glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthStencilBuffer, 0);
+ ::glBindTexture(GL_TEXTURE_2D, 0);
+ } else {
+ if (m_attributes.stencil) {
+ ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_stencilBuffer);
+ ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX8, width, height);
+ ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_stencilBuffer);
+ }
+ if (m_attributes.depth) {
+ ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer);
+ ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, width, height);
+ ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer);
+ }
+ ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ }
+ }
+ if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ // FIXME: cleanup
+ notImplemented();
+ }
+
+ return mustRestoreFBO;
}
-
-void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
+void GraphicsContext3D::resolveMultisamplingIfNecessary(IntRect& rect)
{
+ // FIXME: We don't support antialiasing yet.
notImplemented();
}
void GraphicsContext3D::renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height)
{
- notImplemented();
+ makeContextCurrent();
+ ::glRenderbufferStorageEXT(target, internalformat, width, height);
}
void GraphicsContext3D::getIntegerv(GC3Denum pname, GC3Dint* value)
{
- notImplemented();
+ makeContextCurrent();
+ ::glGetIntegerv(pname, value);
}
bool GraphicsContext3D::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
{
- notImplemented();
- return false;
+ if (width && height && !pixels) {
+ synthesizeGLError(INVALID_VALUE);
+ return false;
+ }
+ makeContextCurrent();
+ ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
+ return true;
}
-}
-
#endif // ENABLE(WEBGL)