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

Extend segment building to handle clip in/out, multiple clip regions. #2242

Merged
merged 4 commits into from Dec 20, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -14,21 +14,8 @@ void brush_vs(
#define RASTERIZATION_MODE_LOCAL_SPACE 0.0
#define RASTERIZATION_MODE_SCREEN_SPACE 1.0

#define SEGMENT_ALL 0
#define SEGMENT_TOP_LEFT 1
#define SEGMENT_TOP_RIGHT 2
#define SEGMENT_BOTTOM_RIGHT 3
#define SEGMENT_BOTTOM_LEFT 4
#define SEGMENT_TOP_MID 5
#define SEGMENT_MID_RIGHT 6
#define SEGMENT_BOTTOM_MID 7
#define SEGMENT_MID_LEFT 8
#define SEGMENT_CENTER 9

#define AA_KIND_DEFAULT 0
#define AA_KIND_SEGMENT 1

#define VECS_PER_BRUSH_PRIM 4
#define VECS_PER_BRUSH_PRIM 2
#define VECS_PER_SEGMENT 2

struct BrushInstance {
int picture_address;
@@ -37,7 +24,7 @@ struct BrushInstance {
int scroll_node_id;
int clip_address;
int z;
int segment_kind;
int segment_index;
ivec2 user_data;
};

@@ -50,7 +37,7 @@ BrushInstance load_brush() {
bi.scroll_node_id = aData0.z % 65536;
bi.clip_address = aData0.w;
bi.z = aData1.x;
bi.segment_kind = aData1.y;
bi.segment_index = aData1.y;
bi.user_data = aData1.zw;

return bi;
@@ -59,18 +46,14 @@ BrushInstance load_brush() {
struct BrushPrimitive {
RectWithSize local_rect;
RectWithSize local_clip_rect;
vec4 offsets;
int aa_kind;
};

BrushPrimitive fetch_brush_primitive(int address) {
vec4 data[4] = fetch_from_resource_cache_4(address);
vec4 data[2] = fetch_from_resource_cache_2(address);

BrushPrimitive prim = BrushPrimitive(
RectWithSize(data[0].xy, data[0].zw),
RectWithSize(data[1].xy, data[1].zw),
data[2],
int(data[3].x)
RectWithSize(data[1].xy, data[1].zw)
);

return prim;
@@ -86,67 +69,14 @@ void main(void) {
BrushPrimitive brush_prim = fetch_brush_primitive(brush.prim_address);

// Fetch the segment of this brush primitive we are drawing.
RectWithSize local_segment_rect;
vec4 edge_aa_segment_mask;

// p0 = origin of outer rect
// p1 = origin of inner rect
// p2 = bottom right corner of inner rect
// p3 = bottom right corner of outer rect
vec2 p0 = brush_prim.local_rect.p0;
vec2 p1 = brush_prim.local_rect.p0 + brush_prim.offsets.xy;
vec2 p2 = brush_prim.local_rect.p0 + brush_prim.local_rect.size - brush_prim.offsets.zw;
vec2 p3 = brush_prim.local_rect.p0 + brush_prim.local_rect.size;

switch (brush.segment_kind) {
case SEGMENT_ALL:
local_segment_rect = brush_prim.local_rect;
break;

case SEGMENT_TOP_LEFT:
local_segment_rect = RectWithSize(p0, p1 - p0);
break;
case SEGMENT_TOP_RIGHT:
local_segment_rect = RectWithSize(vec2(p2.x, p0.y), vec2(p3.x - p2.x, p1.y - p0.y));
break;
case SEGMENT_BOTTOM_RIGHT:
local_segment_rect = RectWithSize(vec2(p2.x, p2.y), vec2(p3.x - p2.x, p3.y - p2.y));
break;
case SEGMENT_BOTTOM_LEFT:
local_segment_rect = RectWithSize(vec2(p0.x, p2.y), vec2(p1.x - p0.x, p3.y - p2.y));
break;

case SEGMENT_TOP_MID:
local_segment_rect = RectWithSize(vec2(p1.x, p0.y), vec2(p2.x - p1.x, p1.y - p0.y));
break;
case SEGMENT_MID_RIGHT:
local_segment_rect = RectWithSize(vec2(p2.x, p1.y), vec2(p3.x - p2.x, p2.y - p1.y));
break;
case SEGMENT_BOTTOM_MID:
local_segment_rect = RectWithSize(vec2(p1.x, p2.y), vec2(p2.x - p1.x, p3.y - p2.y));
break;
case SEGMENT_MID_LEFT:
local_segment_rect = RectWithSize(vec2(p0.x, p1.y), vec2(p1.x - p0.x, p2.y - p1.y));
break;

case SEGMENT_CENTER:
local_segment_rect = RectWithSize(p1, p2 - p1);
break;

default:
local_segment_rect = RectWithSize(vec2(0.0), vec2(0.0));
break;
}

switch (brush_prim.aa_kind) {
case AA_KIND_SEGMENT:
// TODO: select these correctly based on the segment kind.
edge_aa_segment_mask = vec4(1.0);
break;
case AA_KIND_DEFAULT:
edge_aa_segment_mask = vec4(1.0);
break;
}
int segment_address = brush.prim_address +
VECS_PER_BRUSH_PRIM +
VECS_PER_SPECIFIC_BRUSH +
brush.segment_index * VECS_PER_SEGMENT;

vec4[2] segment_data = fetch_from_resource_cache_2(segment_address);
RectWithSize local_segment_rect = RectWithSize(segment_data[0].xy, segment_data[0].zw);
vec4 edge_aa_segment_mask = vec4((int(segment_data[1].x) & ivec4(1,2,4,8)) != ivec4(0));

vec2 device_pos, local_pos;

@@ -2,6 +2,8 @@
* 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 VECS_PER_SPECIFIC_BRUSH 0

#include shared,prim_shared,brush

#ifdef WR_FEATURE_ALPHA_PASS
@@ -2,6 +2,8 @@
* 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 VECS_PER_SPECIFIC_BRUSH 1

#include shared,prim_shared,ellipse,brush

flat varying float vClipMode;
@@ -2,6 +2,8 @@
* 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 VECS_PER_SPECIFIC_BRUSH 4

#include shared,prim_shared,ellipse,brush

flat varying float vClipMode;
@@ -2,6 +2,8 @@
* 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 VECS_PER_SPECIFIC_BRUSH 1

#include shared,prim_shared,brush

flat varying vec4 vColor;
@@ -9,8 +9,8 @@ use clip::ClipSource;
use ellipse::Ellipse;
use frame_builder::FrameBuilder;
use gpu_cache::GpuDataRequest;
use prim_store::{BrushAntiAliasMode, BrushSegmentDescriptor, BrushSegmentKind};
use prim_store::{BorderPrimitiveCpu, PrimitiveContainer, TexelRect};
use prim_store::{BorderPrimitiveCpu, BrushSegment, BrushSegmentDescriptor};
use prim_store::{BrushClipMaskKind, EdgeAaSegmentMask, PrimitiveContainer, TexelRect};
use util::{lerp, pack_as_float};

#[repr(u8)]
@@ -422,84 +422,90 @@ impl FrameBuilder {
let has_no_curve = radius.is_zero();

if has_no_curve && all_corners_simple && all_edges_simple {
let inner_rect = LayerRect::new(
LayerPoint::new(
info.rect.origin.x + left_len,
info.rect.origin.y + top_len,
),
LayerSize::new(
info.rect.size.width - left_len - right_len,
info.rect.size.height - top_len - bottom_len,
),
let p0 = info.rect.origin;
let p1 = LayerPoint::new(
info.rect.origin.x + left_len,
info.rect.origin.y + top_len,
);
let p2 = LayerPoint::new(
info.rect.origin.x + info.rect.size.width - right_len,
info.rect.origin.y + info.rect.size.height - bottom_len,
);
let p3 = info.rect.bottom_right();

let segment = |x0, y0, x1, y1, mask| BrushSegment::new(
LayerPoint::new(x0, y0),
LayerSize::new(x1-x0, y1-y0),
false,
mask
);

// Add a solid rectangle for each visible edge/corner combination.
if top_edge == BorderEdgeKind::Solid {
let descriptor = BrushSegmentDescriptor::new(
&info.rect,
&inner_rect,
Some(&[
BrushSegmentKind::TopLeft,
BrushSegmentKind::TopMid,
BrushSegmentKind::TopRight
]),
);
let descriptor = BrushSegmentDescriptor {
segments: vec![
segment(p0.x, p0.y, p1.x, p1.y, EdgeAaSegmentMask::TOP | EdgeAaSegmentMask::LEFT),
segment(p2.x, p0.y, p3.x, p1.y, EdgeAaSegmentMask::TOP | EdgeAaSegmentMask::RIGHT),
segment(p1.x, p0.y, p2.x, p1.y, EdgeAaSegmentMask::TOP),
],
clip_mask_kind: BrushClipMaskKind::Unknown,
};

self.add_solid_rectangle(
clip_and_scroll,
&info,
border.top.color,
Some(Box::new(descriptor)),
BrushAntiAliasMode::Segment,
Some(descriptor),
);
}

if left_edge == BorderEdgeKind::Solid {
let descriptor = BrushSegmentDescriptor::new(
&info.rect,
&inner_rect,
Some(&[
BrushSegmentKind::MidLeft,
]),
);
let descriptor = BrushSegmentDescriptor {
segments: vec![
segment(p0.x, p1.y, p1.x, p2.y, EdgeAaSegmentMask::LEFT),
],
clip_mask_kind: BrushClipMaskKind::Unknown,
};

self.add_solid_rectangle(
clip_and_scroll,
&info,
border.left.color,
Some(Box::new(descriptor)),
BrushAntiAliasMode::Segment,
Some(descriptor),
);
}

if right_edge == BorderEdgeKind::Solid {
let descriptor = BrushSegmentDescriptor::new(
&info.rect,
&inner_rect,
Some(&[
BrushSegmentKind::MidRight,
]),
);
let descriptor = BrushSegmentDescriptor {
segments: vec![
segment(p2.x, p1.y, p3.x, p2.y, EdgeAaSegmentMask::RIGHT),
],
clip_mask_kind: BrushClipMaskKind::Unknown,
};

self.add_solid_rectangle(
clip_and_scroll,
&info,
border.right.color,
Some(Box::new(descriptor)),
BrushAntiAliasMode::Segment,
Some(descriptor),
);
}

if bottom_edge == BorderEdgeKind::Solid {
let descriptor = BrushSegmentDescriptor::new(
&info.rect,
&inner_rect,
Some(&[
BrushSegmentKind::BottomLeft,
BrushSegmentKind::BottomMid,
BrushSegmentKind::BottomRight
]),
);
let descriptor = BrushSegmentDescriptor {
segments: vec![
segment(p1.x, p2.y, p2.x, p3.y, EdgeAaSegmentMask::BOTTOM),
segment(p2.x, p2.y, p3.x, p3.y, EdgeAaSegmentMask::BOTTOM | EdgeAaSegmentMask::RIGHT),
segment(p0.x, p2.y, p1.x, p3.y, EdgeAaSegmentMask::BOTTOM | EdgeAaSegmentMask::LEFT),
],
clip_mask_kind: BrushClipMaskKind::Unknown,
};

self.add_solid_rectangle(
clip_and_scroll,
&info,
border.bottom.color,
Some(Box::new(descriptor)),
BrushAntiAliasMode::Segment,
Some(descriptor),
);
}
} else {
@@ -10,7 +10,7 @@ use app_units::Au;
use clip::ClipSource;
use frame_builder::FrameBuilder;
use gpu_types::BrushImageKind;
use prim_store::{BrushAntiAliasMode, PrimitiveContainer};
use prim_store::{PrimitiveContainer};
use prim_store::{BrushMaskKind, BrushKind, BrushPrimitive};
use picture::PicturePrimitive;
use util::RectHelpers;
@@ -136,7 +136,6 @@ impl FrameBuilder {
color: *color,
},
None,
BrushAntiAliasMode::Primitive,
)
),
);
@@ -188,7 +187,6 @@ impl FrameBuilder {
kind: BrushMaskKind::Corner(corner_size),
},
None,
BrushAntiAliasMode::Primitive,
);
} else {
// Create a minimal size primitive mask to blur. In this
@@ -226,7 +224,6 @@ impl FrameBuilder {
kind: BrushMaskKind::RoundedRect(clip_rect, shadow_radius),
},
None,
BrushAntiAliasMode::Primitive,
);
};

@@ -311,7 +308,6 @@ impl FrameBuilder {
kind: BrushMaskKind::RoundedRect(clip_rect, shadow_radius),
},
None,
BrushAntiAliasMode::Primitive,
);
let brush_info = LayerPrimitiveInfo::new(brush_rect);
let brush_prim_index = self.create_primitive(
@@ -17,7 +17,6 @@ use euclid::rect;
use frame_builder::{FrameBuilder, FrameBuilderConfig, ScrollbarInfo};
use gpu_cache::GpuCache;
use internal_types::{FastHashMap, FastHashSet, RenderedDocument};
use prim_store::{BrushAntiAliasMode};
use profiler::{GpuCacheProfileCounters, TextureCacheProfileCounters};
use resource_cache::{FontInstanceMap,ResourceCache, TiledImageMap};
use scene::{Scene, StackingContextHelpers, ScenePipeline, SceneProperties};
@@ -106,7 +105,6 @@ impl<'a> FlattenContext<'a> {
&info,
bg_color,
None,
BrushAntiAliasMode::Primitive,
);
}
}
@@ -448,7 +446,6 @@ impl<'a> FlattenContext<'a> {
&prim_info,
info.color,
None,
BrushAntiAliasMode::Primitive,
);
}
SpecificDisplayItem::ClearRectangle => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.