blob: ad45a17e86d678b4a3a60b22050ba19891726307 [file] [log] [blame]
reedc8e47652015-02-19 11:39:46 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkImage.h"
11#include "SkRandom.h"
12#include "SkSurface.h"
13
14static SkImage* make_image() {
15 const SkImageInfo info = SkImageInfo::MakeN32Premul(319, 52);
16 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
17 SkCanvas* canvas = surface->getCanvas();
18 canvas->drawColor(0xFFF8F8F8);
19
20 SkPaint paint;
21 paint.setAntiAlias(true);
22
23 paint.setStyle(SkPaint::kStroke_Style);
24 for (int i = 0; i < 20; ++i) {
25 canvas->drawCircle(-4, 25, 20, paint);
26 canvas->translate(25, 0);
27 }
28 return surface->newImageSnapshot();
29}
30
31static void test_mip(SkCanvas* canvas) {
reed1c846342015-07-09 11:47:36 -070032 SkAutoTUnref<SkImage> img(make_image());//SkImage::NewFromEncoded(data));
reedc8e47652015-02-19 11:39:46 -080033
34 SkPaint paint;
35 const SkRect dst = SkRect::MakeWH(177, 15);
36
37 paint.setTextSize(30);
38 SkString str;
39 str.printf("scale %g %g", dst.width() / img->width(), dst.height() / img->height());
40// canvas->drawText(str.c_str(), str.size(), 300, 100, paint);
41
42 canvas->translate(20, 20);
43 for (int i = 0; i < 4; ++i) {
reed93a12152015-03-16 10:08:34 -070044 paint.setFilterQuality(SkFilterQuality(i));
reedc8e47652015-02-19 11:39:46 -080045 canvas->drawImageRect(img, NULL, dst, &paint);
46 canvas->translate(0, 20);
47 }
48 canvas->drawImage(img, 20, 20, NULL);
49}
50
51class MipMapGM : public skiagm::GM {
52public:
53 MipMapGM() {}
54
55protected:
mtklein36352bf2015-03-25 18:17:31 -070056 SkString onShortName() override { return SkString("mipmap"); }
reedc8e47652015-02-19 11:39:46 -080057
mtklein36352bf2015-03-25 18:17:31 -070058 SkISize onISize() override { return SkISize::Make(400, 200); }
reedc8e47652015-02-19 11:39:46 -080059
mtklein36352bf2015-03-25 18:17:31 -070060 void onDraw(SkCanvas* canvas) override {
reedc8e47652015-02-19 11:39:46 -080061 test_mip(canvas);
62 }
63
64private:
65 typedef skiagm::GM INHERITED;
66};
67DEF_GM( return new MipMapGM; )
68