Skip to content

Commit 3e09154

Browse files
authored
Merge pull request #3335 from dabingnn/add_dirtyRegion
Add dirty region
2 parents 6eba2ac + 5a15370 commit 3e09154

18 files changed

+749
-211
lines changed

cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js

+25-17
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,15 @@
5757
}
5858

5959
stencil._renderCmd.rendering = function (ctx, scaleX, scaleY) {
60-
scaleX = scaleX || cc.view.getScaleX();
61-
scaleY = scaleY ||cc.view.getScaleY();
62-
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
60+
//make it do nothing and draw it in clipp render command
61+
return;
62+
};
6363

64-
var t = this._transform;
65-
context.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY);
66-
for (var i = 0; i < stencil._buffer.length; i++) {
67-
var vertices = stencil._buffer[i].verts;
68-
//TODO: need support circle etc
69-
//cc.assert(cc.vertexListIsClockwise(vertices),
70-
// "Only clockwise polygons should be used as stencil");
64+
stencil._renderCmd._canUseDirtyRegion = true;
65+
this._rendererSaveCmd._canUseDirtyRegion = true;
66+
this._rendererClipCmd._canUseDirtyRegion = true;
67+
this._rendererRestoreCmd._canUseDirtyRegion = true;
7168

72-
var firstPoint = vertices[0];
73-
context.moveTo(firstPoint.x * scaleX, -firstPoint.y * scaleY);
74-
for (var j = vertices.length - 1; j > 0; j--)
75-
context.lineTo(vertices[j].x * scaleX, -vertices[j].y * scaleY);
76-
}
77-
};
7869
}else{
7970
stencil._parent = this._node;
8071
}
@@ -92,11 +83,11 @@
9283
locCacheCtx.drawImage(canvas, 0, 0); //save the result to shareCache canvas
9384
} else {
9485
wrapper.save();
95-
context.beginPath(); //save for clip
9686
//Because drawNode's content size is zero
9787
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
9888

9989
if (this._node.inverted) {
90+
context.beginPath(); //save for clip
10091
context.rect(0, 0, context.canvas.width, -context.canvas.height);
10192
context.clip();
10293
}
@@ -126,6 +117,23 @@
126117
//hack
127118
this._setStencilCompositionOperation(node._stencil);
128119
} else {
120+
var stencil = this._node._stencil;
121+
if(stencil instanceof cc.DrawNode) {
122+
context.beginPath();
123+
var t = stencil._renderCmd._transform;
124+
context.transform(t.a, t.b, t.c, t.d, t.tx, -t.ty);
125+
for (var i = 0; i < stencil._buffer.length; i++) {
126+
var vertices = stencil._buffer[i].verts;
127+
//TODO: need support circle etc
128+
//cc.assert(cc.vertexListIsClockwise(vertices),
129+
// "Only clockwise polygons should be used as stencil");
130+
131+
var firstPoint = vertices[0];
132+
context.moveTo(firstPoint.x , -firstPoint.y );
133+
for (var j = vertices.length - 1; j > 0; j--)
134+
context.lineTo(vertices[j].x , -vertices[j].y );
135+
}
136+
}
129137
context.clip();
130138
}
131139
};

cocos2d/core/CCDrawingPrimitivesCanvas.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
9797
drawLine:function (origin, destination) {
9898
var locContext = this._renderContext.getContext(), locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
9999
locContext.beginPath();
100-
locContext.moveTo(origin.x * locScaleX, -origin.y * locScaleY);
101-
locContext.lineTo(destination.x * locScaleX, -destination.y * locScaleY);
100+
locContext.moveTo(origin.x , -origin.y );
101+
locContext.lineTo(destination.x, -destination.y );
102102
locContext.closePath();
103103
locContext.stroke();
104104
},
@@ -153,9 +153,9 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
153153
var firstPoint = vertices[0], locContext = this._renderContext.getContext();
154154
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
155155
locContext.beginPath();
156-
locContext.moveTo(firstPoint.x * locScaleX, -firstPoint.y * locScaleY);
156+
locContext.moveTo(firstPoint.x , -firstPoint.y );
157157
for (var i = 1, len = vertices.length; i < len; i++)
158-
locContext.lineTo(vertices[i].x * locScaleX, -vertices[i].y * locScaleY);
158+
locContext.lineTo(vertices[i].x , -vertices[i].y );
159159

160160
if (closePolygon)
161161
locContext.closePath();
@@ -192,9 +192,9 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
192192
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
193193
locContext.beginPath();
194194
var endAngle = angle - Math.PI * 2;
195-
locContext.arc(0 | (center.x * locScaleX), 0 | -(center.y * locScaleY), radius * locScaleX, -angle, -endAngle, false);
195+
locContext.arc(0 | (center.x ), 0 | -(center.y ), radius , -angle, -endAngle, false);
196196
if (drawLineToCenter) {
197-
locContext.lineTo(0 | (center.x * locScaleX), 0 | -(center.y * locScaleY));
197+
locContext.lineTo(0 | (center.x ), 0 | -(center.y ));
198198
}
199199
locContext.stroke();
200200
},
@@ -338,7 +338,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
338338
drawStar:function (ctx, radius, color) {
339339
var wrapper = ctx || this._renderContext;
340340
var context = wrapper.getContext();
341-
radius *= cc.view.getScaleX();
342341
var colorStr = "rgba(" + (0 | color.r) + "," + (0 | color.g) + "," + (0 | color.b);
343342
wrapper.setFillStyle(colorStr + ",1)");
344343
//context.fillStyle = colorStr + ",1)";

0 commit comments

Comments
 (0)