Skip to content

Commit

Permalink
Add multisampling for SVG (WIP, doesn't work yet), overflow:hidden wo…
Browse files Browse the repository at this point in the history
…rks now
  • Loading branch information
fschutt committed Oct 31, 2018
1 parent dd2c591 commit ee54878
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ExternalImageHandler for Compositor {
ExternalImageSource::NativeTexture(tex.texture.inner.get_id()),
TypedPoint2D::<f32, DevicePixel>::new(
tex.texture.inner.width() as f32,
tex.texture.inner.height() as f32
tex.texture.inner.height() as f32,
)
))
})
Expand Down
38 changes: 29 additions & 9 deletions src/css_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,15 +1165,20 @@ impl LayoutOverflow {
}

pub fn allows_horizontal_overflow(&self) -> bool {
use self::TextOverflowBehaviourInner::*;
match self.horizontal {
TextOverflowBehaviour::Modified(m) => match m {
Scroll | Auto => true,
Hidden | Visible => false,
},
// default: allow horizontal overflow
TextOverflowBehaviour::NotModified => false,
}
self.horizontal.can_overflow()
}

pub fn allows_vertical_overflow(&self) -> bool {
self.vertical.can_overflow()
}

// If this overflow setting should show the horizontal scrollbar
pub fn allows_horizontal_scrollbar(&self) -> bool {
self.allows_horizontal_overflow()
}

pub fn allows_vertical_scrollbar(&self) -> bool {
self.allows_vertical_overflow()
}
}

Expand Down Expand Up @@ -2241,6 +2246,21 @@ pub enum TextOverflowBehaviour {
Modified(TextOverflowBehaviourInner),
}

impl TextOverflowBehaviour {
pub fn can_overflow(&self) -> bool {
use self::TextOverflowBehaviour::*;
use self::TextOverflowBehaviourInner::*;
match self {
Modified(m) => match m {
Scroll | Auto => true,
Hidden | Visible => false,
},
// default: allow horizontal overflow
NotModified => false,
}
}
}

