| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef TESTING_DISPLAY_LIST_TESTING_H_ |
| 6 | #define TESTING_DISPLAY_LIST_TESTING_H_ |
| 7 | |
| 8 | #include <ostream> |
| 9 | |
| 10 | #include "flutter/display_list/display_list.h" |
| 11 | #include "flutter/display_list/dl_op_receiver.h" |
| 12 | |
| 13 | namespace flutter { |
| 14 | namespace testing { |
| 15 | |
| 16 | bool DisplayListsEQ_Verbose(const DisplayList* a, const DisplayList* b); |
| 17 | bool inline DisplayListsEQ_Verbose(const DisplayList& a, const DisplayList& b) { |
| 18 | return DisplayListsEQ_Verbose(a: &a, b: &b); |
| 19 | } |
| 20 | bool inline DisplayListsEQ_Verbose(sk_sp<const DisplayList> a, |
| 21 | sk_sp<const DisplayList> b) { |
| 22 | return DisplayListsEQ_Verbose(a: a.get(), b: b.get()); |
| 23 | } |
| 24 | bool DisplayListsNE_Verbose(const DisplayList* a, const DisplayList* b); |
| 25 | bool inline DisplayListsNE_Verbose(const DisplayList& a, const DisplayList& b) { |
| 26 | return DisplayListsNE_Verbose(a: &a, b: &b); |
| 27 | } |
| 28 | bool inline DisplayListsNE_Verbose(sk_sp<const DisplayList> a, |
| 29 | sk_sp<const DisplayList> b) { |
| 30 | return DisplayListsNE_Verbose(a: a.get(), b: b.get()); |
| 31 | } |
| 32 | |
| 33 | extern std::ostream& operator<<(std::ostream& os, |
| 34 | const DisplayList& display_list); |
| 35 | extern std::ostream& operator<<(std::ostream& os, const DlPaint& paint); |
| 36 | extern std::ostream& operator<<(std::ostream& os, const DlBlendMode& mode); |
| 37 | extern std::ostream& operator<<(std::ostream& os, const DlCanvas::ClipOp& op); |
| 38 | extern std::ostream& operator<<(std::ostream& os, |
| 39 | const DlCanvas::PointMode& op); |
| 40 | extern std::ostream& operator<<(std::ostream& os, |
| 41 | const DlCanvas::SrcRectConstraint& op); |
| 42 | extern std::ostream& operator<<(std::ostream& os, const DlStrokeCap& cap); |
| 43 | extern std::ostream& operator<<(std::ostream& os, const DlStrokeJoin& join); |
| 44 | extern std::ostream& operator<<(std::ostream& os, const DlDrawStyle& style); |
| 45 | extern std::ostream& operator<<(std::ostream& os, const DlBlurStyle& style); |
| 46 | extern std::ostream& operator<<(std::ostream& os, const DlFilterMode& mode); |
| 47 | extern std::ostream& operator<<(std::ostream& os, const DlColor& color); |
| 48 | extern std::ostream& operator<<(std::ostream& os, DlImageSampling sampling); |
| 49 | extern std::ostream& operator<<(std::ostream& os, const DlVertexMode& mode); |
| 50 | extern std::ostream& operator<<(std::ostream& os, const DlTileMode& mode); |
| 51 | extern std::ostream& operator<<(std::ostream& os, const DlImage* image); |
| 52 | |
| 53 | class DisplayListStreamDispatcher final : public DlOpReceiver { |
| 54 | public: |
| 55 | DisplayListStreamDispatcher(std::ostream& os, |
| 56 | int cur_indent = 2, |
| 57 | int indent = 2) |
| 58 | : os_(os), cur_indent_(cur_indent), indent_(indent) {} |
| 59 | |
| 60 | void setAntiAlias(bool aa) override; |
| 61 | void setDither(bool dither) override; |
| 62 | void setDrawStyle(DlDrawStyle style) override; |
| 63 | void setColor(DlColor color) override; |
| 64 | void setStrokeWidth(SkScalar width) override; |
| 65 | void setStrokeMiter(SkScalar limit) override; |
| 66 | void setStrokeCap(DlStrokeCap cap) override; |
| 67 | void setStrokeJoin(DlStrokeJoin join) override; |
| 68 | void setColorSource(const DlColorSource* source) override; |
| 69 | void setColorFilter(const DlColorFilter* filter) override; |
| 70 | void setInvertColors(bool invert) override; |
| 71 | void setBlendMode(DlBlendMode mode) override; |
| 72 | void setPathEffect(const DlPathEffect* effect) override; |
| 73 | void setMaskFilter(const DlMaskFilter* filter) override; |
| 74 | void setImageFilter(const DlImageFilter* filter) override; |
| 75 | |
| 76 | void save() override; |
| 77 | void saveLayer(const SkRect* bounds, |
| 78 | const SaveLayerOptions options, |
| 79 | const DlImageFilter* backdrop) override; |
| 80 | void restore() override; |
| 81 | |
| 82 | void translate(SkScalar tx, SkScalar ty) override; |
| 83 | void scale(SkScalar sx, SkScalar sy) override; |
| 84 | void rotate(SkScalar degrees) override; |
| 85 | void skew(SkScalar sx, SkScalar sy) override; |
| 86 | // clang-format off |
| 87 | void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, |
| 88 | SkScalar myx, SkScalar myy, SkScalar myt) override; |
| 89 | void transformFullPerspective( |
| 90 | SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, |
| 91 | SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, |
| 92 | SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, |
| 93 | SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override; |
| 94 | // clang-format on |
| 95 | void transformReset() override; |
| 96 | |
| 97 | void clipRect(const SkRect& rect, ClipOp clip_op, bool is_aa) override; |
| 98 | void clipRRect(const SkRRect& rrect, ClipOp clip_op, bool is_aa) override; |
| 99 | void clipPath(const SkPath& path, ClipOp clip_op, bool is_aa) override; |
| 100 | |
| 101 | void drawColor(DlColor color, DlBlendMode mode) override; |
| 102 | void drawPaint() override; |
| 103 | void drawLine(const SkPoint& p0, const SkPoint& p1) override; |
| 104 | void drawRect(const SkRect& rect) override; |
| 105 | void drawOval(const SkRect& bounds) override; |
| 106 | void drawCircle(const SkPoint& center, SkScalar radius) override; |
| 107 | void drawRRect(const SkRRect& rrect) override; |
| 108 | void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; |
| 109 | void drawPath(const SkPath& path) override; |
| 110 | void drawArc(const SkRect& oval_bounds, |
| 111 | SkScalar start_degrees, |
| 112 | SkScalar sweep_degrees, |
| 113 | bool use_center) override; |
| 114 | void drawPoints(PointMode mode, |
| 115 | uint32_t count, |
| 116 | const SkPoint points[]) override; |
| 117 | void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; |
| 118 | void drawImage(const sk_sp<DlImage> image, |
| 119 | const SkPoint point, |
| 120 | DlImageSampling sampling, |
| 121 | bool render_with_attributes) override; |
| 122 | void drawImageRect(const sk_sp<DlImage> image, |
| 123 | const SkRect& src, |
| 124 | const SkRect& dst, |
| 125 | DlImageSampling sampling, |
| 126 | bool render_with_attributes, |
| 127 | SrcRectConstraint constraint) override; |
| 128 | void drawImageNine(const sk_sp<DlImage> image, |
| 129 | const SkIRect& center, |
| 130 | const SkRect& dst, |
| 131 | DlFilterMode filter, |
| 132 | bool render_with_attributes) override; |
| 133 | void drawAtlas(const sk_sp<DlImage> atlas, |
| 134 | const SkRSXform xform[], |
| 135 | const SkRect tex[], |
| 136 | const DlColor colors[], |
| 137 | int count, |
| 138 | DlBlendMode mode, |
| 139 | DlImageSampling sampling, |
| 140 | const SkRect* cull_rect, |
| 141 | bool render_with_attributes) override; |
| 142 | void drawDisplayList(const sk_sp<DisplayList> display_list, |
| 143 | SkScalar opacity) override; |
| 144 | void drawTextBlob(const sk_sp<SkTextBlob> blob, |
| 145 | SkScalar x, |
| 146 | SkScalar y) override; |
| 147 | void drawShadow(const SkPath& path, |
| 148 | const DlColor color, |
| 149 | const SkScalar elevation, |
| 150 | bool transparent_occluder, |
| 151 | SkScalar dpr) override; |
| 152 | |
| 153 | private: |
| 154 | std::ostream& os_; |
| 155 | int cur_indent_; |
| 156 | int indent_; |
| 157 | |
| 158 | void indent() { indent(spaces: indent_); } |
| 159 | void outdent() { outdent(spaces: indent_); } |
| 160 | void indent(int spaces) { cur_indent_ += spaces; } |
| 161 | void outdent(int spaces) { cur_indent_ -= spaces; } |
| 162 | |
| 163 | template <class T> |
| 164 | std::ostream& out_array(std::string name, int count, const T array[]); |
| 165 | |
| 166 | std::ostream& startl(); |
| 167 | |
| 168 | void out(const DlColorFilter& filter); |
| 169 | void out(const DlColorFilter* filter); |
| 170 | void out(const DlImageFilter& filter); |
| 171 | void out(const DlImageFilter* filter); |
| 172 | }; |
| 173 | |
| 174 | } // namespace testing |
| 175 | } // namespace flutter |
| 176 | |
| 177 | #endif // TESTING_DISPLAY_LIST_TESTING_H_ |
| 178 | |