aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-02-09 08:50:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-09 14:19:51 +0000
commit67f8584b6f899876ca4187dba4f449ce5489f9c8 (patch)
treeef23d8ccb9430be5ed954ff4cc0eb345baeafc98 /tests
parentc4616804bb407506c6ac1046c7e25e2016911449 (diff)
Revert "Revert "Remove SkImage deferred texture image data APIs.""
This reverts commit aae533e418f37d788cdb1a1177e882d0f8868b62. Change-Id: I0434892d8946490a75e17620c49c594eaa18158e Reviewed-on: https://skia-review.googlesource.com/100603 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageTest.cpp173
1 files changed, 0 insertions, 173 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 700584e5af..873f0eea95 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -1017,179 +1017,6 @@ DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) {
});
}
-static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, const SkImage* b) {
- if (a->width() != b->width() || a->height() != b->height()) {
- ERRORF(reporter, "Images must have the same size");
- return;
- }
- if (a->alphaType() != b->alphaType()) {
- ERRORF(reporter, "Images must have the same alpha type");
- return;
- }
-
- SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height());
- SkAutoPixmapStorage apm;
- SkAutoPixmapStorage bpm;
-
- apm.alloc(info);
- bpm.alloc(info);
-
- if (!a->readPixels(apm, 0, 0)) {
- ERRORF(reporter, "Could not read image a's pixels");
- return;
- }
- if (!b->readPixels(bpm, 0, 0)) {
- ERRORF(reporter, "Could not read image b's pixels");
- return;
- }
-
- for (auto y = 0; y < info.height(); ++y) {
- for (auto x = 0; x < info.width(); ++x) {
- uint32_t pixelA = *apm.addr32(x, y);
- uint32_t pixelB = *bpm.addr32(x, y);
- if (pixelA != pixelB) {
- ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x",
- x, y, pixelA, pixelB);
- return;
- }
- }
- }
-}
-
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) {
- GrContext* context = ctxInfo.grContext();
- sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
- sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
-
- GrContextFactory otherFactory;
- ContextInfo otherContextInfo = otherFactory.getContextInfo(ctxInfo.type());
-
- testContext->makeCurrent();
- REPORTER_ASSERT(reporter, proxy);
- auto createLarge = [context] {
- return create_image_large(context->caps()->maxTextureSize());
- };
- struct {
- std::function<sk_sp<SkImage> ()> fImageFactory;
- std::vector<SkImage::DeferredTextureImageUsageParams> fParams;
- sk_sp<SkColorSpace> fColorSpace;
- SkColorType fColorType;
- SkFilterQuality fExpectedQuality;
- int fExpectedScaleFactor;
- bool fExpectation;
- } testCases[] = {
- { create_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, true },
- { create_codec_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, true },
- { create_data_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, true },
- { create_picture_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, false },
- { [context] { return create_gpu_image(context); },
- {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, false },
- // Create a texture image in a another GrContext.
- { [testContext, otherContextInfo] {
- otherContextInfo.testContext()->makeCurrent();
- sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext());
- testContext->makeCurrent();
- return otherContextImage;
- }, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, false },
- // Create an image that is too large to upload.
- { createLarge, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kN32_SkColorType, kNone_SkFilterQuality, 1, false },
- // Create an image that is too large, but is scaled to an acceptable size.
- { createLarge, {{SkMatrix::I(), kMedium_SkFilterQuality, 4}},
- nullptr, kN32_SkColorType, kMedium_SkFilterQuality, 16, true},
- // Create an image with multiple low filter qualities, make sure we round up.
- { createLarge, {{SkMatrix::I(), kNone_SkFilterQuality, 4},
- {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
- nullptr, kN32_SkColorType, kMedium_SkFilterQuality, 16, true},
- // Create an image with multiple prescale levels, make sure we chose the minimum scale.
- { createLarge, {{SkMatrix::I(), kMedium_SkFilterQuality, 5},
- {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
- nullptr, kN32_SkColorType, kMedium_SkFilterQuality, 16, true},
- // Create a images which are decoded to a 4444 backing.
- { create_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kARGB_4444_SkColorType, kNone_SkFilterQuality, 1, true },
- { create_codec_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kARGB_4444_SkColorType, kNone_SkFilterQuality, 1, true },
- { create_data_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- nullptr, kARGB_4444_SkColorType, kNone_SkFilterQuality, 1, true },
- // Valid SkColorSpace and SkColorType.
- { create_data_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- SkColorSpace::MakeSRGB(), kN32_SkColorType, kNone_SkFilterQuality, 1, true },
- // Invalid SkColorSpace and SkColorType.
- { create_data_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
- SkColorSpace::MakeSRGB(), kARGB_4444_SkColorType, kNone_SkFilterQuality, 1, false },
- };
-
-
- for (auto testCase : testCases) {
- sk_sp<SkImage> image(testCase.fImageFactory());
- if (!image) {
- ERRORF(reporter, "Failed to create image!");
- continue;
- }
-
- size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParams.data(),
- static_cast<int>(testCase.fParams.size()),
- nullptr, testCase.fColorSpace.get(),
- testCase.fColorType);
- static const char *const kFS[] = { "fail", "succeed" };
- if (SkToBool(size) != testCase.fExpectation) {
- ERRORF(reporter, "This image was expected to %s but did not.",
- kFS[testCase.fExpectation]);
- }
- if (size) {
- void* buffer = sk_malloc_throw(size);
- void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(buffer) + 3);
- if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data(),
- static_cast<int>(testCase.fParams.size()),
- misaligned, testCase.fColorSpace.get(),
- testCase.fColorType)) {
- ERRORF(reporter, "Should fail when buffer is misaligned.");
- }
- if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.data(),
- static_cast<int>(testCase.fParams.size()),
- buffer, testCase.fColorSpace.get(),
- testCase.fColorType)) {
- ERRORF(reporter, "deferred image size succeeded but creation failed.");
- } else {
- for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
- sk_sp<SkImage> newImage(
- SkImage::MakeFromDeferredTextureImageData(context, buffer, budgeted));
- REPORTER_ASSERT(reporter, newImage != nullptr);
- if (newImage) {
- // Scale the image in software for comparison.
- SkImageInfo scaled_info = SkImageInfo::MakeN32(
- image->width() / testCase.fExpectedScaleFactor,
- image->height() / testCase.fExpectedScaleFactor,
- image->alphaType());
- SkAutoPixmapStorage scaled;
- scaled.alloc(scaled_info);
- image->scalePixels(scaled, testCase.fExpectedQuality);
- sk_sp<SkImage> scaledImage = SkImage::MakeRasterCopy(scaled);
- check_images_same(reporter, scaledImage.get(), newImage.get());
- }
- // The other context should not be able to create images from texture data
- // created by the original context.
- sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureImageData(
- otherContextInfo.grContext(), buffer, budgeted));
- REPORTER_ASSERT(reporter, !newImage2);
- testContext->makeCurrent();
- }
- }
- sk_free(buffer);
- }
-
- testContext->makeCurrent();
- context->flush();
- }
-}
-
static uint32_t GetIdForBackendObject(GrContext* ctx, GrBackendObject object) {
if (!object) {
return 0;