impl Default for TextOverflowBehaviour {
fn default() -> Self {
TextOverflowBehaviour::NotModified
Expand Down
18 changes: 11 additions & 7 deletions src/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,15 @@ fn displaylist_handle_rect<'a,'b,'c,'d,'e,'f, T: Layout>(
if let Some(overflow) = &overflow_result {
// push scrollbars if necessary
// If the rectangle should have a scrollbar, push a scrollbar onto the display list
if let TextOverflow::IsOverflowing(amount_vert) = overflow.text_overflow.vertical {
push_scrollbar(referenced_mutable_content.builder, &overflow.text_overflow, &scrollbar_style, &bounds, &rect.style.border)
if rect.style.overflow.unwrap_or_default().allows_vertical_scrollbar() {
if let TextOverflow::IsOverflowing(amount_vert) = overflow.text_overflow.vertical {
push_scrollbar(referenced_mutable_content.builder, &overflow.text_overflow, &scrollbar_style, &bounds, &rect.style.border)
}
}
if let TextOverflow::IsOverflowing(amount_horz) = overflow.text_overflow.horizontal {
push_scrollbar(referenced_mutable_content.builder, &overflow.text_overflow, &scrollbar_style, &bounds, &rect.style.border)
if rect.style.overflow.unwrap_or_default().allows_horizontal_scrollbar() {
if let TextOverflow::IsOverflowing(amount_horz) = overflow.text_overflow.horizontal {
push_scrollbar(referenced_mutable_content.builder, &overflow.text_overflow, &scrollbar_style, &bounds, &rect.style.border)
}
}
}

Expand Down Expand Up @@ -660,7 +664,7 @@ fn push_opengl_texture<'a, 'b, 'c, 'd, 'e,'f, T: Layout>(

let opaque = false;
let allow_mipmaps = true;
let descriptor = ImageDescriptor::new(texture.inner.width(), texture.inner.height(), ImageFormat::BGRA8, opaque, allow_mipmaps);
let descriptor = ImageDescriptor::new(info.rect.size.width as u32, info.rect.size.height as u32, ImageFormat::BGRA8, opaque, allow_mipmaps);
let key = referenced_content.render_api.generate_image_key();
let external_image_id = ExternalImageId(new_opengl_texture_id() as u64);

Expand All @@ -680,7 +684,7 @@ fn push_opengl_texture<'a, 'b, 'c, 'd, 'e,'f, T: Layout>(

referenced_mutable_content.builder.push_image(
&info,
info.rect.size,
LayoutSize::new(texture.inner.width() as f32, texture.inner.height() as f32),
LayoutSize::zero(),
ImageRendering::Auto,
AlphaType::Alpha,
Expand Down Expand Up @@ -825,7 +829,7 @@ fn push_text(
let font_size = style.font_size.unwrap_or(DEFAULT_FONT_SIZE);
let font_size_app_units = Au((font_size.0.to_pixels() as i32) * AU_PER_PX as i32);
let font_instance_key = push_font(&font_id, font_size_app_units, resource_updates, app_resources, render_api)?;
let overflow_behaviour = style.overflow.unwrap_or(LayoutOverflow::default());
let overflow_behaviour = style.overflow.unwrap_or_default();

let text_layout_options = TextLayoutOptions {
horz_alignment,
Expand Down
9 changes: 6 additions & 3 deletions src/text_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,19 @@ fn estimate_overflow_pass_2(
// scrollbar gets shown on the right edge, so we need to subtract from the
// **width** of the rectangle.

if pass1.horizontal.is_overflowing() {
let need_recalc_horz = pass1.horizontal.is_overflowing() && !overflow.allows_horizontal_overflow();
let need_recalc_vert = pass1.vertical.is_overflowing() && !overflow.allows_vertical_overflow();

if need_recalc_horz {
new_size.height -= scrollbar_info.width.0; // both in px
}

if pass1.vertical.is_overflowing() {
if need_recalc_vert {
new_size.width -= scrollbar_info.width.0; // both in px
}

// If the words are not overflowing, just take the result from the first pass
let recalc_scrollbar_info = if pass1.horizontal.is_overflowing() || pass1.vertical.is_overflowing() {
let recalc_scrollbar_info = if need_recalc_horz || need_recalc_vert {
estimate_overflow_pass_1(words, &new_size, font_metrics, overflow)
} else {
pass1
Expand Down
19 changes: 17 additions & 2 deletions src/widgets/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,9 @@ pub struct Svg {
pub enable_hidpi: bool,
/// Background color (default: transparent)
pub background_color: ColorU,
/// Multisampling (default: 1.0) - since there is no anti-aliasing yet, simply
/// increases the texture size that is drawn to.
pub multisampling_factor: f32,
}

impl Default for Svg {
Expand All @@ -1695,6 +1698,7 @@ impl Default for Svg {
enable_fxaa: false,
enable_hidpi: true,
background_color: ColorU { r: 0, b: 0, g: 0, a: 0 },
multisampling_factor: 1.0,
}
}
}
Expand Down Expand Up @@ -2232,6 +2236,14 @@ impl Svg {
self
}

/// Since there is no anti-aliasing yet, this will enlarge the texture that is drawn to by
/// the factor X. Default is `1.0`, but you could for example, render to a `1.2x` texture.
#[inline]
pub fn with_multisampling_factor(mut self, multisampling_factor: f32) -> Self {
self.multisampling_factor = multisampling_factor;
self
}

#[inline]
pub fn with_fxaa(mut self, enable_fxaa: bool) -> Self {
self.enable_fxaa = enable_fxaa;
Expand All @@ -2252,7 +2264,10 @@ impl Svg {
height: usize)
-> Texture
{
let tex = window.create_texture(width as u32, height as u32);
let texture_width = (width as f32 * self.multisampling_factor) as u32;
let texture_height = (height as f32 * self.multisampling_factor) as u32;
let tex = window.create_texture(texture_width, texture_height);

let (window_width, window_height) = window.get_physical_size();

// TODO: This currently doesn't work - only the first draw call is drawn
Expand Down Expand Up @@ -2282,7 +2297,7 @@ impl Svg {
background_color.r,
background_color.g,
background_color.b,
0.0);
background_color.a);

for layer in &self.layers {

Expand Down

0 comments on commit ee54878

Please sign in to comment.