Index: tests/SpecialImageTest.cpp |
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp |
index 1c71f7563a9be3b2c59229fc74c8cd3aa2764262..2818ce9ec7388ac1f6e94186966f8bc29708b5a9 100644 |
--- a/tests/SpecialImageTest.cpp |
+++ b/tests/SpecialImageTest.cpp |
@@ -51,7 +51,7 @@ static SkBitmap create_bm() { |
// Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw) |
static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* reporter, |
- bool peekPixelsSucceeds, bool peekTextureSucceeds, |
+ GrContext* context, bool peekTextureSucceeds, |
int offset, int size) { |
const SkIRect subset = TestingSpecialImageAccess::Subset(img.get()); |
REPORTER_ASSERT(reporter, offset == subset.left()); |
@@ -61,17 +61,27 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep |
//-------------- |
// Test that peekTexture reports the correct backing type |
- REPORTER_ASSERT(reporter, peekTextureSucceeds == |
- !!TestingSpecialImageAccess::PeekTexture(img.get())); |
+ REPORTER_ASSERT(reporter, peekTextureSucceeds == img->isTextureBacked()); |
+ |
+#if SK_SUPPORT_GPU |
+ //-------------- |
+ // Test getTextureAsRef - as long as there is a context this should succeed |
+ if (context) { |
+ sk_sp<GrTexture> texture(img->asTextureRef(context)); |
+ REPORTER_ASSERT(reporter, texture); |
+ } |
+#endif |
//-------------- |
- // Test that peekPixels reports the correct backing type |
- SkPixmap pixmap; |
- REPORTER_ASSERT(reporter, peekPixelsSucceeds == |
- !!TestingSpecialImageAccess::PeekPixels(img.get(), &pixmap)); |
- if (peekPixelsSucceeds) { |
- REPORTER_ASSERT(reporter, size == pixmap.width()); |
- REPORTER_ASSERT(reporter, size == pixmap.height()); |
+ // Test getROPixels - this should always succeed regardless of backing store |
+ SkBitmap bitmap; |
+ REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); |
+ if (context) { |
+ REPORTER_ASSERT(reporter, kSmallerSize == bitmap.width()); |
+ REPORTER_ASSERT(reporter, kSmallerSize == bitmap.height()); |
+ } else { |
+ REPORTER_ASSERT(reporter, size == bitmap.width()); |
+ REPORTER_ASSERT(reporter, size == bitmap.height()); |
} |
//-------------- |
@@ -110,7 +120,7 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep |
REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); |
REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture()); |
SkPixmap tmpPixmap; |
- REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightImg->peekPixels(&tmpPixmap)); |
+ REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(&tmpPixmap)); |
} |
{ |
SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), |
@@ -122,7 +132,7 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep |
REPORTER_ASSERT(reporter, peekTextureSucceeds == |
!!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_BackendHandleAccess)); |
SkPixmap tmpPixmap; |
- REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightSurf->peekPixels(&tmpPixmap)); |
+ REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightSurf->peekPixels(&tmpPixmap)); |
} |
} |
@@ -138,12 +148,12 @@ DEF_TEST(SpecialImage_Raster, reporter) { |
{ |
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, subset, bm)); |
- test_image(subSImg1, reporter, true, false, kPad, kFullSize); |
+ test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
} |
{ |
sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
- test_image(subSImg2, reporter, true, false, 0, kSmallerSize); |
+ test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
} |
} |
@@ -162,12 +172,12 @@ DEF_TEST(SpecialImage_Image, reporter) { |
{ |
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, subset, |
fullImage)); |
- test_image(subSImg1, reporter, true, false, kPad, kFullSize); |
+ test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
} |
{ |
sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
- test_image(subSImg2, reporter, true, false, 0, kSmallerSize); |
+ test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
} |
} |
@@ -185,7 +195,7 @@ DEF_TEST(SpecialImage_Pixmap, reporter) { |
{ |
sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset, pixmap, |
nullptr, nullptr)); |
- test_image(img, reporter, true, false, kPad, kFullSize); |
+ test_image(img, reporter, nullptr, false, kPad, kFullSize); |
} |
} |
@@ -196,7 +206,7 @@ static void test_texture_backed(skiatest::Reporter* reporter, |
const sk_sp<SkSpecialImage>& orig, |
const sk_sp<SkSpecialImage>& gpuBacked) { |
REPORTER_ASSERT(reporter, gpuBacked); |
- REPORTER_ASSERT(reporter, gpuBacked->peekTexture()); |
+ REPORTER_ASSERT(reporter, gpuBacked->isTextureBacked()); |
REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().width() && |
gpuBacked->subset().height() == orig->subset().height()); |
@@ -297,12 +307,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { |
nullptr, subset, |
kNeedNewImageUniqueID_SpecialImage, |
texture)); |
- test_image(subSImg1, reporter, false, true, kPad, kFullSize); |
+ test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
} |
{ |
sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
- test_image(subSImg2, reporter, false, true, kPad, kFullSize); |
+ test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
} |
} |