Revert of Revert of Fix SkTextBlob offset semantics. (patchset #1 id:1 of https://codereview.chromium.org/609223003/)

Reason for revert:
Re-landing: Chromium-side fix to be landed with the roll (https://codereview.chromium.org/607853003/)

Original issue's description:
> Revert of Fix SkTextBlob offset semantics. (patchset #2 id:20001 of https://codereview.chromium.org/605533002/)
>
> 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
>
> TBR=jvanverth@google.com,reed@google.com,bsalomon@google.com,fmalita@chromium.org
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/d46b8d2bab7cfba8458432248e1568ac377429e9

R=jvanverth@google.com, reed@google.com, bsalomon@google.com, robertphillips@google.com
TBR=bsalomon@google.com, jvanverth@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true

Author: fmalita@chromium.org

Review URL: https://codereview.chromium.org/607413003
This commit is contained in:
fmalita 2014-09-29 06:29:53 -07:00 committed by Commit bot
parent ee6631ef90
commit 05c4a4322e
27 changed files with 111 additions and 134 deletions

View File

@ -120,10 +120,10 @@ protected:
} }
virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len, virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) { const SkPoint& offset, const SkPaint& paint) {
before(); before();
INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint); INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
after(); after();
} }

View File

@ -96,8 +96,8 @@ protected:
virtual void drawText(const SkDraw&, const void* text, size_t len, virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE; SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE;
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE; const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE;
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) SK_OVERRIDE; const SkPaint& paint) SK_OVERRIDE;

View File

@ -218,8 +218,8 @@ protected:
virtual void drawText(const SkDraw&, const void* text, size_t len, virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) = 0; SkScalar x, SkScalar y, const SkPaint& paint) = 0;
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) = 0; const SkPoint& offset, const SkPaint& paint) = 0;
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) = 0; const SkPaint& paint) = 0;

View File

@ -60,8 +60,8 @@ public:
void drawText(const char text[], size_t byteLength, SkScalar x, void drawText(const char text[], size_t byteLength, SkScalar x,
SkScalar y, const SkPaint& paint) const; SkScalar y, const SkPaint& paint) const;
void drawPosText(const char text[], size_t byteLength, void drawPosText(const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition, const SkPaint& paint) const; const SkPoint& offset, const SkPaint& paint) const;
void drawTextOnPath(const char text[], size_t byteLength, void drawTextOnPath(const char text[], size_t byteLength,
const SkPath&, const SkMatrix*, const SkPaint&) const; const SkPath&, const SkMatrix*, const SkPaint&) const;
void drawVertices(SkCanvas::VertexMode mode, int count, void drawVertices(SkCanvas::VertexMode mode, int count,
@ -113,8 +113,8 @@ public:
void drawText_asPaths(const char text[], size_t byteLength, void drawText_asPaths(const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkPaint&) const; SkScalar x, SkScalar y, const SkPaint&) const;
void drawPosText_asPaths(const char text[], size_t byteLength, void drawPosText_asPaths(const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition, const SkPaint&) const; const SkPoint& offset, const SkPaint&) const;
private: private:
void drawDevMask(const SkMask& mask, const SkPaint&) const; void drawDevMask(const SkMask& mask, const SkPaint&) const;

View File

@ -118,8 +118,8 @@ protected:
virtual void drawPosText( virtual void drawPosText(
const SkDraw&, const SkDraw&,
const void* text, size_t len, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, int scalarsPerPos, const SkScalar pos[], int scalarsPerPos,
const SkPaint& paint) SK_OVERRIDE; const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE;
virtual void drawTextOnPath( virtual void drawTextOnPath(
const SkDraw&, const SkDraw&,

View File

@ -98,8 +98,8 @@ public:
virtual void drawText(const SkDraw&, const void* text, size_t len, virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint&) SK_OVERRIDE; const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) SK_OVERRIDE; const SkPaint& paint) SK_OVERRIDE;

View 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, void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
const SkScalar xpos[], SkScalar y, const SkScalar xpos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) { const SkPoint& offset, const SkPaint& paint) {
draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); draw.drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint);
} }
void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text,

