Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webrender, copy new shaders, pin ipc-channel. #12711

Merged
merged 4 commits into from Aug 3, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Copy shaders from WR repo.

  • Loading branch information
gw3583 authored and Ms2ger committed Aug 3, 2016
commit 2ebf8618c03bd3019299c3c55a9c67e7e63c248d
@@ -28,7 +28,7 @@ void main(void) {
lColorTexCoord.x <= 1.0 &&
lColorTexCoord.y >= 0.0 &&
lColorTexCoord.y <= 1.0 ?
Texture(sDiffuse, lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin) :
texture(sDiffuse, lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin) :
vec4(0.0);

// Alpha must be premultiplied in order to properly blur the alpha channel.
@@ -141,6 +141,8 @@ void main(void) {
vec2 radii = vBorderRadii.xy;
float sigma = vBlurRadius / 2.0;
float value = color(pos, p0Rect, p1Rect, radii, sigma);
SetFragColor(vec4(vColor.rgb, max(value, 0.0)));

value = max(value, 0.0);
SetFragColor(vec4(vColor.rgb, vColor.a == 0.0 ? 1.0 - value : value));
}

@@ -4,5 +4,5 @@

void main(void)
{
SetFragColor(vColor);
oFragColor = vColor;
}
@@ -5,9 +5,9 @@
void main(void)
{
#ifdef SERVO_ES2
float alpha = Texture(sDiffuse, vColorTexCoord.xy).a;
float alpha = texture(sDiffuse, vColorTexCoord.xy).a;
#else
float alpha = Texture(sDiffuse, vColorTexCoord.xy).r;
float alpha = texture(sDiffuse, vColorTexCoord.xy).r;
#endif
SetFragColor(vec4(vColor.xyz, vColor.w * alpha));
oFragColor = vec4(vColor.xyz, vColor.w * alpha);
}
@@ -65,6 +65,6 @@ vec2 SnapToPixels(vec2 pos)
// Snap the vertex to pixel position to guarantee correct texture
// sampling when using bilinear filtering.

// TODO(gw): Do we ever get negative coords here?
// TODO(gw): ES2 doesn't have round(). Do we ever get negative coords here?
return floor(0.5 + pos * uDevicePixelRatio) / uDevicePixelRatio;
}
@@ -62,8 +62,5 @@ vec2 SnapToPixels(vec2 pos)
{
// Snap the vertex to pixel position to guarantee correct texture
// sampling when using bilinear filtering.

// Don't use round() because its behavior is implementation-defined on 0.5.
// TODO: Do we ever get negative coords here?
return floor(0.5 + pos * uDevicePixelRatio) / uDevicePixelRatio;
return round(pos * uDevicePixelRatio) / uDevicePixelRatio;
}
@@ -0,0 +1,180 @@
#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/. */

#define PST_INVALID uint(0)
#define PST_TOP_LEFT uint(1)
#define PST_TOP_RIGHT uint(2)
#define PST_BOTTOM_LEFT uint(3)
#define PST_BOTTOM_RIGHT uint(4)
#define PST_TOP uint(5)
#define PST_LEFT uint(6)
#define PST_BOTTOM uint(7)
#define PST_RIGHT uint(8)

// Border styles as defined in webrender_traits/types.rs
#define BORDER_STYLE_NONE uint(0)
#define BORDER_STYLE_SOLID uint(1)
#define BORDER_STYLE_DOUBLE uint(2)
#define BORDER_STYLE_DOTTED uint(3)
#define BORDER_STYLE_DASHED uint(4)
#define BORDER_STYLE_HIDDEN uint(5)
#define BORDER_STYLE_GROOVE uint(6)
#define BORDER_STYLE_RIDGE uint(7)
#define BORDER_STYLE_INSET uint(8)
#define BORDER_STYLE_OUTSET uint(9)

#ifdef WR_VERTEX_SHADER
struct Layer {
mat4 transform;
mat4 inv_transform;
ivec4 world_clip_rect;
vec4 screen_vertices[4];
};

layout(std140) uniform Layers {
Layer layers[WR_MAX_PRIM_LAYERS];
};

struct Tile {
uvec4 actual_rect;
uvec4 target_rect;
};

layout(std140) uniform Tiles {
Tile tiles[WR_MAX_PRIM_TILES];
};

struct PrimitiveInfo {
uvec4 layer_tile_part;
vec4 local_clip_rect;
vec4 local_rect;
};

