Remove translateZ and lights from SkCanvas
authorJim Van Verth <jvanverth@google.com>
Tue, 2 May 2017 20:49:24 +0000 (16:49 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 2 May 2017 21:17:01 +0000 (21:17 +0000)
Bug: skia:6557
Change-Id: I0dbf70c4131ab59e7fc6c674a6587767af98e13a
Reviewed-on: https://skia-review.googlesource.com/15151
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
18 files changed:
include/core/SkCanvas.h
include/private/SkRecords.h
src/core/SkCanvas.cpp
src/core/SkLiteDL.cpp
src/core/SkLiteRecorder.cpp
src/core/SkLiteRecorder.h
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPictureRecord.cpp
src/core/SkPictureRecord.h
src/core/SkRecordDraw.cpp
src/core/SkRecorder.cpp
src/core/SkRecorder.h
tests/CanvasTest.cpp
tools/debugger/SkDebugCanvas.cpp
tools/debugger/SkDebugCanvas.h
tools/debugger/SkDrawCommand.cpp
tools/debugger/SkDrawCommand.h

index 21e5c1c..a259e53 100644 (file)
@@ -423,24 +423,6 @@ public:
     */
     void resetMatrix();
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    /** Add the specified translation to the current draw depth of the canvas.
-        @param z    The distance to translate in Z.
-                    Negative into screen, positive out of screen.
-                    Without translation, the draw depth defaults to 0.
-    */
-    void translateZ(SkScalar z);
-
-    /** Set the current set of lights in the canvas.
-        @param lights   The lights that we want the canvas to have.
-    */
-    void setLights(sk_sp<SkLights> lights);
-
-    /** Returns the current set of lights the canvas uses
-      */
-    sk_sp<SkLights> getLights() const;
-#endif
-
     /**
      *  Modify the current clip with the specified rectangle.
      *  @param rect The rect to combine with the current clip
@@ -1249,14 +1231,6 @@ public:
     void temporary_internal_getRgnClip(SkRegion*);
 
 protected:
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    /** Returns the current (cumulative) draw depth of the canvas.
-      */
-    SkScalar getZ() const;
-
-    sk_sp<SkLights> fLights;
-#endif
-
     // default impl defers to getDevice()->newSurface(info)
     virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
 
@@ -1288,10 +1262,6 @@ protected:
         this->didConcat(SkMatrix::MakeTrans(dx, dy));
     }
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    virtual void didTranslateZ(SkScalar) {}
-#endif
-
     virtual SkRect onGetLocalClipBounds() const;
     virtual SkIRect onGetDeviceClipBounds() const;
 
