Merge from Chromium at DEPS revision 33.0.1750.16

This commit was generated by merge_to_master.py.

Change-Id: Ic2c2f7b040db93139c4321c5a0f0666792156c15
diff --git a/core/SkCanvas.cpp b/core/SkCanvas.cpp
index 47d3cca..feeba75 100644
--- a/core/SkCanvas.cpp
+++ b/core/SkCanvas.cpp
@@ -19,7 +19,6 @@
 #include "SkPicture.h"
 #include "SkRasterClip.h"
 #include "SkRRect.h"
-#include "SkScalarCompare.h"
 #include "SkSurface_Base.h"
 #include "SkTemplates.h"
 #include "SkTextFormatParams.h"
@@ -485,8 +484,8 @@
 
 SkBaseDevice* SkCanvas::init(SkBaseDevice* device) {
     fBounder = NULL;
-    fLocalBoundsCompareType.setEmpty();
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBounds.setEmpty();
+    fCachedLocalClipBoundsDirty = true;
     fAllowSoftClip = true;
     fAllowSimplifyClip = false;
     fDeviceCMDirty = false;
@@ -897,7 +896,7 @@
     SkASSERT(fMCStack.count() != 0);
 
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
 
     if (SkCanvas::kClip_SaveFlag & fMCRec->fFlags) {
         fClipStack.restore();
@@ -1056,37 +1055,37 @@
 
 bool SkCanvas::translate(SkScalar dx, SkScalar dy) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     return fMCRec->fMatrix->preTranslate(dx, dy);
 }
 
 bool SkCanvas::scale(SkScalar sx, SkScalar sy) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     return fMCRec->fMatrix->preScale(sx, sy);
 }
 
 bool SkCanvas::rotate(SkScalar degrees) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     return fMCRec->fMatrix->preRotate(degrees);
 }
 
 bool SkCanvas::skew(SkScalar sx, SkScalar sy) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     return fMCRec->fMatrix->preSkew(sx, sy);
 }
 
 bool SkCanvas::concat(const SkMatrix& matrix) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     return fMCRec->fMatrix->preConcat(matrix);
 }
 
 void SkCanvas::setMatrix(const SkMatrix& matrix) {
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     *fMCRec->fMatrix = matrix;
 }
 
@@ -1110,7 +1109,7 @@
 
         if (this->quickReject(rect)) {
             fDeviceCMDirty = true;
-            fLocalBoundsCompareTypeDirty = true;
+            fCachedLocalClipBoundsDirty = true;
 
             fClipStack.clipEmpty();
             return fMCRec->fRasterClip->setEmpty();
@@ -1121,7 +1120,7 @@
     AutoValidateClip avc(this);
 
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     doAA &= fAllowSoftClip;
 
     if (fMCRec->fMatrix->rectStaysRect()) {
@@ -1206,7 +1205,7 @@
 
         if (this->quickReject(path.getBounds())) {
             fDeviceCMDirty = true;
-            fLocalBoundsCompareTypeDirty = true;
+            fCachedLocalClipBoundsDirty = true;
 
             fClipStack.clipEmpty();
             return fMCRec->fRasterClip->setEmpty();
@@ -1217,7 +1216,7 @@
     AutoValidateClip avc(this);
 
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
     doAA &= fAllowSoftClip;
 
     SkPath devPath;
@@ -1350,7 +1349,7 @@
     AutoValidateClip avc(this);
 
     fDeviceCMDirty = true;
-    fLocalBoundsCompareTypeDirty = true;
+    fCachedLocalClipBoundsDirty = true;
 
     // todo: signal fClipStack that we have a region, and therefore (I guess)
     // we have to ignore it, and use the region directly?
@@ -1423,19 +1422,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void SkCanvas::computeLocalClipBoundsCompareType() const {
-    SkRect r;
-
-    if (!this->getClipBounds(&r)) {
-        fLocalBoundsCompareType.setEmpty();
-    } else {
-        fLocalBoundsCompareType.set(SkScalarToCompareType(r.fLeft),
-                                    SkScalarToCompareType(r.fTop),
-                                    SkScalarToCompareType(r.fRight),
-                                    SkScalarToCompareType(r.fBottom));
-    }
-}
-
 bool SkCanvas::quickReject(const SkRect& rect) const {
 
     if (!rect.isFinite())
@@ -1452,17 +1438,14 @@
         dst.roundOut(&idst);
         return !SkIRect::Intersects(idst, fMCRec->fRasterClip->getBounds());
     } else {
-        const SkRectCompareType& clipR = this->getLocalClipBoundsCompareType();
+        const SkRect& clipR = this->getLocalClipBounds();
 
         // for speed, do the most likely reject compares first
-        SkScalarCompareType userT = SkScalarToCompareType(rect.fTop);
-        SkScalarCompareType userB = SkScalarToCompareType(rect.fBottom);
-        if (userT >= clipR.fBottom || userB <= clipR.fTop) {
+        // TODO: should we use | instead, or compare all 4 at once?
+        if (rect.fTop >= clipR.fBottom || rect.fBottom <= clipR.fTop) {
             return true;
         }
-        SkScalarCompareType userL = SkScalarToCompareType(rect.fLeft);
-        SkScalarCompareType userR = SkScalarToCompareType(rect.fRight);
-        if (userL >= clipR.fRight || userR <= clipR.fLeft) {
+        if (rect.fLeft >= clipR.fRight || rect.fRight <= clipR.fLeft) {
             return true;
         }
         return false;
diff --git a/core/SkDraw.cpp b/core/SkDraw.cpp
index 52891ea..ccab56c 100644
--- a/core/SkDraw.cpp
+++ b/core/SkDraw.cpp
@@ -1841,19 +1841,16 @@
 //   e.g. subpixel doesn't round
 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*);
 
-static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph,
-                          SkIPoint* dst) {
+static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
     dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY));
 }
 
-static void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph,
-                            SkIPoint* dst) {
+static void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
     dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1),
              SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1));
 }
 
