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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 context.setFillColor(opaque); | 1035 context.setFillColor(opaque); |
| 1036 path.moveTo(FloatPoint(10, 10)); | 1036 path.moveTo(FloatPoint(10, 10)); |
| 1037 path.addLineTo(FloatPoint(40, 40)); | 1037 path.addLineTo(FloatPoint(40, 40)); |
| 1038 context.strokePath(path); | 1038 context.strokePath(path); |
| 1039 | 1039 |
| 1040 context.endLayer(); | 1040 context.endLayer(); |
| 1041 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); | 1041 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); |
| 1042 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); | 1042 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 TEST(GraphicsContextTest, OpaqueRegionForLayer) | |
| 1046 { | |
| 1047 // For non-opaque preserving mode and deviceClip is not rect | |
| 1048 // we will mark opaque rect as empty. | |
| 1049 Path path; | |
| 1050 path.moveTo(FloatPoint(0, 0)); | |
| 1051 path.addLineTo(FloatPoint(50, 50)); | |
| 1052 | |
| 1053 SkCanvas canvas(400, 400); | |
| 1054 GraphicsContext context(&canvas); | |
| 1055 context.clipPath(path, RULE_EVENODD); | |
| 1056 context.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); | |
| 1057 | |
| 1058 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); | |
| 1059 | |
| 1060 context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); | |
|
danakj
2014/08/05 15:26:54
Can you EXPECT_EQ the opaqueRegion after this, and
sohanjg
2014/08/06 05:56:21
Done.
| |
| 1061 context.setCompositeOperation(CompositeSourceOut); | |
| 1062 context.beginTransparencyLayer(0.5); | |
| 1063 | |
| 1064 context.endLayer(); | |
| 1065 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); | |
| 1066 | |
| 1067 // For opaque preserving mode and deviceClip is not rect | |
| 1068 // we will not alter opaque rect. | |
| 1069 context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); | |
| 1070 context.setCompositeOperation(CompositeSourceOver); | |
| 1071 context.beginTransparencyLayer(0.5); | |
| 1072 | |
| 1073 context.endLayer(); | |
| 1074 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); | |
| 1075 | |
| 1076 SkBitmap bitmap; | |
| 1077 ASSERT_TRUE(bitmap.allocN32Pixels(400, 400)); | |
| 1078 bitmap.eraseColor(0); | |
| 1079 SkCanvas canvas2(bitmap); | |
| 1080 | |
| 1081 GraphicsContext context2(&canvas2); | |
| 1082 context2.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); | |
| 1083 | |
| 1084 // For non-opaque preserving mode and deviceClip is rect | |
| 1085 // we will mark device clip rect as non opaque. | |
| 1086 context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); | |
|
danakj
2014/08/05 15:26:54
Can you EXPECT_EQ the opaqueRegion after this, and
sohanjg
2014/08/05 16:48:12
this part has device clip as 'rect', we would need
danakj
2014/08/05 17:18:34
Oh, this is a different context, i missed that "2"
sohanjg
2014/08/06 05:56:21
Done.
| |
| 1087 context2.setCompositeOperation(CompositeSourceOut); | |
| 1088 context2.beginTransparencyLayer(0.5); | |
| 1089 | |
| 1090 context2.endLayer(); | |
| 1091 EXPECT_EQ_RECT(IntRect(), context2.opaqueRegion().asRect()); | |
| 1092 EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect()); | |
| 1093 | |
| 1094 // For opaque preserving mode and deviceClip is rect | |
| 1095 // we will intersect device clip rect with src opaque rect. | |
| 1096 context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); | |
| 1097 context2.setCompositeOperation(CompositeSourceOver); | |
| 1098 context2.beginTransparencyLayer(0.5); | |
| 1099 | |
| 1100 context2.endLayer(); | |
| 1101 EXPECT_EQ_RECT(IntRect(30, 30, 90, 90), context2.opaqueRegion().asRect()); | |
| 1102 EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect()); | |
| 1103 } | |
| 1104 | |
| 1045 #define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while (0); | 1105 #define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while (0); |
| 1046 #define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op( param1, param2); } while (0); | 1106 #define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op( param1, param2); } while (0); |
| 1047 | 1107 |
| 1048 TEST(GraphicsContextTest, RecordingTotalMatrix) | 1108 TEST(GraphicsContextTest, RecordingTotalMatrix) |
| 1049 { | 1109 { |
| 1050 SkBitmap bitmap; | 1110 SkBitmap bitmap; |
| 1051 ASSERT_TRUE(bitmap.allocN32Pixels(400, 400)); | 1111 ASSERT_TRUE(bitmap.allocN32Pixels(400, 400)); |
| 1052 bitmap.eraseColor(0); | 1112 bitmap.eraseColor(0); |
| 1053 SkCanvas canvas(bitmap); | 1113 SkCanvas canvas(bitmap); |
| 1054 GraphicsContext context(&canvas); | 1114 GraphicsContext context(&canvas); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 EXPECT_FALSE(pic); | 1174 EXPECT_FALSE(pic); |
| 1115 | 1175 |
| 1116 // endRecording finally makes the picture accessible | 1176 // endRecording finally makes the picture accessible |
| 1117 dl->endRecording(); | 1177 dl->endRecording(); |
| 1118 pic = dl->picture(); | 1178 pic = dl->picture(); |
| 1119 EXPECT_TRUE(pic); | 1179 EXPECT_TRUE(pic); |
| 1120 EXPECT_EQ(1, pic->getRefCnt()); | 1180 EXPECT_EQ(1, pic->getRefCnt()); |
| 1121 } | 1181 } |
| 1122 | 1182 |
| 1123 } // namespace | 1183 } // namespace |
| OLD | NEW |