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

Unified Diff: gm/showmiplevels.cpp

Issue 1594613002: add GM to show miplevels for all colortypes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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/showmiplevels.cpp
diff --git a/gm/showmiplevels.cpp b/gm/showmiplevels.cpp
index 385d713fe1d15e9b10913884e3975fec03804000..013adda23ff34c6214ad4ba38caf7b9b64072259 100644
--- a/gm/showmiplevels.cpp
+++ b/gm/showmiplevels.cpp
@@ -18,28 +18,28 @@
#include "Resources.h"
#include "sk_tool_utils.h"
-static SkBitmap make_bitmap(int size) {
+static SkBitmap make_bitmap(int w, int h) {
SkBitmap bm;
- bm.allocN32Pixels(size, size);
+ bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(size / 16.0f);
- canvas.drawCircle(size/2.0f, size/2.0f, size/3.0f, paint);
+ paint.setStrokeWidth(w / 16.0f);
+ canvas.drawCircle(w/2.0f, h/2.0f, w/3.0f, paint);
return bm;
}
-static SkBitmap make_bitmap2(int size) {
+static SkBitmap make_bitmap2(int w, int h) {
SkBitmap bm;
- bm.allocN32Pixels(size, size);
+ bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
SkScalar inset = 2;
- SkRect r = SkRect::MakeIWH(size, size).makeInset(0.5f, 0.5f);
+ SkRect r = SkRect::MakeIWH(w, h).makeInset(0.5f, 0.5f);
while (r.width() > 4) {
canvas.drawRect(r, paint);
r.inset(inset, inset);
@@ -49,16 +49,16 @@ static SkBitmap make_bitmap2(int size) {
}
#include "SkNx.h"
-static SkBitmap make_bitmap3(int size) {
+static SkBitmap make_bitmap3(int w, int h) {
SkBitmap bm;
- bm.allocN32Pixels(size, size);
+ bm.allocN32Pixels(w, h);
SkCanvas canvas(bm);
canvas.clear(0xFFFFFFFF);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2.1f);
- SkScalar s = SkIntToScalar(size);
+ SkScalar s = SkIntToScalar(w);
Sk4f p(s, -s, -s, s);
Sk4f d(5);
while (p.kth<1>() < s) {
@@ -103,9 +103,9 @@ public:
ShowMipLevels(int N) : fN(N) {
fBM[0] = sk_tool_utils::create_checkerboard_bitmap(N, N, SK_ColorBLACK, SK_ColorWHITE, 2);
- fBM[1] = make_bitmap(N);
- fBM[2] = make_bitmap2(N);
- fBM[3] = make_bitmap3(N);
+ fBM[1] = make_bitmap(N, N);
+ fBM[2] = make_bitmap2(N, N);
+ fBM[3] = make_bitmap3(N, N);
}
protected:
@@ -146,7 +146,8 @@ protected:
SkMipMap::Level level;
SkScalar scale = 0.5f;
while (mm->extractLevel(scale, &level)) {
- SkImageInfo info = SkImageInfo::MakeN32Premul(level.fWidth, level.fHeight);
+ SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight,
+ baseBM.colorType(), baseBM.alphaType());
SkPixmap levelPM{ info, level.fPixels, level.fRowBytes };
SkBitmap bm = func(prevPM, levelPM);
@@ -210,3 +211,103 @@ private:
DEF_GM( return new ShowMipLevels(255); )
DEF_GM( return new ShowMipLevels(256); )
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Show mip levels that were built, for all supported colortypes
+ */
+class ShowMipLevels2 : public skiagm::GM {
+ const int fW, fH;
+ SkBitmap fBM[4];
+
+public:
+ ShowMipLevels2(int w, int h) : fW(w), fH(h) {
+ fBM[0] = sk_tool_utils::create_checkerboard_bitmap(w, h, SK_ColorBLACK, SK_ColorWHITE, 2);
+ fBM[1] = make_bitmap(w, h);
+ fBM[2] = make_bitmap2(w, h);
+ fBM[3] = make_bitmap3(w, h);
+ }
+
+protected:
+
+ SkString onShortName() override {
+ SkString str;
+ str.printf("showmiplevels2_%dx%d", fW, fH);
+ return str;
+ }
+
+ SkISize onISize() override {
+ return { 824, 862 };
+ }
+
+ static void DrawAndFrame(SkCanvas* canvas, const SkBitmap& bm, SkScalar x, SkScalar y) {
+ canvas->drawBitmap(bm, x, y, nullptr);
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setColor(0xFFFFCCCC);
+ canvas->drawRect(SkRect::MakeIWH(bm.width(), bm.height()).makeOffset(x, y).makeOutset(0.5f, 0.5f), paint);
+ }
+
+ void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM) {
+ SkScalar x = 4;
+ SkScalar y = 4;
+
+ SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr));
+
+ int index = 0;
+ SkMipMap::Level level;
+ SkScalar scale = 0.5f;
+ while (mm->extractLevel(scale, &level)) {
+ SkImageInfo info = SkImageInfo::Make(level.fWidth, level.fHeight,
+ baseBM.colorType(), baseBM.alphaType());
+
+ SkBitmap bm;
+ bm.installPixels(info, level.fPixels, level.fRowBytes);
+ DrawAndFrame(canvas, bm, x, y);
+
+ if (info.width() <= 2 || info.height() <= 2) {
+ break;
+ }
+ if (index & 1) {
+ x += info.width() + 4;
+ } else {
+ y += info.height() + 4;
+ }
+ scale /= 2;
+ index += 1;
+ }
+ }
+
+ void drawSet(SkCanvas* canvas, const SkBitmap& orig) {
+ const SkColorType ctypes[] = {
+ kN32_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kGray_8_SkColorType
+ };
+
+ SkAutoCanvasRestore acr(canvas, true);
+
+ for (auto ctype : ctypes) {
+ SkBitmap bm;
+ orig.copyTo(&bm, ctype);
+ drawLevels(canvas, bm);
+ canvas->translate(orig.width()/2 + 8.0f, 0);
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ canvas->translate(4, 4);
+ for (const auto& bm : fBM) {
+ this->drawSet(canvas, bm);
+ // round so we always produce an integral translate, so the GOLD tool won't show
+ // unimportant diffs if this is drawn on a GPU with different rounding rules
+ // since we draw the bitmaps using nearest-neighbor
+ canvas->translate(0, SkScalarRoundToScalar(bm.height() * 0.85f));
+ }
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new ShowMipLevels2(255, 255); )
+DEF_GM( return new ShowMipLevels2(256, 255); )
+DEF_GM( return new ShowMipLevels2(255, 256); )
+DEF_GM( return new ShowMipLevels2(256, 256); )
« 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