Skip to content

Commit b47e11c

Browse files
author
bors-servo
authored
Auto merge of servo#508 - glennw:blend-mode-prep, r=pcwalton
Add support for specific blend modes per batch. Also track the previous blend mode while drawing batches and only set it when changed. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/508) <!-- Reviewable:end -->
2 parents 6e0f4ba + 878c6aa commit b47e11c

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

webrender/src/renderer.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ const GPU_TAG_PRIM_BOX_SHADOW: GpuProfileTag = GpuProfileTag { label: "BoxShadow
8888
// Orange
8989
const GPU_TAG_PRIM_BORDER: GpuProfileTag = GpuProfileTag { label: "Border", color: ColorF { r: 1.0, g: 0.5, b: 0.0, a: 1.0 } };
9090

91+
#[derive(Debug, Copy, Clone, PartialEq)]
92+
pub enum BlendMode {
93+
None,
94+
Alpha,
95+
}
96+
9197
struct VertexDataTexture {
9298
id: TextureId,
9399
}
@@ -1390,14 +1396,23 @@ impl Renderer {
13901396
&projection);
13911397
}
13921398

1399+
let mut prev_blend_mode = BlendMode::None;
1400+
13931401
for batch in &target.alpha_batcher.batches {
13941402
let color_texture_id = batch.key.color_texture_id;
13951403
let mask_texture_id = batch.key.mask_texture_id;
13961404
let transform_kind = batch.key.flags.transform_kind();
13971405
let has_complex_clip = batch.key.flags.needs_clipping();
1398-
let blending_enabled = batch.key.flags.needs_blending();
13991406

1400-
self.device.set_blend(blending_enabled);
1407+
if batch.key.blend_mode != prev_blend_mode {
1408+
match batch.key.blend_mode {
1409+
// TODO(gw): More blend modes to come with subpixel aa work.
1410+
BlendMode::None | BlendMode::Alpha => {
1411+
self.device.set_blend(batch.key.blend_mode == BlendMode::Alpha);
1412+
}
1413+
}
1414+
prev_blend_mode = batch.key.blend_mode;
1415+
}
14011416

14021417
match &batch.data {
14031418
&PrimitiveBatchData::Blend(ref ubo_data) => {

webrender/src/tiling.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use prim_store::{GradientPrimitiveCpu, GradientPrimitiveGpu, GradientType};
2020
use prim_store::{PrimitiveCacheKey, TextRunPrimitiveGpu, TextRunPrimitiveCpu};
2121
use prim_store::{PrimitiveStore, GpuBlock16, GpuBlock32, GpuBlock64, GpuBlock128};
2222
use profiler::FrameProfileCounters;
23+
use renderer::BlendMode;
2324
use resource_cache::ResourceCache;
2425
use resource_list::ResourceList;
2526
use std::cmp;
@@ -388,11 +389,16 @@ impl AlphaBatcher {
388389
!prim_metadata.is_opaque ||
389390
needs_clipping;
390391
let flags = AlphaBatchKeyFlags::new(transform_kind,
391-
needs_blending,
392392
needs_clipping);
393+
let blend_mode = if needs_blending {
394+
BlendMode::Alpha
395+
} else {
396+
BlendMode::None
397+
};
393398
let batch_kind = ctx.prim_store.get_batch_kind(prim_metadata);
394399
batch_key = AlphaBatchKey::primitive(batch_kind,
395400
flags,
401+
blend_mode,
396402
prim_metadata.color_texture_id,
397403
prim_metadata.mask_texture_id);
398404
}
@@ -805,6 +811,7 @@ enum AlphaBatchKind {
805811
pub struct AlphaBatchKey {
806812
kind: AlphaBatchKind,
807813
pub flags: AlphaBatchKeyFlags,
814+
pub blend_mode: BlendMode,
808815
pub color_texture_id: TextureId,
809816
pub mask_texture_id: TextureId,
810817
}
@@ -814,8 +821,8 @@ impl AlphaBatchKey {
814821
AlphaBatchKey {
815822
kind: AlphaBatchKind::Blend,
816823
flags: AlphaBatchKeyFlags::new(TransformedRectKind::AxisAligned,
817-
true,
818824
false),
825+
blend_mode: BlendMode::Alpha,
819826
color_texture_id: TextureId::invalid(),
820827
mask_texture_id: TextureId::invalid(),
821828
}
@@ -825,21 +832,23 @@ impl AlphaBatchKey {
825832
AlphaBatchKey {
826833
kind: AlphaBatchKind::Composite,
827834
flags: AlphaBatchKeyFlags::new(TransformedRectKind::AxisAligned,
828-
true,
829835
false),
836+
blend_mode: BlendMode::Alpha,
830837
color_texture_id: TextureId::invalid(),
831838
mask_texture_id: TextureId::invalid(),
832839
}
833840
}
834841

835842
fn primitive(kind: AlphaBatchKind,
836843
flags: AlphaBatchKeyFlags,
844+
blend_mode: BlendMode,
837845
color_texture_id: TextureId,
838846
mask_texture_id: TextureId)
839847
-> AlphaBatchKey {
840848
AlphaBatchKey {
841849
kind: kind,
842850
flags: flags,
851+
blend_mode: blend_mode,
843852
color_texture_id: color_texture_id,
844853
mask_texture_id: mask_texture_id,
845854
}
@@ -862,11 +871,9 @@ pub struct AlphaBatchKeyFlags(u8);
862871

863872
impl AlphaBatchKeyFlags {
864873
fn new(transform_kind: TransformedRectKind,
865-
needs_blending: bool,
866874
needs_clipping: bool) -> AlphaBatchKeyFlags {
867-
AlphaBatchKeyFlags( ((needs_clipping as u8) << 2) |
868-
((transform_kind as u8) << 1) |
869-
((needs_blending as u8) << 0) )
875+
AlphaBatchKeyFlags( ((transform_kind as u8) << 1) |
876+
((needs_clipping as u8) << 0) )
870877
}
871878

872879
pub fn transform_kind(&self) -> TransformedRectKind {
@@ -877,12 +884,8 @@ impl AlphaBatchKeyFlags {
877884
}
878885
}
879886

880-
pub fn needs_blending(&self) -> bool {
881-
(self.0 & 1) != 0
882-
}
883-
884887
pub fn needs_clipping(&self) -> bool {
885-
(self.0 & 4) != 0
888+
(self.0 & 1) != 0
886889
}
887890
}
888891

0 commit comments

Comments
 (0)