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

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

Issue 23643003: ImageBuffer-less SVG masking and clipping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix the Win build. Created 7 years, 3 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 /* 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 context.restore(); 208 context.restore();
209 209
210 // Another non-rectangular clip. 210 // Another non-rectangular clip.
211 context.save(); 211 context.save();
212 context.clip(IntRect(30, 30, 20, 20)); 212 context.clip(IntRect(30, 30, 20, 20));
213 context.clipOut(IntRect(30, 30, 10, 10)); 213 context.clipOut(IntRect(30, 30, 10, 10));
214 context.fillRect(FloatRect(10, 10, 90, 90), opaque, CompositeSourceOver); 214 context.fillRect(FloatRect(10, 10, 90, 90), opaque, CompositeSourceOver);
215 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 215 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
216 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); 216 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect());
217 context.restore(); 217 context.restore();
218
219 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100));
220 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha);
221
222 // Clipping with a non-opaque Image (there is no way to mark an ImageBuffer as opaque today).
223 context.save();
224 context.clipToImageBuffer(alphaImage.get(), FloatRect(30, 30, 10, 10));
225 context.fillRect(FloatRect(10, 10, 90, 90), opaque, CompositeSourceOver);
226 context.restore();
227 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
228 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect());
229 } 218 }
230 219
231 TEST(GraphicsContextTest, trackImageMask) 220 TEST(GraphicsContextTest, trackImageMask)
232 { 221 {
233 SkBitmap bitmap; 222 SkBitmap bitmap;
234 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400); 223 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
235 bitmap.allocPixels(); 224 bitmap.allocPixels();
236 bitmap.eraseColor(0); 225 bitmap.eraseColor(0);
237 SkCanvas canvas(bitmap); 226 SkCanvas canvas(bitmap);
238 227
(...skipping 13 matching lines...) Expand all
252 241
253 context.setCompositeOperation(CompositeDestinationIn); 242 context.setCompositeOperation(CompositeDestinationIn);
254 context.beginTransparencyLayer(1); 243 context.beginTransparencyLayer(1);
255 244
256 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100)); 245 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100));
257 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha); 246 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha);
258 247
259 context.setCompositeOperation(CompositeSourceOver); 248 context.setCompositeOperation(CompositeSourceOver);
260 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10)); 249 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10));
261 250
262 context.endTransparencyLayer(); 251 context.endLayer();
263 context.endTransparencyLayer(); 252 context.endLayer();
264 253
265 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 254 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
266 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); 255 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect());
267 } 256 }
268 257
269 TEST(GraphicsContextTest, trackImageMaskWithOpaqueRect) 258 TEST(GraphicsContextTest, trackImageMaskWithOpaqueRect)
270 { 259 {
271 SkBitmap bitmap; 260 SkBitmap bitmap;
272 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400); 261 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
273 bitmap.allocPixels(); 262 bitmap.allocPixels();
(...skipping 19 matching lines...) Expand all
293 282
294 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100)); 283 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100));
295 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha); 284 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha);
296 285
297 context.setCompositeOperation(CompositeSourceOver); 286 context.setCompositeOperation(CompositeSourceOver);
298 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10)); 287 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10));
299 288
300 // We can't have an opaque mask actually, but we can pretend here like it wo uld look if we did. 289 // We can't have an opaque mask actually, but we can pretend here like it wo uld look if we did.
301 context.fillRect(FloatRect(12, 12, 3, 3), opaque, CompositeSourceOver); 290 context.fillRect(FloatRect(12, 12, 3, 3), opaque, CompositeSourceOver);
302 291
303 context.endTransparencyLayer(); 292 context.endLayer();
304 context.endTransparencyLayer(); 293 context.endLayer();
305 294
306 EXPECT_EQ_RECT(IntRect(12, 12, 3, 3), context.opaqueRegion().asRect()); 295 EXPECT_EQ_RECT(IntRect(12, 12, 3, 3), context.opaqueRegion().asRect());
307 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); 296 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect());
308 } 297 }
309 298
310 TEST(GraphicsContextTest, trackOpaqueJoinTest) 299 TEST(GraphicsContextTest, trackOpaqueJoinTest)
311 { 300 {
312 SkBitmap bitmap; 301 SkBitmap bitmap;
313 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400); 302 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
314 bitmap.allocPixels(); 303 bitmap.allocPixels();
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 EXPECT_EQ_RECT(IntRect(20, 20, 10, 10), context.opaqueRegion().asRect()); 942 EXPECT_EQ_RECT(IntRect(20, 20, 10, 10), context.opaqueRegion().asRect());
954 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); 943 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect());
955 944
956 context.clearRect(FloatRect(20, 20, 10, 10)); 945 context.clearRect(FloatRect(20, 20, 10, 10));
957 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 946 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
958 947
959 context.beginTransparencyLayer(0.5); 948 context.beginTransparencyLayer(0.5);
960 context.save(); 949 context.save();
961 context.fillRect(FloatRect(20, 20, 10, 10), opaque, CompositeSourceOver); 950 context.fillRect(FloatRect(20, 20, 10, 10), opaque, CompositeSourceOver);
962 context.restore(); 951 context.restore();
963 context.endTransparencyLayer(); 952 context.endLayer();
964 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 953 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
965 954
966 context.clearRect(FloatRect(20, 20, 10, 10)); 955 context.clearRect(FloatRect(20, 20, 10, 10));
967 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 956 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
968 957
969 context.beginTransparencyLayer(0.5); 958 context.beginTransparencyLayer(0.5);
970 context.fillRect(FloatRect(20, 20, 10, 10), opaque, CompositeSourceOver); 959 context.fillRect(FloatRect(20, 20, 10, 10), opaque, CompositeSourceOver);
971 context.endTransparencyLayer(); 960 context.endLayer();
972 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 961 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
973 } 962 }
974 963
975 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) 964 TEST(GraphicsContextTest, UnboundedDrawsAreClipped)
976 { 965 {
977 SkBitmap bitmap; 966 SkBitmap bitmap;
978 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400); 967 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
979 bitmap.allocPixels(); 968 bitmap.allocPixels();
980 bitmap.eraseColor(0); 969 bitmap.eraseColor(0);
981 SkCanvas canvas(bitmap); 970 SkCanvas canvas(bitmap);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 1049
1061 // This should not destroy the device opaqueness. 1050 // This should not destroy the device opaqueness.
1062 context.fillRect(FloatRect(10, 10, 40, 40), opaque, CompositeSourceOver); 1051 context.fillRect(FloatRect(10, 10, 40, 40), opaque, CompositeSourceOver);
1063 1052
1064 // This should not destroy the device opaqueness either. 1053 // This should not destroy the device opaqueness either.
1065 context.setFillColor(opaque); 1054 context.setFillColor(opaque);
1066 path.moveTo(FloatPoint(10, 10)); 1055 path.moveTo(FloatPoint(10, 10));
1067 path.addLineTo(FloatPoint(40, 40)); 1056 path.addLineTo(FloatPoint(40, 40));
1068 context.strokePath(path); 1057 context.strokePath(path);
1069 1058
1070 context.endTransparencyLayer(); 1059 context.endLayer();
1071 context.endTransparencyLayer(); 1060 context.endLayer();
1072 EXPECT_EQ_RECT(IntRect(10, 10, 40, 40), context.opaqueRegion().asRect()); 1061 EXPECT_EQ_RECT(IntRect(10, 10, 40, 40), context.opaqueRegion().asRect());
1073 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); 1062 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect());
1074 1063
1075 // Now begin a layer that does not preserve opaque and draw through it to th e device. 1064 // Now begin a layer that does not preserve opaque and draw through it to th e device.
1076 context.setCompositeOperation(CompositeSourceOut); 1065 context.setCompositeOperation(CompositeSourceOut);
1077 context.beginTransparencyLayer(0.5); 1066 context.beginTransparencyLayer(0.5);
1078 1067
1079 // This should destroy the device opaqueness. 1068 // This should destroy the device opaqueness.
1080 context.fillRect(FloatRect(10, 10, 40, 40), opaque, CompositeSourceOver); 1069 context.fillRect(FloatRect(10, 10, 40, 40), opaque, CompositeSourceOver);
1081 1070
1082 context.endTransparencyLayer(); 1071 context.endLayer();
1083 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 1072 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
1084 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); 1073 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect());
1085 1074
1086 // Now we draw with a path for which it cannot compute fast bounds. This sho uld destroy the entire opaque region. 1075 // Now we draw with a path for which it cannot compute fast bounds. This sho uld destroy the entire opaque region.
1087 1076
1088 context.setCompositeOperation(CompositeSourceOut); 1077 context.setCompositeOperation(CompositeSourceOut);
1089 context.beginTransparencyLayer(0.5); 1078 context.beginTransparencyLayer(0.5);
1090 1079
1091 // This should nuke the device opaqueness. 1080 // This should nuke the device opaqueness.
1092 context.setFillColor(opaque); 1081 context.setFillColor(opaque);
1093 path.moveTo(FloatPoint(10, 10)); 1082 path.moveTo(FloatPoint(10, 10));
1094 path.addLineTo(FloatPoint(40, 40)); 1083 path.addLineTo(FloatPoint(40, 40));
1095 context.strokePath(path); 1084 context.strokePath(path);
1096 1085
1097 context.endTransparencyLayer(); 1086 context.endLayer();
1098 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); 1087 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect());
1099 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); 1088 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect());
1100 } 1089 }
1101 1090
1102 } // namespace 1091 } // namespace
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContextState.h ('k') | Source/core/platform/graphics/GraphicsTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698