OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "SkDiscardableMemory_chrome.h" |
| 6 |
| 7 SkDiscardableMemoryChrome::SkDiscardableMemoryChrome() |
| 8 : discardable_(new base::DiscardableMemory()) { |
| 9 } |
| 10 |
| 11 SkDiscardableMemoryChrome::~SkDiscardableMemoryChrome() { |
| 12 } |
| 13 |
| 14 bool SkDiscardableMemoryChrome::lock() { |
| 15 base::LockDiscardableMemoryStatus status = discardable_->Lock(); |
| 16 switch (status) { |
| 17 case base::DISCARDABLE_MEMORY_SUCCESS: |
| 18 return true; |
| 19 case base::DISCARDABLE_MEMORY_PURGED: |
| 20 discardable_->Unlock(); |
| 21 return false; |
| 22 default: |
| 23 discardable_.reset(); |
| 24 return false; |
| 25 } |
| 26 } |
| 27 |
| 28 void* SkDiscardableMemoryChrome::data() { |
| 29 return discardable_->Memory(); |
| 30 } |
| 31 |
| 32 void SkDiscardableMemoryChrome::unlock() { |
| 33 discardable_->Unlock(); |
| 34 } |
| 35 |
| 36 bool SkDiscardableMemoryChrome::InitializeAndLock(size_t bytes) { |
| 37 return discardable_->InitializeAndLock(bytes); |
| 38 } |
| 39 |
| 40 SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) { |
| 41 if (!base::DiscardableMemory::Supported()) { |
| 42 return NULL; |
| 43 } |
| 44 scoped_ptr<SkDiscardableMemoryChrome> discardable( |
| 45 new SkDiscardableMemoryChrome()); |
| 46 if (discardable->InitializeAndLock(bytes)) |
| 47 return discardable.release(); |
| 48 return NULL; |
| 49 } |
OLD | NEW |