View File

@ -2152,11 +2152,13 @@ void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca
void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
const SkPaint& paint) { const SkPaint& paint) {
SkPoint textOffset = SkPoint::Make(0, 0);
LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
while (iter.next()) { while (iter.next()) {
SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 2, textOffset,
dfp.paint()); dfp.paint());
} }
@ -2165,11 +2167,14 @@ void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint
void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
SkScalar constY, const SkPaint& paint) { SkScalar constY, const SkPaint& paint) {
SkPoint textOffset = SkPoint::Make(0, constY);
LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
while (iter.next()) { while (iter.next()) {
SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, iter.fDevice->drawPosText(iter, text, byteLength, xpos, 1, textOffset,
dfp.paint()); dfp.paint());
} }

View File

@ -96,27 +96,6 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
const SkPaint &paint) { const SkPaint &paint) {
SkPaint runPaint = 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); SkTextBlob::RunIterator it(blob);
while (!it.done()) { while (!it.done()) {
@ -128,12 +107,15 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: case SkTextBlob::kDefault_Positioning:
this->drawText(localDraw, it.glyphs(), textLen, offset.x(), offset.y(), runPaint); this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
break; break;
case SkTextBlob::kHorizontal_Positioning: 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: case SkTextBlob::kFull_Positioning:
this->drawPosText(localDraw, it.glyphs(), textLen, it.pos(), offset.y(), this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2,
SkTextBlob::ScalarsPerGlyph(it.positioning()), runPaint); SkPoint::Make(x, y), runPaint);
break; break;
default: default:
SkFAIL("unhandled positioning mode"); SkFAIL("unhandled positioning mode");

View File

@ -1655,9 +1655,8 @@ void SkDraw::drawText(const char text[], size_t byteLength,
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition, const SkPoint& offset, const SkPaint& origPaint) const {
const SkPaint& origPaint) const {
// setup our std paint, in hopes of getting hits in the cache // setup our std paint, in hopes of getting hits in the cache
SkPaint paint(origPaint); SkPaint paint(origPaint);
SkScalar matrixScale = paint.setupForAsPaths(); SkScalar matrixScale = paint.setupForAsPaths();
@ -1675,7 +1674,7 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
const char* stop = text + byteLength; const char* stop = text + byteLength;
SkTextAlignProcScalar alignProc(paint.getTextAlign()); SkTextAlignProcScalar alignProc(paint.getTextAlign());
SkTextMapStateProc tmsProc(SkMatrix::I(), constY, scalarsPerPosition); SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
// Now restore the original settings, so we "draw" with whatever style/stroking. // Now restore the original settings, so we "draw" with whatever style/stroking.
paint.setStyle(origPaint.getStyle()); paint.setStyle(origPaint.getStyle());
@ -1705,8 +1704,8 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
} }
void SkDraw::drawPosText(const char text[], size_t byteLength, void SkDraw::drawPosText(const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition, const SkPaint& paint) const { const SkPoint& offset, const SkPaint& paint) const {
SkASSERT(byteLength == 0 || text != NULL); SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@ -1718,8 +1717,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
} }
if (ShouldDrawTextAsPaths(paint, *fMatrix)) { if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
this->drawPosText_asPaths(text, byteLength, pos, constY, this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, offset, paint);
scalarsPerPosition, paint);
return; return;
} }
@ -1743,7 +1741,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
SkTextAlignProc alignProc(paint.getTextAlign()); SkTextAlignProc alignProc(paint.getTextAlign());
SkDraw1Glyph d1g; SkDraw1Glyph d1g;
SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint);
SkTextMapStateProc tmsProc(*fMatrix, constY, scalarsPerPosition); SkTextMapStateProc tmsProc(*fMatrix, offset, scalarsPerPosition);
if (cache->isSubpixel()) { if (cache->isSubpixel()) {
// maybe we should skip the rounding if linearText is set // maybe we should skip the rounding if linearText is set

View File

@ -13,20 +13,22 @@
class SkTextMapStateProc { class SkTextMapStateProc {
public: public:
SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPosition) SkTextMapStateProc(const SkMatrix& matrix, const SkPoint& offset, int scalarsPerPosition)
: fMatrix(matrix) : fMatrix(matrix)
, fProc(matrix.getMapXYProc()) , fProc(matrix.getMapXYProc())
, fY(y) , fOffset(offset)
, fScaleX(fMatrix.getScaleX()) , fScaleX(fMatrix.getScaleX()) {
, fTransX(fMatrix.getTranslateX()) {
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
if (1 == scalarsPerPosition) { if (1 == scalarsPerPosition) {
unsigned mtype = fMatrix.getType(); unsigned mtype = fMatrix.getType();
if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
fMapCase = kX; fMapCase = kX;
} else { } else {
fY = SkScalarMul(y, fMatrix.getScaleY()) + // Bake the matrix scale/translation components into fOffset,
fMatrix.getTranslateY(); // to expedite proc computations.
fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatrix.getTranslateX(),
SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatrix.getTranslateY());
if (mtype & SkMatrix::kScale_Mask) { if (mtype & SkMatrix::kScale_Mask) {
fMapCase = kOnlyScaleX; fMapCase = kOnlyScaleX;
} else { } else {
@ -49,25 +51,25 @@ private:
kX kX
} fMapCase; } fMapCase;
const SkMatrix::MapXYProc fProc; const SkMatrix::MapXYProc fProc;
SkScalar fY; // Ignored by kXY case. SkPoint fOffset; // In kOnly* mode, this includes the matrix translation component.
SkScalar fScaleX, fTransX; // These are only used by Only... cases. SkScalar fScaleX; // This is only used by kOnly... cases.
}; };
inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const { inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const {
switch(fMapCase) { switch(fMapCase) {
case kXY: case kXY:
fProc(fMatrix, pos[0], pos[1], loc); fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc);
break; break;
case kOnlyScaleX: case kOnlyScaleX:
loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY); loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y());
break; break;
case kOnlyTransX: case kOnlyTransX:
loc->set(*pos + fTransX, fY); loc->set(*pos + fOffset.x(), fOffset.y());
break; break;
default: default:
SkASSERT(false); SkASSERT(false);
case kX: case kX:
fProc(fMatrix, *pos, fY, loc); fProc(fMatrix, *pos + fOffset.x(), fOffset.y(), loc);
break; break;
} }
} }

View File

@ -2165,9 +2165,8 @@ void SkXPSDevice::drawText(const SkDraw& d,
void SkXPSDevice::drawPosText(const SkDraw& d, void SkXPSDevice::drawPosText(const SkDraw& d,
const void* text, size_t byteLen, const void* text, size_t byteLen,
const SkScalar pos[], const SkScalar pos[], int scalarsPerPos,
SkScalar constY, int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) {
const SkPaint& paint) {
if (byteLen < 1) return; if (byteLen < 1) return;
if (text_must_be_pathed(paint, *d.fMatrix)) { if (text_must_be_pathed(paint, *d.fMatrix)) {
@ -2187,9 +2186,7 @@ void SkXPSDevice::drawPosText(const SkDraw& d,
SkXPSDrawProcs procs; SkXPSDrawProcs procs;
text_draw_init(paint, text, byteLen, *typeface->glyphsUsed, myDraw, procs); text_draw_init(paint, text, byteLen, *typeface->glyphsUsed, myDraw, procs);
myDraw.drawPosText(static_cast<const char*>(text), byteLen, myDraw.drawPosText(static_cast<const char*>(text), byteLen, pos, scalarsPerPos, offset, paint);
pos, constY, scalarsPerPos,
paint);
// SkDraw may have clipped out the glyphs, so we need to check // SkDraw may have clipped out the glyphs, so we need to check
if (procs.xpsGlyphs.count() == 0) { if (procs.xpsGlyphs.count() == 0) {

View File

@ -270,8 +270,8 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint, void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) { const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != NULL); SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@ -295,7 +295,7 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
const char* stop = text + byteLength; const char* stop = text + byteLength;
SkTextAlignProc alignProc(fSkPaint.getTextAlign()); SkTextAlignProc alignProc(fSkPaint.getTextAlign());
SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); SkTextMapStateProc tmsProc(ctm, offset, scalarsPerPosition);
SkFixed halfSampleX = 0, halfSampleY = 0; SkFixed halfSampleX = 0, halfSampleY = 0;
if (cache->isSubpixel()) { if (cache->isSubpixel()) {

View File

@ -25,8 +25,8 @@ public:
SkScalar x, SkScalar y) SK_OVERRIDE; SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void drawPosText(const GrPaint&, const SkPaint&, virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) SK_OVERRIDE; const SkPoint& offset) SK_OVERRIDE;
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;

View File

@ -609,8 +609,8 @@ void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s
void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint, void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) { const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != NULL); SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 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); const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) { if (glyph.fWidth) {
SkScalar x = pos[0]; SkScalar x = offset.x() + pos[0];
SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
@ -657,8 +657,8 @@ void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) { if (glyph.fWidth) {
SkScalar x = pos[0]; SkScalar x = offset.x() + pos[0];
SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),

View File

@ -25,8 +25,8 @@ public:
SkScalar x, SkScalar y) SK_OVERRIDE; SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void drawPosText(const GrPaint&, const SkPaint&, virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) SK_OVERRIDE; const SkPoint& offset) SK_OVERRIDE;
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;

View File

@ -54,7 +54,7 @@ void GrStencilAndCoverTextContext::drawText(const GrPaint& paint,
// will turn off the use of device-space glyphs when perspective transforms // will turn off the use of device-space glyphs when perspective transforms
// are in use. // are in use.
this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode); this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode, SkPoint::Make(0, 0));
// Transform our starting point. // Transform our starting point.
if (fNeedsDeviceSpaceGlyphs) { if (fNeedsDeviceSpaceGlyphs) {
@ -123,8 +123,8 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
const char text[], const char text[],
size_t byteLength, size_t byteLength,
const SkScalar pos[], const SkScalar pos[],
SkScalar constY, int scalarsPerPosition,
int scalarsPerPosition) { const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != NULL); SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@ -141,8 +141,7 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
// transform is not part of SkPaint::measureText API, and thus we use the // transform is not part of SkPaint::measureText API, and thus we use the
// same glyphs as what were measured. // same glyphs as what were measured.
const float textTranslateY = (1 == scalarsPerPosition ? constY : 0); this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, offset);
this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, textTranslateY);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@ -171,7 +170,7 @@ void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
} }
} else { } else {
fTransformType = GrPathRendering::kTranslate_PathTransformType; fTransformType = GrPathRendering::kTranslate_PathTransformType;
SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition); SkTextMapStateProc tmsProc(SkMatrix::I(), SkPoint::Make(0, 0), scalarsPerPosition);
SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign());
while (text < stop) { while (text < stop) {
const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
@ -242,7 +241,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
const SkPaint& skPaint, const SkPaint& skPaint,
size_t textByteLength, size_t textByteLength,
RenderMode renderMode, RenderMode renderMode,
SkScalar textTranslateY) { const SkPoint& textTranslate) {
GrTextContext::init(paint, skPaint); GrTextContext::init(paint, skPaint);
fContextInitialMatrix = fContext->getMatrix(); fContextInitialMatrix = fContext->getMatrix();
@ -258,7 +257,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
if (fNeedsDeviceSpaceGlyphs) { if (fNeedsDeviceSpaceGlyphs) {
// SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms. // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms.
SkASSERT(!fContextInitialMatrix.hasPerspective()); SkASSERT(!fContextInitialMatrix.hasPerspective());
SkASSERT(0 == textTranslateY); // TODO: Handle textTranslateY in device-space usecase. SkASSERT(textTranslate.isZero()); // TODO: Handle textTranslate in device-space usecase.
fTextRatio = fTextInverseRatio = 1.0f; fTextRatio = fTextInverseRatio = 1.0f;
@ -340,7 +339,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
} }
SkMatrix textMatrix; SkMatrix textMatrix;
textMatrix.setTranslate(0, textTranslateY); textMatrix.setTranslate(textTranslate.x(), textTranslate.y());
// Glyphs loaded by GPU path rendering have an inverted y-direction. // Glyphs loaded by GPU path rendering have an inverted y-direction.
textMatrix.preScale(fTextRatio, -fTextRatio); textMatrix.preScale(fTextRatio, -fTextRatio);
fPaint.localCoordChange(textMatrix); fPaint.localCoordChange(textMatrix);

View File

@ -32,8 +32,8 @@ public:
SkScalar x, SkScalar y) SK_OVERRIDE; SkScalar x, SkScalar y) SK_OVERRIDE;
virtual void drawPosText(const GrPaint&, const SkPaint&, virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) SK_OVERRIDE; const SkPoint& offset) SK_OVERRIDE;
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
@ -62,7 +62,7 @@ private:
}; };
void init(const GrPaint&, const SkPaint&, size_t textByteLength, void init(const GrPaint&, const SkPaint&, size_t textByteLength,
RenderMode, SkScalar textTranslateY = 0); RenderMode, const SkPoint& textTranslate);
void initGlyphs(SkGlyphCache* cache); void initGlyphs(SkGlyphCache* cache);
void appendGlyph(uint16_t glyphID, float x); void appendGlyph(uint16_t glyphID, float x);
void appendGlyph(uint16_t glyphID, float x, float y); void appendGlyph(uint16_t glyphID, float x, float y);

