From 85d34b2e841d99dab914111fe2eaa4db99345e1e Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 10 May 2017 12:06:26 -0400 Subject: Remove SkCrossContextImageData and all support code Bug: skia: Change-Id: I8eb8cef5456c05a8e314d8404698893c7af82d13 Reviewed-on: https://skia-review.googlesource.com/16368 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- tests/CrossContextImageTest.cpp | 240 ---------------------------------------- tests/ResourceCacheTest.cpp | 27 +---- 2 files changed, 3 insertions(+), 264 deletions(-) delete mode 100644 tests/CrossContextImageTest.cpp (limited to 'tests') diff --git a/tests/CrossContextImageTest.cpp b/tests/CrossContextImageTest.cpp deleted file mode 100644 index 5c8b21e9b6..0000000000 --- a/tests/CrossContextImageTest.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkTypes.h" - -#if SK_SUPPORT_GPU - -#include "GrContextFactory.h" -#include "Resources.h" -#include "SkAutoPixmapStorage.h" -#include "SkBitmap.h" -#include "SkCanvas.h" -#include "SkCrossContextImageData.h" -#include "SkSemaphore.h" -#include "SkSurface.h" -#include "SkThreadUtils.h" -#include "Test.h" - -using namespace sk_gpu_test; - -static SkImageInfo read_pixels_info(SkImage* image) { - return SkImageInfo::MakeN32(image->width(), image->height(), image->alphaType()); -} - -static bool colors_are_close(SkColor a, SkColor b, int error) { - return SkTAbs((int)SkColorGetR(a) - (int)SkColorGetR(b)) <= error && - SkTAbs((int)SkColorGetG(a) - (int)SkColorGetG(b)) <= error && - SkTAbs((int)SkColorGetB(a) - (int)SkColorGetB(b)) <= error; -} - -static void assert_equal(skiatest::Reporter* reporter, SkImage* a, SkImage* b, int error) { - REPORTER_ASSERT(reporter, a->width() == b->width()); - REPORTER_ASSERT(reporter, a->height() == b->height()); - - SkAutoPixmapStorage pmapA, pmapB; - pmapA.alloc(read_pixels_info(a)); - pmapB.alloc(read_pixels_info(b)); - - REPORTER_ASSERT(reporter, a->readPixels(pmapA, 0, 0)); - REPORTER_ASSERT(reporter, b->readPixels(pmapB, 0, 0)); - - for (int y = 0; y < a->height(); ++y) { - for (int x = 0; x < a->width(); ++x) { - SkColor ca = pmapA.getColor(x, y); - SkColor cb = pmapB.getColor(x, y); - if (!error) { - if (ca != cb) { - ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d)", ca, cb, x, y); - return; - } - } else { - if (!colors_are_close(ca, cb, error)) { - ERRORF(reporter, "Expected 0x%08x +-%d but got 0x%08x at (%d, %d)", - ca, error, cb, x, y); - return; - } - } - } - } -} - -static void draw_image_test_pattern(SkCanvas* canvas) { - canvas->clear(SK_ColorWHITE); - SkPaint paint; - paint.setColor(SK_ColorBLACK); - canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); -} - -static sk_sp create_test_image() { - SkBitmap bm; - bm.allocN32Pixels(20, 20, true); - SkCanvas canvas(bm); - draw_image_test_pattern(&canvas); - - return SkImage::MakeFromBitmap(bm); -} - -static sk_sp create_test_data(SkEncodedImageFormat format) { - auto image = create_test_image(); - return sk_sp(image->encode(format, 100)); -} - -DEF_GPUTEST(CrossContextImage_SameContext, reporter, /*factory*/) { - GrContextFactory factory; - sk_sp testImage = create_test_image(); - - // Test both PNG and JPG, to exercise GPU YUV conversion - for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) { - sk_sp encoded = create_test_data(format); - - for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { - GrContextFactory::ContextType ctxType = static_cast(i); - if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) { - continue; - } - - ContextInfo info = factory.getContextInfo(ctxType); - if (!info.grContext()) { - continue; - } - - auto ccid = SkCrossContextImageData::MakeFromEncoded(info.grContext(), encoded, - nullptr); - REPORTER_ASSERT(reporter, ccid != nullptr); - - auto image = SkImage::MakeFromCrossContextImageData(info.grContext(), std::move(ccid)); - REPORTER_ASSERT(reporter, image != nullptr); - - // JPEG encode -> decode won't round trip the image perfectly - assert_equal(reporter, testImage.get(), image.get(), - SkEncodedImageFormat::kJPEG == format ? 2 : 0); - } - } -} - -DEF_GPUTEST(CrossContextImage_SharedContextSameThread, reporter, /*factory*/) { - GrContextFactory factory; - sk_sp testImage = create_test_image(); - - // Test both PNG and JPG, to exercise GPU YUV conversion - for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) { - sk_sp encoded = create_test_data(format); - - for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { - GrContextFactory::ContextType ctxType = static_cast(i); - if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) { - continue; - } - - ContextInfo info = factory.getContextInfo(ctxType); - if (!info.grContext()) { - continue; - } - auto ccid = SkCrossContextImageData::MakeFromEncoded(info.grContext(), encoded, - nullptr); - REPORTER_ASSERT(reporter, ccid != nullptr); - - ContextInfo info2 = factory.getSharedContextInfo(info.grContext()); - GrContext* ctx2 = info2.grContext(); - int resourceCountBefore = 0, resourceCountAfter = 0; - size_t resourceBytesBefore = 0, resourceBytesAfter = 0; - if (ctx2 && info.grContext()->caps()->crossContextTextureSupport()) { - ctx2->getResourceCacheUsage(&resourceCountBefore, &resourceBytesBefore); - } - - auto image = SkImage::MakeFromCrossContextImageData(ctx2, std::move(ccid)); - REPORTER_ASSERT(reporter, image != nullptr); - - if (ctx2 && info.grContext()->caps()->crossContextTextureSupport()) { - // MakeFromCrossContextImageData should have imported the texture back into our - // cache, so we should see an uptick. (If we have crossContextTextureSupport, - // otherwise we're just handing around a CPU or codec-backed image, so no cache - // impact will occur). - ctx2->getResourceCacheUsage(&resourceCountAfter, &resourceBytesAfter); - REPORTER_ASSERT(reporter, resourceCountAfter == resourceCountBefore + 1); - REPORTER_ASSERT(reporter, resourceBytesAfter > resourceBytesBefore); - } - - // JPEG encode -> decode won't round trip the image perfectly - assert_equal(reporter, testImage.get(), image.get(), - SkEncodedImageFormat::kJPEG == format ? 2 : 0); - } - } -} - -namespace { -struct CrossContextImage_ThreadContext { - GrContext* fGrContext; - sk_gpu_test::TestContext* fTestContext; - SkSemaphore fSemaphore; - std::unique_ptr fCCID; - sk_sp fEncoded; -}; -} - -static void upload_image_thread_proc(void* data) { - CrossContextImage_ThreadContext* ctx = static_cast(data); - ctx->fTestContext->makeCurrent(); - ctx->fCCID = SkCrossContextImageData::MakeFromEncoded(ctx->fGrContext, ctx->fEncoded, nullptr); - ctx->fSemaphore.signal(); -} - -DEF_GPUTEST(CrossContextImage_SharedContextOtherThread, reporter, /*factory*/) { - sk_sp testImage = create_test_image(); - - // Test both PNG and JPG, to exercise GPU YUV conversion - for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) { - // Use a new factory for each batch of tests. Otherwise the shared context will still be - // current on the upload thread when we do the second iteration, and we get undefined - // behavior. - GrContextFactory factory; - sk_sp encoded = create_test_data(format); - - for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { - GrContextFactory::ContextType ctxType = static_cast(i); - if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) { - continue; - } - - // Create two GrContexts in a share group - ContextInfo info = factory.getContextInfo(ctxType); - if (!info.grContext()) { - continue; - } - ContextInfo info2 = factory.getSharedContextInfo(info.grContext()); - if (!info2.grContext()) { - continue; - } - - // Make the first one current (on this thread) again - info.testContext()->makeCurrent(); - - // Bundle up data for the worker thread - CrossContextImage_ThreadContext ctx; - ctx.fGrContext = info2.grContext(); - ctx.fTestContext = info2.testContext(); - ctx.fEncoded = encoded; - - SkThread uploadThread(upload_image_thread_proc, &ctx); - SkAssertResult(uploadThread.start()); - - ctx.fSemaphore.wait(); - auto image = SkImage::MakeFromCrossContextImageData(info.grContext(), - std::move(ctx.fCCID)); - REPORTER_ASSERT(reporter, image != nullptr); - - // JPEG encode -> decode won't round trip the image perfectly - assert_equal(reporter, testImage.get(), image.get(), - SkEncodedImageFormat::kJPEG == format ? 2 : 0); - - uploadThread.join(); - } - } -} - -#endif diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 3a11bb9c2e..45946cf7d8 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -212,13 +212,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI return; } - GrBackendObject texHandles[3]; + GrBackendObject texHandles[2]; static const int kW = 100; static const int kH = 100; texHandles[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); texHandles[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); - texHandles[2] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); context->resetContext(); @@ -240,46 +239,26 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI backendTex2, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, kAdopt_GrWrapOwnership)); - GrBackendTexture backendTex3 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kW, - kH, - kRGBA_8888_GrPixelConfig, - texHandles[2]); - sk_sp adoptedAndCached(context->resourceProvider()->wrapBackendTexture( - backendTex3, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, - kAdoptAndCache_GrWrapOwnership)); - - REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr && - adoptedAndCached != nullptr); - if (!borrowed || !adopted || !adoptedAndCached) { + REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); + if (!borrowed || !adopted) { return; } borrowed.reset(nullptr); adopted.reset(nullptr); - adoptedAndCached.reset(nullptr); context->flush(); bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]); bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]); - bool adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]); REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive); - REPORTER_ASSERT(reporter, adoptedAndCachedIsAlive); // Still alive because it's in the cache gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive); gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive); - // We can't delete texHandles[2] - we've given control of the lifetime to the context/cache context->resetContext(); - - // Purge the cache. This should force texHandles[2] to be deleted - context->getResourceCache()->purgeAllUnlocked(); - adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]); - REPORTER_ASSERT(reporter, !adoptedAndCachedIsAlive); - gpu->deleteTestingOnlyBackendTexture(texHandles[2], !adoptedAndCachedIsAlive); } class TestResource : public GrGpuResource { -- cgit v1.2.3