Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 path.AddLineTo(FloatPoint(40, 40)); | 134 path.AddLineTo(FloatPoint(40, 40)); |
| 135 PaintFlags flags; | 135 PaintFlags flags; |
| 136 flags.setColor(alpha.Rgb()); | 136 flags.setColor(alpha.Rgb()); |
| 137 flags.setBlendMode(SkBlendMode::kSrcOut); | 137 flags.setBlendMode(SkBlendMode::kSrcOut); |
| 138 context.DrawPath(path.GetSkPath(), flags); | 138 context.DrawPath(path.GetSkPath(), flags); |
| 139 | 139 |
| 140 canvas.drawPicture(context.EndRecording()); | 140 canvas.drawPicture(context.EndRecording()); |
| 141 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 141 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 TEST(GraphicsContextTest, HighContrast) { | |
| 145 SkBitmap bitmap; | |
| 146 bitmap.allocN32Pixels(4, 8); | |
| 147 bitmap.eraseColor(0); | |
| 148 SkiaPaintCanvas canvas(bitmap); | |
| 149 | |
| 150 std::unique_ptr<PaintController> paint_controller = PaintController::Create(); | |
| 151 GraphicsContext context(*paint_controller); | |
| 152 | |
| 153 Color black(0.0f, 0.0f, 0.0f, 1.0f); | |
| 154 Color white(1.0f, 1.0f, 1.0f, 1.0f); | |
| 155 Color red(1.0f, 0.0f, 0.0f, 1.0f); | |
| 156 Color gray(0.5f, 0.5f, 0.5f, 1.0f); | |
| 157 | |
| 158 context.BeginRecording(FloatRect(0, 0, 4, 8)); | |
| 159 | |
| 160 // Row 0: No high contrast. | |
| 161 context.FillRect(FloatRect(0, 0, 1, 1), black); | |
|
chrishtr
2017/06/05 16:35:18
It would be clearer to put each mode you're testin
dmazzoni
2017/06/06 05:23:24
Done.
| |
| 162 context.FillRect(FloatRect(1, 0, 1, 1), white); | |
| 163 context.FillRect(FloatRect(2, 0, 1, 1), red); | |
| 164 context.FillRect(FloatRect(3, 0, 1, 1), gray); | |
| 165 | |
| 166 // Row 1: High contrast mode off. | |
| 167 HighContrastSettings settings; | |
| 168 settings.mode = HighContrastMode::kOff; | |
| 169 settings.grayscale = false; | |
| 170 settings.contrast = 0; | |
| 171 context.SetHighContrast(settings); | |
| 172 context.FillRect(FloatRect(0, 1, 1, 1), black); | |
| 173 context.FillRect(FloatRect(1, 1, 1, 1), white); | |
| 174 context.FillRect(FloatRect(2, 1, 1, 1), red); | |
| 175 context.FillRect(FloatRect(3, 1, 1, 1), gray); | |
| 176 | |
| 177 // Row 2: Simple invert for testing. Each color component |c| | |
| 178 // is replaced with |255 - c| for easy testing. | |
| 179 settings.mode = HighContrastMode::kSimpleInvertForTesting; | |
| 180 context.SetHighContrast(settings); | |
| 181 context.FillRect(FloatRect(0, 2, 1, 1), black); | |
| 182 context.FillRect(FloatRect(1, 2, 1, 1), white); | |
| 183 context.FillRect(FloatRect(2, 2, 1, 1), red); | |
| 184 context.FillRect(FloatRect(3, 2, 1, 1), gray); | |
| 185 | |
| 186 // Row 3: Invert brightness (with gamma correction). | |
| 187 settings.mode = HighContrastMode::kInvertBrightness; | |
| 188 context.SetHighContrast(settings); | |
| 189 context.FillRect(FloatRect(0, 3, 1, 1), black); | |
| 190 context.FillRect(FloatRect(1, 3, 1, 1), white); | |
| 191 context.FillRect(FloatRect(2, 3, 1, 1), red); | |
| 192 context.FillRect(FloatRect(3, 3, 1, 1), gray); | |
| 193 | |
| 194 // Row 4: Invert lightness (in HSL space). | |
| 195 settings.mode = HighContrastMode::kInvertLightness; | |
| 196 context.SetHighContrast(settings); | |
| 197 context.FillRect(FloatRect(0, 4, 1, 1), black); | |
| 198 context.FillRect(FloatRect(1, 4, 1, 1), white); | |
| 199 context.FillRect(FloatRect(2, 4, 1, 1), red); | |
| 200 context.FillRect(FloatRect(3, 4, 1, 1), gray); | |
| 201 | |
| 202 // Row 5: Invert lightness plus grayscale. | |
| 203 settings.mode = HighContrastMode::kInvertLightness; | |
| 204 settings.grayscale = true; | |
| 205 context.SetHighContrast(settings); | |
| 206 context.FillRect(FloatRect(0, 5, 1, 1), black); | |
| 207 context.FillRect(FloatRect(1, 5, 1, 1), white); | |
| 208 context.FillRect(FloatRect(2, 5, 1, 1), red); | |
| 209 context.FillRect(FloatRect(3, 5, 1, 1), gray); | |
| 210 | |
| 211 // Row 6: Invert lightness plus increased contrast. | |
| 212 settings.mode = HighContrastMode::kInvertLightness; | |
| 213 settings.grayscale = false; | |
| 214 settings.contrast = 0.2; | |
| 215 context.SetHighContrast(settings); | |
| 216 context.FillRect(FloatRect(0, 6, 1, 1), black); | |
| 217 context.FillRect(FloatRect(1, 6, 1, 1), white); | |
| 218 context.FillRect(FloatRect(2, 6, 1, 1), red); | |
| 219 context.FillRect(FloatRect(3, 6, 1, 1), gray); | |
| 220 | |
| 221 // Capture the result in the bitmap. | |
| 222 canvas.drawPicture(context.EndRecording()); | |
| 223 | |
| 224 // Test row 0: No high contrast. | |
| 225 EXPECT_EQ(0xff000000, *bitmap.getAddr32(0, 0)); | |
| 226 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(1, 0)); | |
| 227 EXPECT_EQ(0xffff0000, *bitmap.getAddr32(2, 0)); | |
| 228 EXPECT_EQ(0xff808080, *bitmap.getAddr32(3, 0)); | |
| 229 | |
| 230 // Test row 1: High contrast mode off. | |
| 231 EXPECT_EQ(0xff000000, *bitmap.getAddr32(0, 1)); | |
| 232 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(1, 1)); | |
| 233 EXPECT_EQ(0xffff0000, *bitmap.getAddr32(2, 1)); | |
| 234 EXPECT_EQ(0xff808080, *bitmap.getAddr32(3, 1)); | |
| 235 | |
| 236 // Test row 2: Simple invert for testing. | |
| 237 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(0, 2)); | |
| 238 EXPECT_EQ(0xff000000, *bitmap.getAddr32(1, 2)); | |
| 239 EXPECT_EQ(0xff00ffff, *bitmap.getAddr32(2, 2)); | |
| 240 EXPECT_EQ(0xff7f7f7f, *bitmap.getAddr32(3, 2)); | |
| 241 | |
| 242 // Test row 3: Invert brightness. | |
| 243 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(0, 3)); | |
| 244 EXPECT_EQ(0xff000000, *bitmap.getAddr32(1, 3)); | |
| 245 EXPECT_EQ(0xff00ffff, *bitmap.getAddr32(2, 3)); | |
| 246 EXPECT_EQ(0xffdddddd, *bitmap.getAddr32(3, 3)); | |
| 247 | |
| 248 // Test row 4: Invert lightness. | |
| 249 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(0, 4)); | |
| 250 EXPECT_EQ(0xff000000, *bitmap.getAddr32(1, 4)); | |
| 251 EXPECT_EQ(0xffff0000, *bitmap.getAddr32(2, 4)); | |
| 252 EXPECT_EQ(0xffdddddd, *bitmap.getAddr32(3, 4)); | |
| 253 | |
| 254 // Test row 5: Invert lightness plus grayscale. | |
| 255 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(0, 5)); | |
| 256 EXPECT_EQ(0xff000000, *bitmap.getAddr32(1, 5)); | |
| 257 EXPECT_EQ(0xffe2e2e2, *bitmap.getAddr32(2, 5)); | |
| 258 EXPECT_EQ(0xffdddddd, *bitmap.getAddr32(3, 5)); | |
| 259 | |
| 260 // Test row 6: Invert lightness plus increased contrast. | |
| 261 EXPECT_EQ(0xffffffff, *bitmap.getAddr32(0, 6)); | |
| 262 EXPECT_EQ(0xff000000, *bitmap.getAddr32(1, 6)); | |
| 263 EXPECT_EQ(0xffff0000, *bitmap.getAddr32(2, 6)); | |
| 264 EXPECT_EQ(0xffeeeeee, *bitmap.getAddr32(3, 6)); | |
| 265 } | |
| 266 | |
| 144 } // namespace blink | 267 } // namespace blink |
| OLD | NEW |