diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkCanvas.cpp | 8 | ||||
-rw-r--r-- | src/core/SkShape.cpp | 85 | ||||
-rw-r--r-- | src/core/core_files.mk | 1 |
3 files changed, 94 insertions, 0 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 199c1b0b97..57b4f7b340 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -22,6 +22,7 @@ #include "SkDrawLooper.h" #include "SkPicture.h" #include "SkScalarCompare.h" +#include "SkShape.h" #include "SkTemplates.h" #include "SkUtils.h" #include <new> @@ -1357,12 +1358,19 @@ void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength, this->drawTextOnPath(text, byteLength, path, &matrix, paint); } +/////////////////////////////////////////////////////////////////////////////// + void SkCanvas::drawPicture(SkPicture& picture) { int saveCount = save(); picture.draw(this); restoreToCount(saveCount); } +void SkCanvas::drawShape(SkShape* shape) { + // shape baseclass takes care of save/restore + shape->draw(this); +} + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkShape.cpp b/src/core/SkShape.cpp new file mode 100644 index 0000000000..a6d19af96b --- /dev/null +++ b/src/core/SkShape.cpp @@ -0,0 +1,85 @@ +#include "SkCanvas.h" +#include "SkShape.h" +#include "SkMatrix.h" + +SkShape::~SkShape() { + if (fMatrix) { + SkDELETE(fMatrix); + } +} + +void SkShape::getMatrix(SkMatrix* matrix) const { + if (matrix) { + if (fMatrix) { + *matrix = *fMatrix; + } else { + matrix->reset(); + } + } +} + +void SkShape::setMatrix(const SkMatrix& matrix) { + if (matrix.isIdentity()) { + this->resetMatrix(); + } else { + if (NULL == fMatrix) { + fMatrix = SkNEW(SkMatrix); + } + *fMatrix = matrix; + } +} + +void SkShape::resetMatrix() { + if (fMatrix) { + SkDELETE(fMatrix); + fMatrix = NULL; + } +} + +void SkShape::draw(SkCanvas* canvas) { + int saveCount = canvas->getSaveCount(); + if (fMatrix) { + canvas->save(SkCanvas::kMatrix_SaveFlag); + canvas->concat(*fMatrix); + } + this->onDraw(canvas); + canvas->restoreToCount(saveCount); +} + +void SkShape::drawXY(SkCanvas* canvas, SkScalar dx, SkScalar dy) { + int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag); + canvas->translate(dx, dy); + if (fMatrix) { + canvas->concat(*fMatrix); + } + this->onDraw(canvas); + canvas->restoreToCount(saveCount); +} + +void SkShape::drawMatrix(SkCanvas* canvas, const SkMatrix& matrix) { + int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag); + canvas->concat(matrix); + if (fMatrix) { + canvas->concat(*fMatrix); + } + this->onDraw(canvas); + canvas->restoreToCount(saveCount); +} + +/////////////////////////////////////////////////////////////////////////////// + +void SkShape::flatten(SkFlattenableWriteBuffer& buffer) { + buffer.writeBool(fMatrix != NULL); + if (fMatrix) { + *(SkMatrix*)buffer.reserve(sizeof(SkMatrix)) = *fMatrix; + } +} + +SkShape::SkShape(SkFlattenableReadBuffer& buffer) { + fMatrix = NULL; + if (buffer.readBool()) { + fMatrix = SkNEW(SkMatrix); + buffer.read(fMatrix, sizeof(*fMatrix)); + } +} + diff --git a/src/core/core_files.mk b/src/core/core_files.mk index 27849e7021..94e19d7255 100644 --- a/src/core/core_files.mk +++ b/src/core/core_files.mk @@ -72,6 +72,7 @@ SOURCE := \ SkScan_Hairline.cpp \ SkScan_Path.cpp \ SkShader.cpp \ + SkShape.cpp \ SkSpriteBlitter_ARGB32.cpp \ SkSpriteBlitter_RGB16.cpp \ SkStream.cpp \ |