aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SpecialImageTest.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-21 13:44:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-21 13:44:18 -0700
commitb4bd11e66519f545282f914c67b54bf17cecab84 (patch)
tree4e8c5c77cfcc77192edc4122cd19334464bb6a2a /tests/SpecialImageTest.cpp
parent60316a9ec4b3d76ff3b63952f463f8ddee8841f8 (diff)
Update SkSpecialImage to be able to create tight SkImages and SkSurfaces
This calved off of: https://codereview.chromium.org/1810693003/ (Switch SkTileImageFilter over to new onFilterImage interface) since the TileImageFilter needs a tight bitmap/texture/image to perform its draw. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1816223002 Review URL: https://codereview.chromium.org/1816223002
Diffstat (limited to 'tests/SpecialImageTest.cpp')
-rw-r--r--tests/SpecialImageTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index 3240fbd3a7..432adc8327 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -12,6 +12,7 @@
#include "SkPixmap.h"
#include "SkSpecialImage.h"
#include "SkSpecialSurface.h"
+#include "SkSurface.h"
#include "Test.h"
#include "TestingSpecialImageAccess.h"
@@ -59,10 +60,12 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
REPORTER_ASSERT(reporter, kSmallerSize == subset.height());
//--------------
+ // Test that peekTexture reports the correct backing type
REPORTER_ASSERT(reporter, peekTextureSucceeds ==
!!TestingSpecialImageAccess::PeekTexture(img.get()));
//--------------
+ // Test that peekPixels reports the correct backing type
SkPixmap pixmap;
REPORTER_ASSERT(reporter, peekPixelsSucceeds ==
!!TestingSpecialImageAccess::PeekPixels(img.get(), &pixmap));
@@ -72,6 +75,7 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
}
//--------------
+ // Test that draw restricts itself to the subset
SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlphaType);
sk_sp<SkSpecialSurface> surf(img->makeSurface(info));
@@ -94,6 +98,32 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
kSmallerSize+kPad-1));
REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad,
kSmallerSize+kPad));
+
+ //--------------
+ // Test that makeTightSubset & makeTightSurface return appropriately sized objects
+ // of the correct backing type
+ SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height());
+ {
+ sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset));
+
+ REPORTER_ASSERT(reporter, tightImg->width() == subset.width());
+ REPORTER_ASSERT(reporter, tightImg->height() == subset.height());
+ REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture());
+ SkPixmap tmpPixmap;
+ REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightImg->peekPixels(&tmpPixmap));
+ }
+ {
+ SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(),
+ kPremul_SkAlphaType);
+ sk_sp<SkSurface> tightSurf(img->makeTightSurface(info));
+
+ REPORTER_ASSERT(reporter, tightSurf->width() == subset.width());
+ REPORTER_ASSERT(reporter, tightSurf->height() == subset.height());
+ REPORTER_ASSERT(reporter, peekTextureSucceeds ==
+ !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_BackendHandleAccess));
+ SkPixmap tmpPixmap;
+ REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightSurf->peekPixels(&tmpPixmap));
+ }
}
DEF_TEST(SpecialImage_Raster, reporter) {