| Differences between
and this patch
- a/Source/WebCore/ChangeLog +27 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2011-03-16  Jarkko Sakkinen  <jarkko.j.sakkinen@gmail.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [Qt] WebGL content not shown when accelerated compositing is enabled
6
        https://bugs.webkit.org/show_bug.cgi?id=56339
7
8
        Removed all previously implemented WebGL code from GraphicsLayerQt
9
        because API has changed. GraphicsContext3D provides PlatformLayer
10
        that is added as a child of GraphicsLayer and is therefore painted
11
        through QGraphicsView pipeline.
12
13
        * platform/graphics/GraphicsContext3D.h:
14
        * platform/graphics/qt/GraphicsContext3DQt.cpp:
15
        (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
16
        (WebCore::GraphicsContext3DInternal::paint):
17
        (WebCore::GraphicsContext3DInternal::boundingRect):
18
        (WebCore::GraphicsContext3D::platformLayer):
19
        (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
20
        (WebCore::GraphicsContext3D::reshape):
21
        * platform/graphics/qt/GraphicsLayerQt.cpp:
22
        (WebCore::GraphicsLayerQtImpl::GraphicsLayerQtImpl):
23
        (WebCore::GraphicsLayerQtImpl::paint):
24
        (WebCore::GraphicsLayerQtImpl::flushChanges):
25
        (WebCore::GraphicsLayerQt::setContentsToCanvas):
26
        * platform/graphics/qt/GraphicsLayerQt.h:
27
1
2011-03-16  Andrey Adaikin  <aandrey@google.com>
28
2011-03-16  Andrey Adaikin  <aandrey@google.com>
2
29
3
        Reviewed by Yury Semikhatsky.
30
        Reviewed by Yury Semikhatsky.
- a/Source/WebCore/platform/graphics/GraphicsContext3D.h -2 / +1 lines
Lines 461-467 public: a/Source/WebCore/platform/graphics/GraphicsContext3D.h_sec1
461
    PlatformGraphicsContext3D platformGraphicsContext3D();
461
    PlatformGraphicsContext3D platformGraphicsContext3D();
462
    Platform3DObject platformTexture() const;
462
    Platform3DObject platformTexture() const;
463
#if USE(ACCELERATED_COMPOSITING)
463
#if USE(ACCELERATED_COMPOSITING)
464
    PlatformLayer* platformLayer() const { return 0; }
464
    PlatformLayer* platformLayer() const;
465
#endif
465
#endif
466
#else
466
#else
467
    PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
467
    PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; }
Lines 760-766 public: a/Source/WebCore/platform/graphics/GraphicsContext3D.h_sec2
760
    PassRefPtr<ImageData> paintRenderingResultsToImageData();
760
    PassRefPtr<ImageData> paintRenderingResultsToImageData();
761
761
762
#if PLATFORM(QT)
762
#if PLATFORM(QT)
763
    void paint(QPainter* painter, const QRect& rect) const;
764
    bool paintsIntoCanvasBuffer() const { return true; }
763
    bool paintsIntoCanvasBuffer() const { return true; }
765
#elif PLATFORM(CHROMIUM)
764
#elif PLATFORM(CHROMIUM)
766
    bool paintsIntoCanvasBuffer() const;
765
    bool paintsIntoCanvasBuffer() const;
- a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp -29 / +53 lines
Lines 27-36 a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec1
27
#include "HTMLCanvasElement.h"
27
#include "HTMLCanvasElement.h"
28
#include "HostWindow.h"
28
#include "HostWindow.h"
29
#include "ImageBuffer.h"
29
#include "ImageBuffer.h"
30
#include "ImageData.h"
30
#include "NotImplemented.h"
31
#include "NotImplemented.h"
31
#include "QWebPageClient.h"
32
#include "PageClientQt.h"
33
#include "qwebpage.h"
32
#include <QAbstractScrollArea>
34
#include <QAbstractScrollArea>
35
#include <QGraphicsObject>
33
#include <QGLContext>
36
#include <QGLContext>
37
#include <QStyleOptionGraphicsItem>
34
#include <wtf/UnusedParam.h>
38
#include <wtf/UnusedParam.h>
35
#include <wtf/text/CString.h>
39
#include <wtf/text/CString.h>
36
40
Lines 145-157 typedef void (APIENTRY* glVertexAttrib4fType) (GLuint, const GLfloat, const GLfl a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec2
145
typedef void (APIENTRY* glVertexAttrib4fvType) (GLuint, const GLfloat*);
149
typedef void (APIENTRY* glVertexAttrib4fvType) (GLuint, const GLfloat*);
146
typedef void (APIENTRY* glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*);
150
typedef void (APIENTRY* glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*);
147
151
148
class GraphicsContext3DInternal {
152
class GraphicsContext3DInternal : public QGraphicsObject {
149
public:
153
public:
150
    GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow);
154
    GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow);
151
    ~GraphicsContext3DInternal();
155
    ~GraphicsContext3DInternal();
152
156
153
    bool isContextValid() { return m_contextValid; }
157
    bool isContextValid() { return m_contextValid; }
154
    QGLWidget* getOwnerGLWidget(QWebPageClient* webPageClient);
158
    QGLWidget* getOwnerGLWidget(QWebPageClient* webPageClient);
159
    void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
160
    QRectF boundingRect() const;
155
161
156
    glActiveTextureType activeTexture;
162
    glActiveTextureType activeTexture;
157
    glAttachShaderType attachShader;
163
    glAttachShaderType attachShader;
Lines 247-252 public: a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec3
247
    GraphicsContext3D::Attributes m_attrs;
253
    GraphicsContext3D::Attributes m_attrs;
248
    HostWindow* m_hostWindow;
254
    HostWindow* m_hostWindow;
249
    QGLWidget* m_glWidget;
255
    QGLWidget* m_glWidget;
256
    QGLWidget* m_ownerGLWidget;
257
    QRectF m_boundingRect;
250
    GLuint m_texture;
258
    GLuint m_texture;
251
    GLuint m_mainFbo;
259
    GLuint m_mainFbo;
252
    GLuint m_currentFbo;
260
    GLuint m_currentFbo;
Lines 281-297 GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attribut a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec4
281
    : m_attrs(attrs)
289
    : m_attrs(attrs)
282
    , m_hostWindow(hostWindow)
290
    , m_hostWindow(hostWindow)
283
    , m_glWidget(0)
291
    , m_glWidget(0)
292
    , m_ownerGLWidget(0)
284
    , m_texture(0)
293
    , m_texture(0)
285
    , m_mainFbo(0)
294
    , m_mainFbo(0)
286
    , m_currentFbo(0)
295
    , m_currentFbo(0)
287
    , m_depthBuffer(0)
296
    , m_depthBuffer(0)
288
    , m_contextValid(true)
297
    , m_contextValid(true)
289
{
298
{
290
    QWebPageClient* webPageClient = hostWindow->platformPageClient();
299
    PageClientQWidget* webPageClient
291
    QGLWidget* ownerGLWidget  = getOwnerGLWidget(webPageClient);
300
        = static_cast<PageClientQWidget*>(hostWindow->platformPageClient());
292
301
293
    if (ownerGLWidget) 
302
#if USE(ACCELERATED_COMPOSITING)
294
        m_glWidget = new QGLWidget(0, ownerGLWidget);
303
    if (webPageClient->page->settings()->testAttribute(QWebSettings::AcceleratedCompositingEnabled)) {
304
        QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(webPageClient->ownerWidget());
305
        if (scrollArea)
306
            m_ownerGLWidget = qobject_cast<QGLWidget*>(scrollArea->viewport());
307
    }
308
#endif
309
310
    if (m_ownerGLWidget)
311
        m_glWidget = new QGLWidget(0, m_ownerGLWidget);
295
    else {
312
    else {
296
        QGLFormat format;
313
        QGLFormat format;
297
        format.setDepth(true);
314
        format.setDepth(true);
Lines 454-467 GraphicsContext3DInternal::~GraphicsContext3DInternal() a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec5
454
    m_glWidget = 0;
471
    m_glWidget = 0;
455
}
472
}
456
473
457
QGLWidget* GraphicsContext3DInternal::getOwnerGLWidget(QWebPageClient* webPageClient)
474
void GraphicsContext3DInternal::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
458
{
475
{
459
    QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(webPageClient->ownerWidget());
476
    Q_UNUSED(widget);
460
477
461
    if (scrollArea) 
478
    QRectF rect = option ? option->rect : boundingRect();
462
        return qobject_cast<QGLWidget*>(scrollArea->viewport());
463
479
464
    return 0;
480
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
481
    // Use direct texture mapping if WebGL canvas has a shared OpenGL context
482
    // with browsers OpenGL context.
483
    if (m_ownerGLWidget) {
484
        m_ownerGLWidget->drawTexture(rect, m_texture);
485
        return;
486
    }
487
#endif
488
489
    // Alternatively read pixels to a memory buffer.
490
    m_glWidget->makeCurrent();
491
    bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_mainFbo);
492
    glReadPixels(/* x */ 0, /* y */ 0, rect.width(), rect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, m_pixels.bits());
493
    painter->drawImage(/* x */ 0, /* y */ 0, m_pixels.rgbSwapped().transformed(QMatrix().rotate(180)));
494
    bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_currentFbo);
495
}
496
497
QRectF GraphicsContext3DInternal::boundingRect() const
498
{
499
    return m_boundingRect;
465
}
500
}
466
501
467
void* GraphicsContext3DInternal::getProcAddress(const String& proc)
502
void* GraphicsContext3DInternal::getProcAddress(const String& proc)
Lines 511-516 Platform3DObject GraphicsContext3D::platformTexture() const a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec6
511
    return m_internal->m_texture;
546
    return m_internal->m_texture;
512
}
547
}
513
548
549
PlatformLayer* GraphicsContext3D::platformLayer() const
550
{
551
    return m_internal.get();
552
}
553
514
void GraphicsContext3D::makeContextCurrent()
554
void GraphicsContext3D::makeContextCurrent()
515
{
555
{
516
    m_internal->m_glWidget->makeCurrent();
556
    m_internal->m_glWidget->makeCurrent();
Lines 522-528 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* co a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec7
522
    HTMLCanvasElement* canvas = context->canvas();
562
    HTMLCanvasElement* canvas = context->canvas();
523
    ImageBuffer* imageBuffer = canvas->buffer();
563
    ImageBuffer* imageBuffer = canvas->buffer();
524
    QPainter* painter = imageBuffer->context()->platformContext();
564
    QPainter* painter = imageBuffer->context()->platformContext();
525
    paint(painter, QRect(QPoint(0, 0), QSize(m_currentWidth, m_currentHeight)));
565
    m_internal->paint(painter, 0, 0);
526
}
566
}
527
567
528
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
568
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
Lines 532-554 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData() a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec8
532
    return 0;