index 95067d1..02d2108 100644 (file)
@@ -50,7 +50,6 @@ namespace SkRecords {
     M(SaveLayer)                                                    \
     M(SetMatrix)                                                    \
     M(Translate)                                                    \
-    M(TranslateZ)                                                   \
     M(Concat)                                                       \
     M(ClipPath)                                                     \
     M(ClipRRect)                                                    \
@@ -191,7 +190,6 @@ RECORD(Concat, 0,
 RECORD(Translate, 0,
         SkScalar dx;
         SkScalar dy);
-RECORD(TranslateZ, 0, SkScalar z);
 
 struct ClipOpAndAA {
     ClipOpAndAA() {}
index ad9bcf5..5e33dbf 100644 (file)
@@ -293,22 +293,17 @@ public:
     SkMatrix            fMatrix;
     int                 fDeferredSaveCount;
 
-    // This is the current cumulative depth (aggregate of all done translateZ calls)
-    SkScalar        fCurDrawDepth;
-
     MCRec() {
         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),
-                               fCurDrawDepth(prev.fCurDrawDepth) {
+    MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix) {
         fFilter = SkSafeRef(prev.fFilter);
         fLayer = nullptr;
         fTopLayer = prev.fTopLayer;
@@ -640,9 +635,6 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
     fAllowSimplifyClip = false;
     fSaveCount = 1;
     fMetaData = nullptr;
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    fLights = nullptr;
-#endif
 
     fMCRec = (MCRec*)fMCStack.push_back();
     new (fMCRec) MCRec;
@@ -1405,26 +1397,6 @@ void SkCanvas::resetMatrix() {
     this->setMatrix(SkMatrix::I());
 }
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-void SkCanvas::translateZ(SkScalar z) {
-    this->checkForDeferredSave();
-    this->fMCRec->fCurDrawDepth += z;
-    this->didTranslateZ(z);
-}
-
-SkScalar SkCanvas::getZ() const {
-    return this->fMCRec->fCurDrawDepth;
-}
-
-void SkCanvas::setLights(sk_sp<SkLights> lights) {
-    this->fLights = lights;
-}
-
-sk_sp<SkLights> SkCanvas::getLights() const {
-    return this->fLights;
-}
-#endif
-
 //////////////////////////////////////////////////////////////////////////////
 
 void SkCanvas::clipRect(const SkRect& rect, SkClipOp op, bool doAA) {
index fb629dd..0162327 100644 (file)
@@ -47,7 +47,7 @@ static const D* pod(const T* op, size_t offset = 0) {
 namespace {
 #define TYPES(M)                                                                \
     M(SetDrawFilter) M(Save) M(Restore) M(SaveLayer)                            \
-    M(Concat) M(SetMatrix) M(Translate) M(TranslateZ)                           \
+    M(Concat) M(SetMatrix) M(Translate)                                         \
     M(ClipPath) M(ClipRect) M(ClipRRect) M(ClipRegion)                          \
     M(DrawPaint) M(DrawPath) M(DrawRect) M(DrawRegion) M(DrawOval) M(DrawArc)   \
     M(DrawRRect) M(DrawDRRect) M(DrawAnnotation) M(DrawDrawable) M(DrawPicture) \
@@ -133,16 +133,6 @@ namespace {
             c->translate(dx, dy);
         }
     };
-    struct TranslateZ final : Op {
-        static const auto kType = Type::TranslateZ;
-        TranslateZ(SkScalar dz) : dz(dz) {}
-        SkScalar dz;
-        void draw(SkCanvas* c, const SkMatrix&) const {
-        #ifdef SK_EXPERIMENTAL_SHADOWING
-            c->translateZ(dz);
-        #endif
-        }
-    };
 
     struct ClipPath final : Op {
         static const auto kType = Type::ClipPath;
@@ -538,7 +528,6 @@ void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
 void SkLiteDL::   concat(const SkMatrix& matrix)   { this->push   <Concat>(0, matrix); }
 void SkLiteDL::setMatrix(const SkMatrix& matrix)   { this->push<SetMatrix>(0, matrix); }
 void SkLiteDL::translate(SkScalar dx, SkScalar dy) { this->push<Translate>(0, dx, dy); }
-void SkLiteDL::translateZ(SkScalar dz) { this->push<TranslateZ>(0, dz); }
 
 void SkLiteDL::clipPath(const SkPath& path, SkClipOp op, bool aa) {
     this->push<ClipPath>(0, path, op, aa);
index d252549..5affb3d 100644 (file)
@@ -194,7 +194,3 @@ void SkLiteRecorder::onDrawAtlas(const SkImage* atlas,
                                  const SkPaint* paint) {
     fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, cull, paint);
 }
-
-void SkLiteRecorder::didTranslateZ(SkScalar dz) {
-    fDL->translateZ(dz);
-}
index 9f52493..3c156af 100644 (file)
@@ -78,12 +78,6 @@ public:
     void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
                      int, SkBlendMode, const SkRect*, const SkPaint*) override;
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    void didTranslateZ(SkScalar) override;
-#else
-    void didTranslateZ(SkScalar);
-#endif
-
 private:
     typedef SkNoDrawCanvas INHERITED;
 
index 745a7e3..5340fcb 100644 (file)
@@ -87,9 +87,9 @@ enum DrawType {
     DRAW_DRAWABLE_MATRIX,
     DRAW_TEXT_RSXFORM,
 
-    TRANSLATE_Z,
+    TRANSLATE_Z, // deprecated (M60)
 
-    DRAW_SHADOWED_PICTURE_LIGHTS,
+    DRAW_SHADOWED_PICTURE_LIGHTS,  // deprecated (M60)
     DRAW_IMAGE_LATTICE,
     DRAW_ARC,
     DRAW_REGION,
index 3af7909..cad665b 100644 (file)
@@ -783,14 +783,6 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
 
             canvas->translate(dx, dy);
         } break;
-        case TRANSLATE_Z: {
-#ifdef SK_EXPERIMENTAL_SHADOWING
-            SkScalar dz = reader->readScalar();
-            BREAK_ON_READ_ERROR(reader);
-
-            canvas->translateZ(dz);
-#endif
-        } break;
         default:
             SkASSERTF(false, "Unknown draw type: %d", op);
     }
index f794b73..69a35f5 100644 (file)
@@ -234,18 +234,6 @@ void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) {
     this->INHERITED::didSetMatrix(matrix);
 }
 
-void SkPictureRecord::didTranslateZ(SkScalar z) {
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    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);
-#endif
-}
-
 static bool clipOpExpands(SkClipOp op) {
     switch (op) {
         case kUnion_SkClipOp:
index dcdfebe..08aa335 100644 (file)
@@ -164,12 +164,6 @@ protected:
     void didConcat(const SkMatrix&) override;
     void didSetMatrix(const SkMatrix&) override;
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    void didTranslateZ(SkScalar) override;
-#else
-    void didTranslateZ(SkScalar);
-#endif
-
     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
 
     void onDrawText(const void* text, size_t, SkScalar x, SkScalar y, const SkPaint&) override;
index 634676c..fbb7f7c 100644 (file)
@@ -89,12 +89,6 @@ 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));
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-DRAW(TranslateZ, SkCanvas::translateZ(r.z));
-#else
-template <> void Draw::draw(const TranslateZ& r) { }
-#endif
-
 DRAW(DrawArc, drawArc(r.oval, r.startAngle, r.sweepAngle, r.useCenter, r.paint));
 DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
 DRAW(DrawImage, drawImage(r.image.get(), r.left, r.top, r.paint));
@@ -297,7 +291,6 @@ private:
     void trackBounds(const SetMatrix&)         { this->pushControl(); }
     void trackBounds(const Concat&)            { this->pushControl(); }
     void trackBounds(const Translate&)         { this->pushControl(); }
-    void trackBounds(const TranslateZ&)        { this->pushControl(); }
     void trackBounds(const ClipRect&)          { this->pushControl(); }
     void trackBounds(const ClipRRect&)         { this->pushControl(); }
     void trackBounds(const ClipPath&)          { this->pushControl(); }
index c111db6..64d613d 100644 (file)
@@ -372,12 +372,6 @@ void SkRecorder::didTranslate(SkScalar dx, SkScalar dy) {
     APPEND(Translate, dx, dy);
 }
 
-void SkRecorder::didTranslateZ(SkScalar z) {
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    APPEND(TranslateZ, z);
-#endif
-}
-
 void SkRecorder::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
     INHERITED(onClipRect, rect, op, edgeStyle);
     SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
index c815744..5344934 100644 (file)
@@ -62,12 +62,6 @@ public:
     void didSetMatrix(const SkMatrix&) override;
     void didTranslate(SkScalar, SkScalar) override;
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    void didTranslateZ(SkScalar) override;
-#else
-    void didTranslateZ(SkScalar);
-#endif
-
     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
     void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
     void onDrawText(const void* text,
index cca692b..b304a0d 100644 (file)
@@ -658,46 +658,6 @@ DEF_TEST(Canvas_ClipEmptyPath, reporter) {
     canvas.restore();
 }
 
-#define SHADOW_TEST_CANVAS_CONST 10
-#ifdef SK_EXPERIMENTAL_SHADOWING
-class SkShadowTestCanvas : public SkPaintFilterCanvas {
-public:
-
-    SkShadowTestCanvas(int x, int y, skiatest::Reporter* reporter)
-        : INHERITED(x,y)
-        , fReporter(reporter) {}
-
-    bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const {
-        REPORTER_ASSERT(this->fReporter, this->getZ() == SHADOW_TEST_CANVAS_CONST);
-
-        return true;
-    }
-
-    void testUpdateDepth(skiatest::Reporter *reporter) {
-        // set some depths (with picture enabled), then check them as they get set
-
-        REPORTER_ASSERT(reporter, this->getZ() == 0);
-        this->translateZ(-10);
-        REPORTER_ASSERT(reporter, this->getZ() == -10);
-
-        this->save();
-        this->translateZ(20);
-        REPORTER_ASSERT(reporter, this->getZ() == 10);
-
-        this->restore();
-        REPORTER_ASSERT(reporter, this->getZ() == -10);
-
-        this->translateZ(13.14f);
-        REPORTER_ASSERT(reporter, SkScalarNearlyEqual(this->getZ(), 3.14f));
-    }
-
-private:
-    skiatest::Reporter* fReporter;
-
-    typedef SkPaintFilterCanvas INHERITED;
-};
-#endif
-
 namespace {
 
 class MockFilterCanvas : public SkPaintFilterCanvas {
@@ -727,22 +687,6 @@ DEF_TEST(PaintFilterCanvas_ConsistentState, reporter) {
     filterCanvas.scale(0.75f, 0.5f);
     REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
     REPORTER_ASSERT(reporter, filterCanvas.getLocalClipBounds().contains(canvas.getLocalClipBounds()));
-
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    SkShadowTestCanvas* tCanvas = new SkShadowTestCanvas(100,100, reporter);
-    tCanvas->testUpdateDepth(reporter);
-    delete(tCanvas);
-
-    SkPictureRecorder recorder;
-    SkShadowTestCanvas *tSCanvas = new SkShadowTestCanvas(100, 100, reporter);
-    SkCanvas *tPCanvas = recorder.beginRecording(SkRect::MakeIWH(100, 100));
-
-    tPCanvas->translateZ(SHADOW_TEST_CANVAS_CONST);
-    sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
-    tSCanvas->drawPicture(pic);
-
-    delete(tSCanvas);
-#endif
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
index bed6da0..23f4ae3 100644 (file)
@@ -621,13 +621,6 @@ void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
     this->INHERITED::didSetMatrix(matrix);
 }
 
-void SkDebugCanvas::didTranslateZ(SkScalar z) {
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    this->addDrawCommand(new SkTranslateZCommand(z));
-    this->INHERITED::didTranslateZ(z);
-#endif
-}
-
 void SkDebugCanvas::toggleCommand(int index, bool toggle) {
     SkASSERT(index < fCommandVector.count());
     fCommandVector[index]->setVisible(toggle);
index 6eb3456..9b944f7 100644 (file)
@@ -195,12 +195,6 @@ protected:
 
     void didSetMatrix(const SkMatrix &) override;
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    void didTranslateZ(SkScalar) override;
-#else
-    void didTranslateZ(SkScalar);
-#endif
-
     void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
     void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
index 6029f83..16a270b 100644 (file)
@@ -237,7 +237,6 @@ const char* SkDrawCommand::GetCommandString(OpType type) {
         case kSave_OpType: return "Save";
         case kSaveLayer_OpType: return "SaveLayer";
         case kSetMatrix_OpType: return "SetMatrix";
-        case kTranslateZ_OpType: return "TranslateZ";
         default:
             SkDebugf("OpType error 0x%08x\n", type);
             SkASSERT(0);
@@ -295,9 +294,6 @@ SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& url
         INSTALL_FACTORY(Save);
         INSTALL_FACTORY(SaveLayer);
         INSTALL_FACTORY(SetMatrix);
-#ifdef SK_EXPERIMENTAL_SHADOWING
-        INSTALL_FACTORY(TranslateZ);
-#endif
     }
     SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString());
     FROM_JSON* factory = factories.find(name);
@@ -1570,14 +1566,6 @@ static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) {
     result->set9(values);
 }
 
-#ifdef SK_EXPERIMENTAL_SHADOWING
-// somehow this is only used in shadows...
-static void extract_json_scalar(Json::Value& scalar, SkScalar* result) {
-    SkScalar value = scalar.asFloat();
-    *result = value;
-}
-#endif
-
 static void extract_json_path(Json::Value& path, SkPath* result) {
     const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString();
     if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) {
@@ -3469,32 +3457,3 @@ SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command,
     extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix);
     return new SkSetMatrixCommand(matrix);
 }
-
-SkTranslateZCommand::SkTranslateZCommand(SkScalar z)
-    : INHERITED(kTranslateZ_OpType) {
-    fZTranslate = z;
-    fInfo.push(SkObjectParser::ScalarToString(fZTranslate, "drawDepthTranslation"));
-}
-
-void SkTranslateZCommand::execute(SkCanvas* canvas) const {
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    canvas->translateZ(fZTranslate);
-#endif
-}
-
-Json::Value SkTranslateZCommand::toJSON(UrlDataManager& urlDataManager) const {
-    Json::Value result = INHERITED::toJSON(urlDataManager);
-    result[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS] = MakeJsonScalar(fZTranslate);
-    return result;
-}
-
-SkTranslateZCommand* SkTranslateZCommand::fromJSON(Json::Value& command,
-                                       UrlDataManager& urlDataManager) {
-    SkScalar z;
-#ifdef SK_EXPERIMENTAL_SHADOWING
-    extract_json_scalar(command[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS], &z);
-#else
-    z = 0;
-#endif
-    return new SkTranslateZCommand(z);
-}
index ff64dd5..fc2f45a 100644 (file)
@@ -57,9 +57,8 @@ public:
         kSave_OpType,
         kSaveLayer_OpType,
         kSetMatrix_OpType,
-        kTranslateZ_OpType,
 
-        kLast_OpType = kTranslateZ_OpType
+        kLast_OpType = kSetMatrix_OpType
     };
 
     static const int kOpTypeCount = kLast_OpType + 1;
@@ -761,18 +760,5 @@ private:
 
     typedef SkDrawCommand INHERITED;
 };
-
-class SkTranslateZCommand : public SkDrawCommand {
-public:
-    SkTranslateZCommand(SkScalar);
-    void execute(SkCanvas* canvas) const override;
-    Json::Value toJSON(UrlDataManager& urlDataManager) const override;
-    static SkTranslateZCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager);
-
-private:
-    SkScalar fZTranslate;
-
-    typedef SkDrawCommand INHERITED;
-};
 #endif