| OLD | NEW |
| 1 | 1 |
| 2 | 2 |
| 3 /* | 3 /* |
| 4 * Copyright 2012 Google Inc. | 4 * Copyright 2012 Google Inc. |
| 5 * | 5 * |
| 6 * Use of this source code is governed by a BSD-style license that can be | 6 * Use of this source code is governed by a BSD-style license that can be |
| 7 * found in the LICENSE file. | 7 * found in the LICENSE file. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #include "gm.h" | 10 #include "gm.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 SkString onShortName() { | 22 SkString onShortName() { |
| 23 return SkString("distantclip"); | 23 return SkString("distantclip"); |
| 24 } | 24 } |
| 25 | 25 |
| 26 SkISize onISize() { return make_isize(100, 100); } | 26 SkISize onISize() { return make_isize(100, 100); } |
| 27 | 27 |
| 28 virtual void onDraw(SkCanvas* canvas) { | 28 virtual void onDraw(SkCanvas* canvas) { |
| 29 int offset = 35000; | 29 int offset = 35000; |
| 30 int extents = 1000; | 30 int extents = 1000; |
| 31 | 31 |
| 32 SkPictureRecorder recorder; |
| 32 // We record a picture of huge vertical extents in which we clear the ca
nvas to red, create | 33 // We record a picture of huge vertical extents in which we clear the ca
nvas to red, create |
| 33 // a 'extents' by 'extents' round rect clip at a vertical offset of 'off
set', then draw | 34 // a 'extents' by 'extents' round rect clip at a vertical offset of 'off
set', then draw |
| 34 // green into that. | 35 // green into that. |
| 35 SkPicture pict; | 36 SkCanvas* rec = recorder.beginRecording(100, offset + extents); |
| 36 SkCanvas* rec = pict.beginRecording(100, offset + extents); | |
| 37 rec->drawColor(0xffff0000); | 37 rec->drawColor(0xffff0000); |
| 38 rec->save(); | 38 rec->save(); |
| 39 SkRect r = { | 39 SkRect r = { |
| 40 SkIntToScalar(-extents), | 40 SkIntToScalar(-extents), |
| 41 SkIntToScalar(offset - extents), | 41 SkIntToScalar(offset - extents), |
| 42 SkIntToScalar(extents), | 42 SkIntToScalar(extents), |
| 43 SkIntToScalar(offset + extents) | 43 SkIntToScalar(offset + extents) |
| 44 }; | 44 }; |
| 45 SkPath p; | 45 SkPath p; |
| 46 p.addRoundRect(r, 5, 5); | 46 p.addRoundRect(r, 5, 5); |
| 47 rec->clipPath(p, SkRegion::kIntersect_Op, true); | 47 rec->clipPath(p, SkRegion::kIntersect_Op, true); |
| 48 rec->drawColor(0xff00ff00); | 48 rec->drawColor(0xff00ff00); |
| 49 rec->restore(); | 49 rec->restore(); |
| 50 pict.endRecording(); | 50 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
| 51 | 51 |
| 52 // Next we play that picture into another picture of the same size. | 52 // Next we play that picture into another picture of the same size. |
| 53 SkPicture pict2; | 53 pict->draw(recorder.beginRecording(100, offset + extents)); |
| 54 pict.draw(pict2.beginRecording(100, offset + extents)); | 54 SkAutoTUnref<SkPicture> pict2(recorder.endRecording()); |
| 55 pict2.endRecording(); | |
| 56 | 55 |
| 57 // Finally we play the part of that second picture that should be green
into the canvas. | 56 // Finally we play the part of that second picture that should be green
into the canvas. |
| 58 canvas->save(); | 57 canvas->save(); |
| 59 canvas->translate(SkIntToScalar(extents / 2), | 58 canvas->translate(SkIntToScalar(extents / 2), |
| 60 SkIntToScalar(-(offset - extents / 2))); | 59 SkIntToScalar(-(offset - extents / 2))); |
| 61 pict2.draw(canvas); | 60 pict2->draw(canvas); |
| 62 canvas->restore(); | 61 canvas->restore(); |
| 63 | 62 |
| 64 // If the image is red, we erroneously decided the clipPath was empty an
d didn't record | 63 // If the image is red, we erroneously decided the clipPath was empty an
d didn't record |
| 65 // the green drawColor, if it's green we're all good. | 64 // the green drawColor, if it's green we're all good. |
| 66 } | 65 } |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 typedef GM INHERITED; | 68 typedef GM INHERITED; |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
| 73 | 72 |
| 74 static GM* MyFactory(void*) { return new DistantClipGM; } | 73 static GM* MyFactory(void*) { return new DistantClipGM; } |
| 75 static GMRegistry reg(MyFactory); | 74 static GMRegistry reg(MyFactory); |
| 76 | 75 |
| 77 } | 76 } |
| OLD | NEW |