Skip to content
Open
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
105 changes: 55 additions & 50 deletions lib/zebra/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,7 @@ pkg.Manager = Class([
*/
pkg.PaintManager = Class(pkg.Manager, [
function $prototype() {
var $painting = {};
var $timers = {};

/**
Expand Down Expand Up @@ -2834,62 +2835,66 @@ pkg.PaintManager = Class(pkg.Manager, [
if (h + y > y2) h = y2 - y;

if (w > 0 && h > 0) {
if ($painting[canvas] != null) {
//!!! Perhaps a better policy is to honor
// the repaint request anyway, but still
// emit a warning
zebra.warn('repaint called synchronously from paint, update, or paintOnTop ignored!');
return;
}

var da = canvas.$da;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement (canvas.js line 2851) seems redundant since MB.unite should take care of it anyway (and you're saving very little by doing this check beforehand), but I left it in just in case.

Sorry I couldn't figure out how to select the line ranges on github :(.

if (da.width > 0) {
if (x >= da.x &&
y >= da.y &&
x + w <= da.x + da.width &&
y + h <= da.y + da.height )
{
return;
if ($timers[canvas] != null) {
// paint is already scheduled, just need
// to update the dirty area

if (x < da.x ||
y < da.y ||
x + w > da.x + da.width ||
y + h > da.y + da.height )
{
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
else {
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);
return;
}

if (da.width > 0 && $timers[canvas] == null) {
var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;

// prevent double painting, sometimes
// width can be -1 what cause clearRect
// clean incorrectly
if (canvas.$da.width <= 0) {
return ;
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);

var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;

var context = canvas.$context;
// record that we are painting to warn
// if repaint is called recursively
$painting[canvas] = true;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

var context = canvas.$context;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

$this.paint(context, canvas);

context.restore();
canvas.$da.width = -1; //!!!
}
catch(e) { zebra.print(e); }
}, 50);
}
$this.paint(context, canvas);

context.restore();
}
catch(e) { zebra.print(e); }
$painting[canvas] = null;
}, 50);

// !!! not sure the code below is redundant, but it looks redundantly
// if (da.width > 0) {
Expand Down
103 changes: 54 additions & 49 deletions lib/zebra/zebra.canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8251,6 +8251,7 @@ pkg.Manager = Class([
*/
pkg.PaintManager = Class(pkg.Manager, [
function $prototype() {
var $painting = {};
var $timers = {};

/**
Expand Down Expand Up @@ -8312,62 +8313,66 @@ pkg.PaintManager = Class(pkg.Manager, [
if (h + y > y2) h = y2 - y;

if (w > 0 && h > 0) {
if ($painting[canvas] != null) {
//!!! Perhaps a better policy is to honor
// the repaint request anyway, but still
// emit a warning
zebra.warn('repaint called synchronously from paint, update, or paintOnTop ignored!');
return;
}

var da = canvas.$da;
if (da.width > 0) {
if (x >= da.x &&
y >= da.y &&
x + w <= da.x + da.width &&
y + h <= da.y + da.height )
{
return;
if ($timers[canvas] != null) {
// paint is already scheduled, just need
// to update the dirty area

if (x < da.x ||
y < da.y ||
x + w > da.x + da.width ||
y + h > da.y + da.height )
{
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
else {
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);
return;
}

if (da.width > 0 && $timers[canvas] == null) {
var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;

// prevent double painting, sometimes
// width can be -1 what cause clearRect
// clean incorrectly
if (canvas.$da.width <= 0) {
return ;
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);

var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;

var context = canvas.$context;
// record that we are painting to warn
// if repaint is called recursively
$painting[canvas] = true;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

var context = canvas.$context;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

$this.paint(context, canvas);
$this.paint(context, canvas);

context.restore();
canvas.$da.width = -1; //!!!
}
catch(e) { zebra.print(e); }
}, 50);
}
context.restore();
}
catch(e) { zebra.print(e); }
$painting[canvas] = null;
}, 50);

// !!! not sure the code below is redundant, but it looks redundantly
// if (da.width > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/zebra/zebra.canvas.min.js

Large diffs are not rendered by default.

101 changes: 53 additions & 48 deletions lib/zebra/zebra.js
Original file line number Diff line number Diff line change
Expand Up @@ -9047,6 +9047,7 @@ pkg.Manager = Class([
*/
pkg.PaintManager = Class(pkg.Manager, [
function $prototype() {
var $painting = {};
var $timers = {};

/**
Expand Down Expand Up @@ -9108,62 +9109,66 @@ pkg.PaintManager = Class(pkg.Manager, [
if (h + y > y2) h = y2 - y;

if (w > 0 && h > 0) {
if ($painting[canvas] != null) {
//!!! Perhaps a better policy is to honor
// the repaint request anyway, but still
// emit a warning
zebra.warn('repaint called synchronously from paint, update, or paintOnTop ignored!');
return;
}

var da = canvas.$da;
if (da.width > 0) {
if (x >= da.x &&
y >= da.y &&
x + w <= da.x + da.width &&
y + h <= da.y + da.height )
{
return;
if ($timers[canvas] != null) {
// paint is already scheduled, just need
// to update the dirty area

if (x < da.x ||
y < da.y ||
x + w > da.x + da.width ||
y + h > da.y + da.height )
{
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
MB.unite(da.x, da.y, da.width, da.height, x, y, w, h, da);
}
else {
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);
return;
}

if (da.width > 0 && $timers[canvas] == null) {
var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;
MB.intersection(0, 0, canvas.width, canvas.height, x, y, w, h, da);

// prevent double painting, sometimes
// width can be -1 what cause clearRect
// clean incorrectly
if (canvas.$da.width <= 0) {
return ;
var $this = this;
$timers[canvas] = setTimeout(function() {
$timers[canvas] = null;

var context = canvas.$context;
// record that we are painting to warn
// if repaint is called recursively
$painting[canvas] = true;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

var context = canvas.$context;
try {
canvas.validate();
context.save();
context.translate(canvas.x, canvas.y);

//!!!! debug
// zebra.print(" ============== DA = " + canvas.$da.y );
// var dg = canvas.canvas.getContext("2d");
// dg.strokeStyle = 'red';
// dg.beginPath();
// dg.rect(da.x, da.y, da.width, da.height);
// dg.stroke();

context.clipRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
if (canvas.bg == null) {
context.clearRect(canvas.$da.x, canvas.$da.y,
canvas.$da.width, canvas.$da.height);
}

$this.paint(context, canvas);
$this.paint(context, canvas);

context.restore();
canvas.$da.width = -1; //!!!
}
catch(e) { zebra.print(e); }
}, 50);
}
context.restore();
}
catch(e) { zebra.print(e); }
$painting[canvas] = null;
}, 50);

// !!! not sure the code below is redundant, but it looks redundantly
// if (da.width > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/zebra/zebra.min.js

Large diffs are not rendered by default.