aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gn/tests.gni2
-rw-r--r--tests/EGLImageTest.cpp66
-rw-r--r--tests/ImageTest.cpp12
-rw-r--r--tests/RectangleTextureTest.cpp103
-rw-r--r--tests/TestUtils.cpp117
-rw-r--r--tests/TestUtils.h34
6 files changed, 154 insertions, 180 deletions
diff --git a/gn/tests.gni b/gn/tests.gni
index 6a836f6ca5..483f574ed6 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -234,8 +234,6 @@ tests_sources = [
"$_tests/Test.cpp",
"$_tests/TestConfigParsing.cpp",
"$_tests/TestTest.cpp",
- "$_tests/TestUtils.h",
- "$_tests/TestUtils.cpp",
"$_tests/TextBlobCacheTest.cpp",
"$_tests/TextBlobTest.cpp",
"$_tests/TextureCompressionTest.cpp",
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 02ba4a82df..79d326156a 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -6,7 +6,6 @@
*/
#include "Test.h"
-#include "TestUtils.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
@@ -42,6 +41,58 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx
}
}
+static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceContext* externalTextureContext,
+ uint32_t expectedPixelValues[]) {
+ int pixelCnt = externalTextureContext->width() * externalTextureContext->height();
+ SkAutoTMalloc<uint32_t> pixels(pixelCnt);
+ memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
+
+ SkImageInfo ii = SkImageInfo::Make(externalTextureContext->width(),
+ externalTextureContext->height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ bool read = externalTextureContext->readPixels(ii, pixels.get(), 0, 0, 0);
+ if (!read) {
+ ERRORF(reporter, "Error reading external texture.");
+ }
+ for (int i = 0; i < pixelCnt; ++i) {
+ if (pixels.get()[i] != expectedPixelValues[i]) {
+ ERRORF(reporter, "Error, external texture pixel value %d should be 0x%08x,"
+ " got 0x%08x.", i, expectedPixelValues[i], pixels.get()[i]);
+ break;
+ }
+ }
+}
+
+static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceContext* externalTextureContext) {
+ int pixelCnt = externalTextureContext->width() * externalTextureContext->height();
+ SkAutoTMalloc<uint32_t> pixels(pixelCnt);
+ memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
+
+ SkImageInfo ii = SkImageInfo::Make(externalTextureContext->width(),
+ externalTextureContext->height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ bool write = externalTextureContext->writePixels(ii, pixels.get(), 0, 0, 0);
+ REPORTER_ASSERT_MESSAGE(reporter, !write, "Should not be able to write to a EXTERNAL"
+ " texture.");
+}
+
+static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceProxy* externalTextureProxy,
+ uint32_t expectedPixelValues[]) {
+ GrSurfaceDesc copyDesc;
+ copyDesc.fConfig = kRGBA_8888_GrPixelConfig;
+ copyDesc.fWidth = externalTextureProxy->width();
+ copyDesc.fHeight = externalTextureProxy->height();
+ copyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+
+ sk_sp<GrSurfaceContext> copyContext(GrSurfaceProxy::TestCopy(context, copyDesc,
+ externalTextureProxy));
+
+ test_read_pixels(reporter, context, copyContext.get(), expectedPixelValues);
+}
+
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
GrContext* context0 = ctxInfo.grContext();
sk_gpu_test::GLTestContext* glCtx0 = ctxInfo.glContext();
@@ -172,17 +223,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
externalDesc.fSampleCnt = 0;
}
- test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get(),
- "EGLImageTest-read");
+ test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get());
- // We should not be able to write to a EXTERNAL texture
- test_write_pixels(reporter, context0, externalTextureContext.get(), false,
- "EGLImageTest-write");
+ test_write_pixels(reporter, context0, externalTextureContext.get());
- // Only test RT-config
- // TODO: why do we always need to draw to copy from an external texture?
- test_copy_from_surface(reporter, context0, externalTextureContext->asDeferredSurface(),
- pixels.get(), true, "EGLImageTest-copy");
+ test_copy_surface(reporter, context0, externalTextureContext->asDeferredSurface(),
+ pixels.get());
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image);
}
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 66f19fa7ea..4f9d944d25 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -541,7 +541,7 @@ static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
return true;
}
-static void image_test_read_pixels(skiatest::Reporter* reporter, SkImage* image) {
+static void test_read_pixels(skiatest::Reporter* reporter, SkImage* image) {
if (!image) {
ERRORF(reporter, "Failed to create image!");
return;
@@ -591,23 +591,23 @@ static void image_test_read_pixels(skiatest::Reporter* reporter, SkImage* image)
}
DEF_TEST(ImageReadPixels, reporter) {
sk_sp<SkImage> image(create_image());
- image_test_read_pixels(reporter, image.get());
+ test_read_pixels(reporter, image.get());
image = create_data_image();
- image_test_read_pixels(reporter, image.get());
+ test_read_pixels(reporter, image.get());
RasterDataHolder dataHolder;
image = create_rasterproc_image(&dataHolder);
- image_test_read_pixels(reporter, image.get());
+ test_read_pixels(reporter, image.get());
image.reset();
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
image = create_codec_image();
- image_test_read_pixels(reporter, image.get());
+ test_read_pixels(reporter, image.get());
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) {
- image_test_read_pixels(reporter, create_gpu_image(ctxInfo.grContext()).get());
+ test_read_pixels(reporter, create_gpu_image(ctxInfo.grContext()).get());
}
#endif
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index d55b882f7e..523c2e3437 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -6,8 +6,6 @@
*/
#include "Test.h"
-#include "TestUtils.h"
-
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
@@ -16,6 +14,92 @@
#include "gl/GrGLUtil.h"
#include "gl/GLTestContext.h"
+static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceContext* srcContext, uint32_t expectedPixelValues[]) {
+ int pixelCnt = srcContext->width() * srcContext->height();
+ SkAutoTMalloc<uint32_t> pixels(pixelCnt);
+ memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
+
+ SkImageInfo ii = SkImageInfo::Make(srcContext->width(), srcContext->height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ bool read = srcContext->readPixels(ii, pixels.get(), 0, 0, 0);
+ if (!read) {
+ ERRORF(reporter, "Error reading rectangle texture.");
+ }
+
+ for (int i = 0; i < pixelCnt; ++i) {
+ if (pixels.get()[i] != expectedPixelValues[i]) {
+ ERRORF(reporter, "Error, pixel value %d should be 0x%08x, got 0x%08x.", i,
+ expectedPixelValues[i], pixels.get()[i]);
+ break;
+ }
+ }
+}
+
+static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceContext* rectSurfaceContext) {
+ int pixelCnt = rectSurfaceContext->width() * rectSurfaceContext->height();
+ SkAutoTMalloc<uint32_t> pixels(pixelCnt);
+ for (int y = 0; y < rectSurfaceContext->width(); ++y) {
+ for (int x = 0; x < rectSurfaceContext->height(); ++x) {
+ pixels.get()[y * rectSurfaceContext->width() + x] = GrColorPackRGBA(x, y, x + y, x * y);
+ }
+ }
+
+ SkImageInfo ii = SkImageInfo::Make(rectSurfaceContext->width(), rectSurfaceContext->height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ bool write = rectSurfaceContext->writePixels(ii, pixels.get(), 0, 0, 0);
+ if (!write) {
+ ERRORF(reporter, "Error writing to rectangle texture.");
+ }
+
+ test_read_pixels(reporter, context, rectSurfaceContext, pixels.get());
+}
+
+static void test_copy_surface_src(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceProxy* rectProxy, uint32_t expectedPixelValues[]) {
+ GrSurfaceDesc copyDstDesc;
+ copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
+ copyDstDesc.fWidth = rectProxy->width();
+ copyDstDesc.fHeight = rectProxy->height();
+
+ for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) {
+ copyDstDesc.fFlags = flags;
+
+ sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, copyDstDesc,
+ rectProxy));
+
+ test_read_pixels(reporter, context, dstContext.get(), expectedPixelValues);
+ }
+}
+
+static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* context,
+ GrSurfaceContext* rectContext) {
+
+ int pixelCnt = rectContext->width() * rectContext->height();
+ SkAutoTMalloc<uint32_t> pixels(pixelCnt);
+ for (int y = 0; y < rectContext->width(); ++y) {
+ for (int x = 0; x < rectContext->height(); ++x) {
+ pixels.get()[y * rectContext->width() + x] = GrColorPackRGBA(y, x, x * y, x *+ y);
+ }
+ }
+ for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) {
+ GrSurfaceDesc copySrcDesc;
+ copySrcDesc.fConfig = kRGBA_8888_GrPixelConfig;
+ copySrcDesc.fWidth = rectContext->width();
+ copySrcDesc.fHeight = rectContext->height();
+ copySrcDesc.fFlags = flags;
+
+ sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(*context->caps(),
+ context->textureProvider(),
+ copySrcDesc,
+ SkBudgeted::kYes, pixels.get(), 0));
+ rectContext->copy(src.get());
+
+ test_read_pixels(reporter, context, rectContext, pixels.get());
+ }
+}
+
// skbug.com/5932
static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context,
sk_sp<GrSurfaceProxy> rectProxy, uint32_t expectedPixelValues[]) {
@@ -36,8 +120,7 @@ static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* cont
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.addColorFragmentProcessor(std::move(fp));
rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I());
- test_read_pixels(reporter, context, rtContext.get(), expectedPixelValues,
- "RectangleTexture-basic-draw");
+ test_read_pixels(reporter, context, rtContext.get(), expectedPixelValues);
}
}
@@ -82,7 +165,7 @@ static void test_clear(skiatest::Reporter* reporter, GrContext* context,
}
}
- test_read_pixels(reporter, context, rtc, expectedPixels.get(), "RectangleTexture-clear");
+ test_read_pixels(reporter, context, rtc, expectedPixels.get());
}
}
@@ -154,19 +237,17 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
test_basic_draw_as_src(reporter, context, rectProxy, refPixels);
- // Test copy to both a texture and RT
- test_copy_from_surface(reporter, context, rectProxy.get(), refPixels,
- false, "RectangleTexture-copy-from");
+ test_copy_surface_src(reporter, context, rectProxy.get(), refPixels);
sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext(
std::move(rectProxy), nullptr);
SkASSERT(rectContext);
- test_read_pixels(reporter, context, rectContext.get(), refPixels, "RectangleTexture-read");
+ test_read_pixels(reporter, context, rectContext.get(), refPixels);
- test_copy_to_surface(reporter, context, rectContext.get(), "RectangleTexture-copy-to");
+ test_copy_surface_dst(reporter, context, rectContext.get());
- test_write_pixels(reporter, context, rectContext.get(), true, "RectangleTexture-write");
+ test_write_pixels(reporter, context, rectContext.get());
test_clear(reporter, context, rectContext.get());
diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp
deleted file mode 100644
index 61f4636f66..0000000000
--- a/tests/TestUtils.cpp
+++ /dev/null
@@ -1,117 +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 "TestUtils.h"
-
-#if SK_SUPPORT_GPU
-
-#include "GrSurfaceContext.h"
-#include "GrSurfaceProxy.h"
-
-void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* srcContext, uint32_t expectedPixelValues[],
- const char* testName) {
- int pixelCnt = srcContext->width() * srcContext->height();
- SkAutoTMalloc<uint32_t> pixels(pixelCnt);
- memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
-
- SkImageInfo ii = SkImageInfo::Make(srcContext->width(), srcContext->height(),
- kRGBA_8888_SkColorType, kPremul_SkAlphaType);
- bool read = srcContext->readPixels(ii, pixels.get(), 0, 0, 0);
- if (!read) {
- ERRORF(reporter, "%s: Error reading from texture.", testName);
- }
-
- for (int i = 0; i < pixelCnt; ++i) {
- if (pixels.get()[i] != expectedPixelValues[i]) {
- ERRORF(reporter, "%s: Error, pixel value %d should be 0x%08x, got 0x%08x.",
- testName, i, expectedPixelValues[i], pixels.get()[i]);
- break;
- }
- }
-}
-
-void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* dstContext, bool expectedToWork,
- const char* testName) {
- int pixelCnt = dstContext->width() * dstContext->height();
- SkAutoTMalloc<uint32_t> pixels(pixelCnt);
- for (int y = 0; y < dstContext->width(); ++y) {
- for (int x = 0; x < dstContext->height(); ++x) {
- pixels.get()[y * dstContext->width() + x] = GrColorPackRGBA(x, y, x + y, x * y);
- }
- }
-
- SkImageInfo ii = SkImageInfo::Make(dstContext->width(), dstContext->height(),
- kRGBA_8888_SkColorType, kPremul_SkAlphaType);
- bool write = dstContext->writePixels(ii, pixels.get(), 0, 0, 0);
- if (!write) {
- if (expectedToWork) {
- ERRORF(reporter, "%s: Error writing to texture.", testName);
- }
- return;
- }
-
- if (write && !expectedToWork) {
- ERRORF(reporter, "%s: writePixels succeeded when it wasn't supposed to.", testName);
- return;
- }
-
- test_read_pixels(reporter, context, dstContext, pixels.get(), testName);
-}
-
-void test_copy_from_surface(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceProxy* proxy, uint32_t expectedPixelValues[],
- bool onlyTestRTConfig, const char* testName) {
- GrSurfaceDesc copyDstDesc;
- copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
- copyDstDesc.fWidth = proxy->width();
- copyDstDesc.fHeight = proxy->height();
-
- for (auto flags : { kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag }) {
- if (kNone_GrSurfaceFlags == flags && onlyTestRTConfig) {
- continue;
- }
-
- copyDstDesc.fFlags = flags;
-
- sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, copyDstDesc, proxy));
-
- test_read_pixels(reporter, context, dstContext.get(), expectedPixelValues, testName);
- }
-}
-
-void test_copy_to_surface(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* dstContext, const char* testName) {
-
- int pixelCnt = dstContext->width() * dstContext->height();
- SkAutoTMalloc<uint32_t> pixels(pixelCnt);
- for (int y = 0; y < dstContext->width(); ++y) {
- for (int x = 0; x < dstContext->height(); ++x) {
- pixels.get()[y * dstContext->width() + x] = GrColorPackRGBA(y, x, x * y, x *+ y);
- }
- }
-
- GrSurfaceDesc copySrcDesc;
- copySrcDesc.fConfig = kRGBA_8888_GrPixelConfig;
- copySrcDesc.fWidth = dstContext->width();
- copySrcDesc.fHeight = dstContext->height();
-
- for (auto flags : { kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag }) {
- copySrcDesc.fFlags = flags;
-
- sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(*context->caps(),
- context->textureProvider(),
- copySrcDesc,
- SkBudgeted::kYes, pixels.get(), 0));
- dstContext->copy(src.get());
-
- test_read_pixels(reporter, context, dstContext, pixels.get(), testName);
- }
-}
-
-#endif
diff --git a/tests/TestUtils.h b/tests/TestUtils.h
deleted file mode 100644
index 7c3370ed7e..0000000000
--- a/tests/TestUtils.h
+++ /dev/null
@@ -1,34 +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 "Test.h"
-
-#if SK_SUPPORT_GPU
-
-class GrSurfaceContext;
-class GrSurfaceProxy;
-
-// Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues
-void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* srcContext, uint32_t expectedPixelValues[],
- const char* testName);
-
-// See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the
-// expectation ('expectedToWork')
-void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* srcContext, bool expectedToWork, const char* testName);
-
-// Ensure that the pixels can be copied from 'proxy' to an RGBA 8888 destination (both
-// texture-backed and rendertarget-backed).
-void test_copy_from_surface(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceProxy* proxy, uint32_t expectedPixelValues[],
- bool onlyTestRTConfig, const char* testName);
-
-// Ensure that RGBA 8888 pixels can be copied into 'dstContext'
-void test_copy_to_surface(skiatest::Reporter* reporter, GrContext* context,
- GrSurfaceContext* dstContext, const char* testName);
-#endif