diff --git a/components/net/image_cache_thread.rs b/components/net/image_cache_thread.rs index 440ebd32100..5929100e2a1 100644 --- a/components/net/image_cache_thread.rs +++ b/components/net/image_cache_thread.rs @@ -323,7 +323,11 @@ fn get_placeholder_image(webrender_api: &webrender_traits::RenderApi) -> io::Res let format = convert_format(image.format); let mut bytes = Vec::new(); bytes.extend_from_slice(&*image.bytes); - image.id = Some(webrender_api.add_image(image.width, image.height, format, bytes)); + image.id = Some(webrender_api.add_image(image.width, + image.height, + None, + format, + bytes)); Ok(Arc::new(image)) } @@ -478,7 +482,11 @@ impl ImageCache { let format = convert_format(image.format); let mut bytes = Vec::new(); bytes.extend_from_slice(&*image.bytes); - image.id = Some(self.webrender_api.add_image(image.width, image.height, format, bytes)); + image.id = Some(self.webrender_api.add_image(image.width, + image.height, + None, + format, + bytes)); } LoadResult::PlaceholderLoaded(..) | LoadResult::None => {} } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 528b947a7a3..911c7c95ba4 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -2833,11 +2833,12 @@ dependencies = [ [[package]] name = "webrender" version = "0.8.0" -source = "git+https://github.com/servo/webrender#13e06df7906b71aaa2aa621a012678cae1f88052" +source = "git+https://github.com/servo/webrender#a0b6ea0b51a170caf591fb281f5aba25e566158f" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2858,7 +2859,7 @@ dependencies = [ [[package]] name = "webrender_traits" version = "0.8.0" -source = "git+https://github.com/servo/webrender#13e06df7906b71aaa2aa621a012678cae1f88052" +source = "git+https://github.com/servo/webrender#a0b6ea0b51a170caf591fb281f5aba25e566158f" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 980958d0a99..8e94b56ce50 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -2691,11 +2691,12 @@ dependencies = [ [[package]] name = "webrender" version = "0.8.0" -source = "git+https://github.com/servo/webrender#13e06df7906b71aaa2aa621a012678cae1f88052" +source = "git+https://github.com/servo/webrender#a0b6ea0b51a170caf591fb281f5aba25e566158f" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2716,7 +2717,7 @@ dependencies = [ [[package]] name = "webrender_traits" version = "0.8.0" -source = "git+https://github.com/servo/webrender#13e06df7906b71aaa2aa621a012678cae1f88052" +source = "git+https://github.com/servo/webrender#a0b6ea0b51a170caf591fb281f5aba25e566158f" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/resources/shaders/blend.fs.glsl b/resources/shaders/blend.fs.glsl deleted file mode 100644 index 8dc29cf4d8f..00000000000 --- a/resources/shaders/blend.fs.glsl +++ /dev/null @@ -1,193 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -vec3 Multiply(vec3 Cb, vec3 Cs) { - return Cb * Cs; -} - -vec3 Screen(vec3 Cb, vec3 Cs) { - return Cb + Cs - (Cb * Cs); -} - -vec3 HardLight(vec3 Cb, vec3 Cs) { - vec3 m = Multiply(Cb, 2.0 * Cs); - vec3 s = Screen(Cb, 2.0 * Cs - 1.0); - vec3 edge = vec3(0.5, 0.5, 0.5); - return mix(m, s, step(edge, Cs)); -} - -// TODO: Worth doing with mix/step? Check GLSL output. -float ColorDodge(float Cb, float Cs) { - if (Cb == 0.0) - return 0.0; - else if (Cs == 1.0) - return 1.0; - else - return min(1.0, Cb / (1.0 - Cs)); -} - -// TODO: Worth doing with mix/step? Check GLSL output. -float ColorBurn(float Cb, float Cs) { - if (Cb == 1.0) - return 1.0; - else if (Cs == 0.0) - return 0.0; - else - return 1.0 - min(1.0, (1.0 - Cb) / Cs); -} - -float SoftLight(float Cb, float Cs) { - if (Cs <= 0.5) { - return Cb - (1.0 - 2.0 * Cs) * Cb * (1.0 - Cb); - } else { - float D; - - if (Cb <= 0.25) - D = ((16.0 * Cb - 12.0) * Cb + 4.0) * Cb; - else - D = sqrt(Cb); - - return Cb + (2.0 * Cs - 1.0) * (D - Cb); - } -} - -vec3 Difference(vec3 Cb, vec3 Cs) { - return abs(Cb - Cs); -} - -vec3 Exclusion(vec3 Cb, vec3 Cs) { - return Cb + Cs - 2.0 * Cb * Cs; -} - -// These functions below are taken from the spec. -// There's probably a much quicker way to implement -// them in GLSL... -float Sat(vec3 c) { - return max(c.r, max(c.g, c.b)) - min(c.r, min(c.g, c.b)); -} - -float Lum(vec3 c) { - vec3 f = vec3(0.3, 0.59, 0.11); - return dot(c, f); -} - -vec3 ClipColor(vec3 C) { - float L = Lum(C); - float n = min(C.r, min(C.g, C.b)); - float x = max(C.r, max(C.g, C.b)); - - if (n < 0.0) - C = L + (((C - L) * L) / (L - n)); - - if (x > 1.0) - C = L + (((C - L) * (1.0 - L)) / (x - L)); - - return C; -} - -vec3 SetLum(vec3 C, float l) { - float d = l - Lum(C); - return ClipColor(C + d); -} - -void SetSatInner(inout float Cmin, inout float Cmid, inout float Cmax, float s) { - if (Cmax > Cmin) { - Cmid = (((Cmid - Cmin) * s) / (Cmax - Cmin)); - Cmax = s; - } else { - Cmid = 0.0; - Cmax = 0.0; - } - Cmin = 0.0; -} - -vec3 SetSat(vec3 C, float s) { - if (C.r <= C.g) { - if (C.g <= C.b) { - SetSatInner(C.r, C.g, C.b, s); - } else { - if (C.r <= C.b) { - SetSatInner(C.r, C.b, C.g, s); - } else { - SetSatInner(C.b, C.r, C.g, s); - } - } - } else { - if (C.r <= C.b) { - SetSatInner(C.g, C.r, C.b, s); - } else { - if (C.g <= C.b) { - SetSatInner(C.g, C.b, C.r, s); - } else { - SetSatInner(C.b, C.g, C.r, s); - } - } - } - return C; -} - -vec3 Hue(vec3 Cb, vec3 Cs) { - return SetLum(SetSat(Cs, Sat(Cb)), Lum(Cb)); -} - -vec3 Saturation(vec3 Cb, vec3 Cs) { - return SetLum(SetSat(Cb, Sat(Cs)), Lum(Cb)); -} - -vec3 Color(vec3 Cb, vec3 Cs) { - return SetLum(Cs, Lum(Cb)); -} - -vec3 Luminosity(vec3 Cb, vec3 Cs) { - return SetLum(Cb, Lum(Cs)); -} - -void main(void) -{ - vec3 Cs = Texture(sDiffuse, vColorTexCoord).xyz; - vec3 Cb = Texture(sMask, vMaskTexCoord).xyz; - - // TODO: Relies on the ordering of MixBlendMode enum! - // TODO: May be best to have separate shaders (esp. on Tegra) - int blend_mode = int(uBlendParams.x); - - // Return yellow if none of the branches match (shouldn't happen). - vec3 result = vec3(1.0, 1.0, 0.0); - - if (blend_mode == 2) { - result = Screen(Cb, Cs); - } else if (blend_mode == 3) { - result = HardLight(Cs, Cb); // Overlay is inverse of Hardlight - } else if (blend_mode == 6) { - result.r = ColorDodge(Cb.r, Cs.r); - result.g = ColorDodge(Cb.g, Cs.g); - result.b = ColorDodge(Cb.b, Cs.b); - } else if (blend_mode == 7) { - result.r = ColorBurn(Cb.r, Cs.r); - result.g = ColorBurn(Cb.g, Cs.g); - result.b = ColorBurn(Cb.b, Cs.b); - } else if (blend_mode == 8) { - result = HardLight(Cb, Cs); - } else if (blend_mode == 9) { - result.r = SoftLight(Cb.r, Cs.r); - result.g = SoftLight(Cb.g, Cs.g); - result.b = SoftLight(Cb.b, Cs.b); - } else if (blend_mode == 10) { - result = Difference(Cb, Cs); - } else if (blend_mode == 11) { - result = Exclusion(Cb, Cs); - } else if (blend_mode == 12) { - result = Hue(Cb, Cs); - } else if (blend_mode == 13) { - result = Saturation(Cb, Cs); - } else if (blend_mode == 14) { - result = Color(Cb, Cs); - } else if (blend_mode == 15) { - result = Luminosity(Cb, Cs); - } - - // TODO: Handle output alpha correctly. - SetFragColor(vec4(result, 1.0)); -} - diff --git a/resources/shaders/blend.vs.glsl b/resources/shaders/blend.vs.glsl deleted file mode 100644 index 031ccacdc1b..00000000000 --- a/resources/shaders/blend.vs.glsl +++ /dev/null @@ -1,10 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void main(void) -{ - vColorTexCoord = aColorTexCoordRectTop.xy; - vMaskTexCoord = aMaskTexCoordRectTop.xy / 65535.0; - gl_Position = uTransform * vec4(aPosition, 1.0); -} diff --git a/resources/shaders/box_shadow.fs.glsl b/resources/shaders/box_shadow.fs.glsl deleted file mode 100644 index e71ba6a193b..00000000000 --- a/resources/shaders/box_shadow.fs.glsl +++ /dev/null @@ -1,148 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// See http://asciimath.org to render the equations here. - -// The Gaussian function used for blurring: -// -// G_sigma(x) = 1/sqrt(2 pi sigma^2) e^(-x^2/(2 sigma^2)) -float gauss(float x, float sigma) { - float sigmaPow2 = sigma * sigma; - return 1.0 / sqrt(6.283185307179586 * sigmaPow2) * exp(-(x * x) / (2.0 * sigmaPow2)); -} - -// An approximation of the error function, which is related to the integral of the Gaussian -// function: -// -// "erf"(x) = 2/sqrt(pi) int_0^x e^(-t^2) dt -// ~~ 1 - 1 / (1 + a_1 x + a_2 x^2 + a_3 x^3 + a_4 x^4)^4 -// -// where: -// -// a_1 = 0.278393, a_2 = 0.230389, a_3 = 0.000972, a_4 = 0.078108 -// -// This approximation is accurate to `5 xx 10^-4`, more than accurate enough for our purposes. -// -// See: https://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_functions -float erf(float x) { - bool negative = x < 0.0; - if (negative) - x = -x; - float x2 = x * x; - float x3 = x2 * x; - float x4 = x2 * x2; - float denom = 1.0 + 0.278393 * x + 0.230389 * x2 + 0.000972 * x3 + 0.078108 * x4; - float result = 1.0 - 1.0 / (denom * denom * denom * denom); - return negative ? -result : result; -} - -// A useful helper for calculating integrals of the Gaussian function via the error function: -// -// "erf"_sigma(x) = 2 int 1/sqrt(2 pi sigma^2) e^(-x^2/(2 sigma^2)) dx -// = "erf"(x/(sigma sqrt(2))) -float erfSigma(float x, float sigma) { - return erf(x / (sigma * 1.4142135623730951)); -} - -// Returns the blurred color value from the box itself (not counting any rounded corners). `p_0` is -// the vector distance to the top left corner of the box; `p_1` is the vector distance to its -// bottom right corner. -// -// "colorFromRect"_sigma(p_0, p_1) -// = int_{p_{0_y}}^{p_{1_y}} int_{p_{1_x}}^{p_{0_x}} G_sigma(y) G_sigma(x) dx dy -// = 1/4 ("erf"_sigma(p_{1_x}) - "erf"_sigma(p_{0_x})) -// ("erf"_sigma(p_{1_y}) - "erf"_sigma(p_{0_y})) -float colorFromRect(vec2 p0, vec2 p1, float sigma) { - return (erfSigma(p1.x, sigma) - erfSigma(p0.x, sigma)) * - (erfSigma(p1.y, sigma) - erfSigma(p0.y, sigma)) / 4.0; -} - -// Returns the `x` coordinate on the ellipse with the given radii for the given `y` coordinate: -// -// "ellipsePoint"(y, y_0, a, b) = a sqrt(1 - ((y - y_0) / b)^2) -float ellipsePoint(float y, float y0, vec2 radii) { - float bStep = (y - y0) / radii.y; - return radii.x * sqrt(1.0 - bStep * bStep); -} - -// A helper function to compute the value that needs to be subtracted to accommodate the border -// corners. -// -// "colorCutout"_sigma(x_{0_l}, x_{0_r}, y_0, y_{min}, y_{max}, a, b) -// = int_{y_{min}}^{y_{max}} -// int_{x_{0_r} + "ellipsePoint"(y, y_0, a, b)}^{x_{0_r} + a} G_sigma(y) G_sigma(x) dx -// + int_{x_{0_l} - a}^{x_{0_l} - "ellipsePoint"(y, y_0, a, b)} G_sigma(y) G_sigma(x) -// dx dy -// = int_{y_{min}}^{y_{max}} 1/2 G_sigma(y) -// ("erf"_sigma(x_{0_r} + a) - "erf"_sigma(x_{0_r} + "ellipsePoint"(y, y_0, a, b)) + -// "erf"_sigma(x_{0_l} - "ellipsePoint"(y, y_0, a, b)) - "erf"_sigma(x_{0_l} - a)) -// -// with the outer integral evaluated numerically. -float colorCutoutGeneral(float x0l, - float x0r, - float y0, - float yMin, - float yMax, - vec2 radii, - float sigma) { - float sum = 0.0; - for (float y = yMin; y <= yMax; y += 1.0) { - float xEllipsePoint = ellipsePoint(y, y0, radii); - sum += gauss(y, sigma) * - (erfSigma(x0r + radii.x, sigma) - erfSigma(x0r + xEllipsePoint, sigma) + - erfSigma(x0l - xEllipsePoint, sigma) - erfSigma(x0l - radii.x, sigma)); - } - return sum / 2.0; -} - -// The value that needs to be subtracted to accommodate the top border corners. -float colorCutoutTop(float x0l, float x0r, float y0, vec2 radii, float sigma) { - return colorCutoutGeneral(x0l, x0r, y0, y0, y0 + radii.y, radii, sigma); -} - -// The value that needs to be subtracted to accommodate the bottom border corners. -float colorCutoutBottom(float x0l, float x0r, float y0, vec2 radii, float sigma) { - return colorCutoutGeneral(x0l, x0r, y0, y0 - radii.y, y0, radii, sigma); -} - -// The blurred color value for the point at `pos` with the top left corner of the box at -// `p_{0_"rect"}` and the bottom right corner of the box at `p_{1_"rect"}`. -float color(vec2 pos, vec2 p0Rect, vec2 p1Rect, vec2 radii, float sigma) { - // Compute the vector distances `p_0` and `p_1`. - vec2 p0 = p0Rect - pos, p1 = p1Rect - pos; - - // Compute the basic color `"colorFromRect"_sigma(p_0, p_1)`. This is all we have to do if - // the box is unrounded. - float cRect = colorFromRect(p0, p1, sigma); - if (radii.x == 0.0 || radii.y == 0.0) - return cRect; - - // Compute the inner corners of the box, taking border radii into account: `x_{0_l}`, - // `y_{0_t}`, `x_{0_r}`, and `y_{0_b}`. - float x0l = p0.x + radii.x; - float y0t = p1.y - radii.y; - float x0r = p1.x - radii.x; - float y0b = p0.y + radii.y; - - // Compute the final color: - // - // "colorFromRect"_sigma(p_0, p_1) - - // ("colorCutoutTop"_sigma(x_{0_l}, x_{0_r}, y_{0_t}, a, b) + - // "colorCutoutBottom"_sigma(x_{0_l}, x_{0_r}, y_{0_b}, a, b)) - float cCutoutTop = colorCutoutTop(x0l, x0r, y0t, radii, sigma); - float cCutoutBottom = colorCutoutBottom(x0l, x0r, y0b, radii, sigma); - return cRect - (cCutoutTop + cCutoutBottom); -} - -void main(void) { - vec2 pos = vPosition.xy; - vec2 p0Rect = vBorderPosition.xy, p1Rect = vBorderPosition.zw; - vec2 radii = vBorderRadii.xy; - float sigma = vBlurRadius / 2.0; - float value = color(pos, p0Rect, p1Rect, radii, sigma); - - value = max(value, 0.0); - SetFragColor(vec4(vColor.rgb, vColor.a == 0.0 ? 1.0 - value : value)); -} - diff --git a/resources/shaders/box_shadow.vs.glsl b/resources/shaders/box_shadow.vs.glsl deleted file mode 100644 index de3793c211e..00000000000 --- a/resources/shaders/box_shadow.vs.glsl +++ /dev/null @@ -1,14 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void main(void) -{ - vPosition = aPosition.xy; - vColor = aColorRectTL; - vBorderPosition = aBorderPosition; - vBorderRadii = aBorderRadii; - vBlurRadius = aBlurRadius; - gl_Position = uTransform * vec4(aPosition, 1.0); -} - diff --git a/resources/shaders/es2_common.fs.glsl b/resources/shaders/es2_common.fs.glsl deleted file mode 100644 index 088bc670036..00000000000 --- a/resources/shaders/es2_common.fs.glsl +++ /dev/null @@ -1,42 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#version 110 - -#define SERVO_ES2 - -precision highp float; - -uniform sampler2D sDiffuse; -uniform sampler2D sMask; -uniform vec4 uBlendParams; -uniform vec4 uAtlasParams; -uniform vec2 uDirection; -uniform vec4 uFilterParams; - -varying vec2 vPosition; -varying vec4 vColor; -varying vec2 vColorTexCoord; -varying vec2 vMaskTexCoord; -varying vec4 vBorderPosition; -varying vec4 vBorderRadii; -varying vec2 vDestTextureSize; -varying vec2 vSourceTextureSize; -varying float vBlurRadius; -varying vec4 vTileParams; -varying vec4 vClipInRect; -varying vec4 vClipOutRect; - -vec4 Texture(sampler2D sampler, vec2 texCoord) { - return texture2D(sampler, texCoord); -} - -float GetAlphaFromMask(vec4 mask) { - return mask.a; -} - -void SetFragColor(vec4 color) { - gl_FragColor = color; -} - diff --git a/resources/shaders/es2_common.vs.glsl b/resources/shaders/es2_common.vs.glsl deleted file mode 100644 index ccb8c3dcec5..00000000000 --- a/resources/shaders/es2_common.vs.glsl +++ /dev/null @@ -1,70 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#version 110 - -#define SERVO_ES2 - -uniform mat4 uTransform; -uniform vec4 uOffsets[32]; -uniform vec4 uClipRects[64]; -uniform mat4 uMatrixPalette[32]; -uniform vec2 uDirection; -uniform vec4 uBlendParams; -uniform vec4 uFilterParams; -uniform float uDevicePixelRatio; -uniform vec4 uTileParams[64]; - -attribute vec3 aPosition; -attribute vec4 aPositionRect; // Width can be negative to flip horizontally (for border corners). -attribute vec4 aColorRectTL; -attribute vec4 aColorRectTR; -attribute vec4 aColorRectBR; -attribute vec4 aColorRectBL; -attribute vec4 aColorTexCoordRectTop; -attribute vec4 aColorTexCoordRectBottom; -attribute vec4 aMaskTexCoordRectTop; -attribute vec4 aMaskTexCoordRectBottom; -attribute vec4 aBorderPosition; -attribute vec4 aBorderRadii; -attribute vec2 aSourceTextureSize; -attribute vec2 aDestTextureSize; -attribute float aBlurRadius; -// x = matrix index; y = clip-in rect; z = clip-out rect; w = tile params index. -// -// A negative w value activates border corner mode. In this mode, the TR and BL colors are ignored, -// the color of the top left corner applies to all vertices of the top left triangle, and the color -// of the bottom right corner applies to all vertices of the bottom right triangle. -attribute vec4 aMisc; - -varying vec2 vPosition; -varying vec4 vColor; -varying vec2 vColorTexCoord; -varying vec2 vMaskTexCoord; -varying vec4 vBorderPosition; -varying vec4 vBorderRadii; -varying vec2 vDestTextureSize; -varying vec2 vSourceTextureSize; -varying float vBlurRadius; -varying vec4 vTileParams; -varying vec4 vClipInRect; -varying vec4 vClipOutRect; - -int Bottom7Bits(int value) { - return value % 0x80; -} - -bool IsBottomTriangle() { - // FIXME(pcwalton): No gl_VertexID in OpenGL ES 2. We'll need some extra data. - return false; -} - -vec2 SnapToPixels(vec2 pos) -{ - // Snap the vertex to pixel position to guarantee correct texture - // sampling when using bilinear filtering. - - // TODO(gw): ES2 doesn't have round(). Do we ever get negative coords here? - return floor(0.5 + pos * uDevicePixelRatio) / uDevicePixelRatio; -} diff --git a/resources/shaders/filter.fs.glsl b/resources/shaders/filter.fs.glsl deleted file mode 100644 index b4b5b707d5f..00000000000 --- a/resources/shaders/filter.fs.glsl +++ /dev/null @@ -1,148 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -vec3 rgbToHsv(vec3 c) { - float value = max(max(c.r, c.g), c.b); - - float chroma = value - min(min(c.r, c.g), c.b); - if (chroma == 0.0) { - return vec3(0.0); - } - float saturation = chroma / value; - - float hue; - if (c.r == value) - hue = (c.g - c.b) / chroma; - else if (c.g == value) - hue = 2.0 + (c.b - c.r) / chroma; - else // if (c.b == value) - hue = 4.0 + (c.r - c.g) / chroma; - - hue *= 1.0/6.0; - if (hue < 0.0) - hue += 1.0; - return vec3(hue, saturation, value); -} - -vec3 hsvToRgb(vec3 c) { - if (c.s == 0.0) { - return vec3(c.z); - } - - float hue = c.x * 6.0; - int sector = int(hue); - float residualHue = hue - float(sector); - - vec3 pqt = c.z * vec3(1.0 - c.y, 1.0 - c.y * residualHue, 1.0 - c.y * (1.0 - residualHue)); - if (sector == 0) - return vec3(c.z, pqt.z, pqt.x); - if (sector == 1) - return vec3(pqt.y, c.z, pqt.x); - if (sector == 2) - return vec3(pqt.x, c.z, pqt.z); - if (sector == 3) - return vec3(pqt.x, pqt.y, c.z); - if (sector == 4) - return vec3(pqt.z, pqt.x, c.z); - return vec3(c.z, pqt.x, pqt.y); -} - -float gauss(float x, float sigma) { - if (sigma == 0.0) - return 1.0; - return (1.0 / sqrt(6.283185307179586 * sigma * sigma)) * exp(-(x * x) / (2.0 * sigma * sigma)); -} - -vec4 Blur(float radius, vec2 direction) { -#ifdef SERVO_ES2 - // TODO(gw): for loops have to be unrollable on es2. - return vec4(1.0, 0.0, 0.0, 1.0); -#else - int range = int(radius) * 3; - float sigma = radius / 2.0; - vec4 color = vec4(0.0); - for (int offset = -range; offset <= range; offset++) { - float offsetF = float(offset); - - // Here, we use the vMaskTexCoord.xy (i.e. the muv) to store the texture size. - vec2 texCoord = vColorTexCoord.xy + vec2(offsetF) / vMaskTexCoord.xy * direction; - vec4 x = texCoord.x >= 0.0 && - texCoord.x <= 1.0 && - texCoord.y >= 0.0 && - texCoord.y <= 1.0 ? - Texture(sDiffuse, texCoord) : - vec4(0.0); - color += x * gauss(offsetF, sigma); - } - return color; -#endif -} - -vec4 Contrast(vec4 Cs, float amount) { - return vec4(Cs.rgb * amount - 0.5 * amount + 0.5, 1.0); -} - -vec4 Grayscale(vec4 Cs, float amount) { - float ia = 1.0 - amount; - return mat4(vec4(0.2126 + 0.7874 * ia, 0.2126 - 0.2126 * ia, 0.2126 - 0.2126 * ia, 0.0), - vec4(0.7152 - 0.7152 * ia, 0.7152 + 0.2848 * ia, 0.7152 - 0.7152 * ia, 0.0), - vec4(0.0722 - 0.0722 * ia, 0.0722 - 0.0722 * ia, 0.0722 + 0.9278 * ia, 0.0), - vec4(0.0, 0.0, 0.0, 1.0)) * Cs; -} - -vec4 HueRotate(vec4 Cs, float amount) { - vec3 CsHsv = rgbToHsv(Cs.rgb); - CsHsv.x = mod(CsHsv.x + amount / 6.283185307179586, 1.0); - return vec4(hsvToRgb(CsHsv), Cs.a); -} - -vec4 Invert(vec4 Cs, float amount) { - return mix(Cs, vec4(1.0, 1.0, 1.0, Cs.a) - vec4(Cs.rgb, 0.0), amount); -} - -vec4 Saturate(vec4 Cs, float amount) { - return vec4(hsvToRgb(min(vec3(1.0, amount, 1.0) * rgbToHsv(Cs.rgb), vec3(1.0))), Cs.a); -} - -vec4 Sepia(vec4 Cs, float amount) { - float ia = 1.0 - amount; - return mat4(vec4(0.393 + 0.607 * ia, 0.349 - 0.349 * ia, 0.272 - 0.272 * ia, 0.0), - vec4(0.769 - 0.769 * ia, 0.686 + 0.314 * ia, 0.534 - 0.534 * ia, 0.0), - vec4(0.189 - 0.189 * ia, 0.168 - 0.168 * ia, 0.131 + 0.869 * ia, 0.0), - vec4(0.0, 0.0, 0.0, 1.0)) * Cs; -} - -void main(void) -{ - // TODO: May be best to have separate shaders (esp. on Tegra) - int filterOp = int(uFilterParams.x); - float amount = uFilterParams.y; - - // Return yellow if none of the branches match (shouldn't happen). - vec4 result = vec4(1.0, 1.0, 0.0, 1.0); - - if (filterOp == 0) { - // Gaussian blur is specially handled: - result = Blur(amount, uFilterParams.zw); - } else { - vec4 Cs = Texture(sDiffuse, vColorTexCoord); - - if (filterOp == 1) { - result = Contrast(Cs, amount); - } else if (filterOp == 2) { - result = Grayscale(Cs, amount); - } else if (filterOp == 3) { - result = HueRotate(Cs, amount); - } else if (filterOp == 4) { - result = Invert(Cs, amount); - } else if (filterOp == 5) { - result = Saturate(Cs, amount); - } else if (filterOp == 6) { - result = Sepia(Cs, amount); - } - } - - SetFragColor(result); -} - diff --git a/resources/shaders/filter.vs.glsl b/resources/shaders/filter.vs.glsl deleted file mode 100644 index a8d526383bc..00000000000 --- a/resources/shaders/filter.vs.glsl +++ /dev/null @@ -1,12 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void main(void) -{ - vColorTexCoord = aColorTexCoordRectTop.xy; - vMaskTexCoord = aMaskTexCoordRectTop.xy; - vec4 pos = vec4(aPosition, 1.0); - pos.xy = SnapToPixels(pos.xy); - gl_Position = uTransform * pos; -} diff --git a/resources/shaders/gl3_common.fs.glsl b/resources/shaders/gl3_common.fs.glsl deleted file mode 100644 index e88e921f65f..00000000000 --- a/resources/shaders/gl3_common.fs.glsl +++ /dev/null @@ -1,41 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#define SERVO_GL3 - -precision highp float; - -uniform sampler2D sDiffuse; -uniform sampler2D sMask; -uniform vec4 uBlendParams; -uniform vec2 uDirection; -uniform vec4 uFilterParams; - -in vec2 vPosition; -in vec4 vColor; -in vec2 vColorTexCoord; -in vec2 vMaskTexCoord; -in vec4 vBorderPosition; -in vec4 vBorderRadii; -in vec2 vDestTextureSize; -in vec2 vSourceTextureSize; -in float vBlurRadius; -in vec4 vTileParams; -in vec4 vClipInRect; -in vec4 vClipOutRect; - -out vec4 oFragColor; - -vec4 Texture(sampler2D sampler, vec2 texCoord) { - return texture(sampler, texCoord); -} - -float GetAlphaFromMask(vec4 mask) { - return mask.r; -} - -void SetFragColor(vec4 color) { - oFragColor = color; -} - diff --git a/resources/shaders/gl3_common.vs.glsl b/resources/shaders/gl3_common.vs.glsl deleted file mode 100644 index cffcfc80eb7..00000000000 --- a/resources/shaders/gl3_common.vs.glsl +++ /dev/null @@ -1,66 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#define SERVO_GL3 - -uniform mat4 uTransform; -uniform vec4 uOffsets[32]; -uniform vec4 uClipRects[64]; -uniform mat4 uMatrixPalette[32]; -uniform vec2 uDirection; -uniform vec4 uBlendParams; -uniform vec4 uFilterParams; -uniform float uDevicePixelRatio; -uniform vec4 uTileParams[64]; -uniform vec4 uAtlasParams; - -in vec3 aPosition; -in vec4 aPositionRect; // Width can be negative to flip horizontally (for border corners). -in vec4 aColorRectTL; -in vec4 aColorRectTR; -in vec4 aColorRectBR; -in vec4 aColorRectBL; -in vec4 aColorTexCoordRectTop; -in vec4 aColorTexCoordRectBottom; -in vec4 aMaskTexCoordRectTop; -in vec4 aMaskTexCoordRectBottom; -in vec4 aBorderPosition; -in vec4 aBorderRadii; -in vec2 aSourceTextureSize; -in vec2 aDestTextureSize; -in float aBlurRadius; -// x = matrix index; y = clip-in rect; z = clip-out rect; w = tile params index. -// -// A negative w value activates border corner mode. In this mode, the TR and BL colors are ignored, -// the color of the top left corner applies to all vertices of the top left triangle, and the color -// of the bottom right corner applies to all vertices of the bottom right triangle. -in vec4 aMisc; - -out vec2 vPosition; -out vec4 vColor; -out vec2 vColorTexCoord; -out vec2 vMaskTexCoord; -out vec4 vBorderPosition; -out vec4 vBorderRadii; -out vec2 vDestTextureSize; -out vec2 vSourceTextureSize; -out float vBlurRadius; -out vec4 vTileParams; -out vec4 vClipInRect; -out vec4 vClipOutRect; - -int Bottom7Bits(int value) { - return value & 0x7f; -} - -bool IsBottomTriangle() { - return gl_VertexID > 2; -} - -vec2 SnapToPixels(vec2 pos) -{ - // Snap the vertex to pixel position to guarantee correct texture - // sampling when using bilinear filtering. - return round(pos * uDevicePixelRatio) / uDevicePixelRatio; -} diff --git a/resources/shaders/ps_text.fs.glsl b/resources/shaders/ps_text.fs.glsl deleted file mode 100644 index 79051beb583..00000000000 --- a/resources/shaders/ps_text.fs.glsl +++ /dev/null @@ -1,13 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void main(void) { - float a = texture(sDiffuse, vUv).a; -#ifdef WR_FEATURE_TRANSFORM - float alpha = 0.0; - init_transform_fs(vLocalPos, vLocalRect, alpha); - a *= alpha; -#endif - oFragColor = vec4(vColor.rgb, vColor.a * a); -} diff --git a/resources/shaders/ps_text.glsl b/resources/shaders/ps_text.glsl deleted file mode 100644 index d58ff7d14bb..00000000000 --- a/resources/shaders/ps_text.glsl +++ /dev/null @@ -1,11 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -flat varying vec4 vColor; -varying vec2 vUv; - -#ifdef WR_FEATURE_TRANSFORM -varying vec3 vLocalPos; -flat varying vec4 vLocalRect; -#endif diff --git a/resources/shaders/ps_text.vs.glsl b/resources/shaders/ps_text.vs.glsl deleted file mode 100644 index 18d5f5530fa..00000000000 --- a/resources/shaders/ps_text.vs.glsl +++ /dev/null @@ -1,25 +0,0 @@ -#line 1 -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void main(void) { - Glyph glyph = fetch_glyph(gl_InstanceID); - -#ifdef WR_FEATURE_TRANSFORM - TransformVertexInfo vi = write_transform_vertex(glyph.info); - vLocalRect = vi.clipped_local_rect; - vLocalPos = vi.local_pos; - vec2 f = (vi.local_pos.xy / vi.local_pos.z - glyph.info.local_rect.xy) / glyph.info.local_rect.zw; -#else - VertexInfo vi = write_vertex(glyph.info); - vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0); -#endif - - vec2 texture_size = vec2(textureSize(sDiffuse, 0)); - vec2 st0 = glyph.uv_rect.xy / texture_size; - vec2 st1 = glyph.uv_rect.zw / texture_size; - - vColor = glyph.color; - vUv = mix(st0, st1, f); -}