#include <color_source_contents.h>
Public Types | |
using | BindFragmentCallback = std::function< bool(RenderPass &pass)> |
using | PipelineBuilderCallback = std::function< PipelineRef(ContentContextOptions)> |
using | CreateGeometryCallback = std::function< GeometryResult(const ContentContext &renderer, const Entity &entity, RenderPass &pass, const Geometry *geom)> |
![]() | |
using | ColorFilterProc = std::function< Color(Color)> |
using | RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> |
using | CoverageProc = std::function< std::optional< Rect >(const Entity &entity)> |
Public Member Functions | |
ColorSourceContents () | |
~ColorSourceContents () override | |
void | SetGeometry (const Geometry *geometry) |
Set the geometry that this contents will use to render. More... | |
const Geometry * | GetGeometry () const |
Get the geometry that this contents will use to render. More... | |
void | SetEffectTransform (Matrix matrix) |
Set the effect transform for this color source. More... | |
const Matrix & | GetInverseEffectTransform () const |
Set the inverted effect transform for this color source. More... | |
void | SetOpacityFactor (Scalar opacity) |
Set the opacity factor for this color source. More... | |
Scalar | GetOpacityFactor () const |
Get the opacity factor for this color source. More... | |
virtual bool | IsSolidColor () const |
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. More... | |
void | SetInheritedOpacity (Scalar opacity) override |
Inherit the provided opacity. More... | |
![]() | |
Contents () | |
virtual | ~Contents () |
virtual bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0 |
void | SetCoverageHint (std::optional< Rect > coverage_hint) |
Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of GetCoverage() . More... | |
const std::optional< Rect > & | GetCoverageHint () const |
virtual bool | IsOpaque (const Matrix &transform) const |
Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity. More... | |
virtual std::optional< Snapshot > | RenderToSnapshot (const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, std::string_view label="Snapshot") const |
Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of GetCoverage(entity) . More... | |
std::optional< Size > | GetColorSourceSize () const |
Return the color source's intrinsic size, if available. More... | |
void | SetColorSourceSize (Size size) |
virtual std::optional< Color > | AsBackgroundColor (const Entity &entity, ISize target_size) const |
Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation. More... | |
virtual bool | ApplyColorFilter (const ColorFilterProc &color_filter_proc) |
If possible, applies a color filter to this contents inputs on the CPU. More... | |
Static Public Member Functions | |
template<typename VertexShaderT > | |
static bool | DrawGeometry (const Contents *contents, const Geometry *geometry, const ContentContext &renderer, const Entity &entity, RenderPass &pass, const PipelineBuilderCallback &pipeline_callback, typename VertexShaderT::FrameInfo frame_info, const BindFragmentCallback &bind_fragment_callback, bool force_stencil=false, const CreateGeometryCallback &create_geom_callback=DefaultCreateGeometryCallback) |
![]() | |
static std::shared_ptr< Contents > | MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc) |
Protected Member Functions | |
bool | AppliesAlphaForStrokeCoverage (const Matrix &transform) const |
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverage. More... | |
template<typename VertexShaderT > | |
bool | DrawGeometry (const ContentContext &renderer, const Entity &entity, RenderPass &pass, const PipelineBuilderCallback &pipeline_callback, typename VertexShaderT::FrameInfo frame_info, const BindFragmentCallback &bind_fragment_callback, bool force_stencil=false, const CreateGeometryCallback &create_geom_callback=DefaultCreateGeometryCallback) const |
Static Protected Member Functions | |
static GeometryResult | DefaultCreateGeometryCallback (const ContentContext &renderer, const Entity &entity, RenderPass &pass, const Geometry *geom) |
Color sources are geometry-ignostic Contents
capable of shading any area defined by an impeller::Geometry
. Conceptually, impeller::ColorSourceContents
implement a particular color shading behavior.
This separation of concerns between geometry and color source output allows Impeller to handle most possible draw combinations in a consistent way. For example: There are color sources for handling solid colors, gradients, textures, custom runtime effects, and even 3D scenes.
There are some special rendering exceptions that deviate from this pattern and cross geometry and color source concerns, such as text atlas and image atlas rendering. Special Contents
exist for rendering these behaviors which don't implement ColorSourceContents
.
impeller::Geometry
Definition at line 38 of file color_source_contents.h.
using impeller::ColorSourceContents::BindFragmentCallback = std::function<bool(RenderPass& pass)> |
Definition at line 40 of file color_source_contents.h.
using impeller::ColorSourceContents::CreateGeometryCallback = std::function<GeometryResult(const ContentContext& renderer, const Entity& entity, RenderPass& pass, const Geometry* geom)> |
Definition at line 43 of file color_source_contents.h.
using impeller::ColorSourceContents::PipelineBuilderCallback = std::function<PipelineRef(ContentContextOptions)> |
Definition at line 41 of file color_source_contents.h.
|
default |
|
overridedefault |
|
protected |
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverage.
Definition at line 53 of file color_source_contents.cc.
References impeller::Geometry::ComputeAlphaCoverage(), GetGeometry(), and transform.
Referenced by impeller::LinearGradientContents::IsOpaque(), impeller::RadialGradientContents::IsOpaque(), impeller::SolidColorContents::IsOpaque(), impeller::SweepGradientContents::IsOpaque(), and impeller::TiledTextureContents::IsOpaque().
|
inlinestaticprotected |
Definition at line 259 of file color_source_contents.h.
References impeller::Geometry::GetPositionBuffer().
|
inlineprotected |
|
inlinestatic |
Stencil preparation draw.
Cover draw.
Definition at line 113 of file color_source_contents.h.
References impeller::RenderPass::Draw(), impeller::HostBuffer::EmplaceUniform(), impeller::Entity::GetBlendMode(), impeller::Entity::GetClipDepth(), impeller::ContentContext::GetClipPipeline(), impeller::Contents::GetCoverage(), impeller::Geometry::GetCoverage(), impeller::Geometry::GetPositionBuffer(), impeller::Geometry::GetResultMode(), impeller::Entity::GetShaderClipDepth(), impeller::ContentContext::GetTransientsBuffer(), impeller::ContentContextOptions::kCoverCompare, impeller::kDst, impeller::GeometryResult::kEvenOdd, impeller::GeometryResult::kNonZero, impeller::ContentContextOptions::kOverdrawPreventionIncrement, impeller::GeometryResult::kPreventOverdraw, impeller::kSrc, impeller::ContentContextOptions::kStencilEvenOddFill, impeller::ContentContextOptions::kStencilNonZeroFill, impeller::GeometryResult::mode, impeller::OptionsFromPassAndEntity(), impeller::RenderClipRestore(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetStencilReference(), impeller::RenderPass::SetVertexBuffer(), impeller::GeometryResult::transform, impeller::GeometryResult::type, impeller::GeometryResult::vertex_buffer, and impeller::VertexBuffer::vertex_count.
|
overridevirtual |
Get the area of the render pass that will be affected when this contents is rendered.
During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.
std::nullopt
result means that rendering this contents has no effect on the output color. Implements impeller::Contents.
Reimplemented in impeller::SolidColorContents.
Definition at line 44 of file color_source_contents.cc.
References impeller::Geometry::GetCoverage(), and impeller::Entity::GetTransform().
Referenced by impeller::TiledTextureContents::RenderToSnapshot().
const Geometry * impeller::ColorSourceContents::GetGeometry | ( | ) | const |
Get the geometry that this contents will use to render.
Definition at line 20 of file color_source_contents.cc.
Referenced by AppliesAlphaForStrokeCoverage(), impeller::SolidColorContents::AsBackgroundColor(), DrawGeometry(), impeller::SolidColorContents::GetCoverage(), impeller::SolidColorContents::Render(), impeller::TiledTextureContents::Render(), and impeller::TiledTextureContents::RenderToSnapshot().
const Matrix & impeller::ColorSourceContents::GetInverseEffectTransform | ( | ) | const |
Set the inverted effect transform for this color source.
When the effect transform is set via `SetEffectTransform`, the value is inverted upon storage. The reason for this is that most color sources internally use the inverted transform.
SetEffectTransform
.SetEffectTransform
Definition at line 36 of file color_source_contents.cc.
Referenced by impeller::TiledTextureContents::Render(), and impeller::TiledTextureContents::RenderToSnapshot().
Scalar impeller::ColorSourceContents::GetOpacityFactor | ( | ) | const |
Get the opacity factor for this color source.
This value is is factored into the output of the color source in addition to opacity information that may be supplied any other inputs.
Contents
. Definition at line 28 of file color_source_contents.cc.
Referenced by impeller::SolidColorContents::GetColor(), impeller::LinearGradientContents::IsOpaque(), impeller::RadialGradientContents::IsOpaque(), impeller::SweepGradientContents::IsOpaque(), impeller::TiledTextureContents::IsOpaque(), impeller::TiledTextureContents::Render(), and impeller::TiledTextureContents::RenderToSnapshot().
|
virtual |
Reimplemented in impeller::SolidColorContents.
Definition at line 40 of file color_source_contents.cc.
void impeller::ColorSourceContents::SetEffectTransform | ( | Matrix | matrix | ) |
Set the effect transform for this color source.
The effect transform is a transform matrix that is applied to the shaded color output and does not impact geometry in any way. For example: With repeat tiling, any gradient or `TiledTextureContents` could be used with an effect transform to inexpensively draw an infinite scrolling background pattern.
Definition at line 32 of file color_source_contents.cc.
References impeller::Matrix::Invert().
void impeller::ColorSourceContents::SetGeometry | ( | const Geometry * | geometry | ) |
Set the geometry that this contents will use to render.
Definition at line 16 of file color_source_contents.cc.
Referenced by impeller::testing::TEST_P().
|
overridevirtual |
Inherit the provided opacity.
Use of this method is invalid if CanAcceptOpacity returns false.
Reimplemented from impeller::Contents.
Definition at line 49 of file color_source_contents.cc.
void impeller::ColorSourceContents::SetOpacityFactor | ( | Scalar | opacity | ) |
Set the opacity factor for this color source.
Definition at line 24 of file color_source_contents.cc.