Revert of Fix SkTextBlob offset semantics. (patchset #2 id:20001 of https://coderevie...
authorrobertphillips <robertphillips@google.com>
Mon, 29 Sep 2014 11:48:52 +0000 (04:48 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 29 Sep 2014 11:48:52 +0000 (04:48 -0700)
Reason for revert:
Breaking the Chrome builds with the error:

[14:54:14.317833] ../../skia/ext/pixel_ref_utils.cc:221:16: error: 'drawPosText' marked 'override' but does not override any member functions
[14:54:14.318022]   virtual void drawPosText(const SkDraw& draw,
[14:54:14.318082]                ^

Original issue's description:
> Fix SkTextBlob offset semantics.
>
> Implement proper x/y drawTextBlob() handling by plumbing a
> drawPosText() offset parameter (to act as an additional glyph pos
> translation) throughout the device layer.
>
> The new offset superceeds the existing constY, with a minor semantic
> tweak: whereas previous implementations were ignoring constY in 2D
> positioning mode (scalarsPerGlyph == 2), now the offset is always
> observed, in all positioning modes. We can do this because existing
> drawPosText() clients always pass constY == 0 for full positioning mode.
>
> R=reed@google.com, jvanverth@google.com, robertphillips@google.com
>
> Committed: https://skia.googlesource.com/skia/+/c13bc571d3e61a43b87eb97f0719abd304cafaf2

R=jvanverth@google.com, reed@google.com, bsalomon@google.com, fmalita@chromium.org
TBR=bsalomon@google.com, fmalita@chromium.org, jvanverth@google.com, reed@google.com
NOTREECHECKS=true
NOTRY=true

Author: robertphillips@google.com

Review URL: https://codereview.chromium.org/609223003

27 files changed:
experimental/PdfViewer/SkTrackDevice.h
include/core/SkBitmapDevice.h
include/core/SkDevice.h
include/core/SkDraw.h
include/device/xps/SkXPSDevice.h
include/pdf/SkPDFDevice.h
src/core/SkBitmapDevice.cpp
src/core/SkCanvas.cpp
src/core/SkDevice.cpp
src/core/SkDraw.cpp
src/core/SkTextMapStateProc.h
src/device/xps/SkXPSDevice.cpp
src/gpu/GrBitmapTextContext.cpp
src/gpu/GrBitmapTextContext.h
src/gpu/GrDistanceFieldTextContext.cpp
src/gpu/GrDistanceFieldTextContext.h
src/gpu/GrStencilAndCoverTextContext.cpp
src/gpu/GrStencilAndCoverTextContext.h
src/gpu/GrTextContext.h
src/gpu/SkGpuDevice.cpp
src/gpu/SkGpuDevice.h
src/pdf/SkPDFDevice.cpp
src/pdf/SkPDFDeviceFlattener.cpp
src/pdf/SkPDFDeviceFlattener.h
src/utils/SkDeferredCanvas.cpp
src/utils/SkGatherPixelRefsAndRects.h
src/utils/SkPictureUtils.cpp

index 8d6a923..ca4c689 100644 (file)
@@ -120,10 +120,10 @@ protected:
     }
 
     virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint& paint) {
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint& paint) {
         before();
-        INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
+        INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
         after();
     }
 
index 8b87fc8..0ab0234 100644 (file)
@@ -96,8 +96,8 @@ protected:
     virtual void drawText(const SkDraw&, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE;
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE;
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
                                 const SkPath& path, const SkMatrix* matrix,
                                 const SkPaint& paint) SK_OVERRIDE;
index fb3c206..08320bf 100644 (file)
@@ -218,8 +218,8 @@ protected:
     virtual void drawText(const SkDraw&, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint& paint) = 0;
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint& paint) = 0;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint& paint) = 0;
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
                                 const SkPath& path, const SkMatrix* matrix,
                                 const SkPaint& paint) = 0;
