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

Unified Diff: gm/drawminibitmaprect.cpp

Issue 1294513002: Add GM to test drawing atlas case (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: change strict for fast Created 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/drawminibitmaprect.cpp
diff --git a/gm/drawminibitmaprect.cpp b/gm/drawminibitmaprect.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7617aa5fdf72271b475d0722fb33433dddf67d2f
--- /dev/null
+++ b/gm/drawminibitmaprect.cpp
@@ -0,0 +1,148 @@
+/*
robertphillips 2015/08/13 18:17:52 2015 ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ * Copyright 2011 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"
robertphillips 2015/08/13 18:17:51 Do we need the blur headers ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+#include "SkBlurMask.h"
+#include "SkBlurMaskFilter.h"
+#include "SkColorPriv.h"
+#include "SkGradientShader.h"
+#include "SkShader.h"
+#include "SkImage.h"
+#include "SkRandom.h"
+
+static SkImage* image_from_bitmap(const SkBitmap& bm) {
+ SkBitmap b(bm);
+ b.lockPixels();
+ return SkImage::NewRasterCopy(b.info(), b.getPixels(), b.rowBytes());
+}
+
robertphillips 2015/08/13 18:17:52 Can we pass the GM's canvas in here and use newSur
+static SkImage* makebm(SkBitmap* bm, int w, int h) {
+ bm->allocN32Pixels(w, h);
+ bm->eraseColor(SK_ColorTRANSPARENT);
+
+ SkCanvas canvas(*bm);
+
+ SkScalar wScalar = SkIntToScalar(w);
+ SkScalar hScalar = SkIntToScalar(h);
+
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkPoint pt = { wScalar / 2, hScalar / 2 };
+
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
+
robertphillips 2015/08/13 18:17:52 const ? static ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
+ SK_ColorGREEN, SK_ColorMAGENTA,
+ SK_ColorBLUE, SK_ColorCYAN,
+ SK_ColorRED};
+
robertphillips 2015/08/13 18:17:52 const ? static ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkScalar pos[] = {0,
+ SK_Scalar1 / 6,
+ 2 * SK_Scalar1 / 6,
+ 3 * SK_Scalar1 / 6,
+ 4 * SK_Scalar1 / 6,
+ 5 * SK_Scalar1 / 6,
+ SK_Scalar1};
+
robertphillips 2015/08/13 18:17:51 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkPaint paint;
+ SkRect rect = SkRect::MakeWH(wScalar, hScalar);
+ SkMatrix mat = SkMatrix::I();
+ for (int i = 0; i < 4; ++i) {
+ paint.setShader(SkGradientShader::CreateRadial(
+ pt, radius,
+ colors, pos,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kRepeat_TileMode,
+ 0, &mat))->unref();
+ canvas.drawRect(rect, paint);
+ rect.inset(wScalar / 8, hScalar / 8);
+ mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
+ }
+ // Let backends know we won't change this, so they don't have to deep copy it defensively.
+ bm->setImmutable();
+
+ return image_from_bitmap(*bm);
+}
+
+static const int gSize = 1024;
+static const int gBmpSize = 2048;
+
robertphillips 2015/08/13 18:17:52 // This GM calls drawImageRect several times using
joshualitt 2015/08/13 19:31:27 Acknowledged.
+class DrawMiniBitmapRectGM : public skiagm::GM {
+public:
+ DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) {
+ fName.set("drawminibitmaprect");
+ if (fAA) {
+ fName.appendf("_aa");
+ }
+ }
+
+ bool fAA;
robertphillips 2015/08/13 18:17:52 Do we need to keep fLargeBitmap around?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkBitmap fLargeBitmap;
+ SkAutoTUnref<SkImage> fImage;
+ SkString fName;
+
+protected:
+ SkString onShortName() override { return fName; }
+
+ SkISize onISize() override { return SkISize::Make(gSize, gSize); }
+
+ void onOnceBeforeDraw() override {
+ fImage.reset(makebm(&fLargeBitmap, gBmpSize, gBmpSize));
+ }
+
+ void onDraw(SkCanvas* canvas) override {
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
+ static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
+
+ static const int kPadX = 30;
+ static const int kPadY = 40;
+
+ int rowCount = 0;
+ canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
robertphillips 2015/08/13 18:17:52 Is there a restore to match this ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ canvas->save();
+ SkRandom random;
+
+ SkPaint paint;
+ paint.setAntiAlias(fAA);
+ for (int w = 1; w <= kMaxSrcRectSize; w *= 3) {
+ for (int h = 1; h <= kMaxSrcRectSize; h *= 3) {
+
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
+ SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h);
+ canvas->save();
+ switch (random.nextU() % 3) {
+ case 0:
+ canvas->rotate(random.nextF() * 10.f);
+ break;
+ case 1:
+ canvas->rotate(-random.nextF() * 10.f);
+ break;
+ case 2:
+ // rect stays rect
+ break;
+ }
+ canvas->drawImageRect(fImage, srcRect, dstRect, &paint,
+ SkCanvas::kFast_SrcRectConstraint);
+ canvas->restore();
+
+ canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
+ ++rowCount;
+ if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) {
+ canvas->restore();
+ canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
+ canvas->save();
+ rowCount = 0;
+ }
+ }
+ }
+
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+
+DEF_GM( return new DrawMiniBitmapRectGM(true); )
+DEF_GM( return new DrawMiniBitmapRectGM(false); )
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698