Skip to content

Commit 4cdc61c

Browse files
committed
Bug 1700434 - Store mono bitmaps and alpha glyphs with same texture format. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D115511 [ghsync] From https://hg.mozilla.org/mozilla-central/rev/0a38ce1f4c59f60ce0fbe66c3bce3be551069071
1 parent 4e8ef4b commit 4cdc61c

File tree

6 files changed

+27
-34
lines changed

6 files changed

+27
-34
lines changed

webrender/res/brush_image.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void brush_vs(
246246

247247
switch (color_mode) {
248248
case COLOR_MODE_ALPHA:
249-
case COLOR_MODE_BITMAP:
249+
case COLOR_MODE_BITMAP_SHADOW:
250250
#ifdef SWGL_BLEND
251251
swgl_blendDropShadow(image_data.color);
252252
v_mask_swizzle = vec2(1.0, 0.0);

webrender/res/prim_shared.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ varying vec2 vClipMaskUv;
3232
#define COLOR_MODE_SUBPX_BG_PASS1 4
3333
#define COLOR_MODE_SUBPX_BG_PASS2 5
3434
#define COLOR_MODE_SUBPX_DUAL_SOURCE 6
35-
#define COLOR_MODE_BITMAP 7
35+
#define COLOR_MODE_BITMAP_SHADOW 7
3636
#define COLOR_MODE_COLOR_BITMAP 8
3737
#define COLOR_MODE_IMAGE 9
3838
#define COLOR_MODE_MULTIPLY_DUAL_SOURCE 10

webrender/res/ps_text_run.glsl

+9-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,15 @@ void main() {
233233
v_mask_swizzle = vec3(0.0, 1.0, 1.0);
234234
v_color = text.color;
235235
break;
236-
case COLOR_MODE_BITMAP:
237-
v_mask_swizzle = vec3(0.0, 1.0, 0.0);
238-
v_color = text.color;
236+
case COLOR_MODE_BITMAP_SHADOW:
237+
#ifdef SWGL_BLEND
238+
swgl_blendDropShadow(text.color);
239+
v_mask_swizzle = vec3(1.0, 0.0, 0.0);
240+
v_color = vec4(1.0);
241+
#else
242+
v_mask_swizzle = vec3(0.0, 1.0, 0.0);
243+
v_color = text.color;
244+
#endif
239245
break;
240246
case COLOR_MODE_SUBPX_BG_PASS2:
241247
v_mask_swizzle = vec3(1.0, 0.0, 0.0);

webrender/src/batch.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -1271,14 +1271,9 @@ impl BatchBuilder {
12711271
&glyph_keys,
12721272
&mut self.glyph_fetch_buffer,
12731273
gpu_cache,
1274-
|texture_id, mut glyph_format, glyphs| {
1274+
|texture_id, glyph_format, glyphs| {
12751275
debug_assert_ne!(texture_id, TextureSource::Invalid);
12761276

1277-
// Ignore color and only sample alpha when shadowing.
1278-
if run.shadow {
1279-
glyph_format = glyph_format.ignore_color();
1280-
}
1281-
12821277
let subpx_dir = subpx_dir.limit_by(glyph_format);
12831278

12841279
let textures = BatchTextures::prim_textured(
@@ -1309,22 +1304,22 @@ impl BatchBuilder {
13091304
}
13101305
}
13111306
GlyphFormat::Alpha |
1312-
GlyphFormat::TransformedAlpha => {
1313-
(
1314-
BlendMode::PremultipliedAlpha,
1315-
ShaderColorMode::Alpha,
1316-
)
1317-
}
1307+
GlyphFormat::TransformedAlpha |
13181308
GlyphFormat::Bitmap => {
13191309
(
13201310
BlendMode::PremultipliedAlpha,
1321-
ShaderColorMode::Bitmap,
1311+
ShaderColorMode::Alpha,
13221312
)
13231313
}
13241314
GlyphFormat::ColorBitmap => {
13251315
(
13261316
BlendMode::PremultipliedAlpha,
1327-
ShaderColorMode::ColorBitmap,
1317+
if run.shadow {
1318+
// Ignore color and only sample alpha when shadowing.
1319+
ShaderColorMode::BitmapShadow
1320+
} else {
1321+
ShaderColorMode::ColorBitmap
1322+
},
13281323
)
13291324
}
13301325
};

webrender/src/glyph_rasterizer/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -759,22 +759,14 @@ pub enum GlyphFormat {
759759
}
760760

761761
impl GlyphFormat {
762-
pub fn ignore_color(self) -> Self {
763-
match self {
764-
GlyphFormat::ColorBitmap => GlyphFormat::Bitmap,
765-
_ => self,
766-
}
767-
}
768-
769762
/// Returns the ImageFormat that a glyph should be stored as in the texture cache.
770763
/// can_use_r8_format should be set false on platforms where we have encountered
771764
/// issues with R8 textures, so that we do not use them for glyphs.
772765
pub fn image_format(&self, can_use_r8_format: bool) -> ImageFormat {
773766
match *self {
774-
// GlyphFormat::Bitmap glyphs could be stored in an R8 texture. However, we currently
775-
// support drawing ColorBitmap glyphs (stored in a BGRA8 texture) in Bitmap mode, and
776-
// currently the text shader cannot differentiate between the two cases.
777-
GlyphFormat::Alpha | GlyphFormat::TransformedAlpha => {
767+
GlyphFormat::Alpha |
768+
GlyphFormat::TransformedAlpha |
769+
GlyphFormat::Bitmap => {
778770
if can_use_r8_format {
779771
ImageFormat::R8
780772
} else {
@@ -783,7 +775,6 @@ impl GlyphFormat {
783775
}
784776
GlyphFormat::Subpixel |
785777
GlyphFormat::TransformedSubpixel |
786-
GlyphFormat::Bitmap |
787778
GlyphFormat::ColorBitmap => ImageFormat::BGRA8,
788779
}
789780
}

webrender/src/renderer/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub enum ShaderColorMode {
312312
SubpixelWithBgColorPass1 = 4,
313313
SubpixelWithBgColorPass2 = 5,
314314
SubpixelDualSource = 6,
315-
Bitmap = 7,
315+
BitmapShadow = 7,
316316
ColorBitmap = 8,
317317
Image = 9,
318318
MultiplyDualSource = 10,
@@ -321,11 +321,12 @@ pub enum ShaderColorMode {
321321
impl From<GlyphFormat> for ShaderColorMode {
322322
fn from(format: GlyphFormat) -> ShaderColorMode {
323323
match format {
324-
GlyphFormat::Alpha | GlyphFormat::TransformedAlpha => ShaderColorMode::Alpha,
324+
GlyphFormat::Alpha |
325+
GlyphFormat::TransformedAlpha |
326+
GlyphFormat::Bitmap => ShaderColorMode::Alpha,
325327
GlyphFormat::Subpixel | GlyphFormat::TransformedSubpixel => {
326328
panic!("Subpixel glyph formats must be handled separately.");
327329
}
328-
GlyphFormat::Bitmap => ShaderColorMode::Bitmap,
329330
GlyphFormat::ColorBitmap => ShaderColorMode::ColorBitmap,
330331
}
331332
}

0 commit comments

Comments
 (0)