aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2016-12-13 15:29:42 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-13 22:01:58 +0000
commit398487a850431cf495330d4023607df5305a311f (patch)
tree7ab227c99eaab21554428f7a94e0c2df67be009a /tests
parent24f19780d1e76595c049d8cad4352de839cfc6b5 (diff)
Add a deferred copy surface (take 2)
This CL forces all GrSurface copies to go through a GrSurfaceContext (rather than GrContext). There is a bit of goofiness going on here until read/writePixels is also consolidated in GrSurfaceContext and a proxy-backed SkImage/SkSurface is added. This is a reland of https://skia-review.googlesource.com/c/5773/ (Add a deferred copy surface) Change-Id: Ide560f569aede5e622420dc2f30eef76357d69f4 Reviewed-on: https://skia-review.googlesource.com/5939 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/CopySurfaceTest.cpp36
-rw-r--r--tests/EGLImageTest.cpp13
-rw-r--r--tests/GrTextureStripAtlasTest.cpp119
-rw-r--r--tests/IntTextureTest.cpp70
-rw-r--r--tests/RectangleTextureTest.cpp37
5 files changed, 179 insertions, 96 deletions
diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp
index 053b456f57..68113e7ecc 100644
--- a/tests/CopySurfaceTest.cpp
+++ b/tests/CopySurfaceTest.cpp
@@ -10,6 +10,9 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrContextPriv.h"
+#include "GrSurfaceContext.h"
+#include "GrSurfaceProxy.h"
#include "GrTexture.h"
#include "GrTextureProvider.h"
@@ -68,22 +71,29 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
dstDesc.fOrigin = dOrigin;
dstDesc.fFlags = dFlags;
- sk_sp<GrTexture> src(
- context->textureProvider()->createTexture(srcDesc, SkBudgeted::kNo,
- srcPixels.get(),
- kRowBytes));
- sk_sp<GrTexture> dst(
- context->textureProvider()->createTexture(dstDesc, SkBudgeted::kNo,
- dstPixels.get(),
- kRowBytes));
+ sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(
+ *context->caps(),
+ context->textureProvider(),
+ srcDesc, SkBudgeted::kNo,
+ srcPixels.get(),
+ kRowBytes));
+
+ sk_sp<GrSurfaceProxy> dst(GrSurfaceProxy::MakeDeferred(
+ *context->caps(),
+ context->textureProvider(),
+ dstDesc, SkBudgeted::kNo,
+ dstPixels.get(),
+ kRowBytes));
if (!src || !dst) {
ERRORF(reporter,
"Could not create surfaces for copy surface test.");
continue;
}
- bool result
- = context->copySurface(dst.get(), src.get(), srcRect, dstPoint);
+ sk_sp<GrSurfaceContext> sContext =
+ context->contextPriv().makeTestSurfaceContext(dst);
+
+ bool result = sContext->copy(src.get(), srcRect, dstPoint);
bool expectedResult = true;
SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft,
@@ -120,9 +130,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
continue;
}
+ GrSurface* dstSurf = dst->instantiate(context->textureProvider());
+
sk_memset32(read.get(), 0, kW * kH);
- if (!dst->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(),
- kRowBytes)) {
+ if (!dstSurf->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(),
+ kRowBytes)) {
ERRORF(reporter, "Error calling readPixels");
continue;
}
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index f78a0ea02a..0dcacf9b6b 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -10,6 +10,7 @@
#include "GrContext.h"
#include "GrContextFactory.h"
#include "GrShaderCaps.h"
+#include "GrSurfaceContext.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLUtil.h"
#include "gl/GLTestContext.h"
@@ -40,7 +41,7 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx
}
static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrTexture* externalTexture, uint32_t expectedPixelValues[]) {
+ GrSurface* externalTexture, uint32_t expectedPixelValues[]) {
int pixelCnt = externalTexture->width() * externalTexture->height();
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
@@ -76,9 +77,13 @@ static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context,
copyDesc.fWidth = externalTexture->width();
copyDesc.fHeight = externalTexture->height();
copyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- sk_sp<GrTexture> copy(context->textureProvider()->createTexture(copyDesc, SkBudgeted::kYes));
- context->copySurface(copy.get(), externalTexture);
- test_read_pixels(reporter, context, copy.get(), expectedPixelValues);
+
+ sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, copyDesc,
+ externalTexture, SkBudgeted::kYes));
+
+ GrSurface* copySurf = copy->instantiate(context->textureProvider());
+
+ test_read_pixels(reporter, context, copySurf, expectedPixelValues);
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
diff --git a/tests/GrTextureStripAtlasTest.cpp b/tests/GrTextureStripAtlasTest.cpp
index 60b8a6dcc4..d3f5598650 100644
--- a/tests/GrTextureStripAtlasTest.cpp
+++ b/tests/GrTextureStripAtlasTest.cpp
@@ -9,6 +9,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrTextureStripAtlas.h"
#include "GrTypes.h"
@@ -21,51 +22,97 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextureStripAtlasFlush, reporter, ctxInfo)
desc.fWidth = 32;
desc.fHeight = 32;
desc.fConfig = kRGBA_8888_GrPixelConfig;
- GrTexture* texture = context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
- nullptr, 0);
- GrSurfaceDesc targetDesc = desc;
- targetDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- GrTexture* target = context->textureProvider()->createTexture(targetDesc, SkBudgeted::kYes,
- nullptr, 0);
+ sk_sp<GrSurfaceProxy> srcProxy;
- SkAutoTMalloc<uint32_t> pixels(desc.fWidth * desc.fHeight);
- memset(pixels.get(), 0xFF, sizeof(uint32_t) * desc.fWidth * desc.fHeight);
- texture->writePixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_8888_GrPixelConfig, pixels.get());
+ {
+ SkAutoTMalloc<uint32_t> pixels(desc.fWidth * desc.fHeight);
+ memset(pixels.get(), 0xFF, sizeof(uint32_t) * desc.fWidth * desc.fHeight);
- // Add a pending read to the texture, and then make it available for reuse.
- context->copySurface(target, texture);
- texture->unref();
+ srcProxy = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(),
+ desc, SkBudgeted::kYes,
+ pixels.get(), 0);
+ }
+
+ // Add a pending read to the src texture, and then make it available for reuse.
+ sk_sp<GrSurfaceProxy> targetProxy;
+ GrSurface* srcSurface;
+
+ {
+ GrSurfaceDesc targetDesc = desc;
+ targetDesc.fFlags = kRenderTarget_GrSurfaceFlag;
+
+ // We can't use GrSurfaceProxy::Copy bc we may be changing the dst proxy type
+ sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
+ targetDesc,
+ SkBudgeted::kYes));
+ REPORTER_ASSERT(reporter, dstContext);
+
+ if (!dstContext->copy(srcProxy.get())) {
+ return;
+ }
+
+ targetProxy = sk_ref_sp(dstContext->asDeferredSurface());
+
+ srcSurface = srcProxy->instantiate(context->textureProvider());
+ srcProxy.reset();
+ }
// Create an atlas with parameters that allow it to reuse the texture.
- GrTextureStripAtlas::Desc atlasDesc;
- atlasDesc.fContext = context;
- atlasDesc.fConfig = desc.fConfig;
- atlasDesc.fWidth = desc.fWidth;
- atlasDesc.fHeight = desc.fHeight;
- atlasDesc.fRowHeight = 1;
- GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(atlasDesc);
+ GrTextureStripAtlas* atlas;
+
+ {
+ GrTextureStripAtlas::Desc atlasDesc;
+ atlasDesc.fContext = context;
+ atlasDesc.fConfig = desc.fConfig;
+ atlasDesc.fWidth = desc.fWidth;
+ atlasDesc.fHeight = desc.fHeight;
+ atlasDesc.fRowHeight = 1;
+ atlas = GrTextureStripAtlas::GetAtlas(atlasDesc);
+ }
// Write to the atlas' texture.
- SkImageInfo info = SkImageInfo::MakeN32(desc.fWidth, desc.fHeight, kPremul_SkAlphaType);
- size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
- SkBitmap bitmap;
- bitmap.allocPixels(info, rowBytes);
- memset(bitmap.getPixels(), 1, rowBytes * desc.fHeight);
- int row = atlas->lockRow(bitmap);
- if (!context->caps()->preferVRAMUseOverFlushes())
- REPORTER_ASSERT(reporter, texture == atlas->getTexture());
+ int lockedRow;
+
+ {
+ SkImageInfo info = SkImageInfo::MakeN32(desc.fWidth, desc.fHeight, kPremul_SkAlphaType);
+ size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
+ SkBitmap bitmap;
+ bitmap.allocPixels(info, rowBytes);
+ memset(bitmap.getPixels(), 1, rowBytes * desc.fHeight);
+ lockedRow = atlas->lockRow(bitmap);
+ }
// The atlas' use of its texture shouldn't change which pixels got copied to the target.
- SkAutoTMalloc<uint32_t> actualPixels(desc.fWidth * desc.fHeight);
- bool success = target->readPixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_8888_GrPixelConfig,
- actualPixels.get());
- REPORTER_ASSERT(reporter, success);
- REPORTER_ASSERT(reporter,
- !memcmp(pixels.get(), actualPixels.get(),
- sizeof(uint32_t) * desc.fWidth * desc.fHeight));
- target->unref();
- atlas->unlockRow(row);
+ {
+ SkAutoTMalloc<uint8_t> actualPixels(sizeof(uint32_t) * desc.fWidth * desc.fHeight);
+
+ // TODO: move readPixels to GrSurfaceProxy?
+ GrSurface* surf = targetProxy->instantiate(context->textureProvider());
+
+ bool success = surf->readPixels(0, 0, desc.fWidth, desc.fHeight,
+ kRGBA_8888_GrPixelConfig, actualPixels.get());
+ REPORTER_ASSERT(reporter, success);
+
+ bool good = true;
+
+ const uint8_t* bytes = actualPixels.get();
+ for (size_t i = 0; i < sizeof(uint32_t) * desc.fWidth * desc.fHeight; ++i, ++bytes) {
+ if (0xFF != *bytes) {
+ good = false;
+ break;
+ }
+ }
+
+ REPORTER_ASSERT(reporter, good);
+ }
+
+ if (!context->caps()->preferVRAMUseOverFlushes()) {
+ // This is kindof dodgy since we released it!
+ REPORTER_ASSERT(reporter, srcSurface == atlas->getTexture());
+ }
+
+ atlas->unlockRow(lockedRow);
}
#endif
diff --git a/tests/IntTextureTest.cpp b/tests/IntTextureTest.cpp
index a6eaf98aea..5e3fde2f75 100644
--- a/tests/IntTextureTest.cpp
+++ b/tests/IntTextureTest.cpp
@@ -95,40 +95,48 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, !success);
// Test that copying from one integer texture to another succeeds.
- sk_sp<GrTexture> copy(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
- REPORTER_ASSERT(reporter, copy);
- if (!copy) {
- return;
- }
- success = context->copySurface(copy.get(), texture.get());
- REPORTER_ASSERT(reporter, success);
- if (!success) {
- return;
- }
- sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
- success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
- REPORTER_ASSERT(reporter, success);
- if (success) {
- check_pixels(reporter, kS, kS, testData.get(), readData.get());
+ {
+ sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, desc,
+ texture.get(), SkBudgeted::kYes));
+ REPORTER_ASSERT(reporter, copy);
+ if (!copy) {
+ return;
+ }
+
+ GrSurface* copySurface = copy->instantiate(context->textureProvider());
+ REPORTER_ASSERT(reporter, copySurface);
+ if (!copySurface) {
+ return;
+ }
+
+ sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
+ success = copySurface->readPixels(0, 0, kS, kS,
+ kRGBA_8888_sint_GrPixelConfig, readData.get());
+ REPORTER_ASSERT(reporter, success);
+ if (success) {
+ check_pixels(reporter, kS, kS, testData.get(), readData.get());
+ }
}
- // Test that copying to a non-integer texture fails.
- GrSurfaceDesc nonIntDesc = desc;
- nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
- copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
- REPORTER_ASSERT(reporter, copy);
- if (!copy) {
- return;
+
+ // Test that copying to a non-integer (8888) texture fails.
+ {
+ GrSurfaceDesc nonIntDesc = desc;
+ nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
+
+ sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc,
+ texture.get(), SkBudgeted::kYes));
+ REPORTER_ASSERT(reporter, !copy);
}
- success = context->copySurface(copy.get(), texture.get());
- REPORTER_ASSERT(reporter, !success);
- nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
- copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
- REPORTER_ASSERT(reporter, copy ||
- !context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig));
- if (copy) {
- success = context->copySurface(copy.get(), texture.get());
- REPORTER_ASSERT(reporter, !success);
+
+ // Test that copying to a non-integer (RGBA_half) texture fails.
+ if (context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
+ GrSurfaceDesc nonIntDesc = desc;
+ nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
+
+ sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc,
+ texture.get(), SkBudgeted::kYes));
+ REPORTER_ASSERT(reporter, !copy);
}
// We overwrite the top left quarter of the texture with the bottom right quarter of the
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index cc0c4d1e31..587160448c 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -15,7 +15,7 @@
#include "gl/GLTestContext.h"
static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
- GrTexture* texture, uint32_t expectedPixelValues[]) {
+ GrSurface* texture, uint32_t expectedPixelValues[]) {
int pixelCnt = texture->width() * texture->height();
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
@@ -52,22 +52,30 @@ static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
}
static void test_copy_surface_src(skiatest::Reporter* reporter, GrContext* context,
- GrTexture* rectangleTexture, uint32_t expectedPixelValues[]) {
+ GrTexture* rectTexture, uint32_t expectedPixelValues[]) {
+ GrSurfaceDesc copyDstDesc;
+ copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
+ copyDstDesc.fWidth = rectTexture->width();
+ copyDstDesc.fHeight = rectTexture->height();
+
for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) {
- GrSurfaceDesc copyDstDesc;
- copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig;
- copyDstDesc.fWidth = rectangleTexture->width();
- copyDstDesc.fHeight = rectangleTexture->height();
copyDstDesc.fFlags = flags;
- sk_sp<GrTexture> dst(
- context->textureProvider()->createTexture(copyDstDesc, SkBudgeted::kYes));
- context->copySurface(dst.get(), rectangleTexture);
- test_read_pixels(reporter, context, dst.get(), expectedPixelValues);
+
+ sk_sp<GrSurfaceProxy> dst(GrSurfaceProxy::TestCopy(context, copyDstDesc,
+ rectTexture, SkBudgeted::kYes));
+
+ GrSurface* dstSurf = dst->instantiate(context->textureProvider());
+
+ test_read_pixels(reporter, context, dstSurf, expectedPixelValues);
}
}
static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* context,
GrTexture* rectangleTexture) {
+
+ sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext(
+ sk_ref_sp(rectangleTexture)));
+
int pixelCnt = rectangleTexture->width() * rectangleTexture->height();
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
for (int y = 0; y < rectangleTexture->width(); ++y) {
@@ -81,10 +89,13 @@ static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* conte
copySrcDesc.fWidth = rectangleTexture->width();
copySrcDesc.fHeight = rectangleTexture->height();
copySrcDesc.fFlags = flags;
- sk_sp<GrTexture> src(context->textureProvider()->createTexture(
- copySrcDesc, SkBudgeted::kYes, pixels.get(), 0));
- context->copySurface(rectangleTexture, src.get());
+ sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(*context->caps(),
+ context->textureProvider(),
+ copySrcDesc,
+ SkBudgeted::kYes, pixels.get(), 0));
+ sContext->copy(src.get());
+
test_read_pixels(reporter, context, rectangleTexture, pixels.get());
}
}