View File

@ -28,8 +28,8 @@ public:
SkScalar x, SkScalar y) = 0; SkScalar x, SkScalar y) = 0;
virtual void drawPosText(const GrPaint&, const SkPaint&, virtual void drawPosText(const GrPaint&, const SkPaint&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPosition,
int scalarsPerPosition) = 0; const SkPoint& offset) = 0;
virtual bool canDraw(const SkPaint& paint) = 0; virtual bool canDraw(const SkPaint& paint) = 0;

View File

@ -1713,10 +1713,9 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
} }
} }
void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength,
size_t byteLength, const SkScalar pos[], const SkScalar pos[], int scalarsPerPos,
SkScalar constY, int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) {
const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
CHECK_SHOULD_DRAW(draw, false); CHECK_SHOULD_DRAW(draw, false);
@ -1727,7 +1726,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos, fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
constY, scalarsPerPos); scalarsPerPos, offset);
} else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint; GrPaint grPaint;
SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
@ -1735,10 +1734,9 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos, fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
constY, scalarsPerPos); scalarsPerPos, offset);
} else { } else {
draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerPos, offset, paint);
scalarsPerPos, paint);
} }
} }

View File

@ -90,8 +90,8 @@ public:
virtual void drawText(const SkDraw&, const void* text, size_t len, virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint&) SK_OVERRIDE; const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint&) SK_OVERRIDE; const SkPaint&) SK_OVERRIDE;

