14 #include "impeller/entity/texture_fill.frag.h" 
   15 #include "impeller/entity/texture_fill.vert.h" 
   16 #include "impeller/entity/texture_fill_strict_src.frag.h" 
   17 #include "impeller/entity/tiled_texture_fill_external.frag.h" 
   29   auto contents = std::make_shared<TextureContents>();
 
   30   contents->destination_rect_ = destination;
 
   39   destination_rect_ = rect;
 
   43   texture_ = std::move(texture);
 
   55   stencil_enabled_ = enabled;
 
   59   inherited_opacity_ = opacity;
 
   63   return opacity_ * inherited_opacity_;
 
   76     std::optional<Rect> coverage_limit,
 
   77     const std::optional<SamplerDescriptor>& sampler_descriptor,
 
   80     std::string_view label)
 const {
 
   83   auto bounds = destination_rect_;
 
   87     auto scale = 
Vector2(bounds.GetSize() / 
Size(texture_->GetSize()));
 
   93         .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
 
  100       sampler_descriptor.value_or(sampler_descriptor_),  
 
  109   using VS = TextureFillVertexShader;
 
  110   using FS = TextureFillFragmentShader;
 
  111   using FSStrict = TextureFillStrictSrcFragmentShader;
 
  114       texture_ == 
nullptr || texture_->GetSize().IsEmpty()) {
 
  118 #ifdef IMPELLER_ENABLE_OPENGLES 
  119   using FSExternal = TiledTextureFillExternalFragmentShader;
 
  120   bool is_external_texture =
 
  124   auto texture_coords =
 
  128   std::array<VS::PerVertexData, 4> vertices = {
 
  129       VS::PerVertexData{destination_rect_.
GetLeftTop(),
 
  130                         texture_coords.GetLeftTop()},
 
  132                         texture_coords.GetRightTop()},
 
  134                         texture_coords.GetLeftBottom()},
 
  136                         texture_coords.GetRightBottom()},
 
  140   VS::FrameInfo frame_info;
 
  142   frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
 
  144 #ifdef IMPELLER_DEBUG 
  145   if (label_.empty()) {
 
  153   if (!stencil_enabled_) {
 
  158   pipeline_options.depth_write_enabled =
 
  161 #ifdef IMPELLER_ENABLE_OPENGLES 
  162   if (is_external_texture) {
 
  164         renderer.GetTiledTextureExternalPipeline(pipeline_options));
 
  167         strict_source_rect_enabled_
 
  178   VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
 
  180   if (strict_source_rect_enabled_) {
 
  184     auto strict_texture_coords =
 
  187     FSStrict::FragInfo frag_info;
 
  188     frag_info.source_rect = 
Vector4(strict_texture_coords.GetLTRB());
 
  190     FSStrict::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
 
  191     FSStrict::BindTextureSampler(
 
  193         renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
 
  194             sampler_descriptor_));
 
  195 #ifdef IMPELLER_ENABLE_OPENGLES 
  196   } 
else if (is_external_texture) {
 
  197     FSExternal::FragInfo frag_info;
 
  198     frag_info.x_tile_mode =
 
  200     frag_info.y_tile_mode =
 
  203     FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
 
  215     FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
 
  217         renderer.
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
 
  220     FS::FragInfo frag_info;
 
  222     FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
 
  223     FS::BindTextureSampler(
 
  225         renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
 
  226             sampler_descriptor_));
 
  228   return pass.
Draw().ok();
 
  232   source_rect_ = source_rect;
 
  240   strict_source_rect_enabled_ = strict;
 
  244   return strict_source_rect_enabled_;
 
  248   sampler_descriptor_ = desc;
 
  252   return sampler_descriptor_;
 
  256   defer_applying_opacity_ = defer_applying_opacity;
 
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
PipelineRef GetTextureStrictSrcPipeline(ContentContextOptions opts) const
PipelineRef GetTexturePipeline(ContentContextOptions opts) const
std::shared_ptr< Context > GetContext() const
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,...
Matrix GetShaderTransform(const RenderPass &pass) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
std::shared_ptr< Texture > GetTexture() const
void SetSourceRect(const Rect &source_rect)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetSamplerDescriptor(const SamplerDescriptor &desc)
Scalar GetOpacity() const
void SetStrictSourceRect(bool strict)
void SetDeferApplyingOpacity(bool defer_applying_opacity)
const SamplerDescriptor & GetSamplerDescriptor() const
void SetOpacity(Scalar opacity)
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="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
bool GetStrictSourceRect() const
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
const Rect & GetSourceRect() const
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
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.
void SetTexture(std::shared_ptr< Texture > texture)
~TextureContents() override
void SetLabel(std::string_view label)
void SetStencilEnabled(bool enabled)
void SetDestinationRect(Rect rect)
constexpr float kEhCloseEnough
LinePipeline::FragmentShader FS
@ kBase
The texture is sampled as if it only had a single mipmap level.
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > texture
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
constexpr TPoint< T > GetLeftBottom() const
constexpr TPoint< T > GetRightTop() const
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr TPoint< T > GetRightBottom() const
constexpr TPoint< T > GetLeftTop() const