From 134ec26ee095ca1bc64a09a11d3ad516ac76d5ff Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sat, 14 Oct 2017 16:44:40 +0200 Subject: [PATCH] Remove non-JavaScript render code It wasn't used anyway so simplify things. --- core/display.js | 71 ++++++-------- docs/API-internal.md | 1 - tests/test.display.js | 209 +++++++++++++++++++++--------------------- 3 files changed, 129 insertions(+), 152 deletions(-) diff --git a/core/display.js b/core/display.js index dbeee24..6b036ff 100644 --- a/core/display.js +++ b/core/display.js @@ -77,11 +77,6 @@ export default function Display(target, defaults) { 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 if (this._cursor_uri || this._cursor_uri === null || this._cursor_uri === undefined) { @@ -381,56 +376,45 @@ Display.prototype = { this._tile = this._drawCtx.createImageData(width, height); } - if (this._prefer_js) { - var red = color[2]; - var green = color[1]; - var blue = color[0]; + var red = color[2]; + var green = color[1]; + var blue = color[0]; - var data = this._tile.data; - for (var i = 0; i < width * height * 4; i += 4) { - data[i] = red; - data[i + 1] = green; - data[i + 2] = blue; - data[i + 3] = 255; - } - } else { - this.fillRect(x, y, width, height, color, true); + var data = this._tile.data; + for (var i = 0; i < width * height * 4; i += 4) { + data[i] = red; + data[i + 1] = green; + data[i + 2] = blue; + data[i + 3] = 255; } }, // update sub-rectangle of the current tile subTile: function (x, y, w, h, color) { - if (this._prefer_js) { - var red = color[2]; - var green = color[1]; - var blue = color[0]; - var xend = x + w; - var yend = y + h; - - var data = this._tile.data; - var width = this._tile.width; - for (var j = y; j < yend; j++) { - for (var i = x; i < xend; i++) { - var p = (i + (j * width)) * 4; - data[p] = red; - data[p + 1] = green; - data[p + 2] = blue; - data[p + 3] = 255; - } + var red = color[2]; + var green = color[1]; + var blue = color[0]; + var xend = x + w; + var yend = y + h; + + var data = this._tile.data; + var width = this._tile.width; + for (var j = y; j < yend; j++) { + for (var i = x; i < xend; i++) { + var p = (i + (j * width)) * 4; + data[p] = red; + data[p + 1] = green; + data[p + 2] = blue; + 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 finishTile: function () { - if (this._prefer_js) { - this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y); - this._damage(this._tile_x, this._tile_y, - this._tile.width, this._tile.height); - } - // else: No-op -- already done by setSubTile + this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y); + this._damage(this._tile_x, this._tile_y, + this._tile.width, this._tile.height); }, blitImage: function (x, y, width, height, arr, offset, from_queue) { @@ -697,7 +681,6 @@ make_properties(Display, [ ['width', 'ro', 'int'], // Display area width ['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 ['onFlush', 'rw', 'func'], // onFlush(): A flush request has finished diff --git a/docs/API-internal.md b/docs/API-internal.md index a5324be..e33f806 100644 --- a/docs/API-internal.md +++ b/docs/API-internal.md @@ -97,7 +97,6 @@ None | viewport | bool | RW | false | Use viewport clipping | width | int | RO | | Display area width | 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 ### 2.3.2 Methods diff --git a/tests/test.display.js b/tests/test.display.js index 7706587..3a8c13d 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -40,19 +40,19 @@ describe('Display/Canvas Helper', function () { describe('checking for cursor uri support', function () { it('should disable cursor URIs if there is no support', function () { _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; }); it('should enable cursor URIs if there is support', function () { _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; }); it('respect the cursor_uri option if there is support', function () { _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; }); }); @@ -60,7 +60,7 @@ describe('Display/Canvas Helper', function () { describe('viewport handling', function () { var display; 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.viewportChangeSize(3, 3); display.viewportChangePos(1, 1); @@ -153,7 +153,7 @@ describe('Display/Canvas Helper', function () { describe('resizing', function () { var display; 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); }); @@ -215,7 +215,7 @@ describe('Display/Canvas Helper', function () { beforeEach(function () { canvas = document.createElement('canvas'); - display = new Display(canvas, { prefer_js: false, viewport: true }); + display = new Display(canvas, { viewport: true }); display.resize(4, 4); display.viewportChangeSize(3, 3); display.viewportChangePos(1, 1); @@ -255,7 +255,7 @@ describe('Display/Canvas Helper', function () { beforeEach(function () { canvas = document.createElement('canvas'); - display = new Display(canvas, { prefer_js: false, viewport: true }); + display = new Display(canvas, { viewport: true }); display.resize(4, 3); 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 // basic cases - function drawing_tests (pref_js) { - var display; - beforeEach(function () { - display = new Display(document.createElement('canvas'), { prefer_js: pref_js }); - display.resize(4, 4); - }); - - it('should clear the screen on #clear without a logo set', function () { - display.fillRect(0, 0, 4, 4, [0x00, 0x00, 0xff]); - display._logo = null; - display.clear(); - display.resize(4, 4); - var empty = []; - for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; } - expect(display).to.have.displayed(new Uint8Array(empty)); - }); - - 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.clear(); - 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(); - }); + var display; + beforeEach(function () { + display = new Display(document.createElement('canvas')); + display.resize(4, 4); + }); - 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 clear the screen on #clear without a logo set', function () { + display.fillRect(0, 0, 4, 4, [0x00, 0x00, 0xff]); + display._logo = null; + display.clear(); + display.resize(4, 4); + var empty = []; + for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; } + expect(display).to.have.displayed(new Uint8Array(empty)); + }); - 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(); + 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.clear(); + 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 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 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 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); - done(); - }); - display.flush(); - }); + 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 drawing tile data with a background color and sub tiles', function () { - display.startTile(0, 0, 4, 4, [0, 0xff, 0]); - display.subTile(0, 0, 2, 2, [0xff, 0, 0]); - display.subTile(2, 2, 2, 2, [0xff, 0, 0]); - display.finishTile(); - 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 BGRX blit images with true color via #blitImage', function () { - var data = []; - for (var i = 0; i < 16; i++) { - data[i * 4] = checked_data[i * 4 + 2]; - data[i * 4 + 1] = checked_data[i * 4 + 1]; - data[i * 4 + 2] = checked_data[i * 4]; - data[i * 4 + 3] = checked_data[i * 4 + 3]; - } - display.blitImage(0, 0, 4, 4, data, 0); - display.flip(); + 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); + done(); }); + display.flush(); + }); - it('should support drawing RGB blit images with true color via #blitRgbImage', function () { - var data = []; - for (var i = 0; i < 16; i++) { - data[i * 3] = checked_data[i * 4]; - data[i * 3 + 1] = checked_data[i * 4 + 1]; - 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 tile data with a background color and sub tiles', function () { + display.startTile(0, 0, 4, 4, [0, 0xff, 0]); + display.subTile(0, 0, 2, 2, [0xff, 0, 0]); + display.subTile(2, 2, 2, 2, [0xff, 0, 0]); + display.finishTile(); + 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); - }); - } + it('should support drawing BGRX blit images with true color via #blitImage', function () { + var data = []; + for (var i = 0; i < 16; i++) { + data[i * 4] = checked_data[i * 4 + 2]; + data[i * 4 + 1] = checked_data[i * 4 + 1]; + data[i * 4 + 2] = checked_data[i * 4]; + 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); + }); - describe('(prefering native methods)', function () { drawing_tests.call(this, false); }); - describe('(prefering JavaScript)', function () { drawing_tests.call(this, true); }); + it('should support drawing RGB blit images with true color via #blitRgbImage', function () { + var data = []; + for (var i = 0; i < 16; i++) { + data[i * 3] = checked_data[i * 4]; + data[i * 3 + 1] = checked_data[i * 4 + 1]; + 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('the render queue processor', function () { var display; beforeEach(function () { - display = new Display(document.createElement('canvas'), { prefer_js: false }); + display = new Display(document.createElement('canvas')); display.resize(4, 4); sinon.spy(display, '_scan_renderQ'); }); -- 2.39.5