diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/efl')
-rw-r--r-- | Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.cpp | 109 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.h (renamed from Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.h) | 31 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp | 909 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp | 1100 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h | 204 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.cpp | 57 |
6 files changed, 367 insertions, 2043 deletions
diff --git a/Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.cpp b/Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.cpp new file mode 100644 index 000000000..d7232413e --- /dev/null +++ b/Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.cpp @@ -0,0 +1,109 @@ +/* + Copyright (C) 2009-2010 ProFUSION embedded systems + Copyright (C) 2009-2010 Samsung Electronics + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "CairoUtilitiesEfl.h" + +#include "RefPtrCairo.h" + +namespace WebCore { + +PassRefPtr<Evas_Object> evasObjectFromCairoImageSurface(Evas* canvas, cairo_surface_t* surface) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0); + + cairo_status_t status = cairo_surface_status(surface); + if (status != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "cairo surface is invalid: %s", cairo_status_to_string(status)); + return 0; + } + + cairo_surface_type_t type = cairo_surface_get_type(surface); + if (type != CAIRO_SURFACE_TYPE_IMAGE) { + fprintf(stderr, "unknown surface type %d, required %d (CAIRO_SURFACE_TYPE_IMAGE).", + type, CAIRO_SURFACE_TYPE_IMAGE); + return 0; + } + + cairo_format_t format = cairo_image_surface_get_format(surface); + if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) { + fprintf(stderr, "unknown surface format %d, expected %d or %d.", + format, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24); + return 0; + } + + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + int stride = cairo_image_surface_get_stride(surface); + if (width <= 0 || height <= 0 || stride <= 0) { + fprintf(stderr, "invalid image size %dx%d, stride=%d", width, height, stride); + return 0; + } + + void* data = cairo_image_surface_get_data(surface); + if (!data) { + fprintf(stderr, "could not get source data."); + return 0; + } + + RefPtr<Evas_Object> image = adoptRef(evas_object_image_filled_add(canvas)); + if (!image) { + fprintf(stderr, "could not add image to canvas."); + return 0; + } + + evas_object_image_colorspace_set(image.get(), EVAS_COLORSPACE_ARGB8888); + evas_object_image_size_set(image.get(), width, height); + evas_object_image_alpha_set(image.get(), format == CAIRO_FORMAT_ARGB32); + + if (evas_object_image_stride_get(image.get()) != stride) { + fprintf(stderr, "evas' stride %d diverges from cairo's %d.", + evas_object_image_stride_get(image.get()), stride); + return 0; + } + + evas_object_image_data_copy_set(image.get(), data); + + return image.release(); +} + +PassRefPtr<cairo_surface_t> createSurfaceForBackingStore(Ecore_Evas* ee) +{ + ASSERT(ee); + + int width; + int height; + ecore_evas_geometry_get(ee, 0, 0, &width, &height); + ASSERT(width > 0 && height > 0); + + unsigned char* buffer = static_cast<unsigned char*>(const_cast<void*>(ecore_evas_buffer_pixels_get(ee))); + RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32, width, height, width * 4)); + + cairo_status_t status = cairo_surface_status(surface.get()); + if (status != CAIRO_STATUS_SUCCESS) { + EINA_LOG_ERR("Could not create cairo surface: %s", cairo_status_to_string(status)); + return 0; + } + + return surface; +} + +} diff --git a/Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.h b/Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.h index d03fb1b75..a5cd2e2fb 100644 --- a/Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.h +++ b/Source/WebCore/platform/graphics/efl/CairoUtilitiesEfl.h @@ -1,5 +1,6 @@ /* - Copyright (C) 2009-2011 Samsung Electronics + Copyright (C) 2009-2010 ProFUSION embedded systems + Copyright (C) 2009-2010 Samsung Electronics This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,26 +18,20 @@ Boston, MA 02110-1301, USA. */ -#ifndef GraphicsLayerEfl_h -#define GraphicsLayerEfl_h +#ifndef CairoUtilitiesEfl_h +#define CairoUtilitiesEfl_h -#if USE(ACCELERATED_COMPOSITING) - -#include "GraphicsLayer.h" +#include <Ecore_Evas.h> +#include <Evas.h> +#include <cairo.h> +#include <wtf/PassRefPtr.h> +#include <wtf/efl/RefPtrEfl.h> namespace WebCore { -class GraphicsLayerEfl : public GraphicsLayer { -public: - GraphicsLayerEfl(GraphicsLayerClient*); - virtual ~GraphicsLayerEfl(); - - virtual void setNeedsDisplay(); - virtual void setNeedsDisplayInRect(const FloatRect&); -}; - -} // namespace WebCore +PassRefPtr<Evas_Object> evasObjectFromCairoImageSurface(Evas* canvas, cairo_surface_t*); +PassRefPtr<cairo_surface_t> createSurfaceForBackingStore(Ecore_Evas* ee); -#endif // USE(ACCELERATED_COMPOSITING) +} -#endif // GraphicsLayerEfl_h +#endif // CairoUtilitiesEfl_h diff --git a/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp b/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp index 721d7c7be..6f1d4ca15 100644 --- a/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp +++ b/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp @@ -18,33 +18,134 @@ */ #include "config.h" +#include "GraphicsContext3D.h" #if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING) #include "GraphicsContext3DPrivate.h" - #include "ImageData.h" #include "NotImplemented.h" +#include "OpenGLShims.h" +#include "PlatformContextCairo.h" +#include <GL/glx.h> + +#if USE(OPENGL_ES_2) +#include "Extensions3DOpenGLES.h" +#else +#include "Extensions3DOpenGL.h" +#endif namespace WebCore { PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, RenderStyle renderStyle) { - bool renderDirectlyToEvasGLObject = (renderStyle == RenderDirectlyToHostWindow); - - OwnPtr<GraphicsContext3DPrivate> internal = GraphicsContext3DPrivate::create(attrs, hostWindow, renderDirectlyToEvasGLObject); - if (!internal) - return 0; - RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderStyle)); - context->m_private = internal.release(); - return context.release(); + return context->m_private ? context.release() : 0; } GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) -{ + , m_compiler(isGLES2Compliant() ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT) + , m_attrs(attrs) + , m_texture(0) + , m_compositorTexture(0) + , m_fbo(0) +#if USE(OPENGL_ES_2) + , m_depthBuffer(0) + , m_stencilBuffer(0) +#endif + , m_depthStencilBuffer(0) + , m_layerComposited(false) + , m_internalColorFormat(0) + , m_boundFBO(0) + , m_activeTexture(GL_TEXTURE0) + , m_boundTexture0(0) + , m_multisampleFBO(0) + , m_multisampleDepthStencilBuffer(0) + , m_multisampleColorBuffer(0) + , m_private(adoptPtr(new GraphicsContext3DPrivate(this, hostWindow, renderStyle))) +{ + validateAttributes(); + + if (!m_private) + return; + + static bool initializedShims = false; + static bool success = true; + if (!initializedShims) { + success = initializeOpenGLShims(); + initializedShims = true; + } + if (!success) { + m_private = nullptr; + return; + } + + if (renderStyle == RenderToCurrentGLContext) { + // Evas doesn't allow including gl headers and Evas_GL headers at the same time, + // so we need to query the current gl context/surface here instead of in GraphicsContext3DPrivate. + void* currentContext = (void*)glXGetCurrentContext(); + void* currentSurface = (void*)glXGetCurrentDrawable(); + m_private->setCurrentGLContext(currentContext, currentSurface); + } + + if (renderStyle == RenderOffscreen) { + // Create buffers for the canvas FBO. + glGenFramebuffers(/* count */ 1, &m_fbo); + + // Create a texture to render into. + glGenTextures(1, &m_texture); + glBindTexture(GraphicsContext3D::TEXTURE_2D, m_texture); + glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); + glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); + glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); + glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); + glBindTexture(GraphicsContext3D::TEXTURE_2D, 0); + + // Create a multisample FBO. + if (m_attrs.antialias) { + glGenFramebuffers(1, &m_multisampleFBO); + glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); + m_boundFBO = m_multisampleFBO; + glGenRenderbuffers(1, &m_multisampleColorBuffer); + if (m_attrs.stencil || m_attrs.depth) + glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); + } else { + // Bind canvas FBO. + glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); + m_boundFBO = m_fbo; +#if USE(OPENGL_ES_2) + if (m_attrs.depth) + glGenRenderbuffers(1, &m_depthBuffer); + if (m_context->m_attrs.stencil) + glGenRenderbuffers(1, &m_stencilBuffer); +#endif + if (m_attrs.stencil || m_attrs.depth) + glGenRenderbuffers(1, &m_depthStencilBuffer); + } + } + + // ANGLE initialization. + ShBuiltInResources ANGLEResources; + ShInitBuiltInResources(&ANGLEResources); + + getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); + getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); + getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); + getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); + getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); + getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); + getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); + + // Always set to 1 for OpenGL ES. + ANGLEResources.MaxDrawBuffers = 1; + m_compiler.setResources(ANGLEResources); + +#if !USE(OPENGL_ES_2) + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif } GraphicsContext3D::~GraphicsContext3D() @@ -59,768 +160,74 @@ PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() #if USE(ACCELERATED_COMPOSITING) PlatformLayer* GraphicsContext3D::platformLayer() const { +#if USE(TEXTURE_MAPPER_GL) + return m_private.get(); +#else notImplemented(); return 0; +#endif } #endif bool GraphicsContext3D::makeContextCurrent() { - return m_private->makeContextCurrent(); -} - -bool GraphicsContext3D::isGLES2Compliant() const -{ - return m_private->isGLES2Compliant(); -} - -void GraphicsContext3D::activeTexture(GC3Denum texture) -{ - m_private->activeTexture(texture); -} - -void GraphicsContext3D::attachShader(Platform3DObject program, Platform3DObject shader) -{ - m_private->attachShader(program, shader); -} - -void GraphicsContext3D::bindAttribLocation(Platform3DObject program, GC3Duint index, const String& name) -{ - m_private->bindAttribLocation(program, index, name); -} - -void GraphicsContext3D::bindBuffer(GC3Denum target, Platform3DObject buffer) -{ - m_private->bindBuffer(target, buffer); -} - -void GraphicsContext3D::bindFramebuffer(GC3Denum target, Platform3DObject buffer) -{ - m_private->bindFramebuffer(target, buffer); -} - -void GraphicsContext3D::bindRenderbuffer(GC3Denum target, Platform3DObject renderbuffer) -{ - m_private->bindRenderbuffer(target, renderbuffer); -} - -void GraphicsContext3D::bindTexture(GC3Denum target, Platform3DObject texture) -{ - m_private->bindTexture(target, texture); -} - -void GraphicsContext3D::blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha) -{ - m_private->blendColor(red, green, blue, alpha); -} - -void GraphicsContext3D::blendEquation(GC3Denum mode) -{ - m_private->blendEquation(mode); -} - -void GraphicsContext3D::blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha) -{ - m_private->blendEquationSeparate(modeRGB, modeAlpha); -} - -void GraphicsContext3D::blendFunc(GC3Denum srcFactor, GC3Denum dstFactor) -{ - m_private->blendFunc(srcFactor, dstFactor); -} - -void GraphicsContext3D::blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha) -{ - m_private->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); -} - -void GraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage) -{ - m_private->bufferData(target, size, 0, usage); -} - -void GraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage) -{ - m_private->bufferData(target, size, data, usage); -} - -void GraphicsContext3D::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data) -{ - m_private->bufferSubData(target, offset, size, data); -} - -GC3Denum GraphicsContext3D::checkFramebufferStatus(GC3Denum target) -{ - return m_private->checkFramebufferStatus(target); -} - -void GraphicsContext3D::clear(GC3Dbitfield mask) -{ - m_private->clear(mask); -} - -void GraphicsContext3D::clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha) -{ - m_private->clearColor(red, green, blue, alpha); -} - -void GraphicsContext3D::clearDepth(GC3Dclampf depth) -{ - m_private->clearDepth(depth); -} - -void GraphicsContext3D::clearStencil(GC3Dint clearValue) -{ - m_private->clearStencil(clearValue); -} - -void GraphicsContext3D::colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha) -{ - m_private->colorMask(red, green, blue, alpha); -} - -void GraphicsContext3D::compileShader(Platform3DObject shader) -{ - m_private->compileShader(shader); -} - -void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border) -{ - m_private->copyTexImage2D(target, level, internalformat, x, y, width, height, border); -} - -void GraphicsContext3D::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - m_private->copyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height); -} - -void GraphicsContext3D::cullFace(GC3Denum mode) -{ - m_private->cullFace(mode); -} - -void GraphicsContext3D::depthFunc(GC3Denum func) -{ - m_private->depthFunc(func); -} - -void GraphicsContext3D::depthMask(GC3Dboolean flag) -{ - m_private->depthMask(flag); -} - -void GraphicsContext3D::depthRange(GC3Dclampf zNear, GC3Dclampf zFar) -{ - m_private->depthRange(zNear, zFar); -} - -void GraphicsContext3D::detachShader(Platform3DObject program, Platform3DObject shader) -{ - m_private->detachShader(program, shader); -} - -void GraphicsContext3D::disable(GC3Denum cap) -{ - m_private->disable(cap); -} - -void GraphicsContext3D::disableVertexAttribArray(GC3Duint index) -{ - m_private->disableVertexAttribArray(index); -} - -void GraphicsContext3D::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count) -{ - m_private->drawArrays(mode, first, count); -} - -void GraphicsContext3D::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset) -{ - m_private->drawElements(mode, count, type, offset); -} - -void GraphicsContext3D::enable(GC3Denum cap) -{ - m_private->enable(cap); -} - -void GraphicsContext3D::enableVertexAttribArray(GC3Duint index) -{ - m_private->enableVertexAttribArray(index); -} - -void GraphicsContext3D::finish() -{ - m_private->finish(); -} - -void GraphicsContext3D::flush() -{ - m_private->flush(); -} - -void GraphicsContext3D::framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbufferTarget, Platform3DObject buffer) -{ - m_private->framebufferRenderbuffer(target, attachment, renderbufferTarget, buffer); -} - -void GraphicsContext3D::framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum texTarget, Platform3DObject texture, GC3Dint level) -{ - m_private->framebufferTexture2D(target, attachment, texTarget, texture, level); -} - -void GraphicsContext3D::frontFace(GC3Denum mode) -{ - m_private->frontFace(mode); -} - -void GraphicsContext3D::generateMipmap(GC3Denum target) -{ - m_private->generateMipmap(target); -} - -bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info) -{ - return m_private->getActiveAttrib(program, index, info); -} - -bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info) -{ - return m_private->getActiveUniform(program, index, info); -} - -void GraphicsContext3D::getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders) -{ - m_private->getAttachedShaders(program, maxCount, count, shaders); -} - -int GraphicsContext3D::getAttribLocation(Platform3DObject program, const String& name) -{ - return m_private->getAttribLocation(program, name); -} - -void GraphicsContext3D::getBooleanv(GC3Denum paramName, GC3Dboolean* value) -{ - m_private->getBooleanv(paramName, value); -} - -void GraphicsContext3D::getBufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - m_private->getBufferParameteriv(target, paramName, value); -} - -GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() -{ - return m_private->getContextAttributes(); -} - -GC3Denum GraphicsContext3D::getError() -{ - return m_private->getError(); -} - -void GraphicsContext3D::getFloatv(GC3Denum paramName, GC3Dfloat* value) -{ - m_private->getFloatv(paramName, value); -} - -void GraphicsContext3D::getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum paramName, GC3Dint* value) -{ - m_private->getFramebufferAttachmentParameteriv(target, attachment, paramName, value); -} - -void GraphicsContext3D::getIntegerv(GC3Denum paramName, GC3Dint* value) -{ - m_private->getIntegerv(paramName, value); -} - -void GraphicsContext3D::getProgramiv(Platform3DObject program, GC3Denum paramName, GC3Dint* value) -{ - m_private->getProgramiv(program, paramName, value); -} - -String GraphicsContext3D::getProgramInfoLog(Platform3DObject program) -{ - return m_private->getProgramInfoLog(program); -} - -void GraphicsContext3D::getRenderbufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - m_private->getRenderbufferParameteriv(target, paramName, value); -} - -void GraphicsContext3D::getShaderiv(Platform3DObject shader, GC3Denum paramName, GC3Dint* value) -{ - m_private->getShaderiv(shader, paramName, value); -} - -String GraphicsContext3D::getShaderInfoLog(Platform3DObject shader) -{ - return m_private->getShaderInfoLog(shader); -} - -String GraphicsContext3D::getShaderSource(Platform3DObject shader) -{ - return m_private->getShaderSource(shader); -} - -String GraphicsContext3D::getString(GC3Denum name) -{ - return m_private->getString(name); -} - -void GraphicsContext3D::getTexParameterfv(GC3Denum target, GC3Denum paramName, GC3Dfloat* value) -{ - m_private->getTexParameterfv(target, paramName, value); -} - -void GraphicsContext3D::getTexParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - m_private->getTexParameteriv(target, paramName, value); -} - -void GraphicsContext3D::getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value) -{ - m_private->getUniformfv(program, location, value); -} - -void GraphicsContext3D::getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value) -{ - m_private->getUniformiv(program, location, value); -} - -GC3Dint GraphicsContext3D::getUniformLocation(Platform3DObject program, const String& name) -{ - return m_private->getUniformLocation(program, name); -} - -void GraphicsContext3D::getVertexAttribfv(GC3Duint index, GC3Denum paramName, GC3Dfloat* value) -{ - m_private->getVertexAttribfv(index, paramName, value); -} - -void GraphicsContext3D::getVertexAttribiv(GC3Duint index, GC3Denum paramName, GC3Dint* value) -{ - m_private->getVertexAttribiv(index, paramName, value); -} - -long GraphicsContext3D::getVertexAttribOffset(GC3Duint index, GC3Denum paramName) -{ - return m_private->getVertexAttribOffset(index, paramName); -} - -void GraphicsContext3D::hint(GC3Denum target, GC3Denum mode) -{ - m_private->hint(target, mode); -} - -GC3Dboolean GraphicsContext3D::isBuffer(Platform3DObject obj) -{ - return m_private->isBuffer(obj); -} - -GC3Dboolean GraphicsContext3D::isEnabled(GC3Denum cap) -{ - return m_private->isEnabled(cap); -} - -GC3Dboolean GraphicsContext3D::isFramebuffer(Platform3DObject obj) -{ - return m_private->isFramebuffer(obj); -} - -GC3Dboolean GraphicsContext3D::isProgram(Platform3DObject obj) -{ - return m_private->isProgram(obj); -} - -GC3Dboolean GraphicsContext3D::isRenderbuffer(Platform3DObject obj) -{ - return m_private->isRenderbuffer(obj); -} - -GC3Dboolean GraphicsContext3D::isShader(Platform3DObject obj) -{ - return m_private->isShader(obj); -} - -GC3Dboolean GraphicsContext3D::isTexture(Platform3DObject obj) -{ - return m_private->isTexture(obj); -} - -void GraphicsContext3D::lineWidth(GC3Dfloat width) -{ - m_private->lineWidth(width); -} - -void GraphicsContext3D::linkProgram(Platform3DObject program) -{ - m_private->linkProgram(program); -} - -void GraphicsContext3D::pixelStorei(GC3Denum paramName, GC3Dint param) -{ - m_private->pixelStorei(paramName, param); -} - -void GraphicsContext3D::polygonOffset(GC3Dfloat factor, GC3Dfloat units) -{ - m_private->polygonOffset(factor, units); -} - -void GraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data) -{ - m_private->readPixels(x, y, width, height, format, type, data); -} - -void GraphicsContext3D::releaseShaderCompiler() -{ - notImplemented(); -} - -void GraphicsContext3D::renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height) -{ - m_private->renderbufferStorage(target, internalformat, width, height); -} - -void GraphicsContext3D::sampleCoverage(GC3Dclampf value, GC3Dboolean invert) -{ - m_private->sampleCoverage(value, invert); -} - -void GraphicsContext3D::scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - m_private->scissor(x, y, width, height); -} - -void GraphicsContext3D::shaderSource(Platform3DObject program, const String& string) -{ - m_private->shaderSource(program, string); -} - -void GraphicsContext3D::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask) -{ - m_private->stencilFunc(func, ref, mask); -} - -void GraphicsContext3D::stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask) -{ - m_private->stencilFuncSeparate(face, func, ref, mask); -} - -void GraphicsContext3D::stencilMask(GC3Duint mask) -{ - m_private->stencilMask(mask); -} - -void GraphicsContext3D::stencilMaskSeparate(GC3Denum face, GC3Duint mask) -{ - m_private->stencilMaskSeparate(face, mask); -} - -void GraphicsContext3D::stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass) -{ - m_private->stencilOp(fail, zfail, zpass); -} - -void GraphicsContext3D::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass) -{ - m_private->stencilOpSeparate(face, fail, zfail, zpass); -} - -bool GraphicsContext3D::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels) -{ - return m_private->texImage2D(target, level, internalformat, width, height, border, format, type, pixels); -} - -void GraphicsContext3D::texParameterf(GC3Denum target, GC3Denum paramName, GC3Dfloat param) -{ - m_private->texParameterf(target, paramName, param); -} - -void GraphicsContext3D::texParameteri(GC3Denum target, GC3Denum paramName, GC3Dint param) -{ - m_private->texParameteri(target, paramName, param); -} - -void GraphicsContext3D::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels) -{ - m_private->texSubImage2D(target, level, xOffset, yOffset, width, height, format, type, pixels); -} - -void GraphicsContext3D::uniform1f(GC3Dint location, GC3Dfloat x) -{ - m_private->uniform1f(location, x); -} - -void GraphicsContext3D::uniform1fv(GC3Dint location, GGC3Dsizei size, C3Dfloat* v) -{ - m_private->uniform1fv(location, size, v); -} - -void GraphicsContext3D::uniform1i(GC3Dint location, GC3Dint x) -{ - m_private->uniform1i(location, x); -} - -void GraphicsContext3D::uniform1iv(GC3Dint location, GGC3Dsizei size, C3Dint* v) -{ - m_private->uniform1iv(location, size, v); -} - -void GraphicsContext3D::uniform2f(GC3Dint location, GC3Dfloat x, float y) -{ - m_private->uniform2f(location, x, y); -} - -void GraphicsContext3D::uniform2fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v) -{ - m_private->uniform2fv(location, size, v); -} - -void GraphicsContext3D::uniform2i(GC3Dint location, GC3Dint x, GC3Dint y) -{ - m_private->uniform2i(location, x, y); -} - -void GraphicsContext3D::uniform2iv(GC3Dint location, GC3Dsizei size, GC3Dint* v) -{ - m_private->uniform2iv(location, size, v); -} - -void GraphicsContext3D::uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z) -{ - m_private->uniform3f(location, x, y, z); -} - -void GraphicsContext3D::uniform3fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v) -{ - m_private->uniform3fv(location, size, v); -} - -void GraphicsContext3D::uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z) -{ - m_private->uniform3i(location, x, y, z); -} - -void GraphicsContext3D::uniform3iv(GC3Dint location, GC3Dsizei size, GC3Dint* v) -{ - m_private->uniform3iv(location, size, v); -} - -void GraphicsContext3D::uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w) -{ - m_private->uniform4f(location, x, y, z, w); -} - -void GraphicsContext3D::uniform4fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* v) -{ - m_private->uniform4fv(location, size, v); -} - -void GraphicsContext3D::uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w) -{ - m_private->uniform4i(location, x, y, z, w); -} - -void GraphicsContext3D::uniform4iv(GC3Dint location, GC3Dsizei size, GC3Dint* v) -{ - m_private->uniform4iv(location, size, v); -} - -void GraphicsContext3D::uniformMatrix2fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - m_private->uniformMatrix2fv(location, size, transpose, value); -} - -void GraphicsContext3D::uniformMatrix3fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - m_private->uniformMatrix3fv(location, size, transpose, value); -} - -void GraphicsContext3D::uniformMatrix4fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - m_private->uniformMatrix4fv(location, size, transpose, value); -} - -void GraphicsContext3D::useProgram(Platform3DObject program) -{ - m_private->useProgram(program); -} - -void GraphicsContext3D::validateProgram(Platform3DObject program) -{ - m_private->validateProgram(program); -} - -void GraphicsContext3D::vertexAttrib1f(GC3Duint index, GC3Dfloat x) -{ - m_private->vertexAttrib1f(index, x); -} - -void GraphicsContext3D::vertexAttrib1fv(GC3Duint index, GC3Dfloat* values) -{ - m_private->vertexAttrib1fv(index, values); -} - -void GraphicsContext3D::vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y) -{ - m_private->vertexAttrib2f(index, x, y); -} + if (!m_private) + return false; -void GraphicsContext3D::vertexAttrib2fv(GC3Duint index, GC3Dfloat* values) -{ - m_private->vertexAttrib2fv(index, values); -} - -void GraphicsContext3D::vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z) -{ - m_private->vertexAttrib3f(index, x, y, z); -} - -void GraphicsContext3D::vertexAttrib3fv(GC3Duint index, GC3Dfloat* values) -{ - m_private->vertexAttrib3fv(index, values); -} - -void GraphicsContext3D::vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w) -{ - m_private->vertexAttrib4f(index, x, y, z, w); -} + if (m_renderStyle == RenderToCurrentGLContext) + return true; -void GraphicsContext3D::vertexAttrib4fv(GC3Duint index, GC3Dfloat* values) -{ - m_private->vertexAttrib4fv(index, values); -} - -void GraphicsContext3D::vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized, GC3Dsizei stride, GC3Dintptr offset) -{ - m_private->vertexAttribPointer(index, size, type, normalized, stride, offset); -} - -void GraphicsContext3D::viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - m_private->viewport(x, y, width, height); -} - -void GraphicsContext3D::reshape(int width, int height) -{ - notImplemented(); -} - -void GraphicsContext3D::markContextChanged() -{ - notImplemented(); -} - -void GraphicsContext3D::markLayerComposited() -{ - notImplemented(); + return m_private->makeContextCurrent(); } -bool GraphicsContext3D::layerComposited() const +bool GraphicsContext3D::isGLES2Compliant() const { - notImplemented(); +#if USE(OPENGL_ES_2) + return true; +#else return false; +#endif } -void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer* drawingBuffer) +void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>) { notImplemented(); } -PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer) +void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>) { notImplemented(); - return 0; -} - -bool GraphicsContext3D::paintCompositedResultsToCanvas(ImageBuffer*) -{ - return false; -} - -Platform3DObject GraphicsContext3D::createBuffer() -{ - return m_private->createBuffer(); -} - -Platform3DObject GraphicsContext3D::createFramebuffer() -{ - return m_private->createFramebuffer(); -} - -Platform3DObject GraphicsContext3D::createProgram() -{ - return m_private->createProgram(); -} - -Platform3DObject GraphicsContext3D::createRenderbuffer() -{ - return m_private->createRenderbuffer(); -} - -Platform3DObject GraphicsContext3D::createShader(GC3Denum type) -{ - return m_private->createShader(type); -} - -Platform3DObject GraphicsContext3D::createTexture() -{ - return m_private->createTexture(); } -void GraphicsContext3D::deleteBuffer(Platform3DObject buffer) +void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, PlatformContextCairo* context) { - m_private->deleteBuffer(buffer); -} + if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0 || !context) + return; -void GraphicsContext3D::deleteFramebuffer(Platform3DObject buffer) -{ - m_private->deleteFramebuffer(buffer); -} + cairo_t* cr = context->cr(); + context->save(); -void GraphicsContext3D::deleteProgram(Platform3DObject program) -{ - m_private->deleteProgram(program); -} + RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data( + const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageWidth, imageHeight, imageWidth * 4)); -void GraphicsContext3D::deleteRenderbuffer(Platform3DObject buffer) -{ - m_private->deleteRenderbuffer(buffer); -} + // OpenGL keeps the pixels stored bottom up, so we need to flip the image here. + cairo_translate(cr, 0, imageHeight); + cairo_scale(cr, 1, -1); -void GraphicsContext3D::deleteShader(Platform3DObject shader) -{ - m_private->deleteShader(shader); -} + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface(cr, imageSurface.get(), 0, 0); + cairo_rectangle(cr, 0, 0, canvasWidth, -canvasHeight); -void GraphicsContext3D::deleteTexture(Platform3DObject texture) -{ - m_private->deleteTexture(texture); -} - -void GraphicsContext3D::synthesizeGLError(GC3Denum error) -{ - m_private->synthesizeGLError(error); + cairo_fill(cr); + context->restore(); } -Extensions3D* GraphicsContext3D::getExtensions() -{ - return m_private->getExtensions(); -} - -IntSize GraphicsContext3D::getInternalFramebufferSize() const -{ - notImplemented(); - return IntSize(); -} - -void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>) +#if USE(GRAPHICS_SURFACE) +void GraphicsContext3D::createGraphicsSurfaces(const IntSize& size) { notImplemented(); } +#endif bool GraphicsContext3D::getImageData(Image* image, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, Vector<uint8_t>& outputVector) @@ -829,32 +236,6 @@ bool GraphicsContext3D::getImageData(Image* image, GC3Denum format, GC3Denum typ return false; } -void GraphicsContext3D::validateAttributes() -{ - notImplemented(); -} - -void GraphicsContext3D::readRenderingResults(unsigned char* pixels, int pixelsSize) -{ - notImplemented(); -} - -bool GraphicsContext3D::reshapeFBOs(const IntSize&) -{ - notImplemented(); -} - -void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect&) -{ - notImplemented(); -} - -bool GraphicsContext3D::isResourceSafe() -{ - notImplemented(); - return false; -} - } // namespace WebCore #endif // USE(3D_GRAPHICS) diff --git a/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp b/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp index 78e6fb12a..68bd0d57b 100644 --- a/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp +++ b/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp @@ -20,93 +20,90 @@ #include "config.h" #if USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING) - #include "GraphicsContext3DPrivate.h" +#include "GraphicsContext.h" #include "HostWindow.h" #include "NotImplemented.h" -#include "PageClientEfl.h" - +#include <Ecore_Evas.h> +#include <Evas_GL.h> #include <wtf/OwnArrayPtr.h> #include <wtf/text/CString.h> namespace WebCore { -PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create(GraphicsContext3D::Attributes attributes, HostWindow* hostWindow, bool renderDirectlyToHostWindow) -{ - OwnPtr<GraphicsContext3DPrivate> internal = adoptPtr(new GraphicsContext3DPrivate()); - - if (!internal->initialize(attributes, hostWindow, renderDirectlyToHostWindow)) - return nullptr; - - return internal.release(); -} - -GraphicsContext3DPrivate::GraphicsContext3DPrivate() - : m_boundFBO(0) - , m_boundTexture(0) - , m_boundArrayBuffer(0) +GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) + : m_context(context) + , m_hostWindow(hostWindow) , m_evasGL(0) - , m_context(0) - , m_surface(0) + , m_evasGLContext(0) + , m_evasGLSurface(0) + , m_glContext(0) + , m_glSurface(0) , m_api(0) + , m_renderStyle(renderStyle) { -} - -GraphicsContext3DPrivate::~GraphicsContext3DPrivate() -{ - if (!m_evasGL) + if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext) return; - if (m_surface) - evas_gl_surface_destroy(m_evasGL, m_surface); - - if (m_context) - evas_gl_context_destroy(m_evasGL, m_context); - - evas_gl_free(m_evasGL); -} + if (m_hostWindow && m_hostWindow->platformPageClient()) { + // FIXME: Implement this code path for WebKit1. + // Get Evas object from platformPageClient and set EvasGL related members. + return; + } -bool GraphicsContext3DPrivate::initialize(GraphicsContext3D::Attributes attributes, HostWindow* hostWindow, bool renderDirectlyToHostWindow) -{ - PageClientEfl* pageClient = static_cast<PageClientEfl*>(hostWindow->platformPageClient()); + // For WebKit2, we need to create a dummy ecoreEvas object for the WebProcess in order to use EvasGL APIs. +#ifdef HAVE_ECORE_X + ecore_evas_init(); + m_ecoreEvas = adoptPtr(ecore_evas_gl_x11_new(0, 0, 0, 0, 1, 1)); + if (!m_ecoreEvas) + return; +#else + return; +#endif - Evas* evas = evas_object_evas_get(pageClient->view()); + Evas* evas = ecore_evas_get(m_ecoreEvas.get()); + if (!evas) + return; // Create a new Evas_GL object for gl rendering on efl. m_evasGL = evas_gl_new(evas); if (!m_evasGL) - return false; + return; // Get the API for rendering using OpenGL. // This returns a structure that contains all the OpenGL functions we can use to render in Evas m_api = evas_gl_api_get(m_evasGL); if (!m_api) - return false; - - Evas_GL_Context* shareContext = 0; - -#if USE(ACCELERATED_COMPOSITING) - // GC3D with RenderOffscreen style for WebGL has to be shared with AC's context when AC is enabled. - if (!renderDirectlyToHostWindow) { - GraphicsContext3D* context = pageClient->acceleratedCompositingContext(); - if (context) - shareContext = static_cast<Evas_GL_Context*>(context->platformGraphicsContext3D()); - } -#endif + return; // Create a context - m_context = evas_gl_context_create(m_evasGL, shareContext); - if (!m_context) - return false; + m_evasGLContext = evas_gl_context_create(m_evasGL, 0); + if (!m_evasGLContext) + return; // Create a surface - if (!createSurface(pageClient, renderDirectlyToHostWindow)) - return false; + if (!createSurface(0, renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow)) + return; + + makeContextCurrent(); +} + +GraphicsContext3DPrivate::~GraphicsContext3DPrivate() +{ + if (!m_evasGL) + return; + + if (m_evasGLSurface) + evas_gl_surface_destroy(m_evasGL, m_evasGLSurface); - return makeContextCurrent(); + if (m_evasGLContext) + evas_gl_context_destroy(m_evasGL, m_evasGLContext); + + evas_gl_free(m_evasGL); } + bool GraphicsContext3DPrivate::createSurface(PageClientEfl* pageClient, bool renderDirectlyToHostWindow) { // If RenderStyle is RenderOffscreen, we will be rendering to a FBO, @@ -117,8 +114,11 @@ bool GraphicsContext3DPrivate::createSurface(PageClientEfl* pageClient, bool ren int height = 1; // But, in case of RenderDirectlyToHostWindow, we have to render to a render target surface with the same size as our webView. - if (renderDirectlyToHostWindow) - evas_object_geometry_get(pageClient->view(), &x, &y, &width, &height); + if (renderDirectlyToHostWindow) { + if (!pageClient) + return false; + // FIXME: Get geometry of webView and set size of target surface. + } Evas_GL_Config config = { EVAS_GL_RGBA_8888, @@ -128,1002 +128,48 @@ bool GraphicsContext3DPrivate::createSurface(PageClientEfl* pageClient, bool ren }; // Create a new Evas_GL_Surface object - m_surface = evas_gl_surface_create(m_evasGL, &config, width, height); - if (!m_surface) + m_evasGLSurface = evas_gl_surface_create(m_evasGL, &config, width, height); + if (!m_evasGLSurface) return false; #if USE(ACCELERATED_COMPOSITING) if (renderDirectlyToHostWindow) { Evas_Native_Surface nativeSurface; // Fill in the Native Surface information from the given Evas GL surface. - evas_gl_native_surface_get(m_evasGL, m_surface, &nativeSurface); + evas_gl_native_surface_get(m_evasGL, m_evasGLSurface, &nativeSurface); - // Create and specially set up a evas_object which act as the render targer surface. - if (!pageClient->createEvasObjectForAcceleratedCompositing(&nativeSurface, IntRect(x, y, width, height))) - return false; + // FIXME: Create and specially set up a evas_object which act as the render targer surface. } #endif - return true; -} - -PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const -{ - return m_context; -} -bool GraphicsContext3DPrivate::makeContextCurrent() -{ - return evas_gl_make_current(m_evasGL, m_surface, m_context); -} - -bool GraphicsContext3DPrivate::isGLES2Compliant() const -{ return true; } -void GraphicsContext3DPrivate::activeTexture(GC3Denum texture) +void GraphicsContext3DPrivate::setCurrentGLContext(void* context, void* surface) { - makeContextCurrent(); - m_api->glActiveTexture(texture); -} - -void GraphicsContext3DPrivate::attachShader(Platform3DObject program, Platform3DObject shader) -{ - makeContextCurrent(); - m_api->glAttachShader(program, shader); -} - -void GraphicsContext3DPrivate::bindAttribLocation(Platform3DObject program, GC3Duint index, const String& name) -{ - makeContextCurrent(); - m_api->glBindAttribLocation(program, index, name.utf8().data()); -} - -void GraphicsContext3DPrivate::bindBuffer(GC3Denum target, Platform3DObject buffer) -{ - makeContextCurrent(); - m_api->glBindBuffer(target, buffer); - - if (target == GL_ARRAY_BUFFER) - m_boundArrayBuffer = buffer; -} - -void GraphicsContext3DPrivate::bindFramebuffer(GC3Denum target, Platform3DObject framebuffer) -{ - makeContextCurrent(); - - if (framebuffer != m_boundFBO) { - m_api->glBindFramebuffer(target, framebuffer); - m_boundFBO = framebuffer; - } + m_glContext = context; + m_glSurface = surface; } -void GraphicsContext3DPrivate::bindRenderbuffer(GC3Denum target, Platform3DObject buffer) -{ - makeContextCurrent(); - m_api->glBindRenderbuffer(target, buffer); -} - -void GraphicsContext3DPrivate::bindTexture(GC3Denum target, Platform3DObject texture) -{ - makeContextCurrent(); - m_api->glBindTexture(target, texture); - m_boundTexture = texture; -} - -void GraphicsContext3DPrivate::blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha) -{ - makeContextCurrent(); - m_api->glBlendColor(red, green, blue, alpha); -} - -void GraphicsContext3DPrivate::blendEquation(GC3Denum mode) -{ - makeContextCurrent(); - m_api->glBlendEquation(mode); -} - -void GraphicsContext3DPrivate::blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha) -{ - makeContextCurrent(); - m_api->glBlendEquationSeparate(modeRGB, modeAlpha); -} - -void GraphicsContext3DPrivate::blendFunc(GC3Denum srcFactor, GC3Denum dstFactor) -{ - makeContextCurrent(); - m_api->glBlendFunc(srcFactor, dstFactor); -} - -void GraphicsContext3DPrivate::blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha) -{ - makeContextCurrent(); - m_api->glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); -} - -void GraphicsContext3DPrivate::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage) -{ - makeContextCurrent(); - m_api->glBufferData(target, size, data, usage); -} - -void GraphicsContext3DPrivate::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data) -{ - makeContextCurrent(); - m_api->glBufferSubData(target, offset, size, data); -} - -GC3Denum GraphicsContext3DPrivate::checkFramebufferStatus(GC3Denum target) -{ - makeContextCurrent(); - return m_api->glCheckFramebufferStatus(target); -} - -void GraphicsContext3DPrivate::clear(GC3Dbitfield mask) -{ - makeContextCurrent(); - m_api->glClear(mask); -} - -void GraphicsContext3DPrivate::clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha) -{ - makeContextCurrent(); - m_api->glClearColor(red, green, blue, alpha); -} - -void GraphicsContext3DPrivate::clearDepth(GC3Dclampf depth) -{ - makeContextCurrent(); - m_api->glClearDepthf(depth); -} - -void GraphicsContext3DPrivate::clearStencil(GC3Dint clearValue) -{ - makeContextCurrent(); - m_api->glClearStencil(clearValue); -} - -void GraphicsContext3DPrivate::colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha) -{ - makeContextCurrent(); - m_api->glColorMask(red, green, blue, alpha); -} - -void GraphicsContext3DPrivate::compileShader(Platform3DObject shader) -{ - makeContextCurrent(); - m_api->glCompileShader(shader); -} - -void GraphicsContext3DPrivate::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border) -{ - makeContextCurrent(); - m_api->glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); -} - -void GraphicsContext3DPrivate::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - makeContextCurrent(); - m_api->glCopyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height); -} - -void GraphicsContext3DPrivate::cullFace(GC3Denum mode) -{ - makeContextCurrent(); - m_api->glCullFace(mode); -} - -void GraphicsContext3DPrivate::depthFunc(GC3Denum func) -{ - makeContextCurrent(); - m_api->glDepthFunc(func); -} - -void GraphicsContext3DPrivate::depthMask(GC3Dboolean flag) -{ - makeContextCurrent(); - m_api->glDepthMask(flag); -} - -void GraphicsContext3DPrivate::depthRange(GC3Dclampf zNear, GC3Dclampf zFar) -{ - makeContextCurrent(); - m_api->glDepthRangef(zNear, zFar); -} - -void GraphicsContext3DPrivate::detachShader(Platform3DObject program, Platform3DObject shader) -{ - makeContextCurrent(); - m_api->glDetachShader(program, shader); -} - -void GraphicsContext3DPrivate::disable(GC3Denum cap) -{ - makeContextCurrent(); - m_api->glDisable(cap); -} - -void GraphicsContext3DPrivate::disableVertexAttribArray(GC3Duint index) -{ - makeContextCurrent(); - m_api->glDisableVertexAttribArray(index); -} - -void GraphicsContext3DPrivate::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count) -{ - makeContextCurrent(); - m_api->glDrawArrays(mode, first, count); -} - -void GraphicsContext3DPrivate::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset) -{ - makeContextCurrent(); - m_api->glDrawElements(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset))); -} - -void GraphicsContext3DPrivate::enable(GC3Denum cap) -{ - makeContextCurrent(); - m_api->glEnable(cap); -} - -void GraphicsContext3DPrivate::enableVertexAttribArray(GC3Duint index) -{ - makeContextCurrent(); - m_api->glEnableVertexAttribArray(index); -} - -void GraphicsContext3DPrivate::finish() -{ - makeContextCurrent(); - m_api->glFinish(); -} - -void GraphicsContext3DPrivate::flush() -{ - makeContextCurrent(); - m_api->glFlush(); -} - -void GraphicsContext3DPrivate::framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbufferTarget, Platform3DObject renderbuffer) -{ - makeContextCurrent(); - m_api->glFramebufferRenderbuffer(target, attachment, renderbufferTarget, renderbuffer); -} - -void GraphicsContext3DPrivate::framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum texTarget, Platform3DObject texture, GC3Dint level) -{ - makeContextCurrent(); - m_api->glFramebufferTexture2D(target, attachment, texTarget, texture, level); -} - -void GraphicsContext3DPrivate::frontFace(GC3Denum mode) -{ - makeContextCurrent(); - m_api->glFrontFace(mode); -} - -void GraphicsContext3DPrivate::generateMipmap(GC3Denum target) -{ - makeContextCurrent(); - m_api->glGenerateMipmap(target); -} - -bool GraphicsContext3DPrivate::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info) -{ - if (!program) { - synthesizeGLError(GL_INVALID_VALUE); - return false; - } - - makeContextCurrent(); - - GLint maxNameLength = 0; - m_api->glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength); - if (!maxNameLength) - return false; - - OwnArrayPtr<char> name = adoptArrayPtr(new char[maxNameLength]); - if (!name) { - synthesizeGLError(GL_OUT_OF_MEMORY); - return false; - } - - GLsizei length = 0; - GLint size = 0; - GLenum type = 0; - m_api->glGetActiveAttrib(program, index, maxNameLength, &length, &size, &type, name.get()); - if (!length) - return false; - - info.name = String::fromUTF8(name.get(), length); - info.type = type; - info.size = size; - return true; -} - -bool GraphicsContext3DPrivate::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info) -{ - if (!program) { - synthesizeGLError(GL_INVALID_VALUE); - return false; - } - - makeContextCurrent(); - - GLint maxNameLength = 0; - m_api->glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength); - if (!maxNameLength) - return false; - - OwnArrayPtr<char> name = adoptArrayPtr(new char[maxNameLength]); - if (!name) { - synthesizeGLError(GL_OUT_OF_MEMORY); - return false; - } - - GLsizei length = 0; - GLint size = 0; - GLenum type = 0; - m_api->glGetActiveUniform(program, index, maxNameLength, &length, &size, &type, name.get()); - if (!length) - return false; - - info.name = String::fromUTF8(name.get(), length); - info.type = type; - info.size = size; - return true; -} - -void GraphicsContext3DPrivate::getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders) -{ - makeContextCurrent(); - m_api->glGetAttachedShaders(program, maxCount, count, shaders); -} - -int GraphicsContext3DPrivate::getAttribLocation(Platform3DObject program, const String& name) -{ - makeContextCurrent(); - return m_api->glGetAttribLocation(program, name.utf8().data()); -} - -void GraphicsContext3DPrivate::getBooleanv(GC3Denum paramName, GC3Dboolean* value) -{ - makeContextCurrent(); - m_api->glGetBooleanv(paramName, value); -} - -void GraphicsContext3DPrivate::getBufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetBufferParameteriv(target, paramName, value); -} - -GraphicsContext3D::Attributes GraphicsContext3DPrivate::getContextAttributes() -{ - return m_attributes; -} - -GC3Denum GraphicsContext3DPrivate::getError() -{ - if (!m_syntheticErrors.isEmpty()) { - GC3Denum error = m_syntheticErrors.first(); - m_syntheticErrors.remove(m_syntheticErrors.begin()); - return error; - } - - makeContextCurrent(); - return m_api->glGetError(); -} - -void GraphicsContext3DPrivate::getFloatv(GC3Denum paramName, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glGetFloatv(paramName, value); -} - -void GraphicsContext3DPrivate::getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetFramebufferAttachmentParameteriv(target, attachment, paramName, value); -} - -void GraphicsContext3DPrivate::getIntegerv(GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetIntegerv(paramName, value); -} - -void GraphicsContext3DPrivate::getProgramiv(Platform3DObject program, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetProgramiv(program, paramName, value); -} - -String GraphicsContext3DPrivate::getProgramInfoLog(Platform3DObject program) -{ - makeContextCurrent(); - - GLint logLength = 0; - m_api->glGetProgramiv(program, GraphicsContext3D::INFO_LOG_LENGTH, &logLength); - if (!logLength) - return String(); - - OwnArrayPtr<char> log = adoptArrayPtr(new char[logLength]); - if (!log) - return String(); - - GLint returnedLogLength = 0; - m_api->glGetProgramInfoLog(program, logLength, &returnedLogLength, log.get()); - ASSERT(logLength == returnedLogLength + 1); - - String result = String::fromUTF8(log.get(), returnedLogLength); - return result; -} - -void GraphicsContext3DPrivate::getRenderbufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetRenderbufferParameteriv(target, paramName, value); -} - -void GraphicsContext3DPrivate::getShaderiv(Platform3DObject shader, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetShaderiv(shader, paramName, value); -} - -String GraphicsContext3DPrivate::getShaderInfoLog(Platform3DObject shader) -{ - makeContextCurrent(); - - GLint logLength = 0; - m_api->glGetShaderiv(shader, GraphicsContext3D::INFO_LOG_LENGTH, &logLength); - if (logLength <= 1) - return String(); - - OwnArrayPtr<char> log = adoptArrayPtr(new char[logLength]); - if (!log) - return String(); - - GLint returnedLogLength = 0; - m_api->glGetShaderInfoLog(shader, logLength, &returnedLogLength, log.get()); - ASSERT(logLength == returnedLogLength + 1); - - String result = String::fromUTF8(log.get(), returnedLogLength); - return result; -} - -String GraphicsContext3DPrivate::getShaderSource(Platform3DObject shader) -{ - makeContextCurrent(); - - GLint logLength = 0; - m_api->glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); - if (logLength <= 1) - return String(); - - OwnArrayPtr<char> log = adoptArrayPtr(new char[logLength]); - if (!log) - return String(); - - GLint returnedLogLength = 0; - m_api->glGetShaderSource(shader, logLength, &returnedLogLength, log.get()); - ASSERT(logLength == returnedLogLength + 1); - - String result = String::fromUTF8(log.get(), returnedLogLength); - return result; -} - -String GraphicsContext3DPrivate::getString(GC3Denum name) -{ - makeContextCurrent(); - return String(reinterpret_cast<const char*>(m_api->glGetString(name))); -} - -void GraphicsContext3DPrivate::getTexParameterfv(GC3Denum target, GC3Denum paramName, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glGetTexParameterfv(target, paramName, value); -} - -void GraphicsContext3DPrivate::getTexParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetTexParameteriv(target, paramName, value); -} - -void GraphicsContext3DPrivate::getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glGetUniformfv(program, location, value); -} - -void GraphicsContext3DPrivate::getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetUniformiv(program, location, value); -} - -GC3Dint GraphicsContext3DPrivate::getUniformLocation(Platform3DObject program, const String& name) -{ - makeContextCurrent(); - return m_api->glGetUniformLocation(program, name.utf8().data()); -} - -void GraphicsContext3DPrivate::getVertexAttribfv(GC3Duint index, GC3Denum paramName, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glGetVertexAttribfv(index, paramName, value); -} - -void GraphicsContext3DPrivate::getVertexAttribiv(GC3Duint index, GC3Denum paramName, GC3Dint* value) -{ - makeContextCurrent(); - m_api->glGetVertexAttribiv(index, paramName, value); -} - -GC3Dsizeiptr GraphicsContext3DPrivate::getVertexAttribOffset(GC3Duint index, GC3Denum paramName) -{ - makeContextCurrent(); - void* pointer = 0; - m_api->glGetVertexAttribPointerv(index, paramName, &pointer); - return reinterpret_cast<GC3Dsizeiptr>(pointer); -} - -void GraphicsContext3DPrivate::hint(GC3Denum target, GC3Denum mode) -{ - makeContextCurrent(); - m_api->glHint(target, mode); -} - -GC3Dboolean GraphicsContext3DPrivate::isBuffer(Platform3DObject buffer) -{ - makeContextCurrent(); - return m_api->glIsBuffer(buffer); -} - -GC3Dboolean GraphicsContext3DPrivate::isEnabled(GC3Denum cap) -{ - makeContextCurrent(); - return m_api->glIsEnabled(cap); -} - -GC3Dboolean GraphicsContext3DPrivate::isFramebuffer(Platform3DObject framebuffer) -{ - makeContextCurrent(); - return m_api->glIsFramebuffer(framebuffer); -} - -GC3Dboolean GraphicsContext3DPrivate::isProgram(Platform3DObject program) -{ - makeContextCurrent(); - return m_api->glIsProgram(program); -} - -GC3Dboolean GraphicsContext3DPrivate::isRenderbuffer(Platform3DObject renderbuffer) -{ - makeContextCurrent(); - return m_api->glIsRenderbuffer(renderbuffer); -} - -GC3Dboolean GraphicsContext3DPrivate::isShader(Platform3DObject shader) -{ - makeContextCurrent(); - return m_api->glIsShader(shader); -} - -GC3Dboolean GraphicsContext3DPrivate::isTexture(Platform3DObject texture) -{ - makeContextCurrent(); - return m_api->glIsTexture(texture); -} - -void GraphicsContext3DPrivate::lineWidth(GC3Dfloat width) -{ - makeContextCurrent(); - m_api->glLineWidth(width); -} - -void GraphicsContext3DPrivate::linkProgram(Platform3DObject program) -{ - makeContextCurrent(); - m_api->glLinkProgram(program); -} - -void GraphicsContext3DPrivate::pixelStorei(GC3Denum paramName, GC3Dint param) -{ - makeContextCurrent(); - m_api->glPixelStorei(paramName, param); -} - -void GraphicsContext3DPrivate::polygonOffset(GC3Dfloat factor, GC3Dfloat units) -{ - makeContextCurrent(); - m_api->glPolygonOffset(factor, units); -} - -void GraphicsContext3DPrivate::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data) -{ - makeContextCurrent(); - - m_api->glFlush(); - m_api->glReadPixels(x, y, width, height, format, type, data); -} - -void GraphicsContext3DPrivate::renderbufferStorage(GC3Denum target, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height) -{ - makeContextCurrent(); - m_api->glRenderbufferStorage(target, internalFormat, width, height); -} - -void GraphicsContext3DPrivate::sampleCoverage(GC3Dclampf value, GC3Dboolean invert) -{ - makeContextCurrent(); - m_api->glSampleCoverage(value, invert); -} - -void GraphicsContext3DPrivate::scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - makeContextCurrent(); - m_api->glScissor(x, y, width, height); -} - -void GraphicsContext3DPrivate::shaderSource(Platform3DObject shader, const String& string) -{ - makeContextCurrent(); - const char* str = string.utf8().data(); - int length = string.length(); - m_api->glShaderSource(shader, 1, &str, &length); -} - -void GraphicsContext3DPrivate::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask) -{ - makeContextCurrent(); - m_api->glStencilFunc(func, ref, mask); -} - -void GraphicsContext3DPrivate::stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask) -{ - makeContextCurrent(); - m_api->glStencilFuncSeparate(face, func, ref, mask); -} - -void GraphicsContext3DPrivate::stencilMask(GC3Duint mask) -{ - makeContextCurrent(); - m_api->glStencilMask(mask); -} - -void GraphicsContext3DPrivate::stencilMaskSeparate(GC3Denum face, GC3Duint mask) -{ - makeContextCurrent(); - m_api->glStencilMaskSeparate(face, mask); -} - -void GraphicsContext3DPrivate::stencilOp(GC3Denum fail, GC3Denum zFail, GC3Denum zPass) -{ - makeContextCurrent(); - m_api->glStencilOp(fail, zFail, zPass); -} - -void GraphicsContext3DPrivate::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zFail, GC3Denum zPass) -{ - makeContextCurrent(); - m_api->glStencilOpSeparate(face, fail, zFail, zPass); -} - -bool GraphicsContext3DPrivate::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels) -{ - makeContextCurrent(); - m_api->glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels); - return true; -} - -void GraphicsContext3DPrivate::texParameterf(GC3Denum target, GC3Denum paramName, GC3Dfloat param) -{ - makeContextCurrent(); - m_api->glTexParameterf(target, paramName, param); -} - -void GraphicsContext3DPrivate::texParameteri(GC3Denum target, GC3Denum paramName, GC3Dint param) -{ - makeContextCurrent(); - m_api->glTexParameteri(target, paramName, param); -} - -void GraphicsContext3DPrivate::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels) -{ - makeContextCurrent(); - m_api->glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, pixels); -} - -void GraphicsContext3DPrivate::uniform1f(GC3Dint location, GC3Dfloat x) -{ - makeContextCurrent(); - m_api->glUniform1f(location, x); -} - -void GraphicsContext3DPrivate::uniform1fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* array) -{ - makeContextCurrent(); - m_api->glUniform1fv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform1i(GC3Dint location, GC3Dint x) -{ - makeContextCurrent(); - m_api->glUniform1i(location, x); -} - -void GraphicsContext3DPrivate::uniform1iv(GC3Dint location, GC3Dsizei size, GC3Dint* array) -{ - makeContextCurrent(); - m_api->glUniform1iv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y) -{ - makeContextCurrent(); - m_api->glUniform2f(location, x, y); -} - -void GraphicsContext3DPrivate::uniform2fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* array) -{ - makeContextCurrent(); - m_api->glUniform2fv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform2i(GC3Dint location, GC3Dint x, GC3Dint y) -{ - makeContextCurrent(); - m_api->glUniform2i(location, x, y); -} - -void GraphicsContext3DPrivate::uniform2iv(GC3Dint location, GC3Dsizei size, GC3Dint* array) -{ - makeContextCurrent(); - m_api->glUniform2iv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z) -{ - makeContextCurrent(); - m_api->glUniform3f(location, x, y, z); -} - -void GraphicsContext3DPrivate::uniform3fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* array) -{ - makeContextCurrent(); - m_api->glUniform3fv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z) -{ - makeContextCurrent(); - m_api->glUniform3i(location, x, y, z); -} - -void GraphicsContext3DPrivate::uniform3iv(GC3Dint location, GC3Dsizei size, GC3Dint* array) -{ - makeContextCurrent(); - m_api->glUniform3iv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w) -{ - makeContextCurrent(); - m_api->glUniform4f(location, x, y, z, w); -} - -void GraphicsContext3DPrivate::uniform4fv(GC3Dint location, GC3Dsizei size, GC3Dfloat* array) -{ - makeContextCurrent(); - m_api->glUniform4fv(location, size, array); -} - -void GraphicsContext3DPrivate::uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w) -{ - makeContextCurrent(); - m_api->glUniform4i(location, x, y, z, w); -} - -void GraphicsContext3DPrivate::uniform4iv(GC3Dint location, GC3Dsizei size, GC3Dint* array) -{ - makeContextCurrent(); - m_api->glUniform4iv(location, size, array); -} - -void GraphicsContext3DPrivate::uniformMatrix2fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glUniformMatrix2fv(location, size, transpose, value); -} - -void GraphicsContext3DPrivate::uniformMatrix3fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glUniformMatrix3fv(location, size, transpose, value); -} - -void GraphicsContext3DPrivate::uniformMatrix4fv(GC3Dint location, GC3Dsizei size, GC3Dboolean transpose, GC3Dfloat* value) -{ - makeContextCurrent(); - m_api->glUniformMatrix4fv(location, size, transpose, value); -} - -void GraphicsContext3DPrivate::useProgram(Platform3DObject program) -{ - makeContextCurrent(); - m_api->glUseProgram(program); -} - -void GraphicsContext3DPrivate::validateProgram(Platform3DObject program) -{ - makeContextCurrent(); - m_api->glValidateProgram(program); -} - -void GraphicsContext3DPrivate::vertexAttrib1f(GC3Duint index, GC3Dfloat x) -{ - makeContextCurrent(); - m_api->glVertexAttrib1f(index, x); -} - -void GraphicsContext3DPrivate::vertexAttrib1fv(GC3Duint index, GC3Dfloat* values) -{ - makeContextCurrent(); - m_api->glVertexAttrib1fv(index, values); -} - -void GraphicsContext3DPrivate::vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y) -{ - makeContextCurrent(); - m_api->glVertexAttrib2f(index, x, y); -} - -void GraphicsContext3DPrivate::vertexAttrib2fv(GC3Duint index, GC3Dfloat* values) -{ - makeContextCurrent(); - m_api->glVertexAttrib2fv(index, values); -} - -void GraphicsContext3DPrivate::vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z) -{ - makeContextCurrent(); - m_api->glVertexAttrib3f(index, x, y, z); -} - -void GraphicsContext3DPrivate::vertexAttrib3fv(GC3Duint index, GC3Dfloat* values) -{ - makeContextCurrent(); - m_api->glVertexAttrib3fv(index, values); -} - -void GraphicsContext3DPrivate::vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w) -{ - makeContextCurrent(); - m_api->glVertexAttrib4f(index, x, y, z, w); -} - -void GraphicsContext3DPrivate::vertexAttrib4fv(GC3Duint index, GC3Dfloat* values) -{ - makeContextCurrent(); - m_api->glVertexAttrib4fv(index, values); -} - -void GraphicsContext3DPrivate::vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized, GC3Dsizei stride, GC3Dintptr offset) -{ - makeContextCurrent(); - - if (m_boundArrayBuffer <= 0) - return; - - m_api->glVertexAttribPointer(index, size, type, normalized, stride, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset))); -} - -void GraphicsContext3DPrivate::viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) -{ - makeContextCurrent(); - m_api->glViewport(x, y, width, height); -} - -Platform3DObject GraphicsContext3DPrivate::createBuffer() -{ - makeContextCurrent(); - Platform3DObject buffer = 0; - m_api->glGenBuffers(1, &buffer); - return buffer; -} - -Platform3DObject GraphicsContext3DPrivate::createFramebuffer() -{ - makeContextCurrent(); - Platform3DObject buffer = 0; - m_api->glGenFramebuffers(1, &buffer); - return buffer; -} - -Platform3DObject GraphicsContext3DPrivate::createProgram() -{ - makeContextCurrent(); - return m_api->glCreateProgram(); -} - -Platform3DObject GraphicsContext3DPrivate::createRenderbuffer() -{ - makeContextCurrent(); - Platform3DObject buffer; - m_api->glGenRenderbuffers(1, &buffer); - return buffer; -} - -Platform3DObject GraphicsContext3DPrivate::createShader(GC3Denum shaderType) -{ - makeContextCurrent(); - return m_api->glCreateShader(shaderType); -} - -Platform3DObject GraphicsContext3DPrivate::createTexture() -{ - makeContextCurrent(); - Platform3DObject texture; - m_api->glGenTextures(1, &texture); - return texture; -} - -void GraphicsContext3DPrivate::deleteBuffer(Platform3DObject buffer) -{ - makeContextCurrent(); - m_api->glDeleteBuffers(1, &buffer); -} - -void GraphicsContext3DPrivate::deleteFramebuffer(Platform3DObject framebuffer) -{ - makeContextCurrent(); - if (framebuffer == m_boundFBO) { - // Make sure the framebuffer is not going to be used for drawing - // operations after it gets deleted. - bindFramebuffer(FRAMEBUFFER, 0); - } - m_api->glDeleteFramebuffers(1, &framebuffer); -} - -void GraphicsContext3DPrivate::deleteProgram(Platform3DObject program) -{ - makeContextCurrent(); - m_api->glDeleteProgram(program); -} - -void GraphicsContext3DPrivate::deleteRenderbuffer(Platform3DObject renderbuffer) -{ - makeContextCurrent(); - m_api->glDeleteRenderbuffers(1, &renderbuffer); -} - -void GraphicsContext3DPrivate::deleteShader(Platform3DObject shader) +PlatformGraphicsContext3D GraphicsContext3DPrivate::platformGraphicsContext3D() const { - makeContextCurrent(); - m_api->glDeleteShader(shader); -} + if (m_renderStyle == GraphicsContext3D::RenderToCurrentGLContext) + return m_glContext; -void GraphicsContext3DPrivate::deleteTexture(Platform3DObject texture) -{ - makeContextCurrent(); - m_api->glDeleteTextures(1, &texture); + return m_evasGLContext; } -void GraphicsContext3DPrivate::synthesizeGLError(GC3Denum error) +bool GraphicsContext3DPrivate::makeContextCurrent() { - m_syntheticErrors.add(error); + return evas_gl_make_current(m_evasGL, m_evasGLSurface, m_evasGLContext); } -Extensions3D* GraphicsContext3DPrivate::getExtensions() +#if USE(TEXTURE_MAPPER_GL) +void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask) { notImplemented(); - return 0; } - +#endif } // namespace WebCore #endif // USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h b/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h index d02b87845..08ccf77a6 100644 --- a/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h +++ b/Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.h @@ -22,15 +22,26 @@ #include "GraphicsContext3D.h" -#include <Evas_GL.h> +#if USE(TEXTURE_MAPPER_GL) +#include <texmap/TextureMapperPlatformLayer.h> +#endif -namespace WebCore { +typedef struct _Evas_GL Evas_GL; +typedef struct _Evas_GL_Surface Evas_GL_Surface; +typedef struct _Evas_GL_Context Evas_GL_Context; +typedef struct _Evas_GL_Config Evas_GL_Config; +typedef struct _Evas_GL_API Evas_GL_API; class PageClientEfl; -class GraphicsContext3DPrivate { +namespace WebCore { +class GraphicsContext3DPrivate +#if USE(TEXTURE_MAPPER_GL) + : public TextureMapperPlatformLayer +#endif +{ public: - static PassOwnPtr<GraphicsContext3DPrivate> create(GraphicsContext3D::Attributes attrs, HostWindow*, bool renderDirectlyToEvasGLObject); + GraphicsContext3DPrivate(GraphicsContext3D*, HostWindow*, GraphicsContext3D::RenderStyle); ~GraphicsContext3DPrivate(); PlatformGraphicsContext3D platformGraphicsContext3D() const; @@ -38,188 +49,27 @@ public: #if USE(ACCELERATED_COMPOSITING) PlatformLayer* platformLayer() const; #endif - +#if USE(TEXTURE_MAPPER_GL) + virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask); +#endif bool makeContextCurrent(); - - bool isGLES2Compliant() const; - - void activeTexture(GC3Denum texture); - void attachShader(Platform3DObject program, Platform3DObject shader); - void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name); - void bindBuffer(GC3Denum target, Platform3DObject); - void bindFramebuffer(GC3Denum target, Platform3DObject); - void bindRenderbuffer(GC3Denum target, Platform3DObject); - void bindTexture(GC3Denum target, Platform3DObject); - void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha); - void blendEquation(GC3Denum mode); - void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha); - void blendFunc(GC3Denum srcFactor, GC3Denum dstFactor); - void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha); - - void bufferData(GC3Denum target, GC3Dsizeiptr, const void* data, GC3Denum usage); - void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr, const void* data); - - GC3Denum checkFramebufferStatus(GC3Denum target); - void clear(GC3Dbitfield mask); - void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha); - void clearDepth(GC3Dclampf depth); - void clearStencil(GC3Dint clearValue); - void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha); - void compileShader(Platform3DObject); - - void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border); - void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); - void cullFace(GC3Denum mode); - void depthFunc(GC3Denum func); - void depthMask(GC3Dboolean flag); - void depthRange(GC3Dclampf zNear, GC3Dclampf zFar); - void detachShader(Platform3DObject, Platform3DObject); - void disable(GC3Denum cap); - void disableVertexAttribArray(GC3Duint index); - void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count); - void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset); - - void enable(GC3Denum cap); - void enableVertexAttribArray(GC3Duint index); - void finish(); - void flush(); - void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbufferTarget, Platform3DObject); - void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum texTarget, Platform3DObject, GC3Dint level); - void frontFace(GC3Denum mode); - void generateMipmap(GC3Denum target); - - bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&); - bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&); - void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders); - GC3Dint getAttribLocation(Platform3DObject, const String& name); - void getBooleanv(GC3Denum paramName, GC3Dboolean* value); - void getBufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value); - GraphicsContext3D::Attributes getContextAttributes(); - GC3Denum getError(); - void getFloatv(GC3Denum paramName, GC3Dfloat* value); - void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum paramName, GC3Dint* value); - void getIntegerv(GC3Denum paramName, GC3Dint* value); - void getProgramiv(Platform3DObject program, GC3Denum paramName, GC3Dint* value); - String getProgramInfoLog(Platform3DObject); - void getRenderbufferParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value); - void getShaderiv(Platform3DObject, GC3Denum paramName, GC3Dint* value); - String getShaderInfoLog(Platform3DObject); - - String getShaderSource(Platform3DObject); - String getString(GC3Denum name); - void getTexParameterfv(GC3Denum target, GC3Denum paramName, GC3Dfloat* value); - void getTexParameteriv(GC3Denum target, GC3Denum paramName, GC3Dint* value); - void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value); - void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value); - GC3Dint getUniformLocation(Platform3DObject, const String& name); - void getVertexAttribfv(GC3Duint index, GC3Denum paramName, GC3Dfloat* value); - void getVertexAttribiv(GC3Duint index, GC3Denum paramName, GC3Dint* value); - GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum paramName); - - void hint(GC3Denum target, GC3Denum mode); - GC3Dboolean isBuffer(Platform3DObject); - GC3Dboolean isEnabled(GC3Denum cap); - GC3Dboolean isFramebuffer(Platform3DObject); - GC3Dboolean isProgram(Platform3DObject); - GC3Dboolean isRenderbuffer(Platform3DObject); - GC3Dboolean isShader(Platform3DObject); - GC3Dboolean isTexture(Platform3DObject); - void lineWidth(GC3Dfloat); - void linkProgram(Platform3DObject); - void pixelStorei(GC3Denum paramName, GC3Dint param); - void polygonOffset(GC3Dfloat factor, GC3Dfloat units); - - void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data); - - void renderbufferStorage(GC3Denum target, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height); - void sampleCoverage(GC3Dclampf value, GC3Dboolean invert); - void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); - void shaderSource(Platform3DObject, const String&); - void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask); - void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask); - void stencilMask(GC3Duint mask); - void stencilMaskSeparate(GC3Denum face, GC3Duint mask); - void stencilOp(GC3Denum fail, GC3Denum zFail, GC3Denum zPass); - void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zFail, GC3Denum zPass); - - bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels); - void texParameterf(GC3Denum target, GC3Denum paramName, GC3Dfloat param); - void texParameteri(GC3Denum target, GC3Denum paramName, GC3Dint param); - void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xOffset, GC3Dint yOffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels); - - void uniform1f(GC3Dint location, GC3Dfloat x); - void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); - void uniform1i(GC3Dint location, GC3Dint x); - void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v); - void uniform2f(GC3Dint location, GC3Dfloat x, float y); - void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); - void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y); - void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v); - void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); - void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); - void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z); - void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v); - void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w); - void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); - void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w); - void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v); - void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value); - void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value); - void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC3Dfloat* value); - - void useProgram(Platform3DObject); - void validateProgram(Platform3DObject); - - void vertexAttrib1f(GC3Duint index, GC3Dfloat x); - void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values); - void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y); - void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values); - void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); - void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values); - void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w); - void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values); - void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized, - GC3Dsizei stride, GC3Dintptr offset); - - void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); - - Platform3DObject createBuffer(); - Platform3DObject createFramebuffer(); - Platform3DObject createProgram(); - Platform3DObject createRenderbuffer(); - Platform3DObject createShader(GC3Denum); - Platform3DObject createTexture(); - - void deleteBuffer(Platform3DObject); - void deleteFramebuffer(Platform3DObject); - void deleteProgram(Platform3DObject); - void deleteRenderbuffer(Platform3DObject); - void deleteShader(Platform3DObject); - void deleteTexture(Platform3DObject); - - void synthesizeGLError(GC3Denum error); - - Extensions3D* getExtensions(); - -private: - GraphicsContext3DPrivate(); - - bool initialize(GraphicsContext3D::Attributes attrs, HostWindow*, bool renderDirectlyToHostWindow); - bool createSurface(PageClientEfl*, bool renderDirectlyToEvasGLObject); + void setCurrentGLContext(void*, void*); GraphicsContext3D::Attributes m_attributes; - - Platform3DObject m_boundFBO; - Platform3DObject m_boundTexture; - Platform3DObject m_boundArrayBuffer; + GraphicsContext3D* m_context; + HostWindow* m_hostWindow; ListHashSet<GC3Denum> m_syntheticErrors; + OwnPtr<Ecore_Evas> m_ecoreEvas; Evas_GL* m_evasGL; - Evas_GL_Context* m_context; - Evas_GL_Surface* m_surface; + Evas_GL_Context* m_evasGLContext; + Evas_GL_Surface* m_evasGLSurface; + void* m_glContext; + void* m_glSurface; Evas_GL_API* m_api; + GraphicsContext3D::RenderStyle m_renderStyle; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.cpp b/Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.cpp deleted file mode 100644 index a566bd064..000000000 --- a/Source/WebCore/platform/graphics/efl/GraphicsLayerEfl.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright (C) 2009-2011 Samsung Electronics - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ - -#include "config.h" - -#if USE(ACCELERATED_COMPOSITING) - -#include "GraphicsLayerEfl.h" - -#include "NotImplemented.h" - -namespace WebCore { - -PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) -{ - return adoptPtr(new GraphicsLayerEfl(client)); -} - -GraphicsLayerEfl::GraphicsLayerEfl(GraphicsLayerClient* client) - : GraphicsLayer(client) -{ -} - -GraphicsLayerEfl::~GraphicsLayerEfl() -{ - willBeDestroyed(); -} - -void GraphicsLayerEfl::setNeedsDisplay() -{ - notImplemented(); -} - -void GraphicsLayerEfl::setNeedsDisplayInRect(const FloatRect&) -{ - notImplemented(); -} - -} // namespace WebCore - -#endif // USE(ACCELERATED_COMPOSITING) |