aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar vjiaoblack <vjiaoblack@google.com>2016-07-13 14:05:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-13 14:05:28 -0700
commite5de130788c8637d2f7df9ddb0241b78e04d5882 (patch)
treee837af1f0ce2a87a9b4be70172f74d9a5dea57a4 /src
parentf382b48687176f15091c2defc0002f0a189f4167 (diff)
Added the framework for having canvas/recorder/picture record depth_set's.
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp17
-rw-r--r--src/core/SkPictureFlat.h4
-rw-r--r--src/core/SkPicturePlayback.cpp8
-rw-r--r--src/core/SkPictureRecord.cpp10
-rw-r--r--src/core/SkPictureRecord.h2
-rw-r--r--src/core/SkRecordDraw.cpp4
-rw-r--r--src/core/SkRecorder.cpp4
-rw-r--r--src/core/SkRecorder.h1
8 files changed, 46 insertions, 4 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f893a62e75..0bd3851c06 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -294,17 +294,22 @@ public:
SkMatrix fMatrix;
int fDeferredSaveCount;
+ // This is the current cumulative depth (aggregate of all done translateZ calls)
+ SkScalar fCurDrawDepth;
+
MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) {
fFilter = nullptr;
fLayer = nullptr;
fTopLayer = nullptr;
fMatrix.reset();
fDeferredSaveCount = 0;
+ fCurDrawDepth = 0;
// don't bother initializing fNext
inc_rec();
}
- MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix) {
+ MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix),
+ fCurDrawDepth(prev.fCurDrawDepth) {
fFilter = SkSafeRef(prev.fFilter);
fLayer = nullptr;
fTopLayer = prev.fTopLayer;
@@ -1539,6 +1544,16 @@ void SkCanvas::resetMatrix() {
this->setMatrix(SkMatrix::I());
}
+void SkCanvas::translateZ(SkScalar z) {
+ this->checkForDeferredSave();
+ this->fMCRec->fCurDrawDepth += z;
+ this->didTranslateZ(z);
+}
+
+SkScalar SkCanvas::getZ() const {
+ return this->fMCRec->fCurDrawDepth;
+}
+
//////////////////////////////////////////////////////////////////////////////
void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 3546fb2e0a..125d4e95e8 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -81,7 +81,9 @@ enum DrawType {
DRAW_DRAWABLE_MATRIX,
DRAW_TEXT_RSXFORM,
- LAST_DRAWTYPE_ENUM = DRAW_DRAWABLE_MATRIX,
+ TRANSLATE_Z,
+
+ LAST_DRAWTYPE_ENUM = TRANSLATE_Z
};
// In the 'match' method, this constant will match any flavor of DRAW_BITMAP*
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 6b8930436f..60c4fe898d 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -129,8 +129,8 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
reader->skip(size - 4);
} break;
case CLIP_PATH: {
- const SkPath& path = fPictureData->getPath(reader);
- uint32_t packed = reader->readInt();
+ const SkPath& path = fPictureData->getPath(reader);
+ uint32_t packed = reader->readInt();
SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
bool doAA = ClipParams_unpackDoAA(packed);
size_t offsetToRestore = reader->readInt();
@@ -616,6 +616,10 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
SkScalar dy = reader->readScalar();
canvas->translate(dx, dy);
} break;
+ case TRANSLATE_Z: {
+ SkScalar dz = reader->readScalar();
+ canvas->translateZ(dz);
+ }
default:
SkASSERTF(false, "Unknown draw type: %d", op);
}
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 17ed1aa20b..f2a0fd857c 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -218,6 +218,16 @@ void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) {
this->INHERITED::didSetMatrix(matrix);
}
+void SkPictureRecord::didTranslateZ(SkScalar z) {
+ this->validate(fWriter.bytesWritten(), 0);
+ // op + scalar
+ size_t size = 1 * kUInt32Size + 1 * sizeof(SkScalar);
+ size_t initialOffset = this->addDraw(TRANSLATE_Z, &size);
+ this->addScalar(z);
+ this->validate(initialOffset, size);
+ this->INHERITED::didTranslateZ(z);
+}
+
static bool regionOpExpands(SkRegion::Op op) {
switch (op) {
case SkRegion::kUnion_Op:
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index bdb6609bd9..276dd3e29b 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -159,6 +159,8 @@ protected:
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
+ void didTranslateZ(SkScalar) override;
+
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
void onDrawText(const void* text, size_t, SkScalar x, SkScalar y, const SkPaint&) override;
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index eb027296f1..02d07d5005 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -86,6 +86,8 @@ DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa));
DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa));
DRAW(ClipRegion, clipRegion(r.region, r.op));
+DRAW(TranslateZ, SkCanvas::translateZ(r.z));
+
DRAW(DrawBitmap, drawBitmap(r.bitmap.shallowCopy(), r.left, r.top, r.paint));
DRAW(DrawBitmapNine, drawBitmapNine(r.bitmap.shallowCopy(), r.center, r.dst, r.paint));
DRAW(DrawBitmapRect,
@@ -287,6 +289,8 @@ private:
void trackBounds(const ClipPath&) { this->pushControl(); }
void trackBounds(const ClipRegion&) { this->pushControl(); }
+ void trackBounds(const TranslateZ&) { this->pushControl(); }
+
// For all other ops, we can calculate and store the bounds directly now.
template <typename T> void trackBounds(const T& op) {
fBounds[fCurrentOp] = this->bounds(op);
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index 19cb663eaf..c7869bb6a4 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -369,6 +369,10 @@ void SkRecorder::didSetMatrix(const SkMatrix& matrix) {
APPEND(SetMatrix, matrix);
}
+void SkRecorder::didTranslateZ(SkScalar z) {
+ APPEND(TranslateZ, z);
+}
+
void SkRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
INHERITED(onClipRect, rect, op, edgeStyle);
SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 3cf0be97c3..66a006712e 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -60,6 +60,7 @@ public:
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
+ void didTranslateZ(SkScalar) override;
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
void onDrawDrawable(SkDrawable*, const SkMatrix*) override;