skia2/tests/RepeatedClippedBlurTest.cpp

117 lines
4.6 KiB
C++
Raw Normal View History

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkImageFilters.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrResourceCache.h"
#include "tests/Test.h"
// This is the repro of a CastOS memory regression bug (b/138674523).
// The test simply keeps calling SkImage::makeWithFilter (with a blur image filter) while
// shrinking the clip.
// When explicit resource allocation was enabled the last (re-expanded) image in the
// blur creation process became exact.
// This meant that its backing texture could no longer be reused.
// In CastOS' case (and, presumably, Linux desktop) they were only using Ganesh for
// 2D canvas and compositor image filtering. In this case Chrome doesn't regularly purge
// the cache. This would result in Ganesh quickly running up to its max cache limit.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) {
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
auto dContext = ctxInfo.directContext();
GrResourceCache* cache = dContext->priv().getResourceCache();
const SkImageInfo ii = SkImageInfo::Make(1024, 600, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
sk_sp<SkSurface> dst(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii));
if (!dst) {
ERRORF(reporter, "Could not create surfaces for repeated clipped blur test.");
return;
}
SkCanvas* dstCanvas = dst->getCanvas();
sk_sp<SkImage> bigImg;
// Create the initial big image (this corresponds to the album artwork - which is larger
// than the screen)
{
SkImageInfo srcImageII = SkImageInfo::Make(1280, 1280, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
// Make a red ring around a field of green. When rendered the blurred red ring
// should still be visible on all sides of the dest image.
SkBitmap bm;
bm.allocPixels(srcImageII);
bm.eraseColor(SK_ColorRED);
bm.eraseArea(SkIRect::MakeXYWH(1, 2, 1277, 1274), SK_ColorGREEN);
sk_sp<SkImage> rasterImg = bm.asImage();
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
bigImg = rasterImg->makeTextureImage(dContext);
}
sk_sp<SkImage> smImg;
// Shrink the album artwork down to the screen's size
{
SkImageInfo screenII = SkImageInfo::Make(1024, 600, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes,
screenII, 1, kTopLeft_GrSurfaceOrigin,
nullptr);
SkCanvas* c = s->getCanvas();
c->drawImageRect(bigImg, SkRect::MakeWH(1024, 600), SkSamplingOptions());
smImg = s->makeImageSnapshot();
}
// flush here just to clear the playing field
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
dContext->flushAndSubmit();
size_t beforeBytes = cache->getResourceBytes();
// Now draw the screen-sized image, blurred, multiple times with a shrinking clip.
// This simulates the swipe away where the screen-sized album artwork is moved off
// screen.
// Note that the blur has to big enough to kick the blur code into the decimate then
// re-expand case.
const SkIRect subset = SkIRect::MakeWH(1024, 600);
SkIRect clip = SkIRect::MakeWH(1024, 600);
for (int i = 0; i < 30; ++i) {
dstCanvas->clear(SK_ColorBLUE);
sk_sp<SkImageFilter> blur = SkImageFilters::Blur(20, 20, nullptr);
SkIRect outSubset;
SkIPoint offset;
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
sk_sp<SkImage> filteredImg = smImg->makeWithFilter(dContext, blur.get(), subset, clip,
&outSubset, &offset);
SkRect dstRect = SkRect::MakeXYWH(offset.fX, offset.fY,
outSubset.width(), outSubset.height());
dstCanvas->drawImageRect(filteredImg, SkRect::Make(outSubset), dstRect, SkSamplingOptions(),
nullptr, SkCanvas::kStrict_SrcRectConstraint);
// Flush here to mimic Chrome's SkiaHelper::ApplyImageFilter
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-07-21 20:50:06 +00:00
dContext->flushAndSubmit();
clip.fRight -= 16;
}
size_t afterBytes = cache->getResourceBytes();
// When the bug manifests the resource cache will accumulate ~80MB. If texture recycling
// is working as expected the cache size will level off at ~20MB.
REPORTER_ASSERT(reporter, afterBytes < beforeBytes + 20000000);
}