'../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',
],
'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',
],
}],
],
'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',
],
}],
'sources!': [
'../src/ports/SkDebug_stdio.cpp',
'../src/ports/SkDiscardableMemory_none.cpp',
- '../src/ports/SkPurgeableMemoryBlock_none.cpp',
],
'sources': [
'../src/ports/SkDebug_android.cpp',
'../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',
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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));
-}
+++ /dev/null
-/*
- * 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 <sys/mman.h>
-#include <unistd.h>
-
-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;
- }
-}
+++ /dev/null
-/*
- * 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 <mach/mach.h>
-
-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<vm_address_t>(fAddr),
- static_cast<vm_size_t>(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<vm_size_t>(fSize),
- VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE);
- if (KERN_SUCCESS == ret) {
- fAddr = reinterpret_cast<void*>(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<vm_address_t>(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<vm_address_t>(fAddr),
- VM_PURGABLE_SET_STATE, &state);
- fPinned = false;
-
-#ifdef SK_DEBUG
- if (ret != KERN_SUCCESS) {
- SkDebugf("SkPurgeableMemoryBlock::unpin() failed.\n");
- }
-#endif
-}
+++ /dev/null
-/*
- * 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() {
-}