OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrReducedClip.h" | 10 #include "GrReducedClip.h" |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 } | 999 } |
1000 | 1000 |
1001 REPORTER_ASSERT(reporter, region == reducedRegion); | 1001 REPORTER_ASSERT(reporter, region == reducedRegion); |
1002 } | 1002 } |
1003 } | 1003 } |
1004 | 1004 |
1005 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { | 1005 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { |
1006 { | 1006 { |
1007 SkClipStack stack; | 1007 SkClipStack stack; |
1008 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O
p, true); | 1008 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O
p, true); |
1009 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 50.3, 50.3), SkRegion::kReplace
_Op, true); | 1009 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 50.3f, 50.3f), SkRegion::kRepla
ce_Op, true); |
1010 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 1010 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
1011 | 1011 |
1012 GrReducedClip::ElementList reducedClips; | 1012 GrReducedClip::ElementList reducedClips; |
1013 int32_t reducedGenID; | 1013 int32_t reducedGenID; |
1014 GrReducedClip::InitialState initial; | 1014 GrReducedClip::InitialState initial; |
1015 SkIRect tightBounds; | 1015 SkIRect tightBounds; |
1016 | 1016 |
1017 GrReducedClip::ReduceClipStack(stack, | 1017 GrReducedClip::ReduceClipStack(stack, |
1018 inflatedIBounds, | 1018 inflatedIBounds, |
1019 &reducedClips, | 1019 &reducedClips, |
1020 &reducedGenID, | 1020 &reducedGenID, |
1021 &initial, | 1021 &initial, |
1022 &tightBounds); | 1022 &tightBounds); |
1023 | 1023 |
1024 REPORTER_ASSERT(reporter, reducedClips.count() == 1); | 1024 REPORTER_ASSERT(reporter, reducedClips.count() == 1); |
1025 // Clips will be cached based on the generation id. Make sure the gen id
is valid. | 1025 // Clips will be cached based on the generation id. Make sure the gen id
is valid. |
1026 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); | 1026 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); |
1027 } | 1027 } |
1028 { | 1028 { |
1029 SkClipStack stack; | 1029 SkClipStack stack; |
1030 | 1030 |
1031 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: | 1031 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: |
1032 // A B | 1032 // A B |
1033 // C D | 1033 // C D |
1034 | 1034 |
1035 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 25.3, 25.3), SkRegion::kReplace
_Op, true); | 1035 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 25.3f, 25.3f), SkRegion::kRepla
ce_Op, true); |
1036 int32_t genIDA = stack.getTopmostGenID(); | 1036 int32_t genIDA = stack.getTopmostGenID(); |
1037 stack.clipDevRect(SkRect::MakeXYWH(50, 0, 25.3, 25.3), SkRegion::kUnion_
Op, true); | 1037 stack.clipDevRect(SkRect::MakeXYWH(50, 0, 25.3f, 25.3f), SkRegion::kUnio
n_Op, true); |
1038 int32_t genIDB = stack.getTopmostGenID(); | 1038 int32_t genIDB = stack.getTopmostGenID(); |
1039 stack.clipDevRect(SkRect::MakeXYWH(0, 50, 25.3, 25.3), SkRegion::kUnion_
Op, true); | 1039 stack.clipDevRect(SkRect::MakeXYWH(0, 50, 25.3f, 25.3f), SkRegion::kUnio
n_Op, true); |
1040 int32_t genIDC = stack.getTopmostGenID(); | 1040 int32_t genIDC = stack.getTopmostGenID(); |
1041 stack.clipDevRect(SkRect::MakeXYWH(50, 50, 25.3, 25.3), SkRegion::kUnion
_Op, true); | 1041 stack.clipDevRect(SkRect::MakeXYWH(50, 50, 25.3f, 25.3f), SkRegion::kUni
on_Op, true); |
1042 int32_t genIDD = stack.getTopmostGenID(); | 1042 int32_t genIDD = stack.getTopmostGenID(); |
1043 | 1043 |
| 1044 #define XYWH SkIRect::MakeXYWH |
| 1045 |
| 1046 SkIRect unused; |
| 1047 unused.setEmpty(); |
| 1048 SkIRect stackBounds = XYWH(0, 0, 76, 76); |
| 1049 |
1044 // The base test is to test each rect in two ways: | 1050 // The base test is to test each rect in two ways: |
1045 // 1) The box dimensions. (Should reduce to "all in", no elements). | 1051 // 1) The box dimensions. (Should reduce to "all in", no elements). |
1046 // 2) A bit over the box dimensions. | 1052 // 2) A bit over the box dimensions. |
1047 // In the case 2, test that the generation id is what is expected. | 1053 // In the case 2, test that the generation id is what is expected. |
1048 // The rects are of fractional size so that case 2 never gets optimized
to an empty element | 1054 // The rects are of fractional size so that case 2 never gets optimized
to an empty element |
1049 // list. | 1055 // list. |
1050 | 1056 |
1051 // Not passing in tighter bounds is tested for consistency. | 1057 // Not passing in tighter bounds is tested for consistency. |
1052 struct GenIDTestCase { | 1058 struct { |
1053 SkIRect testBounds; | 1059 SkIRect testBounds; |
1054 int reducedClipCount; | 1060 int reducedClipCount; |
1055 int32_t reducedGenID; | 1061 int32_t reducedGenID; |
1056 GrReducedClip::InitialState initialState; | 1062 GrReducedClip::InitialState initialState; |
1057 SkIRect tighterBounds; // If this is empty, the query will not pass
tighter bounds | 1063 SkIRect tighterBounds; // If this is empty, the query will not pass
tighter bounds |
1058 // parameter. | 1064 // parameter. |
1059 }; | 1065 } testCases[] = { |
1060 | |
1061 #define XYWH SkIRect::MakeXYWH | |
1062 | |
1063 SkIRect unused; | |
1064 unused.setEmpty(); | |
1065 SkIRect stackBounds = XYWH(0, 0, 76, 76); | |
1066 | |
1067 GenIDTestCase testCases[] = { | |
1068 // Rect A. | 1066 // Rect A. |
1069 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, XYWH(0, 0, 25, 25) }, | 1067 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, XYWH(0, 0, 25, 25) }, |
1070 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, unused }, | 1068 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, unused }, |
1071 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, XYWH(0, 0, 27, 27)}, | 1069 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, XYWH(0, 0, 27, 27)}, |
1072 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, unused }, | 1070 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, unused }, |
1073 | 1071 |
1074 // Rect B. | 1072 // Rect B. |
1075 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(50, 0, 25, 25) }, | 1073 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(50, 0, 25, 25) }, |
1076 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, unused }, | 1074 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, unused }, |
1077 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat
e, XYWH(50, 0, 26, 27) }, | 1075 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat
e, XYWH(50, 0, 26, 27) }, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 test_quickContains(reporter); | 1199 test_quickContains(reporter); |
1202 #if SK_SUPPORT_GPU | 1200 #if SK_SUPPORT_GPU |
1203 test_reduced_clip_stack(reporter); | 1201 test_reduced_clip_stack(reporter); |
1204 test_reduced_clip_stack_genid(reporter); | 1202 test_reduced_clip_stack_genid(reporter); |
1205 test_reduced_clip_stack_no_aa_crash(reporter); | 1203 test_reduced_clip_stack_no_aa_crash(reporter); |
1206 #endif | 1204 #endif |
1207 } | 1205 } |
1208 | 1206 |
1209 #include "TestClassDef.h" | 1207 #include "TestClassDef.h" |
1210 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) | 1208 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) |
OLD | NEW |