Commit 060cd8bf authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Remove deadcode Canvas::DrawFadedString(...)

This CL is removing the unused method:
  void Canvas::DrawFadedString(...);

Change-Id: I77c279ab1de9cf587b840142563501cb870fff79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902477Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714726}
parent d8f9971d
......@@ -63,12 +63,6 @@
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/skia_util.h"
#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_version.h"
#endif
using cc::MatchesPNGFile;
using cc::WritePNGFile;
......@@ -108,35 +102,6 @@ class ColoredLayer : public Layer, public LayerDelegate {
SkColor color_;
};
// Layer delegate for painting text with fade effect on canvas.
class DrawFadedStringLayerDelegate : public LayerDelegate {
public:
DrawFadedStringLayerDelegate(SkColor back_color, const gfx::Size& layer_size)
: background_color_(back_color), layer_size_(layer_size) {}
~DrawFadedStringLayerDelegate() override {}
// Overridden from LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override {
ui::PaintRecorder recorder(context, layer_size_);
gfx::Rect bounds(layer_size_);
recorder.canvas()->DrawColor(background_color_);
const base::string16 text = base::ASCIIToUTF16("Tests!");
recorder.canvas()->DrawFadedString(text, font_list_, SK_ColorRED, bounds,
0);
}
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override {}
private:
const SkColor background_color_;
const gfx::FontList font_list_;
const gfx::Size layer_size_;
DISALLOW_COPY_AND_ASSIGN(DrawFadedStringLayerDelegate);
};
// Param specifies whether to use SkiaRenderer or not
class LayerWithRealCompositorTest : public testing::TestWithParam<bool> {
public:
......@@ -195,15 +160,6 @@ class LayerWithRealCompositorTest : public testing::TestWithParam<bool> {
return layer;
}
std::unique_ptr<Layer> CreateDrawFadedStringLayerDelegate(
const gfx::Rect& bounds,
DrawFadedStringLayerDelegate* delegate) {
auto layer = std::make_unique<Layer>(LAYER_TEXTURED);
layer->SetBounds(bounds);
layer->set_delegate(delegate);
return layer;
}
void DrawTree(Layer* root) {
GetCompositor()->SetRootLayer(root);
GetCompositor()->ScheduleDraw();
......@@ -467,17 +423,6 @@ class TestCompositorAnimationObserver : public CompositorAnimationObserver {
DISALLOW_COPY_AND_ASSIGN(TestCompositorAnimationObserver);
};
#if defined(OS_WIN)
bool IsFontsSmoothingEnabled() {
BOOL antialiasing = TRUE;
BOOL result = SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &antialiasing, 0);
if (result == FALSE) {
ADD_FAILURE() << "Failed to retrieve font aliasing configuration.";
}
return antialiasing;
}
#endif
} // namespace
INSTANTIATE_TEST_SUITE_P(, LayerWithRealCompositorTest, ::testing::Bool());
......@@ -1993,57 +1938,6 @@ TEST_P(LayerWithRealCompositorTest, BackgroundBlurChangeDeviceScale) {
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, fuzzy_comparator));
}
// It is really hard to write pixel test on text rendering,
// due to different font appearance.
// So we choose to check result only on Windows.
// See https://codereview.chromium.org/1634103003/#msg41
#if defined(OS_WIN)
TEST_P(LayerWithRealCompositorTest, CanvasDrawFadedString) {
ASSERT_TRUE(IsFontsSmoothingEnabled())
<< "The test requires that fonts smoothing (anti-aliasing) is activated. "
"If this assert is failing you need to manually activate the flag in "
"your system fonts settings.";
viz::ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
gfx::Size size(50, 50);
GetCompositor()->SetScaleAndSize(
1.0f, size, allocator.GetCurrentLocalSurfaceIdAllocation());
DrawFadedStringLayerDelegate delegate(SK_ColorBLUE, size);
std::unique_ptr<Layer> layer =
CreateDrawFadedStringLayerDelegate(gfx::Rect(size), &delegate);
DrawTree(layer.get());
SkBitmap bitmap;
ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty());
std::string filename;
if (base::win::GetVersion() < base::win::Version::WIN10) {
filename = "string_faded_win7.png";
} else {
filename = "string_faded_win10.png";
}
base::FilePath ref_img = test_data_dir().AppendASCII(filename);
// WritePNGFile(bitmap, ref_img, true);
float percentage_pixels_large_error = 8.0f; // 200px / (50*50)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 80.f;
int large_error_allowed = 255;
int small_error_allowed = 0;
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img,
cc::FuzzyPixelComparator(
true,
percentage_pixels_large_error,
percentage_pixels_small_error,
average_error_allowed_in_bad_pixels,
large_error_allowed,
small_error_allowed)));
}
#endif // defined(OS_WIN)
// Opacity is rendered correctly.
// Checks that modifying the hierarchy correctly affects final composite.
TEST_P(LayerWithRealCompositorTest, Opacity) {
......
......@@ -435,13 +435,6 @@ class GFX_EXPORT Canvas {
// Apply transformation on the canvas.
void Transform(const Transform& transform);
// Draws the given string with a fade gradient at the end.
void DrawFadedString(const base::string16& text,
const FontList& font_list,
SkColor color,
const Rect& display_rect,
int flags);
// Note that writing to this bitmap will modify pixels stored in this canvas.
SkBitmap GetBitmap() const;
......
......@@ -237,32 +237,4 @@ void Canvas::DrawStringRectWithFlags(const base::string16& text,
canvas_->restore();
}
void Canvas::DrawFadedString(const base::string16& text,
const FontList& font_list,
SkColor color,
const Rect& display_rect,
int flags) {
// If the whole string fits in the destination then just draw it directly.
if (GetStringWidth(text, font_list) <= display_rect.width()) {
DrawStringRectWithFlags(text, font_list, color, display_rect, flags);
return;
}
// Align with content directionality instead of fading both ends.
flags &= ~TEXT_ALIGN_CENTER;
if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT)))
flags |= TEXT_ALIGN_TO_HEAD;
flags |= NO_ELLIPSIS;
// TODO(tapted): Remove Canvas::DrawFadedString() - it's unused.
auto render_text = RenderText::CreateInstanceDeprecated();
Rect rect = display_rect;
UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
render_text->SetElideBehavior(FADE_TAIL);
canvas_->save();
ClipRect(display_rect);
render_text->Draw(this);
canvas_->restore();
}
} // namespace gfx
......@@ -48,7 +48,7 @@ const wchar_t kRightToLeftText[] =
L"\x5e9\x5dc\x5d5\x5dd \x5d4\x5e2\x5d5\x5dc\x5dd!";
const char* kTextExamples[] = { "Short", "Long", "Ampersands", "RTL Hebrew", };
const char* kElideBehaviors[] = { "Elide", "No Elide", "Fade", };
const char* kElideBehaviors[] = {"Elide", "No Elide"};
const char* kPrefixOptions[] = { "Default", "Show", "Hide", };
const char* kHorizontalAligments[] = { "Default", "Left", "Center", "Right", };
constexpr const char* kWeightLabels[] = {
......@@ -82,11 +82,7 @@ class TextExample::TextExampleView : public View {
View::OnPaint(canvas);
const gfx::Rect bounds = GetContentsBounds();
const SkColor color = SK_ColorDKGRAY;
if (elide_ == gfx::FADE_TAIL) {
canvas->DrawFadedString(text_, font_list_, color, bounds, flags_);
} else {
canvas->DrawStringRectWithFlags(text_, font_list_, color, bounds, flags_);
}
canvas->DrawStringRectWithFlags(text_, font_list_, color, bounds, flags_);
}
int flags() const { return flags_; }
......@@ -247,9 +243,6 @@ void TextExample::OnPerformAction(Combobox* combobox) {
case 1:
text_view_->set_elide(gfx::NO_ELIDE);
break;
case 2:
text_view_->set_elide(gfx::FADE_TAIL);
break;
}
} else if (combobox == prefix_cb_) {
flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment