Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: gm/samplerstress.cpp

Issue 468483002: re-add samplerstress gm, but use blurmaskfilter instead (std filter) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/samplerstress.cpp
diff --git a/gm/samplerstress.cpp b/gm/samplerstress.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c395b08ba170fee1c2efe34eee63e05c75078a46
--- /dev/null
+++ b/gm/samplerstress.cpp
@@ -0,0 +1,157 @@
+/*
+ * 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 "SkShader.h"
+#include "SkBlurMaskFilter.h"
+
+namespace skiagm {
+
+/**
+ * Stress test the GPU samplers by rendering a textured glyph with a mask and
+ * an AA clip
+ */
+class SamplerStressGM : public GM {
+public:
+ SamplerStressGM()
+ : fTextureCreated(false)
+ , fShader(NULL)
+ , fMaskFilter(NULL) {
+ }
+
+ virtual ~SamplerStressGM() {
+ }
+
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ virtual SkString onShortName() {
+ return SkString("gpusamplerstress");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(640, 480);
+ }
+
+ /**
+ * Create a red & green stripes on black texture
+ */
+ void createTexture() {
+ if (fTextureCreated) {
+ return;
+ }
+
+ static const int xSize = 16;
+ static const int ySize = 16;
+
+ fTexture.allocN32Pixels(xSize, ySize);
+ SkPMColor* addr = fTexture.getAddr32(0, 0);
+
+ for (int y = 0; y < ySize; ++y) {
+ for (int x = 0; x < xSize; ++x) {
+ addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorBLACK);
+
+ if ((y % 5) == 0) {
+ addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorRED);
+ }
+ if ((x % 7) == 0) {
+ addr[y*xSize+x] = SkPreMultiplyColor(SK_ColorGREEN);
+ }
+ }
+ }
+
+ fTextureCreated = true;
+ }
+
+ void createShader() {
+ if (NULL != fShader.get()) {
+ return;
+ }
+
+ createTexture();
+
+ fShader.reset(SkShader::CreateBitmapShader(fTexture,
+ SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode));
+ }
+
+ void createMaskFilter() {
+ if (NULL != fMaskFilter.get()) {
+ return;
+ }
+
+ const SkScalar sigma = 1;
+ fMaskFilter.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, sigma));
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+
+ createShader();
+ createMaskFilter();
+
+ canvas->save();
+
+ // draw a letter "M" with a green & red striped texture and a
robertphillips 2014/08/12 13:52:46 blur
+ // stipple mask with a round rect soft clip
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setTextSize(72);
+ paint.setShader(fShader.get());
+ paint.setMaskFilter(fMaskFilter.get());
+
+ SkRect temp;
+ temp.set(SkIntToScalar(115),
+ SkIntToScalar(75),
+ SkIntToScalar(144),
+ SkIntToScalar(110));
+
+ SkPath path;
+ path.addRoundRect(temp, SkIntToScalar(5), SkIntToScalar(5));
+
+ canvas->clipPath(path, SkRegion::kReplace_Op, true); // AA is on
+
+ canvas->drawText("M", 1,
+ SkIntToScalar(100), SkIntToScalar(100),
+ paint);
+
+ canvas->restore();
+
+ // Now draw stroked versions of the "M" and the round rect so we can
+ // see what is going on
+ SkPaint paint2;
+ paint2.setColor(SK_ColorBLACK);
+ paint2.setAntiAlias(true);
+ paint2.setTextSize(72);
+ paint2.setStyle(SkPaint::kStroke_Style);
+ paint2.setStrokeWidth(1);
+ canvas->drawText("M", 1,
+ SkIntToScalar(100), SkIntToScalar(100),
+ paint2);
+
+ paint2.setColor(SK_ColorGRAY);
+
+ canvas->drawPath(path, paint2);
+ }
+
+private:
+ SkBitmap fTexture;
+ bool fTextureCreated;
+ SkAutoTUnref<SkShader> fShader;
+ SkAutoTUnref<SkMaskFilter> fMaskFilter;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new SamplerStressGM; }
+static GMRegistry reg(MyFactory);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698