index 4b8d02b..21d4210 100644 (file)
@@ -60,8 +60,8 @@ public:
     void    drawText(const char text[], size_t byteLength, SkScalar x,
                      SkScalar y, const SkPaint& paint) const;
     void    drawPosText(const char text[], size_t byteLength,
-                        const SkScalar pos[], int scalarsPerPosition,
-                        const SkPoint& offset, const SkPaint& paint) const;
+                        const SkScalar pos[], SkScalar constY,
+                        int scalarsPerPosition, const SkPaint& paint) const;
     void    drawTextOnPath(const char text[], size_t byteLength,
                         const SkPath&, const SkMatrix*, const SkPaint&) const;
     void    drawVertices(SkCanvas::VertexMode mode, int count,
@@ -113,8 +113,8 @@ public:
     void        drawText_asPaths(const char text[], size_t byteLength,
                                  SkScalar x, SkScalar y, const SkPaint&) const;
     void        drawPosText_asPaths(const char text[], size_t byteLength,
-                                    const SkScalar pos[], int scalarsPerPosition,
-                                    const SkPoint& offset, const SkPaint&) const;
+                                    const SkScalar pos[], SkScalar constY,
+                                    int scalarsPerPosition, const SkPaint&) const;
 
 private:
     void    drawDevMask(const SkMask& mask, const SkPaint&) const;
index a9f513d..2aa7ba8 100644 (file)
@@ -118,8 +118,8 @@ protected:
     virtual void drawPosText(
         const SkDraw&,
         const void* text, size_t len,
-        const SkScalar pos[], int scalarsPerPos,
-        const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE;
+        const SkScalar pos[], SkScalar constY, int scalarsPerPos,
+        const SkPaint& paint) SK_OVERRIDE;
 
     virtual void drawTextOnPath(
         const SkDraw&,
index 0ada531..0bfbc36 100644 (file)
@@ -98,8 +98,8 @@ public:
     virtual void drawText(const SkDraw&, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint&) SK_OVERRIDE;
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
                                 const SkPath& path, const SkMatrix* matrix,
                                 const SkPaint& paint) SK_OVERRIDE;
index cc4155a..b48432e 100644 (file)
@@ -329,9 +329,9 @@ void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len,
 }
 
 void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
-                                 const SkScalar xpos[], int scalarsPerPos,
-                                 const SkPoint& offset, const SkPaint& paint) {
-    draw.drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint);
+                                 const SkScalar xpos[], SkScalar y,
+                                 int scalarsPerPos, const SkPaint& paint) {
+    draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint);
 }
 
 void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text,
index 065aecd..d43d5a4 100644 (file)
@@ -2152,13 +2152,11 @@ void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca
 
 void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
                              const SkPaint& paint) {
-    SkPoint textOffset = SkPoint::Make(0, 0);
-
     LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
 
     while (iter.next()) {
         SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
-        iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 2, textOffset,
+        iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2,
                                   dfp.paint());
     }
 
