Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Qt] Fix issues when using the WebView as ShaderEffectSource
https://bugs.webkit.org/show_bug.cgi?id=83587

Reviewed by Noam Rosenthal.

Source/WebCore:

- Make sure that the bound frame buffer is preserved instead of binding
  to the default one
- Accept a "mirrored" flag in beginPainting that we're applying on the
  projection matrix just as with internal FBOs

The "flip" logic in createProjectionMatrix has been reversed and renamed to
mirrored so that FBO rendering is considered the special case and not the
other way around just like within Qt.

* platform/graphics/texmap/TextureMapper.h:
(WebCore::TextureMapper::beginPainting):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGLData::TextureMapperGLData):
(TextureMapperGLData):
(WebCore::TextureMapperGL::beginPainting):
(WebCore::createProjectionMatrix):
(WebCore::BitmapTextureGL::bind):
(WebCore::TextureMapperGL::bindSurface):
* platform/graphics/texmap/TextureMapperGL.h:

Source/WebKit2:

Qt is going to mirror the projection matrix when the shader effect source
is grabbed. Detect that the matrix is mirrored and pass on this information
to TextureMapper so that it can do the same.

* UIProcess/WebLayerTreeRenderer.cpp:
(WebKit::WebLayerTreeRenderer::paintToCurrentGLContext):
* UIProcess/WebLayerTreeRenderer.h:
(WebLayerTreeRenderer):
* UIProcess/qt/QtWebPageSGNode.cpp:
(WebKit::ContentsSGNode::render):

Canonical link: https://commits.webkit.org/101157@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@113859 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jturcotte committed Apr 11, 2012
1 parent 7c79c03 commit 00c2e7e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 15 deletions.
27 changes: 27 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,30 @@
2012-04-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>

[Qt] Fix issues when using the WebView as ShaderEffectSource
https://bugs.webkit.org/show_bug.cgi?id=83587

Reviewed by Noam Rosenthal.

- Make sure that the bound frame buffer is preserved instead of binding
to the default one
- Accept a "mirrored" flag in beginPainting that we're applying on the
projection matrix just as with internal FBOs

The "flip" logic in createProjectionMatrix has been reversed and renamed to
mirrored so that FBO rendering is considered the special case and not the
other way around just like within Qt.

* platform/graphics/texmap/TextureMapper.h:
(WebCore::TextureMapper::beginPainting):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGLData::TextureMapperGLData):
(TextureMapperGLData):
(WebCore::TextureMapperGL::beginPainting):
(WebCore::createProjectionMatrix):
(WebCore::BitmapTextureGL::bind):
(WebCore::TextureMapperGL::bindSurface):
* platform/graphics/texmap/TextureMapperGL.h:

2012-04-11 Stephen Chenney <schenney@chromium.org>

Shadow tree TreeScope data is not removed by ContainerNode::removeAllChildren
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/platform/graphics/texmap/TextureMapper.h
Expand Up @@ -104,6 +104,11 @@ class TextureMapper {

public:
enum AccelerationMode { SoftwareMode, OpenGLMode };
enum PaintFlag {
PaintingMirrored = 1 << 0,
};
typedef unsigned PaintFlags;

static PassOwnPtr<TextureMapper> create(AccelerationMode newMode = SoftwareMode);
virtual ~TextureMapper() { }

Expand All @@ -124,7 +129,7 @@ class TextureMapper {
TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
virtual AccelerationMode accelerationMode() const = 0;

virtual void beginPainting() { }
virtual void beginPainting(PaintFlags flags = 0) { }
virtual void endPainting() { }

virtual IntSize maxTextureSize() const { return IntSize(INT_MAX, INT_MAX); }
Expand Down
26 changes: 18 additions & 8 deletions Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Expand Up @@ -187,15 +187,19 @@ struct TextureMapperGLData {
void initializeStencil();

TextureMapperGLData()
: previousProgram(0)
: PaintFlags(0)
, previousProgram(0)
, targetFrameBuffer(0)
, didModifyStencil(false)
, previousScissorState(0)
, previousDepthState(0)
, m_sharedGLData(TextureMapperGLData::SharedGLData::currentSharedGLData())
{ }

TransformationMatrix projectionMatrix;
TextureMapper::PaintFlags PaintFlags;
GLint previousProgram;
GLint targetFrameBuffer;
bool didModifyStencil;
GLint previousScissorState;
GLint previousDepthState;
Expand Down Expand Up @@ -234,7 +238,7 @@ TextureMapperGL::TextureMapperGL()
{
}

void TextureMapperGL::beginPainting()
void TextureMapperGL::beginPainting(PaintFlags flags)
{
// Make sure that no GL error code stays from previous operations.
glGetError();
Expand All @@ -259,6 +263,8 @@ void TextureMapperGL::beginPainting()
GL_CMD(glGetIntegerv(GL_SCISSOR_BOX, data().previousScissor));
data().sharedGLData().clipState.stencilIndex = 1;
data().sharedGLData().clipState.scissorBox = IntRect(0, 0, data().viewport[2], data().viewport[3]);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &data().targetFrameBuffer);
data().PaintFlags = flags;
bindSurface(0);
}

Expand Down Expand Up @@ -507,15 +513,15 @@ void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, co

}

static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool flip)
static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored)
{
const float near = 9999999;
const float far = -99999;

return TransformationMatrix(2.0 / float(size.width()), 0, 0, 0,
0, (flip ? -2.0 : 2.0) / float(size.height()), 0, 0,
0, (mirrored ? 2.0 : -2.0) / float(size.height()), 0, 0,
0, 0, -2.f / (far - near), 0,
-1, flip ? 1 : -1, -(far + near) / (far - near), 1);
-1, mirrored ? -1 : 1, -(far + near) / (far - near), 1);
}

