webrender/pattern/cutout.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5//! Cutouts patterns act a mask on top of already rendered content.
6//!
7//! Their main purpose is to "punch a hole" in the current layer so that
8//! an underlay layer can be seen through it.
9//! The clip chain controls the shape of the mask. When rendering the
10//! cutout, opaque white means pixels will be fully masked, transparent
11//! black means pixels will be shown, and values in between represent
12//! different levels of transparency.
13
14use api::{ColorF, units::*};
15
16use crate::pattern::{Pattern, PatternBuilder, PatternBuilderContext, PatternBuilderState};
17use crate::renderer::BlendMode;
18
19pub struct Cutout;
20
21impl PatternBuilder for Cutout {
22 fn build(
23 &self,
24 _sub_rect: Option<DeviceRect>,
25 _offset: LayoutVector2D,
26 _ctx: &PatternBuilderContext,
27 _state: &mut PatternBuilderState,
28 ) -> Pattern {
29 Pattern::color(ColorF::WHITE)
30 .with_blend_mode(BlendMode::PremultipliedDestOut)
31 }
32}
33
34// TODO: Cutouts are applied to the destination layer entirely in the alpha
35// pass, the fully masked segments could be drawn in the opaque pass.
36
37// TODO: Currently, complex masks for cutouts are drawn into intermediate
38// surfaces using the same logic as regular patterns. They could be drawn
39// directly into the the destination layer.