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

Side by Side Diff: cc/output/filter_operations_unittest.cc

Issue 2231243002: Use CheckedNumeric when converting SkIRect to gfx::Rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make SkIRectToRect clamp Created 4 years, 4 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/skia_util.cc » ('j') | ui/gfx/skia_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/output/filter_operations.h" 7 #include "cc/output/filter_operations.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/core/SkXfermode.h"
9 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 10 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" 11 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
11 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" 12 #include "third_party/skia/include/effects/SkOffsetImageFilter.h"
13 #include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
12 #include "ui/gfx/geometry/point.h" 14 #include "ui/gfx/geometry/point.h"
13 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
14 16
15 namespace cc { 17 namespace cc {
16 namespace { 18 namespace {
17 19
18 TEST(FilterOperationsTest, GetOutsetsBlur) { 20 TEST(FilterOperationsTest, GetOutsetsBlur) {
19 FilterOperations ops; 21 FilterOperations ops;
20 ops.Append(FilterOperation::CreateBlurFilter(20)); 22 ops.Append(FilterOperation::CreateBlurFilter(20));
21 int top, right, bottom, left; 23 int top, right, bottom, left;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 TEST(FilterOperationsTest, MapRectReverseDropShadowDoesNotContract) { 271 TEST(FilterOperationsTest, MapRectReverseDropShadowDoesNotContract) {
270 // Even with a drop-shadow, the original content is still drawn. Thus the 272 // Even with a drop-shadow, the original content is still drawn. Thus the
271 // content bounds are never contracted due to a drop-shadow. 273 // content bounds are never contracted due to a drop-shadow.
272 FilterOperations ops; 274 FilterOperations ops;
273 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0)); 275 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
274 EXPECT_EQ(gfx::Rect(-3, -8, 13, 18), 276 EXPECT_EQ(gfx::Rect(-3, -8, 13, 18),
275 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 277 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
276 } 278 }
277 279
280 TEST(FilterOperationsTest, MapRectTypeConversionDoesNotOverflow) {
281 // Must be bigger than half of the positive range so that the width/height
282 // overflow happens, but small enough that there aren't other issues before
283 // the overflow would happen.
284 SkScalar big_offset =
285 SkFloatToScalar(std::numeric_limits<int>::max()) * 2 / 3;
286
287 FilterOperations ops;
288 ops.Append(FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
289 SkXfermode::Make(SkXfermode::kSrcOver_Mode),
290 SkOffsetImageFilter::Make(-big_offset, -big_offset, nullptr),
291 SkOffsetImageFilter::Make(big_offset, big_offset, nullptr), nullptr)));
292 gfx::Rect rect = ops.MapRect(gfx::Rect(-10, -10, 20, 20), SkMatrix::I());
293 EXPECT_GT(rect.width(), 0);
294 EXPECT_GT(rect.height(), 0);
295 }
296
278 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ 297 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
279 { \ 298 { \
280 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ 299 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
281 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ 300 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
282 EXPECT_EQ(a, op.amount()); \ 301 EXPECT_EQ(a, op.amount()); \
283 \ 302 \
284 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ 303 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
285 op2.set_type(FilterOperation::filter_type); \ 304 op2.set_type(FilterOperation::filter_type); \
286 \ 305 \
287 EXPECT_NE(a, op2.amount()); \ 306 EXPECT_NE(a, op2.amount()); \
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 blended = to.Blend(from, -0.75); 952 blended = to.Blend(from, -0.75);
934 EXPECT_EQ(to, blended); 953 EXPECT_EQ(to, blended);
935 blended = to.Blend(from, 0.75); 954 blended = to.Blend(from, 0.75);
936 EXPECT_EQ(to, blended); 955 EXPECT_EQ(to, blended);
937 blended = to.Blend(from, 1.5); 956 blended = to.Blend(from, 1.5);
938 EXPECT_EQ(to, blended); 957 EXPECT_EQ(to, blended);
939 } 958 }
940 959
941 } // namespace 960 } // namespace
942 } // namespace cc 961 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/skia_util.cc » ('j') | ui/gfx/skia_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698