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

Side by Side Diff: Source/platform/graphics/GraphicsContextTest.cpp

Issue 417153002: Avoid passing uninitialized value to markRectAsNonOpaque. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Tests Updated. Created 6 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
OLDNEW
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
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 // Set non-rect device clip.
1048 Path path;
1049 path.moveTo(FloatPoint(0, 0));
1050 path.addLineTo(FloatPoint(50, 50));
1051
1052 SkCanvas canvas(50, 50);
danakj 2014/08/05 13:53:28 can you make the canvas bigger than the path's bou
sohanjg 2014/08/05 15:23:21 Done.
1053 GraphicsContext context(&canvas);
1054 context.clipPath(path, RULE_EVENODD);
1055 context.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque);
1056
1057 Color opaque(1.0f, 0.0f, 0.0f, 1.0f);
1058
1059 // Set Opaque Rect.
danakj 2014/08/05 13:53:28 Say why not what, all of these comments just say w
sohanjg 2014/08/05 15:23:20 Done.
1060 context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver);
danakj 2014/08/05 13:53:28 isn't this outside the bounds of the canvas?
sohanjg 2014/08/05 15:23:21 Done. I was trying to avoid markRectAsNonOpaque ea
1061 // Begin non-opaque-preserving layer.
1062 context.setCompositeOperation(CompositeSourceOut);
1063 context.beginTransparencyLayer(0.5);
1064
1065 context.endLayer();
1066 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
1067
1068 // Set rect device clip.
1069 SkBitmap bitmap;
1070 ASSERT_TRUE(bitmap.allocN32Pixels(50, 50));
1071 bitmap.eraseColor(0);
1072 SkCanvas canvas2(bitmap);
1073
1074 GraphicsContext context2(&canvas2);
1075 context2.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque);
1076
1077 // Set Opaque Rect.
1078 context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver);
1079 // Begin non-opaque-preserving layer.
1080 context2.setCompositeOperation(CompositeSourceOut);
1081 context2.beginTransparencyLayer(0.5);
1082
1083 context2.endLayer();
1084 EXPECT_EQ_RECT(IntRect(), context2.opaqueRegion().asRect());
1085 EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect());
1086
1087 // Set Opaque Rect.
1088 context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver);
1089 // Begin opaque-preserving layer.
1090 context2.setCompositeOperation(CompositeSourceOver);
1091 context2.beginTransparencyLayer(0.5);
1092
1093 context2.endLayer();
1094 EXPECT_EQ_RECT(IntRect(30, 30, 20, 20), context2.opaqueRegion().asRect());
1095 EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect());
1096 }
1097
1045 #define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while (0); 1098 #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); 1099 #define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op( param1, param2); } while (0);
1047 1100
1048 TEST(GraphicsContextTest, RecordingTotalMatrix) 1101 TEST(GraphicsContextTest, RecordingTotalMatrix)
1049 { 1102 {
1050 SkBitmap bitmap; 1103 SkBitmap bitmap;
1051 ASSERT_TRUE(bitmap.allocN32Pixels(400, 400)); 1104 ASSERT_TRUE(bitmap.allocN32Pixels(400, 400));
1052 bitmap.eraseColor(0); 1105 bitmap.eraseColor(0);
1053 SkCanvas canvas(bitmap); 1106 SkCanvas canvas(bitmap);
1054 GraphicsContext context(&canvas); 1107 GraphicsContext context(&canvas);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 EXPECT_FALSE(pic); 1167 EXPECT_FALSE(pic);
1115 1168
1116 // endRecording finally makes the picture accessible 1169 // endRecording finally makes the picture accessible
1117 dl->endRecording(); 1170 dl->endRecording();
1118 pic = dl->picture(); 1171 pic = dl->picture();
1119 EXPECT_TRUE(pic); 1172 EXPECT_TRUE(pic);
1120 EXPECT_EQ(1, pic->getRefCnt()); 1173 EXPECT_EQ(1, pic->getRefCnt());
1121 } 1174 }
1122 1175
1123 } // namespace 1176 } // namespace
OLDNEW
« no previous file with comments | « no previous file | Source/platform/graphics/RegionTracker.cpp » ('j') | Source/platform/graphics/RegionTracker.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698