blob: be77a87406168a4bae5463c96c38bf8d114c4bfa [file] [log] [blame]
fmalita1a178ca2015-01-15 06:01:23 -08001/*
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
13static 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
25static 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
49DEF_TEST(Rect, reporter) {
50 test_stroke_width_clipping(reporter);
51}