2013-08-08 22:55:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2015-04-08 18:01:54 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrGpuResourceCacheAccess.h"
|
|
|
|
#include "src/gpu/GrGpuResourcePriv.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRenderTargetPriv.h"
|
|
|
|
#include "src/gpu/GrResourceCache.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-15 14:15:52 +00:00
|
|
|
#include "src/core/SkMessageBus.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkMipMap.h"
|
|
|
|
#include "src/gpu/SkGr.h"
|
|
|
|
#include "tests/Test.h"
|
2013-08-08 22:55:21 +00:00
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2013-08-08 22:55:21 +00:00
|
|
|
static const int gWidth = 640;
|
|
|
|
static const int gHeight = 480;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2015-12-01 12:35:26 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
|
2015-12-01 12:35:26 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
2013-08-08 22:55:21 +00:00
|
|
|
const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
|
|
|
|
|
|
|
|
SkBitmap src;
|
2014-02-13 14:41:43 +00:00
|
|
|
src.allocN32Pixels(size.width(), size.height());
|
2013-08-08 22:55:21 +00:00
|
|
|
src.eraseColor(SK_ColorBLACK);
|
2017-10-03 18:47:21 +00:00
|
|
|
size_t srcSize = src.computeByteSize();
|
2013-08-08 22:55:21 +00:00
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
size_t initialCacheSize;
|
2015-08-27 14:41:13 +00:00
|
|
|
context->getResourceCacheUsage(nullptr, &initialCacheSize);
|
2013-08-08 22:55:21 +00:00
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t oldMaxBytes = context->getResourceCacheLimit();
|
2013-08-09 07:01:22 +00:00
|
|
|
|
2013-08-08 22:55:21 +00:00
|
|
|
// Set the cache limits so we can fit 10 "src" images and the
|
|
|
|
// max number of textures doesn't matter
|
|
|
|
size_t maxCacheSize = initialCacheSize + 10*srcSize;
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(maxCacheSize);
|
2013-08-08 22:55:21 +00:00
|
|
|
|
|
|
|
SkBitmap readback;
|
2014-02-13 14:41:43 +00:00
|
|
|
readback.allocN32Pixels(size.width(), size.height());
|
2013-08-08 22:55:21 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
canvas->drawBitmap(src, 0, 0);
|
2017-07-21 18:24:29 +00:00
|
|
|
surface->readPixels(readback, 0, 0);
|
2013-08-08 22:55:21 +00:00
|
|
|
|
|
|
|
// "modify" the src texture
|
|
|
|
src.notifyPixelsChanged();
|
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
size_t curCacheSize;
|
2015-08-27 14:41:13 +00:00
|
|
|
context->getResourceCacheUsage(nullptr, &curCacheSize);
|
2013-08-08 22:55:21 +00:00
|
|
|
|
|
|
|
// we should never go over the size limit
|
|
|
|
REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(oldMaxBytes);
|
2013-08-08 22:55:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 15:13:48 +00:00
|
|
|
static bool is_rendering_and_not_angle_es3(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
if (type == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES3_ContextType ||
|
|
|
|
type == sk_gpu_test::GrContextFactory::kANGLE_GL_ES3_ContextType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return sk_gpu_test::GrContextFactory::IsRenderingContext(type);
|
|
|
|
}
|
|
|
|
|
2017-09-21 16:00:26 +00:00
|
|
|
static GrStencilAttachment* get_SB(GrRenderTarget* rt) {
|
|
|
|
return rt->renderTargetPriv().getStencilAttachment();
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<GrRenderTarget> create_RT_with_SB(GrResourceProvider* provider,
|
|
|
|
int size, int sampleCount, SkBudgeted budgeted) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = size;
|
|
|
|
desc.fHeight = size;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
auto format =
|
|
|
|
provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes);
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, format, GrRenderable::kYes, sampleCount,
|
2019-09-17 13:01:56 +00:00
|
|
|
GrMipMapped::kNo, budgeted, GrProtected::kNo));
|
2017-09-21 16:00:26 +00:00
|
|
|
if (!tex || !tex->asRenderTarget()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:28:03 +00:00
|
|
|
if (!provider->attachStencilAttachment(tex->asRenderTarget(), sampleCount)) {
|
2017-09-21 16:00:26 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SkASSERT(get_SB(tex->asRenderTarget()));
|
|
|
|
|
|
|
|
return sk_ref_sp(tex->asRenderTarget());
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:13:48 +00:00
|
|
|
// This currently fails on ES3 ANGLE contexts
|
|
|
|
DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angle_es3, reporter,
|
2017-10-30 18:02:48 +00:00
|
|
|
ctxInfo, nullptr) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-06-24 17:25:42 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
|
|
|
if (caps->avoidStencilBuffers()) {
|
2017-05-08 19:02:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-23 17:06:38 +00:00
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
2017-09-21 16:00:26 +00:00
|
|
|
|
2019-07-09 18:06:58 +00:00
|
|
|
GrColorType grColorType = GrColorType::kRGBA_8888;
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, GrRenderable::kYes);
|
2019-06-24 17:25:42 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
sk_sp<GrRenderTarget> smallRT0 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kYes);
|
2017-09-21 16:00:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, smallRT0);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Two budgeted RTs with the same desc should share a stencil buffer.
|
2018-02-03 01:32:49 +00:00
|
|
|
sk_sp<GrRenderTarget> smallRT1 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kYes);
|
|
|
|
REPORTER_ASSERT(reporter, smallRT1);
|
2017-09-21 16:00:26 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT1.get()));
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 16:00:26 +00:00
|
|
|
{
|
|
|
|
// An unbudgeted RT with the same desc should also share.
|
2018-02-03 01:32:49 +00:00
|
|
|
sk_sp<GrRenderTarget> smallRT2 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kNo);
|
2017-09-21 16:00:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, smallRT2);
|
2015-02-19 17:09:00 +00:00
|
|
|
|
2017-09-21 16:00:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT2.get()));
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
2017-09-21 16:00:26 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// An RT with a much larger size should not share.
|
2018-02-03 01:32:49 +00:00
|
|
|
sk_sp<GrRenderTarget> bigRT = create_RT_with_SB(resourceProvider, 400, 1, SkBudgeted::kNo);
|
2017-09-21 16:00:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, bigRT);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(bigRT.get()));
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
2017-09-21 16:00:26 +00:00
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
int smallSampleCount =
|
2019-08-07 19:52:37 +00:00
|
|
|
context->priv().caps()->getRenderTargetSampleCount(2, format);
|
2018-02-03 01:32:49 +00:00
|
|
|
if (smallSampleCount > 1) {
|
2016-03-16 17:28:35 +00:00
|
|
|
// An RT with a different sample count should not share.
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrRenderTarget> smallMSAART0 = create_RT_with_SB(resourceProvider, 4,
|
|
|
|
smallSampleCount, SkBudgeted::kNo);
|
2017-09-21 16:00:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, smallMSAART0);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(smallMSAART0.get()));
|
|
|
|
|
|
|
|
{
|
|
|
|
// A second MSAA RT should share with the first MSAA RT.
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrRenderTarget> smallMSAART1 = create_RT_with_SB(resourceProvider, 4,
|
|
|
|
smallSampleCount,
|
2017-09-21 16:00:26 +00:00
|
|
|
SkBudgeted::kNo);
|
|
|
|
REPORTER_ASSERT(reporter, smallMSAART1);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) == get_SB(smallMSAART1.get()));
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
2017-09-21 16:00:26 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
// But one with a larger sample count should not. (Also check that the two requests didn't
|
|
|
|
// rounded up to the same actual sample count or else they could share.).
|
2019-08-07 19:52:37 +00:00
|
|
|
int bigSampleCount = context->priv().caps()->getRenderTargetSampleCount(5, format);
|
2018-02-03 01:32:49 +00:00
|
|
|
if (bigSampleCount > 0 && bigSampleCount != smallSampleCount) {
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrRenderTarget> smallMSAART2 = create_RT_with_SB(resourceProvider, 4,
|
|
|
|
bigSampleCount,
|
2017-09-21 16:00:26 +00:00
|
|
|
SkBudgeted::kNo);
|
|
|
|
REPORTER_ASSERT(reporter, smallMSAART2);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) != get_SB(smallMSAART2.get()));
|
2015-02-19 17:09:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2015-07-15 17:16:56 +00:00
|
|
|
// this test is only valid for GL
|
|
|
|
if (!gpu || !gpu->glContextForTesting()) {
|
2015-06-18 16:12:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backendTextures[2];
|
2015-06-18 16:12:16 +00:00
|
|
|
static const int kW = 100;
|
|
|
|
static const int kH = 100;
|
2015-07-13 14:19:57 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
backendTextures[0] = context->createBackendTexture(kW, kH, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrMipMapped::kNo, GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
2019-06-04 15:03:06 +00:00
|
|
|
backendTextures[1] = context->createBackendTexture(kW, kH, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrMipMapped::kNo, GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
2018-01-10 14:57:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTextures[0].isValid());
|
|
|
|
REPORTER_ASSERT(reporter, backendTextures[1].isValid());
|
|
|
|
if (!backendTextures[0].isValid() || !backendTextures[1].isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-13 14:19:57 +00:00
|
|
|
|
2015-06-18 16:12:16 +00:00
|
|
|
context->resetContext();
|
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture(
|
2019-07-23 14:27:09 +00:00
|
|
|
backendTextures[0], GrColorType::kRGBA_8888,
|
|
|
|
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
|
2017-12-12 18:01:25 +00:00
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture(
|
2019-07-23 14:27:09 +00:00
|
|
|
backendTextures[1], GrColorType::kRGBA_8888,
|
|
|
|
kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2017-05-10 16:06:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr);
|
|
|
|
if (!borrowed || !adopted) {
|
2015-06-18 16:12:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
borrowed.reset(nullptr);
|
|
|
|
adopted.reset(nullptr);
|
2015-06-18 16:12:16 +00:00
|
|
|
|
|
|
|
context->flush();
|
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[0]);
|
|
|
|
bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[1]);
|
2015-06-18 16:12:16 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, borrowedIsAlive);
|
|
|
|
REPORTER_ASSERT(reporter, !adoptedIsAlive);
|
|
|
|
|
2018-03-07 16:47:54 +00:00
|
|
|
if (borrowedIsAlive) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTextures[0]);
|
2018-03-07 16:47:54 +00:00
|
|
|
}
|
|
|
|
if (adoptedIsAlive) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTextures[1]);
|
2018-03-07 16:47:54 +00:00
|
|
|
}
|
2015-06-18 16:12:16 +00:00
|
|
|
|
|
|
|
context->resetContext();
|
|
|
|
}
|
|
|
|
|
2014-07-25 15:35:45 +00:00
|
|
|
class TestResource : public GrGpuResource {
|
2015-01-21 17:32:40 +00:00
|
|
|
enum ScratchConstructor { kScratchConstructor };
|
2014-01-15 23:09:01 +00:00
|
|
|
public:
|
2015-08-13 12:19:14 +00:00
|
|
|
static const size_t kDefaultSize = 100;
|
2016-03-16 17:28:35 +00:00
|
|
|
|
2015-01-21 17:32:40 +00:00
|
|
|
/** Property that distinctly categorizes the resource.
|
|
|
|
* For example, textures have width, height, ... */
|
2015-02-06 19:54:28 +00:00
|
|
|
enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
|
2015-01-21 17:32:40 +00:00
|
|
|
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
TestResource(GrGpu* gpu, SkBudgeted budgeted = SkBudgeted::kYes, size_t size = kDefaultSize)
|
|
|
|
: INHERITED(gpu)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fToDelete(nullptr)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fSize(size)
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
, fProperty(kA_SimulatedProperty)
|
|
|
|
, fIsScratch(false) {
|
2015-01-14 18:42:08 +00:00
|
|
|
++fNumAlive;
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
this->registerWithCache(budgeted);
|
2015-01-14 18:42:08 +00:00
|
|
|
}
|
|
|
|
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted,
|
2018-06-13 13:41:19 +00:00
|
|
|
SimulatedProperty property, size_t size = kDefaultSize) {
|
|
|
|
return new TestResource(gpu, budgeted, property, kScratchConstructor, size);
|
2014-11-10 18:19:06 +00:00
|
|
|
}
|
2019-01-24 21:03:07 +00:00
|
|
|
static TestResource* CreateWrapped(GrGpu* gpu, GrWrapCacheable cacheable,
|
|
|
|
size_t size = kDefaultSize) {
|
|
|
|
return new TestResource(gpu, cacheable, size);
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~TestResource() override {
|
2014-11-05 22:47:41 +00:00
|
|
|
--fNumAlive;
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 22:47:41 +00:00
|
|
|
static int NumAlive() { return fNumAlive; }
|
2014-01-15 23:09:01 +00:00
|
|
|
|
2018-07-11 18:56:22 +00:00
|
|
|
void setUnrefWhenDestroyed(sk_sp<TestResource> resource) {
|
|
|
|
fToDelete = std::move(resource);
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 17:32:40 +00:00
|
|
|
static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) {
|
|
|
|
static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType();
|
|
|
|
GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt);
|
2015-01-23 12:24:04 +00:00
|
|
|
for (int i = 0; i < kScratchKeyFieldCnt; ++i) {
|
|
|
|
builder[i] = static_cast<uint32_t>(i + property);
|
2015-01-21 17:32:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ExpectedScratchKeySize() {
|
|
|
|
return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt);
|
|
|
|
}
|
2014-01-15 23:09:01 +00:00
|
|
|
private:
|
2015-01-23 12:24:04 +00:00
|
|
|
static const int kScratchKeyFieldCnt = 6;
|
2015-01-21 17:32:40 +00:00
|
|
|
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor,
|
|
|
|
size_t size = kDefaultSize)
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
: INHERITED(gpu)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fToDelete(nullptr)
|
2018-06-13 13:41:19 +00:00
|
|
|
, fSize(size)
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
, fProperty(property)
|
|
|
|
, fIsScratch(true) {
|
2015-01-21 17:32:40 +00:00
|
|
|
++fNumAlive;
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
this->registerWithCache(budgeted);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for simulating resources that wrap backend objects.
|
2019-01-24 21:03:07 +00:00
|
|
|
TestResource(GrGpu* gpu, GrWrapCacheable cacheable, size_t size)
|
|
|
|
: INHERITED(gpu)
|
|
|
|
, fToDelete(nullptr)
|
|
|
|
, fSize(size)
|
|
|
|
, fProperty(kA_SimulatedProperty)
|
|
|
|
, fIsScratch(false) {
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
++fNumAlive;
|
2019-01-24 21:03:07 +00:00
|
|
|
this->registerWithCacheWrapped(cacheable);
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void computeScratchKey(GrScratchKey* key) const override {
|
|
|
|
if (fIsScratch) {
|
|
|
|
ComputeScratchKey(fProperty, key);
|
|
|
|
}
|
2015-01-21 17:32:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
size_t onGpuMemorySize() const override { return fSize; }
|
2018-03-29 17:40:02 +00:00
|
|
|
const char* getResourceType() const override { return "Test"; }
|
2014-11-12 19:13:39 +00:00
|
|
|
|
2018-07-11 18:56:22 +00:00
|
|
|
sk_sp<TestResource> fToDelete;
|
2014-05-05 19:09:13 +00:00
|
|
|
size_t fSize;
|
2014-11-05 22:47:41 +00:00
|
|
|
static int fNumAlive;
|
2015-01-21 17:32:40 +00:00
|
|
|
SimulatedProperty fProperty;
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
bool fIsScratch;
|
2014-07-25 15:35:45 +00:00
|
|
|
typedef GrGpuResource INHERITED;
|
2014-01-15 23:09:01 +00:00
|
|
|
};
|
2014-11-05 22:47:41 +00:00
|
|
|
int TestResource::fNumAlive = 0;
|
2014-01-15 23:09:01 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
class Mock {
|
|
|
|
public:
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock(size_t maxBytes) {
|
2017-07-25 14:05:01 +00:00
|
|
|
fContext = GrContext::MakeMock(nullptr);
|
2015-01-23 15:19:22 +00:00
|
|
|
SkASSERT(fContext);
|
2019-09-03 14:29:20 +00:00
|
|
|
fContext->setResourceCacheLimit(maxBytes);
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceCache* cache = fContext->priv().getResourceCache();
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
}
|
2015-01-23 15:19:22 +00:00
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceCache* cache() { return fContext->priv().getResourceCache(); }
|
2015-01-23 15:19:22 +00:00
|
|
|
|
2016-11-04 15:49:42 +00:00
|
|
|
GrContext* context() { return fContext.get(); }
|
2015-01-23 15:19:22 +00:00
|
|
|
|
2018-08-10 13:48:08 +00:00
|
|
|
void reset() {
|
|
|
|
fContext.reset();
|
|
|
|
}
|
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
private:
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrContext> fContext;
|
2015-01-23 15:19:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void test_no_key(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
// Create a bunch of resources with no keys
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11);
|
|
|
|
TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12);
|
|
|
|
TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13 );
|
|
|
|
TestResource* d = new TestResource(gpu, SkBudgeted::kYes, 14 );
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() +
|
2015-02-11 18:49:59 +00:00
|
|
|
d->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
// Should be safe to purge without deleting the resources since we still have refs.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
|
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
// Since the resources have neither unique nor scratch keys, delete immediately upon unref.
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
a->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
c->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
d->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
b->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 12:24:04 +00:00
|
|
|
// Each integer passed as a template param creates a new domain.
|
2017-01-06 17:04:19 +00:00
|
|
|
template <int>
|
|
|
|
static void make_unique_key(GrUniqueKey* key, int data, const char* tag = nullptr) {
|
2015-02-19 15:24:21 +00:00
|
|
|
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
|
2017-01-06 17:04:19 +00:00
|
|
|
GrUniqueKey::Builder builder(key, d, 1, tag);
|
2015-01-23 12:24:04 +00:00
|
|
|
builder[0] = data;
|
|
|
|
}
|
|
|
|
|
2018-03-28 16:25:42 +00:00
|
|
|
static void test_purge_unlocked(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2018-03-28 16:25:42 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2018-03-28 16:25:42 +00:00
|
|
|
|
|
|
|
// Create two resource w/ a unique key and two w/o but all of which have scratch keys.
|
|
|
|
TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kA_SimulatedProperty, 11);
|
2018-03-28 16:25:42 +00:00
|
|
|
|
|
|
|
GrUniqueKey uniqueKey;
|
|
|
|
make_unique_key<0>(&uniqueKey, 0);
|
|
|
|
|
|
|
|
TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kA_SimulatedProperty, 12);
|
2018-03-28 16:25:42 +00:00
|
|
|
b->resourcePriv().setUniqueKey(uniqueKey);
|
|
|
|
|
|
|
|
TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kA_SimulatedProperty, 13);
|
2018-03-28 16:25:42 +00:00
|
|
|
|
|
|
|
GrUniqueKey uniqueKey2;
|
|
|
|
make_unique_key<0>(&uniqueKey2, 1);
|
|
|
|
|
|
|
|
TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kA_SimulatedProperty, 14);
|
2018-03-28 16:25:42 +00:00
|
|
|
d->resourcePriv().setUniqueKey(uniqueKey2);
|
|
|
|
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
|
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() +
|
|
|
|
d->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
|
|
|
|
// Should be safe to purge without deleting the resources since we still have refs.
|
|
|
|
cache->purgeUnlockedResources(false);
|
|
|
|
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// Unref them all. Since they all have keys they should remain in the cache.
|
|
|
|
|
|
|
|
a->unref();
|
|
|
|
b->unref();
|
|
|
|
c->unref();
|
|
|
|
d->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
|
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() +
|
|
|
|
d->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
|
|
|
|
// Purge only the two scratch resources
|
|
|
|
cache->purgeUnlockedResources(true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
|
|
|
|
|
|
|
// Purge the uniquely keyed resources
|
|
|
|
cache->purgeUnlockedResources(false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
|
|
|
}
|
|
|
|
|
2014-11-17 17:33:27 +00:00
|
|
|
static void test_budgeting(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(300);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey uniqueKey;
|
|
|
|
make_unique_key<0>(&uniqueKey, 0);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
// Create a scratch, a unique, and a wrapped resource
|
2015-01-21 17:32:40 +00:00
|
|
|
TestResource* scratch =
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty,
|
|
|
|
10);
|
|
|
|
TestResource* unique = new TestResource(gpu, SkBudgeted::kYes, 11);
|
2015-02-19 16:24:16 +00:00
|
|
|
unique->resourcePriv().setUniqueKey(uniqueKey);
|
2019-01-24 21:03:07 +00:00
|
|
|
TestResource* wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, 12);
|
|
|
|
TestResource* wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo, 13);
|
|
|
|
TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 14);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
// Make sure we can add a unique key to the wrapped resources
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey uniqueKey2;
|
|
|
|
make_unique_key<0>(&uniqueKey2, 1);
|
2019-01-24 21:03:07 +00:00
|
|
|
GrUniqueKey uniqueKey3;
|
|
|
|
make_unique_key<0>(&uniqueKey3, 2);
|
|
|
|
wrappedCacheable->resourcePriv().setUniqueKey(uniqueKey2);
|
|
|
|
wrappedUncacheable->resourcePriv().setUniqueKey(uniqueKey3);
|
|
|
|
GrGpuResource* wrappedCacheableViaKey = cache->findAndRefUniqueResource(uniqueKey2);
|
|
|
|
REPORTER_ASSERT(reporter, wrappedCacheableViaKey);
|
|
|
|
GrGpuResource* wrappedUncacheableViaKey = cache->findAndRefUniqueResource(uniqueKey3);
|
|
|
|
REPORTER_ASSERT(reporter, wrappedUncacheableViaKey);
|
|
|
|
|
|
|
|
// Remove the extra refs we just added.
|
|
|
|
SkSafeUnref(wrappedCacheableViaKey);
|
|
|
|
SkSafeUnref(wrappedUncacheableViaKey);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
// Make sure sizes are as we expect
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, 5 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2019-01-24 21:03:07 +00:00
|
|
|
wrappedCacheable->gpuMemorySize() +
|
|
|
|
wrappedUncacheable->gpuMemorySize() +
|
|
|
|
unbudgeted->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2015-01-23 20:47:59 +00:00
|
|
|
// Our refs mean that the resources are non purgeable.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, 5 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2019-01-24 21:03:07 +00:00
|
|
|
wrappedCacheable->gpuMemorySize() +
|
|
|
|
wrappedUncacheable->gpuMemorySize() +
|
|
|
|
unbudgeted->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
// Unreffing the cacheable wrapped resource with a unique key shouldn't free it right away.
|
|
|
|
// However, unreffing the uncacheable wrapped resource should free it.
|
|
|
|
wrappedCacheable->unref();
|
|
|
|
wrappedUncacheable->unref();
|
2018-09-10 18:10:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2019-01-24 21:03:07 +00:00
|
|
|
wrappedCacheable->gpuMemorySize() +
|
|
|
|
unbudgeted->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2014-11-17 17:33:27 +00:00
|
|
|
// Now try freeing the budgeted resources first
|
2019-01-24 21:03:07 +00:00
|
|
|
wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo);
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->unref();
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes());
|
|
|
|
// This will free 'unique' but not wrappedCacheable which has a key. That requires the key to be
|
|
|
|
// removed to be freed.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
2019-01-24 17:18:33 +00:00
|
|
|
|
|
|
|
wrappedCacheableViaKey = cache->findAndRefUniqueResource(uniqueKey2);
|
|
|
|
REPORTER_ASSERT(reporter, wrappedCacheableViaKey);
|
|
|
|
if (wrappedCacheableViaKey) {
|
|
|
|
wrappedCacheableViaKey->resourcePriv().removeUniqueKey();
|
|
|
|
wrappedCacheable->unref();
|
|
|
|
}
|
|
|
|
// We shouldn't have to call purgeAllUnlocked as removing the key on a wrapped cacheable
|
|
|
|
// resource should immediately delete it.
|
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
|
|
|
|
|
|
|
wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes);
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrappedCacheable->gpuMemorySize() +
|
|
|
|
wrappedUncacheable->gpuMemorySize() +
|
|
|
|
unbudgeted->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
scratch->unref();
|
2018-06-13 13:41:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrappedCacheable->gpuMemorySize() +
|
|
|
|
wrappedUncacheable->gpuMemorySize() ==
|
|
|
|
cache->getResourceBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
// Unreffing the wrapped resources (with no unique key) should free them right away.
|
|
|
|
wrappedUncacheable->unref();
|
|
|
|
wrappedCacheable->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 17:33:27 +00:00
|
|
|
|
|
|
|
unbudgeted->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2014-11-17 15:34:06 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
static void test_unbudgeted(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey uniqueKey;
|
|
|
|
make_unique_key<0>(&uniqueKey, 0);
|
2015-01-14 18:42:08 +00:00
|
|
|
|
|
|
|
TestResource* scratch;
|
2015-02-19 15:24:21 +00:00
|
|
|
TestResource* unique;
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* wrapped;
|
|
|
|
TestResource* unbudgeted;
|
|
|
|
|
|
|
|
// A large uncached or wrapped resource shouldn't evict anything.
|
2018-01-22 15:48:15 +00:00
|
|
|
scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kB_SimulatedProperty, 10);
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
scratch->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2018-06-13 13:41:19 +00:00
|
|
|
unique = new TestResource(gpu, SkBudgeted::kYes, 11);
|
2015-02-19 16:24:16 +00:00
|
|
|
unique->resourcePriv().setUniqueKey(uniqueKey);
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
size_t large = 2 * cache->getResourceBytes();
|
2018-01-22 15:48:15 +00:00
|
|
|
unbudgeted = new TestResource(gpu, SkBudgeted::kNo, large);
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
|
|
|
unbudgeted->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
wrapped = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, large);
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
|
|
|
wrapped->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
|
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2015-01-14 18:42:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 22:20:05 +00:00
|
|
|
// This method can't be static because it needs to friended in GrGpuResource::CacheAccess.
|
|
|
|
void test_unbudgeted_to_scratch(skiatest::Reporter* reporter);
|
|
|
|
/*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(300);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
TestResource* resource =
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrScratchKey key;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
size_t size = resource->gpuMemorySize();
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
// Since this resource is unbudgeted, it should not be reachable as scratch.
|
2015-02-13 22:20:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
|
2019-01-24 21:03:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrBudgetedType::kUnbudgetedUncacheable ==
|
2019-01-24 20:58:58 +00:00
|
|
|
resource->resourcePriv().budgetedType());
|
2019-09-06 15:48:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(key));
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
// Once it is unrefed, it should become available as scratch.
|
|
|
|
resource->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, size == cache->getPurgeableBytes());
|
2019-09-06 15:48:27 +00:00
|
|
|
resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key));
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, resource);
|
2015-02-13 22:20:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
|
2019-01-24 20:58:58 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType());
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
if (0 == i) {
|
2016-03-16 17:28:35 +00:00
|
|
|
// If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try
|
2015-01-23 15:19:22 +00:00
|
|
|
// the above tests again.
|
2015-02-13 22:20:05 +00:00
|
|
|
resource->resourcePriv().makeUnbudgeted();
|
2015-01-23 15:19:22 +00:00
|
|
|
} else {
|
|
|
|
// After the second time around, try removing the scratch key
|
2015-02-13 22:20:05 +00:00
|
|
|
resource->resourcePriv().removeScratchKey();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2015-02-13 22:20:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid());
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
|
2019-01-24 20:58:58 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType());
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
// now when it is unrefed it should die since it has no key.
|
|
|
|
resource->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
2015-01-23 15:19:22 +00:00
|
|
|
}
|
2014-11-10 18:19:06 +00:00
|
|
|
}
|
2015-01-23 15:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(gpu,
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kB_SimulatedProperty, 11);
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* b = TestResource::CreateScratch(gpu,
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kB_SimulatedProperty, 12);
|
2015-01-21 17:32:40 +00:00
|
|
|
GrScratchKey scratchKey1;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
|
2015-01-21 17:32:40 +00:00
|
|
|
// Check for negative case consistency. (leaks upon test failure.)
|
2019-09-06 15:48:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey1));
|
2015-01-21 17:32:40 +00:00
|
|
|
|
|
|
|
GrScratchKey scratchKey;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
|
2015-01-21 17:32:40 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
// Scratch resources are registered with GrResourceCache just by existing. There are 2.
|
2014-11-14 14:47:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-01-23 20:47:59 +00:00
|
|
|
// Our refs mean that the resources are non purgeable.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Unref but don't purge
|
|
|
|
a->unref();
|
|
|
|
b->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));)
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-01-23 20:47:59 +00:00
|
|
|
// Purge again. This time resources should be purgeable.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
|
2014-11-10 18:19:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
static void test_remove_scratch_key(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
2014-11-25 13:52:06 +00:00
|
|
|
a->unref();
|
|
|
|
b->unref();
|
|
|
|
|
2015-01-21 17:32:40 +00:00
|
|
|
GrScratchKey scratchKey;
|
|
|
|
// Ensure that scratch key lookup is correct for negative case.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
|
2015-01-21 17:32:40 +00:00
|
|
|
// (following leaks upon test failure).
|
2019-09-06 15:48:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey));
|
2015-01-21 17:32:40 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
// Scratch resources are registered with GrResourceCache just by existing. There are 2.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
|
2014-11-25 13:52:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// Find the first resource and remove its scratch key
|
2019-09-06 15:48:27 +00:00
|
|
|
GrGpuResource* find = cache->findAndRefScratchResource(scratchKey);
|
2015-02-13 22:20:05 +00:00
|
|
|
find->resourcePriv().removeScratchKey();
|
2014-11-25 13:52:06 +00:00
|
|
|
// It's still alive, but not cached by scratch key anymore
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// The cache should immediately delete it when it's unrefed since it isn't accessible.
|
|
|
|
find->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// Repeat for the second resource.
|
2019-09-06 15:48:27 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey);
|
2015-02-13 22:20:05 +00:00
|
|
|
find->resourcePriv().removeScratchKey();
|
2014-11-25 13:52:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// Should be able to call this multiple times with no problem.
|
2015-02-13 22:20:05 +00:00
|
|
|
find->resourcePriv().removeScratchKey();
|
2014-11-25 13:52:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
find->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
2014-11-25 13:52:06 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 17:32:40 +00:00
|
|
|
static void test_scratch_key_consistency(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2015-01-21 17:32:40 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
2015-01-21 17:32:40 +00:00
|
|
|
a->unref();
|
|
|
|
b->unref();
|
|
|
|
|
|
|
|
GrScratchKey scratchKey;
|
|
|
|
// Ensure that scratch key comparison and assignment is consistent.
|
|
|
|
GrScratchKey scratchKey1;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
|
2015-01-21 17:32:40 +00:00
|
|
|
GrScratchKey scratchKey2;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize());
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey2 != scratchKey1);
|
|
|
|
scratchKey = scratchKey1;
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize());
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey1 == scratchKey);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey == scratchKey1);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey2 != scratchKey);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey != scratchKey2);
|
|
|
|
scratchKey = scratchKey2;
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize());
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey1 != scratchKey);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey != scratchKey1);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey2 == scratchKey);
|
|
|
|
REPORTER_ASSERT(reporter, scratchKey == scratchKey2);
|
|
|
|
|
|
|
|
// Ensure that scratch key lookup is correct for negative case.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
|
2015-01-21 17:32:40 +00:00
|
|
|
// (following leaks upon test failure).
|
2019-09-06 15:48:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey));
|
2015-01-21 17:32:40 +00:00
|
|
|
|
|
|
|
// Find the first resource with a scratch key and a copy of a scratch key.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
|
2019-09-06 15:48:27 +00:00
|
|
|
GrGpuResource* find = cache->findAndRefScratchResource(scratchKey);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, find != nullptr);
|
2015-01-21 17:32:40 +00:00
|
|
|
find->unref();
|
|
|
|
|
|
|
|
scratchKey2 = scratchKey;
|
2019-09-06 15:48:27 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey2);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, find != nullptr);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, find == a || find == b);
|
|
|
|
|
2019-09-06 15:48:27 +00:00
|
|
|
GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, find2 != nullptr);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, find2 == a || find2 == b);
|
|
|
|
REPORTER_ASSERT(reporter, find2 != find);
|
|
|
|
find2->unref();
|
|
|
|
find->unref();
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key;
|
|
|
|
make_unique_key<0>(&key, 0);
|
2016-03-16 17:28:35 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
// Create two resources that we will attempt to register with the same unique key.
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11);
|
2016-03-16 17:28:35 +00:00
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
// Set key on resource a.
|
|
|
|
a->resourcePriv().setUniqueKey(key);
|
|
|
|
REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key));
|
|
|
|
a->unref();
|
|
|
|
|
|
|
|
// Make sure that redundantly setting a's key works.
|
|
|
|
a->resourcePriv().setUniqueKey(key);
|
|
|
|
REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key));
|
|
|
|
a->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// Create resource b and set the same key. It should replace a's unique key cache entry.
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12);
|
2015-02-19 16:24:16 +00:00
|
|
|
b->resourcePriv().setUniqueKey(key);
|
|
|
|
REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key));
|
|
|
|
b->unref();
|
2014-11-14 20:10:14 +00:00
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
// Still have two resources because a is still reffed.
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2015-02-19 16:24:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
a->unref();
|
|
|
|
// Now a should be gone.
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// Now replace b with c, but make sure c can start with one unique key and change it to b's key.
|
|
|
|
// Also make b be unreffed when replacement occurs.
|
2014-11-10 18:19:06 +00:00
|
|
|
b->unref();
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13);
|
2015-02-19 16:24:16 +00:00
|
|
|
GrUniqueKey differentKey;
|
|
|
|
make_unique_key<0>(&differentKey, 1);
|
|
|
|
c->resourcePriv().setUniqueKey(differentKey);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
// c replaces b and b should be immediately purged.
|
|
|
|
c->resourcePriv().setUniqueKey(key);
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2015-02-19 16:24:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
// c shouldn't be purged because it is ref'ed.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2015-02-19 16:24:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
// Drop the ref on c, it should be kept alive because it has a unique key.
|
|
|
|
c->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2015-02-19 16:24:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2015-02-19 16:24:16 +00:00
|
|
|
// Verify that we can find c, then remove its unique key. It should get purged immediately.
|
|
|
|
REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key));
|
|
|
|
c->resourcePriv().removeUniqueKey();
|
|
|
|
c->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-08-04 17:01:58 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GrUniqueKey key2;
|
|
|
|
make_unique_key<0>(&key2, 0);
|
2018-01-22 15:48:15 +00:00
|
|
|
sk_sp<TestResource> d(new TestResource(gpu));
|
2015-08-04 17:01:58 +00:00
|
|
|
int foo = 4132;
|
2016-08-02 21:40:46 +00:00
|
|
|
key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo)));
|
2015-08-04 17:01:58 +00:00
|
|
|
d->resourcePriv().setUniqueKey(key2);
|
|
|
|
}
|
|
|
|
|
|
|
|
GrUniqueKey key3;
|
|
|
|
make_unique_key<0>(&key3, 0);
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrGpuResource> d2(cache->findAndRefUniqueResource(key3));
|
2015-08-04 17:01:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data() == 4132);
|
2014-11-10 18:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_purge_invalidated(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2, key3;
|
|
|
|
make_unique_key<0>(&key1, 1);
|
|
|
|
make_unique_key<0>(&key2, 2);
|
|
|
|
make_unique_key<0>(&key3, 3);
|
2016-03-16 17:28:35 +00:00
|
|
|
|
2015-02-06 19:54:28 +00:00
|
|
|
// Add three resources to the cache. Only c is usable as scratch.
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* a = new TestResource(gpu);
|
|
|
|
TestResource* b = new TestResource(gpu);
|
|
|
|
TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kA_SimulatedProperty);
|
2015-02-19 15:24:21 +00:00
|
|
|
a->resourcePriv().setUniqueKey(key1);
|
|
|
|
b->resourcePriv().setUniqueKey(key2);
|
|
|
|
c->resourcePriv().setUniqueKey(key3);
|
2014-01-15 23:09:01 +00:00
|
|
|
a->unref();
|
2015-02-06 19:54:28 +00:00
|
|
|
// hold b until *after* the message is sent.
|
2014-11-10 18:19:06 +00:00
|
|
|
c->unref();
|
2014-01-15 23:09:01 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3));
|
2014-11-05 22:47:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
|
2015-02-06 19:54:28 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
typedef GrUniqueKeyInvalidatedMessage Msg;
|
|
|
|
typedef SkMessageBus<GrUniqueKeyInvalidatedMessage> Bus;
|
2015-02-06 19:54:28 +00:00
|
|
|
|
|
|
|
// Invalidate two of the three, they should be purged and no longer accessible via their keys.
|
2019-02-04 18:26:26 +00:00
|
|
|
Bus::Post(Msg(key1, context->priv().contextID()));
|
|
|
|
Bus::Post(Msg(key2, context->priv().contextID()));
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAsNeeded();
|
2015-02-06 19:54:28 +00:00
|
|
|
// a should be deleted now, but we still have a ref on b.
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2));
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3));
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Invalidate the third.
|
2019-02-04 18:26:26 +00:00
|
|
|
Bus::Post(Msg(key3, context->priv().contextID()));
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAsNeeded();
|
2015-02-06 19:54:28 +00:00
|
|
|
// we still have a ref on b, c should be recycled as scratch.
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3));
|
2014-11-14 20:10:14 +00:00
|
|
|
|
2015-02-06 19:54:28 +00:00
|
|
|
// make b purgeable. It should be immediately deleted since it has no key.
|
|
|
|
b->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// Make sure we actually get to c via it's scratch key, before we say goodbye.
|
|
|
|
GrScratchKey scratchKey;
|
|
|
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
|
2019-09-06 15:48:27 +00:00
|
|
|
GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey);
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch == c);
|
|
|
|
SkSafeUnref(scratch);
|
|
|
|
|
|
|
|
// Get rid of c.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2019-09-06 15:48:27 +00:00
|
|
|
scratch = cache->findAndRefScratchResource(scratchKey);
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, !scratch);
|
|
|
|
SkSafeUnref(scratch);
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:10:14 +00:00
|
|
|
static void test_cache_chained_purge(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2015-01-23 15:19:22 +00:00
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<0>(&key1, 1);
|
|
|
|
make_unique_key<0>(&key2, 2);
|
2014-01-17 17:56:21 +00:00
|
|
|
|
2018-07-11 18:56:22 +00:00
|
|
|
sk_sp<TestResource> a(new TestResource(gpu));
|
|
|
|
sk_sp<TestResource> b(new TestResource(gpu));
|
2015-02-19 15:24:21 +00:00
|
|
|
a->resourcePriv().setUniqueKey(key1);
|
|
|
|
b->resourcePriv().setUniqueKey(key2);
|
2014-11-14 20:10:14 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
// Make a cycle
|
|
|
|
a->setUnrefWhenDestroyed(b);
|
|
|
|
b->setUnrefWhenDestroyed(a);
|
2014-11-05 22:47:41 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2014-11-05 22:47:41 +00:00
|
|
|
|
2018-07-11 18:56:22 +00:00
|
|
|
TestResource* unownedA = a.release();
|
|
|
|
unownedA->unref();
|
|
|
|
b.reset();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2014-11-13 21:33:28 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
// Break the cycle
|
2018-07-11 18:56:22 +00:00
|
|
|
unownedA->setUnrefWhenDestroyed(nullptr);
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2014-11-14 14:47:39 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2014-01-17 17:56:21 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 19:38:44 +00:00
|
|
|
static void test_timestamp_wrap(skiatest::Reporter* reporter) {
|
|
|
|
static const int kCount = 50;
|
|
|
|
static const int kLockedFreq = 8;
|
2019-09-03 14:29:20 +00:00
|
|
|
static const int kBudgetSize = 0; // always over budget
|
2015-02-19 19:38:44 +00:00
|
|
|
|
|
|
|
SkRandom random;
|
|
|
|
|
|
|
|
// Run the test 2*kCount times;
|
|
|
|
for (int i = 0; i < 2 * kCount; ++i ) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(kBudgetSize);
|
2015-02-19 19:38:44 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2015-02-19 19:38:44 +00:00
|
|
|
|
|
|
|
// Pick a random number of resources to add before the timestamp will wrap.
|
Reland "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."
This reverts commit ab17347df32807cabd9f2a518d22c3bd420e482f.
Reason for revert: Chromium should now be ok.
Original change's description:
> Revert "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."
>
> This reverts commit e1bc7de7c07686b28b00b850e44e0722189f3592.
>
> Reason for revert: chrome used it
>
> Original change's description:
> > Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines.
> >
> > sed 's/SK_MaxSizeT/SIZE_MAX/g'
> > sed 's/SK_MaxU32/UINT32_MAX/g'
> > sed 's/SK_MaxU16/UINT16_MAX/g'
> >
> > SK_MinU32 and SK_MinU16 were unused
> >
> > Change-Id: I6b6c824df47b05bde7e73b13a58e851a5f63fe0e
> > Reviewed-on: https://skia-review.googlesource.com/134607
> > Commit-Queue: Hal Canary <halcanary@google.com>
> > Reviewed-by: Ben Wagner <bungeman@google.com>
>
> TBR=halcanary@google.com,bungeman@google.com,reed@google.com
>
> Change-Id: I1e2c440dcf9f59bf87c1fea113248cd5136f7519
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/134921
> Reviewed-by: Hal Canary <halcanary@google.com>
> Commit-Queue: Hal Canary <halcanary@google.com>
CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux-ozone-rel
TBR=halcanary@google.com,bungeman@google.com,reed@google.com
Change-Id: I7709f9715bea0463b85b5b0a89712ac1020fcddb
Reviewed-on: https://skia-review.googlesource.com/135180
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2018-06-15 15:37:57 +00:00
|
|
|
cache->changeTimestamp(UINT32_MAX - random.nextULessThan(kCount + 1));
|
2015-02-19 19:38:44 +00:00
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
static const int kNumToPurge = kCount;
|
2015-02-19 19:38:44 +00:00
|
|
|
|
|
|
|
SkTDArray<int> shouldPurgeIdxs;
|
|
|
|
int purgeableCnt = 0;
|
|
|
|
SkTDArray<GrGpuResource*> resourcesToUnref;
|
|
|
|
|
|
|
|
// Add kCount resources, holding onto resources at random so we have a mix of purgeable and
|
|
|
|
// unpurgeable resources.
|
|
|
|
for (int j = 0; j < kCount; ++j) {
|
|
|
|
GrUniqueKey key;
|
|
|
|
make_unique_key<0>(&key, j);
|
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2015-02-19 19:38:44 +00:00
|
|
|
r->resourcePriv().setUniqueKey(key);
|
|
|
|
if (random.nextU() % kLockedFreq) {
|
|
|
|
// Make this is purgeable.
|
|
|
|
r->unref();
|
|
|
|
++purgeableCnt;
|
|
|
|
if (purgeableCnt <= kNumToPurge) {
|
|
|
|
*shouldPurgeIdxs.append() = j;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*resourcesToUnref.append() = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that the correct resources were purged.
|
|
|
|
int currShouldPurgeIdx = 0;
|
|
|
|
for (int j = 0; j < kCount; ++j) {
|
|
|
|
GrUniqueKey key;
|
|
|
|
make_unique_key<0>(&key, j);
|
|
|
|
GrGpuResource* res = cache->findAndRefUniqueResource(key);
|
|
|
|
if (currShouldPurgeIdx < shouldPurgeIdxs.count() &&
|
|
|
|
shouldPurgeIdxs[currShouldPurgeIdx] == j) {
|
|
|
|
++currShouldPurgeIdx;
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == res);
|
2015-02-19 19:38:44 +00:00
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr != res);
|
2015-02-19 19:38:44 +00:00
|
|
|
}
|
|
|
|
SkSafeUnref(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < resourcesToUnref.count(); ++j) {
|
|
|
|
resourcesToUnref[j]->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:53:13 +00:00
|
|
|
static void test_time_purge(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(1000000);
|
2017-03-22 18:53:13 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2017-03-22 18:53:13 +00:00
|
|
|
|
|
|
|
static constexpr int kCnts[] = {1, 10, 1024};
|
|
|
|
auto nowish = []() {
|
|
|
|
// We sleep so that we ensure we get a value that is greater than the last call to
|
|
|
|
// GrStdSteadyClock::now().
|
|
|
|
std::this_thread::sleep_for(GrStdSteadyClock::duration(5));
|
|
|
|
auto result = GrStdSteadyClock::now();
|
|
|
|
// Also sleep afterwards so we don't get this value again.
|
|
|
|
std::this_thread::sleep_for(GrStdSteadyClock::duration(5));
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int cnt : kCnts) {
|
|
|
|
std::unique_ptr<GrStdSteadyClock::time_point[]> timeStamps(
|
|
|
|
new GrStdSteadyClock::time_point[cnt]);
|
|
|
|
{
|
|
|
|
// Insert resources and get time points between each addition.
|
|
|
|
for (int i = 0; i < cnt; ++i) {
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2017-03-22 18:53:13 +00:00
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, i);
|
|
|
|
r->resourcePriv().setUniqueKey(k);
|
|
|
|
r->unref();
|
|
|
|
timeStamps.get()[i] = nowish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Purge based on the time points between resource additions. Each purge should remove
|
|
|
|
// the oldest resource.
|
|
|
|
for (int i = 0; i < cnt; ++i) {
|
|
|
|
cache->purgeResourcesNotUsedSince(timeStamps[i]);
|
|
|
|
REPORTER_ASSERT(reporter, cnt - i - 1 == cache->getResourceCount());
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, j);
|
|
|
|
GrGpuResource* r = cache->findAndRefUniqueResource(k);
|
|
|
|
REPORTER_ASSERT(reporter, !SkToBool(r));
|
|
|
|
SkSafeUnref(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a similar test but where we leave refs on some resources to prevent them from being
|
|
|
|
// purged.
|
|
|
|
{
|
|
|
|
std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]);
|
|
|
|
for (int i = 0; i < cnt; ++i) {
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2017-03-22 18:53:13 +00:00
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, i);
|
|
|
|
r->resourcePriv().setUniqueKey(k);
|
|
|
|
// Leave a ref on every other resource, beginning with the first.
|
|
|
|
if (SkToBool(i & 0x1)) {
|
|
|
|
refedResources.get()[i / 2] = r;
|
|
|
|
} else {
|
|
|
|
r->unref();
|
|
|
|
}
|
|
|
|
timeStamps.get()[i] = nowish();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < cnt; ++i) {
|
|
|
|
// Should get a resource purged every other frame.
|
|
|
|
cache->purgeResourcesNotUsedSince(timeStamps[i]);
|
|
|
|
REPORTER_ASSERT(reporter, cnt - i / 2 - 1 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unref all the resources that we kept refs on in the first loop.
|
|
|
|
for (int i = 0; i < (cnt / 2); ++i) {
|
|
|
|
refedResources.get()[i]->unref();
|
|
|
|
cache->purgeResourcesNotUsedSince(nowish());
|
|
|
|
REPORTER_ASSERT(reporter, cnt / 2 - i - 1 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
|
|
|
// Verify that calling flush() on a GrContext with nothing to do will not trigger resource
|
|
|
|
// eviction
|
|
|
|
context->flush();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2017-03-22 18:53:13 +00:00
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, i);
|
|
|
|
r->resourcePriv().setUniqueKey(k);
|
|
|
|
r->unref();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
|
|
|
context->flush();
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
|
|
|
cache->purgeResourcesNotUsedSince(nowish());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:43:59 +00:00
|
|
|
static void test_partial_purge(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(100);
|
2017-05-25 20:43:59 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2017-05-25 20:43:59 +00:00
|
|
|
|
|
|
|
enum TestsCase {
|
|
|
|
kOnlyScratch_TestCase = 0,
|
|
|
|
kPartialScratch_TestCase = 1,
|
|
|
|
kAllScratch_TestCase = 2,
|
|
|
|
kPartial_TestCase = 3,
|
|
|
|
kAll_TestCase = 4,
|
|
|
|
kNone_TestCase = 5,
|
|
|
|
kEndTests_TestCase = kNone_TestCase + 1
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int testCase = 0; testCase < kEndTests_TestCase; testCase++) {
|
|
|
|
|
|
|
|
GrUniqueKey key1, key2, key3;
|
|
|
|
make_unique_key<0>(&key1, 1);
|
|
|
|
make_unique_key<0>(&key2, 2);
|
|
|
|
make_unique_key<0>(&key3, 3);
|
|
|
|
|
|
|
|
// Add three unique resources to the cache.
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource *unique1 = new TestResource(gpu, SkBudgeted::kYes, 10);
|
|
|
|
TestResource *unique2 = new TestResource(gpu, SkBudgeted::kYes, 11);
|
|
|
|
TestResource *unique3 = new TestResource(gpu, SkBudgeted::kYes, 12);
|
2017-05-25 20:43:59 +00:00
|
|
|
|
|
|
|
unique1->resourcePriv().setUniqueKey(key1);
|
|
|
|
unique2->resourcePriv().setUniqueKey(key2);
|
|
|
|
unique3->resourcePriv().setUniqueKey(key3);
|
|
|
|
|
|
|
|
// Add two scratch resources to the cache.
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kA_SimulatedProperty,
|
|
|
|
13);
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource::kB_SimulatedProperty,
|
|
|
|
14);
|
2017-05-25 20:43:59 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
|
|
|
|
|
|
|
// Add resources to the purgeable queue
|
|
|
|
unique1->unref();
|
|
|
|
scratch1->unref();
|
|
|
|
unique2->unref();
|
|
|
|
scratch2->unref();
|
|
|
|
unique3->unref();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes());
|
|
|
|
|
|
|
|
switch(testCase) {
|
|
|
|
case kOnlyScratch_TestCase: {
|
|
|
|
context->purgeUnlockedResources(14, true);
|
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 33 == cache->getBudgetedResourceBytes());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kPartialScratch_TestCase: {
|
|
|
|
context->purgeUnlockedResources(3, true);
|
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 47 == cache->getBudgetedResourceBytes());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kAllScratch_TestCase: {
|
|
|
|
context->purgeUnlockedResources(50, true);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kPartial_TestCase: {
|
|
|
|
context->purgeUnlockedResources(13, false);
|
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 37 == cache->getBudgetedResourceBytes());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kAll_TestCase: {
|
|
|
|
context->purgeUnlockedResources(50, false);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kNone_TestCase: {
|
|
|
|
context->purgeUnlockedResources(0, true);
|
|
|
|
context->purgeUnlockedResources(0, false);
|
|
|
|
REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes());
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 20:33:19 +00:00
|
|
|
}
|
2017-05-25 20:43:59 +00:00
|
|
|
|
|
|
|
// ensure all are purged before the next
|
2019-02-06 20:12:53 +00:00
|
|
|
context->priv().testingOnly_purgeAllUnlockedResources();
|
2017-05-25 20:43:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 17:01:58 +00:00
|
|
|
static void test_custom_data(skiatest::Reporter* reporter) {
|
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<0>(&key1, 1);
|
|
|
|
make_unique_key<0>(&key2, 2);
|
|
|
|
int foo = 4132;
|
2016-08-02 21:40:46 +00:00
|
|
|
key1.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo)));
|
2015-08-04 17:01:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132);
|
|
|
|
REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr);
|
|
|
|
|
|
|
|
// Test that copying a key also takes a ref on its custom data.
|
|
|
|
GrUniqueKey key3 = key1;
|
|
|
|
REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132);
|
|
|
|
}
|
|
|
|
|
2015-09-24 14:07:40 +00:00
|
|
|
static void test_abandoned(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(300);
|
2015-09-24 14:07:40 +00:00
|
|
|
GrContext* context = mock.context();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2018-01-22 15:48:15 +00:00
|
|
|
|
|
|
|
sk_sp<GrGpuResource> resource(new TestResource(gpu));
|
2015-09-24 14:07:40 +00:00
|
|
|
context->abandonContext();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, resource->wasDestroyed());
|
|
|
|
|
|
|
|
// Call all the public methods on resource in the abandoned state. They shouldn't crash.
|
|
|
|
|
2016-08-31 21:04:06 +00:00
|
|
|
resource->uniqueID();
|
2015-09-24 14:07:40 +00:00
|
|
|
resource->getUniqueKey();
|
|
|
|
resource->wasDestroyed();
|
|
|
|
resource->gpuMemorySize();
|
|
|
|
resource->getContext();
|
|
|
|
|
|
|
|
resource->resourcePriv().getScratchKey();
|
2019-01-24 20:58:58 +00:00
|
|
|
resource->resourcePriv().budgetedType();
|
2015-09-24 14:07:40 +00:00
|
|
|
resource->resourcePriv().makeBudgeted();
|
|
|
|
resource->resourcePriv().makeUnbudgeted();
|
|
|
|
resource->resourcePriv().removeScratchKey();
|
|
|
|
GrUniqueKey key;
|
|
|
|
make_unique_key<0>(&key, 1);
|
|
|
|
resource->resourcePriv().setUniqueKey(key);
|
|
|
|
resource->resourcePriv().removeUniqueKey();
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:04:19 +00:00
|
|
|
static void test_tags(skiatest::Reporter* reporter) {
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
// We will insert 1 resource with tag "tag1", 2 with "tag2", and so on, up through kLastTagIdx.
|
|
|
|
static constexpr int kLastTagIdx = 10;
|
|
|
|
static constexpr int kNumResources = kLastTagIdx * (kLastTagIdx + 1) / 2;
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(kNumResources * TestResource::kDefaultSize);
|
2017-01-06 17:04:19 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2017-01-06 17:04:19 +00:00
|
|
|
|
2018-03-29 17:40:02 +00:00
|
|
|
// tag strings are expected to be long lived
|
|
|
|
std::vector<SkString> tagStrings;
|
|
|
|
|
2017-01-06 17:04:19 +00:00
|
|
|
SkString tagStr;
|
|
|
|
int tagIdx = 0;
|
|
|
|
int currTagCnt = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < kNumResources; ++i, ++currTagCnt) {
|
2018-03-29 17:40:02 +00:00
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
sk_sp<GrGpuResource> resource(new TestResource(gpu));
|
2017-01-06 17:04:19 +00:00
|
|
|
GrUniqueKey key;
|
|
|
|
if (currTagCnt == tagIdx) {
|
|
|
|
tagIdx += 1;
|
|
|
|
currTagCnt = 0;
|
|
|
|
tagStr.printf("tag%d", tagIdx);
|
2018-03-29 17:40:02 +00:00
|
|
|
tagStrings.emplace_back(tagStr);
|
2017-01-06 17:04:19 +00:00
|
|
|
}
|
2018-03-29 17:40:02 +00:00
|
|
|
make_unique_key<1>(&key, i, tagStrings.back().c_str());
|
2017-01-06 17:04:19 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key);
|
|
|
|
}
|
|
|
|
SkASSERT(kLastTagIdx == tagIdx);
|
|
|
|
SkASSERT(currTagCnt == kLastTagIdx);
|
|
|
|
|
|
|
|
// Test i = 0 to exercise unused tag string.
|
|
|
|
for (int i = 0; i <= kLastTagIdx; ++i) {
|
|
|
|
tagStr.printf("tag%d", i);
|
|
|
|
REPORTER_ASSERT(reporter, cache->countUniqueKeysWithTag(tagStr.c_str()) == i);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
static void test_free_texture_messages(skiatest::Reporter* reporter) {
|
2019-09-03 14:29:20 +00:00
|
|
|
Mock mock(30000);
|
2018-08-10 13:48:08 +00:00
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2018-08-10 13:48:08 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
GrBackendTexture backends[3];
|
|
|
|
GrTexture* wrapped[3];
|
|
|
|
int freed[3] = { 0, 0, 0 };
|
2018-08-10 13:48:08 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
auto releaseProc = [](void* ctx) {
|
|
|
|
int* index = (int*) ctx;
|
|
|
|
*index = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
backends[i] = context->createBackendTexture(16, 16, SkColorType::kRGBA_8888_SkColorType,
|
|
|
|
GrMipMapped::kNo, GrRenderable::kNo);
|
|
|
|
wrapped[i] = gpu->wrapBackendTexture(backends[i], GrColorType::kRGBA_8888,
|
|
|
|
GrWrapOwnership::kBorrow_GrWrapOwnership,
|
|
|
|
(i < 2) ? GrWrapCacheable::kYes
|
|
|
|
: GrWrapCacheable::kNo,
|
|
|
|
GrIOType::kRead_GrIOType).release();
|
|
|
|
wrapped[i]->setRelease(releaseProc, &freed[i]);
|
|
|
|
}
|
2018-08-10 13:48:08 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
cache->insertDelayedTextureUnref(wrapped[0]);
|
|
|
|
cache->insertDelayedTextureUnref(wrapped[1]);
|
2018-08-10 13:48:08 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
// An uncacheable cross-context should not be purged as soon as we drop our ref. This
|
|
|
|
// is because inserting it as a cross-context resource actually holds a ref until the
|
|
|
|
// message is received.
|
2019-10-16 18:30:09 +00:00
|
|
|
cache->insertDelayedTextureUnref(wrapped[2]);
|
2019-01-24 21:03:07 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2]));
|
2018-08-10 13:48:08 +00:00
|
|
|
|
|
|
|
// Have only ref waiting on message.
|
2019-10-16 18:30:09 +00:00
|
|
|
wrapped[0]->unref();
|
|
|
|
wrapped[1]->unref();
|
|
|
|
wrapped[2]->unref();
|
2018-08-10 13:48:08 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2]));
|
2018-08-10 13:48:08 +00:00
|
|
|
|
|
|
|
// This should free nothing since no messages were sent.
|
|
|
|
cache->purgeAsNeeded();
|
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2]));
|
|
|
|
|
2018-08-10 13:48:08 +00:00
|
|
|
// Send message to free the first resource
|
2019-10-16 18:30:09 +00:00
|
|
|
GrTextureFreedMessage msg1{wrapped[0], context->priv().contextID()};
|
|
|
|
SkMessageBus<GrTextureFreedMessage>::Post(msg1);
|
2019-01-24 21:03:07 +00:00
|
|
|
cache->purgeAsNeeded();
|
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == (freed[0] + freed[1] + freed[2]));
|
|
|
|
REPORTER_ASSERT(reporter, 1 == freed[0]);
|
2019-01-24 21:03:07 +00:00
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
GrTextureFreedMessage msg2{wrapped[2], context->priv().contextID()};
|
|
|
|
SkMessageBus<GrTextureFreedMessage>::Post(msg2);
|
2018-08-10 13:48:08 +00:00
|
|
|
cache->purgeAsNeeded();
|
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == (freed[0] + freed[1] + freed[2]));
|
|
|
|
REPORTER_ASSERT(reporter, 0 == freed[1]);
|
2018-08-10 13:48:08 +00:00
|
|
|
|
|
|
|
mock.reset();
|
|
|
|
|
2019-10-16 18:30:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == (freed[0] + freed[1] + freed[2]));
|
2018-08-10 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) {
|
2014-11-10 18:19:06 +00:00
|
|
|
// The below tests create their own mock contexts.
|
2014-11-14 20:10:14 +00:00
|
|
|
test_no_key(reporter);
|
2018-03-28 16:25:42 +00:00
|
|
|
test_purge_unlocked(reporter);
|
2014-11-17 17:33:27 +00:00
|
|
|
test_budgeting(reporter);
|
2015-01-14 18:42:08 +00:00
|
|
|
test_unbudgeted(reporter);
|
2015-01-23 15:19:22 +00:00
|
|
|
test_unbudgeted_to_scratch(reporter);
|
2015-02-19 15:24:21 +00:00
|
|
|
test_duplicate_unique_key(reporter);
|
2014-11-10 18:19:06 +00:00
|
|
|
test_duplicate_scratch_key(reporter);
|
2014-11-25 13:52:06 +00:00
|
|
|
test_remove_scratch_key(reporter);
|
2015-01-21 17:32:40 +00:00
|
|
|
test_scratch_key_consistency(reporter);
|
2014-11-10 18:19:06 +00:00
|
|
|
test_purge_invalidated(reporter);
|
2014-11-14 20:10:14 +00:00
|
|
|
test_cache_chained_purge(reporter);
|
2015-02-19 19:38:44 +00:00
|
|
|
test_timestamp_wrap(reporter);
|
2017-03-22 18:53:13 +00:00
|
|
|
test_time_purge(reporter);
|
2017-05-25 20:43:59 +00:00
|
|
|
test_partial_purge(reporter);
|
2015-08-04 17:01:58 +00:00
|
|
|
test_custom_data(reporter);
|
2015-09-24 14:07:40 +00:00
|
|
|
test_abandoned(reporter);
|
2017-01-06 17:04:19 +00:00
|
|
|
test_tags(reporter);
|
2019-10-16 18:30:09 +00:00
|
|
|
test_free_texture_messages(reporter);
|
2013-08-08 22:55:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:39:45 +00:00
|
|
|
// This simulates a portion of Chrome's context abandonment processing.
|
|
|
|
// Please see: crbug.com/1011368 and crbug.com/1014993
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceMessagesAfterAbandon, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
|
|
|
GrResourceCache* cache = context->priv().getResourceCache();
|
|
|
|
|
|
|
|
GrBackendTexture backend = context->createBackendTexture(16, 16,
|
|
|
|
SkColorType::kRGBA_8888_SkColorType,
|
|
|
|
GrMipMapped::kNo, GrRenderable::kNo);
|
|
|
|
GrTexture* tex = gpu->wrapBackendTexture(backend, GrColorType::kRGBA_8888,
|
|
|
|
GrWrapOwnership::kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kYes,
|
|
|
|
GrIOType::kRead_GrIOType).release();
|
|
|
|
|
|
|
|
auto releaseProc = [](void* ctx) {
|
|
|
|
int* index = (int*) ctx;
|
|
|
|
*index = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
int freed = 0;
|
|
|
|
|
|
|
|
tex->setRelease(releaseProc, &freed);
|
|
|
|
|
|
|
|
cache->insertDelayedTextureUnref(tex);
|
|
|
|
|
|
|
|
// Now only the cache is holding a ref to this texture
|
|
|
|
tex->unref();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == freed);
|
|
|
|
|
2019-12-04 16:14:29 +00:00
|
|
|
// We must delete the backend texture before abandoning the context in vulkan. We just do it
|
|
|
|
// for all the backends for consistency.
|
|
|
|
context->deleteBackendTexture(backend);
|
2019-10-16 20:39:45 +00:00
|
|
|
context->abandonContext();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == freed);
|
|
|
|
|
|
|
|
// In the past, creating this message could cause an exception due to
|
|
|
|
// an un-safe downcast from GrTexture to GrGpuResource
|
|
|
|
GrTextureFreedMessage msg{tex, context->priv().contextID()};
|
|
|
|
SkMessageBus<GrTextureFreedMessage>::Post(msg);
|
|
|
|
|
2019-12-04 20:17:54 +00:00
|
|
|
// This doesn't actually do anything but it does trigger us to read messages
|
2019-10-16 20:39:45 +00:00
|
|
|
context->purgeUnlockedResources(false);
|
|
|
|
}
|
|
|
|
|
2016-11-07 13:23:48 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2017-03-04 13:12:46 +00:00
|
|
|
static sk_sp<GrTexture> make_normal_texture(GrResourceProvider* provider,
|
2019-07-17 13:59:59 +00:00
|
|
|
GrRenderable renderable,
|
2016-11-07 13:23:48 +00:00
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2019-08-05 16:58:39 +00:00
|
|
|
auto format = provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, renderable);
|
2019-09-17 13:01:56 +00:00
|
|
|
return provider->createTexture(desc, format, renderable, sampleCnt, GrMipMapped::kNo,
|
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_mipmap_proxy(GrContext * context,
|
2019-07-17 13:59:59 +00:00
|
|
|
GrRenderable renderable,
|
2017-04-06 11:59:41 +00:00
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
2019-07-30 16:49:10 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
2016-11-07 13:23:48 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2019-07-17 13:59:59 +00:00
|
|
|
auto origin = renderable == GrRenderable::kYes ? kBottomLeft_GrSurfaceOrigin
|
|
|
|
: kTopLeft_GrSurfaceOrigin;
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2018-03-04 03:43:43 +00:00
|
|
|
|
2020-01-21 19:29:57 +00:00
|
|
|
return proxyProvider->createProxy(format, desc, swizzle, renderable, sampleCnt, origin,
|
2019-08-30 20:19:42 +00:00
|
|
|
GrMipMapped::kYes, SkBackingFit::kExact, SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exercise GrSurface::gpuMemorySize for different combos of MSAA, RT-only,
|
|
|
|
// Texture-only, both-RT-and-Texture and MIPmapped
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2016-11-07 13:23:48 +00:00
|
|
|
|
|
|
|
static const int kSize = 64;
|
|
|
|
|
|
|
|
// Normal versions
|
2017-04-06 11:59:41 +00:00
|
|
|
{
|
|
|
|
sk_sp<GrTexture> tex;
|
|
|
|
|
2019-07-17 13:59:59 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, GrRenderable::kYes, kSize, kSize, 1);
|
2017-04-06 11:59:41 +00:00
|
|
|
size_t size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
|
|
|
|
|
2019-08-07 19:52:37 +00:00
|
|
|
size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, tex->backendFormat());
|
2017-07-19 18:47:42 +00:00
|
|
|
if (sampleCount >= 4) {
|
2019-07-17 13:59:59 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, GrRenderable::kYes, kSize, kSize,
|
2017-07-19 18:47:42 +00:00
|
|
|
sampleCount);
|
2017-04-06 11:59:41 +00:00
|
|
|
size = tex->gpuMemorySize();
|
2017-07-19 18:47:42 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
kSize*kSize*4 == size || // msaa4 failed
|
|
|
|
kSize*kSize*4*sampleCount == size || // auto-resolving
|
|
|
|
kSize*kSize*4*(sampleCount+1) == size); // explicit resolve buffer
|
2017-04-06 11:59:41 +00:00
|
|
|
}
|
2016-11-07 13:23:48 +00:00
|
|
|
|
2019-07-17 13:59:59 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, GrRenderable::kNo, kSize, kSize, 1);
|
2016-11-07 13:23:48 +00:00
|
|
|
size = tex->gpuMemorySize();
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mipmapped versions
|
2018-11-16 20:43:41 +00:00
|
|
|
if (caps->mipMapSupport()) {
|
2017-04-06 11:59:41 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2016-11-07 13:23:48 +00:00
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, 1);
|
2019-10-10 20:10:31 +00:00
|
|
|
size_t size = proxy->gpuMemorySize(*caps);
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
|
2019-08-07 19:52:37 +00:00
|
|
|
size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, proxy->backendFormat());
|
2017-07-19 18:47:42 +00:00
|
|
|
if (sampleCount >= 4) {
|
2019-07-30 16:49:10 +00:00
|
|
|
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, sampleCount);
|
2019-10-10 20:10:31 +00:00
|
|
|
size = proxy->gpuMemorySize(*caps);
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2017-07-19 18:47:42 +00:00
|
|
|
kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed
|
|
|
|
kSize*kSize*4*sampleCount+(kSize*kSize*4)/3 == size || // auto-resolving
|
|
|
|
kSize*kSize*4*(sampleCount+1)+(kSize*kSize*4)/3 == size); // explicit resolve buffer
|
2017-04-06 11:59:41 +00:00
|
|
|
}
|
2017-04-05 18:56:21 +00:00
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
proxy = make_mipmap_proxy(context, GrRenderable::kNo, kSize, kSize, 1);
|
2019-10-10 20:10:31 +00:00
|
|
|
size = proxy->gpuMemorySize(*caps);
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
}
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|
2019-04-04 15:39:55 +00:00
|
|
|
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(OverbudgetFlush, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(1);
|
2019-04-04 15:39:55 +00:00
|
|
|
|
|
|
|
// Helper that determines if cache is overbudget.
|
|
|
|
auto overbudget = [context] {
|
|
|
|
int uNum;
|
|
|
|
size_t uSize;
|
|
|
|
context->getResourceCacheUsage(&uNum, &uSize);
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t bSize = context->getResourceCacheLimit();
|
|
|
|
return uSize > bSize;
|
2019-04-04 15:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper that does a trivial draw to a surface.
|
|
|
|
auto drawToSurf = [](SkSurface* surf) {
|
|
|
|
surf->getCanvas()->drawRect(SkRect::MakeWH(1,1), SkPaint());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper that checks whether a flush has occurred between calls.
|
|
|
|
int baseFlushCount = 0;
|
|
|
|
auto getFlushCountDelta = [context, &baseFlushCount]() {
|
|
|
|
int cur = context->priv().getGpu()->stats()->numFinishFlushes();
|
|
|
|
int delta = cur - baseFlushCount;
|
|
|
|
baseFlushCount = cur;
|
|
|
|
return delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
auto surf1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr);
|
|
|
|
auto surf2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr);
|
|
|
|
|
|
|
|
drawToSurf(surf1.get());
|
|
|
|
drawToSurf(surf2.get());
|
|
|
|
|
|
|
|
// Flush each surface once to ensure that their backing stores are allocated.
|
|
|
|
surf1->flush();
|
|
|
|
surf2->flush();
|
|
|
|
REPORTER_ASSERT(reporter, overbudget());
|
|
|
|
getFlushCountDelta();
|
|
|
|
|
|
|
|
// Nothing should be purgeable so drawing to either surface doesn't cause a flush.
|
|
|
|
drawToSurf(surf1.get());
|
|
|
|
REPORTER_ASSERT(reporter, !getFlushCountDelta());
|
|
|
|
drawToSurf(surf2.get());
|
|
|
|
REPORTER_ASSERT(reporter, !getFlushCountDelta());
|
|
|
|
REPORTER_ASSERT(reporter, overbudget());
|
|
|
|
|
|
|
|
// Make surf1 purgeable. Drawing to surf2 should flush.
|
|
|
|
surf1->flush();
|
|
|
|
surf1.reset();
|
|
|
|
drawToSurf(surf2.get());
|
|
|
|
REPORTER_ASSERT(reporter, getFlushCountDelta());
|
|
|
|
REPORTER_ASSERT(reporter, overbudget());
|
|
|
|
}
|
|
|
|
#endif
|