| 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 FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_ |
| 6 | #define FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_ |
| 7 | |
| 8 | #include "flutter/display_list/dl_op_receiver.h" |
| 9 | #include "flutter/display_list/utils/dl_receiver_utils.h" |
| 10 | |
| 11 | namespace flutter { |
| 12 | |
| 13 | //------------------------------------------------------------------------------ |
| 14 | /// Receives to drawing commands of a DisplayListBuilder. |
| 15 | /// |
| 16 | /// This is used to determine whether any non-transparent pixels will be drawn |
| 17 | /// on the canvas. |
| 18 | /// All the drawImage operations are considered drawing non-transparent pixels. |
| 19 | /// |
| 20 | /// To use this class, dispatch the operations from DisplayList to a concrete |
| 21 | /// DlOpSpy object, and check the result of `did_draw` method. |
| 22 | /// |
| 23 | /// ``` |
| 24 | /// DlOpSpy dl_op_spy; |
| 25 | /// display_list.Dispatch(dl_op_spy); |
| 26 | /// bool did_draw = dl_op_spy.did_draw() |
| 27 | /// ``` |
| 28 | /// |
| 29 | class DlOpSpy final : public virtual DlOpReceiver, |
| 30 | private IgnoreAttributeDispatchHelper, |
| 31 | private IgnoreClipDispatchHelper, |
| 32 | private IgnoreTransformDispatchHelper { |
| 33 | public: |
| 34 | //---------------------------------------------------------------------------- |
| 35 | /// @brief Returns true if any non transparent content has been drawn. |
| 36 | bool did_draw(); |
| 37 | |
| 38 | private: |
| 39 | void setColor(DlColor color) override; |
| 40 | void setColorSource(const DlColorSource* source) override; |
| 41 | void save() override; |
| 42 | void saveLayer(const SkRect* bounds, |
| 43 | const SaveLayerOptions options, |
| 44 | const DlImageFilter* backdrop) override; |
| 45 | void restore() override; |
| 46 | void drawColor(DlColor color, DlBlendMode mode) override; |
| 47 | void drawPaint() override; |
| 48 | void drawLine(const SkPoint& p0, const SkPoint& p1) override; |
| 49 | void drawRect(const SkRect& rect) override; |
| 50 | void drawOval(const SkRect& bounds) override; |
| 51 | void drawCircle(const SkPoint& center, SkScalar radius) override; |
| 52 | void drawRRect(const SkRRect& rrect) override; |
| 53 | void drawDRRect(const SkRRect& outer, const SkRRect& inner) override; |
| 54 | void drawPath(const SkPath& path) override; |
| 55 | void drawArc(const SkRect& oval_bounds, |
| 56 | SkScalar start_degrees, |
| 57 | SkScalar sweep_degrees, |
| 58 | bool use_center) override; |
| 59 | void drawPoints(PointMode mode, |
| 60 | uint32_t count, |
| 61 | const SkPoint points[]) override; |
| 62 | void drawVertices(const DlVertices* vertices, DlBlendMode mode) override; |
| 63 | void drawImage(const sk_sp<DlImage> image, |
| 64 | const SkPoint point, |
| 65 | DlImageSampling sampling, |
| 66 | bool render_with_attributes) override; |
| 67 | void drawImageRect( |
| 68 | const sk_sp<DlImage> image, |
| 69 | const SkRect& src, |
| 70 | const SkRect& dst, |
| 71 | DlImageSampling sampling, |
| 72 | bool render_with_attributes, |
| 73 | SrcRectConstraint constraint = SrcRectConstraint::kFast) override; |
| 74 | void drawImageNine(const sk_sp<DlImage> image, |
| 75 | const SkIRect& center, |
| 76 | const SkRect& dst, |
| 77 | DlFilterMode filter, |
| 78 | bool render_with_attributes) override; |
| 79 | void drawAtlas(const sk_sp<DlImage> atlas, |
| 80 | const SkRSXform xform[], |
| 81 | const SkRect tex[], |
| 82 | const DlColor colors[], |
| 83 | int count, |
| 84 | DlBlendMode mode, |
| 85 | DlImageSampling sampling, |
| 86 | const SkRect* cull_rect, |
| 87 | bool render_with_attributes) override; |
| 88 | void drawDisplayList(const sk_sp<DisplayList> display_list, |
| 89 | SkScalar opacity = SK_Scalar1) override; |
| 90 | void drawTextBlob(const sk_sp<SkTextBlob> blob, |
| 91 | SkScalar x, |
| 92 | SkScalar y) override; |
| 93 | void drawShadow(const SkPath& path, |
| 94 | const DlColor color, |
| 95 | const SkScalar elevation, |
| 96 | bool transparent_occluder, |
| 97 | SkScalar dpr) override; |
| 98 | |
| 99 | // Indicates if the attributes are set to values that will modify the |
| 100 | // destination. For now, the test only checks if there is a non-transparent |
| 101 | // color set. |
| 102 | bool will_draw_ = true; |
| 103 | |
| 104 | bool did_draw_ = false; |
| 105 | }; |
| 106 | |
| 107 | } // namespace flutter |
| 108 | |
| 109 | #endif // FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_ |
| 110 | |