summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/cairo
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/graphics/cairo')
-rw-r--r--Source/WebCore/platform/graphics/cairo/CairoPath.h50
-rw-r--r--Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp2
-rw-r--r--Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp17
-rw-r--r--Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.h2
-rw-r--r--Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp120
-rw-r--r--Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp53
-rw-r--r--Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h24
-rw-r--r--Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp11
-rw-r--r--Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h (renamed from Source/WebCore/platform/graphics/cairo/ImageBufferData.h)7
-rw-r--r--Source/WebCore/platform/graphics/cairo/ImageCairo.cpp4
-rw-r--r--Source/WebCore/platform/graphics/cairo/OpenGLShims.cpp191
-rw-r--r--Source/WebCore/platform/graphics/cairo/OpenGLShims.h315
-rw-r--r--Source/WebCore/platform/graphics/cairo/PathCairo.cpp2
-rw-r--r--Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp47
-rw-r--r--Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h25
-rw-r--r--Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp39
-rw-r--r--Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h43
-rw-r--r--Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp2
18 files changed, 810 insertions, 144 deletions
diff --git a/Source/WebCore/platform/graphics/cairo/CairoPath.h b/Source/WebCore/platform/graphics/cairo/CairoPath.h
deleted file mode 100644
index da7affb..0000000
--- a/Source/WebCore/platform/graphics/cairo/CairoPath.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
- Copyright (C) 2010 Igalia S.L.
-
- 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
- aint 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.
-*/
-
-#ifndef CairoPath_h
-#define CairoPath_h
-
-#include <cairo.h>
-
-namespace WebCore {
-
-// This is necessary since cairo_path_fixed_t isn't exposed in Cairo's public API.
-class CairoPath {
-public:
- CairoPath()
- {
- static cairo_surface_t* pathSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
- m_cr = cairo_create(pathSurface);
- }
-
- ~CairoPath()
- {
- cairo_destroy(m_cr);
- }
-
- cairo_t* context() { return m_cr; }
-
-private:
- cairo_t* m_cr;
-};
-
-} // namespace WebCore
-
-#endif // CairoPath_h
diff --git a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp b/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
index ee159a1..758bce9 100644
--- a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
+++ b/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
@@ -27,13 +27,13 @@
#include "CairoUtilities.h"
#include "AffineTransform.h"
-#include "CairoPath.h"
#include "Color.h"
#include "FloatPoint.h"
#include "FloatRect.h"
#include "IntRect.h"
#include "OwnPtrCairo.h"
#include "Path.h"
+#include "PlatformPathCairo.h"
#include "RefPtrCairo.h"
#include <wtf/Vector.h>
diff --git a/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp b/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp
index 0f90ce4..d968ee9 100644
--- a/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp
@@ -42,11 +42,10 @@ using WTF::max;
namespace WebCore {
-static cairo_surface_t* scratchBuffer = 0;
+static RefPtr<cairo_surface_t> gScratchBuffer;
static void purgeScratchBuffer()
{
- cairo_surface_destroy(scratchBuffer);
- scratchBuffer = 0;
+ gScratchBuffer.clear();
}
// ContextShadow needs a scratch image as the buffer for the blur filter.
@@ -68,20 +67,20 @@ static cairo_surface_t* getScratchBuffer(const IntSize& size)
{
int width = size.width();
int height = size.height();
- int scratchWidth = scratchBuffer ? cairo_image_surface_get_width(scratchBuffer) : 0;
- int scratchHeight = scratchBuffer ? cairo_image_surface_get_height(scratchBuffer) : 0;
+ int scratchWidth = gScratchBuffer.get() ? cairo_image_surface_get_width(gScratchBuffer.get()) : 0;
+ int scratchHeight = gScratchBuffer.get() ? cairo_image_surface_get_height(gScratchBuffer.get()) : 0;
// We do not need to recreate the buffer if the current buffer is large enough.
- if (scratchBuffer && scratchWidth >= width && scratchHeight >= height)
- return scratchBuffer;
+ if (gScratchBuffer.get() && scratchWidth >= width && scratchHeight >= height)
+ return gScratchBuffer.get();
purgeScratchBuffer();
// Round to the nearest 32 pixels so we do not grow the buffer for similar sized requests.
width = (1 + (width >> 5)) << 5;
height = (1 + (height >> 5)) << 5;
- scratchBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
- return scratchBuffer;
+ gScratchBuffer = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height));
+ return gScratchBuffer.get();
}
PlatformContext ContextShadow::beginShadowLayer(GraphicsContext* context, const FloatRect& layerArea)
diff --git a/Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.h b/Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.h
index b90bb8c..3a49d5c 100644
--- a/Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.h
+++ b/Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.h
@@ -21,7 +21,7 @@
*
*/
-#if PLATFORM(CAIRO)
+#if USE(CAIRO)
#ifndef DrawErrorUnderline_h
#define DrawErrorUnderline_h
diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp
new file mode 100644
index 0000000..c90d8ab
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GraphicsContext3D.h"
+#include "PlatformContextCairo.h"
+
+#if ENABLE(WEBGL)
+
+#include "Image.h"
+#include "RefPtrCairo.h"
+#include <cairo.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+bool GraphicsContext3D::getImageData(Image* image, unsigned int format, unsigned int type, bool premultiplyAlpha, bool ignoreGammaAndColorProfile, Vector<uint8_t>& outputVector)
+{
+ if (!image)
+ return false;
+ // We need this to stay in scope because the native image is just a shallow copy of the data.
+ ImageSource decoder(premultiplyAlpha ? ImageSource::AlphaPremultiplied : ImageSource::AlphaNotPremultiplied,
+ ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied);
+ AlphaOp alphaOp = AlphaDoNothing;
+ RefPtr<cairo_surface_t> imageSurface;
+ if (image->data()) {
+ decoder.setData(image->data(), true);
+ if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0))
+ return false;
+ imageSurface = decoder.createFrameAtIndex(0);
+ } else {
+ imageSurface = image->nativeImageForCurrentFrame();
+ if (!premultiplyAlpha)
+ alphaOp = AlphaDoUnmultiply;
+ }
+
+ if (!imageSurface)
+ return false;
+
+ int width = cairo_image_surface_get_width(imageSurface.get());
+ int height = cairo_image_surface_get_height(imageSurface.get());
+ if (!width || !height)
+ return false;
+
+ if (cairo_image_surface_get_format(imageSurface.get()) != CAIRO_FORMAT_ARGB32)
+ return false;
+
+ unsigned int srcUnpackAlignment = 1;
+ size_t bytesPerRow = cairo_image_surface_get_stride(imageSurface.get());
+ size_t bitsPerPixel = 32;
+ unsigned int padding = bytesPerRow - bitsPerPixel / 8 * width;
+ if (padding) {
+ srcUnpackAlignment = padding + 1;
+ while (bytesPerRow % srcUnpackAlignment)
+ ++srcUnpackAlignment;
+ }
+
+ outputVector.resize(width * height * 4);
+ return packPixels(cairo_image_surface_get_data(imageSurface.get()), SourceFormatBGRA8,
+ width, height, srcUnpackAlignment, format, type, alphaOp, outputVector.data());
+}
+
+void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, PlatformContextCairo* context)
+{
+ if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0 || !context)
+ return;
+
+ cairo_t *cr = context->cr();
+ context->save();
+
+ cairo_rectangle(cr, 0, 0, canvasWidth, canvasHeight);
+ cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint(cr);
+
+ RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(
+ const_cast<unsigned char*>(imagePixels), CAIRO_FORMAT_ARGB32, imageWidth, imageHeight, imageWidth * 4));
+
+ // 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);
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_surface(cr, imageSurface.get(), 0, 0);
+ cairo_rectangle(cr, 0, 0, canvasWidth, -canvasHeight);
+
+ cairo_fill(cr);
+ context->restore();
+}
+
+void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL)
diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
index 0fc94df..4cd0844 100644
--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
@@ -32,10 +32,9 @@
#include "config.h"
#include "GraphicsContext.h"
-#if PLATFORM(CAIRO)
+#if USE(CAIRO)
#include "AffineTransform.h"
-#include "CairoPath.h"
#include "CairoUtilities.h"
#include "ContextShadow.h"
#include "FloatConversion.h"
@@ -48,6 +47,7 @@
#include "Path.h"
#include "Pattern.h"
#include "PlatformContextCairo.h"
+#include "PlatformPathCairo.h"
#include "RefPtrCairo.h"
#include "SimpleFontData.h"
#include <cairo.h>
@@ -201,8 +201,9 @@ static void strokeCurrentCairoPath(GraphicsContext* context, cairo_t* cairoCont
}
GraphicsContext::GraphicsContext(cairo_t* cr)
+ : m_updatingControlTints(false)
{
- m_data = new GraphicsContextPlatformPrivate(new PlatformContextCairo(cr));
+ m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
}
void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
@@ -234,24 +235,13 @@ PlatformContextCairo* GraphicsContext::platformContext() const
void GraphicsContext::savePlatformState()
{
- cairo_save(platformContext()->cr());
+ platformContext()->save();
m_data->save();
m_data->shadowStack.append(m_data->shadow);
- m_data->maskImageStack.append(ImageMaskInformation());
}
void GraphicsContext::restorePlatformState()
{
- cairo_t* cr = platformContext()->cr();
-
- const ImageMaskInformation& maskInformation = m_data->maskImageStack.last();
- if (maskInformation.isValid()) {
- const FloatRect& maskRect = maskInformation.maskRect();
- cairo_pop_group_to_source(cr);
- cairo_mask_surface(cr, maskInformation.maskSurface(), maskRect.x(), maskRect.y());
- }
- m_data->maskImageStack.removeLast();
-
if (m_data->shadowStack.isEmpty())
m_data->shadow = ContextShadow();
else {
@@ -259,7 +249,7 @@ void GraphicsContext::restorePlatformState()
m_data->shadowStack.removeLast();
}
- cairo_restore(cr);
+ platformContext()->restore();
m_data->restore();
}
@@ -765,7 +755,7 @@ void GraphicsContext::drawLineForTextChecking(const FloatPoint& origin, float wi
cairo_restore(cr);
}
-FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect)
+FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)
{
FloatRect result;
double x = frect.x();
@@ -1190,33 +1180,6 @@ InterpolationQuality GraphicsContext::imageInterpolationQuality() const
return InterpolationDefault;
}
-void GraphicsContext::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)
-{
- // We must call savePlatformState at least once before we can use image masking,
- // since we actually apply the mask in restorePlatformState.
- ASSERT(!m_data->maskImageStack.isEmpty());
- m_data->maskImageStack.last().update(surface, rect);
-
- // Cairo doesn't support the notion of an image clip, so we push a group here
- // and then paint it to the surface with an image mask (which is an immediate
- // operation) during restorePlatformState.
-
- // We want to allow the clipped elements to composite with the surface as it
- // is now, but they are isolated in another group. To make this work, we're
- // going to blit the current surface contents onto the new group once we push it.
- cairo_t* cr = platformContext()->cr();
- cairo_surface_t* currentTarget = cairo_get_target(cr);
- cairo_surface_flush(currentTarget);
-
- // Pushing a new group ensures that only things painted after this point are clipped.
- cairo_push_group(cr);
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
-
- cairo_set_source_surface(cr, currentTarget, 0, 0);
- cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
- cairo_fill(cr);
-}
-
} // namespace WebCore
-#endif // PLATFORM(CAIRO)
+#endif // USE(CAIRO)
diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h b/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
index 2bc290b..8fd056d 100644
--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
@@ -47,25 +47,6 @@ typedef struct _GdkExposeEvent GdkExposeEvent;
namespace WebCore {
-// In Cairo image masking is immediate, so to emulate image clipping we must save masking
-// details as part of the context state and apply it during platform restore.
-class ImageMaskInformation {
-public:
- void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)
- {
- m_maskSurface = maskSurface;
- m_maskRect = maskRect;
- }
-
- bool isValid() const { return m_maskSurface; }
- cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }
- const FloatRect& maskRect() const { return m_maskRect; }
-
-private:
- RefPtr<cairo_surface_t> m_maskSurface;
- FloatRect m_maskRect;
-};
-
class GraphicsContextPlatformPrivate {
public:
GraphicsContextPlatformPrivate(PlatformContextCairo* newPlatformContext)
@@ -81,7 +62,7 @@ public:
{
}
- ~GraphicsContextPlatformPrivate()
+ virtual ~GraphicsContextPlatformPrivate()
{
}
@@ -121,7 +102,6 @@ public:
Vector<float> layers;
ContextShadow shadow;
Vector<ContextShadow> shadowStack;
- Vector<ImageMaskInformation> maskImageStack;
#if PLATFORM(GTK)
GdkEventExpose* expose;
@@ -142,7 +122,7 @@ public:
{
}
- ~GraphicsContextPlatformPrivateToplevel()
+ virtual ~GraphicsContextPlatformPrivateToplevel()
{
delete platformContext;
}
diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index 1d5d492..8aa6531 100644
--- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -55,11 +55,10 @@ static inline cairo_surface_t* copySurface(cairo_surface_t* surface)
int height = cairo_image_surface_get_height(surface);
cairo_surface_t* newsurface = cairo_image_surface_create(format, width, height);
- cairo_t* cr = cairo_create(newsurface);
- cairo_set_source_surface(cr, surface, 0, 0);
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint(cr);
- cairo_destroy(cr);
+ RefPtr<cairo_t> cr = adoptRef(cairo_create(newsurface));
+ cairo_set_source_surface(cr.get(), surface, 0, 0);
+ cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE);
+ cairo_paint(cr.get());
return newsurface;
}
@@ -117,7 +116,7 @@ PassRefPtr<Image> ImageBuffer::copyImage() const
void ImageBuffer::clip(GraphicsContext* context, const FloatRect& maskRect) const
{
- context->pushImageMask(m_data.m_surface, maskRect);
+ context->platformContext()->pushImageMask(m_data.m_surface, maskRect);
}
void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferData.h b/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h
index 42867d1..5ca7262 100644
--- a/Source/WebCore/platform/graphics/cairo/ImageBufferData.h
+++ b/Source/WebCore/platform/graphics/cairo/ImageBufferDataCairo.h
@@ -23,9 +23,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ImageBufferData_h
-#define ImageBufferData_h
-
#include "PlatformContextCairo.h"
typedef struct _cairo_surface cairo_surface_t;
@@ -42,6 +39,4 @@ public:
PlatformContextCairo m_platformContext;
};
-} // namespace WebCore
-
-#endif // ImageBufferData_h
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp
index d3a52ce..ce7d8b2 100644
--- a/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp
@@ -28,7 +28,7 @@
#include "config.h"
#include "BitmapImage.h"
-#if PLATFORM(CAIRO)
+#if USE(CAIRO)
#include "AffineTransform.h"
#include "CairoUtilities.h"
@@ -205,4 +205,4 @@ void BitmapImage::checkForSolidColor()
}
-#endif // PLATFORM(CAIRO)
+#endif // USE(CAIRO)
diff --git a/Source/WebCore/platform/graphics/cairo/OpenGLShims.cpp b/Source/WebCore/platform/graphics/cairo/OpenGLShims.cpp
new file mode 100644
index 0000000..92d79f9
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cairo/OpenGLShims.cpp
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#if ENABLE(WEBGL)
+
+#define DISABLE_SHIMS
+#include "OpenGLShims.h"
+
+#include <dlfcn.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+#define ASSIGN_FUNCTION_TABLE_ENTRY(FunctionName, success) \
+ openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(lookupOpenGLFunctionAddress(#FunctionName, success))
+
+namespace WebCore {
+
+typedef void* (*glGetProcAddressType) (const char* procName);
+static void* getProcAddress(const char* procName)
+{
+ static bool initialized = false;
+ static glGetProcAddressType getProcAddressFunction = 0;
+
+ if (!initialized) {
+ getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsym(RTLD_DEFAULT, "glXGetProcAddress"));
+ if (!getProcAddressFunction)
+ getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsym(RTLD_DEFAULT, "glXGetProcAddressARB"));
+ }
+
+ if (!getProcAddressFunction)
+ return dlsym(RTLD_DEFAULT, procName);
+ return getProcAddressFunction(procName);
+}
+
+static void* lookupOpenGLFunctionAddress(const char* functionName, bool& success)
+{
+ if (!success)
+ return 0;
+
+ void* target = getProcAddress(functionName);
+ if (target)
+ return target;
+
+ String fullFunctionName(functionName);
+ fullFunctionName.append("ARB");
+ target = getProcAddress(fullFunctionName.utf8().data());
+ if (target)
+ return target;
+
+ fullFunctionName = functionName;
+ fullFunctionName.append("EXT");
+ target = getProcAddress(fullFunctionName.utf8().data());
+
+ // A null address is still a failure case.
+ if (!target)
+ success = false;
+
+ return target;
+}
+
+OpenGLFunctionTable* openGLFunctionTable()
+{
+ static OpenGLFunctionTable table;
+ return &table;
+}
+
+bool initializeOpenGLShims()
+{
+ static bool success = true;
+ static bool initialized = false;
+ if (initialized)
+ return success;
+
+ initialized = true;
+ ASSIGN_FUNCTION_TABLE_ENTRY(glActiveTexture, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glAttachShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBindAttribLocation, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBindBuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBindFramebuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBindRenderbuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBlendColor, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBlendEquation, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBlendEquationSeparate, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBlendFuncSeparate, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBlitFramebuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBufferData, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glBufferSubData, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glCheckFramebufferStatus, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glCompileShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glCreateProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glCreateShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDeleteBuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDeleteFramebuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDeleteProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDeleteRenderbuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDeleteShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDetachShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glDisableVertexAttribArray, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferTexture2D, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGenBuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGenerateMipmap, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGenFramebuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGenRenderbuffers, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetActiveAttrib, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetActiveUniform, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetAttachedShaders, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetAttribLocation, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetBufferParameteriv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetFramebufferAttachmentParameteriv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetProgramInfoLog, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetProgramiv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetRenderbufferParameteriv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderInfoLog, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderiv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderSource, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetUniformfv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetUniformiv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetUniformLocation, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetVertexAttribfv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetVertexAttribiv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glGetVertexAttribPointerv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glIsBuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glIsFramebuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glIsProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glIsRenderbuffer, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glIsShader, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glLinkProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glRenderbufferStorage, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glRenderbufferStorageMultisample, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glSampleCoverage, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glShaderSource, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glStencilFuncSeparate, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glStencilMaskSeparate, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glStencilOpSeparate, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform1f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform1fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform1i, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform1iv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform2f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform2fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform2i, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform2iv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform3f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform3fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform3i, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform3iv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform4f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform4fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform4i, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniform4iv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniformMatrix2fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniformMatrix3fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUniformMatrix4fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glUseProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glValidateProgram, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib1f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib1fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib2f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib2fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib3f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib3fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib4f, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttrib4fv, success);
+ ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttribPointer, success);
+
+ if (!success)
+ LOG_ERROR("Could not initialize OpenGL shims");
+ return success;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGL)
diff --git a/Source/WebCore/platform/graphics/cairo/OpenGLShims.h b/Source/WebCore/platform/graphics/cairo/OpenGLShims.h
new file mode 100644
index 0000000..a431b03
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cairo/OpenGLShims.h
@@ -0,0 +1,315 @@
+/*
+ * Copyright (C) 2010 Tieto Corporation.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <GL/gl.h>
+
+typedef struct _OpenGLFunctionTable OpenGLFunctionTable;
+
+namespace WebCore {
+bool initializeOpenGLShims();
+OpenGLFunctionTable* openGLFunctionTable();
+}
+
+typedef void (*glActiveTextureType) (GLenum);
+typedef void (*glAttachShaderType) (GLuint, GLuint);
+typedef void (*glBindAttribLocationType) (GLuint, GLuint, const char*);
+typedef void (*glBindBufferType) (GLenum, GLuint);
+typedef void (*glBindFramebufferType) (GLenum, GLuint);
+typedef void (*glBindRenderbufferType) (GLenum, GLuint);
+typedef void (*glBlendColorType) (GLclampf, GLclampf, GLclampf, GLclampf);
+typedef void (*glBlendEquationType) (GLenum);
+typedef void (*glBlendEquationSeparateType)(GLenum, GLenum);
+typedef void (*glBlendFuncSeparateType)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (*glBlitFramebufferType) (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum);
+typedef void (*glBufferDataType) (GLenum, GLsizeiptr, const GLvoid*, GLenum);
+typedef void (*glBufferSubDataType) (GLenum, GLintptr, GLsizeiptr, const GLvoid*);
+typedef GLenum (*glCheckFramebufferStatusType) (GLenum);
+typedef void (*glCompileShaderType) (GLuint);
+typedef GLuint (*glCreateProgramType) ();
+typedef GLuint (*glCreateShaderType) (GLenum);
+typedef void (*glDeleteBuffersType) (GLsizei, const GLuint*);
+typedef void (*glDeleteFramebuffersType) (GLsizei n, const GLuint*);
+typedef void (*glDeleteProgramType) (GLuint);
+typedef void (*glDeleteRenderbuffersType) (GLsizei n, const GLuint*);
+typedef void (*glDeleteShaderType) (GLuint);
+typedef void (*glDetachShaderType) (GLuint, GLuint);
+typedef void (*glDisableVertexAttribArrayType) (GLuint);
+typedef void (*glEnableVertexAttribArrayType) (GLuint);
+typedef void (*glFramebufferRenderbufferType) (GLenum, GLenum, GLenum, GLuint);
+typedef void (*glFramebufferTexture2DType) (GLenum, GLenum, GLenum, GLuint, GLint);
+typedef void (*glGenBuffersType) (GLsizei, GLuint*);
+typedef void (*glGenerateMipmapType) (GLenum target);
+typedef void (*glGenFramebuffersType) (GLsizei, GLuint*);
+typedef void (*glGenRenderbuffersType) (GLsizei, GLuint*);
+typedef void (*glGetActiveAttribType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
+typedef void (*glGetActiveUniformType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
+typedef void (*glGetAttachedShadersType) (GLuint, GLsizei, GLsizei*, GLuint*);
+typedef GLint (*glGetAttribLocationType) (GLuint, const char*);
+typedef void (*glGetBufferParameterivType) (GLenum, GLenum, GLint*);
+typedef void (*glGetFramebufferAttachmentParameterivType) (GLenum, GLenum, GLenum, GLint* params);
+typedef void (*glGetProgramInfoLogType) (GLuint, GLsizei, GLsizei*, char*);
+typedef void (*glGetProgramivType) (GLuint, GLenum, GLint*);
+typedef void (*glGetRenderbufferParameterivType) (GLenum, GLenum, GLint*);
+typedef void (*glGetShaderInfoLogType) (GLuint, GLsizei, GLsizei*, char*);
+typedef void (*glGetShaderivType) (GLuint, GLenum, GLint*);
+typedef void (*glGetShaderSourceType) (GLuint, GLsizei, GLsizei*, char*);
+typedef GLint (*glGetUniformLocationType) (GLuint, const char*);
+typedef void (*glGetUniformfvType) (GLuint, GLint, GLfloat*);
+typedef void (*glGetUniformivType) (GLuint, GLint, GLint*);
+typedef void (*glGetVertexAttribfvType) (GLuint, GLenum, GLfloat*);
+typedef void (*glGetVertexAttribivType) (GLuint, GLenum, GLint*);
+typedef void (*glGetVertexAttribPointervType) (GLuint, GLenum, GLvoid**);
+typedef GLboolean (*glIsBufferType) (GLuint);
+typedef GLboolean (*glIsFramebufferType) (GLuint);
+typedef GLboolean (*glIsProgramType) (GLuint);
+typedef GLboolean (*glIsRenderbufferType) (GLuint);
+typedef GLboolean (*glIsShaderType) (GLuint);
+typedef void (*glLinkProgramType) (GLuint);
+typedef void (*glRenderbufferStorageType) (GLenum, GLenum, GLsizei, GLsizei);
+typedef void (*glRenderbufferStorageMultisampleType) (GLenum, GLsizei, GLenum, GLsizei, GLsizei);
+typedef void (*glSampleCoverageType) (GLclampf, GLboolean);
+typedef void (*glShaderSourceType) (GLuint, GLsizei, const char**, const GLint*);
+typedef void (*glStencilFuncSeparateType) (GLenum, GLenum, GLint, GLuint);
+typedef void (*glStencilMaskSeparateType) (GLenum, GLuint);
+typedef void (*glStencilOpSeparateType) (GLenum, GLenum, GLenum, GLenum);
+typedef void (*glUniform1fType) (GLint, GLfloat);
+typedef void (*glUniform1fvType) (GLint, GLsizei, const GLfloat*);
+typedef void (*glUniform1iType) (GLint, GLint);
+typedef void (*glUniform1ivType) (GLint, GLsizei, const GLint*);
+typedef void (*glUniform2fType) (GLint, GLfloat, GLfloat);
+typedef void (*glUniform2fvType) (GLint, GLsizei, const GLfloat*);
+typedef void (*glUniform2iType) (GLint, GLint, GLint);
+typedef void (*glUniform2ivType) (GLint, GLsizei, const GLint*);
+typedef void (*glUniform3fType) (GLint, GLfloat, GLfloat, GLfloat);
+typedef void (*glUniform3fvType) (GLint, GLsizei, const GLfloat*);
+typedef void (*glUniform3iType) (GLint, GLint, GLint, GLint);
+typedef void (*glUniform3ivType) (GLint, GLsizei, const GLint*);
+typedef void (*glUniform4fType) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
+typedef void (*glUniform4fvType) (GLint, GLsizei, const GLfloat*);
+typedef void (*glUniform4iType) (GLint, GLint, GLint, GLint, GLint);
+typedef void (*glUniform4ivType) (GLint, GLsizei, const GLint*);
+typedef void (*glUniformMatrix2fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
+typedef void (*glUniformMatrix3fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
+typedef void (*glUniformMatrix4fvType) (GLint, GLsizei, GLboolean, const GLfloat*);
+typedef void (*glUseProgramType) (GLuint);
+typedef void (*glValidateProgramType) (GLuint);
+typedef void (*glVertexAttrib1fType) (GLuint, const GLfloat);
+typedef void (*glVertexAttrib1fvType) (GLuint, const GLfloat*);
+typedef void (*glVertexAttrib2fType) (GLuint, const GLfloat, const GLfloat);
+typedef void (*glVertexAttrib2fvType) (GLuint, const GLfloat*);
+typedef void (*glVertexAttrib3fType) (GLuint, const GLfloat, const GLfloat, const GLfloat);
+typedef void (*glVertexAttrib3fvType) (GLuint, const GLfloat*);
+typedef void (*glVertexAttrib4fType) (GLuint, const GLfloat, const GLfloat, const GLfloat, const GLfloat);
+typedef void (*glVertexAttrib4fvType) (GLuint, const GLfloat*);
+typedef void (*glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*);
+
+#define FUNCTION_TABLE_ENTRY(FunctionName) FunctionName##Type FunctionName
+
+typedef struct _OpenGLFunctionTable {
+ FUNCTION_TABLE_ENTRY(glActiveTexture);
+ FUNCTION_TABLE_ENTRY(glAttachShader);
+ FUNCTION_TABLE_ENTRY(glBindAttribLocation);
+ FUNCTION_TABLE_ENTRY(glBindBuffer);
+ FUNCTION_TABLE_ENTRY(glBindFramebuffer);
+ FUNCTION_TABLE_ENTRY(glBindRenderbuffer);
+ FUNCTION_TABLE_ENTRY(glBlendColor);
+ FUNCTION_TABLE_ENTRY(glBlendEquation);
+ FUNCTION_TABLE_ENTRY(glBlendEquationSeparate);
+ FUNCTION_TABLE_ENTRY(glBlendFuncSeparate);
+ FUNCTION_TABLE_ENTRY(glBlitFramebuffer);
+ FUNCTION_TABLE_ENTRY(glBufferData);
+ FUNCTION_TABLE_ENTRY(glBufferSubData);
+ FUNCTION_TABLE_ENTRY(glCheckFramebufferStatus);
+ FUNCTION_TABLE_ENTRY(glCompileShader);
+ FUNCTION_TABLE_ENTRY(glCreateProgram);
+ FUNCTION_TABLE_ENTRY(glCreateShader);
+ FUNCTION_TABLE_ENTRY(glDeleteBuffers);
+ FUNCTION_TABLE_ENTRY(glDeleteFramebuffers);
+ FUNCTION_TABLE_ENTRY(glDeleteProgram);
+ FUNCTION_TABLE_ENTRY(glDeleteRenderbuffers);
+ FUNCTION_TABLE_ENTRY(glDeleteShader);
+ FUNCTION_TABLE_ENTRY(glDetachShader);
+ FUNCTION_TABLE_ENTRY(glDisableVertexAttribArray);
+ FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray);
+ FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer);
+ FUNCTION_TABLE_ENTRY(glFramebufferTexture2D);
+ FUNCTION_TABLE_ENTRY(glGenBuffers);
+ FUNCTION_TABLE_ENTRY(glGenerateMipmap);
+ FUNCTION_TABLE_ENTRY(glGenFramebuffers);
+ FUNCTION_TABLE_ENTRY(glGenRenderbuffers);
+ FUNCTION_TABLE_ENTRY(glGetActiveAttrib);
+ FUNCTION_TABLE_ENTRY(glGetActiveUniform);
+ FUNCTION_TABLE_ENTRY(glGetAttachedShaders);
+ FUNCTION_TABLE_ENTRY(glGetAttribLocation);
+ FUNCTION_TABLE_ENTRY(glGetBufferParameteriv);
+ FUNCTION_TABLE_ENTRY(glGetFramebufferAttachmentParameteriv);
+ FUNCTION_TABLE_ENTRY(glGetProgramInfoLog);
+ FUNCTION_TABLE_ENTRY(glGetProgramiv);
+ FUNCTION_TABLE_ENTRY(glGetRenderbufferParameteriv);
+ FUNCTION_TABLE_ENTRY(glGetShaderInfoLog);
+ FUNCTION_TABLE_ENTRY(glGetShaderiv);
+ FUNCTION_TABLE_ENTRY(glGetShaderSource);
+ FUNCTION_TABLE_ENTRY(glGetUniformfv);
+ FUNCTION_TABLE_ENTRY(glGetUniformiv);
+ FUNCTION_TABLE_ENTRY(glGetUniformLocation);
+ FUNCTION_TABLE_ENTRY(glGetVertexAttribfv);
+ FUNCTION_TABLE_ENTRY(glGetVertexAttribiv);
+ FUNCTION_TABLE_ENTRY(glGetVertexAttribPointerv);
+ FUNCTION_TABLE_ENTRY(glIsBuffer);
+ FUNCTION_TABLE_ENTRY(glIsFramebuffer);
+ FUNCTION_TABLE_ENTRY(glIsProgram);
+ FUNCTION_TABLE_ENTRY(glIsRenderbuffer);
+ FUNCTION_TABLE_ENTRY(glIsShader);
+ FUNCTION_TABLE_ENTRY(glLinkProgram);
+ FUNCTION_TABLE_ENTRY(glRenderbufferStorage);
+ FUNCTION_TABLE_ENTRY(glRenderbufferStorageMultisample);
+ FUNCTION_TABLE_ENTRY(glSampleCoverage);
+ FUNCTION_TABLE_ENTRY(glShaderSource);
+ FUNCTION_TABLE_ENTRY(glStencilFuncSeparate);
+ FUNCTION_TABLE_ENTRY(glStencilMaskSeparate);
+ FUNCTION_TABLE_ENTRY(glStencilOpSeparate);
+ FUNCTION_TABLE_ENTRY(glUniform1f);
+ FUNCTION_TABLE_ENTRY(glUniform1fv);
+ FUNCTION_TABLE_ENTRY(glUniform1i);
+ FUNCTION_TABLE_ENTRY(glUniform1iv);
+ FUNCTION_TABLE_ENTRY(glUniform2f);
+ FUNCTION_TABLE_ENTRY(glUniform2fv);
+ FUNCTION_TABLE_ENTRY(glUniform2i);
+ FUNCTION_TABLE_ENTRY(glUniform2iv);
+ FUNCTION_TABLE_ENTRY(glUniform3f);
+ FUNCTION_TABLE_ENTRY(glUniform3fv);
+ FUNCTION_TABLE_ENTRY(glUniform3i);
+ FUNCTION_TABLE_ENTRY(glUniform3iv);
+ FUNCTION_TABLE_ENTRY(glUniform4f);
+ FUNCTION_TABLE_ENTRY(glUniform4fv);
+ FUNCTION_TABLE_ENTRY(glUniform4i);
+ FUNCTION_TABLE_ENTRY(glUniform4iv);
+ FUNCTION_TABLE_ENTRY(glUniformMatrix2fv);
+ FUNCTION_TABLE_ENTRY(glUniformMatrix3fv);
+ FUNCTION_TABLE_ENTRY(glUniformMatrix4fv);
+ FUNCTION_TABLE_ENTRY(glUseProgram);
+ FUNCTION_TABLE_ENTRY(glValidateProgram);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib1f);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib1fv);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib2f);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib2fv);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib3f);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib3fv);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib4f);
+ FUNCTION_TABLE_ENTRY(glVertexAttrib4fv);
+ FUNCTION_TABLE_ENTRY(glVertexAttribPointer);
+} OpenGLFunctionTable;
+
+// We disable the shims for OpenGLShims.cpp, so that we can set them.
+#ifndef DISABLE_SHIMS
+#define LOOKUP_GL_FUNCTION(Function) WebCore::openGLFunctionTable()->Function
+#define glActiveTexture LOOKUP_GL_FUNCTION(glActiveTexture)
+#define glAttachShader LOOKUP_GL_FUNCTION(glAttachShader)
+#define glBindAttribLocation LOOKUP_GL_FUNCTION(glBindAttribLocation)
+#define glBindBuffer LOOKUP_GL_FUNCTION(glBindBuffer)
+#define glBindFramebufferEXT LOOKUP_GL_FUNCTION(glBindFramebuffer)
+#define glBindRenderbufferEXT LOOKUP_GL_FUNCTION(glBindRenderbuffer)
+#define glBlendColor LOOKUP_GL_FUNCTION(glBlendColor)
+#define glBlendEquation LOOKUP_GL_FUNCTION(glBlendEquation)
+#define glBlendEquationSeparate LOOKUP_GL_FUNCTION(glBlendEquationSeparate)
+#define glBlendFuncSeparate LOOKUP_GL_FUNCTION(glBlendFuncSeparate)
+#define glBlitFramebufferEXT LOOKUP_GL_FUNCTION(glBlitFramebuffer)
+#define glBufferData LOOKUP_GL_FUNCTION(glBufferData)
+#define glBufferSubData LOOKUP_GL_FUNCTION(glBufferSubData)
+#define glCheckFramebufferStatusEXT LOOKUP_GL_FUNCTION(glCheckFramebufferStatus)
+#define glCompileShader LOOKUP_GL_FUNCTION(glCompileShader)
+#define glCreateProgram LOOKUP_GL_FUNCTION(glCreateProgram)
+#define glCreateShader LOOKUP_GL_FUNCTION(glCreateShader)
+#define glDeleteBuffers LOOKUP_GL_FUNCTION(glDeleteBuffers)
+#define glDeleteFramebuffersEXT LOOKUP_GL_FUNCTION(glDeleteFramebuffers)
+#define glDeleteProgram LOOKUP_GL_FUNCTION(glDeleteProgram)
+#define glDeleteRenderbuffersEXT LOOKUP_GL_FUNCTION(glDeleteRenderbuffers)
+#define glDeleteShader LOOKUP_GL_FUNCTION(glDeleteShader)
+#define glDetachShader LOOKUP_GL_FUNCTION(glDetachShader)
+#define glDisableVertexAttribArray LOOKUP_GL_FUNCTION(glDisableVertexAttribArray)
+#define glEnableVertexAttribArray LOOKUP_GL_FUNCTION(glEnableVertexAttribArray)
+#define glFramebufferRenderbufferEXT LOOKUP_GL_FUNCTION(glFramebufferRenderbuffer)
+#define glFramebufferTexture2DEXT LOOKUP_GL_FUNCTION(glFramebufferTexture2D)
+#define glGenBuffers LOOKUP_GL_FUNCTION(glGenBuffers)
+#define glGenerateMipmapEXT LOOKUP_GL_FUNCTION(glGenerateMipmap)
+#define glGenFramebuffersEXT LOOKUP_GL_FUNCTION(glGenFramebuffers)
+#define glGenRenderbuffersEXT LOOKUP_GL_FUNCTION(glGenRenderbuffers)
+#define glGetActiveAttrib LOOKUP_GL_FUNCTION(glGetActiveAttrib)
+#define glGetActiveUniform LOOKUP_GL_FUNCTION(glGetActiveUniform)
+#define glGetAttachedShaders LOOKUP_GL_FUNCTION(glGetAttachedShaders)
+#define glGetAttribLocation LOOKUP_GL_FUNCTION(glGetAttribLocation)
+#define glGetBufferParameteriv LOOKUP_GL_FUNCTION(glGetBufferParameteriv)
+#define glGetBufferParameterivEXT LOOKUP_GL_FUNCTION(glGetBufferParameteriv)
+#define glGetFramebufferAttachmentParameterivEXT LOOKUP_GL_FUNCTION(glGetFramebufferAttachmentParameteriv)
+#define glGetProgramInfoLog LOOKUP_GL_FUNCTION(glGetProgramInfoLog)
+#define glGetProgramiv LOOKUP_GL_FUNCTION(glGetProgramiv)
+#define glGetRenderbufferParameterivEXT LOOKUP_GL_FUNCTION(glGetRenderbufferParameteriv)
+#define glGetShaderInfoLog LOOKUP_GL_FUNCTION(glGetShaderInfoLog)
+#define glGetShaderiv LOOKUP_GL_FUNCTION(glGetShaderiv)
+#define glGetShaderSource LOOKUP_GL_FUNCTION(glGetShaderSource)
+#define glGetUniformfv LOOKUP_GL_FUNCTION(glGetUniformfv)
+#define glGetUniformiv LOOKUP_GL_FUNCTION(glGetUniformiv)
+#define glGetUniformLocation LOOKUP_GL_FUNCTION(glGetUniformLocation)
+#define glGetVertexAttribfv LOOKUP_GL_FUNCTION(glGetVertexAttribfv)
+#define glGetVertexAttribiv LOOKUP_GL_FUNCTION(glGetVertexAttribiv)
+#define glGetVertexAttribPointerv LOOKUP_GL_FUNCTION(glGetVertexAttribPointerv)
+#define glIsBuffer LOOKUP_GL_FUNCTION(glIsBuffer)
+#define glIsFramebufferEXT LOOKUP_GL_FUNCTION(glIsFramebuffer)
+#define glIsProgram LOOKUP_GL_FUNCTION(glIsProgram)
+#define glIsRenderbufferEXT LOOKUP_GL_FUNCTION(glIsRenderbuffer)
+#define glIsShader LOOKUP_GL_FUNCTION(glIsShader)
+#define glLinkProgram LOOKUP_GL_FUNCTION(glLinkProgram)
+#define glRenderbufferStorageEXT LOOKUP_GL_FUNCTION(glRenderbufferStorage)
+#define glRenderbufferStorageMultisampleEXT LOOKUP_GL_FUNCTION(glRenderbufferStorageMultisample)
+#define glSampleCoverage LOOKUP_GL_FUNCTION(glSampleCoverage)
+#define glShaderSource LOOKUP_GL_FUNCTION(glShaderSource)
+#define glStencilFuncSeparate LOOKUP_GL_FUNCTION(glStencilFuncSeparate)
+#define glStencilMaskSeparate LOOKUP_GL_FUNCTION(glStencilMaskSeparate)
+#define glStencilOpSeparate LOOKUP_GL_FUNCTION(glStencilOpSeparate)
+#define glUniform1f LOOKUP_GL_FUNCTION(glUniform1f)
+#define glUniform1fv LOOKUP_GL_FUNCTION(glUniform1fv)
+#define glUniform1i LOOKUP_GL_FUNCTION(glUniform1i)
+#define glUniform1iv LOOKUP_GL_FUNCTION(glUniform1iv)
+#define glUniform2f LOOKUP_GL_FUNCTION(glUniform2f)
+#define glUniform2fv LOOKUP_GL_FUNCTION(glUniform2fv)
+#define glUniform2i LOOKUP_GL_FUNCTION(glUniform2i)
+#define glUniform2iv LOOKUP_GL_FUNCTION(glUniform2iv)
+#define glUniform3f LOOKUP_GL_FUNCTION(glUniform3f)
+#define glUniform3fv LOOKUP_GL_FUNCTION(glUniform3fv)
+#define glUniform3i LOOKUP_GL_FUNCTION(glUniform3i)
+#define glUniform3iv LOOKUP_GL_FUNCTION(glUniform3iv)
+#define glUniform4f LOOKUP_GL_FUNCTION(glUniform4f)
+#define glUniform4fv LOOKUP_GL_FUNCTION(glUniform4fv)
+#define glUniform4i LOOKUP_GL_FUNCTION(glUniform4i)
+#define glUniform4iv LOOKUP_GL_FUNCTION(glUniform4iv)
+#define glUniformMatrix2fv LOOKUP_GL_FUNCTION(glUniformMatrix2fv)
+#define glUniformMatrix3fv LOOKUP_GL_FUNCTION(glUniformMatrix3fv)
+#define glUniformMatrix4fv LOOKUP_GL_FUNCTION(glUniformMatrix4fv)
+#define glUseProgram LOOKUP_GL_FUNCTION(glUseProgram)
+#define glValidateProgram LOOKUP_GL_FUNCTION(glValidateProgram)
+#define glVertexAttrib1f LOOKUP_GL_FUNCTION(glVertexAttrib1f)
+#define glVertexAttrib1fv LOOKUP_GL_FUNCTION(glVertexAttrib1fv)
+#define glVertexAttrib2f LOOKUP_GL_FUNCTION(glVertexAttrib2f)
+#define glVertexAttrib2fv LOOKUP_GL_FUNCTION(glVertexAttrib2fv)
+#define glVertexAttrib3f LOOKUP_GL_FUNCTION(glVertexAttrib3f)
+#define glVertexAttrib3fv LOOKUP_GL_FUNCTION(glVertexAttrib3fv)
+#define glVertexAttrib4f LOOKUP_GL_FUNCTION(glVertexAttrib4f)
+#define glVertexAttrib4fv LOOKUP_GL_FUNCTION(glVertexAttrib4fv)
+#define glVertexAttribPointer LOOKUP_GL_FUNCTION(glVertexAttribPointer)
+#endif
diff --git a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp b/Source/WebCore/platform/graphics/cairo/PathCairo.cpp
index 533df10..d62c33f 100644
--- a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/PathCairo.cpp
@@ -27,10 +27,10 @@
#include "Path.h"
#include "AffineTransform.h"
-#include "CairoPath.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "OwnPtrCairo.h"
+#include "PlatformPathCairo.h"
#include "PlatformString.h"
#include "StrokeStyleApplier.h"
#include <cairo.h>
diff --git a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
index ba75162..061ee06 100644
--- a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
@@ -35,4 +35,51 @@ PlatformContextCairo::PlatformContextCairo(cairo_t* cr)
{
}
+void PlatformContextCairo::restore()
+{
+ const ImageMaskInformation& maskInformation = m_maskImageStack.last();
+ if (maskInformation.isValid()) {
+ const FloatRect& maskRect = maskInformation.maskRect();
+ cairo_pop_group_to_source(m_cr.get());
+ cairo_mask_surface(m_cr.get(), maskInformation.maskSurface(), maskRect.x(), maskRect.y());
+ }
+ m_maskImageStack.removeLast();
+
+ cairo_restore(m_cr.get());
+}
+
+void PlatformContextCairo::save()
+{
+ m_maskImageStack.append(ImageMaskInformation());
+
+ cairo_save(m_cr.get());
+}
+
+void PlatformContextCairo::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)
+{
+ // We must call savePlatformState at least once before we can use image masking,
+ // since we actually apply the mask in restorePlatformState.
+ ASSERT(!m_maskImageStack.isEmpty());
+ m_maskImageStack.last().update(surface, rect);
+
+ // Cairo doesn't support the notion of an image clip, so we push a group here
+ // and then paint it to the surface with an image mask (which is an immediate
+ // operation) during restorePlatformState.
+
+ // We want to allow the clipped elements to composite with the surface as it
+ // is now, but they are isolated in another group. To make this work, we're
+ // going to blit the current surface contents onto the new group once we push it.
+ cairo_surface_t* currentTarget = cairo_get_target(m_cr.get());
+ cairo_surface_flush(currentTarget);
+
+ // Pushing a new group ensures that only things painted after this point are clipped.
+ cairo_push_group(m_cr.get());
+ cairo_set_operator(m_cr.get(), CAIRO_OPERATOR_SOURCE);
+
+ cairo_set_source_surface(m_cr.get(), currentTarget, 0, 0);
+ cairo_rectangle(m_cr.get(), rect.x(), rect.y(), rect.width(), rect.height());
+ cairo_fill(m_cr.get());
+}
+
+
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
index c6cceda..937417a 100644
--- a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
+++ b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
@@ -31,6 +31,25 @@
namespace WebCore {
+// In Cairo image masking is immediate, so to emulate image clipping we must save masking
+// details as part of the context state and apply them during platform restore.
+class ImageMaskInformation {
+public:
+ void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)
+ {
+ m_maskSurface = maskSurface;
+ m_maskRect = maskRect;
+ }
+
+ bool isValid() const { return m_maskSurface; }
+ cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }
+ const FloatRect& maskRect() const { return m_maskRect; }
+
+private:
+ RefPtr<cairo_surface_t> m_maskSurface;
+ FloatRect m_maskRect;
+};
+
// Much like PlatformContextSkia in the Skia port, this class holds information that
// would normally be private to GraphicsContext, except that we want to allow access
// to it in Font and Image code. This allows us to separate the concerns of Cairo-specific
@@ -40,11 +59,17 @@ class PlatformContextCairo {
WTF_MAKE_NONCOPYABLE(PlatformContextCairo);
public:
PlatformContextCairo(cairo_t*);
+
cairo_t* cr() { return m_cr.get(); }
void setCr(cairo_t* cr) { m_cr = cr; }
+ void save();
+ void restore();
+ void pushImageMask(cairo_surface_t*, const FloatRect&);
+
private:
RefPtr<cairo_t> m_cr;
+ Vector<ImageMaskInformation> m_maskImageStack;
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp b/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp
new file mode 100644
index 0000000..3a7d512
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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 "PlatformPathCairo.h"
+
+#include <cairo.h>
+
+namespace WebCore {
+
+static cairo_surface_t* getPathSurface()
+{
+ return cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
+}
+
+static cairo_surface_t* gPathSurface = getPathSurface();
+
+CairoPath::CairoPath()
+ : m_cr(adoptRef(cairo_create(gPathSurface)))
+{
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h b/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h
new file mode 100644
index 0000000..938b942
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cairo/PlatformPathCairo.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * 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.
+ */
+
+#ifndef PlatformPathCairo_h
+#define PlatformPathCairo_h
+
+#include "RefPtrCairo.h"
+
+namespace WebCore {
+
+// This is necessary since cairo_path_fixed_t isn't exposed in Cairo's public API.
+class CairoPath {
+public:
+ CairoPath();
+
+ ~CairoPath() {}
+
+ cairo_t* context() { return m_cr.get(); }
+
+private:
+ RefPtr<cairo_t> m_cr;
+};
+
+} // namespace WebCore
+
+#endif // PlatformPathCairo_h
diff --git a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp
index 1792002..90bc3b1 100644
--- a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp
@@ -61,7 +61,7 @@ template<> void refIfNotNull(cairo_font_face_t* ptr)
template<> void derefIfNotNull(cairo_font_face_t* ptr)
{
if (LIKELY(ptr != 0))
- cairo_font_face_reference(ptr);
+ cairo_font_face_destroy(ptr);
}
template<> void refIfNotNull(cairo_scaled_font_t* ptr)