From 37eb4e4ed1dddcea0a74fee023704b5071ffa754 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Tue, 1 Apr 2014 23:50:53 +0000 Subject: [PATCH] Purge SkPurgeableMemoryBlock. It was an experiment that is no longer used. R=mtklein@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/219133004 git-svn-id: http://skia.googlecode.com/svn/trunk@14020 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gyp/ports.gyp | 7 -- src/lazy/SkPurgeableMemoryBlock.h | 94 ---------------- src/lazy/SkPurgeableMemoryBlock_common.cpp | 16 --- src/ports/SkPurgeableMemoryBlock_android.cpp | 110 ------------------- src/ports/SkPurgeableMemoryBlock_mac.cpp | 104 ------------------ src/ports/SkPurgeableMemoryBlock_none.cpp | 40 ------- 6 files changed, 371 deletions(-) delete mode 100644 src/lazy/SkPurgeableMemoryBlock.h delete mode 100644 src/lazy/SkPurgeableMemoryBlock_common.cpp delete mode 100644 src/ports/SkPurgeableMemoryBlock_android.cpp delete mode 100644 src/ports/SkPurgeableMemoryBlock_mac.cpp delete mode 100644 src/ports/SkPurgeableMemoryBlock_none.cpp diff --git a/gyp/ports.gyp b/gyp/ports.gyp index f5f7bbf7d..d3790067e 100644 --- a/gyp/ports.gyp +++ b/gyp/ports.gyp @@ -51,7 +51,6 @@ '../src/ports/SkOSFile_stdio.cpp', '../src/ports/SkOSFile_win.cpp', '../src/ports/SkDiscardableMemory_none.cpp', - '../src/ports/SkPurgeableMemoryBlock_none.cpp', '../src/ports/SkTime_Unix.cpp', '../src/ports/SkTime_win.cpp', #'../src/ports/SkTLS_none.cpp', @@ -119,11 +118,9 @@ ], 'sources': [ '../src/ports/SkFontHost_mac.cpp', - '../src/ports/SkPurgeableMemoryBlock_mac.cpp', '../src/utils/mac/SkStream_mac.cpp', ], 'sources!': [ - '../src/ports/SkPurgeableMemoryBlock_none.cpp', '../src/ports/SkFontHost_tables.cpp', ], }], @@ -134,11 +131,9 @@ ], 'sources': [ '../src/ports/SkFontHost_mac.cpp', - '../src/ports/SkPurgeableMemoryBlock_mac.cpp', '../src/utils/mac/SkStream_mac.cpp', ], 'sources!': [ - '../src/ports/SkPurgeableMemoryBlock_none.cpp', '../src/ports/SkFontHost_tables.cpp', ], }], @@ -182,7 +177,6 @@ 'sources!': [ '../src/ports/SkDebug_stdio.cpp', '../src/ports/SkDiscardableMemory_none.cpp', - '../src/ports/SkPurgeableMemoryBlock_none.cpp', ], 'sources': [ '../src/ports/SkDebug_android.cpp', @@ -190,7 +184,6 @@ '../src/ports/SkFontConfigInterface_android.cpp', '../src/ports/SkFontConfigParser_android.cpp', '../src/ports/SkFontHost_fontconfig.cpp', - '../src/ports/SkPurgeableMemoryBlock_android.cpp', ], 'dependencies': [ 'android_deps.gyp:expat', diff --git a/src/lazy/SkPurgeableMemoryBlock.h b/src/lazy/SkPurgeableMemoryBlock.h deleted file mode 100644 index 1750ad9d6..000000000 --- a/src/lazy/SkPurgeableMemoryBlock.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkPurgeableMemoryBlock_DEFINED -#define SkPurgeableMemoryBlock_DEFINED - -#include "SkTypes.h" - -class SkPurgeableMemoryBlock : public SkNoncopyable { - -public: - /** - * Whether or not this platform has an implementation for purgeable memory. - */ - static bool IsSupported(); - - /** - * Create a new purgeable memory block of 'size' bytes. Returns NULL if not supported on this - * platform or on failure. - * @param size Number of bytes requested. - * @return A new block, or NULL on failure. - */ - static SkPurgeableMemoryBlock* Create(size_t size); - -#ifdef SK_DEBUG - /** - * Whether the platform supports one shot purge of all unpinned blocks. If so, - * PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge will be called on - * individual blocks. - */ - static bool PlatformSupportsPurgingAllUnpinnedBlocks(); - - /** - * Purge all unpinned blocks at once, if the platform supports it. - */ - static bool PurgeAllUnpinnedBlocks(); - - // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not be called, so it can - // simply return false. - bool purge(); - - bool isPinned() const { return fPinned; } -#endif - - ~SkPurgeableMemoryBlock(); - - /** - * Output parameter for pin(), stating whether the data has been retained. - */ - enum PinResult { - /** - * The data has been purged, or this is the first call to pin. - */ - kUninitialized_PinResult, - - /** - * The data has been retained. The memory contains the same data it held when unpin() was - * called. - */ - kRetained_PinResult, - }; - - /** - * Pin the memory for use. Must not be called while already pinned. - * @param PinResult Whether the data was retained. Ignored on failure. - * @return Pointer to the pinned data on success. NULL on failure. - */ - void* pin(PinResult*); - - /** - * Unpin the data so it can be purged if necessary. - */ - void unpin(); - -private: - void* fAddr; - size_t fSize; - bool fPinned; -#ifdef SK_BUILD_FOR_ANDROID - int fFD; -#endif - - // Unimplemented default constructor is private, to prevent manual creation. - SkPurgeableMemoryBlock(); - - // The correct way to create a new one is from the static Create. - SkPurgeableMemoryBlock(size_t); -}; - -#endif // SkPurgeableMemoryBlock_DEFINED diff --git a/src/lazy/SkPurgeableMemoryBlock_common.cpp b/src/lazy/SkPurgeableMemoryBlock_common.cpp deleted file mode 100644 index a549c46e2..000000000 --- a/src/lazy/SkPurgeableMemoryBlock_common.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPurgeableMemoryBlock.h" - -SkPurgeableMemoryBlock* SkPurgeableMemoryBlock::Create(size_t size) { - SkASSERT(IsSupported()); - if (!IsSupported()) { - return NULL; - } - return SkNEW_ARGS(SkPurgeableMemoryBlock, (size)); -} diff --git a/src/ports/SkPurgeableMemoryBlock_android.cpp b/src/ports/SkPurgeableMemoryBlock_android.cpp deleted file mode 100644 index acabb0d80..000000000 --- a/src/ports/SkPurgeableMemoryBlock_android.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPurgeableMemoryBlock.h" - -#include "android/ashmem.h" -#include -#include - -bool SkPurgeableMemoryBlock::IsSupported() { - return true; -} - -#ifdef SK_DEBUG -bool SkPurgeableMemoryBlock::PlatformSupportsPurgingAllUnpinnedBlocks() { - return false; -} - -bool SkPurgeableMemoryBlock::PurgeAllUnpinnedBlocks() { - return false; -} - -bool SkPurgeableMemoryBlock::purge() { - SkASSERT(!fPinned); - if (-1 != fFD) { - ashmem_purge_all_caches(fFD); - return true; - } else { - return false; - } -} -#endif - -// ashmem likes lengths on page boundaries. -static size_t round_to_page_size(size_t size) { - const size_t mask = getpagesize() - 1; - size_t newSize = (size + mask) & ~mask; - return newSize; -} - -SkPurgeableMemoryBlock::SkPurgeableMemoryBlock(size_t size) - : fAddr(NULL) - , fSize(round_to_page_size(size)) - , fPinned(false) - , fFD(-1) { -} - -SkPurgeableMemoryBlock::~SkPurgeableMemoryBlock() { - if (-1 != fFD) { - munmap(fAddr, fSize); - close(fFD); - } -} - -void* SkPurgeableMemoryBlock::pin(SkPurgeableMemoryBlock::PinResult* pinResult) { - SkASSERT(!fPinned); - if (-1 == fFD) { - int fd = ashmem_create_region(NULL, fSize); - if (-1 == fd) { - SkDebugf("ashmem_create_region failed\n"); - return NULL; - } - - int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); - if (err != 0) { - SkDebugf("ashmem_set_prot_region failed\n"); - close(fd); - return NULL; - } - - void* addr = mmap(NULL, fSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (-1 == (long) addr) { - SkDebugf("mmap failed\n"); - close(fd); - return NULL; - } - fAddr = addr; - fFD = fd; - (void) ashmem_pin_region(fd, 0, 0); - *pinResult = kUninitialized_PinResult; - fPinned = true; - } else { - int pin = ashmem_pin_region(fFD, 0, 0); - if (ASHMEM_NOT_PURGED == pin) { - fPinned = true; - *pinResult = kRetained_PinResult; - } else if (ASHMEM_WAS_PURGED == pin) { - fPinned = true; - *pinResult = kUninitialized_PinResult; - } else { - // Failed. - munmap(fAddr, fSize); - close(fFD); - fFD = -1; - fAddr = NULL; - } - } - return fAddr; -} - -void SkPurgeableMemoryBlock::unpin() { - if (-1 != fFD) { - ashmem_unpin_region(fFD, 0, 0); - fPinned = false; - } -} diff --git a/src/ports/SkPurgeableMemoryBlock_mac.cpp b/src/ports/SkPurgeableMemoryBlock_mac.cpp deleted file mode 100644 index da4cdff12..000000000 --- a/src/ports/SkPurgeableMemoryBlock_mac.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPurgeableMemoryBlock.h" - -#include - -bool SkPurgeableMemoryBlock::IsSupported() { - return true; -} - -#ifdef SK_DEBUG -bool SkPurgeableMemoryBlock::PlatformSupportsPurgingAllUnpinnedBlocks() { - return true; -} - -bool SkPurgeableMemoryBlock::PurgeAllUnpinnedBlocks() { - // Unused. - int state = 0; - kern_return_t ret = vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); - return ret == KERN_SUCCESS; -} - -bool SkPurgeableMemoryBlock::purge() { - return false; -} -#endif - -static size_t round_to_page_size(size_t size) { - const size_t mask = 4096 - 1; - return (size + mask) & ~mask; -} - -SkPurgeableMemoryBlock::SkPurgeableMemoryBlock(size_t size) - : fAddr(NULL) - , fSize(round_to_page_size(size)) - , fPinned(false) { -} - -SkPurgeableMemoryBlock::~SkPurgeableMemoryBlock() { - SkDEBUGCODE(kern_return_t ret =) vm_deallocate(mach_task_self(), - reinterpret_cast(fAddr), - static_cast(fSize)); -#ifdef SK_DEBUG - if (ret != KERN_SUCCESS) { - SkDebugf("SkPurgeableMemoryBlock destructor failed to deallocate.\n"); - } -#endif -} - -void* SkPurgeableMemoryBlock::pin(SkPurgeableMemoryBlock::PinResult* pinResult) { - SkASSERT(!fPinned); - SkASSERT(pinResult != NULL); - if (NULL == fAddr) { - vm_address_t addr = 0; - kern_return_t ret = vm_allocate(mach_task_self(), &addr, static_cast(fSize), - VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE); - if (KERN_SUCCESS == ret) { - fAddr = reinterpret_cast(addr); - *pinResult = kUninitialized_PinResult; - fPinned = true; - } else { - fAddr = NULL; - } - } else { - int state = VM_PURGABLE_NONVOLATILE; - kern_return_t ret = vm_purgable_control(mach_task_self(), - reinterpret_cast(fAddr), - VM_PURGABLE_SET_STATE, &state); - if (ret != KERN_SUCCESS) { - fAddr = NULL; - fPinned = false; - return NULL; - } - - fPinned = true; - - if (state & VM_PURGABLE_EMPTY) { - *pinResult = kUninitialized_PinResult; - } else { - *pinResult = kRetained_PinResult; - } - } - return fAddr; -} - -void SkPurgeableMemoryBlock::unpin() { - SkASSERT(fPinned); - int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT; - SkDEBUGCODE(kern_return_t ret =) vm_purgable_control(mach_task_self(), - reinterpret_cast(fAddr), - VM_PURGABLE_SET_STATE, &state); - fPinned = false; - -#ifdef SK_DEBUG - if (ret != KERN_SUCCESS) { - SkDebugf("SkPurgeableMemoryBlock::unpin() failed.\n"); - } -#endif -} diff --git a/src/ports/SkPurgeableMemoryBlock_none.cpp b/src/ports/SkPurgeableMemoryBlock_none.cpp deleted file mode 100644 index e10832e9a..000000000 --- a/src/ports/SkPurgeableMemoryBlock_none.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPurgeableMemoryBlock.h" - -bool SkPurgeableMemoryBlock::IsSupported() { - return false; -} - -#ifdef SK_DEBUG -bool SkPurgeableMemoryBlock::PlatformSupportsPurgingAllUnpinnedBlocks() { - return false; -} - -bool SkPurgeableMemoryBlock::PurgeAllUnpinnedBlocks() { - return false; -} - -bool SkPurgeableMemoryBlock::purge() { - return false; -} -#endif - -SkPurgeableMemoryBlock::SkPurgeableMemoryBlock(size_t size) { - SkASSERT(false); -} - -SkPurgeableMemoryBlock::~SkPurgeableMemoryBlock() { -} - -void* SkPurgeableMemoryBlock::pin(SkPurgeableMemoryBlock::PinResult*) { - return NULL; -} - -void SkPurgeableMemoryBlock::unpin() { -}