2015-06-15 16:48:15 +00:00
|
|
|
/*
|
2016-07-14 16:24:08 +00:00
|
|
|
* Copyright 2016 Google Inc.
|
2015-06-15 16:48:15 +00:00
|
|
|
*
|
|
|
|
* 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 "GrTexturePriv.h"
|
|
|
|
#include "SkCanvas.h"
|
2016-07-14 16:24:08 +00:00
|
|
|
#include "SkImage_Base.h"
|
2015-06-15 16:48:15 +00:00
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2016-07-14 16:24:08 +00:00
|
|
|
// Tests that MIP maps are created and invalidated as expected when drawing to and from GrTextures.
|
2016-04-06 21:02:39 +00:00
|
|
|
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, ctxInfo) {
|
2016-07-14 16:24:08 +00:00
|
|
|
auto isMipped = [] (SkSurface* surf) {
|
2017-10-23 20:05:23 +00:00
|
|
|
const GrTexture* texture = surf->makeImageSnapshot()->getTexture();
|
|
|
|
return GrMipMapped::kYes == texture->texturePriv().mipMapped();
|
2016-07-14 16:24:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto mipsAreDirty = [] (SkSurface* surf) {
|
2017-06-23 18:09:30 +00:00
|
|
|
return surf->makeImageSnapshot()->getTexture()->texturePriv().mipMapsAreDirty();
|
2016-07-14 16:24:08 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2016-07-14 16:24:08 +00:00
|
|
|
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();
|
2015-12-01 12:35:26 +00:00
|
|
|
|
|
|
|
// No mipmaps initially
|
2016-07-14 16:24:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, !isMipped(surf1.get()));
|
2015-12-01 12:35:26 +00:00
|
|
|
|
|
|
|
// Painting with downscale and medium filter quality should result in mipmap creation
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kMedium_SkFilterQuality);
|
2016-07-14 16:24:08 +00:00
|
|
|
surf2->getCanvas()->scale(0.2f, 0.2f);
|
2017-03-20 12:38:50 +00:00
|
|
|
surf2->getCanvas()->drawImage(surf1->makeImageSnapshot(), 0, 0, &paint);
|
2016-07-14 16:24:08 +00:00
|
|
|
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()));
|
2015-06-15 16:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|