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.
|
|
|
|
*/
|
|
|
|
|
2015-04-08 18:01:54 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2017-03-22 18:53:13 +00:00
|
|
|
#include <thread>
|
2014-10-08 15:40:09 +00:00
|
|
|
#include "GrContext.h"
|
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
|
|
|
#include "GrContextPriv.h"
|
2013-08-08 22:55:21 +00:00
|
|
|
#include "GrContextFactory.h"
|
2014-10-08 15:40:09 +00:00
|
|
|
#include "GrGpu.h"
|
2015-02-13 22:20:05 +00:00
|
|
|
#include "GrGpuResourceCacheAccess.h"
|
|
|
|
#include "GrGpuResourcePriv.h"
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-09-21 16:00:26 +00:00
|
|
|
#include "GrRenderTargetPriv.h"
|
2015-02-11 18:49:59 +00:00
|
|
|
#include "GrResourceCache.h"
|
2015-10-02 14:49:05 +00:00
|
|
|
#include "GrResourceProvider.h"
|
2015-06-18 16:12:16 +00:00
|
|
|
#include "GrTest.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
#include "GrTexture.h"
|
|
|
|
|
2014-10-08 15:40:09 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-11-14 20:10:14 +00:00
|
|
|
#include "SkGr.h"
|
|
|
|
#include "SkMessageBus.h"
|
2016-11-07 13:23:48 +00:00
|
|
|
#include "SkMipMap.h"
|
2014-09-18 13:09:44 +00:00
|
|
|
#include "SkSurface.h"
|
2014-01-10 22:08:27 +00:00
|
|
|
#include "Test.h"
|
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
|
|
|
GrSurfaceDesc desc;
|
2016-10-14 13:16:21 +00:00
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = gWidth;
|
|
|
|
desc.fHeight = gHeight;
|
|
|
|
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
|
|
|
|
|
|
|
int oldMaxNum;
|
|
|
|
size_t oldMaxBytes;
|
2014-05-09 14:29:32 +00:00
|
|
|
context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes);
|
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;
|
2014-05-09 14:29:32 +00:00
|
|
|
context->setResourceCacheLimits(1000, 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);
|
|
|
|
}
|
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
context->setResourceCacheLimits(oldMaxNum, 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.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = size;
|
|
|
|
desc.fHeight = size;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fSampleCnt = sampleCount;
|
|
|
|
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
|
|
|
|
if (!tex || !tex->asRenderTarget()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!provider->attachStencilAttachment(tex->asRenderTarget())) {
|
|
|
|
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();
|
2018-05-11 14:14:21 +00:00
|
|
|
if (context->contextPriv().caps()->avoidStencilBuffers()) {
|
2017-05-08 19:02:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-23 17:06:38 +00:00
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
|
2017-09-21 16:00:26 +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 =
|
|
|
|
context->contextPriv().caps()->getRenderTargetSampleCount(2, kRGBA_8888_GrPixelConfig);
|
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);
|
2015-02-19 20:05:58 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
if (!smallMSAART0) {
|
|
|
|
// The nexus player seems to fail to create MSAA textures.
|
|
|
|
return;
|
|
|
|
}
|
2017-09-21 16:00:26 +00:00
|
|
|
#else
|
|
|
|
REPORTER_ASSERT(reporter, smallMSAART0);
|
2015-02-19 20:05:58 +00:00
|
|
|
#endif
|
2017-09-21 16:00:26 +00:00
|
|
|
|
|
|
|
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.).
|
2018-05-11 14:14:21 +00:00
|
|
|
int bigSampleCount = context->contextPriv().caps()->getRenderTargetSampleCount(
|
|
|
|
5, kRGBA_8888_GrPixelConfig);
|
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();
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
backendTextures[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
|
|
|
|
kRGBA_8888_GrPixelConfig,
|
|
|
|
false, GrMipMapped::kNo);
|
|
|
|
backendTextures[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
|
|
|
|
kRGBA_8888_GrPixelConfig,
|
|
|
|
false, GrMipMapped::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(
|
2017-12-12 18:01:25 +00:00
|
|
|
backendTextures[0], kBorrow_GrWrapOwnership));
|
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture(
|
2017-12-12 18:01:25 +00:00
|
|
|
backendTextures[1], kAdopt_GrWrapOwnership));
|
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) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTextures[0]);
|
2018-03-07 16:47:54 +00:00
|
|
|
}
|
|
|
|
if (adoptedIsAlive) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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
|
|
|
}
|
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* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) {
|
|
|
|
return new TestResource(gpu, 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.
|
|
|
|
TestResource(GrGpu* gpu, size_t size)
|
|
|
|
: INHERITED(gpu)
|
|
|
|
, fToDelete(nullptr)
|
|
|
|
, fSize(size)
|
|
|
|
, fProperty(kA_SimulatedProperty)
|
|
|
|
, fIsScratch(false) {
|
|
|
|
++fNumAlive;
|
|
|
|
this->registerWithCacheWrapped();
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
Mock(int maxCnt, 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);
|
|
|
|
fContext->setResourceCacheLimits(maxCnt, maxBytes);
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceCache* cache = fContext->contextPriv().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
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceCache* cache() { return fContext->contextPriv().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) {
|
|
|
|
Mock mock(10, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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) {
|
|
|
|
Mock mock(10, 30000);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
|
|
|
// 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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(10, 300);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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);
|
2018-06-13 13:41:19 +00:00
|
|
|
TestResource* wrapped = TestResource::CreateWrapped(gpu, 12);
|
|
|
|
TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 13);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2017-05-08 15:16:39 +00:00
|
|
|
// Make sure we can add a unique key to the wrapped resource
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey uniqueKey2;
|
|
|
|
make_unique_key<0>(&uniqueKey2, 1);
|
2015-02-19 16:24:16 +00:00
|
|
|
wrapped->resourcePriv().setUniqueKey(uniqueKey2);
|
2017-05-08 15:16:39 +00:00
|
|
|
GrGpuResource* wrappedViaKey = cache->findAndRefUniqueResource(uniqueKey2);
|
|
|
|
REPORTER_ASSERT(reporter, wrappedViaKey != nullptr);
|
|
|
|
|
|
|
|
// Remove the extra ref we just added.
|
|
|
|
wrappedViaKey->unref();
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
// Make sure sizes are as we expect
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2014-11-17 17:33:27 +00:00
|
|
|
wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
|
|
|
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();
|
|
|
|
REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2014-11-17 17:33:27 +00:00
|
|
|
wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
|
|
|
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
|
|
|
|
|
|
|
// Unreffing the wrapped resource should free it right away.
|
|
|
|
wrapped->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
|
2015-02-11 18:49:59 +00:00
|
|
|
unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
2017-05-24 15:41: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
|
2018-01-22 15:48:15 +00:00
|
|
|
wrapped = TestResource::CreateWrapped(gpu);
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->unref();
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes());
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
2014-11-17 17:33:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() +
|
2015-02-11 18:49:59 +00:00
|
|
|
unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
|
|
|
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();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-17 17:33:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
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
|
|
|
|
|
|
|
wrapped->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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(10, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
wrapped = TestResource::CreateWrapped(gpu, 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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(10, 300);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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());
|
2016-02-25 16:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().isBudgeted());
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
|
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());
|
2015-08-13 12:19:14 +00:00
|
|
|
resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
|
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());
|
2016-02-25 16:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
|
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());
|
2016-02-25 16:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
|
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) {
|
|
|
|
Mock mock(5, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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.)
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(scratchKey1, TestResource::kDefaultSize, 0));
|
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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(5, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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).
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == nullptr);
|
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
|
|
|
|
GrGpuResource* find;
|
2015-08-13 12:19:14 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
|
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.
|
2015-08-13 12:19:14 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
|
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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(5, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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).
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == nullptr);
|
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);
|
2015-08-13 12:19:14 +00:00
|
|
|
GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
|
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;
|
2015-08-13 12:19:14 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0);
|
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);
|
|
|
|
|
2015-08-13 12:19:14 +00:00
|
|
|
GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0);
|
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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(5, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(5, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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.
|
2018-07-11 19:58:57 +00:00
|
|
|
Bus::Post(Msg(key1, context->uniqueID()));
|
|
|
|
Bus::Post(Msg(key2, context->uniqueID()));
|
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.
|
2018-07-11 19:58:57 +00:00
|
|
|
Bus::Post(Msg(key3, context->uniqueID()));
|
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);
|
2015-08-13 12:19:14 +00:00
|
|
|
GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
|
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();
|
2015-08-13 12:19:14 +00:00
|
|
|
scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
|
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) {
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(3, 30000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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 kBudgetCnt = kCount / 2;
|
|
|
|
static const int kLockedFreq = 8;
|
|
|
|
static const int kBudgetSize = 0x80000000;
|
|
|
|
|
|
|
|
SkRandom random;
|
|
|
|
|
|
|
|
// Run the test 2*kCount times;
|
|
|
|
for (int i = 0; i < 2 * kCount; ++i ) {
|
|
|
|
Mock mock(kBudgetCnt, kBudgetSize);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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
|
|
|
|
|
|
|
static const int kNumToPurge = kCount - kBudgetCnt;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 18:01:54 +00:00
|
|
|
static void test_flush(skiatest::Reporter* reporter) {
|
|
|
|
Mock mock(1000000, 1000000);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
2015-04-08 18:01:54 +00:00
|
|
|
|
|
|
|
// The current cache impl will round the max flush count to the next power of 2. So we choose a
|
|
|
|
// power of two here to keep things simpler.
|
|
|
|
static const int kFlushCount = 16;
|
|
|
|
cache->setLimits(1000000, 1000000, kFlushCount);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Insert a resource and send a flush notification kFlushCount times.
|
|
|
|
for (int i = 0; i < kFlushCount; ++i) {
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2015-04-08 18:01:54 +00:00
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, i);
|
|
|
|
r->resourcePriv().setUniqueKey(k);
|
|
|
|
r->unref();
|
2016-09-07 17:02:04 +00:00
|
|
|
cache->notifyFlushOccurred(GrResourceCache::kExternal);
|
2015-04-08 18:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send flush notifications to the cache. Each flush should purge the oldest resource.
|
2016-09-22 19:42:11 +00:00
|
|
|
for (int i = 0; i < kFlushCount; ++i) {
|
|
|
|
cache->notifyFlushOccurred(GrResourceCache::kExternal);
|
2015-04-08 18:01:54 +00:00
|
|
|
REPORTER_ASSERT(reporter, kFlushCount - 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.
|
|
|
|
{
|
|
|
|
GrGpuResource* refedResources[kFlushCount >> 1];
|
|
|
|
for (int i = 0; i < kFlushCount; ++i) {
|
2018-01-22 15:48:15 +00:00
|
|
|
TestResource* r = new TestResource(gpu);
|
2015-04-08 18:01:54 +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[i/2] = r;
|
|
|
|
} else {
|
|
|
|
r->unref();
|
|
|
|
}
|
2016-09-07 17:02:04 +00:00
|
|
|
cache->notifyFlushOccurred(GrResourceCache::kExternal);
|
2015-04-08 18:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kFlushCount; ++i) {
|
|
|
|
// Should get a resource purged every other flush.
|
2016-09-07 17:02:04 +00:00
|
|
|
cache->notifyFlushOccurred(GrResourceCache::kExternal);
|
2016-09-22 19:42:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, kFlushCount - i/2 - 1 == cache->getResourceCount());
|
2015-04-08 18:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unref all the resources that we kept refs on in the first loop.
|
|
|
|
for (int i = 0; i < kFlushCount >> 1; ++i) {
|
|
|
|
refedResources[i]->unref();
|
|
|
|
}
|
|
|
|
|
2016-09-22 19:42:11 +00:00
|
|
|
// After kFlushCount + 1 flushes they all will have sat in the purgeable queue for
|
|
|
|
// kFlushCount full flushes.
|
|
|
|
for (int i = 0; i < kFlushCount + 1; ++i) {
|
2015-04-08 18:01:54 +00:00
|
|
|
REPORTER_ASSERT(reporter, kFlushCount >> 1 == cache->getResourceCount());
|
2016-09-07 17:02:04 +00:00
|
|
|
cache->notifyFlushOccurred(GrResourceCache::kExternal);
|
2015-04-08 18:01:54 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
2016-08-31 18:53:49 +00:00
|
|
|
|
|
|
|
// 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);
|
2016-08-31 18:53:49 +00:00
|
|
|
GrUniqueKey k;
|
|
|
|
make_unique_key<1>(&k, i);
|
|
|
|
r->resourcePriv().setUniqueKey(k);
|
|
|
|
r->unref();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
|
|
|
for (int i = 0; i < 10 * kFlushCount; ++i) {
|
|
|
|
context->flush();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
2015-04-08 18:01:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 18:53:13 +00:00
|
|
|
static void test_time_purge(skiatest::Reporter* reporter) {
|
|
|
|
Mock mock(1000000, 1000000);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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) {
|
|
|
|
Mock mock(6, 100);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ensure all are purged before the next
|
2018-03-06 13:20:37 +00:00
|
|
|
context->contextPriv().purgeAllUnlockedResources_ForTesting();
|
2017-05-25 20:43:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
static void test_large_resource_count(skiatest::Reporter* reporter) {
|
|
|
|
// Set the cache size to double the resource count because we're going to create 2x that number
|
|
|
|
// resources, using two different key domains. Add a little slop to the bytes because we resize
|
|
|
|
// down to 1 byte after creating the resource.
|
2015-01-23 15:19:22 +00:00
|
|
|
static const int kResourceCnt = 2000;
|
2014-11-25 13:52:06 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kResourceCnt; ++i) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<1>(&key1, i);
|
|
|
|
make_unique_key<2>(&key2, i);
|
2015-01-23 12:24:04 +00:00
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
TestResource* resource;
|
|
|
|
|
2018-06-13 13:41:19 +00:00
|
|
|
resource = new TestResource(gpu, SkBudgeted::kYes, 1);
|
2015-02-19 15:24:21 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key1);
|
2014-11-25 13:52:06 +00:00
|
|
|
resource->unref();
|
|
|
|
|
2018-06-13 13:41:19 +00:00
|
|
|
resource = new TestResource(gpu, SkBudgeted::kYes, 1);
|
2015-02-19 15:24:21 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key2);
|
2014-11-25 13:52:06 +00:00
|
|
|
resource->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt);
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->getPurgeableBytes() == 2 * kResourceCnt);
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 2 * kResourceCnt);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 2 * kResourceCnt);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getResourceBytes() == 2 * kResourceCnt);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getResourceCount() == 2 * kResourceCnt);
|
2014-11-25 13:52:06 +00:00
|
|
|
for (int i = 0; i < kResourceCnt; ++i) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<1>(&key1, i);
|
|
|
|
make_unique_key<2>(&key2, i);
|
2015-01-23 12:24:04 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2));
|
2014-11-25 13:52:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-25 13:52:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0);
|
2017-05-24 15:41:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->getPurgeableBytes() == 0);
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->getBudgetedResourceBytes() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getBudgetedResourceCount() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getResourceBytes() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, cache->getResourceCount() == 0);
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kResourceCnt; ++i) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<1>(&key1, i);
|
|
|
|
make_unique_key<2>(&key2, i);
|
2015-01-23 12:24:04 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2));
|
2014-11-25 13:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
Mock mock(10, 300);
|
|
|
|
GrContext* context = mock.context();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
|
|
|
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->abandon();
|
|
|
|
resource->resourcePriv().getScratchKey();
|
|
|
|
resource->resourcePriv().isBudgeted();
|
|
|
|
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;
|
|
|
|
|
|
|
|
Mock mock(kNumResources, kNumResources * TestResource::kDefaultSize);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().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
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:48:08 +00:00
|
|
|
static void test_free_resource_messages(skiatest::Reporter* reporter) {
|
|
|
|
Mock mock(10, 30000);
|
|
|
|
GrContext* context = mock.context();
|
|
|
|
GrResourceCache* cache = mock.cache();
|
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
|
|
|
TestResource* wrapped1 = TestResource::CreateWrapped(gpu, 12);
|
|
|
|
cache->insertCrossContextGpuResource(wrapped1);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
TestResource* wrapped2 = TestResource::CreateWrapped(gpu, 12);
|
|
|
|
cache->insertCrossContextGpuResource(wrapped2);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// Have only ref waiting on message.
|
|
|
|
wrapped1->unref();
|
|
|
|
wrapped2->unref();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
// This should free nothing since no messages were sent.
|
|
|
|
cache->purgeAsNeeded();
|
|
|
|
|
|
|
|
// Send message to free the first resource
|
|
|
|
GrGpuResourceFreedMessage msg { wrapped1, context->uniqueID() };
|
|
|
|
SkMessageBus<GrGpuResourceFreedMessage>::Post(msg);
|
|
|
|
cache->purgeAsNeeded();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
mock.reset();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2015-04-08 18:01:54 +00:00
|
|
|
test_flush(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);
|
2014-11-25 13:52:06 +00:00
|
|
|
test_large_resource_count(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);
|
2018-08-10 13:48:08 +00:00
|
|
|
test_free_resource_messages(reporter);
|
2013-08-08 22:55:21 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2018-03-16 20:47:25 +00:00
|
|
|
GrSurfaceDescFlags descFlags,
|
2016-11-07 13:23:48 +00:00
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
|
|
|
GrSurfaceDesc desc;
|
2018-03-16 20:47:25 +00:00
|
|
|
desc.fFlags = descFlags;
|
2016-11-07 13:23:48 +00:00
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fSampleCnt = sampleCnt;
|
|
|
|
|
2017-04-06 11:59:41 +00:00
|
|
|
return provider->createTexture(desc, SkBudgeted::kYes);
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_mipmap_proxy(GrProxyProvider* proxyProvider,
|
2018-03-16 20:47:25 +00:00
|
|
|
GrSurfaceDescFlags descFlags,
|
2017-04-06 11:59:41 +00:00
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
2016-11-07 13:23:48 +00:00
|
|
|
GrSurfaceDesc desc;
|
2018-03-16 20:47:25 +00:00
|
|
|
desc.fFlags = descFlags;
|
2016-11-07 13:23:48 +00:00
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fSampleCnt = sampleCnt;
|
|
|
|
|
2018-03-16 20:47:25 +00:00
|
|
|
auto origin = (descFlags & kRenderTarget_GrSurfaceFlag) ? kBottomLeft_GrSurfaceOrigin
|
|
|
|
: kTopLeft_GrSurfaceOrigin;
|
2018-03-04 03:43:43 +00:00
|
|
|
|
|
|
|
return proxyProvider->createMipMapProxy(desc, origin, SkBudgeted::kYes);
|
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();
|
2018-01-08 18:40:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
|
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;
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 1);
|
2017-04-06 11:59:41 +00:00
|
|
|
size_t size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
|
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
size_t sampleCount = (size_t)context->contextPriv().caps()->getRenderTargetSampleCount(
|
|
|
|
4, kRGBA_8888_GrPixelConfig);
|
2017-07-19 18:47:42 +00:00
|
|
|
if (sampleCount >= 4) {
|
2018-01-08 18:40:32 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, kRenderTarget_GrSurfaceFlag, 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
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = make_normal_texture(resourceProvider, kNone_GrSurfaceFlags, 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-05-11 14:14:21 +00:00
|
|
|
if (context->contextPriv().caps()->mipMapSupport()) {
|
2017-04-06 11:59:41 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2016-11-07 13:23:48 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
proxy = make_mipmap_proxy(proxyProvider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 1);
|
2017-04-06 11:59:41 +00:00
|
|
|
size_t size = proxy->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
size_t sampleCount = (size_t)context->contextPriv().caps()->getRenderTargetSampleCount(
|
|
|
|
4, kRGBA_8888_GrPixelConfig);
|
2017-07-19 18:47:42 +00:00
|
|
|
if (sampleCount >= 4) {
|
2018-01-08 18:40:32 +00:00
|
|
|
proxy = make_mipmap_proxy(proxyProvider, kRenderTarget_GrSurfaceFlag, kSize, kSize,
|
2017-07-19 18:47:42 +00:00
|
|
|
sampleCount);
|
2017-04-06 11:59:41 +00:00
|
|
|
size = proxy->gpuMemorySize();
|
|
|
|
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
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
proxy = make_mipmap_proxy(proxyProvider, kNone_GrSurfaceFlags, kSize, kSize, 1);
|
2017-04-06 11:59:41 +00:00
|
|
|
size = proxy->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
}
|
2016-11-07 13:23:48 +00:00
|
|
|
}
|