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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-11 18:49:59 +00:00
|
|
|
#include "GrResourceCache.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"
|
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;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-11-05 22:47:41 +00:00
|
|
|
static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanvas* canvas) {
|
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;
|
|
|
|
context->getResourceCacheUsage(NULL, &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;
|
|
|
|
context->getResourceCacheUsage(NULL, &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
|
|
|
}
|
|
|
|
|
2014-07-25 15:35:45 +00:00
|
|
|
class TestResource : public GrGpuResource {
|
2014-05-05 19:09:13 +00:00
|
|
|
static const size_t kDefaultSize = 100;
|
2015-01-21 17:32:40 +00:00
|
|
|
enum ScratchConstructor { kScratchConstructor };
|
2014-01-15 23:09:01 +00:00
|
|
|
public:
|
|
|
|
SK_DECLARE_INST_COUNT(TestResource);
|
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
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
|
|
|
|
: INHERITED(gpu, lifeCycle)
|
|
|
|
, fToDelete(NULL)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fSize(size)
|
2015-02-06 19:54:28 +00:00
|
|
|
, fProperty(kA_SimulatedProperty) {
|
2015-01-14 18:42:08 +00:00
|
|
|
++fNumAlive;
|
|
|
|
this->registerWithCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle)
|
|
|
|
: INHERITED(gpu, lifeCycle)
|
2014-11-17 15:34:06 +00:00
|
|
|
, fToDelete(NULL)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fSize(kDefaultSize)
|
2015-02-06 19:54:28 +00:00
|
|
|
, fProperty(kA_SimulatedProperty) {
|
2014-11-17 15:34:06 +00:00
|
|
|
++fNumAlive;
|
|
|
|
this->registerWithCache();
|
|
|
|
}
|
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
TestResource(GrGpu* gpu)
|
2015-01-14 18:42:08 +00:00
|
|
|
: INHERITED(gpu, kCached_LifeCycle)
|
2014-05-05 19:09:13 +00:00
|
|
|
, fToDelete(NULL)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fSize(kDefaultSize)
|
2015-02-06 19:54:28 +00:00
|
|
|
, fProperty(kA_SimulatedProperty) {
|
2014-11-10 18:19:06 +00:00
|
|
|
++fNumAlive;
|
|
|
|
this->registerWithCache();
|
|
|
|
}
|
|
|
|
|
2015-02-06 19:54:28 +00:00
|
|
|
static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) {
|
2015-01-23 15:19:22 +00:00
|
|
|
return SkNEW_ARGS(TestResource, (gpu, property, cached, kScratchConstructor));
|
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
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor)
|
|
|
|
: INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle)
|
2015-01-21 17:32:40 +00:00
|
|
|
, fToDelete(NULL)
|
|
|
|
, fSize(kDefaultSize)
|
|
|
|
, fProperty(property) {
|
|
|
|
GrScratchKey scratchKey;
|
|
|
|
ComputeScratchKey(fProperty, &scratchKey);
|
|
|
|
this->setScratchKey(scratchKey);
|
|
|
|
++fNumAlive;
|
|
|
|
this->registerWithCache();
|
|
|
|
}
|
|
|
|
|
2014-11-12 19:13:39 +00:00
|
|
|
size_t onGpuMemorySize() const SK_OVERRIDE { return fSize; }
|
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
GrContext* context() { return fContext; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTUnref<GrContext> fContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
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-01-14 18:42:08 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* d = SkNEW_ARGS(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());
|
|
|
|
|
|
|
|
// Since the resources have neither content nor scratch keys, delete immediately upon unref.
|
|
|
|
|
|
|
|
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.
|
|
|
|
template <int> static void make_content_key(GrContentKey* key, int data) {
|
|
|
|
static GrContentKey::Domain d = GrContentKey::GenerateDomain();
|
|
|
|
GrContentKey::Builder builder(key, d, 1);
|
|
|
|
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-01-23 12:24:04 +00:00
|
|
|
GrContentKey contentKey;
|
|
|
|
make_content_key<0>(&contentKey, 0);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
// Create a scratch, a content, and a wrapped resource
|
2015-01-21 17:32:40 +00:00
|
|
|
TestResource* scratch =
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty);
|
2014-11-17 15:34:06 +00:00
|
|
|
scratch->setSize(10);
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
content->setSize(11);
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* wrapped = SkNEW_ARGS(TestResource,
|
|
|
|
(context->getGpu(), GrGpuResource::kWrapped_LifeCycle));
|
|
|
|
wrapped->setSize(12);
|
|
|
|
TestResource* unbudgeted = SkNEW_ARGS(TestResource,
|
|
|
|
(context->getGpu(), GrGpuResource::kUncached_LifeCycle));
|
2014-11-17 17:33:27 +00:00
|
|
|
unbudgeted->setSize(13);
|
2014-11-17 15:34:06 +00:00
|
|
|
|
|
|
|
// Make sure we can't add a content key to the wrapped resource
|
2015-01-23 12:24:04 +00:00
|
|
|
GrContentKey contentKey2;
|
|
|
|
make_content_key<0>(&contentKey2, 1);
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2));
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == cache->findAndRefContentResource(contentKey2));
|
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());
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->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());
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->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());
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->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());
|
2014-11-17 15:34:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->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());
|
2014-11-17 17:33:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->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
|
2015-01-14 18:42:08 +00:00
|
|
|
wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapped_LifeCycle));
|
2014-11-17 15:34:06 +00:00
|
|
|
scratch->setSize(12);
|
|
|
|
content->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-01-23 12:24:04 +00:00
|
|
|
GrContentKey contentKey;
|
|
|
|
make_content_key<0>(&contentKey, 0);
|
2015-01-14 18:42:08 +00:00
|
|
|
|
|
|
|
TestResource* scratch;
|
|
|
|
TestResource* content;
|
|
|
|
TestResource* wrapped;
|
|
|
|
TestResource* unbudgeted;
|
|
|
|
|
|
|
|
// A large uncached or wrapped resource shouldn't evict anything.
|
2015-02-06 19:54:28 +00:00
|
|
|
scratch = TestResource::CreateScratch(context->getGpu(), 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
|
|
|
|
|
|
|
content = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
content->setSize(11);
|
|
|
|
REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
|
|
|
|
content->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();
|
2015-01-14 18:42:08 +00:00
|
|
|
unbudgeted = SkNEW_ARGS(TestResource,
|
|
|
|
(context->getGpu(), large, GrGpuResource::kUncached_LifeCycle));
|
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
|
|
|
|
|
|
|
wrapped = SkNEW_ARGS(TestResource,
|
|
|
|
(context->getGpu(), large, GrGpuResource::kWrapped_LifeCycle));
|
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-01-23 15:19:22 +00:00
|
|
|
static void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) {
|
|
|
|
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 =
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty, false);
|
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.
|
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().getScratchKey() == key);
|
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
|
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().isBudgeted());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key));
|
|
|
|
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());
|
|
|
|
resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key));
|
2015-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, resource);
|
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().getScratchKey() == key);
|
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
|
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().isBudgeted());
|
|
|
|
|
|
|
|
if (0 == i) {
|
|
|
|
// If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try
|
|
|
|
// the above tests again.
|
|
|
|
resource->cacheAccess().makeUnbudgeted();
|
|
|
|
} else {
|
|
|
|
// After the second time around, try removing the scratch key
|
|
|
|
resource->cacheAccess().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-01-23 15:19:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().getScratchKey().isValid());
|
|
|
|
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
|
|
|
|
REPORTER_ASSERT(reporter, resource->cacheAccess().isBudgeted());
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
TestResource::kB_SimulatedProperty);
|
|
|
|
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
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-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKey1));
|
2015-01-21 17:32:40 +00:00
|
|
|
|
|
|
|
GrScratchKey scratchKey;
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
|
2015-01-21 17:32:40 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
// Scratch resources are registered with GrResourceCache just by existing. There are 2.
|
2014-11-14 14:47:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));)
|
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-01-23 20:47:59 +00:00
|
|
|
// Our refs mean that the resources are non purgeable.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Unref but don't purge
|
|
|
|
a->unref();
|
|
|
|
b->unref();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));)
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-01-23 20:47:59 +00:00
|
|
|
// Purge again. This time resources should be purgeable.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
|
2014-11-10 18:19:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
static void test_remove_scratch_key(skiatest::Reporter* reporter) {
|
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.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
TestResource::kB_SimulatedProperty);
|
|
|
|
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
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-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL);
|
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-02-11 18:49:59 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey);
|
2014-11-25 13:52:06 +00:00
|
|
|
find->cacheAccess().removeScratchKey();
|
|
|
|
// 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-02-11 18:49:59 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey);
|
2014-11-25 13:52:06 +00:00
|
|
|
find->cacheAccess().removeScratchKey();
|
|
|
|
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.
|
|
|
|
find->cacheAccess().removeScratchKey();
|
|
|
|
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.
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
TestResource::kB_SimulatedProperty);
|
|
|
|
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
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-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL);
|
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-02-11 18:49:59 +00:00
|
|
|
GrGpuResource* find = cache->findAndRefScratchResource(scratchKey);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, find != NULL);
|
|
|
|
find->unref();
|
|
|
|
|
|
|
|
scratchKey2 = scratchKey;
|
2015-02-11 18:49:59 +00:00
|
|
|
find = cache->findAndRefScratchResource(scratchKey2);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, find != NULL);
|
|
|
|
REPORTER_ASSERT(reporter, find == a || find == b);
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2);
|
2015-01-21 17:32:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, find2 != NULL);
|
|
|
|
REPORTER_ASSERT(reporter, find2 == a || find2 == b);
|
|
|
|
REPORTER_ASSERT(reporter, find2 != find);
|
|
|
|
find2->unref();
|
|
|
|
find->unref();
|
|
|
|
}
|
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
static void test_duplicate_content_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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key;
|
|
|
|
make_content_key<0>(&key, 0);
|
2014-11-05 22:47:41 +00:00
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
// Create two resources that we will attempt to register with the same content key.
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2014-11-10 18:19:06 +00:00
|
|
|
a->setSize(11);
|
|
|
|
b->setSize(12);
|
2014-11-14 20:10:14 +00:00
|
|
|
|
|
|
|
// Can't set the same content key on two resources.
|
|
|
|
REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
|
|
|
|
REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
|
|
|
|
|
|
|
|
// Still have two resources because b is still reffed.
|
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, a->gpuMemorySize() + b->gpuMemorySize() ==
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
|
|
|
|
|
|
|
b->unref();
|
2014-11-14 20:10:14 +00:00
|
|
|
// Now b should be gone.
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2014-11-14 20:10:14 +00:00
|
|
|
// Drop the ref on a but it isn't immediately purged as it still has a valid scratch key.
|
2014-11-10 18:19:06 +00:00
|
|
|
a->unref();
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes());
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2, key3;
|
|
|
|
make_content_key<0>(&key1, 1);
|
|
|
|
make_content_key<0>(&key2, 2);
|
|
|
|
make_content_key<0>(&key3, 3);
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-06 19:54:28 +00:00
|
|
|
// Add three resources to the cache. Only c is usable as scratch.
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2015-02-06 19:54:28 +00:00
|
|
|
TestResource* c = TestResource::CreateScratch(context->getGpu(),
|
|
|
|
TestResource::kA_SimulatedProperty);
|
2014-11-14 20:10:14 +00:00
|
|
|
a->cacheAccess().setContentKey(key1);
|
|
|
|
b->cacheAccess().setContentKey(key2);
|
|
|
|
c->cacheAccess().setContentKey(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-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(key2));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(key3));
|
2014-11-05 22:47:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
|
2015-02-06 19:54:28 +00:00
|
|
|
|
|
|
|
typedef GrContentKeyInvalidatedMessage Msg;
|
|
|
|
typedef SkMessageBus<GrContentKeyInvalidatedMessage> Bus;
|
|
|
|
|
|
|
|
// 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-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(key2));
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(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-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(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-02-11 18:49:59 +00:00
|
|
|
GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey);
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, scratch == c);
|
|
|
|
SkSafeUnref(scratch);
|
|
|
|
|
|
|
|
// Get rid of c.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
scratch = cache->findAndRefScratchResource(scratchKey);
|
2014-11-14 20:10:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
|
2015-02-06 19:54:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, !scratch);
|
|
|
|
SkSafeUnref(scratch);
|
2014-01-15 23:09:01 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:10:14 +00:00
|
|
|
static void test_cache_chained_purge(skiatest::Reporter* reporter) {
|
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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2;
|
|
|
|
make_content_key<0>(&key1, 1);
|
|
|
|
make_content_key<0>(&key2, 2);
|
2014-01-17 17:56:21 +00:00
|
|
|
|
2014-11-05 22:47:41 +00:00
|
|
|
|
2015-01-23 15:19:22 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
|
|
|
a->cacheAccess().setContentKey(key1);
|
|
|
|
b->cacheAccess().setContentKey(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
|
|
|
|
a->setUnrefWhenDestroyed(NULL);
|
|
|
|
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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2;
|
|
|
|
make_content_key<0>(&key1, 1);
|
|
|
|
make_content_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-01-14 18:42:08 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2014-11-14 20:10:14 +00:00
|
|
|
a->cacheAccess().setContentKey(key1);
|
2014-05-05 19:09:13 +00:00
|
|
|
a->unref();
|
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2014-11-14 20:10:14 +00:00
|
|
|
b->cacheAccess().setContentKey(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
|
|
|
{
|
2015-02-11 18:49:59 +00:00
|
|
|
SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache->findAndRefContentResource(key2)));
|
2014-11-10 18:19:06 +00:00
|
|
|
find2->setSize(200);
|
2015-02-11 18:49:59 +00:00
|
|
|
SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache->findAndRefContentResource(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-01-14 18:42:08 +00:00
|
|
|
TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2014-11-10 18:19:06 +00:00
|
|
|
a->setSize(100);
|
2014-11-14 20:10:14 +00:00
|
|
|
a->cacheAccess().setContentKey(key1);
|
2014-05-05 19:09:13 +00:00
|
|
|
a->unref();
|
|
|
|
|
2015-01-14 18:42:08 +00:00
|
|
|
TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2014-11-10 18:19:06 +00:00
|
|
|
b->setSize(100);
|
2014-11-14 20:10:14 +00:00
|
|
|
b->cacheAccess().setContentKey(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
|
|
|
{
|
2015-02-11 18:49:59 +00:00
|
|
|
SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache->findAndRefContentResource(key2)));
|
2014-11-10 18:19:06 +00:00
|
|
|
find2->setSize(201);
|
|
|
|
}
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2;
|
|
|
|
make_content_key<1>(&key1, i);
|
|
|
|
make_content_key<2>(&key2, i);
|
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
TestResource* resource;
|
|
|
|
|
|
|
|
resource = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2015-01-23 12:24:04 +00:00
|
|
|
resource->cacheAccess().setContentKey(key1);
|
2014-11-25 13:52:06 +00:00
|
|
|
resource->setSize(1);
|
|
|
|
resource->unref();
|
|
|
|
|
|
|
|
resource = SkNEW_ARGS(TestResource, (context->getGpu()));
|
2015-01-23 12:24:04 +00:00
|
|
|
resource->cacheAccess().setContentKey(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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2;
|
|
|
|
make_content_key<1>(&key1, i);
|
|
|
|
make_content_key<2>(&key2, i);
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, cache->hasContentKey(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-01-23 12:24:04 +00:00
|
|
|
GrContentKey key1, key2;
|
|
|
|
make_content_key<1>(&key1, i);
|
|
|
|
make_content_key<2>(&key2, i);
|
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(key1));
|
|
|
|
REPORTER_ASSERT(reporter, !cache->hasContentKey(key2));
|
2014-11-25 13:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-15 23:09:01 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-01-10 22:08:27 +00:00
|
|
|
DEF_GPUTEST(ResourceCache, reporter, factory) {
|
2013-08-08 22:55:21 +00:00
|
|
|
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
|
|
|
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
|
|
|
if (!GrContextFactory::IsRenderingGLContext(glType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
GrContext* context = factory->get(glType);
|
2014-11-05 20:30:32 +00:00
|
|
|
if (NULL == context) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc desc;
|
2013-08-08 22:55:21 +00:00
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
2014-10-28 21:33:06 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2013-08-08 22:55:21 +00:00
|
|
|
desc.fWidth = gWidth;
|
|
|
|
desc.fHeight = gHeight;
|
2014-09-18 13:09:44 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
|
2015-01-16 15:32:33 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
|
|
|
|
SkSurface::kNo_Budgeted, info));
|
2014-11-05 20:30:32 +00:00
|
|
|
test_cache(reporter, context, surface->getCanvas());
|
2014-11-05 20:09:45 +00:00
|
|
|
}
|
2014-11-05 22:47:41 +00:00
|
|
|
|
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);
|
2014-11-10 18:19:06 +00:00
|
|
|
test_duplicate_content_key(reporter);
|
|
|
|
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);
|
2014-11-25 13:52:06 +00:00
|
|
|
test_large_resource_count(reporter);
|
2013-08-08 22:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|