Record concat as setMatrix.
authormtklein <mtklein@chromium.org>
Tue, 19 Aug 2014 14:09:40 +0000 (07:09 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 19 Aug 2014 14:09:40 +0000 (07:09 -0700)
Mainly this cuts out a type to have to think about in SkRecord world.
It also means all the CTMs are recorded directly in the SkRecord, so
we can track the current CTM by pointer rather than by copying.

BUG=skia:
R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

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

src/core/SkRecordDraw.cpp
src/core/SkRecorder.cpp
src/core/SkRecords.h

index fda8488..e792d37 100644 (file)
@@ -64,7 +64,6 @@ DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
 DRAW(PopCull, popCull());
 DRAW(PushCull, pushCull(r.rect));
 DRAW(Clear, clear(r.color));
-DRAW(Concat, concat(r.matrix));
 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
 
 DRAW(ClipPath, clipPath(r.path, r.op, r.doAA));
@@ -120,7 +119,7 @@ public:
         // Calculate bounds for all ops.  This won't go quite in order, so we'll need
         // to store the bounds separately then feed them in to the BBH later in order.
         const SkIRect largest = SkIRect::MakeLargest();
-        fCTM.setIdentity();
+        fCTM = &SkMatrix::I();
         fCurrentClipBounds = largest;
         for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) {
             record.visit<void>(fCurrentOp, *this);
@@ -161,9 +160,8 @@ private:
     };
 
     template <typename T> void updateCTM(const T&) { /* most ops don't change the CTM */ }
-    void updateCTM(const Restore& op)   { fCTM = op.matrix; }
-    void updateCTM(const SetMatrix& op) { fCTM = op.matrix; }
-    void updateCTM(const Concat& op)    { fCTM.preConcat(op.matrix); }
+    void updateCTM(const Restore& op)   { fCTM = &op.matrix; }
+    void updateCTM(const SetMatrix& op) { fCTM = &op.matrix; }
 
     template <typename T> void updateClipBounds(const T&) { /* most ops don't change the clip */ }
     // Each of these devBounds fields is the state of the device bounds after the op.
@@ -186,7 +184,6 @@ private:
     void trackBounds(const SaveLayer& op)  { this->pushSaveBlock(op.paint); }
     void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); }
 
-    void trackBounds(const Concat&)     { this->pushControl(); }
     void trackBounds(const SetMatrix&)  { this->pushControl(); }
     void trackBounds(const ClipRect&)   { this->pushControl(); }
     void trackBounds(const ClipRRect&)  { this->pushControl(); }
@@ -359,7 +356,7 @@ private:
         }
 
         // Map the rect back to device space.
-        fCTM.mapRect(&rect);
+        fCTM->mapRect(&rect);
         SkIRect devRect;
         rect.roundOut(&devRect);
 
@@ -376,7 +373,7 @@ private:
     // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative
     // device bounds of the current clip (fCurrentClipBounds).
     unsigned fCurrentOp;
-    SkMatrix fCTM;
+    const SkMatrix* fCTM;
     SkIRect fCurrentClipBounds;
 
     // Used to track the bounds of Save/Restore blocks and the control ops inside them.
index d49de20..1ee24ff 100644 (file)
@@ -218,20 +218,17 @@ void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
 
 void SkRecorder::willSave() {
     APPEND(Save);
-    INHERITED(willSave);
 }
 
 SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds,
                                                       const SkPaint* paint,
                                                       SkCanvas::SaveFlags flags) {
     APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags);
-    INHERITED(willSaveLayer, bounds, paint, flags);
     return SkCanvas::kNoLayer_SaveLayerStrategy;
 }
 
 void SkRecorder::didRestore() {
     APPEND(Restore, this->devBounds(), this->getTotalMatrix());
-    INHERITED(didRestore);
 }
 
 void SkRecorder::onPushCull(const SkRect& rect) {
@@ -243,14 +240,12 @@ void SkRecorder::onPopCull() {
 }
 
 void SkRecorder::didConcat(const SkMatrix& matrix) {
-    APPEND(Concat, matrix);
-    INHERITED(didConcat, matrix);
+    this->didSetMatrix(this->getTotalMatrix());
 }
 
 void SkRecorder::didSetMatrix(const SkMatrix& matrix) {
     SkASSERT(matrix == this->getTotalMatrix());
     APPEND(SetMatrix, matrix);
-    INHERITED(didSetMatrix, matrix);
 }
 
 void SkRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
index bc768d9..01cdbf7 100644 (file)
@@ -44,7 +44,6 @@ namespace SkRecords {
     M(SaveLayer)                                                    \
     M(PushCull)                                                     \
     M(PopCull)                                                      \
-    M(Concat)                                                       \
     M(SetMatrix)                                                    \
     M(ClipPath)                                                     \
     M(ClipRRect)                                                    \
@@ -204,7 +203,6 @@ RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas:
 RECORD1(PushCull, SkRect, rect);
 RECORD0(PopCull);
 
-RECORD1(Concat, SkMatrix, matrix);
 RECORD1(SetMatrix, SkMatrix, matrix);
 
 RECORD4(ClipPath,   SkIRect, devBounds, SkPath,   path,   SkRegion::Op, op, bool, doAA);