aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-13 22:00:04 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-13 22:00:04 +0000
commitfa9e5fa42a555712fb7a29d08d2ae2bdef0ed68e (patch)
tree3b697b22d1fa371f6e1a0420cc19f5c093aa9fa0
parenta7692a9ac6cb8a0bbe6bbdfc83f86014a7dc265e (diff)
replace setConfig+allocPixels with alloc-or-install-pixels
BUG=skia: R=scroggo@google.com, halcanary@google.com, reed@google.com Author: reed@chromium.org Review URL: https://codereview.chromium.org/164203003 git-svn-id: http://skia.googlecode.com/svn/trunk@13442 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--tests/AAClipTest.cpp8
-rw-r--r--tests/AnnotationTest.cpp3
-rw-r--r--tests/BitmapHeapTest.cpp3
-rw-r--r--tests/BitmapTest.cpp14
-rw-r--r--tests/BlitRowTest.cpp50
-rw-r--r--tests/BlurTest.cpp15
-rw-r--r--tests/CanvasStateTest.cpp14
-rw-r--r--tests/CanvasTest.cpp17
-rw-r--r--tests/ClipCubicTest.cpp3
-rw-r--r--tests/ClipperTest.cpp3
-rw-r--r--tests/DeferredCanvasTest.cpp30
-rw-r--r--tests/DeviceLooperTest.cpp4
-rw-r--r--tests/DrawBitmapRectTest.cpp18
-rw-r--r--tests/DrawPathTest.cpp21
-rw-r--r--tests/ReadPixelsTest.cpp16
-rw-r--r--tests/WritePixelsTest.cpp26
16 files changed, 116 insertions, 129 deletions
diff --git a/tests/AAClipTest.cpp b/tests/AAClipTest.cpp
index 961d57ad6b..cadd1806cf 100644
--- a/tests/AAClipTest.cpp
+++ b/tests/AAClipTest.cpp
@@ -71,10 +71,12 @@ static void copyToMask(const SkRegion& rgn, SkMask* mask) {
mask->fImage = SkMask::AllocImage(mask->computeImageSize());
sk_bzero(mask->fImage, mask->computeImageSize());
+ SkImageInfo info = SkImageInfo::Make(mask->fBounds.width(),
+ mask->fBounds.height(),
+ kAlpha_8_SkColorType,
+ kPremul_SkAlphaType);
SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kA8_Config, mask->fBounds.width(),
- mask->fBounds.height(), mask->fRowBytes);
- bitmap.setPixels(mask->fImage);
+ bitmap.installPixels(info, mask->fImage, mask->fRowBytes, NULL, NULL);
// canvas expects its coordinate system to always be 0,0 in the top/left
// so we translate the rgn to match that before drawing into the mask.
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index 3d146649a1..274d53ea4f 100644
--- a/tests/AnnotationTest.cpp
+++ b/tests/AnnotationTest.cpp
@@ -26,8 +26,7 @@ static bool ContainsString(const char* data, size_t dataSize, const char* needle
DEF_TEST(Annotation_NoDraw, reporter) {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
- bm.allocPixels();
+ bm.allocN32Pixels(10, 10);
bm.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bm);
diff --git a/tests/BitmapHeapTest.cpp b/tests/BitmapHeapTest.cpp
index da41f477f7..c6144b7c6a 100644
--- a/tests/BitmapHeapTest.cpp
+++ b/tests/BitmapHeapTest.cpp
@@ -33,8 +33,7 @@ public:
DEF_TEST(BitmapHeap, reporter) {
// Create a bitmap shader.
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
- bm.allocPixels();
+ bm.allocN32Pixels(2, 2);
bm.eraseColor(SK_ColorRED);
uint32_t* pixel = bm.getAddr32(1,0);
*pixel = SK_ColorBLUE;
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index e304076a34..0167d52d02 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -13,8 +13,11 @@ static void test_bigwidth(skiatest::Reporter* reporter) {
SkBitmap bm;
int width = 1 << 29; // *4 will be the high-bit of 32bit int
- REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kA8_Config, width, 1));
- REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kRGB_565_Config, width, 1));
+ SkImageInfo info = SkImageInfo::Make(width, 1, kAlpha_8_SkColorType,
+ kPremul_SkAlphaType);
+ REPORTER_ASSERT(reporter, bm.setConfig(info));
+ info.fColorType = kRGB_565_SkColorType;
+ REPORTER_ASSERT(reporter, bm.setConfig(info));
// for a 4-byte config, this width will compute a rowbytes of 0x80000000,
// which does not fit in a int32_t. setConfig should detect this, and fail.
@@ -22,19 +25,20 @@ static void test_bigwidth(skiatest::Reporter* reporter) {
// TODO: perhaps skia can relax this, and only require that rowBytes fit
// in a uint32_t (or larger), but for now this is the constraint.
- REPORTER_ASSERT(reporter, !bm.setConfig(SkBitmap::kARGB_8888_Config, width, 1));
+ info.fColorType = kPMColor_SkColorType;
+ REPORTER_ASSERT(reporter, !bm.setConfig(info));
}
/**
* This test contains basic sanity checks concerning bitmaps.
*/
DEF_TEST(Bitmap, reporter) {
- const SkBitmap::Config conf = SkBitmap::kARGB_8888_Config;
// Zero-sized bitmaps are allowed
for (int width = 0; width < 2; ++width) {
for (int height = 0; height < 2; ++height) {
SkBitmap bm;
- bool setConf = bm.setConfig(conf, width, height);
+ bool setConf = bm.setConfig(SkImageInfo::MakeN32Premul(width,
+ height));
REPORTER_ASSERT(reporter, setConf);
if (setConf) {
REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp
index 9ab620e904..84e61f307a 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -12,9 +12,9 @@
#include "SkRect.h"
#include "Test.h"
-// these are in the same order as the SkBitmap::Config enum
+// these are in the same order as the SkColorType enum
static const char* gConfigName[] = {
- "None", "A8", "Index8", "565", "4444", "8888"
+ "Unknown", "Alpha8", "565", "4444", "RGBA", "BGRA", "Index8"
};
/** Returns -1 on success, else the x coord of the first bad pixel, return its
@@ -100,11 +100,9 @@ static bool check_color(const SkBitmap& bm, SkPMColor expect32,
static void test_00_FF(skiatest::Reporter* reporter) {
static const int W = 256;
- static const SkBitmap::Config gDstConfig[] = {
- SkBitmap::kARGB_8888_Config,
- SkBitmap::kRGB_565_Config,
-// SkBitmap::kARGB_4444_Config,
-// SkBitmap::kA8_Config,
+ static const SkColorType gDstColorType[] = {
+ kPMColor_SkColorType,
+ kRGB_565_SkColorType,
};
static const struct {
@@ -123,13 +121,13 @@ static void test_00_FF(skiatest::Reporter* reporter) {
SkPaint paint;
SkBitmap srcBM;
- srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, 1);
- srcBM.allocPixels();
+ srcBM.allocN32Pixels(W, 1);
- for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gDstColorType); i++) {
+ SkImageInfo info = SkImageInfo::Make(W, 1, gDstColorType[i],
+ kPremul_SkAlphaType);
SkBitmap dstBM;
- dstBM.setConfig(gDstConfig[i], W, 1);
- dstBM.allocPixels();
+ dstBM.allocPixels(info);
SkCanvas canvas(dstBM);
for (size_t j = 0; j < SK_ARRAY_COUNT(gSrcRec); j++) {
@@ -193,11 +191,9 @@ static void test_diagonal(skiatest::Reporter* reporter) {
static const int W = 64;
static const int H = W;
- static const SkBitmap::Config gDstConfig[] = {
- SkBitmap::kARGB_8888_Config,
- SkBitmap::kRGB_565_Config,
- // SkBitmap::kARGB_4444_Config,
- // SkBitmap::kA8_Config,
+ static const SkColorType gDstColorType[] = {
+ kPMColor_SkColorType,
+ kRGB_565_SkColorType,
};
static const SkColor gDstBG[] = { 0, 0xFFFFFFFF };
@@ -205,20 +201,22 @@ static void test_diagonal(skiatest::Reporter* reporter) {
SkPaint paint;
SkBitmap srcBM;
- srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, H);
- srcBM.allocPixels();
+ srcBM.allocN32Pixels(W, H);
SkRect srcR = {
0, 0, SkIntToScalar(srcBM.width()), SkIntToScalar(srcBM.height()) };
// cons up a mesh to draw the bitmap with
Mesh mesh(srcBM, &paint);
- for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) {
+ SkImageInfo info = SkImageInfo::Make(W, H, kUnknown_SkColorType,
+ kPremul_SkAlphaType);
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gDstColorType); i++) {
+ info.fColorType = gDstColorType[i];
+
SkBitmap dstBM0, dstBM1;
- dstBM0.setConfig(gDstConfig[i], W, H);
- dstBM1.setConfig(gDstConfig[i], W, H);
- dstBM0.allocPixels();
- dstBM1.allocPixels();
+ dstBM0.allocPixels(info);
+ dstBM1.allocPixels(info);
SkCanvas canvas0(dstBM0);
SkCanvas canvas1(dstBM1);
@@ -249,9 +247,9 @@ static void test_diagonal(skiatest::Reporter* reporter) {
}
if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.getSize())) {
- ERRORF(reporter, "Diagonal config=%s bg=0x%x dither=%d"
+ ERRORF(reporter, "Diagonal colortype=%s bg=0x%x dither=%d"
" alpha=0x%x src=0x%x",
- gConfigName[gDstConfig[i]], bgColor, dither,
+ gConfigName[gDstColorType[i]], bgColor, dither,
alpha, c);
}
}
diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp
index 386581c74c..1e9f31479b 100644
--- a/tests/BlurTest.cpp
+++ b/tests/BlurTest.cpp
@@ -27,9 +27,8 @@ static const int outset = 100;
static const SkColor bgColor = SK_ColorWHITE;
static const int strokeWidth = 4;
-static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) {
- bm->setConfig(config, bound.width(), bound.height());
- bm->allocPixels();
+static void create(SkBitmap* bm, const SkIRect& bound) {
+ bm->allocN32Pixels(bound.width(), bound.height());
}
static void drawBG(SkCanvas* canvas) {
@@ -126,7 +125,7 @@ static void test_blur_drawing(skiatest::Reporter* reporter) {
refBound.roundOut(&iref);
iref.inset(-outset, -outset);
SkBitmap refBitmap;
- create(&refBitmap, iref, SkBitmap::kARGB_8888_Config);
+ create(&refBitmap, iref);
SkCanvas refCanvas(refBitmap);
refCanvas.translate(SkIntToScalar(-iref.fLeft),
@@ -137,7 +136,7 @@ static void test_blur_drawing(skiatest::Reporter* reporter) {
for (int view = 0; view < tests[test].viewLen; ++view) {
SkIRect itest = tests[test].views[view];
SkBitmap testBitmap;
- create(&testBitmap, itest, SkBitmap::kARGB_8888_Config);
+ create(&testBitmap, itest);
SkCanvas testCanvas(testBitmap);
testCanvas.translate(SkIntToScalar(-itest.fLeft),
@@ -244,8 +243,7 @@ static void blur_path(SkCanvas* canvas, const SkPath& path,
// Readback the blurred draw results from the canvas
static void readback(SkCanvas* canvas, int* result, int resultCount) {
SkBitmap readback;
- readback.setConfig(SkBitmap::kARGB_8888_Config, resultCount, 30);
- readback.allocPixels();
+ readback.allocN32Pixels(resultCount, 30);
SkIRect readBackRect = { 0, 0, resultCount, 30 };
@@ -265,8 +263,7 @@ static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma,
int* result, int resultCount) {
SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, resultCount, 30);
- bitmap.allocPixels();
+ bitmap.allocN32Pixels(resultCount, 30);
SkCanvas canvas(bitmap);
blur_path(&canvas, path, gaussianSigma);
diff --git a/tests/CanvasStateTest.cpp b/tests/CanvasStateTest.cpp
index f1c35929d6..7c441a40fe 100644
--- a/tests/CanvasStateTest.cpp
+++ b/tests/CanvasStateTest.cpp
@@ -24,10 +24,10 @@ static void test_complex_layers(skiatest::Reporter* reporter) {
SkIntToScalar(WIDTH-(2*SPACER)),
SkIntToScalar((HEIGHT-(2*SPACER)) / 7));
- const SkBitmap::Config configs[] = { SkBitmap::kRGB_565_Config,
- SkBitmap::kARGB_8888_Config
+ const SkColorType colorTypes[] = {
+ kRGB_565_SkColorType, kPMColor_SkColorType
};
- const int configCount = sizeof(configs) / sizeof(SkBitmap::Config);
+ const int configCount = sizeof(colorTypes) / sizeof(SkBitmap::Config);
const int layerAlpha[] = { 255, 255, 0 };
const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag,
@@ -40,8 +40,9 @@ static void test_complex_layers(skiatest::Reporter* reporter) {
for (int i = 0; i < configCount; ++i) {
SkBitmap bitmaps[2];
for (int j = 0; j < 2; ++j) {
- bitmaps[j].setConfig(configs[i], WIDTH, HEIGHT);
- bitmaps[j].allocPixels();
+ bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT,
+ colorTypes[i],
+ kPremul_SkAlphaType));
SkCanvas canvas(bitmaps[j]);
@@ -127,8 +128,7 @@ static void test_complex_clips(skiatest::Reporter* reporter) {
SkBitmap bitmaps[2];
for (int i = 0; i < 2; ++i) {
- bitmaps[i].setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT);
- bitmaps[i].allocPixels();
+ bitmaps[i].allocN32Pixels(WIDTH, HEIGHT);
SkCanvas canvas(bitmaps[i]);
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 55169cc344..b3b1a37dfc 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -84,7 +84,7 @@ static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) {
SkISize size = canvas->getDeviceSize();
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
+ bm.setConfig(SkImageInfo::MakeN32Premul(size.width(), size.height()));
SkCanvas c(bm);
Canvas2CanvasClipVisitor visitor(&c);
@@ -135,9 +135,8 @@ static const char* const kNWayIndirect2StateAssertMessageFormat =
static const char* const kPdfAssertMessageFormat =
"PDF sanity check failed %s";
-static void createBitmap(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
- bm->setConfig(config, kWidth, kHeight);
- bm->allocPixels();
+static void createBitmap(SkBitmap* bm, SkColor color) {
+ bm->allocN32Pixels(kWidth, kHeight);
bm->eraseColor(color);
}
@@ -220,7 +219,7 @@ const SkPoint kTestPoints[3] = {
const size_t kTestPointCount = 3;
static SkBitmap testBitmap() {
SkBitmap bitmap;
- createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708);
+ createBitmap(&bitmap, 0x05060708);
return bitmap;
}
SkBitmap kTestBitmap; // cannot be created during static init
@@ -798,7 +797,7 @@ static void TestProxyCanvasStateConsistency(
const SkCanvas& referenceCanvas) {
SkBitmap indirectStore;
- createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ createBitmap(&indirectStore, 0xFFFFFFFF);
SkBitmapDevice indirectDevice(indirectStore);
SkCanvas indirectCanvas(&indirectDevice);
SkProxyCanvas proxyCanvas(&indirectCanvas);
@@ -821,12 +820,12 @@ static void TestNWayCanvasStateConsistency(
const SkCanvas& referenceCanvas) {
SkBitmap indirectStore1;
- createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ createBitmap(&indirectStore1, 0xFFFFFFFF);
SkBitmapDevice indirectDevice1(indirectStore1);
SkCanvas indirectCanvas1(&indirectDevice1);
SkBitmap indirectStore2;
- createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ createBitmap(&indirectStore2, 0xFFFFFFFF);
SkBitmapDevice indirectDevice2(indirectStore2);
SkCanvas indirectCanvas2(&indirectDevice2);
@@ -859,7 +858,7 @@ static void TestNWayCanvasStateConsistency(
static void TestOverrideStateConsistency(skiatest::Reporter* reporter,
CanvasTestStep* testStep) {
SkBitmap referenceStore;
- createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ createBitmap(&referenceStore, 0xFFFFFFFF);
SkBitmapDevice referenceDevice(referenceStore);
SkCanvas referenceCanvas(&referenceDevice);
testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
diff --git a/tests/ClipCubicTest.cpp b/tests/ClipCubicTest.cpp
index db6ae80293..31b38f2726 100644
--- a/tests/ClipCubicTest.cpp
+++ b/tests/ClipCubicTest.cpp
@@ -16,8 +16,7 @@
// with a device/clip that is larger.
static void test_giantClip() {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 64919, 1);
- bm.allocPixels();
+ bm.allocN32Pixels(64919, 1);
SkCanvas canvas(bm);
canvas.clear(SK_ColorTRANSPARENT);
diff --git a/tests/ClipperTest.cpp b/tests/ClipperTest.cpp
index c8f65db197..00b62293b2 100644
--- a/tests/ClipperTest.cpp
+++ b/tests/ClipperTest.cpp
@@ -13,8 +13,7 @@
static void test_hairclipping(skiatest::Reporter* reporter) {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 4, 4);
- bm.allocPixels();
+ bm.allocN32Pixels(4, 4);
bm.eraseColor(SK_ColorWHITE);
SkPaint paint;
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index a40c667c93..4b67f199fc 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -24,9 +24,8 @@ class GrContextFactory;
static const int gWidth = 2;
static const int gHeight = 2;
-static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
- bm->setConfig(config, gWidth, gHeight);
- bm->allocPixels();
+static void create(SkBitmap* bm, SkColor color) {
+ bm->allocN32Pixels(gWidth, gHeight);
bm->eraseColor(color);
}
@@ -69,8 +68,7 @@ class MockSurface : public SkSurface_Base {
public:
MockSurface(int width, int height) : SkSurface_Base(width, height) {
clearCounts();
- fBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- fBitmap.allocPixels();
+ fBitmap.allocN32Pixels(width, height);
}
virtual SkCanvas* onNewCanvas() SK_OVERRIDE {
@@ -107,8 +105,7 @@ static void TestDeferredCanvasWritePixelsToSurface(skiatest::Reporter* reporter)
SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
SkBitmap srcBitmap;
- srcBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
- srcBitmap.allocPixels();
+ srcBitmap.allocN32Pixels(10, 10);
srcBitmap.eraseColor(SK_ColorGREEN);
// Tests below depend on this bitmap being recognized as opaque
@@ -351,7 +348,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
SkBitmap bmp;
- create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ create(&bmp, 0xFFFFFFFF);
bmp.setAlphaType(kOpaque_SkAlphaType);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
@@ -389,7 +386,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
SkBitmap bmp;
- create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
+ create(&bmp, 0xFFFFFFFF);
bmp.setAlphaType(kPremul_SkAlphaType);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
@@ -507,8 +504,7 @@ static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) {
SkBitmap sourceImage;
// 100 by 100 image, takes 40,000 bytes in memory
- sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- sourceImage.allocPixels();
+ sourceImage.allocN32Pixels(100, 100);
for (int i = 0; i < 5; i++) {
sourceImage.notifyPixelsChanged(); // to force re-serialization
@@ -527,10 +523,8 @@ static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
const int imageCount = 2;
SkBitmap sourceImages[imageCount];
- for (int i = 0; i < imageCount; i++)
- {
- sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- sourceImages[i].allocPixels();
+ for (int i = 0; i < imageCount; i++) {
+ sourceImages[i].allocN32Pixels(100, 100);
}
size_t bitmapSize = sourceImages[0].getSize();
@@ -629,8 +623,7 @@ static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) {
for(int i = 0; i < nbIterations; ++i) {
SkPaint paint;
SkBitmap paintPattern;
- paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
- paintPattern.allocPixels();
+ paintPattern.allocN32Pixels(10, 10);
paint.setShader(SkNEW_ARGS(SkBitmapProcShader,
(paintPattern, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode)))->unref();
canvas->drawPaint(paint);
@@ -658,8 +651,7 @@ static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
SkBitmap sourceImage;
// 100 by 100 image, takes 40,000 bytes in memory
- sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- sourceImage.allocPixels();
+ sourceImage.allocN32Pixels(100, 100);
// 1 under : should not store the image
{
diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp
index ab5841b1bd..5735043074 100644
--- a/tests/DeviceLooperTest.cpp
+++ b/tests/DeviceLooperTest.cpp
@@ -10,8 +10,8 @@
#include "Test.h"
static void make_bm(SkBitmap* bm, int w, int h) {
- bm->setConfig(SkBitmap::kA8_Config, w, h);
- bm->allocPixels();
+ bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType,
+ kPremul_SkAlphaType));
}
static bool equal(const SkRasterClip& a, const SkRasterClip& b) {
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index a1681461cb..f51bf53cc8 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -178,8 +178,7 @@ static void assert_ifDrawnTo(skiatest::Reporter* reporter,
static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
int width, int height, bool shouldBeDrawn) {
SkBitmap dev;
- dev.setConfig(SkBitmap::kARGB_8888_Config, 0x56F, 0x4f6);
- dev.allocPixels();
+ dev.allocN32Pixels(0x56F, 0x4f6);
dev.eraseColor(SK_ColorTRANSPARENT); // necessary, so we know if we draw to it
SkMatrix matrix;
@@ -195,8 +194,7 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
c.concat(matrix);
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- bm.allocPixels();
+ bm.allocN32Pixels(width, height);
bm.eraseColor(SK_ColorRED);
SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
@@ -260,8 +258,7 @@ static void test_giantrepeat_crbug118018(skiatest::Reporter* reporter) {
static void test_nan_antihair() {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 20, 20);
- bm.allocPixels();
+ bm.allocN32Pixels(20, 20);
SkCanvas canvas(bm);
@@ -298,17 +295,16 @@ static bool check_for_all_zeros(const SkBitmap& bm) {
static const int gWidth = 256;
static const int gHeight = 256;
-static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
- bm->setConfig(config, gWidth, gHeight);
- bm->allocPixels();
+static void create(SkBitmap* bm, SkColor color) {
+ bm->allocN32Pixels(gWidth, gHeight);
bm->eraseColor(color);
}
DEF_TEST(DrawBitmapRect, reporter) {
SkBitmap src, dst;
- create(&src, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- create(&dst, SkBitmap::kARGB_8888_Config, 0);
+ create(&src, 0xFFFFFFFF);
+ create(&dst, 0);
SkCanvas canvas(dst);
diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp
index 2cf1bc5c41..e7f70057b9 100644
--- a/tests/DrawPathTest.cpp
+++ b/tests/DrawPathTest.cpp
@@ -11,30 +11,20 @@
#include "SkSurface.h"
#include "Test.h"
-static SkCanvas* create(SkBitmap::Config config, int w, int h, int rb,
- void* addr = NULL) {
+static SkCanvas* new_canvas(int w, int h) {
SkBitmap bm;
- bm.setConfig(config, w, h, rb);
- if (addr) {
- bm.setPixels(addr);
- } else {
- bm.allocPixels();
- }
+ bm.allocN32Pixels(w, h);
return new SkCanvas(bm);
}
-static SkCanvas* new_canvas(int w, int h) {
- return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL);
-}
-
///////////////////////////////////////////////////////////////////////////////
// test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint)
static void test_big_aa_rect(skiatest::Reporter* reporter) {
SkBitmap output;
SkPMColor pixel[1];
- output.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 4);
- output.setPixels(pixel);
+ output.installPixels(SkImageInfo::MakeN32Premul(1, 1),
+ pixel, 4, NULL, NULL);
SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300);
SkCanvas* canvas = surf->getCanvas();
@@ -125,8 +115,7 @@ static void test_crbug131181() {
// stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow
static void test_crbug_140803() {
SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, 2700, 30*1024);
- bm.allocPixels();
+ bm.allocN32Pixels(2700, 30*1024);
SkCanvas canvas(bm);
SkPath path;
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index 5f25007d4b..50f55fd8f0 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -107,8 +107,7 @@ static SkPMColor convertConfig8888ToPMColor(SkCanvas::Config8888 config8888,
static void fillCanvas(SkCanvas* canvas) {
static SkBitmap bmp;
if (bmp.isNull()) {
- bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H);
- SkDEBUGCODE(bool alloc =) bmp.allocPixels();
+ SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H);
SkASSERT(alloc);
SkAutoLockPixels alp(bmp);
intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
@@ -230,9 +229,8 @@ static BitmapInit nextBMI(BitmapInit bmi) {
}
static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init) {
- int w = rect.width();
- int h = rect.height();
- int rowBytes = 0;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height());
+ size_t rowBytes = 0;
bool alloc = true;
switch (init) {
case kNoPixels_BitmapInit:
@@ -240,15 +238,17 @@ static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init)
case kTight_BitmapInit:
break;
case kRowBytes_BitmapInit:
- rowBytes = w * sizeof(SkPMColor) + 16 * sizeof(SkPMColor);
+ rowBytes = (info.width() + 16) * sizeof(SkPMColor);
break;
default:
SkASSERT(0);
break;
}
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes);
+
if (alloc) {
- bitmap->allocPixels();
+ bitmap->allocPixels(info);
+ } else {
+ bitmap->setConfig(info, rowBytes);
}
}
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 43d17e7cb5..e2e4a0c802 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -136,8 +136,7 @@ static uint32_t getBitmapColor(int x, int y, int w, SkCanvas::Config8888 config8
static void fillCanvas(SkCanvas* canvas) {
static SkBitmap bmp;
if (bmp.isNull()) {
- bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H);
- SkDEBUGCODE(bool alloc = ) bmp.allocPixels();
+ SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H);
SkASSERT(alloc);
SkAutoLockPixels alp(bmp);
intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
@@ -304,13 +303,28 @@ static const CanvasConfig gCanvasConfigs[] = {
#endif
};
+#include "SkMallocPixelRef.h"
+
+// This is a tricky pattern, because we have to setConfig+rowBytes AND specify
+// a custom pixelRef (which also has to specify its rowBytes), so we have to be
+// sure that the two rowBytes match (and the infos match).
+//
+static bool allocRowBytes(SkBitmap* bm, const SkImageInfo& info, size_t rowBytes) {
+ if (!bm->setConfig(info, rowBytes)) {
+ return false;
+ }
+ SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, rowBytes, NULL);
+ bm->setPixelRef(pr)->unref();
+ return true;
+}
+
static SkBaseDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) {
switch (c.fDevType) {
case kRaster_DevType: {
SkBitmap bmp;
size_t rowBytes = c.fTightRowBytes ? 0 : 4 * DEV_W + 100;
- bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H, rowBytes);
- if (!bmp.allocPixels()) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
+ if (!allocRowBytes(&bmp, info, rowBytes)) {
sk_throw();
return NULL;
}
@@ -344,8 +358,8 @@ static bool setupBitmap(SkBitmap* bitmap,
int w, int h,
bool tightRowBytes) {
size_t rowBytes = tightRowBytes ? 0 : 4 * w + 60;
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes);
- if (!bitmap->allocPixels()) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+ if (!allocRowBytes(bitmap, info, rowBytes)) {
return false;
}
SkAutoLockPixels alp(*bitmap);