Remove non-JavaScript render code
It wasn't used anyway so simplify things.
This commit is contained in:
parent
656858a6d6
commit
134ec26ee0
|
@ -77,11 +77,6 @@ export default function Display(target, defaults) {
|
||||||
throw new Error("Canvas does not support createImageData");
|
throw new Error("Canvas does not support createImageData");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._prefer_js === null) {
|
|
||||||
Log.Info("Prefering javascript operations");
|
|
||||||
this._prefer_js = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine browser support for setting the cursor via data URI scheme
|
// Determine browser support for setting the cursor via data URI scheme
|
||||||
if (this._cursor_uri || this._cursor_uri === null ||
|
if (this._cursor_uri || this._cursor_uri === null ||
|
||||||
this._cursor_uri === undefined) {
|
this._cursor_uri === undefined) {
|
||||||
|
@ -381,56 +376,45 @@ Display.prototype = {
|
||||||
this._tile = this._drawCtx.createImageData(width, height);
|
this._tile = this._drawCtx.createImageData(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._prefer_js) {
|
var red = color[2];
|
||||||
var red = color[2];
|
var green = color[1];
|
||||||
var green = color[1];
|
var blue = color[0];
|
||||||
var blue = color[0];
|
|
||||||
|
|
||||||
var data = this._tile.data;
|
var data = this._tile.data;
|
||||||
for (var i = 0; i < width * height * 4; i += 4) {
|
for (var i = 0; i < width * height * 4; i += 4) {
|
||||||
data[i] = red;
|
data[i] = red;
|
||||||
data[i + 1] = green;
|
data[i + 1] = green;
|
||||||
data[i + 2] = blue;
|
data[i + 2] = blue;
|
||||||
data[i + 3] = 255;
|
data[i + 3] = 255;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.fillRect(x, y, width, height, color, true);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// update sub-rectangle of the current tile
|
// update sub-rectangle of the current tile
|
||||||
subTile: function (x, y, w, h, color) {
|
subTile: function (x, y, w, h, color) {
|
||||||
if (this._prefer_js) {
|
var red = color[2];
|
||||||
var red = color[2];
|
var green = color[1];
|
||||||
var green = color[1];
|
var blue = color[0];
|
||||||
var blue = color[0];
|
var xend = x + w;
|
||||||
var xend = x + w;
|
var yend = y + h;
|
||||||
var yend = y + h;
|
|
||||||
|
|
||||||
var data = this._tile.data;
|
var data = this._tile.data;
|
||||||
var width = this._tile.width;
|
var width = this._tile.width;
|
||||||
for (var j = y; j < yend; j++) {
|
for (var j = y; j < yend; j++) {
|
||||||
for (var i = x; i < xend; i++) {
|
for (var i = x; i < xend; i++) {
|
||||||
var p = (i + (j * width)) * 4;
|
var p = (i + (j * width)) * 4;
|
||||||
data[p] = red;
|
data[p] = red;
|
||||||
data[p + 1] = green;
|
data[p + 1] = green;
|
||||||
data[p + 2] = blue;
|
data[p + 2] = blue;
|
||||||
data[p + 3] = 255;
|
data[p + 3] = 255;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.fillRect(this._tile_x + x, this._tile_y + y, w, h, color, true);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// draw the current tile to the screen
|
// draw the current tile to the screen
|
||||||
finishTile: function () {
|
finishTile: function () {
|
||||||
if (this._prefer_js) {
|
this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y);
|
||||||
this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y);
|
this._damage(this._tile_x, this._tile_y,
|
||||||
this._damage(this._tile_x, this._tile_y,
|
this._tile.width, this._tile.height);
|
||||||
this._tile.width, this._tile.height);
|
|
||||||
}
|
|
||||||
// else: No-op -- already done by setSubTile
|
|
||||||
},
|
},
|
||||||
|
|
||||||
blitImage: function (x, y, width, height, arr, offset, from_queue) {
|
blitImage: function (x, y, width, height, arr, offset, from_queue) {
|
||||||
|
@ -697,7 +681,6 @@ make_properties(Display, [
|
||||||
['width', 'ro', 'int'], // Display area width
|
['width', 'ro', 'int'], // Display area width
|
||||||
['height', 'ro', 'int'], // Display area height
|
['height', 'ro', 'int'], // Display area height
|
||||||
|
|
||||||
['prefer_js', 'rw', 'str'], // Prefer Javascript over canvas methods
|
|
||||||
['cursor_uri', 'rw', 'raw'], // Can we render cursor using data URI
|
['cursor_uri', 'rw', 'raw'], // Can we render cursor using data URI
|
||||||
|
|
||||||
['onFlush', 'rw', 'func'], // onFlush(): A flush request has finished
|
['onFlush', 'rw', 'func'], // onFlush(): A flush request has finished
|
||||||
|
|
|
@ -97,7 +97,6 @@ None
|
||||||
| viewport | bool | RW | false | Use viewport clipping
|
| viewport | bool | RW | false | Use viewport clipping
|
||||||
| width | int | RO | | Display area width
|
| width | int | RO | | Display area width
|
||||||
| height | int | RO | | Display area height
|
| height | int | RO | | Display area height
|
||||||
| prefer_js | str | RW | | Prefer JavaScript over canvas methods
|
|
||||||
| cursor_uri | raw | RW | | Can we render cursor using data URI
|
| cursor_uri | raw | RW | | Can we render cursor using data URI
|
||||||
|
|
||||||
### 2.3.2 Methods
|
### 2.3.2 Methods
|
||||||
|
|
|
@ -40,19 +40,19 @@ describe('Display/Canvas Helper', function () {
|
||||||
describe('checking for cursor uri support', function () {
|
describe('checking for cursor uri support', function () {
|
||||||
it('should disable cursor URIs if there is no support', function () {
|
it('should disable cursor URIs if there is no support', function () {
|
||||||
_forceCursorURIs(false);
|
_forceCursorURIs(false);
|
||||||
var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false });
|
var display = new Display(document.createElement('canvas'), { viewport: false });
|
||||||
expect(display._cursor_uri).to.be.false;
|
expect(display._cursor_uri).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should enable cursor URIs if there is support', function () {
|
it('should enable cursor URIs if there is support', function () {
|
||||||
_forceCursorURIs(true);
|
_forceCursorURIs(true);
|
||||||
var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false });
|
var display = new Display(document.createElement('canvas'), { viewport: false });
|
||||||
expect(display._cursor_uri).to.be.true;
|
expect(display._cursor_uri).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('respect the cursor_uri option if there is support', function () {
|
it('respect the cursor_uri option if there is support', function () {
|
||||||
_forceCursorURIs(false);
|
_forceCursorURIs(false);
|
||||||
var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false, cursor_uri: false });
|
var display = new Display(document.createElement('canvas'), { viewport: false, cursor_uri: false });
|
||||||
expect(display._cursor_uri).to.be.false;
|
expect(display._cursor_uri).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
describe('viewport handling', function () {
|
describe('viewport handling', function () {
|
||||||
var display;
|
var display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'), { prefer_js: false, viewport: true });
|
display = new Display(document.createElement('canvas'), { viewport: true });
|
||||||
display.resize(5, 5);
|
display.resize(5, 5);
|
||||||
display.viewportChangeSize(3, 3);
|
display.viewportChangeSize(3, 3);
|
||||||
display.viewportChangePos(1, 1);
|
display.viewportChangePos(1, 1);
|
||||||
|
@ -153,7 +153,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
describe('resizing', function () {
|
describe('resizing', function () {
|
||||||
var display;
|
var display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'), { prefer_js: false, viewport: false });
|
display = new Display(document.createElement('canvas'), { viewport: false });
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
canvas = document.createElement('canvas');
|
canvas = document.createElement('canvas');
|
||||||
display = new Display(canvas, { prefer_js: false, viewport: true });
|
display = new Display(canvas, { viewport: true });
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
display.viewportChangeSize(3, 3);
|
display.viewportChangeSize(3, 3);
|
||||||
display.viewportChangePos(1, 1);
|
display.viewportChangePos(1, 1);
|
||||||
|
@ -255,7 +255,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
canvas = document.createElement('canvas');
|
canvas = document.createElement('canvas');
|
||||||
display = new Display(canvas, { prefer_js: false, viewport: true });
|
display = new Display(canvas, { viewport: true });
|
||||||
display.resize(4, 3);
|
display.resize(4, 3);
|
||||||
document.body.appendChild(canvas);
|
document.body.appendChild(canvas);
|
||||||
});
|
});
|
||||||
|
@ -311,124 +311,119 @@ describe('Display/Canvas Helper', function () {
|
||||||
|
|
||||||
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
|
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
|
||||||
// basic cases
|
// basic cases
|
||||||
function drawing_tests (pref_js) {
|
var display;
|
||||||
var display;
|
beforeEach(function () {
|
||||||
beforeEach(function () {
|
display = new Display(document.createElement('canvas'));
|
||||||
display = new Display(document.createElement('canvas'), { prefer_js: pref_js });
|
display.resize(4, 4);
|
||||||
display.resize(4, 4);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should clear the screen on #clear without a logo set', function () {
|
it('should clear the screen on #clear without a logo set', function () {
|
||||||
display.fillRect(0, 0, 4, 4, [0x00, 0x00, 0xff]);
|
display.fillRect(0, 0, 4, 4, [0x00, 0x00, 0xff]);
|
||||||
display._logo = null;
|
display._logo = null;
|
||||||
display.clear();
|
display.clear();
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
var empty = [];
|
var empty = [];
|
||||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
||||||
expect(display).to.have.displayed(new Uint8Array(empty));
|
expect(display).to.have.displayed(new Uint8Array(empty));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should draw the logo on #clear with a logo set', function (done) {
|
it('should draw the logo on #clear with a logo set', function (done) {
|
||||||
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
|
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
|
||||||
display.clear();
|
display.clear();
|
||||||
display.set_onFlush(function () {
|
display.set_onFlush(function () {
|
||||||
expect(display).to.have.displayed(checked_data);
|
|
||||||
expect(display._fb_width).to.equal(4);
|
|
||||||
expect(display._fb_height).to.equal(4);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
display.flush();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not draw directly on the target canvas', function () {
|
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
|
||||||
display.flip();
|
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
|
||||||
var expected = [];
|
|
||||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
|
||||||
expected[i] = 0xff;
|
|
||||||
expected[i+1] = expected[i+2] = 0;
|
|
||||||
expected[i+3] = 0xff;
|
|
||||||
}
|
|
||||||
expect(display).to.have.displayed(new Uint8Array(expected));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support filling a rectangle with particular color via #fillRect', function () {
|
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
|
||||||
display.fillRect(0, 0, 2, 2, [0xff, 0, 0]);
|
|
||||||
display.fillRect(2, 2, 2, 2, [0xff, 0, 0]);
|
|
||||||
display.flip();
|
|
||||||
expect(display).to.have.displayed(checked_data);
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
expect(display._fb_width).to.equal(4);
|
||||||
|
expect(display._fb_height).to.equal(4);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
display.flush();
|
||||||
|
});
|
||||||
|
|
||||||
it('should support copying an portion of the canvas via #copyImage', function () {
|
it('should not draw directly on the target canvas', function () {
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
||||||
display.fillRect(0, 0, 2, 2, [0xff, 0, 0x00]);
|
display.flip();
|
||||||
display.copyImage(0, 0, 2, 2, 2, 2);
|
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||||
display.flip();
|
var expected = [];
|
||||||
|
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
||||||
|
expected[i] = 0xff;
|
||||||
|
expected[i+1] = expected[i+2] = 0;
|
||||||
|
expected[i+3] = 0xff;
|
||||||
|
}
|
||||||
|
expect(display).to.have.displayed(new Uint8Array(expected));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support filling a rectangle with particular color via #fillRect', function () {
|
||||||
|
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||||
|
display.fillRect(0, 0, 2, 2, [0xff, 0, 0]);
|
||||||
|
display.fillRect(2, 2, 2, 2, [0xff, 0, 0]);
|
||||||
|
display.flip();
|
||||||
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support copying an portion of the canvas via #copyImage', function () {
|
||||||
|
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||||
|
display.fillRect(0, 0, 2, 2, [0xff, 0, 0x00]);
|
||||||
|
display.copyImage(0, 0, 2, 2, 2, 2);
|
||||||
|
display.flip();
|
||||||
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support drawing images via #imageRect', function (done) {
|
||||||
|
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
|
||||||
|
display.flip();
|
||||||
|
display.set_onFlush(function () {
|
||||||
expect(display).to.have.displayed(checked_data);
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
display.flush();
|
||||||
|
});
|
||||||
|
|
||||||
it('should support drawing images via #imageRect', function (done) {
|
it('should support drawing tile data with a background color and sub tiles', function () {
|
||||||
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
|
display.startTile(0, 0, 4, 4, [0, 0xff, 0]);
|
||||||
display.flip();
|
display.subTile(0, 0, 2, 2, [0xff, 0, 0]);
|
||||||
display.set_onFlush(function () {
|
display.subTile(2, 2, 2, 2, [0xff, 0, 0]);
|
||||||
expect(display).to.have.displayed(checked_data);
|
display.finishTile();
|
||||||
done();
|
display.flip();
|
||||||
});
|
expect(display).to.have.displayed(checked_data);
|
||||||
display.flush();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should support drawing tile data with a background color and sub tiles', function () {
|
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
||||||
display.startTile(0, 0, 4, 4, [0, 0xff, 0]);
|
var data = [];
|
||||||
display.subTile(0, 0, 2, 2, [0xff, 0, 0]);
|
for (var i = 0; i < 16; i++) {
|
||||||
display.subTile(2, 2, 2, 2, [0xff, 0, 0]);
|
data[i * 4] = checked_data[i * 4 + 2];
|
||||||
display.finishTile();
|
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
||||||
display.flip();
|
data[i * 4 + 2] = checked_data[i * 4];
|
||||||
expect(display).to.have.displayed(checked_data);
|
data[i * 4 + 3] = checked_data[i * 4 + 3];
|
||||||
});
|
}
|
||||||
|
display.blitImage(0, 0, 4, 4, data, 0);
|
||||||
|
display.flip();
|
||||||
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
});
|
||||||
|
|
||||||
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
||||||
var data = [];
|
var data = [];
|
||||||
for (var i = 0; i < 16; i++) {
|
for (var i = 0; i < 16; i++) {
|
||||||
data[i * 4] = checked_data[i * 4 + 2];
|
data[i * 3] = checked_data[i * 4];
|
||||||
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
||||||
data[i * 4 + 2] = checked_data[i * 4];
|
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
||||||
data[i * 4 + 3] = checked_data[i * 4 + 3];
|
}
|
||||||
}
|
display.blitRgbImage(0, 0, 4, 4, data, 0);
|
||||||
display.blitImage(0, 0, 4, 4, data, 0);
|
display.flip();
|
||||||
display.flip();
|
expect(display).to.have.displayed(checked_data);
|
||||||
expect(display).to.have.displayed(checked_data);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
it('should support drawing an image object via #drawImage', function () {
|
||||||
var data = [];
|
var img = make_image_canvas(checked_data);
|
||||||
for (var i = 0; i < 16; i++) {
|
display.drawImage(img, 0, 0);
|
||||||
data[i * 3] = checked_data[i * 4];
|
display.flip();
|
||||||
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
expect(display).to.have.displayed(checked_data);
|
||||||
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
});
|
||||||
}
|
|
||||||
display.blitRgbImage(0, 0, 4, 4, data, 0);
|
|
||||||
display.flip();
|
|
||||||
expect(display).to.have.displayed(checked_data);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support drawing an image object via #drawImage', function () {
|
|
||||||
var img = make_image_canvas(checked_data);
|
|
||||||
display.drawImage(img, 0, 0);
|
|
||||||
display.flip();
|
|
||||||
expect(display).to.have.displayed(checked_data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('(prefering native methods)', function () { drawing_tests.call(this, false); });
|
|
||||||
describe('(prefering JavaScript)', function () { drawing_tests.call(this, true); });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the render queue processor', function () {
|
describe('the render queue processor', function () {
|
||||||
var display;
|
var display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'), { prefer_js: false });
|
display = new Display(document.createElement('canvas'));
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
sinon.spy(display, '_scan_renderQ');
|
sinon.spy(display, '_scan_renderQ');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue