Index: ShaderChromium.cpp =================================================================== --- ShaderChromium.cpp (revision 85565) +++ ShaderChromium.cpp (working copy) @@ -54,11 +54,11 @@ attribute vec4 a_position; attribute vec2 a_texCoord; uniform mat4 matrix; - varying vec2 v_texCoord; + varying vec4 v_texCoord; void main() { gl_Position = matrix * a_position; - v_texCoord = a_texCoord; + v_texCoord = vec4(a_texCoord.xy, 0.0, 1.0); } ); } @@ -140,12 +140,12 @@ attribute vec4 a_position; attribute vec2 a_texCoord; uniform mat4 matrix; - uniform vec4 texTransform; - varying vec2 v_texCoord; + uniform mat4 texTransform; + varying vec4 v_texCoord; void main() { gl_Position = matrix * a_position; - v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; + v_texCoord = texTransform * vec4(a_texCoord.xy, 0.0, 1.0); } ); } @@ -153,6 +153,7 @@ FragmentTexAlphaBinding::FragmentTexAlphaBinding() : m_samplerLocation(-1) , m_alphaLocation(-1) + , m_sizeLocation(-1) { } @@ -160,20 +161,24 @@ { m_samplerLocation = context->getUniformLocation(program, "s_texture"); m_alphaLocation = context->getUniformLocation(program, "alpha"); + m_sizeLocation = context->getUniformLocation(program, "size"); - return m_samplerLocation != -1 && m_alphaLocation != -1; + return m_samplerLocation != -1 && m_alphaLocation != -1 && m_sizeLocation != -1; } String FragmentShaderRGBATexFlipAlpha::getShaderString() const { return SHADER( precision mediump float; - varying vec2 v_texCoord; + varying vec4 v_texCoord; uniform sampler2D s_texture; uniform float alpha; + uniform vec2 size; void main() { - vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); + vec2 coords = vec2(v_texCoord.x / v_texCoord.w, 1.0 - (v_texCoord.y / v_texCoord.w)); + vec2 border = clamp((size + vec2(1, 1)) * 0.5 - abs(size * (coords - 0.5)), 0.0, 1.0); + vec4 texColor = texture2D(s_texture, coords) * border.x * border.y; gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; } ); @@ -183,12 +188,15 @@ { return SHADER( precision mediump float; - varying vec2 v_texCoord; + varying vec4 v_texCoord; uniform sampler2D s_texture; uniform float alpha; + uniform vec2 size; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec2 coords = vec2(v_texCoord.x / v_texCoord.w, v_texCoord.y / v_texCoord.w); + vec2 border = clamp((size + vec2(1, 1)) * 0.5 - abs(size * (coords - 0.5)), 0.0, 1.0); + vec4 texColor = texture2D(s_texture, coords) * border.x * border.y; gl_FragColor = texColor * alpha; } ); @@ -198,12 +206,15 @@ { return SHADER( precision mediump float; - varying vec2 v_texCoord; + varying vec4 v_texCoord; uniform sampler2D s_texture; uniform float alpha; + uniform vec2 size; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); + vec2 coords = vec2(v_texCoord.x / v_texCoord.w, v_texCoord.y / v_texCoord.w); + vec2 border = clamp((size + vec2(1, 1)) * 0.5 - abs(size * (coords - 0.5)), 0.0, 1.0); + vec4 texColor = texture2D(s_texture, coords) * border.x * border.y; gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; } ); @@ -229,14 +240,14 @@ { return SHADER( precision mediump float; - varying vec2 v_texCoord; + varying vec4 v_texCoord; uniform sampler2D s_texture; uniform sampler2D s_mask; uniform float alpha; void main() { - vec4 texColor = texture2D(s_texture, v_texCoord); - vec4 maskColor = texture2D(s_mask, v_texCoord); + vec4 texColor = texture2D(s_texture, v_texCoord.xy); + vec4 maskColor = texture2D(s_mask, v_texCoord.xy); gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; } ); Index: ShaderChromium.h =================================================================== --- ShaderChromium.h (revision 85565) +++ ShaderChromium.h (working copy) @@ -103,10 +103,12 @@ bool init(GraphicsContext3D*, unsigned program); int alphaLocation() const { return m_alphaLocation; } int samplerLocation() const { return m_samplerLocation; } + int sizeLocation() const { return m_sizeLocation; } private: int m_samplerLocation; int m_alphaLocation; + int m_sizeLocation; }; class FragmentShaderRGBATexFlipAlpha : public FragmentTexAlphaBinding { Index: LayerTilerChromium.cpp =================================================================== --- LayerTilerChromium.cpp (revision 85565) +++ LayerTilerChromium.cpp (working copy) @@ -379,12 +379,75 @@ return; GraphicsContext3D* context = layerRendererContext(); + + int left, top, right, bottom; + contentRectToTileIndices(contentRect, left, top, right, bottom); + + // XXX: Anti-aliasing test used for single tile layers. + if (top == bottom && left == right) { + Tile* tile = tileAt(left, top); + if (!tile) + return; + + const LayerTilerChromium::Program* program = layerRenderer()->tilerProgram(); + layerRenderer()->useShader(program->program()); + GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); + + tile->texture()->bindTexture(); + + TransformationMatrix renderMatrix; + + // Get bounding box by projecting content into surface space. + IntRect surfaceRect = globalTransform.mapRect(contentRect); + renderMatrix.translate3d(surfaceRect.x() + surfaceRect.width() / 2.0, + surfaceRect.y() + surfaceRect.height() / 2.0, + 0); + renderMatrix.scale3d(surfaceRect.width(), surfaceRect.height(), 1); + + float glMatrix[16]; + + // Apply the projection matrix before sending the transform over to the shader. + LayerChromium::toGLMatrix(&glMatrix[0], layerRenderer()->projectionMatrix() * renderMatrix); + + GLC(context, context->uniformMatrix4fv(program->vertexShader().matrixLocation(), false, &glMatrix[0], 1)); + + GLC(context, context->uniform1f(program->fragmentShader().alphaLocation(), opacity)); + + TransformationMatrix texMatrix; + + // Set up texture matrix in layer space. + texMatrix.scale3d(1.0 / surfaceRect.width(), + 1.0 / surfaceRect.height(), 1); + texMatrix.translate3d(-surfaceRect.x(), -surfaceRect.y(), 0); + texMatrix.multiply(globalTransform); + + // Transform to texture space (normalized coordinates). + IntRect tileRect = m_tilingData.tileBounds(m_tilingData.tileIndex(tile->i(), tile->j())); + texMatrix.scale3d(tileRect.width(), tileRect.height(), 1); + + // Z component of texture coordinates is always set to zero. + texMatrix.setM13(0.0); + texMatrix.setM23(0.0); + texMatrix.setM33(1.0); + texMatrix.setM43(0.0); + + // Invert before sending the transform over to the shader. + LayerChromium::toGLMatrix(&glMatrix[0], texMatrix.inverse()); + + GLC(context, context->uniformMatrix4fv(program->vertexShader().texTransformLocation(), false, &glMatrix[0], 1)); + + float size[2] = { tileRect.width(), tileRect.height() }; + GLC(context, context->uniform2fv(program->fragmentShader().sizeLocation(), size, 1)); + + GLC(context, context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0)); + + return; + } + const LayerTilerChromium::Program* program = layerRenderer()->tilerProgram(); layerRenderer()->useShader(program->program()); GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); - int left, top, right, bottom; - contentRectToTileIndices(contentRect, left, top, right, bottom); for (int j = top; j <= bottom; ++j) { for (int i = left; i <= right; ++i) { Tile* tile = tileAt(i, j); @@ -445,9 +508,18 @@ GLC(context, context->uniform1f(program->fragmentShader().alphaLocation(), opacity)); - GLC(context, context->uniform4f(program->vertexShader().texTransformLocation(), - texTranslateX, texTranslateY, texScaleX, texScaleY)); + float size[2] = { width, height }; + GLC(context, context->uniform2fv(program->fragmentShader().sizeLocation(), size, 1)); + TransformationMatrix texTransform; + + texTransform.scale3d(texScaleX, texScaleY, 1); + texTransform.translate3d(texTranslateX, texTranslateY, 0); + + LayerChromium::toGLMatrix(&glMatrix[0], texTransform); + + GLC(context, context->uniformMatrix4fv(program->vertexShader().texTransformLocation(), false, &glMatrix[0], 1)); + GLC(context, context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0)); }