rileya@google.com | ffadfb5 | 2012-09-14 13:53:36 +0000 | [diff] [blame] | 1 | |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 Google Inc. |
| 5 | * |
| 6 | * Use of this source code is governed by a BSD-style license that can be |
| 7 | * found in the LICENSE file. |
| 8 | */ |
| 9 | |
| 10 | #include "gm.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkPicture.h" |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | class DistantClipGM : public GM { |
| 17 | public: |
| 18 | DistantClipGM() { } |
| 19 | |
| 20 | protected: |
| 21 | |
| 22 | SkString onShortName() { |
| 23 | return SkString("distantclip"); |
| 24 | } |
| 25 | |
| 26 | SkISize onISize() { return make_isize(100, 100); } |
| 27 | |
| 28 | virtual void onDraw(SkCanvas* canvas) { |
| 29 | int offset = 35000; |
| 30 | int extents = 1000; |
| 31 | |
| 32 | // We record a picture of huge vertical extents in which we clear the canvas to red, create |
| 33 | // a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw |
| 34 | // green into that. |
| 35 | SkPicture pict; |
| 36 | SkCanvas* rec = pict.beginRecording(100, offset + extents); |
| 37 | rec->drawColor(0xffff0000); |
| 38 | rec->save(); |
| 39 | SkRect r = {-extents, offset - extents, extents, offset + extents}; |
| 40 | SkPath p; |
| 41 | p.addRoundRect(r, 5, 5); |
| 42 | rec->clipPath(p, SkRegion::kIntersect_Op, true); |
| 43 | rec->drawColor(0xff00ff00); |
| 44 | rec->restore(); |
| 45 | pict.endRecording(); |
| 46 | |
| 47 | // Next we play that picture into another picture of the same size. |
| 48 | SkPicture pict2; |
| 49 | pict.draw(pict2.beginRecording(100, offset + extents)); |
| 50 | pict2.endRecording(); |
| 51 | |
| 52 | // Finally we play the part of that second picture that should be green into the canvas. |
| 53 | canvas->save(); |
| 54 | canvas->translate(extents / 2, -(offset - extents / 2)); |
rileya@google.com | 71e21ba | 2012-09-14 14:24:14 +0000 | [diff] [blame^] | 55 | pict2.draw(canvas); |
rileya@google.com | ffadfb5 | 2012-09-14 13:53:36 +0000 | [diff] [blame] | 56 | canvas->restore(); |
| 57 | |
| 58 | // If the image is red, we erroneously decided the clipPath was empty and didn't record |
| 59 | // the green drawColor, if it's green we're all good. |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | typedef GM INHERITED; |
| 64 | }; |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | |
| 68 | static GM* MyFactory(void*) { return new DistantClipGM; } |
| 69 | static GMRegistry reg(MyFactory); |
| 70 | |
| 71 | } |