aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-04 22:27:10 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-04 22:27:10 +0000
commit6f8f292aa768869a9e85c314b124875f57504f2c (patch)
treef6131fb47de094839c6a3defecabf8c0fec6e26d /gpu
parentf966fd35cf37562df7aaaf08a490582b764ba170 (diff)
add origin to device
used for interpreting the clipstack when a device is a layer git-svn-id: http://skia.googlecode.com/svn/trunk@894 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu')
-rw-r--r--gpu/include/GrClip.h13
-rw-r--r--gpu/include/GrPath.h6
-rw-r--r--gpu/include/GrRect.h8
-rw-r--r--gpu/src/GrClip.cpp14
-rw-r--r--gpu/src/GrPath.cpp33
5 files changed, 60 insertions, 14 deletions
diff --git a/gpu/include/GrClip.h b/gpu/include/GrClip.h
index 414a6d6806..64c9bbbb34 100644
--- a/gpu/include/GrClip.h
+++ b/gpu/include/GrClip.h
@@ -28,7 +28,11 @@ class GrClip {
public:
GrClip();
GrClip(const GrClip& src);
- GrClip(GrClipIterator* iter, const GrRect* bounds = NULL);
+ /**
+ * If specified, the bounds parameter already takes (tx,ty) into account.
+ */
+ GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* bounds = NULL);
GrClip(const GrIRect& rect);
GrClip(const GrRect& rect);
@@ -77,7 +81,12 @@ public:
* Resets this clip to be empty
*/
void setEmpty();
- void setFromIterator(GrClipIterator* iter, const GrRect* bounds = NULL);
+
+ /**
+ * If specified, the bounds parameter already takes (tx,ty) into account.
+ */
+ void setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* bounds = NULL);
void setFromRect(const GrRect& rect);
void setFromIRect(const GrIRect& rect);
diff --git a/gpu/include/GrPath.h b/gpu/include/GrPath.h
index d70609ee6b..80bbeb358b 100644
--- a/gpu/include/GrPath.h
+++ b/gpu/include/GrPath.h
@@ -46,6 +46,12 @@ public:
GrScalar x2, GrScalar y2);
virtual void close();
+ /**
+ * Offset the path by (tx, ty), adding tx to the horizontal position
+ * and adds ty to the vertical position of every point.
+ */
+ void offset(GrScalar tx, GrScalar ty);
+
class Iter : public GrPathIter {
public:
/**
diff --git a/gpu/include/GrRect.h b/gpu/include/GrRect.h
index e0e53264fd..552fa5e58c 100644
--- a/gpu/include/GrRect.h
+++ b/gpu/include/GrRect.h
@@ -223,6 +223,14 @@ struct GrRect {
fBottom >= r.fBottom;
}
+ /**
+ * Offset the rectangle by (tx, ty), adding tx to the horizontal position
+ * and adds ty to the vertical position.
+ */
+ void offset(GrScalar tx, GrScalar ty) {
+ fLeft += tx; fTop += ty;
+ fRight += tx; fBottom += ty;
+ }
/**
* Initialize a rectangle to a point.
diff --git a/gpu/src/GrClip.cpp b/gpu/src/GrClip.cpp
index 924c01b9f8..5ba991bb1c 100644
--- a/gpu/src/GrClip.cpp
+++ b/gpu/src/GrClip.cpp
@@ -38,9 +38,10 @@ GrClip::GrClip(const GrRect& rect)
this->setFromRect(rect);
}
-GrClip::GrClip(GrClipIterator* iter, const GrRect* bounds)
+GrClip::GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* bounds)
: fList(fListMemory, kPreAllocElements) {
- this->setFromIterator(iter, bounds);
+ this->setFromIterator(iter, tx, ty, bounds);
}
GrClip::~GrClip() {}
@@ -86,7 +87,8 @@ void GrClip::setFromIRect(const GrIRect& r) {
}
}
-void GrClip::setFromIterator(GrClipIterator* iter, const GrRect* bounds) {
+void GrClip::setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* bounds) {
fList.reset();
int rectCount = 0;
@@ -104,6 +106,9 @@ void GrClip::setFromIterator(GrClipIterator* iter, const GrRect* bounds) {
switch (e.fType) {
case kRect_ClipType:
iter->getRect(&e.fRect);
+ if (tx || ty) {
+ e.fRect.offset(tx, ty);
+ }
++rectCount;
if (isectRectValid) {
if (1 == rectCount || kIntersect_SetOp == e.fOp) {
@@ -122,6 +127,9 @@ void GrClip::setFromIterator(GrClipIterator* iter, const GrRect* bounds) {
break;
case kPath_ClipType:
e.fPath.resetFromIter(iter->getPathIter());
+ if (tx || ty) {
+ e.fPath.offset(tx, ty);
+ }
e.fPathFill = iter->getPathFill();
isectRectValid = false;
break;
diff --git a/gpu/src/GrPath.cpp b/gpu/src/GrPath.cpp
index fc53ac2335..019b2fd5c4 100644
--- a/gpu/src/GrPath.cpp
+++ b/gpu/src/GrPath.cpp
@@ -84,12 +84,27 @@ void GrPath::close() {
///////////////////////////////////////////////////////////////////////////////
+void GrPath::offset(GrScalar tx, GrScalar ty) {
+ if (!tx && !ty) {
+ return; // nothing to do
+ }
+
+ GrPoint* iter = fPts.begin();
+ GrPoint* stop = fPts.end();
+ while (iter < stop) {
+ iter->offset(tx, ty);
+ ++iter;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
static bool check_two_vecs(const GrVec& prevVec,
const GrVec& currVec,
GrScalar turnDir,
int* xDir,
int* yDir,
- int* flipX,
+ int* flipX,
int* flipY) {
if (currVec.fX * *xDir < 0) {
++*flipX;
@@ -214,9 +229,9 @@ void GrPath::resetFromIter(GrPathIter* iter) {
vec.setBetween(previousPt, pts[consumed]);
if (vec.fX || vec.fY) {
if (subPathPts >= 2) {
- if (0 == turnDir) {
+ if (0 == turnDir) {
firstVec = previousVec;
- init_from_two_vecs(firstVec, vec,
+ init_from_two_vecs(firstVec, vec,
&turnDir, &xDir, &yDir);
// here we aren't checking whether the x/y dirs
// change between the first and second edge. It
@@ -236,14 +251,14 @@ void GrPath::resetFromIter(GrPathIter* iter) {
}
++consumed;
}
- if (subPathPts > 2 && (kClose_PathCmd == cmd ||
+ if (subPathPts > 2 && (kClose_PathCmd == cmd ||
(!subPathClosed && kEnd_PathCmd == cmd ))) {
// if an additional vector is needed to close the loop check
// that it validates against the previous vector.
GrVec vec;
vec.setBetween(previousPt, firstPt);
if (vec.fX || vec.fY) {
- if (!check_two_vecs(previousVec, vec, turnDir,
+ if (!check_two_vecs(previousVec, vec, turnDir,
&xDir, &yDir, &flipX, &flipY)) {
fConvexHint = kConcave_ConvexHint;
break;
@@ -251,7 +266,7 @@ void GrPath::resetFromIter(GrPathIter* iter) {
previousVec = vec;
}
// check that closing vector validates against the first vector.
- if (!check_two_vecs(previousVec, firstVec, turnDir,
+ if (!check_two_vecs(previousVec, firstVec, turnDir,
&xDir, &yDir, &flipX, &flipY)) {
fConvexHint = kConcave_ConvexHint;
break;
@@ -309,7 +324,7 @@ void GrPath::ConvexUnitTest() {
testIter.reset(triRight);
testPath.resetFromIter(&testIter);
GrAssert(kConvex_ConvexHint == testPath.getConvexHint());
-
+
GrPath square;
square.moveTo(0, 0);
square.lineTo(1, 0);
@@ -335,7 +350,7 @@ void GrPath::ConvexUnitTest() {
square.lineTo(0, 1);
square.lineTo(0, 1);
square.close();
-
+
testIter.reset(redundantSquare);
testPath.resetFromIter(&testIter);
GrAssert(kConvex_ConvexHint == testPath.getConvexHint());
@@ -354,7 +369,7 @@ void GrPath::ConvexUnitTest() {
bowTie.lineTo(0, 1);
bowTie.lineTo(0, 1);
bowTie.close();
-
+
testIter.reset(bowTie);
testPath.resetFromIter(&testIter);
GrAssert(kConcave_ConvexHint == testPath.getConvexHint());