aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-04-14 12:51:55 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-14 17:39:12 +0000
commit74d5a1470378dc7dae9eec38d46f9f802fc5c249 (patch)
tree97fb91742dceea5eb8644f018a5968bea362c591
parent307efd4e8131836594681a7d975ba87dee2d8e93 (diff)
Reduce read/write-SurfacePixels call sites
Change-Id: I657c489c56b93765567be69076fb4c3d526e55a5 Reviewed-on: https://skia-review.googlesource.com/13068 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--tests/PackedConfigsTextureTest.cpp42
-rw-r--r--tests/ReadPixelsTest.cpp50
-rw-r--r--tests/ReadWriteAlphaTest.cpp17
-rw-r--r--tests/VkUploadPixelsTests.cpp74
4 files changed, 104 insertions, 79 deletions
diff --git a/tests/PackedConfigsTextureTest.cpp b/tests/PackedConfigsTextureTest.cpp
index 35d9dfc3c5..e104be594d 100644
--- a/tests/PackedConfigsTextureTest.cpp
+++ b/tests/PackedConfigsTextureTest.cpp
@@ -96,34 +96,40 @@ static void check_565(skiatest::Reporter* reporter,
}
}
-template <typename T>
-void runTest(skiatest::Reporter* reporter, GrContext* context,
- T val1, T val2, int arraySize, GrPixelConfig config) {
- SkTDArray<T> controlPixelData;
+static void run_test(skiatest::Reporter* reporter, GrContext* context,
+ int arraySize, GrPixelConfig config) {
+ SkTDArray<uint16_t> controlPixelData;
// We will read back into an 8888 buffer since 565/4444 read backs aren't supported
SkTDArray<GrColor> readBuffer;
controlPixelData.setCount(arraySize);
readBuffer.setCount(arraySize);
for (int i = 0; i < arraySize; i += 2) {
- controlPixelData[i] = val1;
- controlPixelData[i + 1] = val2;
+ controlPixelData[i] = 0xFF00;
+ controlPixelData[i + 1] = 0xFA62;
}
- for (int origin = 0; origin < 2; ++origin) {
+ const SkImageInfo dstInfo = SkImageInfo::Make(DEV_W, DEV_H,
+ kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
+
+ for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
GrSurfaceDesc desc;
desc.fFlags = kNone_GrSurfaceFlags;
desc.fWidth = DEV_W;
desc.fHeight = DEV_H;
desc.fConfig = config;
- desc.fOrigin = 0 == origin ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
- sk_sp<GrTextureProxy> fpProxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
- desc, SkBudgeted::kNo,
- controlPixelData.begin(), 0);
- SkASSERT(fpProxy);
- context->contextPriv().readSurfacePixels(fpProxy.get(), nullptr, 0, 0, DEV_W, DEV_H,
- kRGBA_8888_GrPixelConfig, nullptr,
- readBuffer.begin(), 0);
+ desc.fOrigin = origin;
+
+ sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+ desc, SkBudgeted::kNo,
+ controlPixelData.begin(), 0);
+ SkASSERT(proxy);
+
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(proxy), nullptr);
+
+ SkAssertResult(sContext->readPixels(dstInfo, readBuffer.begin(), 0, 0, 0));
+
if (kRGBA_4444_GrPixelConfig == config) {
check_4444(reporter, controlPixelData, readBuffer);
} else {
@@ -136,13 +142,11 @@ void runTest(skiatest::Reporter* reporter, GrContext* context,
static const int CONTROL_ARRAY_SIZE = DEV_W * DEV_H;
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGBA4444TextureTest, reporter, ctxInfo) {
- runTest<uint16_t>(reporter, ctxInfo.grContext(), 0xFF00, 0xFA62,
- CONTROL_ARRAY_SIZE, kRGBA_4444_GrPixelConfig);
+ run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kRGBA_4444_GrPixelConfig);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGB565TextureTest, reporter, ctxInfo) {
- runTest<uint16_t>(reporter, ctxInfo.grContext(), 0xFF00, 0xFA62,
- CONTROL_ARRAY_SIZE, kRGB_565_GrPixelConfig);
+ run_test(reporter, ctxInfo.grContext(), CONTROL_ARRAY_SIZE, kRGB_565_GrPixelConfig);
}
#endif
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index c67e62b090..10462c9140 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -123,21 +123,6 @@ static void fill_src_canvas(SkCanvas* canvas) {
canvas->restore();
}
-#if SK_SUPPORT_GPU
-static void fill_src_texture(GrContext* context, GrTextureProxy* proxy) {
- SkBitmap bmp = make_src_bitmap();
- bmp.lockPixels();
-
- SkDEBUGCODE(bool result =) context->contextPriv().writeSurfacePixels(
- proxy, nullptr,
- 0, 0, DEV_W, DEV_H,
- kSkia8888_GrPixelConfig, nullptr,
- bmp.getPixels(), bmp.rowBytes());
- SkASSERT(result);
- bmp.unlockPixels();
-}
-#endif
-
static void fill_dst_bmp_with_init_data(SkBitmap* bitmap) {
SkAutoLockPixels alp(*bitmap);
int w = bitmap->width();
@@ -443,8 +428,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) {
#if SK_SUPPORT_GPU
static void test_readpixels_texture(skiatest::Reporter* reporter,
- GrContext* context, sk_sp<GrTextureProxy> proxy) {
- fill_src_texture(context, proxy.get());
+ sk_sp<GrSurfaceContext> sContext) {
for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
const SkIRect& srcRect = gReadPixelsTestRects[rect];
for (BitmapInit bmi = kFirstBitmapInit; bmi <= kLast_BitmapInit; bmi = nextBMI(bmi)) {
@@ -459,18 +443,14 @@ static void test_readpixels_texture(skiatest::Reporter* reporter,
// Try doing the read directly from a non-renderable texture
if (startsWithPixels) {
fill_dst_bmp_with_init_data(&bmp);
- GrPixelConfig dstConfig = SkImageInfo2GrPixelConfig(bmp.info(),
- *context->caps());
uint32_t flags = 0;
if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) {
flags = GrContextPriv::kUnpremul_PixelOpsFlag;
}
bmp.lockPixels();
- bool success = context->contextPriv().readSurfacePixels(
- proxy.get(), nullptr,
- srcRect.fLeft, srcRect.fTop, bmp.width(),
- bmp.height(), dstConfig, nullptr,
- bmp.getPixels(), bmp.rowBytes(), flags);
+ bool success = sContext->readPixels(bmp.info(), bmp.getPixels(),
+ bmp.rowBytes(),
+ srcRect.fLeft, srcRect.fTop, flags);
bmp.unlockPixels();
check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop,
success, true,
@@ -480,7 +460,13 @@ static void test_readpixels_texture(skiatest::Reporter* reporter,
}
}
}
+
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
+ GrContext* context = ctxInfo.grContext();
+
+ SkBitmap bmp = make_src_bitmap();
+ bmp.lockPixels();
+
// On the GPU we will also try reading back from a non-renderable texture.
for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) {
@@ -490,12 +476,20 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
desc.fHeight = DEV_H;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
- sk_sp<GrTexture> texture =
- ctxInfo.grContext()->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
- test_readpixels_texture(reporter, ctxInfo.grContext(),
- GrSurfaceProxy::MakeWrapped(std::move(texture)));
+
+ sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+ desc, SkBudgeted::kNo,
+ bmp.getPixels(),
+ bmp.rowBytes());
+
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(proxy), nullptr);
+
+ test_readpixels_texture(reporter, std::move(sContext));
}
}
+
+ bmp.unlockPixels();
}
#endif
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 2a68191a2d..531159ff6f 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -142,13 +142,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
}
}
+ const SkImageInfo dstInfo = SkImageInfo::Make(X_SIZE, Y_SIZE,
+ kAlpha_8_SkColorType,
+ kPremul_SkAlphaType);
+
// Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and
// once with a render target.
- for (auto cfg : kRGBAConfigs) {
+ for (auto config : kRGBAConfigs) {
for (int rt = 0; rt < 2; ++rt) {
GrSurfaceDesc desc;
desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
- desc.fConfig = cfg;
+ desc.fConfig = config;
desc.fWidth = X_SIZE;
desc.fHeight = Y_SIZE;
@@ -170,6 +174,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
continue;
}
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(proxy), nullptr);
+
for (auto rowBytes : kRowBytes) {
size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE;
@@ -178,11 +185,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE);
// read the texture back
- bool result = context->contextPriv().readSurfacePixels(
- proxy.get(), nullptr,
- 0, 0, desc.fWidth, desc.fHeight,
- kAlpha_8_GrPixelConfig, nullptr,
- readback.get(), rowBytes);
+ bool result = sContext->readPixels(dstInfo, readback.get(), rowBytes, 0, 0);
REPORTER_ASSERT_MESSAGE(reporter, result, "8888 readPixels failed");
// make sure the original & read back versions match
diff --git a/tests/VkUploadPixelsTests.cpp b/tests/VkUploadPixelsTests.cpp
index 50fc84fda8..7e8481b7c2 100644
--- a/tests/VkUploadPixelsTests.cpp
+++ b/tests/VkUploadPixelsTests.cpp
@@ -13,7 +13,9 @@
#include "GrContextFactory.h"
#include "GrContextPriv.h"
+#include "GrSurfaceProxy.h"
#include "GrTest.h"
+#include "SkGr.h"
#include "Test.h"
#include "vk/GrVkGpu.h"
@@ -33,7 +35,6 @@ void fill_pixel_data(int width, int height, GrColor* data) {
bool does_full_buffer_contain_correct_color(GrColor* srcBuffer,
GrColor* dstBuffer,
- GrPixelConfig config,
int width,
int height) {
GrColor* srcPtr = srcBuffer;
@@ -83,28 +84,40 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
surfDesc.fHeight = kHeight;
surfDesc.fConfig = config;
surfDesc.fSampleCnt = 0;
- sk_sp<GrTexture> tex0(gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0));
- if (tex0) {
+
+ SkColorType ct;
+ SkAssertResult(GrPixelConfigToColorType(config, &ct));
+
+ sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+ surfDesc, SkBudgeted::kNo,
+ srcBuffer, 0);
+
+ if (proxy) {
REPORTER_ASSERT(reporter, canCreate);
- gpu->readPixels(tex0.get(), 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ proxy, nullptr);
+
+ SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kOpaque_SkAlphaType);
+
+ bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0);
+ REPORTER_ASSERT(reporter, result);
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
dstBuffer,
- config,
kWidth,
kHeight));
- sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex0);
-
- bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
- 2, 10, 10, 2,
- config, nullptr, srcBuffer, 0);
- REPORTER_ASSERT(reporter, success);
+ dstInfo = SkImageInfo::Make(10, 2, ct, kOpaque_SkAlphaType);
+ result = sContext->writePixels(dstInfo, srcBuffer, 0, 2, 10);
+ REPORTER_ASSERT(reporter, result);
memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
- gpu->readPixels(tex0.get(), 2, 10, 10, 2, config, dstBuffer, 0);
+
+ result = sContext->readPixels(dstInfo, dstBuffer, 0, 2, 10);
+ REPORTER_ASSERT(reporter, result);
+
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
dstBuffer,
- config,
10,
2));
} else {
@@ -112,28 +125,36 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
}
surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- sk_sp<GrTexture> tex1(gpu->createTexture(surfDesc, SkBudgeted::kNo, srcBuffer, 0));
- if (tex1) {
+
+ proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+ surfDesc, SkBudgeted::kNo,
+ srcBuffer, 0);
+ if (proxy) {
REPORTER_ASSERT(reporter, canCreate);
- gpu->readPixels(tex1.get(), 0, 0, kWidth, kHeight, config, dstBuffer, 0);
+
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ proxy, nullptr);
+
+ SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kOpaque_SkAlphaType);
+
+ bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0);
+ REPORTER_ASSERT(reporter, result);
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
dstBuffer,
- config,
kWidth,
kHeight));
- sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex1);
-
- bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
- 5, 4, 4, 5, config, nullptr,
- srcBuffer, 0);
- REPORTER_ASSERT(reporter, success);
+ dstInfo = SkImageInfo::Make(4, 5, ct, kOpaque_SkAlphaType);
+ result = sContext->writePixels(dstInfo, srcBuffer, 0, 5, 4);
+ REPORTER_ASSERT(reporter, result);
memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor));
- gpu->readPixels(tex1.get(), 5, 4, 4, 5, config, dstBuffer, 0);
+
+ result = sContext->readPixels(dstInfo, dstBuffer, 0, 5, 4);
+ REPORTER_ASSERT(reporter, result);
+
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer,
dstBuffer,
- config,
4,
5));
@@ -143,10 +164,13 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, GrPixe
}
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkUploadPixelsTests, reporter, ctxInfo) {
+ // RGBA
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_GrPixelConfig, false, false);
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_GrPixelConfig, true, false);
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_GrPixelConfig, false, true);
basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_GrPixelConfig, true, true);
+
+ // BGRA
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_GrPixelConfig, false, false);
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_GrPixelConfig, true, false);
basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_GrPixelConfig, false, true);