Flutter Impeller
uber_sdf_contents.h
Go to the documentation of this file.
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_IMPELLER_ENTITY_CONTENTS_UBER_SDF_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_UBER_SDF_CONTENTS_H_
7 
8 #include <memory>
9 
16 #include "impeller/geometry/rect.h"
17 
18 namespace impeller {
19 
21  public:
22  enum class Type {
23  kCircle,
24  kRect,
25  };
26 
27  static std::unique_ptr<UberSDFContents> MakeRect(
28  Color color,
29  Scalar stroke_width,
30  Join stroke_join,
31  bool stroked,
32  const FillRectGeometry* geometry);
33 
34  static std::unique_ptr<UberSDFContents>
35  MakeCircle(Color color, bool stroked, const CircleGeometry* geometry);
36 
37  UberSDFContents(Type type,
38  Rect rect,
39  Color color,
40  Scalar stroke_width,
41  Join stroke_join,
42  bool stroked,
43  const Geometry* geometry,
44  Scalar aa_padding);
45 
46  ~UberSDFContents() override;
47 
48  bool Render(const ContentContext& renderer,
49  const Entity& entity,
50  RenderPass& pass) const override;
51 
52  std::optional<Rect> GetCoverage(const Entity& entity) const override;
53 
54  Color GetColor() const;
55 
56  bool ApplyColorFilter(const ColorFilterProc& color_filter_proc) override;
57 
58  const Geometry* GetGeometry() const override;
59 
60  private:
61  /// The type of geometry (e.g. circle, rect).
62  const Type type_;
63  /// The bounding box of the geometry.
64  Rect bounding_box_;
65  /// The color of the geometry.
66  Color color_;
67  /// The width of the stroke.
68  Scalar stroke_width_ = 0.0f;
69  /// The join of the stroke.
70  Join stroke_join_ = Join::kMiter;
71  /// Whether the geometry is stroked.
72  bool stroked_ = false;
73  /// The geometry.
74  const Geometry* geometry_;
75  /// The antialias padding.
76  Scalar aa_padding_;
77 
78  UberSDFContents(const UberSDFContents&) = delete;
79 
80  UberSDFContents& operator=(const UberSDFContents&) = delete;
81 };
82 
83 } // namespace impeller
84 
85 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_UBER_SDF_CONTENTS_H_
std::function< Color(Color)> ColorFilterProc
Definition: contents.h:35
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
static std::unique_ptr< UberSDFContents > MakeRect(Color color, Scalar stroke_width, Join stroke_join, bool stroked, const FillRectGeometry *geometry)
UberSDFContents(Type type, Rect rect, Color color, Scalar stroke_width, Join stroke_join, bool stroked, const Geometry *geometry, Scalar aa_padding)
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
bool ApplyColorFilter(const ColorFilterProc &color_filter_proc) override
If possible, applies a color filter to this contents inputs on the CPU.
static std::unique_ptr< UberSDFContents > MakeCircle(Color color, bool stroked, const CircleGeometry *geometry)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Join
An enum that describes ways to join two segments of a path.
float Scalar
Definition: scalar.h:19