diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-15 14:40:46 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-15 14:40:46 +0000 |
commit | 1a38d5508f7a0e2c186d3aa8ea807045a46b663d (patch) | |
tree | 175be595d3de79d1cf2a33431bbde1cfef0ce508 | |
parent | 0724f4320d4f8c67d26c77594cca7fd030f4be1d (diff) |
Perform degenerate check in device coords in convex path renderer
Review URL: http://codereview.appspot.com/5821053/
git-svn-id: http://skia.googlecode.com/svn/trunk@3401 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/bigmatrix.cpp | 97 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 | ||||
-rw-r--r-- | src/gpu/GrAAConvexPathRenderer.cpp | 7 |
3 files changed, 102 insertions, 3 deletions
diff --git a/gm/bigmatrix.cpp b/gm/bigmatrix.cpp new file mode 100644 index 0000000000..776566848e --- /dev/null +++ b/gm/bigmatrix.cpp @@ -0,0 +1,97 @@ + +/* + * 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 "SkColorPriv.h" +#include "SkShader.h" + +namespace skiagm { + +class BigMatrixGM : public GM { +public: + BigMatrixGM() { + this->setBGColor(0xFF66AA99); + } + +protected: + virtual SkString onShortName() { + return SkString("bigmatrix"); + } + + virtual SkISize onISize() { + return make_isize(50, 50); + } + + virtual void onDraw(SkCanvas* canvas) { + SkMatrix m; + m.reset(); + m.setRotate(33 * SK_Scalar1); + m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1); + m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1); + canvas->concat(m); + + SkPaint paint; + paint.setColor(SK_ColorRED); + paint.setAntiAlias(true); + + m.invert(&m); + + SkPath path; + + SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1}; + SkScalar small = 1 / (500 * SK_Scalar1); + + m.mapPoints(&pt, 1); + path.addCircle(pt.fX, pt.fY, small); + canvas->drawPath(path, paint); + + pt.set(30 * SK_Scalar1, 10 * SK_Scalar1); + m.mapPoints(&pt, 1); + SkRect rect = {pt.fX - small, pt.fY - small, + pt.fX + small, pt.fY + small}; + canvas->drawRect(rect, paint); + + SkBitmap bmp; + bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); + bmp.allocPixels(); + bmp.lockPixels(); + uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); + pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00); + pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00); + pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00); + pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF); + bmp.unlockPixels(); + pt.set(30 * SK_Scalar1, 30 * SK_Scalar1); + m.mapPoints(&pt, 1); + SkShader* shader = SkShader::CreateBitmapShader( + bmp, + SkShader::kRepeat_TileMode, + SkShader::kRepeat_TileMode); + SkMatrix s; + s.reset(); + s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000); + shader->setLocalMatrix(s); + paint.setShader(shader)->unref(); + paint.setAntiAlias(false); + paint.setFilterBitmap(true); + rect.setLTRB(pt.fX - small, pt.fY - small, + pt.fX + small, pt.fY + small); + canvas->drawRect(rect, paint); + } + +private: + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return new BigMatrixGM; } +static GMRegistry reg(MyFactory); + +} + diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index dd49af4d63..ec223fb07b 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -4,6 +4,7 @@ '../gm/aaclip.cpp', '../gm/aarectmodes.cpp', '../gm/arithmode.cpp', + '../gm/bigmatrix.cpp', '../gm/bitmapcopy.cpp', '../gm/bitmapfilters.cpp', '../gm/bitmapscroll.cpp', diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 22a1bb5070..45ef699b11 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -242,32 +242,33 @@ bool get_segments(const GrPath& path, GrPathCmd cmd = (GrPathCmd)iter.next(pts); switch (cmd) { case kMove_PathCmd: + m.mapPoints(pts, 1); update_degenerate_test(°enerateData, pts[0]); break; case kLine_PathCmd: { - update_degenerate_test(°enerateData, pts[1]); m.mapPoints(pts + 1, 1); + update_degenerate_test(°enerateData, pts[1]); segments->push_back(); segments->back().fType = Segment::kLine; segments->back().fPts[0] = pts[1]; break; } case kQuadratic_PathCmd: + m.mapPoints(pts + 1, 2); update_degenerate_test(°enerateData, pts[1]); update_degenerate_test(°enerateData, pts[2]); - m.mapPoints(pts + 1, 2); segments->push_back(); segments->back().fType = Segment::kQuad; segments->back().fPts[0] = pts[1]; segments->back().fPts[1] = pts[2]; break; case kCubic_PathCmd: { + m.mapPoints(pts, 4); update_degenerate_test(°enerateData, pts[1]); update_degenerate_test(°enerateData, pts[2]); update_degenerate_test(°enerateData, pts[3]); // unlike quads and lines, the pts[0] will also be read (in // convertCubicToQuads). - m.mapPoints(pts, 4); SkSTArray<15, SkPoint, true> quads; GrPathUtils::convertCubicToQuads(pts, SK_Scalar1, &quads); int count = quads.count(); |