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

Side by Side Diff: tests/RectTest.cpp

Issue 801353008: Use device-space stroke width for SkDraw::drawRect() quick-reject (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « src/core/SkDraw.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmap.h"
9 #include "SkCanvas.h"
10 #include "SkRect.h"
11 #include "Test.h"
12
13 static bool has_green_pixels(const SkBitmap& bm) {
14 for (int j = 0; j < bm.height(); ++j) {
15 for (int i = 0; i < bm.width(); ++i) {
16 if (SkColorGetG(bm.getColor(i, j))) {
17 return true;
18 }
19 }
20 }
21
22 return false;
23 }
24
25 static void test_stroke_width_clipping(skiatest::Reporter* reporter) {
26 SkBitmap bm;
27 bm.allocN32Pixels(100, 10);
28 bm.eraseColor(SK_ColorTRANSPARENT);
29
30 SkCanvas canvas(bm);
31 SkPaint paint;
32 paint.setStyle(SkPaint::kStroke_Style);
33 paint.setStrokeWidth(10);
34 paint.setColor(0xff00ff00);
35
36 // clip out the left half of our canvas
37 canvas.clipRect(SkRect::MakeXYWH(51, 0, 49, 100));
38
39 // no stroke bleed should be visible
40 canvas.drawRect(SkRect::MakeWH(44, 100), paint);
41 REPORTER_ASSERT(reporter, !has_green_pixels(bm));
42
43 // right stroke edge should bleed into the visible area
44 canvas.scale(2, 2);
45 canvas.drawRect(SkRect::MakeWH(22, 50), paint);
46 REPORTER_ASSERT(reporter, has_green_pixels(bm));
47 }
48
49 DEF_TEST(Rect, reporter) {
50 test_stroke_width_clipping(reporter);
51 }
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698