Skip to content

Commit

Permalink
Update webrender + shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Aug 16, 2016
1 parent cb01d37 commit 1242a0d
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions resources/shaders/ps_border.fs.glsl
Expand Up @@ -56,6 +56,57 @@ vec4 draw_dotted_edge() {
return mix(white, circleColor, circleColor.a);
}

vec4 draw_double_edge(float pos, float len) {
// Devided border to 3 parts, draw color on first and third part,
// leave second part blank.
float one_third_len = len / 3.0;

float in_first_part = step(pos, one_third_len);
float in_third_part = step(len - one_third_len, pos);

// The result of this should be 1.0 if we're in the 1st or 3rd part.
// And 0.0 for the blank part.
float should_fill = in_first_part + in_third_part;

float color_weight = step(0.0, vF);
vec4 color = mix(vHorizontalColor, vVerticalColor, color_weight);

vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
return mix(white, color, should_fill);
}

vec4 draw_double_edge_vertical() {
// Get our position within this specific segment
float position = vLocalPos.x - vLocalBorders.x;
return draw_double_edge(position, vLocalBorders.z);
}

vec4 draw_double_edge_horizontal() {
// Get our position within this specific segment
float position = vLocalPos.y - vLocalBorders.y;
return draw_double_edge(position, vLocalBorders.w);
}

vec4 draw_double_edge_with_radius() {
// Get our position within this specific segment
float position = distance(vRefPoint, vLocalPos) - vRadii.z;
float len = vRadii.x - vRadii.z;
return draw_double_edge(position, len);
}

vec4 draw_double_edge_corner() {
if (vRadii.x > 0) {
return draw_double_edge_with_radius();
}

bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vF < 0 : vF >= 0;
if (is_vertical) {
return draw_double_edge_vertical();
} else {
return draw_double_edge_horizontal();
}
}

// Our current edge calculation is based only on
// the size of the border-size, but we need to draw
// the dashes in the center of the segment we're drawing.
Expand Down Expand Up @@ -144,6 +195,32 @@ void draw_dashed_border(void) {
}
}

void draw_double_border(void) {
switch (vBorderPart) {
// These are the layer tile part PrimitivePart as uploaded by the tiling.rs
case PST_TOP_LEFT:
case PST_TOP_RIGHT:
case PST_BOTTOM_LEFT:
case PST_BOTTOM_RIGHT:
{
oFragColor = draw_double_edge_corner();
break;
}
case PST_BOTTOM:
case PST_TOP:
{
oFragColor = draw_double_edge_horizontal();
break;
}
case PST_LEFT:
case PST_RIGHT:
{
oFragColor = draw_double_edge_vertical();
break;
}
}
}

// TODO: Investigate performance of this shader and see
// if it's worthwhile splitting it / removing branches etc.
void main(void) {
Expand Down Expand Up @@ -178,6 +255,11 @@ void main(void) {
oFragColor = mix(vHorizontalColor, vVerticalColor, color);
break;
}
case BORDER_STYLE_DOUBLE:
{
draw_double_border();
break;
}
default:
{
discard;
Expand Down
1 change: 1 addition & 0 deletions resources/shaders/ps_border.glsl
Expand Up @@ -16,6 +16,7 @@ flat varying vec4 vRadii; // The border radius from CSS border-radiu
varying vec2 vLocalPos; // The clamped position in local space.
varying vec2 vDevicePos; // The clamped position in device space.
flat varying vec4 vBorders; // the rect of the border in (x, y, width, height) form
flat varying vec4 vLocalBorders; // The rect of the border (x, y, w, h) in local space.

// for corners, this is the beginning of the corner.
// For the lines, this is the top left of the line.
Expand Down
3 changes: 3 additions & 0 deletions resources/shaders/ps_border.vs.glsl
Expand Up @@ -103,6 +103,9 @@ void main(void) {
// Local space
vLocalPos = vi.local_clamped_pos.xy;

// Local space
vLocalBorders = border.info.local_rect;

// These are in device space
vDevicePos = vi.global_clamped_pos;

Expand Down
10 changes: 6 additions & 4 deletions resources/shaders/ps_text.vs.glsl
Expand Up @@ -6,7 +6,7 @@
struct Glyph {
PrimitiveInfo info;
vec4 color;
vec4 st_rect;
ivec4 uv_rect;
};

layout(std140) uniform Items {
Expand All @@ -19,8 +19,10 @@ void main(void) {

vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);

vec2 texture_size = textureSize(sDiffuse, 0);
vec2 st0 = glyph.uv_rect.xy / texture_size;
vec2 st1 = glyph.uv_rect.zw / texture_size;

vColor = glyph.color;
vUv = mix(glyph.st_rect.xy,
glyph.st_rect.zw,
f);
vUv = mix(st0, st1, f);
}
6 changes: 5 additions & 1 deletion resources/shaders/shared.glsl
Expand Up @@ -25,13 +25,17 @@
#define varying in

// Uniform inputs
uniform sampler2D sDiffuse;
uniform sampler2D sMask;

// Fragment shader outputs
out vec4 oFragColor;
#endif

//======================================================================================
// Shared shader uniforms
//======================================================================================
uniform sampler2D sDiffuse;

//======================================================================================
// Interpolator definitions
//======================================================================================
Expand Down

0 comments on commit 1242a0d

Please sign in to comment.