From 14c3fc60b2779b5048df0b3a2569a462a298357c Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Tue, 19 Mar 2013 14:11:15 +0000 Subject: Adding rects-specific GM https://codereview.chromium.org/12934003/ git-svn-id: http://skia.googlecode.com/svn/trunk@8218 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/rects.cpp | 244 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 gm/rects.cpp (limited to 'gm/rects.cpp') diff --git a/gm/rects.cpp b/gm/rects.cpp new file mode 100644 index 0000000000..e059284099 --- /dev/null +++ b/gm/rects.cpp @@ -0,0 +1,244 @@ +/* + * Copyright 2013 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 "SkTArray.h" +#include "SkMatrix.h" +#include "SkBlurMaskFilter.h" +#include "SkGradientShader.h" +#include "SkBlurDrawLooper.h" + +namespace skiagm { + +class RectsGM : public GM { +public: + RectsGM() { + this->setBGColor(0xFF000000); + this->makePaints(); + this->makeMatrices(); + this->makeRects(); + } + +protected: + virtual SkString onShortName() SK_OVERRIDE { + return SkString("rects"); + } + + virtual SkISize onISize() SK_OVERRIDE { + return make_isize(1200, 900); + } + + void makePaints() { + { + // no AA + SkPaint p; + p.setColor(SK_ColorWHITE); + fPaints.push_back(p); + } + + { + // AA + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + fPaints.push_back(p); + } + + { + // AA with mask filter + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + SkMaskFilter* mf = SkBlurMaskFilter::Create(SkIntToScalar(5), + SkBlurMaskFilter::kNormal_BlurStyle, + SkBlurMaskFilter::kHighQuality_BlurFlag); + p.setMaskFilter(mf)->unref(); + fPaints.push_back(p); + } + + { + // AA with radial shader + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30)); + SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN }; + SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 }; + SkShader* s = SkGradientShader::CreateRadial(center, + SkIntToScalar(20), + colors, + pos, + SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode); + p.setShader(s)->unref(); + fPaints.push_back(p); + } + + { + // AA with blur + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + SkBlurDrawLooper* shadowLooper = + new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5), + SkIntToScalar(10), SK_ColorWHITE, + SkBlurDrawLooper::kIgnoreTransform_BlurFlag | + SkBlurDrawLooper::kOverrideColor_BlurFlag | + SkBlurDrawLooper::kHighQuality_BlurFlag ); + SkAutoUnref aurL0(shadowLooper); + p.setLooper(shadowLooper); + fPaints.push_back(p); + } + + { + // AA with stroke style + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(SkIntToScalar(3)); + fPaints.push_back(p); + } + + { + // AA with stroke style, width = 0 + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + fPaints.push_back(p); + } + + { + // AA with stroke and fill style + SkPaint p; + p.setColor(SK_ColorWHITE); + p.setAntiAlias(true); + p.setStyle(SkPaint::kStrokeAndFill_Style); + p.setStrokeWidth(SkIntToScalar(2)); + fPaints.push_back(p); + } + } + + void makeMatrices() { + { + // 1x1.5 scale + SkMatrix m; + m.setScale(1, 1.5); + fMatrices.push_back(m); + } + + { + // 1.5x1.5 scale + SkMatrix m; + m.setScale(1.5, 1.5); + fMatrices.push_back(m); + } + + { + // 1x1.5 skew + SkMatrix m; + m.setSkew(1, 1.5); + fMatrices.push_back(m); + } + + { + // 1.5x1.5 skew + SkMatrix m; + m.setSkew(1.5, 1.5); + fMatrices.push_back(m); + } + + { + // 30 degree rotation + SkMatrix m; + m.setRotate(SkIntToScalar(30)); + fMatrices.push_back(m); + } + } + + void makeRects() { + { + // small square + SkRect r = SkRect::MakeLTRB(0, 0, 30, 30); + fRects.push_back(r); + } + + { + // thin vertical + SkRect r = SkRect::MakeLTRB(0, 0, 2, 40); + fRects.push_back(r); + } + + { + // thin horizontal + SkRect r = SkRect::MakeLTRB(0, 0, 40, 2); + fRects.push_back(r); + } + + { + // very thin + SkRect r = SkRect::MakeLTRB(0, 0, 0.25f, 10); + fRects.push_back(r); + } + + { + // zaftig + SkRect r = SkRect::MakeLTRB(0, 0, 60, 60); + fRects.push_back(r); + } + } + + // position the current test on the canvas + static void position(SkCanvas* canvas, int testCount) { + canvas->translate(SK_Scalar1 * 100 * (testCount % 10) + SK_Scalar1 / 4, + SK_Scalar1 * 100 * (testCount / 10) + 3 * SK_Scalar1 / 4); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); + + int testCount = 0; + + for (int i = 0; i < fPaints.count(); ++i) { + for (int j = 0; j < fRects.count(); ++j, ++testCount) { + canvas->save(); + this->position(canvas, testCount); + canvas->drawRect(fRects[j], fPaints[i]); + canvas->restore(); + } + } + + SkPaint paint; + paint.setColor(SK_ColorWHITE); + paint.setAntiAlias(true); + + for (int i = 0; i < fMatrices.count(); ++i) { + for (int j = 0; j < fRects.count(); ++j, ++testCount) { + canvas->save(); + this->position(canvas, testCount); + canvas->concat(fMatrices[i]); + canvas->drawRect(fRects[j], paint); + canvas->restore(); + } + } + } + +private: + SkTArray fPaints; + SkTArray fMatrices; + SkTArray fRects; + + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return new RectsGM; } +static GMRegistry reg(MyFactory); + +} -- cgit v1.2.3