From ffadfb5d43a2b09394b4650829bcfc7329ed2d30 Mon Sep 17 00:00:00 2001 From: "rileya@google.com" Date: Fri, 14 Sep 2012 13:53:36 +0000 Subject: [PATCH] Add gm to test SkRegion/clipPath bug. Review URL: https://codereview.appspot.com/6501131 git-svn-id: http://skia.googlecode.com/svn/trunk@5540 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/distantclip.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++ gyp/gmslides.gypi | 1 + 2 files changed, 72 insertions(+) create mode 100644 gm/distantclip.cpp diff --git a/gm/distantclip.cpp b/gm/distantclip.cpp new file mode 100644 index 0000000000..b8a7c2b7b7 --- /dev/null +++ b/gm/distantclip.cpp @@ -0,0 +1,71 @@ + + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkPicture.h" + +namespace skiagm { + +class DistantClipGM : public GM { +public: + DistantClipGM() { } + +protected: + + SkString onShortName() { + return SkString("distantclip"); + } + + SkISize onISize() { return make_isize(100, 100); } + + virtual void onDraw(SkCanvas* canvas) { + int offset = 35000; + int extents = 1000; + + // We record a picture of huge vertical extents in which we clear the canvas to red, create + // a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw + // green into that. + SkPicture pict; + SkCanvas* rec = pict.beginRecording(100, offset + extents); + rec->drawColor(0xffff0000); + rec->save(); + SkRect r = {-extents, offset - extents, extents, offset + extents}; + SkPath p; + p.addRoundRect(r, 5, 5); + rec->clipPath(p, SkRegion::kIntersect_Op, true); + rec->drawColor(0xff00ff00); + rec->restore(); + pict.endRecording(); + + // Next we play that picture into another picture of the same size. + SkPicture pict2; + pict.draw(pict2.beginRecording(100, offset + extents)); + pict2.endRecording(); + + // Finally we play the part of that second picture that should be green into the canvas. + canvas->save(); + canvas->translate(extents / 2, -(offset - extents / 2)); + canvas->drawPicture(pict2); + canvas->restore(); + + // If the image is red, we erroneously decided the clipPath was empty and didn't record + // the green drawColor, if it's green we're all good. + } + +private: + typedef GM INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return new DistantClipGM; } +static GMRegistry reg(MyFactory); + +} diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index d80c123610..17a41c8ec9 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -22,6 +22,7 @@ '../gm/degeneratesegments.cpp', '../gm/dashcubics.cpp', '../gm/dashing.cpp', + '../gm/distantclip.cpp', '../gm/drawbitmaprect.cpp', '../gm/drawlooper.cpp', '../gm/extractbitmap.cpp', -- 2.34.1