use SkColorType instead of SkBitmap::Config in samplecode
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 17 Feb 2014 02:55:57 +0000 (02:55 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 17 Feb 2014 02:55:57 +0000 (02:55 +0000)
BUG=skia:
R=reed@google.com

Author: reed@chromium.org

Review URL: https://codereview.chromium.org/169063002

git-svn-id: http://skia.googlecode.com/svn/trunk@13473 2bbb7eff-a529-9590-31e7-b0007b416f81

36 files changed:
samplecode/SampleAAClip.cpp
samplecode/SampleAARectModes.cpp
samplecode/SampleAARects.cpp
samplecode/SampleApp.cpp
samplecode/SampleBitmapRect.cpp
samplecode/SampleBlur.cpp
samplecode/SampleColorFilter.cpp
samplecode/SampleDash.cpp
samplecode/SampleDither.cpp
samplecode/SampleDitherBitmap.cpp
samplecode/SampleEncode.cpp
samplecode/SampleFatBits.cpp
samplecode/SampleFilter.cpp
samplecode/SampleFilter2.cpp
samplecode/SampleFilterFuzz.cpp
samplecode/SampleFontCache.cpp
samplecode/SampleHairModes.cpp
samplecode/SampleHairline.cpp
samplecode/SampleLayerMask.cpp
samplecode/SampleMipMap.cpp
samplecode/SampleOvalTest.cpp
samplecode/SamplePath.cpp
samplecode/SampleRegion.cpp
samplecode/SampleRepeatTile.cpp
samplecode/SampleRotateCircles.cpp
samplecode/SampleShaderText.cpp
samplecode/SampleSlides.cpp
samplecode/SampleText.cpp
samplecode/SampleTextAlpha.cpp
samplecode/SampleTextureDomain.cpp
samplecode/SampleTiling.cpp
samplecode/SampleTinyBitmap.cpp
samplecode/SampleUnpremul.cpp
samplecode/SampleVertices.cpp
samplecode/SampleWritePixels.cpp
samplecode/SampleXfermodesBlur.cpp

index d4e632d7af6f7b1bf288bfc22e933b4d54a27b39..5419f68ed19c4d5aa04eefc804e381a27bfdcc4c 100644 (file)
@@ -46,9 +46,9 @@ static void drawClip(SkCanvas* canvas, const SkAAClip& clip) {
     clip.copyToMask(&mask);
     SkAutoMaskFreeImage amfi(mask.fImage);
 
-    bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(),
-                 mask.fBounds.height(), mask.fRowBytes);
-    bm.setPixels(mask.fImage);
+    bm.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(),
+                                         mask.fBounds.height()),
+                     mask.fImage, mask.fRowBytes, NULL, NULL);
 
     SkPaint paint;
     canvas->drawBitmap(bm,
index 3a8eb13749824b6d8ae7c3e4ec05dd9b6427b7b7..bea0e28799bcb978a144caa5f178f0526d23258b 100644 (file)
@@ -63,8 +63,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
 
 static SkShader* make_bg_shader() {
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
-    bm.allocPixels();
+    bm.allocN32Pixels(2, 2);
     *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
     *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCC,
                                                              0xCC, 0xCC);
index e84c9664a0eee6a1c47e148608580b921aa125c5..f552df6f1586c4ac580ea6d2fe97926c185b3f80 100644 (file)
@@ -14,8 +14,7 @@
 
 static SkBitmap createBitmap(int n) {
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kARGB_8888_Config, n, n);
-    bitmap.allocPixels();
+    bitmap.allocN32Pixels(n, n);
     bitmap.eraseColor(SK_ColorGREEN);
 
     SkCanvas canvas(bitmap);
index 5b37662dcd55175a37473a0dc5d475cfc773709f..80ffaaa6cfb10faf24acd04a493a9afe785bd385 100644 (file)
@@ -1363,24 +1363,6 @@ void SampleWindow::onDraw(SkCanvas* canvas) {
 
 #include "SkColorPriv.h"
 
-#if 0 // UNUSED
-static void reverseRedAndBlue(const SkBitmap& bm) {
-    SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
-    uint8_t* p = (uint8_t*)bm.getPixels();
-    uint8_t* stop = p + bm.getSize();
-    while (p < stop) {
-        // swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply
-        unsigned scale = SkAlpha255To256(p[3]);
-        unsigned r = p[2];
-        unsigned b = p[0];
-        p[0] = SkAlphaMul(r, scale);
-        p[1] = SkAlphaMul(p[1], scale);
-        p[2] = SkAlphaMul(b, scale);
-        p += 4;
-    }
-}
-#endif
-
 void SampleWindow::saveToPdf()
 {
     fSaveToPdf = true;
@@ -1576,7 +1558,7 @@ static SkColorType gColorTypeCycle[] = {
     kUnknown_SkColorType,           // index8 -> none
 };
 
-static SkColorType cycle_configs(SkColorType c) {
+static SkColorType cycle_colortypes(SkColorType c) {
     return gColorTypeCycle[c];
 }
 
@@ -1974,7 +1956,7 @@ bool SampleWindow::onHandleKey(SkKey key) {
             if (USE_ARROWS_FOR_ZOOM) {
                 this->changeZoomLevel(-1.f / 32.f);
             } else {
-                this->setColorType(cycle_configs(this->getBitmap().colorType()));
+                this->setColorType(cycle_colortypes(this->getBitmap().colorType()));
                 this->updateTitle();
             }
             return true;
index 422ed583efb4b7ed79ce71ff110c740fd04a13fc..cf1196c62d7fe9a96328baa0bb2b27804ebc1ae1 100644 (file)
@@ -34,8 +34,7 @@ class GrContext;
 #define SCALAR_SIZE     SkIntToScalar(INT_SIZE)
 
 static void make_bitmap(SkBitmap* bitmap) {
-    bitmap->setConfig(SkBitmap::kARGB_8888_Config, INT_SIZE, INT_SIZE);
-    bitmap->allocPixels();
+    bitmap->allocN32Pixels(INT_SIZE, INT_SIZE);
     SkCanvas canvas(*bitmap);
 
     canvas.drawColor(SK_ColorRED);
@@ -164,8 +163,7 @@ static void make_big_bitmap(SkBitmap* bm) {
 
     const int BIG_W = SkScalarRoundToInt(paint.measureText(gText, strlen(gText)));
 
-    bm->setConfig(SkBitmap::kARGB_8888_Config, BIG_W, BIG_H);
-    bm->allocPixels();
+    bm->allocN32Pixels(BIG_W, BIG_H);
     bm->eraseColor(SK_ColorWHITE);
 
     SkCanvas canvas(*bm);
index d951d8508b528961c9444405835294ac6d541123..a918bf217b7d9a9582e36018fe1b74d9057d2bc0 100644 (file)
@@ -23,8 +23,9 @@ static SkBitmap make_bitmap() {
     SkBitmap bm;
     SkColorTable* ctable = new SkColorTable(c, 256);
 
-    bm.setConfig(SkBitmap::kIndex8_Config, 256, 256);
-    bm.allocPixels(ctable);
+    bm.allocPixels(SkImageInfo::Make(256, 256, kIndex_8_SkColorType,
+                                     kPremul_SkAlphaType),
+                   NULL, ctable);
     ctable->unref();
 
     bm.lockPixels();
index 7218268b625e52ac7661381e88ad203eb2575bdf..2dc2e427dcf0292c6415eb2d6539ece1e5b302ce 100644 (file)
@@ -88,8 +88,7 @@ static void test_5bits() {
 SkShader* createChecker();
 SkShader* createChecker() {
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
-    bm.allocPixels();
+    bm.allocN32Pixels(2, 2);
     bm.lockPixels();
     *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(0xFFFFFFFF);
     *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(0xFFCCCCCC);
@@ -104,8 +103,7 @@ SkShader* createChecker() {
 
 static SkBitmap createBitmap(int n) {
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kARGB_8888_Config, n, n);
-    bitmap.allocPixels();
+    bitmap.allocN32Pixels(n, n);
     bitmap.eraseColor(SK_ColorTRANSPARENT);
 
     SkCanvas canvas(bitmap);
index 20e28969c8044652379dd7eea327db2e05474ced..26d36942dfadced7b2aa952e8b35f2b66039f8d9 100644 (file)
@@ -17,8 +17,7 @@ static void setBitmapDash(SkPaint* paint, int width) {
     SkColor c = paint->getColor();
 
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 1);
-    bm.allocPixels();
+    bm.allocN32Pixels(2, 1);
     bm.lockPixels();
     *bm.getAddr32(0, 0) = SkPreMultiplyARGB(0xFF, SkColorGetR(c),
                                             SkColorGetG(c), SkColorGetB(c));
index 38d67ad7cf748858506d2d72787395657a4b29b6..57c7613d93dc761febaf67772cc43e5fa453ade5 100644 (file)
@@ -70,14 +70,8 @@ static void draw_sweep(SkCanvas* c, int width, int height, SkScalar angle) {
 }
 
 static void make_bm(SkBitmap* bm) {
-    bm->setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
-    bm->allocPixels();
-#if 0
-    bm->eraseColor(SK_ColorBLUE);
-    return;
-#else
+    bm->allocN32Pixels(100, 100);
     bm->eraseColor(SK_ColorTRANSPARENT);
-#endif
 
     SkCanvas c(*bm);
     draw_sweep(&c, bm->width(), bm->height(), 0);
index dc439002d0c8d853d419dafffb49f23ba35bad2f..d6d15e9887749e87c6b8a18dd4dee40f8ddcffa5 100644 (file)
@@ -60,8 +60,9 @@ static SkBitmap make_bitmap() {
     SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
 
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kIndex8_Config, 256, 32);
-    bm.allocPixels(ctable);
+    bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType,
+                                     kPremul_SkAlphaType),
+                   NULL, ctable);
     ctable->unref();
 
     bm.lockPixels();
@@ -101,14 +102,6 @@ protected:
     static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
         SkAutoLockPixels alp(*bm);  // needed for ctable
         bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
-#if 0
-        SkColorTable* ctable = bm->getColorTable();
-        if (ctable) {
-            if (ctable->isOpaque() != isOpaque) {
-                // how do we change a colortable? don't want to
-            }
-        }
-#endif
     }
 
     static void draw2(SkCanvas* canvas, const SkBitmap& bm) {
index 7af47a697ec6a21d4092b4a766fbbd030d976bde..4769fbb0a87f0e2d97eb8be1f0db2c87e57ca0a9 100644 (file)
 
 #include "SkStream.h"
 
-static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
+static void make_image(SkBitmap* bm, SkColorType ct, int configIndex) {
     const int   width = 98;
     const int   height = 100;
-    SkBitmap    device;
-
-    device.setConfig(SkBitmap::kARGB_8888_Config, width, height);
-    device.allocPixels();
+    const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType);
 
+    SkBitmap    device;
+    device.allocN32Pixels(width, height);
     SkCanvas    canvas(device);
     SkPaint     paint;
 
@@ -43,13 +42,12 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
     canvas.drawCircle(SkIntToScalar(width)/2, SkIntToScalar(height)/2,
                       SkIntToScalar(width)/2, paint);
 
-    bm->setConfig(config, width, height);
-    switch (config) {
-        case SkBitmap::kARGB_8888_Config:
+    switch (ct) {
+        case kPMColor_SkColorType:
             bm->swap(device);
             break;
-        case SkBitmap::kRGB_565_Config: {
-            bm->allocPixels();
+        case kRGB_565_SkColorType: {
+            bm->allocPixels(info);
             for (int y = 0; y < height; y++) {
                 for (int x = 0; x < width; x++) {
                     *bm->getAddr16(x, y) = SkPixel32ToPixel16(*device.getAddr32(x, y));
@@ -57,7 +55,7 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
             }
             break;
         }
-        case SkBitmap::kIndex8_Config: {
+        case kIndex_8_SkColorType: {
             SkPMColor colors[256];
             for (int i = 0; i < 256; i++) {
                 if (configIndex & 1) {
@@ -67,9 +65,8 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
                 }
             }
             SkColorTable* ctable = new SkColorTable(colors, 256);
-            bm->allocPixels(ctable);
+            bm->allocPixels(info, NULL, ctable);
             ctable->unref();
-
             for (int y = 0; y < height; y++) {
                 for (int x = 0; x < width; x++) {
                     *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y));
@@ -78,16 +75,16 @@ static void make_image(SkBitmap* bm, SkBitmap::Config config, int configIndex) {
             break;
         }
         default:
-            break;
+            SkASSERT(0);
     }
 }
 
 // configs to build the original bitmap in. Can be at most these 3
-static const SkBitmap::Config gConfigs[] = {
-    SkBitmap::kARGB_8888_Config,
-    SkBitmap::kRGB_565_Config,
-    SkBitmap::kIndex8_Config,   // opaque
-    SkBitmap::kIndex8_Config    // alpha
+static const SkColorType gColorTypes[] = {
+    kPMColor_SkColorType,
+    kRGB_565_SkColorType,
+    kIndex_8_SkColorType,   // opaque
+    kIndex_8_SkColorType    // alpha
 };
 
 static const char* const gConfigLabels[] = {
@@ -115,13 +112,12 @@ public:
     int              fBitmapCount;
 
     EncodeView() {
-    #if 1
-        fBitmapCount = SK_ARRAY_COUNT(gConfigs);
+        fBitmapCount = SK_ARRAY_COUNT(gColorTypes);
         fBitmaps = new SkBitmap[fBitmapCount];
         fEncodedPNGs = new SkAutoDataUnref[fBitmapCount];
         fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount];
         for (int i = 0; i < fBitmapCount; i++) {
-            make_image(&fBitmaps[i], gConfigs[i], i);
+            make_image(&fBitmaps[i], gColorTypes[i], i);
 
             for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
                 SkAutoTDelete<SkImageEncoder> codec(
@@ -144,10 +140,6 @@ public:
                 }
             }
         }
-    #else
-        fBitmaps = NULL;
-        fBitmapCount = 0;
-    #endif
         this->setBGColor(0xFFDDDDDD);
     }
 
index 8b486bd016ce857ba0564dfebad97446e2d5cfe8..6900fae3eb6583e9394fbae83a273d3e360566b7 100644 (file)
@@ -39,8 +39,7 @@ static SkShader* createChecker() {
 //    SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
     SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
-    bm.allocPixels();
+    bm.allocN32Pixels(2, 2);
     bm.lockPixels();
     *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
     *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
index 7f902d5b2e9390b64b2721fac72729927ad26511..1b26bf246341bf66f6975f834ca60883bffdd152 100644 (file)
 #include "SkDither.h"
 
 static void make_bm(SkBitmap* bm) {
-    const SkColor colors[] = {
-        SK_ColorRED, SK_ColorGREEN,
-        SK_ColorBLUE, SK_ColorWHITE
+    const SkPMColor colors[] = {
+        SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN),
+        SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE)
     };
     SkColorTable* ctable = new SkColorTable(colors, 4);
-    bm->setConfig(SkBitmap::kIndex8_Config, 2, 2);
-    bm->allocPixels(ctable);
+    bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
+                                      kOpaque_SkAlphaType),
+                    NULL, ctable);
     ctable->unref();
 
     *bm->getAddr8(0, 0) = 0;
@@ -39,22 +40,8 @@ static void make_bm(SkBitmap* bm) {
 
 static SkScalar draw_bm(SkCanvas* canvas, const SkBitmap& bm,
                         SkScalar x, SkScalar y, SkPaint* paint) {
-#if 1
     canvas->drawBitmap(bm, x, y, paint);
     return SkIntToScalar(bm.width()) * 5/4;
-#else
-    SkAutoCanvasRestore acr(canvas, true);
-    canvas->translate(x, y);
-
-    SkScalar w = SkIntToScalar(bm.width());
-    SkScalar h = SkIntToScalar(bm.height());
-    SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                               SkShader::kRepeat_TileMode);
-    paint->setShader(s)->unref();
-    canvas->drawRect(SkRect::MakeWH(w, h), *paint);
-    paint->setShader(NULL);
-    return w * 5/4;
-#endif
 }
 
 static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p) {
index f3ab7f4574b1e2c7c5449151f89b54791fbb4869..552ce8a83cba17cc61e8a58fe05de8b49e7590e7 100644 (file)
@@ -103,7 +103,7 @@ protected:
                         p.setTextSize(SkIntToScalar(18));
                         SkString s;
                         s.append(" depth=");
-                        s.appendS32(fBitmaps[i].config() == SkBitmap::kRGB_565_Config ? 16 : 32);
+                        s.appendS32(fBitmaps[i].colorType() == kRGB_565_SkColorType ? 16 : 32);
                         canvas->drawText(s.c_str(), s.size(), x + W + SkIntToScalar(4),
                                          y + H/2, p);
                     }
index 4ef7d4033a897b0ed4cffa29a092f3d437991db5..f753b503049c8f346f9cd5b000306bbcae615b9b 100644 (file)
@@ -111,13 +111,36 @@ static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type()
     return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1);
 }
 
-static void make_g_bitmap(SkBitmap& bitmap) {
-    bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
-    while (!bitmap.allocPixels()) {
-        bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
+static bool valid_for_raster_canvas(const SkImageInfo& info) {
+    switch (info.colorType()) {
+        case kAlpha_8_SkColorType:
+        case kRGB_565_SkColorType:
+            return true;
+        case kPMColor_SkColorType:
+            return kPremul_SkAlphaType == info.alphaType() ||
+                   kOpaque_SkAlphaType == info.alphaType();
+        default:
+            break;
     }
-    SkBitmapDevice device(bitmap);
-    SkCanvas canvas(&device);
+    return false;
+}
+
+static SkColorType rand_colortype() {
+    return (SkColorType)R(kLastEnum_SkColorType + 1);
+}
+
+static void rand_bitmap_for_canvas(SkBitmap* bitmap) {
+    SkImageInfo info;
+    do {
+        info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(),
+                                 kPremul_SkAlphaType);
+    } while (!valid_for_raster_canvas(info) || !bitmap->allocPixels(info));
+}
+
+static void make_g_bitmap(SkBitmap& bitmap) {
+    rand_bitmap_for_canvas(&bitmap);
+
+    SkCanvas canvas(bitmap);
     canvas.clear(0x00000000);
     SkPaint paint;
     paint.setAntiAlias(true);
@@ -128,31 +151,10 @@ static void make_g_bitmap(SkBitmap& bitmap) {
                     SkIntToScalar(kBitmapSize/4), paint);
 }
 
-static bool valid_for_raster_canvas(const SkBitmap& bm) {
-    SkImageInfo info;
-    if (!bm.asImageInfo(&info)) {
-        return false;
-    }
-    switch (info.fColorType) {
-        case kAlpha_8_SkColorType:
-        case kRGB_565_SkColorType:
-            return true;
-        case kPMColor_SkColorType:
-            return kPremul_SkAlphaType == info.fAlphaType ||
-                   kOpaque_SkAlphaType == info.fAlphaType;
-        default:
-            break;
-    }
-    return false;
-}
-
 static void make_checkerboard_bitmap(SkBitmap& bitmap) {
-    bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
-    while (valid_for_raster_canvas(bitmap) && !bitmap.allocPixels()) {
-        bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
-    }
-    SkBitmapDevice device(bitmap);
-    SkCanvas canvas(&device);
+    rand_bitmap_for_canvas(&bitmap);
+
+    SkCanvas canvas(bitmap);
     canvas.clear(0x00000000);
     SkPaint darkPaint;
     darkPaint.setColor(0xFF804020);
index c5f44577294ff80418714823a96df59c9f8c0615..77f66b0eff58d63fd83043f41e8d7ae84f9bfdd7 100644 (file)
@@ -92,8 +92,9 @@ public:
             status = pthread_create(&fMThreads[i], NULL,  measure_proc, NULL);
             SkASSERT(0 == status);
 
-            fBitmaps[i].setConfig(SkBitmap::kRGB_565_Config, 320, 240);
-            fBitmaps[i].allocPixels();
+            fBitmaps[i].allocPixels(SkImageInfo::Make(320, 240,
+                                                      kRGB_565_SkColorType,
+                                                      kOpaque_SkAlphaType));
             status = pthread_create(&fDThreads[i], NULL,  draw_proc, &fBitmaps[i]);
             SkASSERT(0 == status);
         }
index 4168ffd6b42c6b4d027390848230a10c000cc6bb..4aa8e0208fea318fc9aa1e2ce4f3d07fee234a61 100644 (file)
@@ -62,8 +62,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha
 
 static SkShader* make_bg_shader() {
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
-    bm.allocPixels();
+    bm.allocN32Pixels(2, 2);
     *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
     *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCC, 0xCC, 0xCC);
 
index f08146e672cb1e13e562bbd5ba651b0453aa5fa1..4ac8b6255a26f846cb97d19243d4b622d9d9d298 100644 (file)
@@ -33,8 +33,7 @@ static SkRandom gRand;
 
 static void test_chromium_9005() {
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config, 800, 600);
-    bm.allocPixels();
+    bm.allocN32Pixels(800, 600);
 
     SkCanvas canvas(bm);
 
@@ -227,16 +226,13 @@ protected:
         }
 
         SkBitmap bm, bm2;
-        bm.setConfig(SkBitmap::kARGB_8888_Config,
-                     WIDTH + MARGIN*2,
-                     HEIGHT + MARGIN*2);
-        bm.allocPixels();
+        bm.allocN32Pixels(WIDTH + MARGIN*2, HEIGHT + MARGIN*2);
         // this will erase our margin, which we want to always stay 0
         bm.eraseColor(SK_ColorTRANSPARENT);
 
-        bm2.setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT,
-                      bm.rowBytes());
-        bm2.setPixels(bm.getAddr32(MARGIN, MARGIN));
+        bm2.installPixels(SkImageInfo::MakeN32Premul(WIDTH, HEIGHT),
+                          bm.getAddr32(MARGIN, MARGIN), bm.rowBytes(),
+                          NULL, NULL);
 
         SkCanvas c2(bm2);
         SkPaint paint;
index 33c06d1cb2c770d63753ad04b337e736c8e1c7d9..b3bbac622fd03fd22293d28b07fe45b5262ea211 100644 (file)
@@ -36,8 +36,7 @@ protected:
             SkBitmap mask;
             int w = SkScalarRoundToInt(r.width());
             int h = SkScalarRoundToInt(r.height());
-            mask.setConfig(SkBitmap::kARGB_8888_Config, w, h);
-            mask.allocPixels();
+            mask.allocN32Pixels(w, h);
             mask.eraseColor(SK_ColorTRANSPARENT);
             SkCanvas c(mask);
             SkRect bounds = r;
index 3cfeeb704ecec46a502c9a9a70850c6b24efcb12..a9804ac5e41a6db55fbbe196d9f3cc03ec42d720 100644 (file)
@@ -14,8 +14,7 @@
 
 static SkBitmap createBitmap(int n) {
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kARGB_8888_Config, n, n);
-    bitmap.allocPixels();
+    bitmap.allocN32Pixels(n, n);
     bitmap.eraseColor(SK_ColorTRANSPARENT);
 
     SkCanvas canvas(bitmap);
index a105b82801b3d4bf038afcd995bf069dd4a8ef1d..ef9c20d031dbcd14a532a10e76a08ed32209e390 100644 (file)
@@ -22,8 +22,7 @@ public:
     OvalTestView() {
         fSize.set(SK_Scalar1, SK_Scalar1);
 
-        fBitmap.setConfig(SkBitmap::kARGB_8888_Config, kILimit, kILimit);
-        fBitmap.allocPixels();
+        fBitmap.allocN32Pixels(kILimit, kILimit);
 
         fInsideColor = SkPreMultiplyColor(SK_ColorRED);
         fOutsideColor = SkPreMultiplyColor(SK_ColorGREEN);
index a09be281b49f0988d0edd3e74598179d84f7bd84..e35eeb6717575ffe2e91c1ca349cc2e1b5c449f5 100644 (file)
@@ -73,8 +73,7 @@ static void test_cubic2() {
     }
 
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 300, 200);
-    bitmap.allocPixels();
+    bitmap.allocN32Pixels(300, 200);
 
     SkCanvas canvas(bitmap);
     SkPaint paint;
index c29f0907ce896180cd25351ca2c0bc12548564bd..54858de7a13eb68a2213b4e8cc61bd1c54ffe5e1 100644 (file)
@@ -20,8 +20,7 @@ static void test_strokerect(SkCanvas* canvas) {
     int height = 100;
 
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kA8_Config, width*2, height*2);
-    bitmap.allocPixels();
+    bitmap.allocPixels(SkImageInfo::MakeA8(width*2, height*2));
     bitmap.eraseColor(SK_ColorTRANSPARENT);
 
     SkScalar dx = 20;
index 988345c0fc947ed09b78a0c9d06232e4364aeadf..b352894329584f84d13392655f3d60785b4b47fe 100644 (file)
@@ -14,8 +14,7 @@
 static void make_bitmap(SkBitmap* bm) {
     const int W = 100;
     const int H = 100;
-    bm->setConfig(SkBitmap::kARGB_8888_Config, W, H);
-    bm->allocPixels();
+    bm->allocN32Pixels(W, H);
 
     SkPaint paint;
     SkCanvas canvas(*bm);
index 537f42485b1618b524aa0313eaaa877dd863a3c4..f9b32ea4170ef7161045baff4485b65c4918f486 100644 (file)
@@ -108,8 +108,7 @@ protected:
         int h = w;
 
         SkBitmap bm;
-        bm.setConfig(SkBitmap::kARGB_8888_Config, w, h);
-        bm.allocPixels();
+        bm.allocN32Pixels(w, h);
         bm.eraseColor(0);
 
         SkAutoLockPixels alp(bm);
index 6855824d3fb669946c032b68b2e025979e8ff659..c7048ab401c37c5a928c8206ffc9ab5e08167303 100644 (file)
@@ -11,9 +11,8 @@
 #include "SkGradientShader.h"
 #include "SkUnitMappers.h"
 
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
-    bm->setConfig(config, w, h);
-    bm->allocPixels();
+static void makebm(SkBitmap* bm, int w, int h) {
+    bm->allocN32Pixels(w, h);
     bm->eraseColor(SK_ColorTRANSPARENT);
 
     SkCanvas    canvas(*bm);
@@ -39,7 +38,7 @@ static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty,
                            int w, int h) {
     static SkBitmap bmp;
     if (bmp.isNull()) {
-        makebm(&bmp, SkBitmap::kARGB_8888_Config, w/2, h/4);
+        makebm(&bmp, w/2, h/4);
     }
     return SkShader::CreateBitmapShader(bmp, tx, ty);
 }
index 4f6803221cbf3ab1f620b93b26cd1231426638d5..26cfc7d1a36bfb6fefae6fe18c4bb0884215bb45 100644 (file)
@@ -686,8 +686,7 @@ public:
         fIndex = 0;
 
         SkBitmap bm;
-        bm.setConfig(SkBitmap::kARGB_8888_Config, 1024, 768);
-        bm.allocPixels();
+        bm.allocN32Pixels(1024, 768);
         SkCanvas canvas(bm);
         SkScalar s = SkIntToScalar(1024) / 640;
         canvas.scale(s, s);
index 7e98171daa4ea96215d1f9acd40376c61f7c2b06..c1aca6398c6cb6cbbc8693067a5ee067b55c6948 100644 (file)
@@ -273,8 +273,8 @@ protected:
     }
 
     static void make_textstrip(SkBitmap* bm) {
-        bm->setConfig(SkBitmap::kRGB_565_Config, 200, 18);
-        bm->allocPixels();
+        bm->allocPixels(SkImageInfo::Make(200, 18, kRGB_565_SkColorType,
+                                          kOpaque_SkAlphaType));
         bm->eraseColor(SK_ColorWHITE);
 
         SkCanvas    canvas(*bm);
index 83616f42602ceac91fc44df3d8d607cac6b94cd1..2732452c82b5f5e2a774b05ff7178f0025ca0cd0 100644 (file)
@@ -29,7 +29,7 @@
 #include "SkStream.h"
 
 static void check_for_nonwhite(const SkBitmap& bm, int alpha) {
-    if (bm.config() != SkBitmap::kRGB_565_Config) {
+    if (bm.colorType() != kRGB_565_SkColorType) {
         return;
     }
 
index 854df6ecfd9f0ea904937104bd8ff2075b8e2074..47a3ab0a09c0cef1ffd2f7d5118264ccfb73ed37 100644 (file)
@@ -13,8 +13,7 @@
 
 static SkBitmap make_bitmap() {
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5);
-    bm.allocPixels();
+    bm.allocN32Pixels(5, 5);
 
     for (int y = 0; y < bm.height(); y++) {
         uint32_t* p = bm.getAddr32(0, y);
index c35cf888463d6eb1aaeacb94d443552a8bae9c15..735b9907ef4e784776955cb59fef322189937192 100644 (file)
@@ -24,9 +24,8 @@
 #include "SkBlurMask.h"
 #include "SkBlurDrawLooper.h"
 
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
-    bm->setConfig(config, w, h);
-    bm->allocPixels();
+static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
+    bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
     bm->eraseColor(SK_ColorTRANSPARENT);
 
     SkCanvas    canvas(*bm);
@@ -55,9 +54,9 @@ static void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
     paint->setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
 }
 
-static const SkBitmap::Config gConfigs[] = {
-    SkBitmap::kARGB_8888_Config,
-    SkBitmap::kRGB_565_Config,
+static const SkColorType gColorTypes[] = {
+    kPMColor_SkColorType,
+    kRGB_565_SkColorType,
 };
 static const int gWidth = 32;
 static const int gHeight = 32;
@@ -71,8 +70,8 @@ public:
                       SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
                       SkIntToScalar(2), SkIntToScalar(2)) {
         fTextPicture = new SkPicture();
-        for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
-            makebm(&fTexture[i], gConfigs[i], gWidth, gHeight);
+        for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
+            makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight);
         }
     }
 
@@ -80,7 +79,7 @@ public:
         fTextPicture->unref();
     }
 
-    SkBitmap    fTexture[SK_ARRAY_COUNT(gConfigs)];
+    SkBitmap    fTexture[SK_ARRAY_COUNT(gColorTypes)];
 
 protected:
     // overrides from SkEventSink
@@ -131,7 +130,7 @@ protected:
 
         y += SkIntToScalar(16);
 
-        for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
+        for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
             for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) {
                 x = SkIntToScalar(10);
                 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
index 72664c7fc81f1d86848d18b3e2f81ddcac56a47a..57ce2ff319ce9770de3b9775d95e954138af21d2 100644 (file)
@@ -22,8 +22,9 @@ static SkBitmap make_bitmap() {
     SkColorTable* ctable = new SkColorTable(c, N);
 
     SkBitmap bm;
-    bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
-    bm.allocPixels(ctable);
+    bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
+                                     kPremul_SkAlphaType),
+                   NULL, ctable);
     ctable->unref();
 
     bm.lockPixels();
index 58d8ec248c3cb9ac47814b4b5af986b61984ab53..f2f60cc3129e7c3798ba35ccd66f3bcb157fb644 100644 (file)
@@ -125,10 +125,7 @@ protected:
             // Copy it to a bitmap which can be drawn, converting
             // to premultiplied:
             SkBitmap bm;
-            bm.setConfig(SkBitmap::kARGB_8888_Config, fBitmap.width(),
-                         fBitmap.height());
-            SkASSERT(fBitmap.config() == SkBitmap::kARGB_8888_Config);
-            if (!bm.allocPixels()) {
+            if (!bm.allocN32Pixels(fBitmap.width(), fBitmap.height())) {
                 SkString errMsg("allocPixels failed");
                 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint);
                 return;
index 323c4b58cb00889bd35400e1f4d04baa9e2c4ccb..4c3a17eb004bc394cbac09b961b01b492f2bd856 100644 (file)
 static SkShader* make_shader0(SkIPoint* size) {
     SkBitmap    bm;
     size->set(2, 2);
-    bm.setConfig(SkBitmap::kARGB_8888_Config, size->fX, size->fY);
     SkPMColor color0 = SkPreMultiplyARGB(0x80, 0x80, 0xff, 0x80);
     SkPMColor color1 = SkPreMultiplyARGB(0x40, 0xff, 0x00, 0xff);
-    bm.allocPixels();
+    bm.allocN32Pixels(size->fX, size->fY);
     bm.eraseColor(color0);
     bm.lockPixels();
     uint32_t* pixels = (uint32_t*) bm.getPixels();
index 04f34840e1821be5a510a230993789bbfb95d438..f7829eaada5bdd17745ab87238a68d470daf1954 100644 (file)
@@ -19,8 +19,7 @@
 static void create_bitmap(SkBitmap* bitmap) {
     const int W = 100;
     const int H = 100;
-    bitmap->setConfig(SkBitmap::kARGB_8888_Config, W, H);
-    bitmap->allocPixels();
+    bitmap->allocN32Pixels(W, H);
 
     SkCanvas canvas(*bitmap);
     canvas.drawColor(SK_ColorRED);
index 3b8b5920172732947547b0c9b26474e74c58da90..cae415d9d0ae878bf874044354088ea1dbd3c4d5 100644 (file)
@@ -76,8 +76,9 @@ public:
     const static int W = 64;
     const static int H = 64;
     XfermodesBlurView() {
-        fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType);
-        fBG.setPixels(gBG);
+        fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
+                                            kPremul_SkAlphaType),
+                          gBG, 4, NULL, NULL);
     }
 
 protected: