Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alp
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE
Expand Down Expand Up @@ -3912,6 +3913,7 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.vert
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag
Expand Down
19 changes: 19 additions & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ void Canvas::RestoreClip() {
GetCurrentPass().AddEntity(entity);
}

void Canvas::DrawPoints(std::vector<Point> points,
Scalar radius,
const Paint& paint,
PointStyle point_style) {
if (radius <= 0) {
return;
}

Entity entity;
entity.SetTransformation(GetCurrentTransformation());
entity.SetStencilDepth(GetStencilDepth());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(paint.WithFilters(paint.CreateContentsForGeometry(
Geometry::MakePointField(std::move(points), radius,
/*round=*/point_style == PointStyle::kRound))));

GetCurrentPass().AddEntity(entity);
}

void Canvas::DrawPicture(Picture picture) {
if (!picture.pass) {
return;
Expand Down
13 changes: 13 additions & 0 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ struct CanvasStackEntry {
bool contains_clips = false;
};

enum class PointStyle {
/// @brief Points are drawn as squares.
kRound,

/// @brief Points are drawn as circles.
kSquare,
};

class Canvas {
public:
struct DebugOptions {
Expand Down Expand Up @@ -100,6 +108,11 @@ class Canvas {

void DrawCircle(Point center, Scalar radius, const Paint& paint);

void DrawPoints(std::vector<Point>,
Scalar radius,
const Paint& paint,
PointStyle point_style);

void DrawImage(const std::shared_ptr<Image>& image,
Point offset,
const Paint& paint,
Expand Down
19 changes: 10 additions & 9 deletions impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,17 @@ void DlDispatcher::drawPoints(PointMode mode,
Paint paint = paint_;
paint.style = Paint::Style::kStroke;
switch (mode) {
case flutter::DlCanvas::PointMode::kPoints:
if (paint.stroke_cap == Cap::kButt) {
paint.stroke_cap = Cap::kSquare;
case flutter::DlCanvas::PointMode::kPoints: {
// Cap::kButt is also treated as a square.
auto point_style = paint.stroke_cap == Cap::kRound ? PointStyle::kRound
: PointStyle::kSquare;
auto radius = paint.stroke_width;
if (radius > 0) {
radius /= 2.0;
}
for (uint32_t i = 0; i < count; i++) {
Point p0 = skia_conversions::ToPoint(points[i]);
auto path = PathBuilder{}.AddLine(p0, p0).TakePath();
canvas_.DrawPath(path, paint);
}
break;
canvas_.DrawPoints(skia_conversions::ToPoints(points, count), radius,
paint, point_style);
} break;
case flutter::DlCanvas::PointMode::kLines:
for (uint32_t i = 1; i < count; i += 2) {
Point p0 = skia_conversions::ToPoint(points[i - 1]);
Expand Down
8 changes: 8 additions & 0 deletions impeller/display_list/skia_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ std::vector<Rect> ToRects(const SkRect tex[], int count) {
return result;
}

std::vector<Point> ToPoints(const SkPoint points[], int count) {
std::vector<Point> result(count);
for (auto i = 0; i < count; i++) {
result[i] = ToPoint(points[i]);
}
return result;
}

PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect) {
using Corner = SkRRect::Corner;
PathBuilder::RoundingRadii radii;
Expand Down
2 changes: 2 additions & 0 deletions impeller/display_list/skia_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ std::optional<Rect> ToRect(const SkRect* rect);

std::vector<Rect> ToRects(const SkRect tex[], int count);

std::vector<Point> ToPoints(const SkPoint points[], int count);

Point ToPoint(const SkPoint& point);

Color ToColor(const SkColor& color);
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impeller_shaders("modern_entity_shaders") {
"shaders/linear_gradient_ssbo_fill.frag",
"shaders/radial_gradient_ssbo_fill.frag",
"shaders/sweep_gradient_ssbo_fill.frag",
"shaders/geometry/points.vert",
]
}

Expand Down
23 changes: 23 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
desc.SetPrimitiveType(primitive_type);

desc.SetPolygonMode(wireframe ? PolygonMode::kLine : PolygonMode::kFill);
desc.SetEnableRasterization(enable_rasterization);
}

template <typename PipelineT>
Expand All @@ -161,6 +162,22 @@ static std::unique_ptr<PipelineT> CreateDefaultPipeline(
return std::make_unique<PipelineT>(context, desc);
}

template <typename PipelineT>
static std::unique_ptr<PipelineT> CreateDefaultNonRenderingPipeline(
const Context& context) {
auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
if (!desc.has_value()) {
return nullptr;
}
// Apply default ContentContextOptions to the descriptor.
const auto default_color_fmt =
context.GetCapabilities()->GetDefaultColorFormat();
ContentContextOptions{.color_attachment_pixel_format = default_color_fmt,
.enable_rasterization = false}
.ApplyToPipelineDescriptor(*desc);
return std::make_unique<PipelineT>(context, desc);
}

ContentContext::ContentContext(std::shared_ptr<Context> context)
: context_(std::move(context)),
tessellator_(std::make_shared<Tessellator>()),
Expand Down Expand Up @@ -296,6 +313,12 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
porter_duff_blend_pipelines_[{}] =
CreateDefaultPipeline<PorterDuffBlendPipeline>(*context_);

if (context_->GetCapabilities()->SupportsDisabledRasterization()) {
point_field_geometry_pipelines_[{}] =
CreateDefaultNonRenderingPipeline<PointFieldGeometryPipeline>(
*context_);
}

if (solid_fill_pipelines_[{}]->GetDescriptor().has_value()) {
auto clip_pipeline_descriptor =
solid_fill_pipelines_[{}]->GetDescriptor().value();
Expand Down
25 changes: 20 additions & 5 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "impeller/entity/linear_to_srgb_filter.vert.h"
#include "impeller/entity/morphology_filter.frag.h"
#include "impeller/entity/morphology_filter.vert.h"
#include "impeller/entity/points.vert.h"
#include "impeller/entity/porter_duff_blend.frag.h"
#include "impeller/entity/radial_gradient_fill.frag.h"
#include "impeller/entity/rrect_blur.frag.h"
Expand Down Expand Up @@ -275,6 +276,10 @@ using FramebufferBlendSoftLightPipeline =
RenderPipelineT<FramebufferBlendVertexShader,
FramebufferBlendSoftlightFragmentShader>;

/// Geometry Pipelines
using PointFieldGeometryPipeline =
RenderPipelineT<PointsVertexShader, NonRenderingFragment>;

/// Pipeline state configuration.
///
/// Each unique combination of these options requires a different pipeline state
Expand All @@ -294,13 +299,14 @@ struct ContentContextOptions {
std::optional<PixelFormat> color_attachment_pixel_format;
bool has_stencil_attachment = true;
bool wireframe = false;
bool enable_rasterization = true;

struct Hash {
constexpr std::size_t operator()(const ContentContextOptions& o) const {
return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare,
o.stencil_operation, o.primitive_type,
o.color_attachment_pixel_format,
o.has_stencil_attachment, o.wireframe);
return fml::HashCombine(
o.sample_count, o.blend_mode, o.stencil_compare, o.stencil_operation,
o.primitive_type, o.color_attachment_pixel_format,
o.has_stencil_attachment, o.wireframe, o.enable_rasterization);
}
};

Expand All @@ -315,7 +321,8 @@ struct ContentContextOptions {
lhs.color_attachment_pixel_format ==
rhs.color_attachment_pixel_format &&
lhs.has_stencil_attachment == rhs.has_stencil_attachment &&
lhs.wireframe == rhs.wireframe;
lhs.wireframe == rhs.wireframe &&
lhs.enable_rasterization == rhs.enable_rasterization;
}
};

Expand Down Expand Up @@ -660,6 +667,12 @@ class ContentContext {
return GetPipeline(framebuffer_blend_softlight_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetPointFieldGeometryPipeline(
ContentContextOptions opts) const {
FML_DCHECK(GetDeviceCapabilities().SupportsDisabledRasterization());
return GetPipeline(point_field_geometry_pipelines_, opts);
}

std::shared_ptr<Context> GetContext() const;

std::shared_ptr<GlyphAtlasContext> GetGlyphAtlasContext(
Expand Down Expand Up @@ -783,6 +796,8 @@ class ContentContext {
mutable Variants<FramebufferBlendSoftLightPipeline>
framebuffer_blend_softlight_pipelines_;

mutable Variants<PointFieldGeometryPipeline> point_field_geometry_pipelines_;

template <class TypedPipeline>
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
Variants<TypedPipeline>& container,
Expand Down
Loading