OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 } | 64 } |
65 bm.setImmutable(); | 65 bm.setImmutable(); |
66 return SkImage::MakeFromBitmap(bm); | 66 return SkImage::MakeFromBitmap(bm); |
67 } | 67 } |
68 | 68 |
69 static void show_mips(SkCanvas* canvas, SkImage* img) { | 69 static void show_mips(SkCanvas* canvas, SkImage* img) { |
70 SkPaint paint; | 70 SkPaint paint; |
71 paint.setFilterQuality(kMedium_SkFilterQuality); | 71 paint.setFilterQuality(kMedium_SkFilterQuality); |
72 | 72 |
73 SkRect dst = SkRect::MakeIWH(img->width(), img->height()); | 73 // Want to ensure we never draw fractional pixels, so we use an IRect |
| 74 SkIRect dst = SkIRect::MakeWH(img->width(), img->height()); |
74 while (dst.width() > 5) { | 75 while (dst.width() > 5) { |
75 canvas->drawImageRect(img, dst, &paint); | 76 canvas->drawImageRect(img, SkRect::Make(dst), &paint); |
76 dst.offset(dst.width() + 10, 0); | 77 dst.offset(dst.width() + 10, 0); |
77 dst.fRight = dst.fLeft + SkScalarHalf(dst.width()); | 78 dst.fRight = dst.fLeft + dst.width()/2; |
78 dst.fBottom = dst.fTop + SkScalarHalf(dst.height()); | 79 dst.fBottom = dst.fTop + dst.height()/2; |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
82 /* | 83 /* |
83 * Ensure that in L32 drawing mode, both images/mips look the same as each othe
r, and | 84 * Ensure that in L32 drawing mode, both images/mips look the same as each othe
r, and |
84 * their mips are darker than the original (since the mips should ignore the ga
mma in L32). | 85 * their mips are darker than the original (since the mips should ignore the ga
mma in L32). |
85 * | 86 * |
86 * Ensure that in S32 drawing mode, all images/mips look the same, and look cor
rect (i.e. | 87 * Ensure that in S32 drawing mode, all images/mips look the same, and look cor
rect (i.e. |
87 * the mip levels match the original in brightness). | 88 * the mip levels match the original in brightness). |
88 */ | 89 */ |
89 DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) { | 90 DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) { |
90 sk_sp<SkImage> limg = make(nullptr); | 91 sk_sp<SkImage> limg = make(nullptr); |
91 sk_sp<SkImage> simg = make(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
); | 92 sk_sp<SkImage> simg = make(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
); |
92 | 93 |
93 canvas->translate(10, 10); | 94 canvas->translate(10, 10); |
94 show_mips(canvas, limg.get()); | 95 show_mips(canvas, limg.get()); |
95 canvas->translate(0, limg->height() + 10.0f); | 96 canvas->translate(0, limg->height() + 10.0f); |
96 show_mips(canvas, simg.get()); | 97 show_mips(canvas, simg.get()); |
97 } | 98 } |
98 | 99 |
OLD | NEW |