void BitmapTextureGL::initializeStencil()
Expand Down Expand Up @@ -550,7 +556,8 @@ void BitmapTextureGL::bind()
GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo));

GL_CMD(glViewport(0, 0, size().width(), size().height()));
m_textureMapper->data().projectionMatrix = createProjectionMatrix(size(), false);
const bool mirrored = true;
m_textureMapper->data().projectionMatrix = createProjectionMatrix(size(), mirrored);
m_textureMapper->beginClip(TransformationMatrix(), FloatRect(IntPoint::zero(), contentSize()));
}

Expand Down Expand Up @@ -586,10 +593,13 @@ void TextureMapperGL::bindSurface(BitmapTexture *surfacePointer)
BitmapTextureGL* surface = static_cast<BitmapTextureGL*>(surfacePointer);

if (!surface) {
GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, data().targetFrameBuffer));

IntSize viewportSize(data().viewport[2], data().viewport[3]);
GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, 0));
data().projectionMatrix = createProjectionMatrix(viewportSize, true);
const bool mirorred = data().PaintFlags & PaintingMirrored;
data().projectionMatrix = createProjectionMatrix(viewportSize, mirorred);
GL_CMD(glViewport(0, 0, viewportSize.width(), viewportSize.height()));

if (data().currentSurface)
endClip();
data().currentSurface.clear();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
Expand Up @@ -52,7 +52,7 @@ class TextureMapperGL : public TextureMapper {
virtual void drawTexture(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture);
virtual void bindSurface(BitmapTexture* surface);
virtual void beginClip(const TransformationMatrix&, const FloatRect&);
virtual void beginPainting();
virtual void beginPainting(PaintFlags = 0);
virtual void endPainting();
virtual void endClip();
virtual IntSize maxTextureSize() { return IntSize(2000, 2000); }
Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,21 @@
2012-04-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>

[Qt] Fix issues when using the WebView as ShaderEffectSource
https://bugs.webkit.org/show_bug.cgi?id=83587

Reviewed by Noam Rosenthal.

Qt is going to mirror the projection matrix when the shader effect source
is grabbed. Detect that the matrix is mirrored and pass on this information
to TextureMapper so that it can do the same.

* UIProcess/WebLayerTreeRenderer.cpp:
(WebKit::WebLayerTreeRenderer::paintToCurrentGLContext):
* UIProcess/WebLayerTreeRenderer.h:
(WebLayerTreeRenderer):
* UIProcess/qt/QtWebPageSGNode.cpp:
(WebKit::ContentsSGNode::render):

2012-04-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>

[Qt] Remove unnecessary rendering code
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp
Expand Up @@ -102,7 +102,7 @@ PassOwnPtr<GraphicsLayer> WebLayerTreeRenderer::createLayer(WebLayerID layerID)
return adoptPtr(newLayer);
}

void WebLayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect)
void WebLayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, TextureMapper::PaintFlags PaintFlags)
{
if (!m_textureMapper)
m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
Expand All @@ -120,7 +120,7 @@ void WebLayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& m
return;

layer->setTextureMapper(m_textureMapper.get());
m_textureMapper->beginPainting();
m_textureMapper->beginPainting(PaintFlags);
m_textureMapper->beginClip(TransformationMatrix(), clipRect);

if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) {
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit2/UIProcess/WebLayerTreeRenderer.h
Expand Up @@ -61,7 +61,7 @@ class WebLayerTreeRenderer : public ThreadSafeRefCounted<WebLayerTreeRenderer>,
WebLayerTreeRenderer(LayerTreeHostProxy*);
virtual ~WebLayerTreeRenderer();
void purgeGLResources();
void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&);
void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&, WebCore::TextureMapper::PaintFlags = 0);
void paintToGraphicsContext(BackingStore::PlatformGraphicsContext);
void syncRemoteContent();
void setContentsSize(const WebCore::FloatSize&);
Expand Down
11 changes: 9 additions & 2 deletions Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp
Expand Up @@ -26,6 +26,8 @@
#include <QtQuick/QSGSimpleRectNode>
#include <private/qsgrendernode_p.h>

using namespace WebCore;

namespace WebKit {

class ContentsSGNode : public QSGRenderNode {
Expand All @@ -40,12 +42,17 @@ class ContentsSGNode : public QSGRenderNode {
return StateFlags(StencilState) | ColorState | BlendState;
}

virtual void render(const RenderState&)
virtual void render(const RenderState& state)
{
QMatrix4x4 renderMatrix = matrix() ? *matrix() : QMatrix4x4();

// When rendering to an intermediate surface, Qt will
// mirror the projection matrix to fit on the destination coordinate system.
const QMatrix4x4* projection = state.projectionMatrix;
bool mirrored = projection && (*projection)(0, 0) * (*projection)(1, 1) - (*projection)(0, 1) * (*projection)(1, 0) > 0;

// FIXME: Support non-rectangular clippings.
layerTreeRenderer()->paintToCurrentGLContext(renderMatrix, inheritedOpacity(), clipRect());
layerTreeRenderer()->paintToCurrentGLContext(renderMatrix, inheritedOpacity(), clipRect(), mirrored ? TextureMapper::PaintingMirrored : 0);
}

~ContentsSGNode()
Expand Down

0 comments on commit 00c2e7e

Please sign in to comment.