Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/compiler/reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
.argument_name = "texture",
});
proto.args.push_back(BindPrototypeArgument{
.type_name = "const std::unique_ptr<const Sampler>&",
.type_name = "raw_ptr<const Sampler>",
.argument_name = "sampler",
});
}
Expand Down
6 changes: 3 additions & 3 deletions impeller/core/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ struct Viewport {
/// @brief Describes how the texture should be sampled when the texture
/// is being shrunk (minified) or expanded (magnified) to fit to
/// the sample point.
enum class MinMagFilter {
enum class MinMagFilter : uint8_t {
/// Select nearest to the sample point. Most widely supported.
kNearest,

Expand All @@ -422,7 +422,7 @@ enum class MinMagFilter {
};

/// @brief Options for selecting and filtering between mipmap levels.
enum class MipFilter {
enum class MipFilter : uint8_t {
/// @brief The texture is sampled as if it only had a single mipmap level.
///
/// All samples are read from level 0.
Expand All @@ -438,7 +438,7 @@ enum class MipFilter {
kLinear,
};

enum class SamplerAddressMode {
enum class SamplerAddressMode : uint8_t {
kClampToEdge,
kRepeat,
kMirror,
Expand Down
3 changes: 2 additions & 1 deletion impeller/core/resource_binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "impeller/core/buffer_view.h"
#include "impeller/core/formats.h"
#include "impeller/core/raw_ptr.h"
#include "impeller/core/sampler.h"
#include "impeller/core/shader_types.h"
#include "impeller/core/texture.h"
Expand All @@ -34,7 +35,7 @@ struct ResourceBinder {
const SampledImageSlot& slot,
const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) = 0;
raw_ptr<const Sampler>) = 0;
};

} // namespace impeller
Expand Down
2 changes: 1 addition & 1 deletion impeller/core/sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace impeller {

Sampler::Sampler(SamplerDescriptor desc) : desc_(std::move(desc)) {}
Sampler::Sampler(const SamplerDescriptor& desc) : desc_(desc) {}

Sampler::~Sampler() = default;

Expand Down
10 changes: 1 addition & 9 deletions impeller/core/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#ifndef FLUTTER_IMPELLER_CORE_SAMPLER_H_
#define FLUTTER_IMPELLER_CORE_SAMPLER_H_

#include <unordered_map>

#include "impeller/base/comparable.h"
#include "impeller/core/sampler_descriptor.h"

namespace impeller {
Expand All @@ -21,19 +18,14 @@ class Sampler {
protected:
SamplerDescriptor desc_;

explicit Sampler(SamplerDescriptor desc);
explicit Sampler(const SamplerDescriptor& desc);

private:
Sampler(const Sampler&) = delete;

Sampler& operator=(const Sampler&) = delete;
};

using SamplerMap = std::unordered_map<SamplerDescriptor,
std::unique_ptr<const Sampler>,
ComparableHash<SamplerDescriptor>,
ComparableEqual<SamplerDescriptor>>;

} // namespace impeller

#endif // FLUTTER_IMPELLER_CORE_SAMPLER_H_
28 changes: 12 additions & 16 deletions impeller/core/sampler_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
#ifndef FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_
#define FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_

#include "impeller/base/comparable.h"
#include "impeller/core/formats.h"

namespace impeller {

class Context;

struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
struct SamplerDescriptor final {
MinMagFilter min_filter = MinMagFilter::kNearest;
MinMagFilter mag_filter = MinMagFilter::kNearest;
MipFilter mip_filter = MipFilter::kNearest;
Expand All @@ -30,20 +29,17 @@ struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
MinMagFilter mag_filter,
MipFilter mip_filter);

// Comparable<SamplerDescriptor>
std::size_t GetHash() const override {
return fml::HashCombine(min_filter, mag_filter, mip_filter,
width_address_mode, height_address_mode,
depth_address_mode);
}

// Comparable<SamplerDescriptor>
bool IsEqual(const SamplerDescriptor& o) const override {
return min_filter == o.min_filter && mag_filter == o.mag_filter &&
mip_filter == o.mip_filter &&
width_address_mode == o.width_address_mode &&
height_address_mode == o.height_address_mode &&
depth_address_mode == o.depth_address_mode;
static uint64_t ToKey(const SamplerDescriptor& d) {
static_assert(sizeof(MinMagFilter) == 1);
static_assert(sizeof(MipFilter) == 1);
static_assert(sizeof(SamplerAddressMode) == 1);

return static_cast<uint64_t>(d.min_filter) << 0 |
static_cast<uint64_t>(d.mag_filter) << 8 |
static_cast<uint64_t>(d.mip_filter) << 16 |
static_cast<uint64_t>(d.width_address_mode) << 24 |
static_cast<uint64_t>(d.height_address_mode) << 32 |
static_cast<uint64_t>(d.depth_address_mode) << 40;
}
};

Expand Down
8 changes: 4 additions & 4 deletions impeller/display_list/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,22 +658,22 @@ void Canvas::DrawPoints(const Point points[],
void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
Point offset,
const Paint& paint,
SamplerDescriptor sampler) {
const SamplerDescriptor& sampler) {
if (!image) {
return;
}

const auto source = Rect::MakeSize(image->GetSize());
const auto dest = source.Shift(offset);

DrawImageRect(image, source, dest, paint, std::move(sampler));
DrawImageRect(image, source, dest, paint, sampler);
}

void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
Rect source,
Rect dest,
const Paint& paint,
SamplerDescriptor sampler,
const SamplerDescriptor& sampler,
SourceRectConstraint src_rect_constraint) {
if (!image || source.IsEmpty() || dest.IsEmpty()) {
return;
Expand Down Expand Up @@ -704,7 +704,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
texture_contents->SetSourceRect(*clipped_source);
texture_contents->SetStrictSourceRect(src_rect_constraint ==
SourceRectConstraint::kStrict);
texture_contents->SetSamplerDescriptor(std::move(sampler));
texture_contents->SetSamplerDescriptor(sampler);
texture_contents->SetOpacity(paint.color.alpha);
texture_contents->SetDeferApplyingOpacity(paint.HasColorFilter());

Expand Down
4 changes: 2 additions & 2 deletions impeller/display_list/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ class Canvas {
void DrawImage(const std::shared_ptr<Texture>& image,
Point offset,
const Paint& paint,
SamplerDescriptor sampler = {});
const SamplerDescriptor& sampler = {});

void DrawImageRect(
const std::shared_ptr<Texture>& image,
Rect source,
Rect dest,
const Paint& paint,
SamplerDescriptor sampler = {},
const SamplerDescriptor& sampler = {},
SourceRectConstraint src_rect_constraint = SourceRectConstraint::kFast);

void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& dst_sampler =
raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);

Expand All @@ -58,7 +58,7 @@ bool AtlasContents::Render(const ContentContext& renderer,

auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();

const std::unique_ptr<const Sampler>& dst_sampler =
raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);

Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static std::optional<Entity> AdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& dst_sampler =
raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
Expand All @@ -210,7 +210,7 @@ static std::optional<Entity> AdvancedBlend(
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& src_sampler =
raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
blend_info.color_factor = 0;
Expand Down Expand Up @@ -361,7 +361,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& dst_sampler =
raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
Expand Down Expand Up @@ -469,7 +469,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& dst_sampler =
raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
Expand Down Expand Up @@ -563,7 +563,7 @@ static std::optional<Entity> PipelineBlend(
return false;
}

const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input->sampler_descriptor);
FS::BindTextureSampler(pass, input->texture, sampler);
Expand Down Expand Up @@ -839,7 +839,7 @@ std::optional<Entity> BlendFilterContents::CreateFramebufferAdvancedBlend(
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& src_sampler =
raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
FS::BindTextureSamplerSrc(pass, src_texture, src_sampler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindTextureSampler(pass, input_snapshot->texture, sampler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
? input_snapshot->opacity
: 1.0f;
const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/filters/matrix_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void MatrixFilterContents::SetRenderingMode(
FilterContents::SetRenderingMode(rendering_mode);
}

void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) {
sampler_descriptor_ = std::move(desc);
void MatrixFilterContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
sampler_descriptor_ = desc;
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/matrix_filter_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MatrixFilterContents final : public FilterContents {
// |FilterContents|
void SetRenderingMode(Entity::RenderingMode rendering_mode) override;

void SetSamplerDescriptor(SamplerDescriptor desc);
void SetSamplerDescriptor(const SamplerDescriptor& desc);

// |FilterContents|
std::optional<Rect> GetFilterCoverage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
? input_snapshot->opacity
: 1.0f;

const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
break;
}

const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/framebuffer_blend_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
const std::unique_ptr<const Sampler>& src_sampler =
raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
FML_DCHECK(sampler_index < texture_inputs_.size());
auto& input = texture_inputs_[sampler_index];

const std::unique_ptr<const Sampler>& sampler =
raw_ptr<const Sampler> sampler =
context->GetSamplerLibrary()->GetSampler(
input.sampler_descriptor);

Expand Down
15 changes: 7 additions & 8 deletions impeller/entity/contents/test/recording_render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,20 @@ bool RecordingRenderPass::BindDynamicResource(
const SampledImageSlot& slot,
std::unique_ptr<ShaderMetadata> metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) {
raw_ptr<const Sampler> sampler) {
if (delegate_) {
return delegate_->BindDynamicResource(
stage, type, slot, std::move(metadata), texture, sampler);
}
return true;
}

bool RecordingRenderPass::BindResource(
ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) {
bool RecordingRenderPass::BindResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture,
raw_ptr<const Sampler> sampler) {
if (delegate_) {
return delegate_->BindResource(stage, type, slot, metadata, texture,
sampler);
Expand Down
15 changes: 7 additions & 8 deletions impeller/entity/contents/test/recording_render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RecordingRenderPass : public RenderPass {
const SampledImageSlot& slot,
const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override;
raw_ptr<const Sampler> sampler) override;

// |RenderPass|
bool BindDynamicResource(ShaderStage stage,
Expand All @@ -66,13 +66,12 @@ class RecordingRenderPass : public RenderPass {
BufferView view) override;

// |RenderPass|
bool BindDynamicResource(
ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
std::unique_ptr<ShaderMetadata> metadata,
std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override;
bool BindDynamicResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
std::unique_ptr<ShaderMetadata> metadata,
std::shared_ptr<const Texture> texture,
raw_ptr<const Sampler> sampler) override;

// |RenderPass|
void OnSetLabel(std::string_view label) override;
Expand Down
Loading