Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sparse_strips/vello_common/src/coarse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ impl<const MODE: u8> Wide<MODE> {
!self.layer_stack.is_empty()
}

/// Whether any coarse batch boundaries have been recorded.
pub fn has_coarse_batches(&self) -> bool {
self.batch_count != 0
}

/// Reset all tiles in the container.
pub fn reset(&mut self) {
if self.tiles_dirty {
Expand Down
38 changes: 24 additions & 14 deletions sparse_strips/vello_hybrid/src/render/webgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ use vello_common::{
EncodedBlurredRoundedRectangle, EncodedGradient, EncodedKind, EncodedPaint,
MAX_GRADIENT_LUT_SIZE, RadialKind,
},
paint::{ImageId, ImageSource},
peniko::{self},
paint::{ImageId, ImageSource, PremulColor},
peniko::{self, color::palette::css::TRANSPARENT},
pixmap::Pixmap,
tile::Tile,
};
Expand Down Expand Up @@ -270,7 +270,9 @@ impl WebGlRenderer {
scene,
&mut resources.image_cache,
render_size,
true,
scene
.background
.or(Some(PremulColor::from_alpha_color(TRANSPARENT))),
RootRenderTarget::UserSurface,
)?;

Expand Down Expand Up @@ -353,7 +355,13 @@ impl WebGlRenderer {
scene,
&mut dummy_image_cache,
&atlas_render_size,
false,
// Note: By default, we don't want to clear the atlas, since the existing glyphs
// should be preserved. The scene background is only set if we have an opaque colored
// rect which covers the whole viewport; meaning that this is only `Some` if for
// some reason the glyph atlas was filled with such a rectangle (which should never happen
// but in case it does happen it means that all existing glyphs are being covered by this
// rectangle anyway), so it's fine to just set the reset color to the scene background.
scene.background,
RootRenderTarget::AtlasLayer,
);
self.dummy_image_cache = Some(dummy_image_cache);
Expand Down Expand Up @@ -465,7 +473,9 @@ impl WebGlRenderer {
&scene,
&mut probe_image_cache,
&render_size,
true,
scene
.background
.or(Some(PremulColor::from_alpha_color(TRANSPARENT))),
RootRenderTarget::AtlasLayer,
);
self.programs.resources.view_framebuffer_override = previous_view_framebuffer;
Expand Down Expand Up @@ -494,16 +504,14 @@ impl WebGlRenderer {
/// Shared render pipeline: prepares GPU resources, runs the scheduler, and
/// maintains caches.
///
/// When `clear` is true the view framebuffer is cleared to transparent black
/// before drawing. This must happen *after* `prepare` (which may create/resize
/// the framebuffer attachment). Atlas renders skip the clear so previously
/// rendered atlas content is preserved.
/// When `clear_color` is `Some`, the view framebuffer is cleared to that color before drawing.
/// This must happen *after* `prepare` (which may create/resize the framebuffer attachment).
fn render_scene(
&mut self,
scene: &Scene,
image_cache: &mut ImageCache,
render_size: &RenderSize,
clear: bool,
clear_color: Option<PremulColor>,
root_output_target: RootRenderTarget,
) -> Result<(), RenderError> {
if !self.filter_context.filter_textures.is_empty() {
Expand Down Expand Up @@ -541,8 +549,8 @@ impl WebGlRenderer {
&self.filter_context,
);

if clear {
self.programs.clear_view_framebuffer(&self.gl);
if let Some(clear_color) = clear_color {
self.programs.clear_view_framebuffer(&self.gl, clear_color);
}
self.programs.resources.depth_cleared_this_frame = false;
let mut ctx = WebGlRendererContext {
Expand Down Expand Up @@ -1568,12 +1576,14 @@ impl WebGlPrograms {

/// Clear the view framebuffer.
// TODO: Investigate adding tests for the clear_view behavior.
fn clear_view_framebuffer(&mut self, gl: &WebGl2RenderingContext) {
fn clear_view_framebuffer(&mut self, gl: &WebGl2RenderingContext, color: PremulColor) {
let [r, g, b, a] = color.as_premul_f32().components;

gl.bind_framebuffer(
WebGl2RenderingContext::FRAMEBUFFER,
self.resources.view_framebuffer_override.as_ref(),
);
gl.clear_color(0.0, 0.0, 0.0, 0.0);
gl.clear_color(r, g, b, a);
gl.clear(WebGl2RenderingContext::COLOR_BUFFER_BIT);
}

Expand Down
32 changes: 20 additions & 12 deletions sparse_strips/vello_hybrid/src/render/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ use vello_common::{
EncodedBlurredRoundedRectangle, EncodedGradient, EncodedKind, EncodedPaint,
MAX_GRADIENT_LUT_SIZE, RadialKind,
},
paint::ImageSource,
peniko,
paint::{ImageSource, PremulColor},
peniko::{self, color::palette::css::TRANSPARENT},
pixmap::Pixmap,
tile::Tile,
};
Expand Down Expand Up @@ -291,7 +291,9 @@ impl Renderer {
view,
&resources.image_cache,
&encoded_paints,
true,
scene
.background
.or(Some(PremulColor::from_alpha_color(TRANSPARENT))),
RootRenderTarget::UserSurface,
);

Expand Down Expand Up @@ -383,7 +385,8 @@ impl Renderer {
&layer_view,
&dummy_image_cache,
&encoded_paints,
false,
// See the note in the WebGL backend.
scene.background,
RootRenderTarget::AtlasLayer,
);
self.dummy_image_cache = Some(dummy_image_cache);
Expand All @@ -404,8 +407,7 @@ impl Renderer {
/// Shared render pipeline: prepares GPU resources, runs the scheduler against
/// the provided `view` at `render_size`, and maintains caches.
///
/// When `clear` is true the render target is cleared to transparent black
/// before drawing (normal frame rendering).
/// When `clear_color` is `Some`, the render target is cleared to that color before drawing.
fn render_scene(
&mut self,
scene: &Scene,
Expand All @@ -416,7 +418,7 @@ impl Renderer {
view: &TextureView,
image_cache: &ImageCache,
encoded_paints: &[EncodedPaint],
clear: bool,
clear_color: Option<PremulColor>,
root_output_target: RootRenderTarget,
) -> Result<(), RenderError> {
self.programs.depth_cleared_this_frame = false;
Expand All @@ -435,8 +437,8 @@ impl Renderer {
&self.filter_context,
);

if clear {
Self::clear_view(encoder, view);
if let Some(clear_color) = clear_color {
Self::clear_view(encoder, view, clear_color);
}
let mut ctx = RendererContext {
programs: &mut self.programs,
Expand All @@ -462,16 +464,22 @@ impl Renderer {
Ok(())
}

/// Clear the view to transparent black.
/// Clear the view to the scene background.
// TODO: Investigate adding tests for the clear_view behavior.
fn clear_view(encoder: &mut CommandEncoder, view: &TextureView) {
fn clear_view(encoder: &mut CommandEncoder, view: &TextureView, color: PremulColor) {
let [r, g, b, a] = color.as_premul_f32().components;
encoder.begin_render_pass(&RenderPassDescriptor {
label: Some("Clear View"),
color_attachments: &[Some(RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
load: wgpu::LoadOp::Clear(wgpu::Color {
r: r.into(),
g: g.into(),
b: b.into(),
a: a.into(),
}),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
Expand Down
Loading
Loading