Skip to content

Commit

Permalink
Fix tests on webkit by using custom clamping to uint8 (#90063)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 7, 2020
1 parent 0ebabc2 commit 5133f11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { RGBA8 } from 'vs/editor/common/core/rgba';
import { Constants, getCharIndex } from './minimapCharSheet';
import { toUint8 } from 'vs/base/common/uint';

export class MinimapCharRenderer {
_minimapCharRendererBrand: void;
Expand All @@ -20,7 +21,7 @@ export class MinimapCharRenderer {
private static soften(input: Uint8ClampedArray, ratio: number): Uint8ClampedArray {
let result = new Uint8ClampedArray(input.length);
for (let i = 0, len = input.length; i < len; i++) {
result[i] = input[i] * ratio;
result[i] = toUint8(input[i] * ratio);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MinimapCharRenderer } from 'vs/editor/browser/viewParts/minimap/minimap
import { allCharCodes } from 'vs/editor/browser/viewParts/minimap/minimapCharSheet';
import { prebakedMiniMaps } from 'vs/editor/browser/viewParts/minimap/minimapPreBaked';
import { Constants } from './minimapCharSheet';
import { toUint8 } from 'vs/base/common/uint';

/**
* Creates character renderers. It takes a 'scale' that determines how large
Expand Down Expand Up @@ -135,7 +136,7 @@ export class MinimapCharRendererFactory {

const final = value / samples;
brightest = Math.max(brightest, final);
dest[targetIndex++] = final;
dest[targetIndex++] = toUint8(final);
}
}

Expand Down
42 changes: 17 additions & 25 deletions src/vs/editor/test/browser/view/minimapCharRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ import { MinimapCharRendererFactory } from 'vs/editor/browser/viewParts/minimap/

suite('MinimapCharRenderer', () => {

let sampleData: Uint8ClampedArray | null = null;

suiteSetup(() => {
sampleData = new Uint8ClampedArray(Constants.SAMPLED_CHAR_HEIGHT * Constants.SAMPLED_CHAR_WIDTH * Constants.RGBA_CHANNELS_CNT * Constants.CHAR_COUNT);
});

suiteTeardown(() => {
sampleData = null;
});

setup(() => {
for (let i = 0; i < sampleData!.length; i++) {
sampleData![i] = 0;
}
});

const sampleD = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xD0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xD0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x78, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -45,7 +29,13 @@ suite('MinimapCharRenderer', () => {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];

function setSampleData(charCode: number, data: number[]) {
function getSampleData() {
const charCode = 'd'.charCodeAt(0);
const result = new Uint8ClampedArray(Constants.SAMPLED_CHAR_HEIGHT * Constants.SAMPLED_CHAR_WIDTH * Constants.RGBA_CHANNELS_CNT * Constants.CHAR_COUNT);
for (let i = 0; i < result.length; i++) {
result[i] = 0;
}

const rowWidth = Constants.SAMPLED_CHAR_WIDTH * Constants.RGBA_CHANNELS_CNT * Constants.CHAR_COUNT;
let chIndex = charCode - Constants.START_CH_CODE;

Expand All @@ -55,13 +45,15 @@ suite('MinimapCharRenderer', () => {
let outputOffset = globalOutputOffset;
for (let j = 0; j < Constants.SAMPLED_CHAR_WIDTH; j++) {
for (let channel = 0; channel < Constants.RGBA_CHANNELS_CNT; channel++) {
sampleData![outputOffset] = data[inputOffset];
result[outputOffset] = sampleD[inputOffset];
inputOffset++;
outputOffset++;
}
}
globalOutputOffset += rowWidth;
}

return result;
}

function createFakeImageData(width: number, height: number): ImageData {
Expand All @@ -73,8 +65,8 @@ suite('MinimapCharRenderer', () => {
}

test('letter d @ 2x', () => {
setSampleData('d'.charCodeAt(0), sampleD);
let renderer = MinimapCharRendererFactory.createFromSampleData(sampleData!, 2);
const sampleData = getSampleData();
let renderer = MinimapCharRendererFactory.createFromSampleData(sampleData, 2);

let background = new RGBA8(0, 0, 0, 255);
let color = new RGBA8(255, 255, 255, 255);
Expand All @@ -94,16 +86,16 @@ suite('MinimapCharRenderer', () => {
}

assert.deepEqual(actual, [
0x2E, 0x2E, 0x2E, 0xFF, 0xAD, 0xAD, 0xAD, 0xFF,
0x2D, 0x2D, 0x2D, 0xFF, 0xAC, 0xAC, 0xAC, 0xFF,
0xC6, 0xC6, 0xC6, 0xFF, 0xC8, 0xC8, 0xC8, 0xFF,
0xC1, 0xC1, 0xC1, 0xFF, 0xCC, 0xCC, 0xCC, 0xFF,
0xC0, 0xC0, 0xC0, 0xFF, 0xCB, 0xCB, 0xCB, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF,
]);
});

test('letter d @ 1x', () => {
setSampleData('d'.charCodeAt(0), sampleD);
let renderer = MinimapCharRendererFactory.createFromSampleData(sampleData!, 1);
const sampleData = getSampleData();
let renderer = MinimapCharRendererFactory.createFromSampleData(sampleData, 1);

let background = new RGBA8(0, 0, 0, 255);
let color = new RGBA8(255, 255, 255, 255);
Expand All @@ -125,7 +117,7 @@ suite('MinimapCharRenderer', () => {

assert.deepEqual(actual, [
0xCB, 0xCB, 0xCB, 0xFF,
0x82, 0x82, 0x82, 0xFF,
0x81, 0x81, 0x81, 0xFF,
]);
});

Expand Down

0 comments on commit 5133f11

Please sign in to comment.