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

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

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

Powered by Google App Engine
This is Rietveld 408576698