@@ -2167,14 +2165,11 @@ void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint
 
 void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
                               SkScalar constY, const SkPaint& paint) {
-
-    SkPoint textOffset = SkPoint::Make(0, constY);
-
     LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
 
     while (iter.next()) {
         SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
-        iter.fDevice->drawPosText(iter, text, byteLength, xpos, 1, textOffset,
+        iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1,
                                   dfp.paint());
     }
 
index 935d489..63a7633 100644 (file)
@@ -96,6 +96,27 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
                                 const SkPaint &paint) {
 
     SkPaint runPaint = paint;
+    SkMatrix localMatrix;
+    SkDraw localDraw(draw);
+
+    if (x || y) {
+        localMatrix = *draw.fMatrix;
+        localMatrix.preTranslate(x, y);
+        localDraw.fMatrix = &localMatrix;
+
+        if (paint.getShader()) {
+            // FIXME: We need to compensate for the translate above. This is suboptimal but
+            // temporary -- until we get proper derived class drawTextBlob implementations.
+
+            // TODO: pass x,y down to the other methods so they can handle the additional
+            // translate without needing to allocate a new shader.
+            SkMatrix shaderMatrix;
+            shaderMatrix.setTranslate(-x, -y);
+            SkAutoTUnref<SkShader> wrapper(
+                SkShader::CreateLocalMatrixShader(paint.getShader(), shaderMatrix));
+            runPaint.setShader(wrapper);
+        }
+    }
 
     SkTextBlob::RunIterator it(blob);
     while (!it.done()) {
@@ -107,15 +128,12 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
 
         switch (it.positioning()) {
         case SkTextBlob::kDefault_Positioning:
-            this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
+            this->drawText(localDraw, it.glyphs(), textLen, offset.x(), offset.y(), runPaint);
             break;
         case SkTextBlob::kHorizontal_Positioning:
-            this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 1,
-                              SkPoint::Make(x, y + offset.y()), runPaint);
-            break;
         case SkTextBlob::kFull_Positioning:
-            this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2,
-                              SkPoint::Make(x, y), runPaint);
+            this->drawPosText(localDraw, it.glyphs(), textLen, it.pos(), offset.y(),
+                              SkTextBlob::ScalarsPerGlyph(it.positioning()), runPaint);
             break;
         default:
             SkFAIL("unhandled positioning mode");
index 929088d..e905f4b 100644 (file)
@@ -1655,8 +1655,9 @@ void SkDraw::drawText(const char text[], size_t byteLength,
 //////////////////////////////////////////////////////////////////////////////
 
 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
-                                 const SkScalar pos[], int scalarsPerPosition,
-                                 const SkPoint& offset, const SkPaint& origPaint) const {
+                                 const SkScalar pos[], SkScalar constY,
+                                 int scalarsPerPosition,
+                                 const SkPaint& origPaint) const {
     // setup our std paint, in hopes of getting hits in the cache
     SkPaint paint(origPaint);
     SkScalar matrixScale = paint.setupForAsPaths();
@@ -1674,7 +1675,7 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
 
     const char*        stop = text + byteLength;
     SkTextAlignProcScalar alignProc(paint.getTextAlign());
-    SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
+    SkTextMapStateProc tmsProc(SkMatrix::I(), constY, scalarsPerPosition);
 
     // Now restore the original settings, so we "draw" with whatever style/stroking.
     paint.setStyle(origPaint.getStyle());
@@ -1704,8 +1705,8 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
 }
 
 void SkDraw::drawPosText(const char text[], size_t byteLength,
-                         const SkScalar pos[], int scalarsPerPosition,
-                         const SkPoint& offset, const SkPaint& paint) const {
+                         const SkScalar pos[], SkScalar constY,
+                         int scalarsPerPosition, const SkPaint& paint) const {
     SkASSERT(byteLength == 0 || text != NULL);
     SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
 
@@ -1717,7 +1718,8 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
     }
 
     if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
-        this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, offset, paint);
+        this->drawPosText_asPaths(text, byteLength, pos, constY,
+                                  scalarsPerPosition, paint);
         return;
     }
 
@@ -1741,7 +1743,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
     SkTextAlignProc    alignProc(paint.getTextAlign());
     SkDraw1Glyph       d1g;
     SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint);