572
    return 0;
533
}
573
}
534
574
535
void GraphicsContext3D::paint(QPainter* painter, const QRect& rect) const
536
{
537
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
538
    QWebPageClient* webPageClient = m_internal->m_hostWindow->platformPageClient();
539
    QGLWidget* ownerGLWidget  = m_internal->getOwnerGLWidget(webPageClient);
540
    if (ownerGLWidget) {
541
        ownerGLWidget->drawTexture(rect, m_internal->m_texture);
542
        return;
543
    } 
544
#endif
545
    m_internal->m_glWidget->makeCurrent();
546
    m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_mainFbo);
547
    glReadPixels(/* x */ 0, /* y */ 0, m_currentWidth, m_currentHeight, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, m_internal->m_pixels.bits());
548
    painter->drawImage(/* x */ 0, /* y */ 0, m_internal->m_pixels.rgbSwapped().transformed(QMatrix().rotate(180)));
549
    m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_currentFbo); 
550
}
551
552
void GraphicsContext3D::reshape(int width, int height)
575
void GraphicsContext3D::reshape(int width, int height)
553
{
576
{
554
    if (((width == m_currentWidth) && (height == m_currentHeight)) || (!m_internal))
577
    if (((width == m_currentWidth) && (height == m_currentHeight)) || (!m_internal))
Lines 557-562 void GraphicsContext3D::reshape(int width, int height) a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec9
557
    m_currentWidth = width;
580
    m_currentWidth = width;
558
    m_currentHeight = height;
581
    m_currentHeight = height;
559
582
583
    m_internal->m_boundingRect = QRectF(QPointF(0, 0), QSizeF(width, height));
560
    m_internal->m_pixels = QImage(m_currentWidth, m_currentHeight, QImage::Format_ARGB32);
584
    m_internal->m_pixels = QImage(m_currentWidth, m_currentHeight, QImage::Format_ARGB32);
561
585
562
    m_internal->m_glWidget->makeCurrent();
586
    m_internal->m_glWidget->makeCurrent();
- a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp -39 / +5 lines
Lines 310-319 public: a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec1
310
        }
310
        }
