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

Tidy up picture/brush code in preparation for box shadow optimizations. #1947

Merged
merged 1 commit into from Oct 27, 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

@@ -24,20 +24,18 @@ void brush_vs(
// we can expand this to support items from
// the normal texture cache and unify this
// with the normal image shader.
RenderTaskData child_task = fetch_render_task(user_data.x);
vUv.z = child_task.data1.x;
BlurTask task = fetch_blur_task(user_data.x);
vUv.z = task.render_target_layer_index;

#if defined WR_FEATURE_COLOR_TARGET
vec2 texture_size = vec2(textureSize(sColor0, 0).xy);
#else
Picture pic = fetch_picture(prim_address);

vec2 texture_size = vec2(textureSize(sColor1, 0).xy);
vColor = pic.color;
vColor = task.color;
#endif

vec2 uv0 = child_task.data0.xy;
vec2 uv1 = (child_task.data0.xy + child_task.data0.zw);
vec2 uv0 = task.target_rect.p0;
vec2 uv1 = (task.target_rect.p0 + task.target_rect.size);

vec2 f = (local_pos - local_rect.p0) / local_rect.size;

@@ -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 PRIMITIVE_HAS_PICTURE_TASK

#include shared,prim_shared

varying vec3 vUv;
@@ -18,16 +20,6 @@ void main(void) {

int glyph_index = prim.user_data0;
int resource_address = prim.user_data1;
int picture_address = prim.user_data2;

// Fetch the owning picture for this primitive. This allows the code
// below to normalize the glyph offsets relative to the original text
// shadow rect, which is the union of all elements that make up this
// text shadow. This allows the text shadow to be rendered at an
// arbitrary location in a render target (provided by the render
// task render_target_origin field).
PrimitiveGeometry shadow_geom = fetch_primitive_geometry(picture_address);
Picture pic = fetch_picture(picture_address + VECS_PER_PRIM_HEADER);

Glyph glyph = fetch_glyph(prim.specific_prim_address,
glyph_index,
@@ -40,8 +32,8 @@ void main(void) {
// the glyph offset, relative to its primitive bounding rect.
vec2 size = (res.uv_rect.zw - res.uv_rect.xy) * res.scale;
vec2 local_pos = glyph.offset + vec2(res.offset.x, -res.offset.y) / uDevicePixelRatio;
vec2 origin = prim.task.render_target_origin +
uDevicePixelRatio * (local_pos + pic.offset - shadow_geom.local_rect.p0);
vec2 origin = prim.task.target_rect.p0 +
uDevicePixelRatio * (local_pos - prim.task.content_origin);
vec4 local_rect = vec4(origin, size);

vec2 texture_size = vec2(textureSize(sColor0, 0));
@@ -53,7 +45,7 @@ void main(void) {
aPosition.xy);

vUv = vec3(mix(st0, st1, aPosition.xy), res.layer);
vColor = pic.color;
vColor = prim.task.color;

gl_Position = uTransform * vec4(pos, 0.0, 1.0);
}
@@ -194,6 +194,47 @@ RenderTaskData fetch_render_task(int index) {
return task;
}

/*
The dynamic picture that this brush exists on. Right now, it
contains minimal information. In the future, it will describe
the transform mode of primitives on this picture, among other things.
*/
struct PictureTask {
RectWithSize target_rect;
float render_target_layer_index;
vec2 content_origin;
vec4 color;
};

PictureTask fetch_picture_task(int address) {
RenderTaskData task_data = fetch_render_task(address);

return PictureTask(
RectWithSize(task_data.data0.xy, task_data.data0.zw),
task_data.data1.x,
task_data.data1.yz,
task_data.data2
);
}

struct BlurTask {
RectWithSize target_rect;
float render_target_layer_index;
float blur_radius;
vec4 color;
};

BlurTask fetch_blur_task(int address) {
RenderTaskData task_data = fetch_render_task(address);

return BlurTask(
RectWithSize(task_data.data0.xy, task_data.data0.zw),
task_data.data1.x,
task_data.data1.y,
task_data.data2
);
}

struct AlphaBatchTask {
vec2 screen_space_origin;
vec2 render_target_origin;
@@ -359,7 +400,11 @@ CompositeInstance fetch_composite_instance() {
struct Primitive {
Layer layer;
ClipArea clip_area;
#ifdef PRIMITIVE_HAS_PICTURE_TASK
PictureTask task;
#else
AlphaBatchTask task;
#endif
RectWithSize local_rect;
RectWithSize local_clip_rect;
int specific_prim_address;
@@ -387,7 +432,11 @@ Primitive load_primitive() {

prim.layer = fetch_layer(pi.layer_index);
prim.clip_area = fetch_clip_area(pi.clip_task_index);
#ifdef PRIMITIVE_HAS_PICTURE_TASK
prim.task = fetch_picture_task(pi.render_task_index);
#else
prim.task = fetch_alpha_batch_task(pi.render_task_index);
#endif

PrimitiveGeometry geom = fetch_primitive_geometry(pi.prim_address);
prim.local_rect = geom.local_rect;
@@ -659,36 +708,6 @@ Rectangle fetch_rectangle(int address) {
return Rectangle(data);
}

struct Picture {
vec4 color;
vec2 offset;
float blur_radius;
};

Picture fetch_picture(int address) {
vec4 data[2] = fetch_from_resource_cache_2(address);
return Picture(data[0], data[1].xy, data[1].z);
}

/*
The dynamic picture that this brush exists on. Right now, it
contains minimal information. In the future, it will describe
the transform mode of primitives on this picture, among other things.
*/
struct PictureTask {
RectWithSize target_rect;
};

PictureTask fetch_picture_task(int index) {
ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);

vec4 target_rect = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));

PictureTask task = PictureTask(RectWithSize(target_rect.xy, target_rect.zw));

return task;
}

struct TextRun {
vec4 color;
vec2 offset;
@@ -2,6 +2,10 @@
* 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/. */

#ifdef WR_FEATURE_CACHE
#define PRIMITIVE_HAS_PICTURE_TASK
#endif

#include shared,prim_shared

varying vec4 vColor;
@@ -70,7 +74,7 @@ void main(void) {
float diameter = size.y;
float period = diameter * 2.0;
float center_line = pos.y + 0.5 * size.y;
float max_x = floor(size.x / period) * period;
float max_x = floor(size.x / period) * period;
vParams = vec4(period,
diameter / 2.0, // radius
center_line,
@@ -95,19 +99,15 @@ void main(void) {
}

#ifdef WR_FEATURE_CACHE
int picture_address = prim.user_data0;
PrimitiveGeometry picture_geom = fetch_primitive_geometry(picture_address);
Picture pic = fetch_picture(picture_address + VECS_PER_PRIM_HEADER);

vec2 device_origin = prim.task.render_target_origin +
uDevicePixelRatio * (prim.local_rect.p0 + pic.offset - picture_geom.local_rect.p0);
vec2 device_origin = prim.task.target_rect.p0 +
uDevicePixelRatio * (prim.local_rect.p0 - prim.task.content_origin);
vec2 device_size = uDevicePixelRatio * prim.local_rect.size;

vec2 device_pos = mix(device_origin,
device_origin + device_size,
aPosition.xy);

vColor = pic.color;
vColor = prim.task.color;
vLocalPos = mix(prim.local_rect.p0,
prim.local_rect.p0 + prim.local_rect.size,
aPosition.xy);
@@ -174,7 +174,13 @@ impl FrameBuilder {
BoxShadowClipMode::Outset,
);

pic_prim.add_primitive(brush_prim_index, clip_and_scroll);
pic_prim.add_primitive(
brush_prim_index,
&brush_rect,
clip_and_scroll
);

pic_prim.build();

extra_clips.push(ClipSource::RoundedRectangle(
prim_info.rect,
@@ -221,7 +227,13 @@ impl FrameBuilder {
BoxShadowClipMode::Inset,
);

pic_prim.add_primitive(brush_prim_index, clip_and_scroll);
pic_prim.add_primitive(
brush_prim_index,
&prim_info.rect,
clip_and_scroll
);

pic_prim.build();

extra_clips.push(ClipSource::RoundedRectangle(
prim_info.rect,
@@ -588,10 +588,8 @@ impl FrameBuilder {
// safe to offset the local rect by the offset of the shadow, which
// is then used when blitting the shadow to the final location.
let metadata = &mut self.prim_store.cpu_metadata[prim_index.0];
let prim = &self.prim_store.cpu_pictures[metadata.cpu_prim_index.0];
let shadow = prim.as_text_shadow();

metadata.local_rect = metadata.local_rect.translate(&shadow.offset);
let prim = &mut self.prim_store.cpu_pictures[metadata.cpu_prim_index.0];
metadata.local_rect = prim.build();
}

// Push any fast-path shadows now
@@ -710,12 +708,11 @@ impl FrameBuilder {

// Only run real blurs here (fast path zero blurs are handled above).
if blur_radius > 0.0 {
let shadow_rect = info.rect.inflate(
blur_radius,
blur_radius,
picture.add_primitive(
prim_index,
&info.rect,
clip_and_scroll,
);
shadow_metadata.local_rect = shadow_metadata.local_rect.union(&shadow_rect);
picture.add_primitive(prim_index, clip_and_scroll);
}
}
}
@@ -1227,12 +1224,11 @@ impl FrameBuilder {
// Only run real blurs here (fast path zero blurs are handled above).
let blur_radius = picture_prim.as_text_shadow().blur_radius;
if blur_radius > 0.0 {
let shadow_rect = rect.inflate(
blur_radius,
blur_radius,
picture_prim.add_primitive(
prim_index,
&rect,
clip_and_scroll,
);
shadow_metadata.local_rect = shadow_metadata.local_rect.union(&shadow_rect);
picture_prim.add_primitive(prim_index, clip_and_scroll);
}
}
}
@@ -1873,6 +1869,7 @@ impl FrameBuilder {
RenderTargetKind::Color,
&[],
ClearMode::Transparent,
ColorF::new(0.0, 0.0, 0.0, 0.0),
);
let blur_render_task_id = render_tasks.add(blur_render_task);
let item = AlphaRenderItem::HardwareComposite(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.