diff options
author | Derek Sollenberger <djsollen@google.com> | 2018-04-12 12:45:58 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-04-12 17:21:10 +0000 |
commit | 6aab2ab762beb0d255529a914e181e927a8e6307 (patch) | |
tree | 19b1157d4574ac58271f8fbd9d5af04b8e4c971a /tools | |
parent | 9438790b66fd2193a47971f66c44f7cec80a795a (diff) |
Include shadow ops in the debugger.
Bug: skia:7803
Change-Id: Ic4441e696a56b898e5095f747ab1b9a9c0e0f858
Reviewed-on: https://skia-review.googlesource.com/121100
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/debugger/SkDebugCanvas.cpp | 4 | ||||
-rw-r--r-- | tools/debugger/SkDebugCanvas.h | 1 | ||||
-rw-r--r-- | tools/debugger/SkDrawCommand.cpp | 97 | ||||
-rw-r--r-- | tools/debugger/SkDrawCommand.h | 18 |
4 files changed, 119 insertions, 1 deletions
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp index 156f957de3..67f4bd3dc9 100644 --- a/tools/debugger/SkDebugCanvas.cpp +++ b/tools/debugger/SkDebugCanvas.cpp @@ -468,6 +468,10 @@ void SkDebugCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode, paint)); } +void SkDebugCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { + this->addDrawCommand(new SkDrawShadowCommand(path, rec)); +} + void SkDebugCanvas::willRestore() { this->addDrawCommand(new SkRestoreCommand()); this->INHERITED::willRestore(); diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h index 2a3dcbbf49..66c46811d4 100644 --- a/tools/debugger/SkDebugCanvas.h +++ b/tools/debugger/SkDebugCanvas.h @@ -164,6 +164,7 @@ protected: void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; void onClipRegion(const SkRegion& region, SkClipOp) override; + void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 27a2765404..9aab347fdb 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -28,6 +28,7 @@ #include "picture_utils.h" #include "SkClipOpPriv.h" #include <SkLatticeIter.h> +#include <SkShadowFlags.h> #define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command" #define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible" @@ -120,6 +121,11 @@ #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEXDIVS "xDivs" #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEYDIVS "yDivs" #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEFLAGS "flags" +#define SKDEBUGCANVAS_ATTRIBUTE_ZPLANE "zPlane" +#define SKDEBUGCANVAS_ATTRIBUTE_LIGHTPOSITION "lightPositions" +#define SKDEBUGCANVAS_ATTRIBUTE_AMBIENTCOLOR "ambientColor" +#define SKDEBUGCANVAS_ATTRIBUTE_SPOTCOLOR "spotColor" +#define SKDEBUGCANVAS_ATTRIBUTE_LIGHTRADIUS "lightRadius" #define SKDEBUGCANVAS_VERB_MOVE "move" #define SKDEBUGCANVAS_VERB_LINE "line" @@ -191,6 +197,9 @@ #define SKDEBUGCANVAS_HINTING_NORMAL "normal" #define SKDEBUGCANVAS_HINTING_FULL "full" +#define SKDEBUGCANVAS_SHADOWFLAG_TRANSPARENT_OCC "transparentOccluder" +#define SKDEBUGCANVAS_SHADOWFLAG_GEOMETRIC_ONLY "geometricOnly" + typedef SkDrawCommand* (*FROM_JSON)(Json::Value&, UrlDataManager&); static SkString* str_append(SkString* str, const SkRect& r) { @@ -234,6 +243,7 @@ const char* SkDrawCommand::GetCommandString(OpType type) { case kDrawRect_OpType: return "DrawRect"; case kDrawRRect_OpType: return "DrawRRect"; case kDrawRegion_OpType: return "DrawRegion"; + case kDrawShadow_OpType: return "DrawShadow"; case kDrawText_OpType: return "DrawText"; case kDrawTextBlob_OpType: return "DrawTextBlob"; case kDrawTextOnPath_OpType: return "DrawTextOnPath"; @@ -294,7 +304,7 @@ SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& url INSTALL_FACTORY(DrawTextOnPath); INSTALL_FACTORY(DrawTextRSXform); INSTALL_FACTORY(DrawTextBlob); - + INSTALL_FACTORY(DrawShadow); INSTALL_FACTORY(DrawRect); INSTALL_FACTORY(DrawRRect); INSTALL_FACTORY(DrawDRRect); @@ -449,6 +459,22 @@ void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) canvas->restore(); } +void render_shadow(SkCanvas* canvas, const SkPath& path, SkDrawShadowRec rec) { + canvas->clear(0xFFFFFFFF); + + const SkRect& bounds = path.getBounds(); + if (bounds.isEmpty()) { + return; + } + + SkAutoCanvasRestore acr(canvas, true); + xlate_and_scale_to_bounds(canvas, bounds); + + rec.fAmbientColor = SK_ColorBLACK; + rec.fSpotColor = SK_ColorBLACK; + canvas->private_draw_shadow_rec(path, rec); +} + static const char* const gBlendModeMap[] = { "clear", "src", @@ -545,6 +571,14 @@ Json::Value SkDrawCommand::MakeJsonPoint(SkScalar x, SkScalar y) { return result; } +Json::Value SkDrawCommand::MakeJsonPoint3(const SkPoint3& point) { + Json::Value result(Json::arrayValue); + result.append(Json::Value(point.x())); + result.append(Json::Value(point.y())); + result.append(Json::Value(point.z())); + return result; +} + Json::Value SkDrawCommand::MakeJsonRect(const SkRect& rect) { Json::Value result(Json::arrayValue); result.append(Json::Value(rect.left())); @@ -1299,6 +1333,10 @@ static SkPoint get_json_point(Json::Value point) { return SkPoint::Make(point[0].asFloat(), point[1].asFloat()); } +static SkPoint3 get_json_point3(Json::Value point) { + return SkPoint3::Make(point[0].asFloat(), point[1].asFloat(), point[2].asFloat()); +} + static SkColor get_json_color(Json::Value color) { return SkColorSetARGB(color[0].asInt(), color[1].asInt(), color[2].asInt(), color[3].asInt()); } @@ -3214,6 +3252,63 @@ SkDrawDRRectCommand* SkDrawDRRectCommand::fromJSON(Json::Value& command, return new SkDrawDRRectCommand(outer, inner, paint); } +SkDrawShadowCommand::SkDrawShadowCommand(const SkPath& path, const SkDrawShadowRec& rec) + : INHERITED(kDrawShadow_OpType) { + fPath = path; + fShadowRec = rec; +} + +void SkDrawShadowCommand::execute(SkCanvas* canvas) const { + canvas->private_draw_shadow_rec(fPath, fShadowRec); +} + +bool SkDrawShadowCommand::render(SkCanvas* canvas) const { + render_shadow(canvas, fPath, fShadowRec); + return true; +} + +Json::Value SkDrawShadowCommand::toJSON(UrlDataManager& urlDataManager) const { + Json::Value result = INHERITED::toJSON(urlDataManager); + result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = MakeJsonPath(fPath); + + bool geometricOnly = SkToBool(fShadowRec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag); + bool transparentOccluder = + SkToBool(fShadowRec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); + + result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = MakeJsonPath(fPath); + result[SKDEBUGCANVAS_ATTRIBUTE_ZPLANE] = MakeJsonPoint3(fShadowRec.fZPlaneParams); + result[SKDEBUGCANVAS_ATTRIBUTE_LIGHTPOSITION] = MakeJsonPoint3(fShadowRec.fLightPos); + result[SKDEBUGCANVAS_ATTRIBUTE_LIGHTRADIUS] = MakeJsonScalar(fShadowRec.fLightRadius); + result[SKDEBUGCANVAS_ATTRIBUTE_AMBIENTCOLOR] = MakeJsonColor(fShadowRec.fAmbientColor); + result[SKDEBUGCANVAS_ATTRIBUTE_SPOTCOLOR] = MakeJsonColor(fShadowRec.fSpotColor); + store_bool(&result, SKDEBUGCANVAS_SHADOWFLAG_TRANSPARENT_OCC, transparentOccluder, false); + store_bool(&result, SKDEBUGCANVAS_SHADOWFLAG_GEOMETRIC_ONLY, geometricOnly, false); + return result; +} + +SkDrawShadowCommand* SkDrawShadowCommand::fromJSON(Json::Value& command, + UrlDataManager& urlDataManager) { + SkPath path; + extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); + SkDrawShadowRec rec; + rec.fZPlaneParams = get_json_point3(command[SKDEBUGCANVAS_ATTRIBUTE_ZPLANE]); + rec.fLightPos = get_json_point3(command[SKDEBUGCANVAS_ATTRIBUTE_LIGHTPOSITION]); + rec.fLightRadius = command[SKDEBUGCANVAS_ATTRIBUTE_LIGHTRADIUS].asFloat(); + rec.fAmbientColor = get_json_color(command[SKDEBUGCANVAS_ATTRIBUTE_AMBIENTCOLOR]); + rec.fSpotColor = get_json_color(command[SKDEBUGCANVAS_ATTRIBUTE_SPOTCOLOR]); + + rec.fFlags = SkShadowFlags::kNone_ShadowFlag; + if (command.isMember(SKDEBUGCANVAS_SHADOWFLAG_TRANSPARENT_OCC) + && command[SKDEBUGCANVAS_SHADOWFLAG_TRANSPARENT_OCC].asBool()) { + rec.fFlags |= SkShadowFlags::kTransparentOccluder_ShadowFlag; + } + if (command.isMember(SKDEBUGCANVAS_SHADOWFLAG_GEOMETRIC_ONLY) + && command[SKDEBUGCANVAS_SHADOWFLAG_GEOMETRIC_ONLY].asBool()) { + rec.fFlags |= SkShadowFlags::kGeometricOnly_ShadowFlag; + } + return new SkDrawShadowCommand(path, rec); +} + SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) : INHERITED(kDrawText_OpType) { diff --git a/tools/debugger/SkDrawCommand.h b/tools/debugger/SkDrawCommand.h index 64830a48c7..257029c913 100644 --- a/tools/debugger/SkDrawCommand.h +++ b/tools/debugger/SkDrawCommand.h @@ -10,6 +10,7 @@ #include "SkBitmap.h" #include "SkCanvas.h" +#include "SkDrawShadowInfo.h" #include "SkFlattenable.h" #include "SkTLazy.h" #include "SkPath.h" @@ -52,6 +53,7 @@ public: kDrawRect_OpType, kDrawRRect_OpType, kDrawRegion_OpType, + kDrawShadow_OpType, kDrawText_OpType, kDrawTextBlob_OpType, kDrawTextOnPath_OpType, @@ -102,6 +104,7 @@ public: static Json::Value MakeJsonColor4f(const SkColor4f& color); static Json::Value MakeJsonPoint(const SkPoint& point); static Json::Value MakeJsonPoint(SkScalar x, SkScalar y); + static Json::Value MakeJsonPoint3(const SkPoint3& point); static Json::Value MakeJsonRect(const SkRect& rect); static Json::Value MakeJsonIRect(const SkIRect&); static Json::Value MakeJsonMatrix(const SkMatrix&); @@ -761,5 +764,20 @@ private: typedef SkDrawCommand INHERITED; }; + +class SkDrawShadowCommand : public SkDrawCommand { +public: + SkDrawShadowCommand(const SkPath& path, const SkDrawShadowRec& rec); + void execute(SkCanvas* canvas) const override; + bool render(SkCanvas* canvas) const override; + Json::Value toJSON(UrlDataManager& urlDataManager) const override; + static SkDrawShadowCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); + +private: + SkPath fPath; + SkDrawShadowRec fShadowRec; + + typedef SkDrawCommand INHERITED; +}; #endif |