aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GrTextureMipMapInvalidationTest.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-07-14 09:24:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-14 09:24:08 -0700
commitb1792f11210f05dfcfd7d5b24bd296b4c95c5cf4 (patch)
treedf02dbf378f843c23588f0a07ca793570e8be6e9 /tests/GrTextureMipMapInvalidationTest.cpp
parentcfc79fe9a3be30b01537214a1d24580951c76c16 (diff)
Rewrite GrTextureMipMapInvalidationTest using SkImage
Diffstat (limited to 'tests/GrTextureMipMapInvalidationTest.cpp')
-rw-r--r--tests/GrTextureMipMapInvalidationTest.cpp67
1 files changed, 31 insertions, 36 deletions
diff --git a/tests/GrTextureMipMapInvalidationTest.cpp b/tests/GrTextureMipMapInvalidationTest.cpp
index 08f23f723c..166c57c066 100644
--- a/tests/GrTextureMipMapInvalidationTest.cpp
+++ b/tests/GrTextureMipMapInvalidationTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Google Inc.
+ * Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
@@ -13,52 +13,47 @@
#include "GrTexture.h"
#include "GrTexturePriv.h"
#include "SkCanvas.h"
-#include "SkGrPriv.h"
+#include "SkImage_Base.h"
#include "SkSurface.h"
#include "Test.h"
-// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
-// and render targets to GrSurface all work as expected.
+// Tests that MIP maps are created and invalidated as expected when drawing to and from GrTextures.
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, ctxInfo) {
+ auto isMipped = [] (SkSurface* surf) {
+ return as_IB(surf->makeImageSnapshot(SkBudgeted::kYes))->
+ peekTexture()->texturePriv().hasMipMaps();
+ };
+
+ auto mipsAreDirty = [] (SkSurface* surf) {
+ return as_IB(surf->makeImageSnapshot(SkBudgeted::kYes))->
+ peekTexture()->texturePriv().mipMapsAreDirty();
+ };
+
GrContext* context = ctxInfo.grContext();
- GrSurfaceDesc desc;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = 256;
- desc.fHeight = 256;
- desc.fSampleCnt = 0;
- GrSurface* texRT1 = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0);
- GrSurface* texRT2 = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0);
- REPORTER_ASSERT(reporter, nullptr != texRT1);
- REPORTER_ASSERT(reporter, nullptr != texRT2);
- GrTexture* tex = texRT1->asTexture();
- REPORTER_ASSERT(reporter, nullptr != tex);
- SkBitmap bitmap;
- GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap);
+ auto info = SkImageInfo::MakeN32Premul(256, 256);
+ auto surf1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
+ auto surf2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);
+ // Draw something just in case we ever had a solid color optimization
+ surf1->getCanvas()->drawCircle(128, 128, 50, SkPaint());
+ surf1->getCanvas()->flush();
// No mipmaps initially
- REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps());
+ REPORTER_ASSERT(reporter, !isMipped(surf1.get()));
// Painting with downscale and medium filter quality should result in mipmap creation
- auto surface = SkSurface::MakeRenderTargetDirect(texRT2->asRenderTarget());
SkPaint paint;
paint.setFilterQuality(kMedium_SkFilterQuality);
- surface->getCanvas()->scale(0.2f, 0.2f);
- surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint);
- context->flush();
-
- REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps());
- REPORTER_ASSERT(reporter, false == tex->texturePriv().mipMapsAreDirty());
-
- // Invalidating the contents of the bitmap should invalidate the mipmap, but not de-allocate
- bitmap.notifyPixelsChanged();
- REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps());
- REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty());
-
- texRT1->unref();
- texRT2->unref();
+ surf2->getCanvas()->scale(0.2f, 0.2f);
+ surf2->getCanvas()->drawImage(surf1->makeImageSnapshot(SkBudgeted::kYes), 0, 0, &paint);
+ surf2->getCanvas()->flush();
+ REPORTER_ASSERT(reporter, isMipped(surf1.get()));
+ REPORTER_ASSERT(reporter, !mipsAreDirty(surf1.get()));
+
+ // Changing the contents of the surface should invalidate the mipmap, but not de-allocate
+ surf1->getCanvas()->drawCircle(128, 128, 100, SkPaint());
+ surf1->getCanvas()->flush();
+ REPORTER_ASSERT(reporter, isMipped(surf1.get()));
+ REPORTER_ASSERT(reporter, mipsAreDirty(surf1.get()));
}
#endif