1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkDiscardableMemory.h"
9 #include "SkDiscardableMemoryPool.h"
10 #include "SkRefCnt.h"
11 #include "Test.h"
12
13 #include <memory>
14
DEF_TEST(DiscardableMemoryPool,reporter)15 DEF_TEST(DiscardableMemoryPool, reporter) {
16 sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(1));
17 pool->setRAMBudget(3);
18 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
19
20 std::unique_ptr<SkDiscardableMemory> dm1(pool->create(100));
21 REPORTER_ASSERT(reporter, dm1->data() != nullptr);
22 REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed());
23 dm1->unlock();
24 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
25 REPORTER_ASSERT(reporter, !dm1->lock());
26
27
28 std::unique_ptr<SkDiscardableMemory> dm2(pool->create(200));
29 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
30 pool->setRAMBudget(400);
31 dm2->unlock();
32 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
33 REPORTER_ASSERT(reporter, dm2->lock());
34 dm2->unlock();
35 pool->dumpPool();
36 REPORTER_ASSERT(reporter, !dm2->lock());
37 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
38 }
39