tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPath.h" |
| 11 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 12 | /** Draw a 2px border around the target, then red behind the target; |
| 13 | set the clip to match the target, then draw >> the target in blue. |
| 14 | */ |
| 15 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 16 | static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 17 | SkPaint borderPaint; |
| 18 | borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); |
| 19 | borderPaint.setAntiAlias(true); |
| 20 | SkPaint backgroundPaint; |
| 21 | backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0)); |
| 22 | backgroundPaint.setAntiAlias(true); |
| 23 | SkPaint foregroundPaint; |
| 24 | foregroundPaint.setColor(SkColorSetRGB(0x0, 0x0, 0xDD)); |
| 25 | foregroundPaint.setAntiAlias(true); |
| 26 | |
| 27 | canvas->save(); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 28 | canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 29 | target.inset(SkIntToScalar(-2), SkIntToScalar(-2)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 30 | canvas->drawRect(target, borderPaint); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 31 | target.inset(SkIntToScalar(2), SkIntToScalar(2)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 32 | canvas->drawRect(target, backgroundPaint); |
| 33 | canvas->clipRect(target, SkRegion::kIntersect_Op, true); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 34 | target.inset(SkIntToScalar(-4), SkIntToScalar(-4)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 35 | canvas->drawRect(target, foregroundPaint); |
| 36 | canvas->restore(); |
| 37 | } |
| 38 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 39 | static void draw_square(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 40 | SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 10 * SK_Scalar1)); |
| 41 | draw(canvas, target, x, y); |
| 42 | } |
| 43 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 44 | static void draw_column(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 45 | SkRect target (SkRect::MakeWH(1 * SK_Scalar1, 10 * SK_Scalar1)); |
| 46 | draw(canvas, target, x, y); |
| 47 | } |
| 48 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 49 | static void draw_bar(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 50 | SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 1 * SK_Scalar1)); |
| 51 | draw(canvas, target, x, y); |
| 52 | } |
| 53 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 54 | static void draw_rect_tests(SkCanvas* canvas) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 55 | draw_square(canvas, 10, 10); |
| 56 | draw_column(canvas, 30, 10); |
| 57 | draw_bar(canvas, 10, 30); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | Test a set of clipping problems discovered while writing blitAntiRect, |
| 62 | and test all the code paths through the clipping blitters. |
| 63 | Each region should show as a blue center surrounded by a 2px green |
| 64 | border, with no red. |
| 65 | */ |
| 66 | |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 67 | class AAClipGM : public skiagm::GM { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 68 | public: |
| 69 | AAClipGM() { |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 70 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | protected: |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 74 | virtual SkString onShortName() SK_OVERRIDE { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 75 | return SkString("aaclip"); |
| 76 | } |
| 77 | |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 78 | virtual SkISize onISize() SK_OVERRIDE { |
| 79 | return SkISize::Make(640, 480); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 80 | } |
| 81 | |
reed@google.com | b6399a7 | 2013-01-28 16:57:29 +0000 | [diff] [blame] | 82 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 83 | // Initial pixel-boundary-aligned draw |
| 84 | draw_rect_tests(canvas); |
| 85 | |
| 86 | // Repeat 4x with .2, .4, .6, .8 px offsets |
| 87 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 88 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 89 | draw_rect_tests(canvas); |
| 90 | |
| 91 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 92 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 93 | draw_rect_tests(canvas); |
| 94 | |
| 95 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 96 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 97 | draw_rect_tests(canvas); |
| 98 | |
| 99 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 100 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 101 | draw_rect_tests(canvas); |
| 102 | } |
| 103 | |
borenet@google.com | b4e7043 | 2012-07-20 18:45:10 +0000 | [diff] [blame] | 104 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 105 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 106 | private: |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 107 | typedef skiagm::GM INHERITED; |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 110 | DEF_GM( return SkNEW(AAClipGM); ) |