311
    } m_state;
311
    } m_state;
312
312
313
#if ENABLE(WEBGL)
314
    const GraphicsContext3D* m_gc3D;
315
#endif
316
317
#ifndef QT_NO_ANIMATION
313
#ifndef QT_NO_ANIMATION
318
    friend class AnimationQtBase;
314
    friend class AnimationQtBase;
319
#endif
315
#endif
Lines 340-348 GraphicsLayerQtImpl::GraphicsLayerQtImpl(GraphicsLayerQt* newLayer) a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec2
340
#if ENABLE(TILED_BACKING_STORE)
336
#if ENABLE(TILED_BACKING_STORE)
341
    , m_tiledBackingStore(0)
337
    , m_tiledBackingStore(0)
342
#endif
338
#endif
343
#if ENABLE(WEBGL)
344
    , m_gc3D(0)
345
#endif
346
{
339
{
347
    // We use graphics-view for compositing-only, not for interactivity.
340
    // We use graphics-view for compositing-only, not for interactivity.
348
    setAcceptedMouseButtons(Qt::NoButton);
341
    setAcceptedMouseButtons(Qt::NoButton);
Lines 665-675 void GraphicsLayerQtImpl::paint(QPainter* painter, const QStyleOptionGraphicsIte a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec3
665
    case MediaContentType:
658
    case MediaContentType:
666
        // we don't need to paint anything: we have a QGraphicsItem from the media element
659
        // we don't need to paint anything: we have a QGraphicsItem from the media element
667
        break;
660
        break;
668
#if ENABLE(WEBGL)
669
    case Canvas3DContentType:
670
        m_gc3D->paint(painter, option->rect);
671
        break;
672
#endif
673
    }
661
    }
674
}
662
}
675
663
Lines 808-823 void GraphicsLayerQtImpl::flushChanges(bool recursive, bool forceUpdateTransform a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec4
808
796
809
            setFlag(ItemHasNoContents, !m_layer->drawsContent());
797
            setFlag(ItemHasNoContents, !m_layer->drawsContent());
810
            break;
798
            break;
811
812
#if ENABLE(WEBGL)
813
        case Canvas3DContentType:
814
            if (m_pendingContent.contentType != m_currentContent.contentType)
815
                update();
816
817
            setCacheMode(NoCache);
818
            setFlag(ItemHasNoContents, false);
819
            break;
820
#endif
821
        }
