Skip drawing whitespace from DynamicCharAtlas

When we remove the background from a glyph, we can keep track of if we
made all the pixels fully transparent. If we did, we can just skip
future calls to _drawFromCache, since it would be a noop anyways.
This commit is contained in:
Benjamin Woodruff
2018-04-15 18:52:06 -07:00
parent 24feaabd9a
commit c8b500c182
2 changed files with 33 additions and 14 deletions
+6 -1
View File
@@ -108,8 +108,10 @@ export function generateStaticCharAtlasTexture(context: Window, canvasFactory: (
/**
* Makes a partiicular rgb color in an ImageData completely transparent.
* @returns True if the result is "empty", meaning all pixels are fully transparent.
*/
export function clearColor(imageData: ImageData, color: IColor): void {
export function clearColor(imageData: ImageData, color: IColor): boolean {
let isEmpty = true;
const r = color.rgba >>> 24;
const g = color.rgba >>> 16 & 0xFF;
const b = color.rgba >>> 8 & 0xFF;
@@ -118,8 +120,11 @@ export function clearColor(imageData: ImageData, color: IColor): void {
imageData.data[offset + 1] === g &&
imageData.data[offset + 2] === b) {
imageData.data[offset + 3] = 0;
} else {
isEmpty = false;
}
}
return isEmpty;
}
function getFont(fontWeight: FontWeight, config: ICharAtlasConfig): string {