Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP: Update one more frame after canvas source paused (#8130) #8163

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/source/canvas_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ class CanvasSource extends ImageSource {
};

this.pause = function() {
this._playing = false;
if (this._playing) {
this.prepare();
this._playing = false;
}
};

this._finishLoading();
Expand Down
Binary file added test/integration/image/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions test/integration/render-tests/canvas/update/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64,
"addFakeCanvas": {
"id": "fake-canvas",
"image": "./image/0.png"
},
"operations": [
["wait"],
["updateFakeCanvas", "canvas", "./image/1.png", "./image/0.png"]
]
}
},
"center": [
-122.514426,
37.562984
],
"zoom": 14,
"sources": {
"canvas": {
"type": "canvas",
"animate": false,
"coordinates": [
[
-122.51596391201019,
37.56238816766053
],
[
-122.51467645168304,
37.56410183312965
],
[
-122.51309394836426,
37.563391708549425
],
[
-122.51423120498657,
37.56161849366671
]
],
"canvas": "fake-canvas"
}
},
"layers": [
{
"id": "canvas",
"type": "raster",
"source": "canvas",
"paint": {
"raster-fade-duration": 0
}
}
]
}
16 changes: 16 additions & 0 deletions test/suite_implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ module.exports = function(style, options, _callback) { // eslint-disable-line im
map.addLayer(new customLayerImplementations[operation[1]](), operation[2]);
map._render();
applyOperations(map, operations.slice(1), callback);
} else if (operation[0] === 'updateFakeCanvas') {
const canvasSource = map.getSource(operation[1]);
canvasSource.play();
// update before pause should be rendered
updateFakeCanvas(window.document, options.addFakeCanvas.id, operation[2]);
canvasSource.pause();
// update after pause should not be rendered
updateFakeCanvas(window.document, options.addFakeCanvas.id, operation[3]);
map._render();
applyOperations(map, operations.slice(1), callback);
} else if (operation[0] === 'setStyle') {
// Disable local ideograph generation (enabled by default) for
// consistent local ideograph rendering using fixtures in all runs of the test suite.
Expand All @@ -178,3 +188,9 @@ function createFakeCanvas(document, id, imagePath) {
fakeCanvas.height = image.height;
return fakeCanvas;
}

function updateFakeCanvas(document, id, imagePath) {
const fakeCanvas = document.getElementById(id);
const image = PNG.sync.read(fs.readFileSync(path.join(__dirname, './integration', imagePath)));
fakeCanvas.data = image.data;
}