Skip to content

Commit

Permalink
[Impeller] Unconditionally dither in gradient shader fragments. (#46746)
Browse files Browse the repository at this point in the history
Partial work towards flutter/flutter#112498.

Won't land this until #46745 is
merged, so expect some redness until then.
  • Loading branch information
matanlurey authored Oct 24, 2023
1 parent 8fdf7df commit fb15e04
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 90 deletions.
4 changes: 0 additions & 4 deletions impeller/aiks/color_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ColorSource ColorSource::MakeLinearGradient(Point start_point,
contents->SetStops(stops);
contents->SetEndPoints(start_point, end_point);
contents->SetTileMode(tile_mode);
contents->SetDither(paint.dither);
contents->SetEffectTransform(effect_transform);

std::vector<Point> bounds{start_point, end_point};
Expand Down Expand Up @@ -92,7 +91,6 @@ ColorSource ColorSource::MakeConicalGradient(Point center,
contents->SetStops(stops);
contents->SetCenterAndRadius(center, radius);
contents->SetTileMode(tile_mode);
contents->SetDither(paint.dither);
contents->SetEffectTransform(effect_transform);
contents->SetFocus(focus_center, focus_radius);

Expand Down Expand Up @@ -124,7 +122,6 @@ ColorSource ColorSource::MakeRadialGradient(Point center,
contents->SetStops(stops);
contents->SetCenterAndRadius(center, radius);
contents->SetTileMode(tile_mode);
contents->SetDither(paint.dither);
contents->SetEffectTransform(effect_transform);

auto radius_pt = Point(radius, radius);
Expand Down Expand Up @@ -156,7 +153,6 @@ ColorSource ColorSource::MakeSweepGradient(Point center,
contents->SetColors(colors);
contents->SetStops(stops);
contents->SetTileMode(tile_mode);
contents->SetDither(paint.dither);
contents->SetEffectTransform(effect_transform);

return contents;
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/contents/conical_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ void ConicalGradientContents::SetTileMode(Entity::TileMode tile_mode) {
tile_mode_ = tile_mode;
}

void ConicalGradientContents::SetDither(bool dither) {
dither_ = dither;
}

void ConicalGradientContents::SetColors(std::vector<Color> colors) {
colors_ = std::move(colors);
}
Expand Down Expand Up @@ -76,7 +72,6 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();
frag_info.dither = dither_;
if (focus_) {
frag_info.focus = focus_.value();
frag_info.focus_radius = focus_radius_;
Expand Down
3 changes: 0 additions & 3 deletions impeller/entity/contents/conical_gradient_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class ConicalGradientContents final : public ColorSourceContents {

void SetTileMode(Entity::TileMode tile_mode);

void SetDither(bool dither);

void SetFocus(std::optional<Point> focus, Scalar radius);

private:
Expand All @@ -65,7 +63,6 @@ class ConicalGradientContents final : public ColorSourceContents {
Color decal_border_color_ = Color::BlackTransparent();
std::optional<Point> focus_;
Scalar focus_radius_ = 0.0f;
bool dither_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(ConicalGradientContents);
};
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ bool LinearGradientContents::IsOpaque() const {
return true;
}

void LinearGradientContents::SetDither(bool dither) {
dither_ = dither;
}

bool LinearGradientContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
Expand Down Expand Up @@ -150,7 +146,6 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer,
auto colors = CreateGradientColors(colors_, stops_);

frag_info.colors_length = colors.size();
frag_info.dither = dither_;
auto color_buffer =
host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData),
DefaultUniformAlignment());
Expand Down
3 changes: 0 additions & 3 deletions impeller/entity/contents/linear_gradient_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class LinearGradientContents final : public ColorSourceContents {

void SetTileMode(Entity::TileMode tile_mode);

void SetDither(bool dither);

private:
bool RenderTexture(const ContentContext& renderer,
const Entity& entity,
Expand All @@ -66,7 +64,6 @@ class LinearGradientContents final : public ColorSourceContents {
std::vector<Scalar> stops_;
Entity::TileMode tile_mode_;
Color decal_border_color_ = Color::BlackTransparent();
bool dither_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(LinearGradientContents);
};
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ void RadialGradientContents::SetTileMode(Entity::TileMode tile_mode) {
tile_mode_ = tile_mode;
}

void RadialGradientContents::SetDither(bool dither) {
dither_ = dither;
}

void RadialGradientContents::SetColors(std::vector<Color> colors) {
colors_ = std::move(colors);
}
Expand Down Expand Up @@ -82,7 +78,6 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();
frag_info.dither = dither_;

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);
Expand Down
3 changes: 0 additions & 3 deletions impeller/entity/contents/radial_gradient_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class RadialGradientContents final : public ColorSourceContents {

void SetTileMode(Entity::TileMode tile_mode);

void SetDither(bool dither);

private:
bool RenderTexture(const ContentContext& renderer,
const Entity& entity,
Expand All @@ -64,7 +62,6 @@ class RadialGradientContents final : public ColorSourceContents {
std::vector<Scalar> stops_;
Entity::TileMode tile_mode_;
Color decal_border_color_ = Color::BlackTransparent();
bool dither_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(RadialGradientContents);
};
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ void SweepGradientContents::SetTileMode(Entity::TileMode tile_mode) {
tile_mode_ = tile_mode;
}

void SweepGradientContents::SetDither(bool dither) {
dither_ = dither;
}

const std::vector<Color>& SweepGradientContents::GetColors() const {
return colors_;
}
Expand Down Expand Up @@ -88,7 +84,6 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();
frag_info.dither = dither_;

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);
Expand Down
3 changes: 0 additions & 3 deletions impeller/entity/contents/sweep_gradient_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class SweepGradientContents final : public ColorSourceContents {

void SetTileMode(Entity::TileMode tile_mode);

void SetDither(bool dither);

const std::vector<Color>& GetColors() const;

const std::vector<Scalar>& GetStops() const;
Expand All @@ -67,7 +65,6 @@ class SweepGradientContents final : public ColorSourceContents {
std::vector<Scalar> stops_;
Entity::TileMode tile_mode_;
Color decal_border_color_ = Color::BlackTransparent();
bool dither_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(SweepGradientContents);
};
Expand Down
7 changes: 2 additions & 5 deletions impeller/entity/shaders/conical_gradient_ssbo_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ uniform FragInfo {
int colors_length;
vec2 focus;
float focus_radius;
bool dither;
}
frag_info;

Expand Down Expand Up @@ -64,9 +63,7 @@ void main() {
}
}
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;

if (frag_info.dither) {
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
7 changes: 2 additions & 5 deletions impeller/entity/shaders/linear_gradient_ssbo_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ uniform FragInfo {
float tile_mode;
vec4 decal_border_color;
int colors_length;
bool dither;
}
frag_info;

Expand Down Expand Up @@ -60,9 +59,7 @@ void main() {
}
}
}
frag_color = IPPremultiply(frag_color) * frag_info.alpha;

if (frag_info.dither) {
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
frag_color = IPPremultiply(frag_color) * frag_info.alpha;
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
7 changes: 2 additions & 5 deletions impeller/entity/shaders/radial_gradient_ssbo_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ uniform FragInfo {
vec4 decal_border_color;
float alpha;
int colors_length;
bool dither;
}
frag_info;

Expand Down Expand Up @@ -60,9 +59,7 @@ void main() {
}
}
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;

if (frag_info.dither) {
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
7 changes: 2 additions & 5 deletions impeller/entity/shaders/sweep_gradient_ssbo_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ uniform FragInfo {
vec4 decal_border_color;
float alpha;
int colors_length;
bool dither;
}
frag_info;

Expand Down Expand Up @@ -61,9 +60,7 @@ void main() {
}
}
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;

if (frag_info.dither) {
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
frag_color = IPPremultiply(result_color) * frag_info.alpha;
frag_color = IPOrderedDither8x8(frag_color, v_position);
}
Loading

0 comments on commit fb15e04

Please sign in to comment.