-    SkTextMapStateProc tmsProc(*fMatrix, offset, scalarsPerPosition);
+    SkTextMapStateProc tmsProc(*fMatrix, constY, scalarsPerPosition);
 
     if (cache->isSubpixel()) {
         // maybe we should skip the rounding if linearText is set
index 8ef9389..5a8dcaa 100644 (file)
 
 class SkTextMapStateProc {
 public:
-    SkTextMapStateProc(const SkMatrix& matrix, const SkPoint& offset, int scalarsPerPosition)
+    SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPosition)
         : fMatrix(matrix)
         , fProc(matrix.getMapXYProc())
-        , fOffset(offset)
-        , fScaleX(fMatrix.getScaleX()) {
+        , fY(y)
+        , fScaleX(fMatrix.getScaleX())
+        , fTransX(fMatrix.getTranslateX()) {
         SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
         if (1 == scalarsPerPosition) {
             unsigned mtype = fMatrix.getType();
             if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
                 fMapCase = kX;
             } else {
-                // Bake the matrix scale/translation components into fOffset,
-                // to expedite proc computations.
-                fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatrix.getTranslateX(),
-                            SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatrix.getTranslateY());
-
+                fY = SkScalarMul(y, fMatrix.getScaleY()) +
+                    fMatrix.getTranslateY();
                 if (mtype & SkMatrix::kScale_Mask) {
                     fMapCase = kOnlyScaleX;
                 } else {
@@ -51,25 +49,25 @@ private:
         kX
     } fMapCase;
     const SkMatrix::MapXYProc fProc;
-    SkPoint  fOffset; // In kOnly* mode, this includes the matrix translation component.
-    SkScalar fScaleX; // This is only used by kOnly... cases.
+    SkScalar fY; // Ignored by kXY case.
+    SkScalar fScaleX, fTransX; // These are only used by Only... cases.
 };
 
 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const {
     switch(fMapCase) {
     case kXY:
-        fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc);
+        fProc(fMatrix, pos[0], pos[1], loc);
         break;
     case kOnlyScaleX:
-        loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y());
+        loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY);
         break;
     case kOnlyTransX:
-        loc->set(*pos + fOffset.x(), fOffset.y());
+        loc->set(*pos + fTransX, fY);
         break;
     default:
         SkASSERT(false);
     case kX:
-        fProc(fMatrix, *pos + fOffset.x(), fOffset.y(), loc);
+        fProc(fMatrix, *pos, fY, loc);
         break;
     }
 }
