remove device field from SkDraw
BUG=skia:6214
Change-Id: I5d57feb3e92f2c1691231c982e74020560febeca
Reviewed-on: https://skia-review.googlesource.com/8837
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 9ea4937..e6bb933 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -214,7 +214,7 @@
void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint) {
- PREPARE_DRAW(draw).drawPoints(mode, count, pts, paint);
+ PREPARE_DRAW(draw).drawPoints(mode, count, pts, paint, nullptr);
}
void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) {
@@ -375,13 +375,14 @@
void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
- PREPARE_DRAW(draw).drawText((const char*)text, len, x, y, paint);
+ PREPARE_DRAW(draw).drawText((const char*)text, len, x, y, paint, &fSurfaceProps);
}
void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
const SkScalar xpos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& paint) {
- PREPARE_DRAW(draw).drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint);
+ PREPARE_DRAW(draw).drawPosText((const char*)text, len, xpos, scalarsPerPos, offset,
+ paint, &fSurfaceProps);
}
void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 6edf536..d2bfb59 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -327,7 +327,7 @@
class SkDrawIter : public SkDraw {
public:
- SkDrawIter(SkCanvas* canvas) {
+ SkDrawIter(SkCanvas* canvas) : fDevice(nullptr) {
canvas->updateDeviceCMCache();
fClipStack = canvas->getClipStack();
@@ -380,13 +380,14 @@
return false;
}
- SkBaseDevice* getDevice() const { return fDevice; }
const SkRasterClip& getClip() const { return *fRC; }
int getX() const { return fDevice->getOrigin().x(); }
int getY() const { return fDevice->getOrigin().y(); }
const SkMatrix& getMatrix() const { return *fMatrix; }
const SkPaint* getPaint() const { return fPaint; }
+ SkBaseDevice* fDevice;
+
private:
const DeviceCM* fCurrLayer;
const SkPaint* fPaint; // May be null.
@@ -1145,7 +1146,6 @@
draw.fMatrix = &SkMatrix::I();
draw.fRC = &rc;
draw.fClipStack = clipStack;
- draw.fDevice = dst;
SkPaint p;
p.setImageFilter(filter->makeWithLocalMatrix(ctm));
@@ -3318,7 +3318,7 @@
}
SkBaseDevice* SkCanvas::LayerIter::device() const {
- return fImpl->getDevice();
+ return fImpl->fDevice;
}
const SkMatrix& SkCanvas::LayerIter::matrix() const {
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 4182ef3..a60325c 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -513,7 +513,7 @@
void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint,
- bool forceUseDevice) const {
+ SkBaseDevice* device) const {
// if we're in lines mode, force count to be even
if (SkCanvas::kLines_PointMode == mode) {
count &= ~(size_t)1;
@@ -532,7 +532,7 @@
}
PtProcRec rec;
- if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) {
+ if (!device && rec.init(mode, paint, fMatrix, fRC)) {
SkAutoBlitterChoose blitter(fDst, *fMatrix, paint);
SkPoint devPts[MAX_DEV_PTS];
@@ -576,8 +576,8 @@
// pass true for the last point, since we can modify
// then path then
path.setIsVolatile((count-1) == i);
- if (fDevice) {
- fDevice->drawPath(*this, path, newPaint, &preMatrix,
+ if (device) {
+ device->drawPath(*this, path, newPaint, &preMatrix,
(count-1) == i);
} else {
this->drawPath(path, newPaint, &preMatrix,
@@ -592,8 +592,8 @@
r.fTop = pts[i].fY - radius;
r.fRight = r.fLeft + width;
r.fBottom = r.fTop + width;
- if (fDevice) {
- fDevice->drawRect(*this, r, newPaint);
+ if (device) {
+ device->drawRect(*this, r, newPaint);
} else {
this->drawRect(r, newPaint);
}
@@ -623,16 +623,16 @@
newP.setStyle(SkPaint::kFill_Style);
if (!pointData.fFirst.isEmpty()) {
- if (fDevice) {
- fDevice->drawPath(*this, pointData.fFirst, newP);
+ if (device) {
+ device->drawPath(*this, pointData.fFirst, newP);
} else {
this->drawPath(pointData.fFirst, newP);
}
}
if (!pointData.fLast.isEmpty()) {
- if (fDevice) {
- fDevice->drawPath(*this, pointData.fLast, newP);
+ if (device) {
+ device->drawPath(*this, pointData.fLast, newP);
} else {
this->drawPath(pointData.fLast, newP);
}
@@ -648,8 +648,8 @@
newP.setStrokeCap(SkPaint::kButt_Cap);
}
- if (fDevice) {
- fDevice->drawPoints(*this,
+ if (device) {
+ device->drawPoints(*this,
SkCanvas::kPoints_PointMode,
pointData.fNumPoints,
pointData.fPoints,
@@ -659,7 +659,7 @@
pointData.fNumPoints,
pointData.fPoints,
newP,
- forceUseDevice);
+ device);
}
break;
} else {
@@ -674,8 +674,8 @@
pointData.fPoints[i].fY - pointData.fSize.fY,
pointData.fPoints[i].fX + pointData.fSize.fX,
pointData.fPoints[i].fY + pointData.fSize.fY);
- if (fDevice) {
- fDevice->drawRect(*this, r, newP);
+ if (device) {
+ device->drawRect(*this, r, newP);
} else {
this->drawRect(r, newP);
}
@@ -696,8 +696,8 @@
for (size_t i = 0; i < count; i += inc) {
path.moveTo(pts[i]);
path.lineTo(pts[i+1]);
- if (fDevice) {
- fDevice->drawPath(*this, path, p, nullptr, true);
+ if (device) {
+ device->drawPath(*this, path, p, nullptr, true);
} else {
this->drawPath(path, p, nullptr, true);
}
@@ -1406,8 +1406,7 @@
return SkPaint::TooBigToUseCache(ctm, *paint.setTextMatrix(&textM));
}
-void SkDraw::drawText_asPaths(const char text[], size_t byteLength,
- SkScalar x, SkScalar y,
+void SkDraw::drawText_asPaths(const char text[], size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) const {
SkDEBUGCODE(this->validate();)
@@ -1424,11 +1423,7 @@
matrix.postTranslate(xpos - prevXPos, 0);
if (iterPath) {
const SkPaint& pnt = iter.getPaint();
- if (fDevice) {
- fDevice->drawPath(*this, *iterPath, pnt, &matrix, false);
- } else {
- this->drawPath(*iterPath, pnt, &matrix, false);
- }
+ this->drawPath(*iterPath, pnt, &matrix, false);
}
prevXPos = xpos;
}
@@ -1560,14 +1555,14 @@
uint32_t SkDraw::scalerContextFlags() const {
uint32_t flags = SkPaint::kBoostContrast_ScalerContextFlag;
- if (!fDevice->imageInfo().colorSpace()) {
+ if (!fDst.colorSpace()) {
flags |= SkPaint::kFakeGamma_ScalerContextFlag;
}
return flags;
}
-void SkDraw::drawText(const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkPaint& paint) const {
+void SkDraw::drawText(const char text[], size_t byteLength, SkScalar x, SkScalar y,
+ const SkPaint& paint, const SkSurfaceProps* props) const {
SkASSERT(byteLength == 0 || text != nullptr);
SkDEBUGCODE(this->validate();)
@@ -1584,7 +1579,7 @@
return;
}
- SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextFlags(), fMatrix);
+ SkAutoGlyphCache cache(paint, props, this->scalerContextFlags(), fMatrix);
// The Blitter Choose needs to be live while using the blitter below.
SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint);
@@ -1598,9 +1593,9 @@
//////////////////////////////////////////////////////////////////////////////
-void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkPaint& origPaint) const {
+void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, const SkScalar pos[],
+ int scalarsPerPosition, const SkPoint& offset,
+ const SkPaint& origPaint, const SkSurfaceProps* props) const {
// setup our std paint, in hopes of getting hits in the cache
SkPaint paint(origPaint);
SkScalar matrixScale = paint.setupForAsPaths();
@@ -1615,7 +1610,7 @@
SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
paint.isDevKernText(),
true);
- SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextFlags(), nullptr);
+ SkAutoGlyphCache cache(paint, props, this->scalerContextFlags(), nullptr);
const char* stop = text + byteLength;
SkTextAlignProc alignProc(paint.getTextAlign());
@@ -1637,20 +1632,16 @@
matrix[SkMatrix::kMTransX] = loc.fX;
matrix[SkMatrix::kMTransY] = loc.fY;
- if (fDevice) {
- fDevice->drawPath(*this, *path, paint, &matrix, false);
- } else {
- this->drawPath(*path, paint, &matrix, false);
- }
+ this->drawPath(*path, paint, &matrix, false);
}
}
pos += scalarsPerPosition;
}
}
-void SkDraw::drawPosText(const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkPaint& paint) const {
+void SkDraw::drawPosText(const char text[], size_t byteLength, const SkScalar pos[],
+ int scalarsPerPosition, const SkPoint& offset, const SkPaint& paint,
+ const SkSurfaceProps* props) const {
SkASSERT(byteLength == 0 || text != nullptr);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -1662,11 +1653,11 @@
}
if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
- this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, offset, paint);
+ this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, offset, paint, props);
return;
}
- SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->scalerContextFlags(), fMatrix);
+ SkAutoGlyphCache cache(paint, props, this->scalerContextFlags(), fMatrix);
// The Blitter Choose needs to be live while using the blitter below.
SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint);
diff --git a/src/core/SkDraw.h b/src/core/SkDraw.h
index 8a2c2d4..5343339 100644
--- a/src/core/SkDraw.h
+++ b/src/core/SkDraw.h
@@ -33,7 +33,7 @@
void drawPaint(const SkPaint&) const;
void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
- const SkPaint&, bool forceUseDevice = false) const;
+ const SkPaint&, SkBaseDevice*) const;
void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
const SkRect* postPaintRect) const;
void drawRect(const SkRect& rect, const SkPaint& paint) const {
@@ -64,10 +64,10 @@
const SkPaint&) const;
void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
void drawText(const char text[], size_t byteLength, SkScalar x,
- SkScalar y, const SkPaint& paint) const;
+ SkScalar y, const SkPaint& paint, const SkSurfaceProps*) const;
void drawPosText(const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkPaint& paint) const;
+ const SkPoint& offset, const SkPaint&, const SkSurfaceProps*) const;
void drawVertices(SkCanvas::VertexMode mode, int count,
const SkPoint vertices[], const SkPoint textures[],
const SkColor colors[], SkBlendMode bmode,
@@ -114,11 +114,11 @@
SkPoint* strokeSize);
static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
- 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;
+ 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 SkSurfaceProps*) const;
static SkScalar ComputeResScaleForStroking(const SkMatrix& );
private:
void drawDevMask(const SkMask& mask, const SkPaint&) const;
@@ -149,9 +149,7 @@
SkPixmap fDst;
const SkMatrix* fMatrix; // required
const SkRasterClip* fRC; // required
-
const SkClipStack* fClipStack; // optional, may be null
- SkBaseDevice* fDevice; // optional, may be null
#ifdef SK_DEBUG
void validate() const;
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index f1cbda7..aedfc0b 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -368,7 +368,7 @@
// else we let the SkDraw call our drawPath()
if (!isHairline || paint.getPathEffect() || paint.getMaskFilter() ||
(paint.isAntiAlias() && needs_antialiasing(mode, count, pts, *draw.fMatrix))) {
- draw.drawPoints(mode, count, pts, paint, true);
+ draw.drawPoints(mode, count, pts, paint, this);
return;
}
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index b2c54fe..8f3146b 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -568,9 +568,7 @@
if (d.fClipStack->isEmpty(this->getGlobalBounds())) {
return;
}
- SkDraw pointDraw(d);
- pointDraw.fDevice = this;
- pointDraw.drawPoints(mode, count, points, passedPaint, true);
+ d.drawPoints(mode, count, points, passedPaint, this);
return;
}
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index 302f79e..bf93302 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -1143,7 +1143,7 @@
size_t count, const SkPoint points[],
const SkPaint& paint) {
//This will call back into the device to do the drawing.
- d.drawPoints(mode, count, points, paint, true);
+ d.drawPoints(mode, count, points, paint, this);
}
void SkXPSDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,