2016-01-14 17:11:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/private/SkNx.h"
|
2020-07-14 21:16:32 +00:00
|
|
|
#include "src/core/SkMipmap.h"
|
2020-11-30 18:09:24 +00:00
|
|
|
#include "src/core/SkMipmapBuilder.h"
|
2021-01-25 00:49:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2016-01-14 17:11:51 +00:00
|
|
|
|
2020-07-10 12:36:42 +00:00
|
|
|
class ShowMipLevels3 : public skiagm::GM {
|
|
|
|
sk_sp<SkImage> fImg;
|
|
|
|
|
|
|
|
SkString onShortName() override { return SkString("showmiplevels_explicit"); }
|
|
|
|
|
2020-07-14 15:29:38 +00:00
|
|
|
SkISize onISize() override { return {1130, 970}; }
|
2020-07-10 12:36:42 +00:00
|
|
|
|
2020-07-14 15:29:38 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
fImg = GetResourceAsImage("images/ship.png");
|
|
|
|
fImg = fImg->makeRasterImage(); // makeWithMips only works on raster for now
|
2020-07-10 12:36:42 +00:00
|
|
|
|
2020-07-14 15:29:38 +00:00
|
|
|
const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
|
|
|
|
|
|
|
|
SkMipmapBuilder builder(fImg->imageInfo());
|
|
|
|
for (int i = 0; i < builder.countLevels(); ++i) {
|
|
|
|
auto surf = SkSurface::MakeRasterDirect(builder.level(i));
|
|
|
|
surf->getCanvas()->drawColor(colors[i % SK_ARRAY_COUNT(colors)]);
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
2020-09-17 17:58:26 +00:00
|
|
|
fImg = builder.attachTo(fImg.get());
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 20:29:16 +00:00
|
|
|
DrawResult onDraw(SkCanvas* canvas, SkString*) override {
|
2020-07-10 12:36:42 +00:00
|
|
|
canvas->drawColor(0xFFDDDDDD);
|
|
|
|
|
|
|
|
canvas->translate(10, 10);
|
2020-07-16 20:29:16 +00:00
|
|
|
for (auto mm : {SkMipmapMode::kNone, SkMipmapMode::kNearest, SkMipmapMode::kLinear}) {
|
2020-11-20 23:45:36 +00:00
|
|
|
for (auto fm : {SkFilterMode::kNearest, SkFilterMode::kLinear}) {
|
|
|
|
canvas->translate(0, draw_downscaling(canvas, {fm, mm}));
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-14 15:29:38 +00:00
|
|
|
return DrawResult::kOk;
|
2020-07-10 12:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-20 23:45:36 +00:00
|
|
|
SkScalar draw_downscaling(SkCanvas* canvas, SkSamplingOptions sampling) {
|
2020-07-14 15:29:38 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect r = {0, 0, 150, 150};
|
|
|
|
for (float scale = 1; scale >= 0.1f; scale *= 0.7f) {
|
|
|
|
SkMatrix matrix = SkMatrix::Scale(scale, scale);
|
|
|
|
paint.setShader(fImg->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
2020-11-20 23:45:36 +00:00
|
|
|
sampling, &matrix));
|
2020-07-14 15:29:38 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->translate(r.width() + 10, 0);
|
|
|
|
}
|
|
|
|
return r.height() + 10;
|
|
|
|
}
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2020-07-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
DEF_GM( return new ShowMipLevels3; )
|