struct ClipCorner {
vec4 rect;
vec4 outer_inner_radius;
};

struct Clip {
vec4 rect;
ClipCorner top_left;
ClipCorner top_right;
ClipCorner bottom_left;
ClipCorner bottom_right;
};

bool ray_plane(vec3 normal, vec3 point, vec3 ray_origin, vec3 ray_dir, out float t)
{
float denom = dot(normal, ray_dir);
if (denom > 1e-6) {
vec3 d = point - ray_origin;
t = dot(d, normal) / denom;
return t >= 0.0;
}

return false;
}

vec4 untransform(vec2 ref, vec3 n, vec3 a, mat4 inv_transform) {
vec3 p = vec3(ref, -10000.0);
vec3 d = vec3(0, 0, 1.0);

float t;
ray_plane(n, a, p, d, t);
vec3 c = p + d * t;

vec4 r = inv_transform * vec4(c, 1.0);
return r;
}

vec3 get_layer_pos(vec2 pos, uint layer_index) {
Layer layer = layers[layer_index];
vec3 a = layer.screen_vertices[0].xyz / layer.screen_vertices[0].w;
vec3 b = layer.screen_vertices[3].xyz / layer.screen_vertices[3].w;
vec3 c = layer.screen_vertices[2].xyz / layer.screen_vertices[2].w;
vec3 n = normalize(cross(b-a, c-a));
vec4 local_pos = untransform(pos, n, a, layer.inv_transform);
return local_pos.xyw;
}

struct Rect {
vec2 p0;
vec2 p1;
};

struct VertexInfo {
Rect local_rect;
vec2 local_clamped_pos;
vec2 global_clamped_pos;
};

VertexInfo write_vertex(PrimitiveInfo info) {
Layer layer = layers[info.layer_tile_part.x];
Tile tile = tiles[info.layer_tile_part.y];

vec2 p0 = floor(0.5 + info.local_rect.xy * uDevicePixelRatio) / uDevicePixelRatio;
vec2 p1 = floor(0.5 + (info.local_rect.xy + info.local_rect.zw) * uDevicePixelRatio) / uDevicePixelRatio;

vec2 local_pos = mix(p0, p1, aPosition.xy);

vec2 cp0 = floor(0.5 + info.local_clip_rect.xy * uDevicePixelRatio) / uDevicePixelRatio;
vec2 cp1 = floor(0.5 + (info.local_clip_rect.xy + info.local_clip_rect.zw) * uDevicePixelRatio) / uDevicePixelRatio;
local_pos = clamp(local_pos, cp0, cp1);

vec4 world_pos = layer.transform * vec4(local_pos, 0, 1);
world_pos.xyz /= world_pos.w;

vec2 device_pos = world_pos.xy * uDevicePixelRatio;

vec2 clamped_pos = clamp(device_pos,
vec2(tile.actual_rect.xy),
vec2(tile.actual_rect.xy + tile.actual_rect.zw));

clamped_pos = clamp(clamped_pos,
vec2(layer.world_clip_rect.xy),
vec2(layer.world_clip_rect.xy + layer.world_clip_rect.zw));

vec4 local_clamped_pos = layer.inv_transform * vec4(clamped_pos / uDevicePixelRatio, world_pos.z, 1);
local_clamped_pos.xyz /= local_clamped_pos.w;

vec2 final_pos = clamped_pos + vec2(tile.target_rect.xy) - vec2(tile.actual_rect.xy);

gl_Position = uTransform * vec4(final_pos, 0, 1);

VertexInfo vi = VertexInfo(Rect(p0, p1), local_clamped_pos.xy, clamped_pos.xy);
return vi;
}
#endif

#ifdef WR_FRAGMENT_SHADER
void do_clip(vec2 pos, vec4 clip_rect, vec4 radius) {
vec2 ref_tl = clip_rect.xy + vec2( radius.x, radius.x);
vec2 ref_tr = clip_rect.zy + vec2(-radius.y, radius.y);
vec2 ref_br = clip_rect.zw + vec2(-radius.z, -radius.z);
vec2 ref_bl = clip_rect.xw + vec2( radius.w, -radius.w);

float d_tl = distance(pos, ref_tl);
float d_tr = distance(pos, ref_tr);
float d_br = distance(pos, ref_br);
float d_bl = distance(pos, ref_bl);

bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > radius.x;
bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > radius.y;
bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > radius.z;
bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > radius.w;

// TODO(gw): Alpha anti-aliasing based on edge distance!
if (out0 || out1 || out2 || out3) {
discard;
}
}

