1 /* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_LOGGING_CANVAS_H_ 32 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_LOGGING_CANVAS_H_ 33 34 #include <memory> 35 #include "third_party/blink/renderer/platform/graphics/intercepting_canvas.h" 36 #include "third_party/blink/renderer/platform/json/json_values.h" 37 38 namespace blink { 39 40 class LoggingCanvas : public InterceptingCanvasBase { 41 public: 42 LoggingCanvas(); 43 44 // Returns a snapshot of the current log data. 45 std::unique_ptr<JSONArray> Log(); 46 47 void onDrawPaint(const SkPaint&) override; 48 void onDrawPoints(PointMode, 49 size_t count, 50 const SkPoint pts[], 51 const SkPaint&) override; 52 void onDrawRect(const SkRect&, const SkPaint&) override; 53 void onDrawOval(const SkRect&, const SkPaint&) override; 54 void onDrawRRect(const SkRRect&, const SkPaint&) override; 55 void onDrawPath(const SkPath&, const SkPaint&) override; 56 void onDrawImage(const SkImage*, SkScalar, SkScalar, const SkPaint*) override; 57 void onDrawImageRect(const SkImage*, 58 const SkRect* src, 59 const SkRect& dst, 60 const SkPaint*, 61 SrcRectConstraint) override; 62 void onDrawVerticesObject(const SkVertices*, 63 SkBlendMode bmode, 64 const SkPaint&) override; 65 66 void onDrawDRRect(const SkRRect& outer, 67 const SkRRect& inner, 68 const SkPaint&) override; 69 void onDrawTextBlob(const SkTextBlob*, 70 SkScalar x, 71 SkScalar y, 72 const SkPaint&) override; 73 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; 74 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; 75 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; 76 void onClipRegion(const SkRegion&, SkClipOp) override; 77 void onDrawPicture(const SkPicture*, 78 const SkMatrix*, 79 const SkPaint*) override; 80 void didSetMatrix(const SkMatrix&) override; 81 void didConcat44(const SkScalar[16]) override; 82 void didConcat(const SkMatrix&) override; 83 void didScale(SkScalar, SkScalar) override; 84 void didTranslate(SkScalar, SkScalar) override; 85 void willSave() override; 86 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; 87 void willRestore() override; 88 89 private: 90 friend class AutoLogger; 91 92 std::unique_ptr<JSONArray> log_; 93 }; 94 95 PLATFORM_EXPORT std::unique_ptr<JSONArray> RecordAsJSON(const PaintRecord&); 96 PLATFORM_EXPORT String RecordAsDebugString(const PaintRecord&); 97 PLATFORM_EXPORT void ShowPaintRecord(const PaintRecord&); 98 PLATFORM_EXPORT std::unique_ptr<JSONArray> SkPictureAsJSON(const SkPicture&); 99 PLATFORM_EXPORT String SkPictureAsDebugString(const SkPicture&); 100 PLATFORM_EXPORT void ShowSkPicture(const SkPicture&); 101 102 } // namespace blink 103 104 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_LOGGING_CANVAS_H_ 105