index 5bf07e9..1a12153 100644 (file)
@@ -2165,8 +2165,9 @@ void SkXPSDevice::drawText(const SkDraw& d,
 
 void SkXPSDevice::drawPosText(const SkDraw& d,
                               const void* text, size_t byteLen,
-                              const SkScalar pos[], int scalarsPerPos,
-                              const SkPoint& offset, const SkPaint& paint) {
+                              const SkScalar pos[],
+                              SkScalar constY, int scalarsPerPos,
+                              const SkPaint& paint) {
     if (byteLen < 1) return;
 
     if (text_must_be_pathed(paint, *d.fMatrix)) {
@@ -2186,7 +2187,9 @@ void SkXPSDevice::drawPosText(const SkDraw& d,
     SkXPSDrawProcs procs;
     text_draw_init(paint, text, byteLen, *typeface->glyphsUsed, myDraw, procs);
 
-    myDraw.drawPosText(static_cast<const char*>(text), byteLen, pos, scalarsPerPos, offset, paint);
+    myDraw.drawPosText(static_cast<const char*>(text), byteLen,
+                       pos, constY, scalarsPerPos,
+                       paint);
 
     // SkDraw may have clipped out the glyphs, so we need to check
     if (procs.xpsGlyphs.count() == 0) {
index 0f6d1b6..82784bf 100755 (executable)
@@ -270,8 +270,8 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
 
 void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
                                       const char text[], size_t byteLength,
-                                      const SkScalar pos[], int scalarsPerPosition,
-                                      const SkPoint& offset) {
+                                      const SkScalar pos[], SkScalar constY,
+                                      int scalarsPerPosition) {
     SkASSERT(byteLength == 0 || text != NULL);
     SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
 
@@ -295,7 +295,7 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
 
     const char*        stop = text + byteLength;
     SkTextAlignProc    alignProc(fSkPaint.getTextAlign());
-    SkTextMapStateProc tmsProc(ctm, offset, scalarsPerPosition);
+    SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition);
     SkFixed halfSampleX = 0, halfSampleY = 0;
 
     if (cache->isSubpixel()) {
index c136270..80abf68 100644 (file)
@@ -25,8 +25,8 @@ public:
                           SkScalar x, SkScalar y) SK_OVERRIDE;
     virtual void drawPosText(const GrPaint&, const SkPaint&,
                              const char text[], size_t byteLength,
-                             const SkScalar pos[], int scalarsPerPosition,
-                             const SkPoint& offset) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPosition) SK_OVERRIDE;
 
     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
 
index e2bd6e9..9fd024a 100755 (executable)
@@ -609,8 +609,8 @@ void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s
 
 void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
                                              const char text[], size_t byteLength,
-                                             const SkScalar pos[], int scalarsPerPosition,
-                                             const SkPoint& offset) {
+                                             const SkScalar pos[], SkScalar constY,
+                                             int scalarsPerPosition) {
 
     SkASSERT(byteLength == 0 || text != NULL);
     SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -638,8 +638,8 @@ void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
             const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
 
             if (glyph.fWidth) {
-                SkScalar x = offset.x() + pos[0];
-                SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
+                SkScalar x = pos[0];
+                SkScalar y = scalarsPerPosition == 1 ? constY : pos[1];
 
                 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
                                                     glyph.getSubXFixed(),
@@ -657,8 +657,8 @@ void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
             const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
 
             if (glyph.fWidth) {
-                SkScalar x = offset.x() + pos[0];
-                SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
+                SkScalar x = pos[0];
+                SkScalar y = scalarsPerPosition == 1 ? constY : pos[1];
 
                 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
                                                     glyph.getSubXFixed(),
index 0b08b59..85d9250 100644 (file)
@@ -25,8 +25,8 @@ public:
                           SkScalar x, SkScalar y) SK_OVERRIDE;
     virtual void drawPosText(const GrPaint&, const SkPaint&,
                              const char text[], size_t byteLength,
-                             const SkScalar pos[], int scalarsPerPosition,
-                             const SkPoint& offset) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPosition) SK_OVERRIDE;
 
     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
 
index cfcabe9..c1d9e9d 100644 (file)
@@ -54,7 +54,7 @@ void GrStencilAndCoverTextContext::drawText(const GrPaint& paint,
     // will turn off the use of device-space glyphs when perspective transforms
     // are in use.
 
-    this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode, SkPoint::Make(0, 0));
+    this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode);
 
     // Transform our starting point.
     if (fNeedsDeviceSpaceGlyphs) {
@@ -123,8 +123,8 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
                                                const char text[],
                                                size_t byteLength,
                                                const SkScalar pos[],
-                                               int scalarsPerPosition,
-                                               const SkPoint& offset) {
+                                               SkScalar constY,
+                                               int scalarsPerPosition) {
     SkASSERT(byteLength == 0 || text != NULL);
     SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
 
@@ -141,7 +141,8 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
     // transform is not part of SkPaint::measureText API, and thus we use the
     // same glyphs as what were measured.
 
-    this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, offset);
+    const float textTranslateY = (1 == scalarsPerPosition ? constY : 0);
+    this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, textTranslateY);
 
     SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
 
@@ -170,7 +171,7 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
         }
     } else {
         fTransformType = GrPathRendering::kTranslate_PathTransformType;
-        SkTextMapStateProc tmsProc(SkMatrix::I(), SkPoint::Make(0, 0), scalarsPerPosition);
+        SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition);
         SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign());
         while (text < stop) {
             const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
@@ -241,7 +242,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
                                         const SkPaint& skPaint,
                                         size_t textByteLength,
                                         RenderMode renderMode,
-                                        const SkPoint& textTranslate) {
+                                        SkScalar textTranslateY) {
     GrTextContext::init(paint, skPaint);
 
     fContextInitialMatrix = fContext->getMatrix();
@@ -257,7 +258,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
     if (fNeedsDeviceSpaceGlyphs) {
         // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms.
         SkASSERT(!fContextInitialMatrix.hasPerspective());
-        SkASSERT(textTranslate.isZero()); // TODO: Handle textTranslate in device-space usecase.
+        SkASSERT(0 == textTranslateY); // TODO: Handle textTranslateY in device-space usecase.
 
         fTextRatio = fTextInverseRatio = 1.0f;
 
@@ -339,7 +340,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
         }
 
         SkMatrix textMatrix;
-        textMatrix.setTranslate(textTranslate.x(), textTranslate.y());
+        textMatrix.setTranslate(0, textTranslateY);
         // Glyphs loaded by GPU path rendering have an inverted y-direction.
         textMatrix.preScale(fTextRatio, -fTextRatio);
         fPaint.localCoordChange(textMatrix);
index b6e23bd..5ba4a70 100644 (file)
@@ -32,8 +32,8 @@ public:
                           SkScalar x, SkScalar y) SK_OVERRIDE;
     virtual void drawPosText(const GrPaint&, const SkPaint&,
                              const char text[], size_t byteLength,
-                             const SkScalar pos[], int scalarsPerPosition,
-                             const SkPoint& offset) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPosition) SK_OVERRIDE;
 
     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
 
