aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-16 09:47:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-16 09:47:08 -0700
commit250581493a0859987e482810879e85e5ac2dc002 (patch)
tree2a9432c347327c16d35a15f6a6b8b53b7704aef3 /tests
parentb3b6beae044ca457edf99cf223cd6379a49d4ef0 (diff)
Add SkSpecialImage::extractSubset & NewFromPixmap
This is calved off of: https://codereview.chromium.org/1785643003/ (Switch SkBlurImageFilter over to new onFilterImage interface) GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1787883002 Review URL: https://codereview.chromium.org/1787883002
Diffstat (limited to 'tests')
-rw-r--r--tests/DeviceLooperTest.cpp1
-rw-r--r--tests/Float16Test.cpp1
-rw-r--r--tests/ImageTest.cpp1
-rw-r--r--tests/SpecialImageTest.cpp99
-rw-r--r--tests/TestingSpecialImageAccess.h2
-rw-r--r--tests/TextureCompressionTest.cpp1
6 files changed, 91 insertions, 14 deletions
diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp
index 1a51b58980..c8eb3c7b75 100644
--- a/tests/DeviceLooperTest.cpp
+++ b/tests/DeviceLooperTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkAutoPixmapStorage.h"
#include "SkDeviceLooper.h"
#include "SkRasterClip.h"
#include "Test.h"
diff --git a/tests/Float16Test.cpp b/tests/Float16Test.cpp
index ef349c6cb6..6a7f9842f4 100644
--- a/tests/Float16Test.cpp
+++ b/tests/Float16Test.cpp
@@ -6,6 +6,7 @@
*/
#include "Test.h"
+#include "SkAutoPixmapStorage.h"
#include "SkColor.h"
#include "SkHalf.h"
#include "SkOpts.h"
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 3c2c31cca9..da9268dded 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -9,6 +9,7 @@
#include <initializer_list>
#include "DMGpuSupport.h"
+#include "SkAutoPixmapStorage.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkData.h"
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index 9bde7eec33..7511e62971 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -5,9 +5,11 @@
* found in the LICENSE file
*/
+#include "SkAutoPixmapStorage.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkImage.h"
+#include "SkPixmap.h"
#include "SkSpecialImage.h"
#include "SkSpecialSurface.h"
#include "Test.h"
@@ -48,10 +50,11 @@ static SkBitmap create_bm() {
// Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw)
static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
- bool peekPixelsSucceeds, bool peekTextureSucceeds) {
+ bool peekPixelsSucceeds, bool peekTextureSucceeds,
+ int offset, int size) {
const SkIRect subset = TestingSpecialImageAccess::Subset(img);
- REPORTER_ASSERT(reporter, kPad == subset.left());
- REPORTER_ASSERT(reporter, kPad == subset.top());
+ REPORTER_ASSERT(reporter, offset == subset.left());
+ REPORTER_ASSERT(reporter, offset == subset.top());
REPORTER_ASSERT(reporter, kSmallerSize == subset.width());
REPORTER_ASSERT(reporter, kSmallerSize == subset.height());
@@ -63,8 +66,8 @@ static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, peekPixelsSucceeds ==
!!TestingSpecialImageAccess::PeekPixels(img, &pixmap));
if (peekPixelsSucceeds) {
- REPORTER_ASSERT(reporter, kFullSize == pixmap.width());
- REPORTER_ASSERT(reporter, kFullSize == pixmap.height());
+ REPORTER_ASSERT(reporter, size == pixmap.width());
+ REPORTER_ASSERT(reporter, size == pixmap.height());
}
//--------------
@@ -95,10 +98,22 @@ static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
DEF_TEST(SpecialImage_Raster, reporter) {
SkBitmap bm = create_bm();
+ SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromRaster(
+ nullptr,
+ SkIRect::MakeWH(kFullSize, kFullSize),
+ bm));
+
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
- SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromRaster(nullptr, subset, bm));
- test_image(img, reporter, true, false);
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromRaster(nullptr, subset, bm));
+ test_image(subSImg1, reporter, true, false, kPad, kFullSize);
+ }
+
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset));
+ test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
+ }
}
DEF_TEST(SpecialImage_Image, reporter) {
@@ -106,12 +121,56 @@ DEF_TEST(SpecialImage_Image, reporter) {
SkAutoTUnref<SkImage> fullImage(SkImage::NewFromBitmap(bm));
+ SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromImage(
+ nullptr,
+ SkIRect::MakeWH(kFullSize, kFullSize),
+ fullImage));
+
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
- SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromImage(nullptr, subset, fullImage));
- test_image(img, reporter, true, false);
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromImage(nullptr,
+ subset,
+ fullImage));
+ test_image(subSImg1, reporter, true, false, kPad, kFullSize);
+ }
+
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset));
+ test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
+ }
}
+DEF_TEST(SpecialImage_Pixmap, reporter) {
+ SkAutoPixmapStorage pixmap;
+
+ const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlphaType);
+ pixmap.alloc(info);
+ pixmap.erase(SK_ColorGREEN);
+
+ const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
+
+ pixmap.erase(SK_ColorRED, subset);
+
+ {
+ // The SkAutoPixmapStorage keeps hold of the memory
+ SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(nullptr, subset, pixmap,
+ nullptr, nullptr));
+ test_image(img, reporter, true, false, kPad, kFullSize);
+ }
+
+ {
+ // The image takes ownership of the memory
+ SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(
+ nullptr, subset, pixmap,
+ [] (void* addr, void*) -> void { sk_free(addr); },
+ nullptr));
+ pixmap.release();
+ test_image(img, reporter, true, false, kPad, kFullSize);
+ }
+}
+
+
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
SkBitmap bm = create_bm();
@@ -128,12 +187,26 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
return;
}
+ SkAutoTUnref<SkSpecialImage> fullSImg(SkSpecialImage::NewFromGpu(
+ nullptr,
+ SkIRect::MakeWH(kFullSize, kFullSize),
+ kNeedNewImageUniqueID_SpecialImage,
+ texture));
+
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
- SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromGpu(nullptr, subset,
- kNeedNewImageUniqueID_SpecialImage,
- texture));
- test_image(img, reporter, false, true);
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromGpu(
+ nullptr, subset,
+ kNeedNewImageUniqueID_SpecialImage,
+ texture));
+ test_image(subSImg1, reporter, false, true, kPad, kFullSize);
+ }
+
+ {
+ SkAutoTUnref<SkSpecialImage> subSImg2(fullSImg->extractSubset(subset));
+ test_image(subSImg2, reporter, false, true, kPad, kFullSize);
+ }
}
#endif
diff --git a/tests/TestingSpecialImageAccess.h b/tests/TestingSpecialImageAccess.h
index cd9d77c7ff..8dd4e9bb50 100644
--- a/tests/TestingSpecialImageAccess.h
+++ b/tests/TestingSpecialImageAccess.h
@@ -15,7 +15,7 @@ public:
}
static bool PeekPixels(const SkSpecialImage* img, SkPixmap* pixmap) {
- return img->testingOnlyPeekPixels(pixmap);
+ return img->peekPixels(pixmap);
}
static GrTexture* PeekTexture(const SkSpecialImage* img) {
diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp
index 18afebeff2..09086605a5 100644
--- a/tests/TextureCompressionTest.cpp
+++ b/tests/TextureCompressionTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkAutoPixmapStorage.h"
#include "SkBitmap.h"
#include "SkData.h"
#include "SkEndian.h"