bool point_in_rect(vec2 p, vec2 p0, vec2 p1) {
return p.x >= p0.x &&
p.y >= p0.y &&
p.x <= p1.x &&
p.y <= p1.y;
}
#endif
@@ -0,0 +1,39 @@
/* 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/. */

float offset(int index) {
return vOffsets[index / 4][index % 4];
}

float linearStep(float lo, float hi, float x) {
float d = hi - lo;
float v = x - lo;
if (d != 0.0) {
v /= d;
}
return clamp(v, 0.0, 1.0);
}

void main(void) {
float angle = atan(-vEndPoint.y + vStartPoint.y,
vEndPoint.x - vStartPoint.x);
float sa = sin(angle);
float ca = cos(angle);

float sx = vStartPoint.x * ca - vStartPoint.y * sa;
float ex = vEndPoint.x * ca - vEndPoint.y * sa;
float d = ex - sx;

float x = vPos.x * ca - vPos.y * sa;

oFragColor = mix(vColors[0],
vColors[1],
linearStep(sx + d * offset(0), sx + d * offset(1), x));

for (int i=1 ; i < vStopCount-1 ; ++i) {
oFragColor = mix(oFragColor,
vColors[i+1],
linearStep(sx + d * offset(i), sx + d * offset(i+1), x));
}
}
@@ -0,0 +1,13 @@
/* 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 MAX_STOPS_PER_ANGLE_GRADIENT 8

flat varying int vStopCount;
flat varying float vAngle;
flat varying vec2 vStartPoint;
flat varying vec2 vEndPoint;
varying vec2 vPos;
flat varying vec4 vColors[MAX_STOPS_PER_ANGLE_GRADIENT];
flat varying vec4 vOffsets[MAX_STOPS_PER_ANGLE_GRADIENT/4];
@@ -0,0 +1,38 @@
#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/. */

struct AngleGradient {
PrimitiveInfo info;
vec4 start_end_point;
uvec4 stop_count;
vec4 colors[MAX_STOPS_PER_ANGLE_GRADIENT];
vec4 offsets[MAX_STOPS_PER_ANGLE_GRADIENT/4];
};

layout(std140) uniform Items {
AngleGradient gradients[WR_MAX_PRIM_ITEMS];
};

void main(void) {
AngleGradient gradient = gradients[gl_InstanceID];
VertexInfo vi = write_vertex(gradient.info);

vStopCount = int(gradient.stop_count.x);
vPos = vi.local_clamped_pos;

// Snap the start/end points to device pixel units.
// I'm not sure this is entirely correct, but the
// old render path does this, and it is needed to
// make the angle gradient ref tests pass. It might
// be better to fix this higher up in DL construction
// and not snap here?
vStartPoint = floor(0.5 + gradient.start_end_point.xy * uDevicePixelRatio) / uDevicePixelRatio;
vEndPoint = floor(0.5 + gradient.start_end_point.zw * uDevicePixelRatio) / uDevicePixelRatio;

for (int i=0 ; i < int(gradient.stop_count.x) ; ++i) {
vColors[i] = gradient.colors[i];
vOffsets[i] = gradient.offsets[i];
}
}
@@ -0,0 +1,10 @@
/* 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/. */

uniform sampler2D sCache;

void main(void) {
vec4 color = texture(sCache, vUv);
oFragColor = vec4(color.rgb, color.a * vOpacity);
}
@@ -0,0 +1,6 @@
/* 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/. */

varying vec2 vUv;
varying float vOpacity;
@@ -0,0 +1,29 @@
#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/. */

struct Blend {
uvec4 target_rect;
uvec4 src_rect;
vec4 opacity;
};

layout(std140) uniform Items {
Blend blends[WR_MAX_PRIM_ITEMS];
};

void main(void) {
Blend blend = blends[gl_InstanceID];

vec2 local_pos = mix(vec2(blend.target_rect.xy),
vec2(blend.target_rect.xy + blend.target_rect.zw),
aPosition.xy);

vec2 st0 = vec2(blend.src_rect.xy) / 2048.0;
vec2 st1 = vec2(blend.src_rect.xy + blend.src_rect.zw) / 2048.0;
vUv = mix(st0, st1, aPosition.xy);
vOpacity = blend.opacity.x;

gl_Position = uTransform * vec4(local_pos, 0, 1);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.