aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-04-08 12:10:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-08 12:10:42 -0700
commit646125114b42b24e5ada3c9f8fac53a85f9ad2a0 (patch)
treec5d599427e99f89313131114b977f33232c3df48 /tests
parent89c2a0b8c12879f94f746a5d9fe723a48434647f (diff)
Upgrade SkSpecialImage to have getTextureRef & getROPixels entry points
This more closely aligns the SkSpecialImage API with the SkImage API. In doing so it allows the image filters to handle SkImages that can sneak through while remaining encoded (e.g., if an input filter just returns a wrapped version of the source SkImage) GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1861643003 Review URL: https://codereview.chromium.org/1861643003
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageFilterTest.cpp14
-rw-r--r--tests/SpecialImageTest.cpp50
-rw-r--r--tests/TestingSpecialImageAccess.h12
3 files changed, 37 insertions, 39 deletions
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index f1df84e20b..b37f9589f7 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -580,10 +580,10 @@ static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy,
SkBitmap positiveResultBM1, positiveResultBM2;
SkBitmap negativeResultBM1, negativeResultBM2;
- TestingSpecialImageAccess::GetROPixels(positiveResult1.get(), &positiveResultBM1);
- TestingSpecialImageAccess::GetROPixels(positiveResult2.get(), &positiveResultBM2);
- TestingSpecialImageAccess::GetROPixels(negativeResult1.get(), &negativeResultBM1);
- TestingSpecialImageAccess::GetROPixels(negativeResult2.get(), &negativeResultBM2);
+ REPORTER_ASSERT(reporter, positiveResult1->getROPixels(&positiveResultBM1));
+ REPORTER_ASSERT(reporter, positiveResult2->getROPixels(&positiveResultBM2));
+ REPORTER_ASSERT(reporter, negativeResult1->getROPixels(&negativeResultBM1));
+ REPORTER_ASSERT(reporter, negativeResult2->getROPixels(&negativeResultBM2));
SkAutoLockPixels lockP1(positiveResultBM1);
SkAutoLockPixels lockP2(positiveResultBM2);
@@ -683,7 +683,7 @@ static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy,
SkBitmap resultBM;
- TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM);
+ REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
SkAutoLockPixels lock(resultBM);
for (int y = 0; y < resultBM.height(); y++) {
@@ -725,7 +725,7 @@ static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy,
REPORTER_ASSERT(reporter, nullptr != result.get());
if (result.get()) {
SkBitmap resultBM;
- TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM);
+ REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
SkAutoLockPixels lock(resultBM);
REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN);
}
@@ -1504,7 +1504,7 @@ static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy,
REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100));
SkBitmap resultBM;
- TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM);
+ REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
SkAutoLockPixels lock(resultBM);
REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN);
}
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index 1c71f7563a..2818ce9ec7 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);
}
}
diff --git a/tests/TestingSpecialImageAccess.h b/tests/TestingSpecialImageAccess.h
index 8dd4e9bb50..64a6d29665 100644
--- a/tests/TestingSpecialImageAccess.h
+++ b/tests/TestingSpecialImageAccess.h
@@ -13,18 +13,6 @@ public:
static const SkIRect& Subset(const SkSpecialImage* img) {
return img->subset();
}
-
- static bool PeekPixels(const SkSpecialImage* img, SkPixmap* pixmap) {
- return img->peekPixels(pixmap);
- }
-
- static GrTexture* PeekTexture(const SkSpecialImage* img) {
- return img->peekTexture();
- }
-
- static bool GetROPixels(const SkSpecialImage* img, SkBitmap* result) {
- return img->testingOnlyGetROPixels(result);
- }
};
#endif