799
        }
822
    }
800
    }
823
801
Lines 1268-1290 void GraphicsLayerQt::setContentsBackgroundColor(const Color& color) a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec5
1268
    GraphicsLayer::setContentsBackgroundColor(color);
1246
    GraphicsLayer::setContentsBackgroundColor(color);
1269
}
1247
}
1270
1248
1271
#if ENABLE(WEBGL)
1272
void GraphicsLayerQt::setContentsToGraphicsContext3D(const GraphicsContext3D* ctx)
1273
{
1274
    if (ctx == m_impl->m_gc3D)
1275
        return;
1276
1277
    m_impl->m_pendingContent.contentType = GraphicsLayerQtImpl::Canvas3DContentType;
1278
    m_impl->m_gc3D = ctx;
1279
    m_impl->notifyChange(GraphicsLayerQtImpl::ContentChange);
1280
}
1281
1282
void GraphicsLayerQt::setGraphicsContext3DNeedsDisplay()
1283
{
1284
    setNeedsDisplay();
1285
}
1286
#endif
1287
1288
void GraphicsLayerQt::setContentsToMedia(PlatformLayer* media)
1249
void GraphicsLayerQt::setContentsToMedia(PlatformLayer* media)
1289
{
1250
{
1290
    if (media) {
1251
    if (media) {
Lines 1297-1302 void GraphicsLayerQt::setContentsToMedia(PlatformLayer* media) a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp_sec6
1297
    GraphicsLayer::setContentsToMedia(media);
1258
    GraphicsLayer::setContentsToMedia(media);
1298
}
1259
}
1299
1260
1261
void GraphicsLayerQt::setContentsToCanvas(PlatformLayer* canvas)
1262
{
1263
    setContentsToMedia(canvas);
1264
}
1265
1300
/* \reimp (GraphicsLayer.h)
1266
/* \reimp (GraphicsLayer.h)
1301
*/
1267
*/
1302
void GraphicsLayerQt::setContentsOrientation(CompositingCoordinatesOrientation orientation)
1268
void GraphicsLayerQt::setContentsOrientation(CompositingCoordinatesOrientation orientation)
- a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.h -7 / +1 lines
Lines 20-28 a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.h_sec1
20
#ifndef GraphicsLayerQt_h
20
#ifndef GraphicsLayerQt_h
21
#define GraphicsLayerQt_h
21
#define GraphicsLayerQt_h
22
22
23
#if ENABLE(WEBGL)
24
#include "GraphicsContext3D.h"
25
#endif
26
#include "GraphicsLayer.h"
23
#include "GraphicsLayer.h"
27
#include "GraphicsLayerClient.h"
24
#include "GraphicsLayerClient.h"
28
25
Lines 78-88 public: a/Source/WebCore/platform/graphics/qt/GraphicsLayerQt.h_sec2
78
    virtual void setContentsToImage(Image*);
75
    virtual void setContentsToImage(Image*);
79
    virtual void setContentsNeedsDisplay();
76
    virtual void setContentsNeedsDisplay();
80
    virtual void setContentsToMedia(PlatformLayer*);
77
    virtual void setContentsToMedia(PlatformLayer*);
78
    virtual void setContentsToCanvas(PlatformLayer*);
81
    virtual void setContentsBackgroundColor(const Color&);
79
    virtual void setContentsBackgroundColor(const Color&);
82
#if ENABLE(WEBGL)
83
    virtual void setContentsToGraphicsContext3D(const GraphicsContext3D*);
84
    virtual void setGraphicsContext3DNeedsDisplay();
85
#endif
86
    virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation);
80
    virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation);
87
    virtual void distributeOpacity(float);
81
    virtual void distributeOpacity(float);
88
    virtual float accumulatedOpacity() const;
82
    virtual float accumulatedOpacity() const;

Return to Bug 56339