Modified: trunk/Source/WebCore/ChangeLog (107812 => 107813)
--- trunk/Source/WebCore/ChangeLog 2012-02-15 15:13:58 UTC (rev 107812)
+++ trunk/Source/WebCore/ChangeLog 2012-02-15 15:26:28 UTC (rev 107813)
@@ -1,3 +1,25 @@
+2012-02-15 Simon Hausmann <[email protected]>
+
+ [Qt] Clean up fallback rendering of GraphicsContext3D to Canvas
+ https://bugs.webkit.org/show_bug.cgi?id=78690
+
+ Reviewed by Noam Rosenthal.
+
+ Use the common paintRenderingResultsToCanvas code to retrieve the
+ pixels from the FBO and use a Qt port specific paintToCanvas
+ implementation to wrap the pixels into a QImage and render it
+ into the graphics context, just like it's done for the other ports.
+
+ This removes the QGraphicsObject based paint, which is an now
+ obsolete method of rendering.
+
+ * platform/graphics/GraphicsContext3D.h:
+ * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+ (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
+ * platform/graphics/qt/GraphicsContext3DQt.cpp:
+ (GraphicsContext3DPrivate):
+ (WebCore::GraphicsContext3D::paintToCanvas):
+
2012-02-14 Simon Hausmann <[email protected]>
[Qt] Eliminate first set of QtWidgets dependencies from WebCore
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (107812 => 107813)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2012-02-15 15:13:58 UTC (rev 107812)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2012-02-15 15:26:28 UTC (rev 107813)
@@ -789,6 +789,9 @@
#elif PLATFORM(GTK) || PLATFORM(EFL)
void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
int canvasWidth, int canvasHeight, PlatformContextCairo* context);
+#elif PLATFORM(QT)
+ void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
+ int canvasWidth, int canvasHeight, QPainter* context);
#endif
void markContextChanged();
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (107812 => 107813)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2012-02-15 15:13:58 UTC (rev 107812)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2012-02-15 15:26:28 UTC (rev 107813)
@@ -111,7 +111,6 @@
return false;
}
-#if !PLATFORM(QT)
void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*)
{
HTMLCanvasElement* canvas = context->canvas();
@@ -138,7 +137,6 @@
paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
canvas->width(), canvas->height(), imageBuffer->context()->platformContext());
}
-#endif
bool GraphicsContext3D::paintCompositedResultsToCanvas(CanvasRenderingContext*)
{
Modified: trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp (107812 => 107813)
--- trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp 2012-02-15 15:13:58 UTC (rev 107812)
+++ trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp 2012-02-15 15:26:28 UTC (rev 107813)
@@ -39,7 +39,6 @@
#include <QAbstractScrollArea>
#include <QGraphicsObject>
#include <QGLContext>
-#include <QStyleOptionGraphicsItem>
#include <wtf/UnusedParam.h>
#include <wtf/text/CString.h>
@@ -77,7 +76,6 @@
virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity, BitmapTexture* mask);
#endif
- void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
QRectF boundingRect() const;
void blitMultisampleFramebuffer() const;
void blitMultisampleFramebufferAndRestoreContext() const;
@@ -202,58 +200,6 @@
return QRectF(QPointF(0, 0), QSizeF(m_context->m_currentWidth, m_context->m_currentHeight));
}
-void GraphicsContext3DPrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
-{
- Q_UNUSED(widget);
-
- QRectF rect = option ? option->rect : boundingRect();
-
- makeCurrentIfNeeded();
- blitMultisampleFramebuffer();
-
- // Use direct texture mapping if WebGL canvas has a shared OpenGL context
- // with browsers OpenGL context.
- QGLWidget* viewportGLWidget = getViewportGLWidget();
- if (viewportGLWidget && viewportGLWidget == m_viewportGLWidget && viewportGLWidget == painter->device()) {
- viewportGLWidget->drawTexture(rect, m_context->m_texture);
- return;
- }
-
- // Alternatively read pixels to a memory buffer.
- QImage offscreenImage(rect.width(), rect.height(), QImage::Format_ARGB32);
- quint32* imagePixels = reinterpret_cast<quint32*>(offscreenImage.bits());
-
- glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_fbo);
- glReadPixels(/* x */ 0, /* y */ 0, rect.width(), rect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, imagePixels);
- glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_boundFBO);
-
- // OpenGL gives us ABGR on 32 bits, and with the origin at the bottom left
- // We need RGB32 or ARGB32_PM, with the origin at the top left.
- quint32* pixelsSrc = imagePixels;
- const int height = static_cast<int>(rect.height());
- const int width = static_cast<int>(rect.width());
- const int halfHeight = height / 2;
- for (int row = 0; row < halfHeight; ++row) {
- const int targetIdx = (height - 1 - row) * width;
- quint32* pixelsDst = imagePixels + targetIdx;
- for (int column = 0; column < width; ++column) {
- quint32 tempPixel = *pixelsSrc;
- *pixelsSrc = swapBgrToRgb(*pixelsDst);
- *pixelsDst = swapBgrToRgb(tempPixel);
- ++pixelsSrc;
- ++pixelsDst;
- }
- }
- if (static_cast<int>(height) % 2) {
- for (int column = 0; column < width; ++column) {
- *pixelsSrc = swapBgrToRgb(*pixelsSrc);
- ++pixelsSrc;
- }
- }
-
- painter->drawImage(/* x */ 0, /* y */ 0, offscreenImage);
-}
-
void GraphicsContext3DPrivate::blitMultisampleFramebuffer() const
{
if (!m_context->m_attrs.antialias)
@@ -448,13 +394,16 @@
return m_private->makeCurrentIfNeeded();
}
-void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*)
+void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
+ int canvasWidth, int canvasHeight, QPainter* context)
{
- makeContextCurrent();
- HTMLCanvasElement* canvas = context->canvas();
- ImageBuffer* imageBuffer = canvas->buffer();
- QPainter* painter = imageBuffer->context()->platformContext();
- m_private->paint(painter, 0, 0);
+ QImage image(imagePixels, imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
+ context->save();
+ context->translate(0, imageHeight);
+ context->scale(1, -1);
+ context->setCompositionMode(QPainter::CompositionMode_Source);
+ context->drawImage(QRect(0, 0, canvasWidth, -canvasHeight), image);
+ context->restore();
}
#if defined(QT_OPENGL_ES_2)