diff options
author | junov <junov@chromium.org> | 2015-06-15 09:48:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-15 09:48:15 -0700 |
commit | da5469d7bc0dc089d098f5a64a818ed079cc0930 (patch) | |
tree | f60f0e26ae41c98a35b83560e420db3b33692dc1 /tests | |
parent | 27631bd5936e03fcfe854a8aa4e55c8b959a10b3 (diff) |
Invalidate GrTexture mipmap on content change notification
This fix is necessary to correctly propagate invalidations that
are external to skia. For example, when drawing video or WebGL
into a 2D canvas in Chrome, with mipmaps enabled.
BUG=crbug.com/498356
TEST=GrTextureMipMapInvalidationTest
Review URL: https://codereview.chromium.org/1177843007
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GrTextureMipMapInvalidationTest.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/GrTextureMipMapInvalidationTest.cpp b/tests/GrTextureMipMapInvalidationTest.cpp new file mode 100644 index 0000000000..ab5c02ac94 --- /dev/null +++ b/tests/GrTextureMipMapInvalidationTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkTypes.h" + +#if SK_SUPPORT_GPU + +#include "GrContext.h" +#include "GrContextFactory.h" +#include "GrTexture.h" +#include "GrTexturePriv.h" +#include "SkCanvas.h" +#include "SkGr.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. +DEF_GPUTEST(GrTextureMipMapInvalidationTest, reporter, factory) { + GrContext* context = factory->get(GrContextFactory::kNull_GLContextType); + if (context) { + 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, false, NULL, 0); + GrSurface* texRT2 = context->textureProvider()->createTexture(desc, false, NULL, 0); + REPORTER_ASSERT(reporter, NULL != texRT1); + REPORTER_ASSERT(reporter, NULL != texRT2); + GrTexture* tex = texRT1->asTexture(); + REPORTER_ASSERT(reporter, NULL != tex); + SkBitmap bitmap; + GrWrapTextureInBitmap(tex, 256, 256, false, &bitmap); + + // No mipmaps initially + REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); + + // Painting with downscale and medium filter quality should result in mipmap creation + SkSurface* surface = SkSurface::NewRenderTargetDirect(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()); + + surface->unref(); + texRT1->unref(); + texRT2->unref(); + } +} + +#endif |