diff options
author | vjiaoblack <vjiaoblack@google.com> | 2016-07-21 10:25:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-21 10:25:54 -0700 |
commit | 95302da19d8b0a3bcd9d9be0e79f486760787f09 (patch) | |
tree | 026a55650eb1678eb9d04b84202c5969eb109776 /tools | |
parent | b5dc4051f722d9c65d55eb3a65e0e8d031e107ad (diff) |
Creating framework for drawShadowedPicture
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2146073003
Committed: https://skia.googlesource.com/skia/+/0ae097d116f4332be02a135ffc99c162473dee6a
Review-Url: https://codereview.chromium.org/2146073003
Diffstat (limited to 'tools')
-rw-r--r-- | tools/debugger/SkDebugCanvas.cpp | 21 | ||||
-rw-r--r-- | tools/debugger/SkDebugCanvas.h | 58 | ||||
-rw-r--r-- | tools/debugger/SkDrawCommand.cpp | 76 | ||||
-rw-r--r-- | tools/debugger/SkDrawCommand.h | 31 |
4 files changed, 168 insertions, 18 deletions
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp index 062445ba0a..d5297ed980 100644 --- a/tools/debugger/SkDebugCanvas.cpp +++ b/tools/debugger/SkDebugCanvas.cpp @@ -58,6 +58,16 @@ protected: this->SkCanvas::onDrawPicture(picture, matrix, paint); } + void onDrawShadowedPicture(const SkPicture* picture, + const SkMatrix* matrix, + const SkPaint* paint) { +#ifdef SK_EXPERIMENTAL_SHADOWING + this->SkCanvas::onDrawShadowedPicture(picture, matrix, paint); +#else + this->SkCanvas::onDrawPicture(picture, matrix, paint); +#endif + } + private: sk_sp<SkXfermode> fOverdrawXfermode; @@ -603,6 +613,15 @@ void SkDebugCanvas::onDrawPicture(const SkPicture* picture, this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint))); } +void SkDebugCanvas::onDrawShadowedPicture(const SkPicture* picture, + const SkMatrix* matrix, + const SkPaint* paint) { + this->addDrawCommand(new SkBeginDrawShadowedPictureCommand(picture, matrix, paint)); + SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); + picture->playback(this); + this->addDrawCommand(new SkEndDrawShadowedPictureCommand(SkToBool(matrix) || SkToBool(paint))); +} + void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); @@ -691,8 +710,10 @@ void SkDebugCanvas::didSetMatrix(const SkMatrix& 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) { diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h index 4264f55200..9f785ef7f3 100644 --- a/tools/debugger/SkDebugCanvas.h +++ b/tools/debugger/SkDebugCanvas.h @@ -24,23 +24,27 @@ class SkNWayCanvas; class SK_API SkDebugCanvas : public SkCanvas { public: SkDebugCanvas(int width, int height); + virtual ~SkDebugCanvas(); void toggleFilter(bool toggle) { fFilter = toggle; } void setMegaVizMode(bool megaVizMode) { fMegaVizMode = megaVizMode; } + bool getMegaVizMode() const { return fMegaVizMode; } /** * Enable or disable overdraw visualization */ void setOverdrawViz(bool overdrawViz); + bool getOverdrawViz() const { return fOverdrawViz; } /** * Set the color of the clip visualization. An alpha of zero renders the clip invisible. */ void setClipVizColor(SkColor clipVizColor) { this->fClipVizColor = clipVizColor; } + SkColor getClipVizColor() const { return fClipVizColor; } void setDrawGpuBatchBounds(bool drawGpuBatchBounds) { @@ -51,7 +55,7 @@ public: bool getAllowSimplifyClip() const { return fAllowSimplifyClip; } - void setPicture(SkPicture* picture) { fPicture = picture; } + void setPicture(SkPicture *picture) { fPicture = picture; } /** * Enable or disable texure filtering override @@ -62,7 +66,7 @@ public: Executes all draw calls to the canvas. @param canvas The canvas being drawn to */ - void draw(SkCanvas* canvas); + void draw(SkCanvas *canvas); /** Executes the draw calls up to the specified index. @@ -70,19 +74,19 @@ public: @param index The index of the final command being executed @param m an optional Mth gpu batch to highlight, or -1 */ - void drawTo(SkCanvas* canvas, int index, int m = -1); + void drawTo(SkCanvas *canvas, int index, int m = -1); /** Returns the most recently calculated transformation matrix */ - const SkMatrix& getCurrentMatrix() { + const SkMatrix &getCurrentMatrix() { return fMatrix; } /** Returns the most recently calculated clip */ - const SkIRect& getCurrentClip() { + const SkIRect &getCurrentClip() { return fClip; } @@ -101,20 +105,20 @@ public: Returns the draw command at the given index. @param index The index of the command */ - SkDrawCommand* getDrawCommandAt(int index); + SkDrawCommand *getDrawCommandAt(int index); /** Sets the draw command for a given index. @param index The index to overwrite @param command The new command */ - void setDrawCommandAt(int index, SkDrawCommand* command); + void setDrawCommandAt(int index, SkDrawCommand *command); /** Returns information about the command at the given index. @param index The index of the command */ - const SkTDArray<SkString*>* getCommandInfo(int index) const; + const SkTDArray<SkString *> *getCommandInfo(int index) const; /** Returns the visibility of the command at the given index. @@ -126,13 +130,13 @@ public: Returns the vector of draw commands */ SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead") - const SkTDArray<SkDrawCommand*>& getDrawCommands() const; + const SkTDArray<SkDrawCommand *> &getDrawCommands() const; /** Returns the vector of draw commands. Do not use this entry point - it is going away! */ - SkTDArray<SkDrawCommand*>& getDrawCommands(); + SkTDArray<SkDrawCommand *> &getDrawCommands(); /** Returns length of draw command vector. @@ -158,9 +162,9 @@ public: SkDebugCanvas::getSize(). The encoder may use the UrlDataManager to store binary data such as images, referring to them via URLs embedded in the JSON. */ - Json::Value toJSON(UrlDataManager& urlDataManager, int n, SkCanvas*); + Json::Value toJSON(UrlDataManager &urlDataManager, int n, SkCanvas *); - Json::Value toJSONBatchList(int n, SkCanvas*); + Json::Value toJSONBatchList(int n, SkCanvas *); //////////////////////////////////////////////////////////////////////////////// // Inherited from SkCanvas @@ -170,8 +174,10 @@ public: static const int kVizImageWidth = 256; bool isClipEmpty() const override { return false; } + bool isClipRect() const override { return true; } - bool getClipBounds(SkRect* bounds) const override { + + bool getClipBounds(SkRect *bounds) const override { if (bounds) { bounds->setXYWH(0, 0, SkIntToScalar(this->imageInfo().width()), @@ -179,7 +185,8 @@ public: } return true; } - bool getClipDeviceBounds(SkIRect* bounds) const override { + + bool getClipDeviceBounds(SkIRect *bounds) const override { if (bounds) { bounds->setLargest(); } @@ -188,13 +195,20 @@ public: protected: void willSave() override; - SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; + + SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override; + void willRestore() override; - void didConcat(const SkMatrix&) override; - void didSetMatrix(const SkMatrix&) override; + void didConcat(const SkMatrix &) override; + + 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; @@ -240,6 +254,16 @@ protected: void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; +#ifdef SK_EXPERIMENTAL_SHADOWING + void onDrawShadowedPicture(const SkPicture*, + const SkMatrix*, + const SkPaint*) override; +#else + void onDrawShadowedPicture(const SkPicture*, + const SkMatrix*, + const SkPaint*); +#endif + void markActiveCommands(int index); private: diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 8f42cb70ec..51eb96706a 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -180,6 +180,7 @@ SkDrawCommand::~SkDrawCommand() { const char* SkDrawCommand::GetCommandString(OpType type) { switch (type) { case kBeginDrawPicture_OpType: return "BeginDrawPicture"; + case kBeginDrawShadowedPicture_OpType: return "BeginDrawShadowedPicture"; case kClipPath_OpType: return "ClipPath"; case kClipRegion_OpType: return "ClipRegion"; case kClipRect_OpType: return "ClipRect"; @@ -208,6 +209,7 @@ const char* SkDrawCommand::GetCommandString(OpType type) { case kDrawTextRSXform_OpType: return "DrawTextRSXform"; case kDrawVertices_OpType: return "DrawVertices"; case kEndDrawPicture_OpType: return "EndDrawPicture"; + case kEndDrawShadowedPicture_OpType: return "EndDrawShadowedPicture"; case kRestore_OpType: return "Restore"; case kSave_OpType: return "Save"; case kSaveLayer_OpType: return "SaveLayer"; @@ -270,8 +272,9 @@ 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); @@ -1491,10 +1494,13 @@ 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(); @@ -2381,6 +2387,68 @@ void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const { } } +SkBeginDrawShadowedPictureCommand::SkBeginDrawShadowedPictureCommand(const SkPicture* picture, + const SkMatrix* matrix, + const SkPaint* paint) + : INHERITED(kBeginDrawShadowedPicture_OpType) + , fPicture(SkRef(picture)) { + + SkString* str = new SkString; + str->appendf("SkPicture: L: %f T: %f R: %f B: %f", + picture->cullRect().fLeft, picture->cullRect().fTop, + picture->cullRect().fRight, picture->cullRect().fBottom); + fInfo.push(str); + + if (matrix) { + fMatrix.set(*matrix); + fInfo.push(SkObjectParser::MatrixToString(*matrix)); + } + + if (paint) { + fPaint.set(*paint); + fInfo.push(SkObjectParser::PaintToString(*paint)); + } +} + +void SkBeginDrawShadowedPictureCommand::execute(SkCanvas* canvas) const { + if (fPaint.isValid()) { + SkRect bounds = fPicture->cullRect(); + if (fMatrix.isValid()) { + fMatrix.get()->mapRect(&bounds); + } + canvas->saveLayer(&bounds, fPaint.get()); + } + + if (fMatrix.isValid()) { + if (!fPaint.isValid()) { + canvas->save(); + } + canvas->concat(*fMatrix.get()); + } +} + +bool SkBeginDrawShadowedPictureCommand::render(SkCanvas* canvas) const { + canvas->clear(0xFFFFFFFF); + canvas->save(); + + xlate_and_scale_to_bounds(canvas, fPicture->cullRect()); + + canvas->drawPicture(fPicture.get()); + + canvas->restore(); + + return true; +} + +SkEndDrawShadowedPictureCommand::SkEndDrawShadowedPictureCommand(bool restore) + : INHERITED(kEndDrawShadowedPicture_OpType) , fRestore(restore) { } + +void SkEndDrawShadowedPictureCommand::execute(SkCanvas* canvas) const { + if (fRestore) { + canvas->restore(); + } +} + SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) : INHERITED(kDrawPoints_OpType) { @@ -3317,7 +3385,9 @@ SkTranslateZCommand::SkTranslateZCommand(SkScalar z) } void SkTranslateZCommand::execute(SkCanvas* canvas) const { +#ifdef SK_EXPERIMENTAL_SHADOWING canvas->translateZ(fZTranslate); +#endif } Json::Value SkTranslateZCommand::toJSON(UrlDataManager& urlDataManager) const { @@ -3329,6 +3399,10 @@ Json::Value SkTranslateZCommand::toJSON(UrlDataManager& urlDataManager) const { 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); } diff --git a/tools/debugger/SkDrawCommand.h b/tools/debugger/SkDrawCommand.h index a7e6c73802..14a7af5882 100644 --- a/tools/debugger/SkDrawCommand.h +++ b/tools/debugger/SkDrawCommand.h @@ -24,6 +24,7 @@ class SK_API SkDrawCommand { public: enum OpType { kBeginDrawPicture_OpType, + kBeginDrawShadowedPicture_OpType, kClipPath_OpType, kClipRegion_OpType, kClipRect_OpType, @@ -52,6 +53,7 @@ public: kDrawTextRSXform_OpType, kDrawVertices_OpType, kEndDrawPicture_OpType, + kEndDrawShadowedPicture_OpType, kRestore_OpType, kSave_OpType, kSaveLayer_OpType, @@ -455,6 +457,35 @@ private: typedef SkDrawCommand INHERITED; }; +class SkBeginDrawShadowedPictureCommand : public SkDrawCommand { +public: + SkBeginDrawShadowedPictureCommand(const SkPicture* picture, + const SkMatrix* matrix, + const SkPaint* paint); + + void execute(SkCanvas* canvas) const override; + bool render(SkCanvas* canvas) const override; + +private: + SkAutoTUnref<const SkPicture> fPicture; + SkTLazy<SkMatrix> fMatrix; + SkTLazy<SkPaint> fPaint; + + typedef SkDrawCommand INHERITED; +}; + +class SkEndDrawShadowedPictureCommand : public SkDrawCommand { +public: + SkEndDrawShadowedPictureCommand(bool restore); + + void execute(SkCanvas* canvas) const override; + +private: + bool fRestore; + + typedef SkDrawCommand INHERITED; +}; + class SkDrawPointsCommand : public SkDrawCommand { public: SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], |