@@ -62,7 +62,7 @@ private:
     };
 
     void init(const GrPaint&, const SkPaint&, size_t textByteLength,
-              RenderMode, const SkPoint& textTranslate);
+              RenderMode, SkScalar textTranslateY = 0);
     void initGlyphs(SkGlyphCache* cache);
     void appendGlyph(uint16_t glyphID, float x);
     void appendGlyph(uint16_t glyphID, float x, float y);
index da41c1b..c139e22 100644 (file)
@@ -28,8 +28,8 @@ public:
                           SkScalar x, SkScalar y) = 0;
     virtual void drawPosText(const GrPaint&, const SkPaint&,
                              const char text[], size_t byteLength,
-                             const SkScalar pos[], int scalarsPerPosition,
-                             const SkPoint& offset) = 0;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPosition) = 0;
 
     virtual bool canDraw(const SkPaint& paint) = 0;
 
index 074eda1..b647613 100644 (file)
@@ -1713,9 +1713,10 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
     }
 }
 
-void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength,
-                              const SkScalar pos[], int scalarsPerPos,
-                              const SkPoint& offset, const SkPaint& paint) {
+void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
+                             size_t byteLength, const SkScalar pos[],
+                             SkScalar constY, int scalarsPerPos,
+                             const SkPaint& paint) {
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
     CHECK_SHOULD_DRAW(draw, false);
 
@@ -1726,7 +1727,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
         SkDEBUGCODE(this->validate();)
 
         fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
-                                      scalarsPerPos, offset);
+                                      constY, scalarsPerPos);
     } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
         GrPaint grPaint;
         SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
@@ -1734,9 +1735,10 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
         SkDEBUGCODE(this->validate();)
 
         fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
-                                          scalarsPerPos, offset);
+                                          constY, scalarsPerPos);
     } else {
-        draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerPos, offset, paint);
+        draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
+                                 scalarsPerPos, paint);
     }
 }
 
index f19d2cb..41b53b1 100644 (file)
@@ -90,8 +90,8 @@ public:
     virtual void drawText(const SkDraw&, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint&) SK_OVERRIDE;
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
                                 const SkPath& path, const SkMatrix* matrix,
                                 const SkPaint&) SK_OVERRIDE;
index bd9b1d7..aa6b521 100644 (file)
@@ -1144,8 +1144,8 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
 }
 
 void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
-                              const SkScalar pos[], int scalarsPerPos,
-                              const SkPoint& offset, const SkPaint& paint) {
+                              const SkScalar pos[], SkScalar constY,
+                              int scalarsPerPos, const SkPaint& paint) {
     NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false);
     if (paint.getMaskFilter() != NULL) {
         // Don't pretend we support drawing MaskFilters, it makes for artifacts
@@ -1177,9 +1177,8 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
             continue;
         }
         fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
-        SkScalar x = offset.x() + pos[i * scalarsPerPos];
-        SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0);
-
+        SkScalar x = pos[i * scalarsPerPos];
+        SkScalar y = scalarsPerPos == 1 ? constY : pos[i * scalarsPerPos + 1];
         align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y);
         set_text_transform(x, y, textPaint.getTextSkewX(),
                            &content.entry()->fContent);
