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

Sync changes from mozilla-central gfx/wr #3841

Merged
merged 7 commits into from Jan 23, 2020

Bug 1606771 - Implement border-image-repeat: round in WebRender. r=jr…

…muizel,kvark

border-image-repeat: Round is equivalent to Repeat with the pattern size adjusted to fill the area with a whole number of repetitions. This is done by adjusting the segment's stretch_size in the shader so that it fits a whole number of times in the segment's size.

Differential Revision: https://phabricator.services.mozilla.com/D59370

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/6b61867f80b123f11aa3e9252f0ac005a12787c0
  • Loading branch information
nical authored and moz-gfx committed Jan 23, 2020
commit 492b36638ff93322c6e41e30982a90f6998a1e8e
@@ -112,7 +112,9 @@ void multi_brush_vs(
#define BRUSH_FLAG_SEGMENT_RELATIVE 2
#define BRUSH_FLAG_SEGMENT_REPEAT_X 4
#define BRUSH_FLAG_SEGMENT_REPEAT_Y 8
#define BRUSH_FLAG_TEXEL_RECT 16
#define BRUSH_FLAG_SEGMENT_REPEAT_X_ROUND 16
#define BRUSH_FLAG_SEGMENT_REPEAT_Y_ROUND 32
#define BRUSH_FLAG_TEXEL_RECT 64

#define INVALID_SEGMENT_INDEX 0xffff

@@ -103,20 +103,35 @@ void image_brush_vs(
uv0 = res.uv_rect.p0 + segment_data.xy * uv_size;
uv1 = res.uv_rect.p0 + segment_data.zw * uv_size;

#ifdef WR_FEATURE_REPETITION
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_X) != 0) {
stretch_size.x = local_rect.size.y / dy * dx;
}
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_Y) != 0) {
stretch_size.y = local_rect.size.x / dx * dy;
}
#endif
} else {
#ifdef WR_FEATURE_REPETITION
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_X) != 0) {
stretch_size.x = dx;
}
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_Y) != 0) {
stretch_size.y = dy;
}
#endif
}

#ifdef WR_FEATURE_REPETITION
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_X_ROUND) != 0) {
float nx = max(1.0, round(segment_rect.size.x / stretch_size.x));
stretch_size.x = segment_rect.size.x / nx;
}
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_Y_ROUND) != 0) {
float ny = max(1.0, round(segment_rect.size.y / stretch_size.y));
stretch_size.y = segment_rect.size.y / ny;
}
#endif
}

float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0;
@@ -1351,38 +1351,43 @@ impl NinePatchDescriptor {
repeat_horizontal: RepeatMode,
repeat_vertical: RepeatMode
) {
if uv_rect.uv1.x > uv_rect.uv0.x &&
uv_rect.uv1.y > uv_rect.uv0.y {

// Use segment relative interpolation for all
// instances in this primitive.
let mut brush_flags =
BrushFlags::SEGMENT_RELATIVE |
BrushFlags::SEGMENT_TEXEL_RECT;

// Enable repeat modes on the segment.
if repeat_horizontal == RepeatMode::Repeat {
brush_flags |= BrushFlags::SEGMENT_REPEAT_X;
}
if repeat_vertical == RepeatMode::Repeat {
brush_flags |= BrushFlags::SEGMENT_REPEAT_Y;
}
if uv_rect.uv1.x < uv_rect.uv0.x || uv_rect.uv1.y < uv_rect.uv0.y {
return;
}

// Use segment relative interpolation for all
// instances in this primitive.
let mut brush_flags =
BrushFlags::SEGMENT_RELATIVE |
BrushFlags::SEGMENT_TEXEL_RECT;

// Enable repeat modes on the segment.
if repeat_horizontal == RepeatMode::Repeat {
brush_flags |= BrushFlags::SEGMENT_REPEAT_X;
} else if repeat_horizontal == RepeatMode::Round {
brush_flags |= BrushFlags::SEGMENT_REPEAT_X | BrushFlags::SEGMENT_REPEAT_X_ROUND;
}

let segment = BrushSegment::new(
rect,
true,
EdgeAaSegmentMask::empty(),
[
uv_rect.uv0.x,
uv_rect.uv0.y,
uv_rect.uv1.x,
uv_rect.uv1.y,
],
brush_flags,
);

segments.push(segment);
if repeat_vertical == RepeatMode::Repeat {
brush_flags |= BrushFlags::SEGMENT_REPEAT_Y;
} else if repeat_vertical == RepeatMode::Round {
brush_flags |= BrushFlags::SEGMENT_REPEAT_Y | BrushFlags::SEGMENT_REPEAT_Y_ROUND;
}

let segment = BrushSegment::new(
rect,
true,
EdgeAaSegmentMask::empty(),
[
uv_rect.uv0.x,
uv_rect.uv0.y,
uv_rect.uv1.x,
uv_rect.uv1.y,
],
brush_flags,
);

segments.push(segment);
}

// Build the list of image segments
@@ -403,16 +403,20 @@ bitflags! {
#[derive(MallocSizeOf)]
pub struct BrushFlags: u8 {
/// Apply perspective interpolation to UVs
const PERSPECTIVE_INTERPOLATION = 0x1;
const PERSPECTIVE_INTERPOLATION = 1;
/// Do interpolation relative to segment rect,
/// rather than primitive rect.
const SEGMENT_RELATIVE = 0x2;
const SEGMENT_RELATIVE = 2;
/// Repeat UVs horizontally.
const SEGMENT_REPEAT_X = 0x4;
const SEGMENT_REPEAT_X = 4;
/// Repeat UVs vertically.
const SEGMENT_REPEAT_Y = 0x8;
const SEGMENT_REPEAT_Y = 8;
/// Horizontally follow border-image-repeat: round
const SEGMENT_REPEAT_X_ROUND = 16;
/// Vorizontally follow border-image-repeat: round
const SEGMENT_REPEAT_Y_ROUND = 32;
/// The extra segment data is a texel rect.
const SEGMENT_TEXEL_RECT = 0x10;
const SEGMENT_TEXEL_RECT = 64;
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.