Remove blitStringImage() in favour of imageRect()

The latter is more generic and can easily be modified for other
mechanisms in the future.
This commit is contained in:
Pierre Ossman 2016-10-29 15:00:22 +02:00
parent 18e96092c3
commit 74e390512d
2 changed files with 27 additions and 31 deletions

View File

@ -350,7 +350,7 @@
clear: function () {
if (this._logo) {
this.resize(this._logo.width, this._logo.height);
this.blitStringImage(this._logo.data, 0, 0);
this.imageRect(0, 0, this._logo.type, this._logo.data);
} else {
if (Util.Engine.trident === 6) {
// NB(directxman12): there's a bug in IE10 where we can fail to actually
@ -563,15 +563,6 @@
}
},
blitStringImage: function (str, x, y) {
var img = new Image();
img.onload = function () {
this._drawCtx.drawImage(img, x - this._viewportLoc.x, y - this._viewportLoc.y);
}.bind(this);
img.src = str;
return img; // for debugging purposes
},
// wrap ctx.drawImage but relative to viewport
drawImage: function (img, x, y) {
this._drawCtx.drawImage(img, x - this._viewportLoc.x, y - this._viewportLoc.y);
@ -820,7 +811,7 @@
Util.make_properties(Display, [
['target', 'wo', 'dom'], // Canvas element for rendering
['context', 'ro', 'raw'], // Canvas 2D context for rendering (read-only)
['logo', 'rw', 'raw'], // Logo to display when cleared: {"width": w, "height": h, "data": data}
['logo', 'rw', 'raw'], // Logo to display when cleared: {"width": w, "height": h, "type": mime-type, "data": data}
['true_color', 'rw', 'bool'], // Use true-color pixel data
['colourMap', 'rw', 'arr'], // Colour map array (when not true-color)
['scale', 'rw', 'float'], // Display area scale factor 0.0 - 1.0

View File

@ -26,6 +26,13 @@ describe('Display/Canvas Helper', function () {
return canvas;
}
function make_image_png (input_data) {
var canvas = make_image_canvas(input_data);
var url = canvas.toDataURL();
var data = url.split(",")[1];
return Base64.decode(data);
}
describe('checking for cursor uri support', function () {
beforeEach(function () {
this._old_browser_supports_cursor_uris = Util.browserSupportsCursorURIs;
@ -282,16 +289,15 @@ describe('Display/Canvas Helper', function () {
});
it('should draw the logo on #clear with a logo set', function (done) {
display._logo = { width: 4, height: 4, data: make_image_canvas(checked_data).toDataURL() };
display._drawCtx._act_drawImg = display._drawCtx.drawImage;
display._drawCtx.drawImage = function (img, x, y) {
this._act_drawImg(img, x, y);
expect(display).to.have.displayed(checked_data);
done();
};
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
display.clear();
expect(display._fb_width).to.equal(4);
expect(display._fb_height).to.equal(4);
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 filling a rectangle with particular color via #fillRect', function () {
@ -308,6 +314,16 @@ describe('Display/Canvas Helper', function () {
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);
done();
});
display.flush();
});
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]);
@ -339,17 +355,6 @@ describe('Display/Canvas Helper', function () {
expect(display).to.have.displayed(checked_data);
});
it('should support drawing blit images from a data URL via #blitStringImage', function (done) {
var img_url = make_image_canvas(checked_data).toDataURL();
display._drawCtx._act_drawImg = display._drawCtx.drawImage;
display._drawCtx.drawImage = function (img, x, y) {
this._act_drawImg(img, x, y);
expect(display).to.have.displayed(checked_data);
done();
};
display.blitStringImage(img_url, 0, 0);
});
it('should support drawing solid colors with color maps', function () {
display._true_color = false;
display.set_colourMap({ 0: [0xff, 0, 0], 1: [0, 0xff, 0] });