index 4774864..aea87f6 100644 (file)
@@ -123,13 +123,13 @@ void SkPDFDeviceFlattener::drawText(const SkDraw& d, const void* text, size_t le
 }
 
 void SkPDFDeviceFlattener::drawPosText(const SkDraw& d, const void* text, size_t len,
-                                       const SkScalar pos[], int scalarsPerPos,
-                                       const SkPoint& offset, const SkPaint& paint) {
+                                       const SkScalar pos[], SkScalar constY,
+                                       int scalarsPerPos, const SkPaint& paint) {
     if (mustPathText(d, paint)) {
-        d.drawPosText_asPaths((const char*)text, len, pos, scalarsPerPos, offset, paint);
+        d.drawPosText_asPaths((const char*)text, len, pos, constY, scalarsPerPos, paint);
         return;
     }
-    INHERITED::drawPosText(d, text, len, pos, scalarsPerPos, offset, paint);
+    INHERITED::drawPosText(d, text, len, pos, constY,scalarsPerPos, paint);
 }
 
 void SkPDFDeviceFlattener::drawTextOnPath(const SkDraw& d, const void* text, size_t len,
index bb15237..f1047db 100644 (file)
@@ -37,8 +37,8 @@ public:
     virtual void drawText(const SkDraw&, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint&) SK_OVERRIDE;
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
                                 const SkPath& path, const SkMatrix* matrix,
                                 const SkPaint& paint) SK_OVERRIDE;
index 06f7bb0..c8402dd 100644 (file)
@@ -210,8 +210,8 @@ protected:
                             SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE
         {SkASSERT(0);}
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE
+                                const SkScalar pos[], SkScalar constY,
+                                int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE
         {SkASSERT(0);}
     virtual void drawTextOnPath(const SkDraw&, const void* text,
                                 size_t len, const SkPath& path,
index 0a4bb5b..e1e5ccd 100644 (file)
@@ -195,8 +195,8 @@ protected:
         this->drawRect(draw, bounds, paint);
     }
     virtual void drawPosText(const SkDraw& draw, const void* text, size_t len,
-                             const SkScalar pos[], int scalarsPerPos,
-                             const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE {
+                             const SkScalar pos[], SkScalar constY,
+                             int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE {
         SkBitmap bitmap;
         if (!GetBitmapFromPaint(paint, &bitmap)) {
             return;
@@ -209,13 +209,18 @@ protected:
         // Similar to SkDraw asserts.
         SkASSERT(scalarsPerPos == 1 || scalarsPerPos == 2);
 
-        SkPoint min = SkPoint::Make(offset.x() + pos[0],
-                                    offset.y() + (2 == scalarsPerPos ? pos[1] : 0));
-        SkPoint max = min;
+        SkScalar y = scalarsPerPos == 1 ? constY : constY + pos[1];
+
+        SkPoint min, max;
+        min.set(pos[0], y);
+        max.set(pos[0], y);
 
         for (size_t i = 1; i < len; ++i) {
-            SkScalar x = offset.x() + pos[i * scalarsPerPos];
-            SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * 2 + 1] : 0);
+            SkScalar x = pos[i * scalarsPerPos];
+            SkScalar y = constY;
+            if (2 == scalarsPerPos) {
+                y += pos[i * scalarsPerPos + 1];
+            }
 
             min.set(SkMinScalar(x, min.x()), SkMinScalar(y, min.y()));
             max.set(SkMaxScalar(x, max.x()), SkMaxScalar(y, max.y()));
index 391e5ff..4f4d2bf 100644 (file)
@@ -132,8 +132,8 @@ public:
         this->addBitmapFromPaint(paint);
     }
     virtual void drawPosText(const SkDraw&, const void* text, size_t len,
-                             const SkScalar pos[], int,
-                             const SkPoint&, const SkPaint& paint) SK_OVERRIDE {
+                             const SkScalar pos[], SkScalar constY,
+                             int, const SkPaint& paint) SK_OVERRIDE {
         this->addBitmapFromPaint(paint);
     }
     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,