2013-12-05 18:31:42 +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.
|
|
|
|
*/
|
|
|
|
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "SkDiscardableMemory.h"
|
|
|
|
#include "SkDiscardableMemoryPool.h"
|
|
|
|
#include "SkRefCnt.h"
|
2018-05-22 12:23:12 +00:00
|
|
|
#include "Test.h"
|
2018-04-17 21:42:08 +00:00
|
|
|
|
2018-05-22 14:48:08 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
DEF_TEST(DiscardableMemoryPool, reporter) {
|
2017-04-25 12:58:57 +00:00
|
|
|
sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(1));
|
2013-12-05 18:31:42 +00:00
|
|
|
pool->setRAMBudget(3);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkDiscardableMemory> dm1(pool->create(100));
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, dm1->data() != nullptr);
|
2013-12-05 18:31:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed());
|
|
|
|
dm1->unlock();
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
REPORTER_ASSERT(reporter, !dm1->lock());
|
|
|
|
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkDiscardableMemory> dm2(pool->create(200));
|
2013-12-05 18:31:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
|
|
|
|
pool->setRAMBudget(400);
|
|
|
|
dm2->unlock();
|
|
|
|
REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
|
|
|
|
REPORTER_ASSERT(reporter, dm2->lock());
|
|
|
|
dm2->unlock();
|
|
|
|
pool->dumpPool();
|
|
|
|
REPORTER_ASSERT(reporter, !dm2->lock());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
}
|