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