aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/downsamplebitmap.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-01-16 05:01:16 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-16 05:01:16 -0800
commitc695e954174e4a789631ea4d6e171bd7118ebc67 (patch)
tree10930e7ab6becb025a77fcf432cc9a58d9340b52 /gm/downsamplebitmap.cpp
parent0582f5a8f1f298879651401a2c432670728e7b9f (diff)
add gm to show miplevels (patchset #2 id:20001 of https://codereview.chromium.org/849173004/)"
fixed memory leak This reverts commit 04f07fcbfddbe8ca97d29053554a01c66d44ece2. BUG=skia: TBR= Review URL: https://codereview.chromium.org/854163002
Diffstat (limited to 'gm/downsamplebitmap.cpp')
-rw-r--r--gm/downsamplebitmap.cpp83
1 files changed, 70 insertions, 13 deletions
diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp
index ce10b47a84..600d2caee2 100644
--- a/gm/downsamplebitmap.cpp
+++ b/gm/downsamplebitmap.cpp
@@ -14,6 +14,22 @@
#include "SkStream.h"
#include "SkPaint.h"
+static void make_checker(SkBitmap* bm, int size, int numChecks) {
+ bm->allocN32Pixels(size, size);
+ for (int y = 0; y < size; ++y) {
+ for (int x = 0; x < size; ++x) {
+ SkPMColor* s = bm->getAddr32(x, y);
+ int cx = (x * numChecks) / size;
+ int cy = (y * numChecks) / size;
+ if ((cx+cy)%2) {
+ *s = 0xFFFFFFFF;
+ } else {
+ *s = 0xFF000000;
+ }
+ }
+ }
+}
+
static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) {
sk_tool_utils::set_portable_typeface(paint, name, style);
}
@@ -139,19 +155,7 @@ class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM {
int fNumChecks;
void make_bitmap() SK_OVERRIDE {
- fBM.allocN32Pixels(fSize, fSize);
- for (int y = 0; y < fSize; ++y) {
- for (int x = 0; x < fSize; ++x) {
- SkPMColor* s = fBM.getAddr32(x, y);
- int cx = (x * fNumChecks) / fSize;
- int cy = (y * fNumChecks) / fSize;
- if ((cx+cy)%2) {
- *s = 0xFFFFFFFF;
- } else {
- *s = 0xFF000000;
- }
- }
- }
+ make_checker(&fBM, fSize, fNumChecks);
}
private:
typedef DownsampleBitmapGM INHERITED;
@@ -190,6 +194,59 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM {
typedef DownsampleBitmapGM INHERITED;
};
+#include "SkMipMap.h"
+class ShowMipLevels : public skiagm::GM {
+public:
+ SkBitmap fBM;
+
+ ShowMipLevels() {
+ this->setBGColor(0xFFDDDDDD);
+ make_checker(&fBM, 512, 256);
+ }
+
+protected:
+#if 0
+ uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+#endif
+
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("showmiplevels");
+ }
+
+ SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(fBM.width() + 8, 2 * fBM.height() + 80);
+ }
+
+ void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkScalar x = 4;
+ SkScalar y = 4;
+ canvas->drawBitmap(fBM, x, y, NULL);
+ y += fBM.height() + 4;
+
+ SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(fBM, NULL));
+
+ SkMipMap::Level level;
+ SkScalar scale = 0.5f;
+ while (mm->extractLevel(scale, &level)) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(level.fWidth, level.fHeight);
+ SkBitmap bm;
+ bm.installPixels(info, level.fPixels, level.fRowBytes);
+ canvas->drawBitmap(bm, x, y, NULL);
+ y += bm.height() + 4;
+ scale /= 2;
+ if (info.width() == 1 || info.height() == 1) {
+ break;
+ }
+ }
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new ShowMipLevels; )
+
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); )