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 here to ensure SK_SUPPORT_GPU is set correctly before it is examined.
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2013-08-08 22:55:21 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-01-10 22:08:27 +00:00
|
|
|
|
2014-10-08 15:40:09 +00:00
|
|
|
#include "GrContext.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"
|
2015-02-23 17:06:38 +00:00
|
|
|
#include "GrRenderTarget.h"
|
|
|
|
#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"
|
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);
|
|
|
|
size_t srcSize = src.getSize();
|
|
|
|
|
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);
|
|
|
|
canvas->readPixels(size, &readback);
|
|
|
|
|
|
|
|
// "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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This currently fails on ES3 ANGLE contexts
|
|
|
|
DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angle_es3, reporter,
|
|
|
|
ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2015-02-19 17:09:00 +00:00
|
|
|
GrSurfaceDesc smallDesc;
|
|
|
|
smallDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2016-10-14 13:16:21 +00:00
|
|
|
smallDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-02-19 17:09:00 +00:00
|
|
|
smallDesc.fWidth = 4;
|
|
|
|
smallDesc.fHeight = 4;
|
|
|
|
smallDesc.fSampleCnt = 0;
|
|
|
|
|
2015-04-30 21:18:54 +00:00
|
|
|
GrTextureProvider* cache = context->textureProvider();
|
2015-09-14 19:56:10 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->resourceProvider();
|
2015-02-19 17:09:00 +00:00
|
|
|
// Test that two budgeted RTs with the same desc share a stencil buffer.
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallRT0(cache->createTexture(smallDesc, SkBudgeted::kYes));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallRT0 && smallRT0->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallRT1(cache->createTexture(smallDesc, SkBudgeted::kYes));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallRT1 && smallRT1->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 18:22:42 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
smallRT0 && smallRT1 &&
|
|
|
|
smallRT0->asRenderTarget() && smallRT1->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()) ==
|
|
|
|
resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget()));
|
2015-02-19 17:09:00 +00:00
|
|
|
|
|
|
|
// An unbudgeted RT with the same desc should also share.
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallRT2(cache->createTexture(smallDesc, SkBudgeted::kNo));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallRT2 && smallRT2->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT2->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
2015-04-16 18:22:42 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
smallRT0 && smallRT2 &&
|
|
|
|
smallRT0->asRenderTarget() && smallRT2->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()) ==
|
|
|
|
resourceProvider->attachStencilAttachment(smallRT2->asRenderTarget()));
|
2015-02-19 17:09:00 +00:00
|
|
|
|
|
|
|
// An RT with a much larger size should not share.
|
|
|
|
GrSurfaceDesc bigDesc;
|
|
|
|
bigDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2016-10-14 13:16:21 +00:00
|
|
|
bigDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-02-19 17:09:00 +00:00
|
|
|
bigDesc.fWidth = 400;
|
|
|
|
bigDesc.fHeight = 200;
|
|
|
|
bigDesc.fSampleCnt = 0;
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> bigRT(cache->createTexture(bigDesc, SkBudgeted::kNo));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (bigRT && bigRT->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(bigRT->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
2015-04-16 18:22:42 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
smallRT0 && bigRT &&
|
|
|
|
smallRT0->asRenderTarget() && bigRT->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()) !=
|
|
|
|
resourceProvider->attachStencilAttachment(bigRT->asRenderTarget()));
|
2015-02-19 17:09:00 +00:00
|
|
|
|
2015-05-29 15:02:10 +00:00
|
|
|
if (context->caps()->maxSampleCount() >= 4) {
|
2016-03-16 17:28:35 +00:00
|
|
|
// An RT with a different sample count should not share.
|
2015-02-19 17:09:00 +00:00
|
|
|
GrSurfaceDesc smallMSAADesc = smallDesc;
|
|
|
|
smallMSAADesc.fSampleCnt = 4;
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallMSAART0 && smallMSAART0->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-23 17:06:38 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
smallRT0 && smallMSAART0 &&
|
|
|
|
smallRT0->asRenderTarget() && smallMSAART0->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()) !=
|
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget()));
|
2015-02-19 17:09:00 +00:00
|
|
|
// A second MSAA RT should share with the first MSAA RT.
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
smallMSAART0 && smallMSAART1 &&
|
|
|
|
smallMSAART0->asRenderTarget() &&
|
|
|
|
smallMSAART1->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget()) ==
|
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget()));
|
2015-02-19 17:09:00 +00:00
|
|
|
// But not one with a larger sample count should not. (Also check that the request for 4
|
|
|
|
// samples didn't get rounded up to >= 8 or else they could share.).
|
2015-05-29 15:02:10 +00:00
|
|
|
if (context->caps()->maxSampleCount() >= 8 &&
|
|
|
|
smallMSAART0 && smallMSAART0->asRenderTarget() &&
|
2015-06-12 15:59:45 +00:00
|
|
|
smallMSAART0->asRenderTarget()->numColorSamples() < 8) {
|
2015-02-19 17:09:00 +00:00
|
|
|
smallMSAADesc.fSampleCnt = 8;
|
2016-02-25 16:33:02 +00:00
|
|
|
smallMSAART1.reset(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrTexture> smallMSAART1(
|
2016-02-25 16:33:02 +00:00
|
|
|
cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
|
2015-02-23 17:06:38 +00:00
|
|
|
if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget());
|
2015-02-23 17:06:38 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter,
|
2015-04-16 18:22:42 +00:00
|
|
|
smallMSAART0 && smallMSAART1 &&
|
|
|
|
smallMSAART0->asRenderTarget() &&
|
|
|
|
smallMSAART1->asRenderTarget() &&
|
2015-09-14 19:56:10 +00:00
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget()) !=
|
|
|
|
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget()));
|
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();
|
2016-02-05 15:17:34 +00:00
|
|
|
GrGpu* gpu = context->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;
|
|
|
|
}
|
|
|
|
|
2015-11-10 19:54:56 +00:00
|
|
|
GrBackendObject texHandles[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
|
|
|
|
2015-11-10 19:54:56 +00:00
|
|
|
texHandles[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig);
|
|
|
|
texHandles[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig);
|
2015-07-13 14:19:57 +00:00
|
|
|
|
2015-06-18 16:12:16 +00:00
|
|
|
context->resetContext();
|
|
|
|
|
|
|
|
GrBackendTextureDesc desc;
|
|
|
|
desc.fConfig = kBGRA_8888_GrPixelConfig;
|
|
|
|
desc.fWidth = kW;
|
|
|
|
desc.fHeight = kH;
|
|
|
|
|
2015-11-10 19:54:56 +00:00
|
|
|
desc.fTextureHandle = texHandles[0];
|
2016-10-27 16:30:08 +00:00
|
|
|
sk_sp<GrTexture> borrowed(context->textureProvider()->wrapBackendTexture(
|
|
|
|
desc, kBorrow_GrWrapOwnership));
|
2015-06-18 16:12:16 +00:00
|
|
|
|
2015-11-10 19:54:56 +00:00
|
|
|
desc.fTextureHandle = texHandles[1];
|
2016-10-27 16:30:08 +00:00
|
|
|
sk_sp<GrTexture> adopted(context->textureProvider()->wrapBackendTexture(
|
|
|
|
desc, kAdopt_GrWrapOwnership));
|
2015-06-18 16:12:16 +00:00
|
|
|
|
2016-10-27 16:30:08 +00:00
|
|
|
printf("\nborrowed: %p, adopted: %p\n", borrowed.get(), adopted.get());
|
2016-03-16 17:28:35 +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();
|
|
|
|
|
2015-11-10 19:54:56 +00:00
|
|
|
bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]);
|
|
|
|
bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]);
|
2015-06-18 16:12:16 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, borrowedIsAlive);
|
|
|
|
REPORTER_ASSERT(reporter, !adoptedIsAlive);
|
|
|
|
|
2015-11-11 20:40:42 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive);
|
|
|
|
gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive);
|
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,
|
|
|
|
SimulatedProperty property) {
|
|
|
|
return new TestResource(gpu, budgeted, property, kScratchConstructor);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
~TestResource() {
|
2014-11-05 22:47:41 +00:00
|
|
|
--fNumAlive;
|
2014-11-14 20:10:14 +00:00
|
|
|
SkSafeUnref(fToDelete);
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:09:13 +00:00
|
|
|
void setSize(size_t size) {
|
|
|
|
fSize = size;
|
|
|
|
this->didChangeGpuMemorySize();
|
|
|
|
}
|
|
|
|
|
2014-11-05 22:47:41 +00:00
|
|
|
static int NumAlive() { return fNumAlive; }
|
2014-01-15 23:09:01 +00:00
|
|
|
|
2014-11-14 20:10:14 +00:00
|
|
|
void setUnrefWhenDestroyed(TestResource* resource) {
|
|
|
|
SkRefCnt_SafeAssign(fToDelete, 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
|
|
|
|
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, SimulatedProperty property, ScratchConstructor)
|
|
|
|
: INHERITED(gpu)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fToDelete(nullptr)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fSize(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
|
|
|
, 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; }
|
2014-11-12 19:13:39 +00:00
|
|
|
|
2014-01-15 23:09:01 +00:00
|
|
|
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) {
|
|
|
|
fContext.reset(GrContext::CreateMockContext());
|
|
|
|
SkASSERT(fContext);
|
|
|
|
fContext->setResourceCacheLimits(maxCnt, maxBytes);
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = fContext->getResourceCache();
|
|
|
|
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
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache() { return fContext->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
|
|
|
|
|
|
|
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();
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
// Create a bunch of resources with no keys
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
|
|
|
TestResource* c = new TestResource(context->getGpu());
|
|
|
|
TestResource* d = new TestResource(context->getGpu());
|
2014-11-14 20:10:14 +00:00
|
|
|
a->setSize(11);
|
|
|
|
b->setSize(12);
|
|
|
|
c->setSize(13);
|
|
|
|
d->setSize(14);
|
|
|
|
|
|
|
|
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.
|
2015-02-19 15:24:21 +00:00
|
|
|
template <int> static void make_unique_key(GrUniqueKey* key, int data) {
|
|
|
|
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
|
|
|
|
GrUniqueKey::Builder builder(key, d, 1);
|
2015-01-23 12:24:04 +00:00
|
|
|
builder[0] = data;
|
|
|
|
}
|
|
|
|
|
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();
|
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 =
|
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::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty);
|
2014-11-17 15:34:06 +00:00
|
|
|
scratch->setSize(10);
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* unique = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->setSize(11);
|
2015-02-19 16:24:16 +00:00
|
|
|
unique->resourcePriv().setUniqueKey(uniqueKey);
|
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* wrapped = TestResource::CreateWrapped(context->getGpu());
|
2015-01-14 18:42:08 +00:00
|
|
|
wrapped->setSize(12);
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* unbudgeted =
|
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
|
|
|
new TestResource(context->getGpu(), SkBudgeted::kNo);
|
2014-11-17 17:33:27 +00:00
|
|
|
unbudgeted->setSize(13);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
// Make sure we can't add a unique key to the wrapped resource
|
|
|
|
GrUniqueKey uniqueKey2;
|
|
|
|
make_unique_key<0>(&uniqueKey2, 1);
|
2015-02-19 16:24:16 +00:00
|
|
|
wrapped->resourcePriv().setUniqueKey(uniqueKey2);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == cache->findAndRefUniqueResource(uniqueKey2));
|
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());
|
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());
|
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());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
2014-11-17 17:33:27 +00:00
|
|
|
// Now try freeing the budgeted resources first
|
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
|
|
|
wrapped = TestResource::CreateWrapped(context->getGpu());
|
2014-11-17 15:34:06 +00:00
|
|
|
scratch->setSize(12);
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->unref();
|
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());
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
scratch->unref();
|
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());
|
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());
|
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());
|
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();
|
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.
|
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
|
|
|
scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
|
|
|
TestResource::kB_SimulatedProperty);
|
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
scratch->setSize(10);
|
|
|
|
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());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
unique = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
unique->setSize(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());
|
2015-01-14 18:42:08 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
size_t large = 2 * cache->getResourceBytes();
|
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
|
|
|
unbudgeted = new TestResource(context->getGpu(), 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());
|
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());
|
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
|
|
|
wrapped = TestResource::CreateWrapped(context->getGpu(), 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());
|
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());
|
|
|
|
|
|
|
|
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());
|
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();
|
2015-01-23 15:19:22 +00:00
|
|
|
|
|
|
|
TestResource* resource =
|
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::CreateScratch(context->getGpu(), 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());
|
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());
|
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());
|
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());
|
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();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
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,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
|
|
|
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
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,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
2014-11-10 18:19:06 +00:00
|
|
|
a->setSize(11);
|
|
|
|
b->setSize(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();
|
2014-11-25 13:52:06 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
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* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
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* b = TestResource::CreateScratch(context->getGpu(), 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();
|
2015-01-21 17:32:40 +00:00
|
|
|
|
|
|
|
// Create two resources that have the same scratch key.
|
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* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::kB_SimulatedProperty);
|
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* b = TestResource::CreateScratch(context->getGpu(), 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();
|
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.
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
2014-11-10 18:19:06 +00:00
|
|
|
a->setSize(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.
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
2015-02-19 16:24:16 +00:00
|
|
|
b->setSize(12);
|
|
|
|
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();
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* c = new TestResource(context->getGpu());
|
2015-02-19 16:24:16 +00:00
|
|
|
GrUniqueKey differentKey;
|
|
|
|
make_unique_key<0>(&differentKey, 1);
|
|
|
|
c->setSize(13);
|
|
|
|
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);
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<TestResource> d(new TestResource(context->getGpu()));
|
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();
|
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.
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
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* c = TestResource::CreateScratch(context->getGpu(), 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.
|
|
|
|
Bus::Post(Msg(key1));
|
|
|
|
Bus::Post(Msg(key2));
|
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.
|
2015-02-06 19:54:28 +00:00
|
|
|
Bus::Post(Msg(key3));
|
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();
|
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
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
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
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
a->unref();
|
|
|
|
b->unref();
|
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
|
2015-08-27 14:41:13 +00:00
|
|
|
a->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
|
|
|
}
|
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
static void test_resource_size_changed(skiatest::Reporter* reporter) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
make_unique_key<0>(&key1, 1);
|
|
|
|
make_unique_key<0>(&key2, 2);
|
2014-05-05 19:09:13 +00:00
|
|
|
|
|
|
|
// Test changing resources sizes (both increase & decrease).
|
|
|
|
{
|
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();
|
2014-05-05 19:09:13 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
a->resourcePriv().setUniqueKey(key1);
|
2014-05-05 19:09:13 +00:00
|
|
|
a->unref();
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
b->resourcePriv().setUniqueKey(key2);
|
2014-05-05 19:09:13 +00:00
|
|
|
b->unref();
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-10 18:19:06 +00:00
|
|
|
{
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<TestResource> find2(
|
2015-02-19 15:24:21 +00:00
|
|
|
static_cast<TestResource*>(cache->findAndRefUniqueResource(key2)));
|
2014-11-10 18:19:06 +00:00
|
|
|
find2->setSize(200);
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<TestResource> find1(
|
2015-02-19 15:24:21 +00:00
|
|
|
static_cast<TestResource*>(cache->findAndRefUniqueResource(key1)));
|
2014-11-10 18:19:06 +00:00
|
|
|
find1->setSize(50);
|
|
|
|
}
|
2014-05-05 19:09:13 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 250 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-05-05 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test increasing a resources size beyond the cache budget.
|
|
|
|
{
|
2015-01-23 15:19:22 +00:00
|
|
|
Mock mock(2, 300);
|
|
|
|
GrContext* context = mock.context();
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = mock.cache();
|
2014-05-05 19:09:13 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* a = new TestResource(context->getGpu());
|
2014-11-10 18:19:06 +00:00
|
|
|
a->setSize(100);
|
2015-02-19 15:24:21 +00:00
|
|
|
a->resourcePriv().setUniqueKey(key1);
|
2014-05-05 19:09:13 +00:00
|
|
|
a->unref();
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* b = new TestResource(context->getGpu());
|
2014-11-10 18:19:06 +00:00
|
|
|
b->setSize(100);
|
2015-02-19 15:24:21 +00:00
|
|
|
b->resourcePriv().setUniqueKey(key2);
|
2014-05-05 19:09:13 +00:00
|
|
|
b->unref();
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-05-05 19:09:13 +00:00
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
{
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<TestResource> find2(static_cast<TestResource*>(
|
2015-02-19 15:24:21 +00:00
|
|
|
cache->findAndRefUniqueResource(key2)));
|
2014-11-10 18:19:06 +00:00
|
|
|
find2->setSize(201);
|
|
|
|
}
|
2015-02-19 15:24:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1));
|
2014-05-05 19:09:13 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes());
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
2014-05-05 19:09:13 +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();
|
|
|
|
|
|
|
|
// Pick a random number of resources to add before the timestamp will wrap.
|
|
|
|
cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* r = new TestResource(context->getGpu());
|
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();
|
|
|
|
|
|
|
|
// 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) {
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* r = new TestResource(context->getGpu());
|
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) {
|
2015-08-26 20:07:48 +00:00
|
|
|
TestResource* r = new TestResource(context->getGpu());
|
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) {
|
|
|
|
TestResource* r = new TestResource(context->getGpu());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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();
|
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;
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
resource = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key1);
|
2014-11-25 13:52:06 +00:00
|
|
|
resource->setSize(1);
|
|
|
|
resource->unref();
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
resource = new TestResource(context->getGpu());
|
2015-02-19 15:24:21 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key2);
|
2014-11-25 13:52:06 +00:00
|
|
|
resource->setSize(1);
|
|
|
|
resource->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, TestResource::NumAlive() == 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);
|
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();
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrGpuResource> resource(new TestResource(context->getGpu()));
|
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();
|
|
|
|
}
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
|
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);
|
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);
|
2014-11-10 18:19:06 +00:00
|
|
|
test_resource_size_changed(reporter);
|
2015-02-19 19:38:44 +00:00
|
|
|
test_timestamp_wrap(reporter);
|
2015-04-08 18:01:54 +00:00
|
|
|
test_flush(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);
|
2013-08-08 22:55:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 13:23:48 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static sk_sp<GrTexture> make_normal_texture(GrTextureProvider* provider,
|
|
|
|
GrSurfaceFlags flags,
|
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = flags;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fSampleCnt = sampleCnt;
|
|
|
|
|
|
|
|
return sk_sp<GrTexture>(provider->createTexture(desc, SkBudgeted::kYes));
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<GrTexture> make_mipmap_texture(GrTextureProvider* provider,
|
|
|
|
GrSurfaceFlags flags,
|
|
|
|
int width, int height,
|
|
|
|
int sampleCnt) {
|
|
|
|
SkBitmap bm;
|
|
|
|
|
|
|
|
bm.allocN32Pixels(width, height, true);
|
|
|
|
bm.eraseColor(SK_ColorBLUE);
|
|
|
|
|
2016-11-08 22:08:54 +00:00
|
|
|
sk_sp<SkMipMap> mipmaps(SkMipMap::Build(bm, SkDestinationSurfaceColorMode::kLegacy, nullptr));
|
2016-11-07 13:23:48 +00:00
|
|
|
SkASSERT(mipmaps);
|
|
|
|
SkASSERT(mipmaps->countLevels() > 1);
|
|
|
|
|
|
|
|
int mipLevelCount = mipmaps->countLevels() + 1;
|
|
|
|
|
|
|
|
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
|
|
|
|
|
|
|
|
texels[0].fPixels = bm.getPixels();
|
|
|
|
texels[0].fRowBytes = bm.rowBytes();
|
|
|
|
|
|
|
|
for (int i = 1; i < mipLevelCount; ++i) {
|
|
|
|
SkMipMap::Level generatedMipLevel;
|
|
|
|
mipmaps->getLevel(i - 1, &generatedMipLevel);
|
|
|
|
texels[i].fPixels = generatedMipLevel.fPixmap.addr();
|
|
|
|
texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = flags;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fSampleCnt = sampleCnt;
|
|
|
|
desc.fIsMipMapped = true;
|
|
|
|
|
|
|
|
return sk_sp<GrTexture>(provider->createMipMappedTexture(desc, SkBudgeted::kYes,
|
|
|
|
texels.get(), mipLevelCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
GrTextureProvider* provider = context->textureProvider();
|
|
|
|
|
|
|
|
static const int kSize = 64;
|
|
|
|
|
|
|
|
sk_sp<GrTexture> tex;
|
|
|
|
|
|
|
|
// Normal versions
|
|
|
|
tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
|
|
|
|
size_t size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
|
|
|
|
|
|
|
|
if (context->caps()->maxSampleCount() >= 4) {
|
|
|
|
tex = make_normal_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
|
|
|
|
size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size || // msaa4 failed
|
|
|
|
kSize*kSize*4*4 == size || // auto-resolving
|
|
|
|
kSize*kSize*4*5 == size); // explicit resolve buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = make_normal_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
|
|
|
|
size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
|
|
|
|
|
|
|
|
// Mipmapped versions
|
|
|
|
tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 0);
|
|
|
|
size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
|
|
|
|
if (context->caps()->maxSampleCount() >= 4) {
|
|
|
|
tex = make_mipmap_texture(provider, kRenderTarget_GrSurfaceFlag, kSize, kSize, 4);
|
|
|
|
size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed
|
|
|
|
kSize*kSize*4*4+(kSize*kSize*4)/3 == size || // auto-resolving
|
|
|
|
kSize*kSize*4*5+(kSize*kSize*4)/3 == size); // explicit resolve buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = make_mipmap_texture(provider, kNone_GrSurfaceFlags, kSize, kSize, 0);
|
|
|
|
size = tex->gpuMemorySize();
|
|
|
|
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-08 22:55:21 +00:00
|
|
|
#endif
|