-static void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph,
-                           SkIPoint* dst) {
+static void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
     dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX,
              SkScalarToFixed(loc.fY) - glyph.fAdvanceY);
 }
@@ -1868,6 +1865,32 @@
     return gProcs[align];
 }
 
+typedef void (*AlignProc_scalar)(const SkPoint&, const SkGlyph&, SkPoint*);
+
+static void leftAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) {
+    dst->set(loc.fX, loc.fY);
+}
+
+static void centerAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) {
+    dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX >> 1),
+             loc.fY - SkFixedToScalar(glyph.fAdvanceY >> 1));
+}
+
+static void rightAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) {
+    dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX),
+             loc.fY - SkFixedToScalar(glyph.fAdvanceY));
+}
+
+static AlignProc_scalar pick_align_proc_scalar(SkPaint::Align align) {
+    static const AlignProc_scalar gProcs[] = {
+        leftAlignProc_scalar, centerAlignProc_scalar, rightAlignProc_scalar
+    };
+
+    SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs));
+
+    return gProcs[align];
+}
+
 class TextMapState {
 public:
     mutable SkPoint fLoc;
@@ -1944,7 +1967,7 @@
     SkGlyphCache*       cache = autoCache.getCache();
 
     const char*        stop = text + byteLength;
-    AlignProc          alignProc = pick_align_proc(paint.getTextAlign());
+    AlignProc_scalar   alignProc = pick_align_proc_scalar(paint.getTextAlign());
     TextMapState       tms(SkMatrix::I(), constY);
     TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition);
 
