reed | c8e4765 | 2015-02-19 11:39:46 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | static SkImage* make_image() { |
| 15 | const SkImageInfo info = SkImageInfo::MakeN32Premul(319, 52); |
| 16 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 17 | SkCanvas* canvas = surface->getCanvas(); |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 18 | canvas->drawColor(sk_tool_utils::color_to_565(0xFFF8F8F8)); |
reed | c8e4765 | 2015-02-19 11:39:46 -0800 | [diff] [blame] | 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 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 31 | DEF_SIMPLE_GM(mipmap, canvas, 400, 200) { |
reed | 1c84634 | 2015-07-09 11:47:36 -0700 | [diff] [blame] | 32 | SkAutoTUnref<SkImage> img(make_image());//SkImage::NewFromEncoded(data)); |
reed | c8e4765 | 2015-02-19 11:39:46 -0800 | [diff] [blame] | 33 | |
| 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) { |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 44 | paint.setFilterQuality(SkFilterQuality(i)); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 45 | canvas->drawImageRect(img, dst, &paint); |
reed | c8e4765 | 2015-02-19 11:39:46 -0800 | [diff] [blame] | 46 | canvas->translate(0, 20); |
| 47 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 48 | canvas->drawImage(img, 20, 20, nullptr); |
reed | c8e4765 | 2015-02-19 11:39:46 -0800 | [diff] [blame] | 49 | } |
| 50 | |