Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 2654853002: Remove gfx::Canvas::DrawStringRectWithHalo. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/canvas.h » ('j') | ui/gfx/render_text.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} 89 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
90 90
91 private: 91 private:
92 SkColor color_; 92 SkColor color_;
93 }; 93 };
94 94
95 // Layer delegate for painting text with effects on canvas. 95 // Layer delegate for painting text with effects on canvas.
96 class DrawStringLayerDelegate : public LayerDelegate { 96 class DrawStringLayerDelegate : public LayerDelegate {
97 public: 97 public:
98 enum DrawFunction { 98 enum DrawFunction {
msw 2017/01/25 18:09:07 Please remove this enum with only one value
Evan Stade 2017/01/26 00:43:10 Done.
99 STRING_WITH_HALO,
100 STRING_FADED, 99 STRING_FADED,
101 }; 100 };
102 101
103 DrawStringLayerDelegate( 102 DrawStringLayerDelegate(
104 SkColor back_color, SkColor halo_color, 103 SkColor back_color,
105 DrawFunction func, const gfx::Size& layer_size) 104 DrawFunction func, const gfx::Size& layer_size)
106 : background_color_(back_color), 105 : background_color_(back_color),
107 halo_color_(halo_color),
108 func_(func), 106 func_(func),
109 layer_size_(layer_size) { 107 layer_size_(layer_size) {
110 } 108 }
111 109
112 ~DrawStringLayerDelegate() override {} 110 ~DrawStringLayerDelegate() override {}
113 111
114 // Overridden from LayerDelegate: 112 // Overridden from LayerDelegate:
115 void OnPaintLayer(const ui::PaintContext& context) override { 113 void OnPaintLayer(const ui::PaintContext& context) override {
116 ui::PaintRecorder recorder(context, layer_size_); 114 ui::PaintRecorder recorder(context, layer_size_);
117 gfx::Rect bounds(layer_size_); 115 gfx::Rect bounds(layer_size_);
118 recorder.canvas()->DrawColor(background_color_); 116 recorder.canvas()->DrawColor(background_color_);
119 const base::string16 text = base::ASCIIToUTF16("Tests!"); 117 const base::string16 text = base::ASCIIToUTF16("Tests!");
120 switch (func_) { 118 switch (func_) {
121 case STRING_WITH_HALO:
122 recorder.canvas()->DrawStringRectWithHalo(
123 text, font_list_, SK_ColorRED, halo_color_, bounds, 0);
124 break;
125 case STRING_FADED: 119 case STRING_FADED:
126 recorder.canvas()->DrawFadedString( 120 recorder.canvas()->DrawFadedString(
127 text, font_list_, SK_ColorRED, bounds, 0); 121 text, font_list_, SK_ColorRED, bounds, 0);
128 break; 122 break;
129 default: 123 default:
130 NOTREACHED(); 124 NOTREACHED();
131 } 125 }
132 } 126 }
133 127
134 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} 128 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
135 129
136 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} 130 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
137 131
138 private: 132 private:
139 const SkColor background_color_; 133 const SkColor background_color_;
140 const SkColor halo_color_;
141 const DrawFunction func_; 134 const DrawFunction func_;
142 const gfx::FontList font_list_; 135 const gfx::FontList font_list_;
143 const gfx::Size layer_size_; 136 const gfx::Size layer_size_;
144 137
145 DISALLOW_COPY_AND_ASSIGN(DrawStringLayerDelegate); 138 DISALLOW_COPY_AND_ASSIGN(DrawStringLayerDelegate);
146 }; 139 };
147 140
148 class LayerWithRealCompositorTest : public testing::Test { 141 class LayerWithRealCompositorTest : public testing::Test {
149 public: 142 public:
150 LayerWithRealCompositorTest() { 143 LayerWithRealCompositorTest() {
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 ReadPixels(&bitmap); 1436 ReadPixels(&bitmap);
1444 ASSERT_FALSE(bitmap.empty()); 1437 ASSERT_FALSE(bitmap.empty());
1445 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); 1438 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true)));
1446 } 1439 }
1447 1440
1448 // It is really hard to write pixel test on text rendering, 1441 // It is really hard to write pixel test on text rendering,
1449 // due to different font appearance. 1442 // due to different font appearance.
1450 // So we choose to check result only on Windows. 1443 // So we choose to check result only on Windows.
1451 // See https://codereview.chromium.org/1634103003/#msg41 1444 // See https://codereview.chromium.org/1634103003/#msg41
1452 #if defined(OS_WIN) 1445 #if defined(OS_WIN)
1453 TEST_F(LayerWithRealCompositorTest, CanvasDrawStringRectWithHalo) {
1454 gfx::Size size(50, 50);
1455 GetCompositor()->SetScaleAndSize(1.0f, size);
1456 DrawStringLayerDelegate delegate(SK_ColorBLUE, SK_ColorWHITE,
1457 DrawStringLayerDelegate::STRING_WITH_HALO,
1458 size);
1459 std::unique_ptr<Layer> layer(
1460 CreateDrawStringLayer(gfx::Rect(size), &delegate));
1461 DrawTree(layer.get());
1462
1463 SkBitmap bitmap;
1464 ReadPixels(&bitmap);
1465 ASSERT_FALSE(bitmap.empty());
1466
1467 base::FilePath ref_img =
1468 test_data_directory().AppendASCII("string_with_halo.png");
1469 // WritePNGFile(bitmap, ref_img, true);
1470
1471 float percentage_pixels_large_error = 1.0f;
1472 float percentage_pixels_small_error = 0.0f;
1473 float average_error_allowed_in_bad_pixels = 1.f;
1474 int large_error_allowed = 1;
1475 int small_error_allowed = 0;
1476
1477 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img,
1478 cc::FuzzyPixelComparator(
1479 true,
1480 percentage_pixels_large_error,
1481 percentage_pixels_small_error,
1482 average_error_allowed_in_bad_pixels,
1483 large_error_allowed,
1484 small_error_allowed)));
1485 }
1486
1487 TEST_F(LayerWithRealCompositorTest, CanvasDrawFadedString) { 1446 TEST_F(LayerWithRealCompositorTest, CanvasDrawFadedString) {
1488 gfx::Size size(50, 50); 1447 gfx::Size size(50, 50);
1489 GetCompositor()->SetScaleAndSize(1.0f, size); 1448 GetCompositor()->SetScaleAndSize(1.0f, size);
1490 DrawStringLayerDelegate delegate(SK_ColorBLUE, SK_ColorWHITE, 1449 DrawStringLayerDelegate delegate(SK_ColorBLUE, SK_ColorWHITE,
1491 DrawStringLayerDelegate::STRING_FADED, 1450 DrawStringLayerDelegate::STRING_FADED,
1492 size); 1451 size);
1493 std::unique_ptr<Layer> layer( 1452 std::unique_ptr<Layer> layer(
1494 CreateDrawStringLayer(gfx::Rect(size), &delegate)); 1453 CreateDrawStringLayer(gfx::Rect(size), &delegate));
1495 DrawTree(layer.get()); 1454 DrawTree(layer.get());
1496 1455
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 layer.set_name("foo"); 2192 layer.set_name("foo");
2234 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = 2193 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info =
2235 layer.TakeDebugInfo(nullptr); 2194 layer.TakeDebugInfo(nullptr);
2236 std::string trace_format("bar,"); 2195 std::string trace_format("bar,");
2237 debug_info->AppendAsTraceFormat(&trace_format); 2196 debug_info->AppendAsTraceFormat(&trace_format);
2238 std::string expected("bar,{\"layer_name\":\"foo\"}"); 2197 std::string expected("bar,{\"layer_name\":\"foo\"}");
2239 EXPECT_EQ(expected, trace_format); 2198 EXPECT_EQ(expected, trace_format);
2240 } 2199 }
2241 2200
2242 } // namespace ui 2201 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/canvas.h » ('j') | ui/gfx/render_text.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698