aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-06-09 12:16:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-09 12:16:53 -0700
commit41e010cb901c0da9066c4df562030808c9ccd7f8 (patch)
tree3bf17e946f9eadd43040ea6968adcfa5f2f882a4 /tests
parent1831f990c31bad0d84641663c96aa8eebf846ab9 (diff)
Revert[2] SkDraw and all Blitters to use pixmap instead of bitmapi
Diffstat (limited to 'tests')
-rw-r--r--tests/DeviceLooperTest.cpp23
-rw-r--r--tests/SurfaceTest.cpp60
-rw-r--r--tests/TextureCompressionTest.cpp69
3 files changed, 91 insertions, 61 deletions
diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp
index 5735043074..1a51b58980 100644
--- a/tests/DeviceLooperTest.cpp
+++ b/tests/DeviceLooperTest.cpp
@@ -9,9 +9,8 @@
#include "SkRasterClip.h"
#include "Test.h"
-static void make_bm(SkBitmap* bm, int w, int h) {
- bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType,
- kPremul_SkAlphaType));
+static void make_pm(SkAutoPixmapStorage* pixmap, int w, int h) {
+ pixmap->alloc(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, kPremul_SkAlphaType));
}
static bool equal(const SkRasterClip& a, const SkRasterClip& b) {
@@ -40,19 +39,19 @@ static const struct {
static void test_simple(skiatest::Reporter* reporter) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
- SkBitmap bitmap;
- make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height());
+ SkAutoPixmapStorage pmap;
+ make_pm(&pmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height());
SkRasterClip rc(gRec[i].fRCBounds);
for (int aa = 0; aa <= 1; ++aa) {
- SkDeviceLooper looper(bitmap, rc, gRec[i].fRect, SkToBool(aa));
+ SkDeviceLooper looper(pmap, rc, gRec[i].fRect, SkToBool(aa));
bool valid = looper.next();
REPORTER_ASSERT(reporter, valid);
if (valid) {
- REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.width());
- REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.height());
+ REPORTER_ASSERT(reporter, looper.getPixmap().width() == pmap.width());
+ REPORTER_ASSERT(reporter, looper.getPixmap().height() == pmap.height());
REPORTER_ASSERT(reporter, equal(looper.getRC(), rc));
REPORTER_ASSERT(reporter, !looper.next());
@@ -62,7 +61,7 @@ static void test_simple(skiatest::Reporter* reporter) {
{
SkIRect r = rc.getBounds();
r.offset(r.width(), 0);
- SkDeviceLooper looper(bitmap, rc, r, false);
+ SkDeviceLooper looper(pmap, rc, r, false);
REPORTER_ASSERT(reporter, !looper.next());
}
}
@@ -109,8 +108,8 @@ static void test_complex(skiatest::Reporter* reporter) {
const int w = gRec[i].fSize.width();
const int h = gRec[i].fSize.height();
- SkBitmap bitmap;
- make_bm(&bitmap, w, h);
+ SkAutoPixmapStorage pmap;
+ make_pm(&pmap, w, h);
const SkIRect rect = SkIRect::MakeWH(w, h);
@@ -125,7 +124,7 @@ static void test_complex(skiatest::Reporter* reporter) {
SkRasterClip rc;
rc.op(rgn, SkRegion::kReplace_Op);
- SkDeviceLooper looper(bitmap, rc, rect, gRec[i].fAA);
+ SkDeviceLooper looper(pmap, rc, rect, gRec[i].fAA);
while (looper.next()) {
REPORTER_ASSERT(reporter, !looper.getRC().isEmpty());
}
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index a3ac216786..4803b68221 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -7,6 +7,7 @@
#include "SkCanvas.h"
#include "SkData.h"
+#include "SkDevice.h"
#include "SkImageEncoder.h"
#include "SkRRect.h"
#include "SkSurface.h"
@@ -350,6 +351,63 @@ static void test_canvaspeek(skiatest::Reporter* reporter,
}
}
+// For compatibility with clients that still call accessBitmap(), we need to ensure that we bump
+// the bitmap's genID when we draw to it, else they won't know it has new values. When they are
+// exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
+// test.
+static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ static const struct {
+ SurfaceType fType;
+ bool fPeekShouldSucceed;
+ } gRec[] = {
+ { kRaster_SurfaceType, true },
+ { kRasterDirect_SurfaceType, true },
+#if SK_SUPPORT_GPU
+ { kGpu_SurfaceType, false },
+ { kGpuScratch_SurfaceType, false },
+#endif
+ };
+
+ int cnt;
+#if SK_SUPPORT_GPU
+ cnt = GrContextFactory::kGLContextTypeCnt;
+#else
+ cnt = 1;
+#endif
+
+ for (int i= 0; i < cnt; ++i) {
+ GrContext* context = NULL;
+#if SK_SUPPORT_GPU
+ GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
+ if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
+ continue;
+ }
+ context = factory->get(glCtxType);
+
+ if (NULL == context) {
+ continue;
+ }
+#endif
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) {
+ SkImageInfo info, requestInfo;
+
+ SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context,
+ &requestInfo));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0);
+
+ SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_testing();
+ SkBitmap bm = device->accessBitmap(false);
+ uint32_t genID0 = bm.getGenerationID();
+ // Now we draw something, which needs to "dirty" the genID (sorta like copy-on-write)
+ canvas->drawColor(SK_ColorBLUE);
+ // Now check that we get a different genID
+ uint32_t genID1 = bm.getGenerationID();
+ REPORTER_ASSERT(reporter, genID0 != genID1);
+ }
+ }
+}
+
static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType,
GrContext* context) {
// Verify that the right canvas commands trigger a copy on write
@@ -587,6 +645,8 @@ DEF_GPUTEST(Surface, reporter, factory) {
test_imagepeek(reporter, factory);
test_canvaspeek(reporter, factory);
+ test_accessPixels(reporter, factory);
+
#if SK_SUPPORT_GPU
TestGetTexture(reporter, kRaster_SurfaceType, NULL);
if (factory) {
diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp
index 568d4d14b6..ca8da28858 100644
--- a/tests/TextureCompressionTest.cpp
+++ b/tests/TextureCompressionTest.cpp
@@ -42,10 +42,8 @@ static bool compresses_a8(SkTextureCompressor::Format fmt) {
* Make sure that we properly fail when we don't have multiple of four image dimensions.
*/
DEF_TEST(CompressAlphaFailDimensions, reporter) {
- SkBitmap bitmap;
static const int kWidth = 17;
static const int kHeight = 17;
- SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
// R11_EAC and LATC are both dimensions of 4, so we need to make sure that we
// are violating those assumptions. And if we are, then we're also violating the
@@ -55,18 +53,16 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) {
REPORTER_ASSERT(reporter, kWidth % 4 != 0);
REPORTER_ASSERT(reporter, kHeight % 4 != 0);
- bool setInfoSuccess = bitmap.setInfo(info);
- REPORTER_ASSERT(reporter, setInfoSuccess);
-
- bitmap.allocPixels(info);
- bitmap.unlockPixels();
+ SkAutoPixmapStorage pixmap;
+ pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
+ // leaving the pixels uninitialized, as they don't affect the test...
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i);
if (!compresses_a8(fmt)) {
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
+ SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, NULL == data);
}
}
@@ -76,10 +72,8 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) {
* compressed textures can (currently) only be created from A8 bitmaps.
*/
DEF_TEST(CompressAlphaFailColorType, reporter) {
- SkBitmap bitmap;
static const int kWidth = 12;
static const int kHeight = 12;
- SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
// ASTC is at most 12x12, and any dimension divisible by 12 is also divisible
// by 4, which is the dimensions of R11_EAC and LATC. In the future, we might
@@ -88,18 +82,16 @@ DEF_TEST(CompressAlphaFailColorType, reporter) {
REPORTER_ASSERT(reporter, kWidth % 12 == 0);
REPORTER_ASSERT(reporter, kHeight % 12 == 0);
- bool setInfoSuccess = bitmap.setInfo(info);
- REPORTER_ASSERT(reporter, setInfoSuccess);
-
- bitmap.allocPixels(info);
- bitmap.unlockPixels();
+ SkAutoPixmapStorage pixmap;
+ pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight));
+ // leaving the pixels uninitialized, as they don't affect the test...
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i);
if (!compresses_a8(fmt)) {
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
+ SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, NULL == data);
}
}
@@ -109,10 +101,8 @@ DEF_TEST(CompressAlphaFailColorType, reporter) {
* then decompress it, you get what you started with.
*/
DEF_TEST(CompressCheckerboard, reporter) {
- SkBitmap bitmap;
static const int kWidth = 48; // We need the number to be divisible by both
static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC).
- SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
// ASTC is at most 12x12, and any dimension divisible by 12 is also divisible
// by 4, which is the dimensions of R11_EAC and LATC. In the future, we might
@@ -123,17 +113,12 @@ DEF_TEST(CompressCheckerboard, reporter) {
REPORTER_ASSERT(reporter, kWidth % 48 == 0);
REPORTER_ASSERT(reporter, kHeight % 48 == 0);
- bool setInfoSuccess = bitmap.setInfo(info);
- REPORTER_ASSERT(reporter, setInfoSuccess);
-
- bitmap.allocPixels(info);
- bitmap.unlockPixels();
+ SkAutoPixmapStorage pixmap;
+ pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
- // Populate bitmap
+ // Populate the pixels
{
- SkAutoLockPixels alp(bitmap);
-
- uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
+ uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr());
REPORTER_ASSERT(reporter, pixels);
if (NULL == pixels) {
return;
@@ -147,7 +132,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
pixels[x] = 0;
}
}
- pixels += bitmap.rowBytes();
+ pixels += pixmap.rowBytes();
}
}
@@ -167,7 +152,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
continue;
}
- SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
+ SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt));
REPORTER_ASSERT(reporter, data);
if (NULL == data) {
continue;
@@ -180,8 +165,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
kWidth, kHeight, fmt);
REPORTER_ASSERT(reporter, decompResult);
- SkAutoLockPixels alp(bitmap);
- uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
+ const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr());
REPORTER_ASSERT(reporter, pixels);
if (NULL == pixels) {
continue;
@@ -189,7 +173,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
for (int y = 0; y < kHeight; ++y) {
for (int x = 0; x < kWidth; ++x) {
- bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWidth + x];
+ bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWidth + x];
REPORTER_ASSERT(reporter, ok);
}
}
@@ -204,16 +188,11 @@ DEF_TEST(CompressLATC, reporter) {
const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format;
static const int kLATCEncodedBlockSize = 8;
- SkBitmap bitmap;
static const int kWidth = 8;
static const int kHeight = 8;
- SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
-
- bool setInfoSuccess = bitmap.setInfo(info);
- REPORTER_ASSERT(reporter, setInfoSuccess);
- bitmap.allocPixels(info);
- bitmap.unlockPixels();
+ SkAutoPixmapStorage pixmap;
+ pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight));
int latcDimX, latcDimY;
SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY);
@@ -226,21 +205,13 @@ DEF_TEST(CompressLATC, reporter) {
REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0);
for (int lum = 0; lum < 256; ++lum) {
- bitmap.lockPixels();
- uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
- REPORTER_ASSERT(reporter, pixels);
- if (NULL == pixels) {
- bitmap.unlockPixels();
- continue;
- }
-
+ uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr());
for (int i = 0; i < kWidth*kHeight; ++i) {
pixels[i] = lum;
}
- bitmap.unlockPixels();
SkAutoDataUnref latcData(
- SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
+ SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat));
REPORTER_ASSERT(reporter, latcData);
if (NULL == latcData) {
continue;