aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GrSurfaceTest.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-05-23 16:53:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-23 21:38:38 +0000
commitd17b4a678b4b1df49a8eb84fb8c3c954d292a12c (patch)
tree82d59ef35abe6666d01723c62e4f22570b563801 /tests/GrSurfaceTest.cpp
parent0610a462ad2e17057849784cdab73d634bab5fb9 (diff)
Revert "Revert "Add a flag to GrSurfaceFlags that requires the texture to be cleared upon creation. ""
This reverts commit a9e795eab5f59a52d96b8fdc39351452835f5eb9. Bug: skia: Change-Id: Ibfc51497ae99f332f8f72a799393a1b2996f7f3f Reviewed-on: https://skia-review.googlesource.com/17767 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests/GrSurfaceTest.cpp')
-rw-r--r--tests/GrSurfaceTest.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 19f2df50fe..dc265fd359 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -123,4 +123,102 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
}
#endif
+#include "GrDrawingManager.h"
+#include "GrSurfaceProxy.h"
+#include "GrTextureContext.h"
+
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(InitialTextureClear, reporter, context_info) {
+ static constexpr int kSize = 100;
+ GrSurfaceDesc desc;
+ desc.fWidth = desc.fHeight = kSize;
+ std::unique_ptr<uint32_t[]> data(new uint32_t[kSize * kSize]);
+ GrContext* context = context_info.grContext();
+ for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
+ desc.fConfig = static_cast<GrPixelConfig>(c);
+ if (!context_info.grContext()->caps()->isConfigTexturable(desc.fConfig)) {
+ continue;
+ }
+ desc.fFlags = kPerformInitialClear_GrSurfaceFlag;
+ for (bool rt : {false, true}) {
+ if (rt && !context->caps()->isConfigRenderable(desc.fConfig, false)) {
+ continue;
+ }
+ desc.fFlags |= rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ for (bool mipped : {false, true}) {
+ desc.fIsMipMapped = mipped;
+ for (GrSurfaceOrigin origin :
+ {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
+ desc.fOrigin = origin;
+ for (bool approx : {false, true}) {
+ auto resourceProvider = context->resourceProvider();
+ // Try directly creating the texture.
+ // Do this twice in an attempt to hit the cache on the second time through.
+ for (int i = 0; i < 2; ++i) {
+ sk_sp<GrTexture> tex;
+ if (approx) {
+ tex = sk_sp<GrTexture>(
+ resourceProvider->createApproxTexture(desc, 0));
+ } else {
+ tex = resourceProvider->createTexture(desc, SkBudgeted::kYes);
+ }
+ if (!tex) {
+ continue;
+ }
+ auto proxy = GrSurfaceProxy::MakeWrapped(std::move(tex));
+ auto texCtx = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(proxy), nullptr);
+ SkImageInfo info = SkImageInfo::Make(
+ kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
+ if (texCtx->readPixels(info, data.get(), 0, 0, 0)) {
+ uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
+ for (int i = 0; i < kSize * kSize; ++i) {
+ if (cmp != data.get()[i]) {
+ ERRORF(reporter, "Failed on config %d", desc.fConfig);
+ break;
+ }
+ }
+ }
+ memset(data.get(), 0xBC, kSize * kSize * sizeof(uint32_t));
+ // Here we overwrite the texture so that the second time through we
+ // test against recycling without reclearing.
+ if (0 == i) {
+ texCtx->writePixels(info, data.get(), 0, 0, 0);
+ }
+ }
+ context->purgeAllUnlockedResources();
+
+ // Try creating the texture as a deferred proxy.
+ for (int i = 0; i < 2; ++i) {
+ auto surfCtx = context->contextPriv().makeDeferredSurfaceContext(
+ desc, approx ? SkBackingFit::kApprox : SkBackingFit::kExact,
+ SkBudgeted::kYes);
+ if (!surfCtx) {
+ continue;
+ }
+ SkImageInfo info = SkImageInfo::Make(
+ kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
+ if (surfCtx->readPixels(info, data.get(), 0, 0, 0)) {
+ uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
+ for (int i = 0; i < kSize * kSize; ++i) {
+ if (cmp != data.get()[i]) {
+ ERRORF(reporter, "Failed on config %d", desc.fConfig);
+ break;
+ }
+ }
+ }
+ // Here we overwrite the texture so that the second time through we
+ // test against recycling without reclearing.
+ if (0 == i) {
+ surfCtx->writePixels(info, data.get(), 0, 0, 0);
+ }
+ }
+ context->purgeAllUnlockedResources();
+ }
+ }
+ }
+ }
+ }
+}
#endif