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

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

Issue 317663005: Scale the ALPHA_THRESHOLD filter's region based on the device scale factor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use SkMatrix when creating AlphaFilter Created 6 years, 5 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 | Annotate | Revision Log
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 "cc/output/filter_operations.h" 5 #include "cc/output/filter_operations.h"
6 #include "skia/ext/refptr.h" 6 #include "skia/ext/refptr.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 8 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
9 #include "ui/gfx/point.h" 9 #include "ui/gfx/point.h"
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 SAVE_RESTORE_OFFSET_AMOUNT_COLOR( 133 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
134 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00); 134 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00);
135 135
136 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 136 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
137 17, 18, 19, 20}; 137 17, 18, 19, 20};
138 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix); 138 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix);
139 139
140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32); 140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32);
141 } 141 }
142 142
143 TEST(FilterOperationsTest, SaveAndRestoreAlphaThreshold) {
144 SkRegion region(SkIRect::MakeLTRB(20, 10, 300, 200));
145 float inner = 0.6f;
146 float outer = 0.3f;
147
148 FilterOperation op =
149 FilterOperation::CreateAlphaThresholdFilter(region, inner, outer);
150 EXPECT_EQ(FilterOperation::ALPHA_THRESHOLD, op.type());
151 EXPECT_EQ(region, op.region());
152 EXPECT_EQ(inner, op.amount());
153 EXPECT_EQ(outer, op.outer_threshold());
154
155 FilterOperation op2 = FilterOperation::CreateEmptyFilter();
156 op2.set_type(FilterOperation::ALPHA_THRESHOLD);
157
158 EXPECT_NE(region, op2.region());
159 EXPECT_NE(inner, op2.amount());
160 EXPECT_NE(outer, op2.outer_threshold());
161
162 op2.set_region(region);
163 op2.set_amount(inner);
164 op2.set_outer_threshold(outer);
165
166 EXPECT_EQ(FilterOperation::ALPHA_THRESHOLD, op2.type());
167 EXPECT_EQ(region, op2.region());
168 EXPECT_EQ(inner, op2.amount());
169 EXPECT_EQ(outer, op2.outer_threshold());
170 }
171
143 TEST(FilterOperationsTest, BlendGrayscaleFilters) { 172 TEST(FilterOperationsTest, BlendGrayscaleFilters) {
144 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f); 173 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f);
145 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f); 174 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f);
146 175
147 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); 176 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
148 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f); 177 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f);
149 EXPECT_EQ(expected, blended); 178 EXPECT_EQ(expected, blended);
150 179
151 blended = FilterOperation::Blend(&from, &to, 0.75); 180 blended = FilterOperation::Blend(&from, &to, 0.75);
152 expected = FilterOperation::CreateGrayscaleFilter(0.625f); 181 expected = FilterOperation::CreateGrayscaleFilter(0.625f);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 EXPECT_EQ(filter, blended); 565 EXPECT_EQ(filter, blended);
537 blended = FilterOperation::Blend(&filter, NULL, 0.75); 566 blended = FilterOperation::Blend(&filter, NULL, 0.75);
538 EXPECT_EQ(null_filter, blended); 567 EXPECT_EQ(null_filter, blended);
539 568
540 blended = FilterOperation::Blend(NULL, &filter, 0.25); 569 blended = FilterOperation::Blend(NULL, &filter, 0.25);
541 EXPECT_EQ(null_filter, blended); 570 EXPECT_EQ(null_filter, blended);
542 blended = FilterOperation::Blend(NULL, &filter, 0.75); 571 blended = FilterOperation::Blend(NULL, &filter, 0.75);
543 EXPECT_EQ(filter, blended); 572 EXPECT_EQ(filter, blended);
544 } 573 }
545 574
575 TEST(FilterOperationsTest, BlendAlphaThresholdFilters) {
576 SkRegion start_region(SkIRect::MakeLTRB(15, 5, 200, 100));
577 SkRegion end_region(SkIRect::MakeLTRB(20, 10, 300, 200));
578
579 FilterOperation from =
580 FilterOperation::CreateAlphaThresholdFilter(start_region, 0.25f, 0.25f);
581 FilterOperation to =
582 FilterOperation::CreateAlphaThresholdFilter(end_region, 0.75f, 0.75f);
583
584 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
585 FilterOperation expected =
586 FilterOperation::CreateAlphaThresholdFilter(start_region, 0.f, 0.f);
587 EXPECT_EQ(expected, blended);
588
589 blended = FilterOperation::Blend(&from, &to, 0.25);
590 expected =
591 FilterOperation::CreateAlphaThresholdFilter(start_region, 0.375f, 0.375f);
592 EXPECT_EQ(expected, blended);
593
594 blended = FilterOperation::Blend(&from, &to, 0.75);
595 expected =
596 FilterOperation::CreateAlphaThresholdFilter(end_region, 0.625f, 0.625f);
597 EXPECT_EQ(expected, blended);
598
599 blended = FilterOperation::Blend(&from, &to, 1.8);
600 expected = FilterOperation::CreateAlphaThresholdFilter(end_region, 1.f, 1.f);
601 EXPECT_EQ(expected, blended);
602 }
603
546 // Tests blending non-empty sequences that have the same length and matching 604 // Tests blending non-empty sequences that have the same length and matching
547 // operations. 605 // operations.
548 TEST(FilterOperationsTest, BlendMatchingSequences) { 606 TEST(FilterOperationsTest, BlendMatchingSequences) {
549 FilterOperations from; 607 FilterOperations from;
550 FilterOperations to; 608 FilterOperations to;
551 609
552 from.Append(FilterOperation::CreateBlurFilter(0.f)); 610 from.Append(FilterOperation::CreateBlurFilter(0.f));
553 to.Append(FilterOperation::CreateBlurFilter(2.f)); 611 to.Append(FilterOperation::CreateBlurFilter(2.f));
554 612
555 from.Append(FilterOperation::CreateSaturateFilter(4.f)); 613 from.Append(FilterOperation::CreateSaturateFilter(4.f));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 blended = to.Blend(from, -0.75); 752 blended = to.Blend(from, -0.75);
695 EXPECT_EQ(to, blended); 753 EXPECT_EQ(to, blended);
696 blended = to.Blend(from, 0.75); 754 blended = to.Blend(from, 0.75);
697 EXPECT_EQ(to, blended); 755 EXPECT_EQ(to, blended);
698 blended = to.Blend(from, 1.5); 756 blended = to.Blend(from, 1.5);
699 EXPECT_EQ(to, blended); 757 EXPECT_EQ(to, blended);
700 } 758 }
701 759
702 } // namespace 760 } // namespace
703 } // namespace cc 761 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698