View 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, void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) { const SkPoint& offset, const SkPaint& paint) {
NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false);
if (paint.getMaskFilter() != NULL) { if (paint.getMaskFilter() != NULL) {
// Don't pretend we support drawing MaskFilters, it makes for artifacts // Don't pretend we support drawing MaskFilters, it makes for artifacts
@ -1177,8 +1177,9 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
continue; continue;
} }
fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1); fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
SkScalar x = pos[i * scalarsPerPos]; SkScalar x = offset.x() + pos[i * scalarsPerPos];
SkScalar y = scalarsPerPos == 1 ? constY : pos[i * scalarsPerPos + 1]; SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0);
align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y); align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y);
set_text_transform(x, y, textPaint.getTextSkewX(), set_text_transform(x, y, textPaint.getTextSkewX(),
&content.entry()->fContent); &content.entry()->fContent);

View 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, void SkPDFDeviceFlattener::drawPosText(const SkDraw& d, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) { const SkPoint& offset, const SkPaint& paint) {
if (mustPathText(d, paint)) { if (mustPathText(d, paint)) {
d.drawPosText_asPaths((const char*)text, len, pos, constY, scalarsPerPos, paint); d.drawPosText_asPaths((const char*)text, len, pos, scalarsPerPos, offset, paint);
return; return;
} }
INHERITED::drawPosText(d, text, len, pos, constY,scalarsPerPos, paint); INHERITED::drawPosText(d, text, len, pos, scalarsPerPos, offset, paint);
} }
void SkPDFDeviceFlattener::drawTextOnPath(const SkDraw& d, const void* text, size_t len, void SkPDFDeviceFlattener::drawTextOnPath(const SkDraw& d, const void* text, size_t len,

View File

@ -37,8 +37,8 @@ public:
virtual void drawText(const SkDraw&, const void* text, size_t len, virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint&) SK_OVERRIDE; const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix, const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) SK_OVERRIDE; const SkPaint& paint) SK_OVERRIDE;

