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

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

Issue 2743363006: Clean up cc/paint interfaces (Closed)
Patch Set: Fix PaintControllerTest v2 Created 3 years, 9 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 SkiaPaintCanvas canvas(bitmap); 74 SkiaPaintCanvas canvas(bitmap);
75 75
76 std::unique_ptr<PaintController> paintController = PaintController::create(); 76 std::unique_ptr<PaintController> paintController = PaintController::create();
77 GraphicsContext context(*paintController); 77 GraphicsContext context(*paintController);
78 78
79 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); 79 Color opaque(1.0f, 0.0f, 0.0f, 1.0f);
80 FloatRect bounds(0, 0, 100, 100); 80 FloatRect bounds(0, 0, 100, 100);
81 81
82 context.beginRecording(bounds); 82 context.beginRecording(bounds);
83 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkBlendMode::kSrcOver); 83 context.fillRect(FloatRect(0, 0, 50, 50), opaque, SkBlendMode::kSrcOver);
84 sk_sp<const PaintRecord> record = context.endRecording(); 84 canvas.drawPicture(context.endRecording());
85 canvas.drawPicture(record.get());
86 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) 85 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50))
87 86
88 context.beginRecording(bounds); 87 context.beginRecording(bounds);
89 context.fillRect(FloatRect(0, 0, 100, 100), opaque, SkBlendMode::kSrcOver); 88 context.fillRect(FloatRect(0, 0, 100, 100), opaque, SkBlendMode::kSrcOver);
90 record = context.endRecording();
91 // Make sure the opaque region was unaffected by the rect drawn during 89 // Make sure the opaque region was unaffected by the rect drawn during
92 // recording. 90 // recording.
93 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50)) 91 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 50, 50))
94 92
95 canvas.drawPicture(record.get()); 93 canvas.drawPicture(context.endRecording());
96 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100)) 94 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(0, 0, 100, 100))
97 } 95 }
98 96
99 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) { 97 TEST(GraphicsContextTest, UnboundedDrawsAreClipped) {
100 SkBitmap bitmap; 98 SkBitmap bitmap;
101 bitmap.allocN32Pixels(400, 400); 99 bitmap.allocN32Pixels(400, 400);
102 bitmap.eraseColor(0); 100 bitmap.eraseColor(0);
103 SkiaPaintCanvas canvas(bitmap); 101 SkiaPaintCanvas canvas(bitmap);
104 102
105 Color opaque(1.0f, 0.0f, 0.0f, 1.0f); 103 Color opaque(1.0f, 0.0f, 0.0f, 1.0f);
(...skipping 11 matching lines...) Expand all
117 context.setStrokeStyle(SolidStroke); 115 context.setStrokeStyle(SolidStroke);
118 116
119 // Make skia unable to compute fast bounds for our paths. 117 // Make skia unable to compute fast bounds for our paths.
120 DashArray dashArray; 118 DashArray dashArray;
121 dashArray.push_back(1); 119 dashArray.push_back(1);
122 dashArray.push_back(0); 120 dashArray.push_back(0);
123 context.setLineDash(dashArray, 0); 121 context.setLineDash(dashArray, 0);
124 122
125 // Make the device opaque in 10,10 40x40. 123 // Make the device opaque in 10,10 40x40.
126 context.fillRect(FloatRect(10, 10, 40, 40), opaque, SkBlendMode::kSrcOver); 124 context.fillRect(FloatRect(10, 10, 40, 40), opaque, SkBlendMode::kSrcOver);
127 sk_sp<const PaintRecord> record = context.endRecording(); 125 canvas.drawPicture(context.endRecording());
128 canvas.drawPicture(record.get());
129 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(10, 10, 40, 40)); 126 EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(10, 10, 40, 40));
130 127
131 context.beginRecording(bounds); 128 context.beginRecording(bounds);
132 // Clip to the left edge of the opaque area. 129 // Clip to the left edge of the opaque area.
133 context.clip(IntRect(10, 10, 10, 40)); 130 context.clip(IntRect(10, 10, 10, 40));
134 131
135 // Draw a path that gets clipped. This should destroy the opaque area, but 132 // Draw a path that gets clipped. This should destroy the opaque area, but
136 // only inside the clip. 133 // only inside the clip.
137 Path path; 134 Path path;
138 path.moveTo(FloatPoint(10, 10)); 135 path.moveTo(FloatPoint(10, 10));
139 path.addLineTo(FloatPoint(40, 40)); 136 path.addLineTo(FloatPoint(40, 40));
140 PaintFlags flags; 137 PaintFlags flags;
141 flags.setColor(alpha.rgb()); 138 flags.setColor(alpha.rgb());
142 flags.setBlendMode(SkBlendMode::kSrcOut); 139 flags.setBlendMode(SkBlendMode::kSrcOut);
143 context.drawPath(path.getSkPath(), flags); 140 context.drawPath(path.getSkPath(), flags);
144 141
145 record = context.endRecording(); 142 canvas.drawPicture(context.endRecording());
146 canvas.drawPicture(record.get());
147 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); 143 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40));
148 } 144 }
149 145
150 } // namespace blink 146 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698