halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 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 | #include "SkDiscardableMemoryPool.h" |
| 8 | |
| 9 | #include "Test.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 10 | |
| 11 | DEF_TEST(DiscardableMemoryPool, reporter) { |
Hal Canary | 788c3c4 | 2017-04-25 08:58:57 -0400 | [diff] [blame] | 12 | sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(1)); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 13 | pool->setRAMBudget(3); |
| 14 | REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
| 15 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 16 | std::unique_ptr<SkDiscardableMemory> dm1(pool->create(100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 17 | REPORTER_ASSERT(reporter, dm1->data() != nullptr); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 18 | REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed()); |
| 19 | dm1->unlock(); |
| 20 | REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
| 21 | REPORTER_ASSERT(reporter, !dm1->lock()); |
| 22 | |
| 23 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 24 | std::unique_ptr<SkDiscardableMemory> dm2(pool->create(200)); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 25 | REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); |
| 26 | pool->setRAMBudget(400); |
| 27 | dm2->unlock(); |
| 28 | REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); |
| 29 | REPORTER_ASSERT(reporter, dm2->lock()); |
| 30 | dm2->unlock(); |
| 31 | pool->dumpPool(); |
| 32 | REPORTER_ASSERT(reporter, !dm2->lock()); |
| 33 | REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
| 34 | } |