downsamplebitmap.cpp revision 1c4029296f518a84ef90095243ba210163a1e1f9
19c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com/* 29c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com * Copyright 2013 Google Inc. 39c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com * 49c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com * Use of this source code is governed by a BSD-style license that can be 59c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com * found in the LICENSE file. 69c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com */ 79c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 89c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com#include "gm.h" 99c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 10bcbc1788b478b1e54079318ad073e8490aa66faetfarina#include "Resources.h" 11bcbc1788b478b1e54079318ad073e8490aa66faetfarina#include "SkGradientShader.h" 129c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com#include "SkTypeface.h" 139c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com#include "SkImageDecoder.h" 149c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com#include "SkStream.h" 15af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com#include "SkPaint.h" 169c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 17c695e954174e4a789631ea4d6e171bd7118ebc67reedstatic void make_checker(SkBitmap* bm, int size, int numChecks) { 18c695e954174e4a789631ea4d6e171bd7118ebc67reed bm->allocN32Pixels(size, size); 19c695e954174e4a789631ea4d6e171bd7118ebc67reed for (int y = 0; y < size; ++y) { 20c695e954174e4a789631ea4d6e171bd7118ebc67reed for (int x = 0; x < size; ++x) { 21c695e954174e4a789631ea4d6e171bd7118ebc67reed SkPMColor* s = bm->getAddr32(x, y); 22c695e954174e4a789631ea4d6e171bd7118ebc67reed int cx = (x * numChecks) / size; 23c695e954174e4a789631ea4d6e171bd7118ebc67reed int cy = (y * numChecks) / size; 24c695e954174e4a789631ea4d6e171bd7118ebc67reed if ((cx+cy)%2) { 25c695e954174e4a789631ea4d6e171bd7118ebc67reed *s = 0xFFFFFFFF; 26c695e954174e4a789631ea4d6e171bd7118ebc67reed } else { 27c695e954174e4a789631ea4d6e171bd7118ebc67reed *s = 0xFF000000; 28c695e954174e4a789631ea4d6e171bd7118ebc67reed } 29c695e954174e4a789631ea4d6e171bd7118ebc67reed } 30c695e954174e4a789631ea4d6e171bd7118ebc67reed } 31c695e954174e4a789631ea4d6e171bd7118ebc67reed} 32c695e954174e4a789631ea4d6e171bd7118ebc67reed 339c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comstatic void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) { 34992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark sk_tool_utils::set_portable_typeface(paint, name, style); 359c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com} 369c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 379c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comclass DownsampleBitmapGM : public skiagm::GM { 389c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.compublic: 399c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkBitmap fBM; 409c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkString fName; 419c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com bool fBitmapMade; 42af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com SkPaint::FilterLevel fFilterLevel; 439c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 44af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com DownsampleBitmapGM(SkPaint::FilterLevel filterLevel) 45af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com : fFilterLevel(filterLevel) 469c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com { 479c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com this->setBGColor(0xFFDDDDDD); 489c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com fBitmapMade = false; 499c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 509c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 51e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com const char* filterLevelToString() { 52e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com static const char *filterLevelNames[] = { 53e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com "none", "low", "medium", "high" 54e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com }; 55e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com return filterLevelNames[fFilterLevel]; 56af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com } 579c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 589c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comprotected: 59a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org 6072c9faab45124e08c85f70ca38536914862d947cmtklein SkString onShortName() SK_OVERRIDE { 619c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com return fName; 629c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 639c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 6472c9faab45124e08c85f70ca38536914862d947cmtklein SkISize onISize() SK_OVERRIDE { 659c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com make_bitmap_wrapper(); 666a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein return SkISize::Make(fBM.width(), 4 * fBM.height()); 679c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 689c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 699c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com void make_bitmap_wrapper() { 709c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com if (!fBitmapMade) { 719c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com fBitmapMade = true; 729c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com make_bitmap(); 739c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 749c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 759c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 769c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com virtual void make_bitmap() = 0; 779c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 7872c9faab45124e08c85f70ca38536914862d947cmtklein void onDraw(SkCanvas* canvas) SK_OVERRIDE { 799c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com make_bitmap_wrapper(); 809c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 816a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein int curY = 0; 826a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein int curHeight; 839c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com float curScale = 1; 849c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com do { 859c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 869c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkMatrix matrix; 879c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com matrix.setScale( curScale, curScale ); 889c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 899c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkPaint paint; 90af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com paint.setFilterLevel(fFilterLevel); 919c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 929c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas->save(); 936a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein canvas->translate(0, (SkScalar)curY); 94c54d8db4d169ea5f2af2a9a2349df007bd428475Florin Malita canvas->concat(matrix); 95c54d8db4d169ea5f2af2a9a2349df007bd428475Florin Malita canvas->drawBitmap(fBM, 0, 0, &paint); 969c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas->restore(); 979c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 986a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein curHeight = (int) (fBM.height() * curScale + 2); 996a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein curY += curHeight; 1009c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com curScale *= 0.75f; 1016a2f5fe8677f27d737da0e4e6dd1f814fbdbb6fcmtklein } while (curHeight >= 2 && curY < 4*fBM.height()); 1029c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1039c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1049c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comprivate: 1059c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com typedef skiagm::GM INHERITED; 1069c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com}; 1079c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1089c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comclass DownsampleBitmapTextGM: public DownsampleBitmapGM { 1099c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com public: 110af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) 111af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com : INHERITED(filterLevel), fTextSize(textSize) 1129c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com { 113e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterLevelToString(), fTextSize); 1149c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1159c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1169c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com protected: 1179c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com float fTextSize; 1189c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 11972c9faab45124e08c85f70ca38536914862d947cmtklein void make_bitmap() SK_OVERRIDE { 120eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); 1219c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkCanvas canvas(fBM); 1229c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas.drawColor(SK_ColorWHITE); 1239c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1249c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkPaint paint; 1259c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com paint.setAntiAlias(true); 1269c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com paint.setSubpixelText(true); 1279c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com paint.setTextSize(fTextSize); 1289c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1299c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com setTypeface(&paint, "Times", SkTypeface::kNormal); 1309c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint); 1319c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com setTypeface(&paint, "Times", SkTypeface::kBold); 1329c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas.drawText("Hamburgefons", 12, fTextSize/2, 2.4f*fTextSize, paint); 1339c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com setTypeface(&paint, "Times", SkTypeface::kItalic); 1349c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint); 1359c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com setTypeface(&paint, "Times", SkTypeface::kBoldItalic); 1369c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint); 1379c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1389c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com private: 1399c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com typedef DownsampleBitmapGM INHERITED; 1409c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com}; 1419c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1429c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comclass DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM { 1439c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com public: 144af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com DownsampleBitmapCheckerboardGM(int size, int numChecks, SkPaint::FilterLevel filterLevel) 145af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) 1469c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com { 147e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterLevelToString(), fSize, fNumChecks); 1489c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1499c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1509c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com protected: 1519c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com int fSize; 1529c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com int fNumChecks; 1539c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 15472c9faab45124e08c85f70ca38536914862d947cmtklein void make_bitmap() SK_OVERRIDE { 155c695e954174e4a789631ea4d6e171bd7118ebc67reed make_checker(&fBM, fSize, fNumChecks); 1569c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1579c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com private: 1589c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com typedef DownsampleBitmapGM INHERITED; 1599c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com}; 1609c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1619c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.comclass DownsampleBitmapImageGM: public DownsampleBitmapGM { 1629c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com public: 163af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com DownsampleBitmapImageGM(const char filename[], SkPaint::FilterLevel filterLevel) 164af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com : INHERITED(filterLevel), fFilename(filename) 1659c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com { 166e2cf805e9ae57f259307ab0834dd23dfe468c316humper@google.com fName.printf("downsamplebitmap_image_%s_%s", this->filterLevelToString(), filename); 1679c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1689c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 1699c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com protected: 1709c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkString fFilename; 1719c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com int fSize; 1729c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 17372c9faab45124e08c85f70ca38536914862d947cmtklein void make_bitmap() SK_OVERRIDE { 174bcbc1788b478b1e54079318ad073e8490aa66faetfarina SkImageDecoder* codec = NULL; 175c846f4a96bcde1ffeaf17afc1469db6f2cbd1ad3tfarina SkString resourcePath = GetResourcePath(fFilename.c_str()); 176bcbc1788b478b1e54079318ad073e8490aa66faetfarina SkFILEStream stream(resourcePath.c_str()); 1779c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com if (stream.isValid()) { 1789c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com codec = SkImageDecoder::Factory(&stream); 1799c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1809c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com if (codec) { 1819c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com stream.rewind(); 182bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71ereed codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); 1839c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com SkDELETE(codec); 1849c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } else { 185eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com fBM.allocN32Pixels(1, 1); 1869c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad 1879c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1889c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com fSize = fBM.height(); 1899c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com } 1909c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com private: 1919c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com typedef DownsampleBitmapGM INHERITED; 1929c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com}; 1939c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 194c695e954174e4a789631ea4d6e171bd7118ebc67reed#include "SkMipMap.h" 195c695e954174e4a789631ea4d6e171bd7118ebc67reedclass ShowMipLevels : public skiagm::GM { 196c695e954174e4a789631ea4d6e171bd7118ebc67reedpublic: 197c695e954174e4a789631ea4d6e171bd7118ebc67reed SkBitmap fBM; 198c695e954174e4a789631ea4d6e171bd7118ebc67reed 199c695e954174e4a789631ea4d6e171bd7118ebc67reed ShowMipLevels() { 200c695e954174e4a789631ea4d6e171bd7118ebc67reed this->setBGColor(0xFFDDDDDD); 201c695e954174e4a789631ea4d6e171bd7118ebc67reed make_checker(&fBM, 512, 256); 202c695e954174e4a789631ea4d6e171bd7118ebc67reed } 203c695e954174e4a789631ea4d6e171bd7118ebc67reed 204c695e954174e4a789631ea4d6e171bd7118ebc67reedprotected: 205c695e954174e4a789631ea4d6e171bd7118ebc67reed 206c695e954174e4a789631ea4d6e171bd7118ebc67reed SkString onShortName() SK_OVERRIDE { 207c695e954174e4a789631ea4d6e171bd7118ebc67reed return SkString("showmiplevels"); 208c695e954174e4a789631ea4d6e171bd7118ebc67reed } 209c695e954174e4a789631ea4d6e171bd7118ebc67reed 210c695e954174e4a789631ea4d6e171bd7118ebc67reed SkISize onISize() SK_OVERRIDE { 211c695e954174e4a789631ea4d6e171bd7118ebc67reed return SkISize::Make(fBM.width() + 8, 2 * fBM.height() + 80); 212c695e954174e4a789631ea4d6e171bd7118ebc67reed } 213c695e954174e4a789631ea4d6e171bd7118ebc67reed 214c695e954174e4a789631ea4d6e171bd7118ebc67reed void onDraw(SkCanvas* canvas) SK_OVERRIDE { 215c695e954174e4a789631ea4d6e171bd7118ebc67reed SkScalar x = 4; 216c695e954174e4a789631ea4d6e171bd7118ebc67reed SkScalar y = 4; 217c695e954174e4a789631ea4d6e171bd7118ebc67reed canvas->drawBitmap(fBM, x, y, NULL); 218c695e954174e4a789631ea4d6e171bd7118ebc67reed y += fBM.height() + 4; 219c695e954174e4a789631ea4d6e171bd7118ebc67reed 220c695e954174e4a789631ea4d6e171bd7118ebc67reed SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(fBM, NULL)); 221c695e954174e4a789631ea4d6e171bd7118ebc67reed 222c695e954174e4a789631ea4d6e171bd7118ebc67reed SkMipMap::Level level; 223c695e954174e4a789631ea4d6e171bd7118ebc67reed SkScalar scale = 0.5f; 224c695e954174e4a789631ea4d6e171bd7118ebc67reed while (mm->extractLevel(scale, &level)) { 225c695e954174e4a789631ea4d6e171bd7118ebc67reed SkImageInfo info = SkImageInfo::MakeN32Premul(level.fWidth, level.fHeight); 226c695e954174e4a789631ea4d6e171bd7118ebc67reed SkBitmap bm; 227c695e954174e4a789631ea4d6e171bd7118ebc67reed bm.installPixels(info, level.fPixels, level.fRowBytes); 228c695e954174e4a789631ea4d6e171bd7118ebc67reed canvas->drawBitmap(bm, x, y, NULL); 229c695e954174e4a789631ea4d6e171bd7118ebc67reed y += bm.height() + 4; 230c695e954174e4a789631ea4d6e171bd7118ebc67reed scale /= 2; 231c695e954174e4a789631ea4d6e171bd7118ebc67reed if (info.width() == 1 || info.height() == 1) { 232c695e954174e4a789631ea4d6e171bd7118ebc67reed break; 233c695e954174e4a789631ea4d6e171bd7118ebc67reed } 234c695e954174e4a789631ea4d6e171bd7118ebc67reed } 235c695e954174e4a789631ea4d6e171bd7118ebc67reed } 2361c4029296f518a84ef90095243ba210163a1e1f9mtklein 237c695e954174e4a789631ea4d6e171bd7118ebc67reedprivate: 238c695e954174e4a789631ea4d6e171bd7118ebc67reed typedef skiagm::GM INHERITED; 239c695e954174e4a789631ea4d6e171bd7118ebc67reed}; 240c695e954174e4a789631ea4d6e171bd7118ebc67reedDEF_GM( return new ShowMipLevels; ) 241c695e954174e4a789631ea4d6e171bd7118ebc67reed 2429c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com////////////////////////////////////////////////////////////////////////////// 2439c96d4b5ffdbf8c82f55b2058a2fea7225fe11d6humper@google.com 244af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); ) 245af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kHigh_FilterLevel); ) 246af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kHigh_FilterLevel); ) 247efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomonDEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", 248efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomon SkPaint::kHigh_FilterLevel); ) 249af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com 250af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kMedium_FilterLevel); ) 251af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kMedium_FilterLevel); ) 252af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kMedium_FilterLevel); ) 253efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomonDEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", 254efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomon SkPaint::kMedium_FilterLevel); ) 255af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com 256af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kLow_FilterLevel); ) 257af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterLevel); ) 258af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_FilterLevel); ) 259efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomonDEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", 260efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomon SkPaint::kLow_FilterLevel); ) 261af42a03051e6a588cda01a988c31eb6493d7d299humper@google.com 262af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) 263af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_FilterLevel); ) 264af42a03051e6a588cda01a988c31eb6493d7d299humper@google.comDEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_FilterLevel); ) 265efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomonDEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", 266efd7d45fc0fc5f2b924c774c5d38ce546f35f3cabsalomon SkPaint::kNone_FilterLevel); ) 267