| 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 | #include "flutter/shell/common/dl_op_spy.h" |
| 6 | |
| 7 | namespace flutter { |
| 8 | |
| 9 | bool DlOpSpy::did_draw() { |
| 10 | return did_draw_; |
| 11 | } |
| 12 | |
| 13 | void DlOpSpy::setColor(DlColor color) { |
| 14 | if (color.isTransparent()) { |
| 15 | will_draw_ = false; |
| 16 | } else { |
| 17 | will_draw_ = true; |
| 18 | } |
| 19 | } |
| 20 | void DlOpSpy::setColorSource(const DlColorSource* source) { |
| 21 | if (!source) { |
| 22 | return; |
| 23 | } |
| 24 | const DlColorColorSource* color_source = source->asColor(); |
| 25 | if (color_source && color_source->color().isTransparent()) { |
| 26 | will_draw_ = false; |
| 27 | return; |
| 28 | } |
| 29 | will_draw_ = true; |
| 30 | } |
| 31 | void DlOpSpy::save() {} |
| 32 | void DlOpSpy::saveLayer(const SkRect* bounds, |
| 33 | const SaveLayerOptions options, |
| 34 | const DlImageFilter* backdrop) {} |
| 35 | void DlOpSpy::restore() {} |
| 36 | void DlOpSpy::drawColor(DlColor color, DlBlendMode mode) { |
| 37 | did_draw_ |= !color.isTransparent(); |
| 38 | } |
| 39 | void DlOpSpy::drawPaint() { |
| 40 | did_draw_ |= will_draw_; |
| 41 | } |
| 42 | // TODO(cyanglaz): check whether the shape (line, rect, oval, etc) needs to be |
| 43 | // evaluated. https://github.com/flutter/flutter/issues/123803 |
| 44 | void DlOpSpy::drawLine(const SkPoint& p0, const SkPoint& p1) { |
| 45 | did_draw_ |= will_draw_; |
| 46 | } |
| 47 | void DlOpSpy::drawRect(const SkRect& rect) { |
| 48 | did_draw_ |= will_draw_; |
| 49 | } |
| 50 | void DlOpSpy::drawOval(const SkRect& bounds) { |
| 51 | did_draw_ |= will_draw_; |
| 52 | } |
| 53 | void DlOpSpy::drawCircle(const SkPoint& center, SkScalar radius) { |
| 54 | did_draw_ |= will_draw_; |
| 55 | } |
| 56 | void DlOpSpy::drawRRect(const SkRRect& rrect) { |
| 57 | did_draw_ |= will_draw_; |
| 58 | } |
| 59 | void DlOpSpy::drawDRRect(const SkRRect& outer, const SkRRect& inner) { |
| 60 | did_draw_ |= will_draw_; |
| 61 | } |
| 62 | void DlOpSpy::drawPath(const SkPath& path) { |
| 63 | did_draw_ |= will_draw_; |
| 64 | } |
| 65 | void DlOpSpy::drawArc(const SkRect& oval_bounds, |
| 66 | SkScalar start_degrees, |
| 67 | SkScalar sweep_degrees, |
| 68 | bool use_center) { |
| 69 | did_draw_ |= will_draw_; |
| 70 | } |
| 71 | void DlOpSpy::drawPoints(PointMode mode, |
| 72 | uint32_t count, |
| 73 | const SkPoint points[]) { |
| 74 | did_draw_ |= will_draw_; |
| 75 | } |
| 76 | void DlOpSpy::drawVertices(const DlVertices* vertices, DlBlendMode mode) { |
| 77 | did_draw_ |= will_draw_; |
| 78 | } |
| 79 | // In theory, below drawImage methods can produce a transparent screen when a |
| 80 | // transparent image is provided. The operation of determine whether an image is |
| 81 | // transparent needs examine all the pixels in the image object, which is slow. |
| 82 | // Drawing a completely transparent image is not a valid use case, thus, such |
| 83 | // case is ignored. |
| 84 | void DlOpSpy::drawImage(const sk_sp<DlImage> image, |
| 85 | const SkPoint point, |
| 86 | DlImageSampling sampling, |
| 87 | bool render_with_attributes) { |
| 88 | did_draw_ = true; |
| 89 | } |
| 90 | void DlOpSpy::drawImageRect(const sk_sp<DlImage> image, |
| 91 | const SkRect& src, |
| 92 | const SkRect& dst, |
| 93 | DlImageSampling sampling, |
| 94 | bool render_with_attributes, |
| 95 | SrcRectConstraint constraint) { |
| 96 | did_draw_ = true; |
| 97 | } |
| 98 | void DlOpSpy::drawImageNine(const sk_sp<DlImage> image, |
| 99 | const SkIRect& center, |
| 100 | const SkRect& dst, |
| 101 | DlFilterMode filter, |
| 102 | bool render_with_attributes) { |
| 103 | did_draw_ = true; |
| 104 | } |
| 105 | void DlOpSpy::drawAtlas(const sk_sp<DlImage> atlas, |
| 106 | const SkRSXform xform[], |
| 107 | const SkRect tex[], |
| 108 | const DlColor colors[], |
| 109 | int count, |
| 110 | DlBlendMode mode, |
| 111 | DlImageSampling sampling, |
| 112 | const SkRect* cull_rect, |
| 113 | bool render_with_attributes) { |
| 114 | did_draw_ = true; |
| 115 | } |
| 116 | void DlOpSpy::drawDisplayList(const sk_sp<DisplayList> display_list, |
| 117 | SkScalar opacity) { |
| 118 | if (did_draw_ || opacity == 0) { |
| 119 | return; |
| 120 | } |
| 121 | DlOpSpy receiver; |
| 122 | display_list->Dispatch(ctx&: receiver); |
| 123 | did_draw_ |= receiver.did_draw(); |
| 124 | } |
| 125 | void DlOpSpy::drawTextBlob(const sk_sp<SkTextBlob> blob, |
| 126 | SkScalar x, |
| 127 | SkScalar y) { |
| 128 | did_draw_ |= will_draw_; |
| 129 | } |
| 130 | void DlOpSpy::drawShadow(const SkPath& path, |
| 131 | const DlColor color, |
| 132 | const SkScalar elevation, |
| 133 | bool transparent_occluder, |
| 134 | SkScalar dpr) { |
| 135 | did_draw_ |= !color.isTransparent(); |
| 136 | } |
| 137 | |
| 138 | } // namespace flutter |
| 139 | |