@@ -1954,11 +1977,11 @@
             const SkPath* path = cache->findPath(glyph);
             if (path) {
                 tmsProc(tms, pos);
-                SkIPoint fixedLoc;
-                alignProc(tms.fLoc, glyph, &fixedLoc);
+                SkPoint loc;
+                alignProc(tms.fLoc, glyph, &loc);
 
-                matrix[SkMatrix::kMTransX] = SkFixedToScalar(fixedLoc.fX);
-                matrix[SkMatrix::kMTransY] = SkFixedToScalar(fixedLoc.fY);
+                matrix[SkMatrix::kMTransX] = loc.fX;
+                matrix[SkMatrix::kMTransY] = loc.fY;
                 if (fDevice) {
                     fDevice->drawPath(*this, *path, paint, &matrix, false);
                 } else {
diff --git a/core/SkMatrix.cpp b/core/SkMatrix.cpp
index 474f272..d9c2677 100644
--- a/core/SkMatrix.cpp
+++ b/core/SkMatrix.cpp
@@ -9,7 +9,6 @@
 #include "Sk64.h"
 #include "SkFloatBits.h"
 #include "SkOnce.h"
-#include "SkScalarCompare.h"
 #include "SkString.h"
 
 #ifdef SK_SCALAR_IS_FLOAT
@@ -251,7 +250,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) {
-    if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) {
+    if (dx || dy) {
         fMat[kMTransX] = dx;
         fMat[kMTransY] = dy;
 
@@ -273,7 +272,7 @@
         return this->preConcat(m);
     }
 
-    if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) {
+    if (dx || dy) {
         fMat[kMTransX] += SkScalarMul(fMat[kMScaleX], dx) +
                           SkScalarMul(fMat[kMSkewX], dy);
         fMat[kMTransY] += SkScalarMul(fMat[kMSkewY], dx) +
@@ -291,7 +290,7 @@
         return this->postConcat(m);
     }
 
-    if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) {
+    if (dx || dy) {
         fMat[kMTransX] += dx;
         fMat[kMTransY] += dy;
         this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
diff --git a/pdf/SkPDFDevice.cpp b/pdf/SkPDFDevice.cpp
index cdfec33..6625a8e 100644
--- a/pdf/SkPDFDevice.cpp
+++ b/pdf/SkPDFDevice.cpp
@@ -1912,8 +1912,10 @@
     ContentEntry* contentEntries = getContentEntries()->get();
     SkASSERT(dst);
     SkASSERT(!contentEntries->fNext.get());
-    // We have to make a copy of these here because changing the current
-    // content into a form-xobject will destroy them.
+    // Changing the current content into a form-xobject will destroy the clip
+    // objects which is fine since the xobject will already be clipped. However
+    // if source has shape, we need to clip it too, so a copy of the clip is
+    // saved.
     SkClipStack clipStack = contentEntries->fState.fClipStack;
     SkRegion clipRegion = contentEntries->fState.fClipRegion;
 
@@ -1930,7 +1932,8 @@
         // reduces to Dst.
         if (shape == NULL || xfermode == SkXfermode::kDstOut_Mode ||
                 xfermode == SkXfermode::kSrcATop_Mode) {
-            ScopedContentEntry content(this, &clipStack, clipRegion, identity,
+            ScopedContentEntry content(this, &fExistingClipStack,
+                                       fExistingClipRegion, identity,
                                        stockPaint);
             SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
                                         &content.entry()->fContent);
@@ -1951,7 +1954,7 @@
         // the non-transparent parts of the device and the outlines (shape) of
         // all images and devices drawn.
         drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst,
-                                &clipStack, clipRegion,
+                                &fExistingClipStack, fExistingClipRegion,
                                 SkXfermode::kSrcOver_Mode, true);
     } else {
         SkAutoTUnref<SkPDFFormXObject> dstMaskStorage;
@@ -1970,16 +1973,17 @@
             dstMaskStorage.reset(createFormXObjectFromDevice());
             dstMask = dstMaskStorage.get();
         }
-        drawFormXObjectWithMask(addXObjectResource(dst), dstMask, &clipStack,
-                                clipRegion, SkXfermode::kSrcOver_Mode, true);
+        drawFormXObjectWithMask(addXObjectResource(dst), dstMask,
+                                &fExistingClipStack, fExistingClipRegion,
+                                SkXfermode::kSrcOver_Mode, true);
     }
 
     if (xfermode == SkXfermode::kClear_Mode) {
         return;
     } else if (xfermode == SkXfermode::kSrc_Mode ||
             xfermode == SkXfermode::kDstATop_Mode) {
-        ScopedContentEntry content(this, &clipStack, clipRegion, identity,
-                                   stockPaint);
+        ScopedContentEntry content(this, &fExistingClipStack,
+                                   fExistingClipRegion, identity, stockPaint);
         if (content.entry()) {
             SkPDFUtils::DrawFormXObject(
                     this->addXObjectResource(srcFormXObject.get()),
@@ -1989,8 +1993,8 @@
             return;
         }
     } else if (xfermode == SkXfermode::kSrcATop_Mode) {
-        ScopedContentEntry content(this, &clipStack, clipRegion, identity,
-                                   stockPaint);
+        ScopedContentEntry content(this, &fExistingClipStack,
+                                   fExistingClipRegion, identity, stockPaint);
         if (content.entry()) {
             SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
                                         &content.entry()->fContent);
@@ -2005,30 +2009,24 @@
              xfermode == SkXfermode::kDstATop_Mode ||
              xfermode == SkXfermode::kModulate_Mode);
 
-    ScopedContentEntry inShapeContentEntry(this, &fExistingClipStack,
-                                           fExistingClipRegion, identity,
-                                           stockPaint);
-    if (!inShapeContentEntry.entry()) {
-        return;
-    }
-
     if (xfermode == SkXfermode::kSrcIn_Mode ||
             xfermode == SkXfermode::kSrcOut_Mode ||
             xfermode == SkXfermode::kSrcATop_Mode) {
         drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst,
-                                &clipStack, clipRegion,
+                                &fExistingClipStack, fExistingClipRegion,
                                 SkXfermode::kSrcOver_Mode,
                                 xfermode == SkXfermode::kSrcOut_Mode);
     } else {
         SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
         if (xfermode == SkXfermode::kModulate_Mode) {
             drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()),
-                                    dst, &clipStack, clipRegion,
+                                    dst, &fExistingClipStack,
+                                    fExistingClipRegion,
                                     SkXfermode::kSrcOver_Mode, false);
             mode = SkXfermode::kMultiply_Mode;
         }
         drawFormXObjectWithMask(addXObjectResource(dst), srcFormXObject.get(),
-                                &clipStack, clipRegion, mode,
+                                &fExistingClipStack, fExistingClipRegion, mode,
                                 xfermode == SkXfermode::kDstOut_Mode);
     }
 }