2017-10-18 19:37:51 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifdef WR_VERTEX_SHADER
|
|
|
|
|
2017-10-27 15:51:39 +03:00
|
|
|
void brush_vs(
|
2018-02-16 19:02:20 +03:00
|
|
|
VertexInfo vi,
|
2017-10-27 15:51:39 +03:00
|
|
|
int prim_address,
|
|
|
|
RectWithSize local_rect,
|
2018-05-03 16:00:55 +03:00
|
|
|
RectWithSize segment_rect,
|
2018-10-16 20:55:02 +03:00
|
|
|
ivec4 user_data,
|
2018-04-04 22:21:50 +03:00
|
|
|
mat4 transform,
|
2018-04-23 16:38:09 +03:00
|
|
|
PictureTask pic_task,
|
2018-05-03 16:00:55 +03:00
|
|
|
int brush_flags,
|
2018-04-23 16:38:09 +03:00
|
|
|
vec4 segment_data
|
2017-10-27 15:51:39 +03:00
|
|
|
);
|
|
|
|
|
2018-01-08 17:19:23 +03:00
|
|
|
#define VECS_PER_SEGMENT 2
|
2017-12-05 19:51:33 +03:00
|
|
|
|
2018-02-20 17:02:40 +03:00
|
|
|
#define BRUSH_FLAG_PERSPECTIVE_INTERPOLATION 1
|
2018-05-03 16:00:55 +03:00
|
|
|
#define BRUSH_FLAG_SEGMENT_RELATIVE 2
|
|
|
|
#define BRUSH_FLAG_SEGMENT_REPEAT_X 4
|
|
|
|
#define BRUSH_FLAG_SEGMENT_REPEAT_Y 8
|
2018-10-17 19:47:25 +03:00
|
|
|
#define BRUSH_FLAG_TEXEL_RECT 16
|
2018-02-20 17:02:40 +03:00
|
|
|
|
2017-10-18 19:37:51 +03:00
|
|
|
void main(void) {
|
|
|
|
// Load the brush instance from vertex attributes.
|
2018-06-28 18:48:27 +03:00
|
|
|
int prim_header_address = aData.x;
|
|
|
|
int clip_address = aData.y;
|
|
|
|
int segment_index = aData.z & 0xffff;
|
|
|
|
int edge_flags = (aData.z >> 16) & 0xff;
|
|
|
|
int brush_flags = (aData.z >> 24) & 0xff;
|
2018-10-16 20:55:02 +03:00
|
|
|
int segment_user_data = aData.w;
|
2018-06-28 18:48:27 +03:00
|
|
|
PrimitiveHeader ph = fetch_prim_header(prim_header_address);
|
2017-12-05 19:51:33 +03:00
|
|
|
|
|
|
|
// Fetch the segment of this brush primitive we are drawing.
|
2018-06-28 18:48:27 +03:00
|
|
|
int segment_address = ph.specific_prim_address +
|
2018-01-08 17:19:23 +03:00
|
|
|
VECS_PER_SPECIFIC_BRUSH +
|
2018-06-28 18:48:27 +03:00
|
|
|
segment_index * VECS_PER_SEGMENT;
|
2017-12-05 19:51:33 +03:00
|
|
|
|
2018-10-03 18:38:56 +03:00
|
|
|
vec4[2] segment_data = fetch_from_gpu_cache_2(segment_address);
|
2018-01-08 17:19:23 +03:00
|
|
|
RectWithSize local_segment_rect = RectWithSize(segment_data[0].xy, segment_data[0].zw);
|
2017-10-18 19:37:51 +03:00
|
|
|
|
2018-02-16 19:02:20 +03:00
|
|
|
VertexInfo vi;
|
2017-10-27 15:51:39 +03:00
|
|
|
|
2017-11-21 18:40:43 +03:00
|
|
|
// Fetch the dynamic picture that we are drawing on.
|
2018-06-28 18:48:27 +03:00
|
|
|
PictureTask pic_task = fetch_picture_task(ph.render_task_index);
|
|
|
|
ClipArea clip_area = fetch_clip_area(clip_address);
|
2017-11-21 18:40:43 +03:00
|
|
|
|
2018-06-28 18:48:27 +03:00
|
|
|
Transform transform = fetch_transform(ph.transform_id);
|
2018-03-22 17:27:18 +03:00
|
|
|
|
|
|
|
// Write the normal vertex information out.
|
2018-06-28 18:48:27 +03:00
|
|
|
if (transform.is_axis_aligned) {
|
2018-03-22 17:27:18 +03:00
|
|
|
vi = write_vertex(
|
|
|
|
local_segment_rect,
|
2018-06-28 18:48:27 +03:00
|
|
|
ph.local_clip_rect,
|
|
|
|
ph.z,
|
|
|
|
transform,
|
2018-03-22 17:27:18 +03:00
|
|
|
pic_task,
|
2018-06-28 18:48:27 +03:00
|
|
|
ph.local_rect
|
2018-03-22 17:27:18 +03:00
|
|
|
);
|
2017-10-27 15:51:39 +03:00
|
|
|
|
2018-04-09 15:26:07 +03:00
|
|
|
// TODO(gw): transform bounds may be referenced by
|
2018-03-22 17:27:18 +03:00
|
|
|
// the fragment shader when running in
|
|
|
|
// the alpha pass, even on non-transformed
|
|
|
|
// items. For now, just ensure it has no
|
|
|
|
// effect. We can tidy this up as we move
|
|
|
|
// more items to be brush shaders.
|
2018-01-08 17:19:23 +03:00
|
|
|
#ifdef WR_FEATURE_ALPHA_PASS
|
2018-10-10 16:57:27 +03:00
|
|
|
init_transform_vs(vec4(vec2(-1.0e16), vec2(1.0e16)));
|
2018-01-08 17:19:23 +03:00
|
|
|
#endif
|
2018-03-22 17:27:18 +03:00
|
|
|
} else {
|
2018-06-28 18:48:27 +03:00
|
|
|
bvec4 edge_mask = notEqual(edge_flags & ivec4(1, 2, 4, 8), ivec4(0));
|
2018-03-22 17:27:18 +03:00
|
|
|
|
|
|
|
vi = write_transform_vertex(
|
|
|
|
local_segment_rect,
|
2018-06-28 18:48:27 +03:00
|
|
|
ph.local_rect,
|
|
|
|
ph.local_clip_rect,
|
2018-03-22 17:27:18 +03:00
|
|
|
mix(vec4(0.0), vec4(1.0), edge_mask),
|
2018-06-28 18:48:27 +03:00
|
|
|
ph.z,
|
|
|
|
transform,
|
2018-08-02 17:20:04 +03:00
|
|
|
pic_task
|
2018-02-16 19:02:20 +03:00
|
|
|
);
|
2018-03-22 17:27:18 +03:00
|
|
|
}
|
2018-02-16 19:02:20 +03:00
|
|
|
|
2018-03-22 17:27:18 +03:00
|
|
|
// For brush instances in the alpha pass, always write
|
|
|
|
// out clip information.
|
|
|
|
// TODO(gw): It's possible that we might want alpha
|
|
|
|
// shaders that don't clip in the future,
|
|
|
|
// but it's reasonable to assume that one
|
|
|
|
// implies the other, for now.
|
2017-10-27 15:51:39 +03:00
|
|
|
#ifdef WR_FEATURE_ALPHA_PASS
|
2018-03-22 17:27:18 +03:00
|
|
|
write_clip(
|
2018-08-02 17:20:04 +03:00
|
|
|
vi.world_pos,
|
2018-09-20 18:05:20 +03:00
|
|
|
vi.snap_offset,
|
2018-03-22 17:27:18 +03:00
|
|
|
clip_area
|
|
|
|
);
|
2017-10-27 15:51:39 +03:00
|
|
|
#endif
|
2017-10-18 19:37:51 +03:00
|
|
|
|
|
|
|
// Run the specific brush VS code to write interpolators.
|
2017-10-27 15:51:39 +03:00
|
|
|
brush_vs(
|
2018-02-16 19:02:20 +03:00
|
|
|
vi,
|
2018-06-28 18:48:27 +03:00
|
|
|
ph.specific_prim_address,
|
|
|
|
ph.local_rect,
|
2018-05-03 16:00:55 +03:00
|
|
|
local_segment_rect,
|
2018-10-16 20:55:02 +03:00
|
|
|
ivec4(ph.user_data, segment_user_data),
|
2018-06-28 18:48:27 +03:00
|
|
|
transform.m,
|
2018-04-23 16:38:09 +03:00
|
|
|
pic_task,
|
2018-06-28 18:48:27 +03:00
|
|
|
brush_flags,
|
2018-04-23 16:38:09 +03:00
|
|
|
segment_data[1]
|
2017-10-27 15:51:39 +03:00
|
|
|
);
|
2017-10-18 19:37:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WR_FRAGMENT_SHADER
|
2017-10-27 15:51:39 +03:00
|
|
|
|
2018-04-26 21:14:24 +03:00
|
|
|
struct Fragment {
|
|
|
|
vec4 color;
|
|
|
|
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
|
|
|
|
vec4 blend;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
Fragment brush_fs();
|
2017-10-27 15:51:39 +03:00
|
|
|
|
2017-10-18 19:37:51 +03:00
|
|
|
void main(void) {
|
2018-08-14 16:47:58 +03:00
|
|
|
#ifdef WR_FEATURE_DEBUG_OVERDRAW
|
|
|
|
oFragColor = WR_DEBUG_OVERDRAW_COLOR;
|
|
|
|
#else
|
2017-10-18 19:37:51 +03:00
|
|
|
// Run the specific brush FS code to output the color.
|
2018-04-26 21:14:24 +03:00
|
|
|
Fragment frag = brush_fs();
|
2017-10-27 15:51:39 +03:00
|
|
|
|
|
|
|
#ifdef WR_FEATURE_ALPHA_PASS
|
|
|
|
// Apply the clip mask
|
2018-04-26 21:14:24 +03:00
|
|
|
float clip_alpha = do_clip();
|
|
|
|
|
|
|
|
frag.color *= clip_alpha;
|
|
|
|
|
|
|
|
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
|
|
|
|
oFragBlend = frag.blend * clip_alpha;
|
|
|
|
#endif
|
2017-10-27 15:51:39 +03:00
|
|
|
#endif
|
2017-10-18 19:37:51 +03:00
|
|
|
|
|
|
|
// TODO(gw): Handle pre-multiply common code here as required.
|
2018-04-26 21:14:24 +03:00
|
|
|
oFragColor = frag.color;
|
2018-08-14 16:47:58 +03:00
|
|
|
#endif
|
2017-10-18 19:37:51 +03:00
|
|
|
}
|
|
|
|
#endif
|