skia2/tests/GrTextureMipMapInvalidationTest.cpp
Yuqian Li 9e9188f84b Revert "Remove budgeted parameter from SkSurface::makeImageSnapshot"
This reverts commit b64bcbdc3a.

Reason for revert: 

Android build failed as shown below.

frameworks/base/libs/hwui/VkLayer.cpp:32:41: error: too many arguments to function call, expected 0, have 1
    mImage = surface->makeImageSnapshot(SkBudgeted::kNo);

Original change's description:
> Remove budgeted parameter from SkSurface::makeImageSnapshot
> 
> This unused feature complicates MDB.
> 
> Chrome compiles locally for me with this CL.
> 
> Change-Id: I611e464885fb984030eace43ead42cf39d0e7f72
> Reviewed-on: https://skia-review.googlesource.com/9734
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> 

TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Iae6e313c15b2352bd0d4fc7b5629de0a51ac398e
Reviewed-on: https://skia-review.googlesource.com/9788
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
2017-03-16 15:05:04 +00:00

60 lines
2.1 KiB
C++

/*
* Copyright 2016 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 "GrTexture.h"
#include "GrTexturePriv.h"
#include "SkCanvas.h"
#include "SkImage_Base.h"
#include "SkSurface.h"
#include "Test.h"
// 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();
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, !isMipped(surf1.get()));
// Painting with downscale and medium filter quality should result in mipmap creation
SkPaint paint;
paint.setFilterQuality(kMedium_SkFilterQuality);
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