View File

@ -210,8 +210,8 @@ protected:
SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE
{SkASSERT(0);} {SkASSERT(0);}
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE
{SkASSERT(0);} {SkASSERT(0);}
virtual void drawTextOnPath(const SkDraw&, const void* text, virtual void drawTextOnPath(const SkDraw&, const void* text,
size_t len, const SkPath& path, size_t len, const SkPath& path,

View File

@ -195,8 +195,8 @@ protected:
this->drawRect(draw, bounds, paint); this->drawRect(draw, bounds, paint);
} }
virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, virtual void drawPosText(const SkDraw& draw, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int scalarsPerPos,
int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE { const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE {
SkBitmap bitmap; SkBitmap bitmap;
if (!GetBitmapFromPaint(paint, &bitmap)) { if (!GetBitmapFromPaint(paint, &bitmap)) {
return; return;
@ -209,18 +209,13 @@ protected:
// Similar to SkDraw asserts. // Similar to SkDraw asserts.
SkASSERT(scalarsPerPos == 1 || scalarsPerPos == 2); SkASSERT(scalarsPerPos == 1 || scalarsPerPos == 2);
SkScalar y = scalarsPerPos == 1 ? constY : constY + pos[1]; SkPoint min = SkPoint::Make(offset.x() + pos[0],
offset.y() + (2 == scalarsPerPos ? pos[1] : 0));
SkPoint min, max; SkPoint max = min;
min.set(pos[0], y);
max.set(pos[0], y);
for (size_t i = 1; i < len; ++i) { for (size_t i = 1; i < len; ++i) {
SkScalar x = pos[i * scalarsPerPos]; SkScalar x = offset.x() + pos[i * scalarsPerPos];
SkScalar y = constY; SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * 2 + 1] : 0);
if (2 == scalarsPerPos) {
y += pos[i * scalarsPerPos + 1];
}
min.set(SkMinScalar(x, min.x()), SkMinScalar(y, min.y())); min.set(SkMinScalar(x, min.x()), SkMinScalar(y, min.y()));
max.set(SkMaxScalar(x, max.x()), SkMaxScalar(y, max.y())); max.set(SkMaxScalar(x, max.x()), SkMaxScalar(y, max.y()));

View File

@ -132,8 +132,8 @@ public:
this->addBitmapFromPaint(paint); this->addBitmapFromPaint(paint);
} }
virtual void drawPosText(const SkDraw&, const void* text, size_t len, virtual void drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY, const SkScalar pos[], int,
int, const SkPaint& paint) SK_OVERRIDE { const SkPoint&, const SkPaint& paint) SK_OVERRIDE {
this->addBitmapFromPaint(paint); this->addBitmapFromPaint(paint);
} }
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,