aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/images.gyp5
-rw-r--r--gyp/ports.gyp2
-rw-r--r--gyp/utils.gyp5
-rw-r--r--src/ports/SkDiscardableMemory_ashmem.cpp128
-rw-r--r--src/utils/android/ashmem.cpp95
-rw-r--r--src/utils/android/ashmem.h50
6 files changed, 0 insertions, 285 deletions
diff --git a/gyp/images.gyp b/gyp/images.gyp
index 5dfb0140da..2b4cfd38a7 100644
--- a/gyp/images.gyp
+++ b/gyp/images.gyp
@@ -148,11 +148,6 @@
],
}],
],
- },{ #else if skia_os != android
- 'sources!': [
- '../src/images/SkImageRef_ashmem.h',
- '../src/images/SkImageRef_ashmem.cpp',
- ],
}],
[ 'skia_os == "chromeos"', {
'dependencies': [
diff --git a/gyp/ports.gyp b/gyp/ports.gyp
index 28d01ad997..cc2d1f7737 100644
--- a/gyp/ports.gyp
+++ b/gyp/ports.gyp
@@ -171,11 +171,9 @@
[ 'skia_os == "android"', {
'sources!': [
'../src/ports/SkDebug_stdio.cpp',
- '../src/ports/SkDiscardableMemory_none.cpp',
],
'sources': [
'../src/ports/SkDebug_android.cpp',
- '../src/ports/SkDiscardableMemory_ashmem.cpp',
'../src/ports/SkFontConfigInterface_android.cpp',
'../src/ports/SkFontConfigParser_android.cpp',
'../src/ports/SkFontHost_fontconfig.cpp',
diff --git a/gyp/utils.gyp b/gyp/utils.gyp
index 583b710aca..066c9015e5 100644
--- a/gyp/utils.gyp
+++ b/gyp/utils.gyp
@@ -110,11 +110,6 @@
'../src/utils/SkThreadUtils_pthread_linux.cpp',
],
}],
- [ 'skia_os == "android"', {
- 'sources': [
- '../src/utils/android/ashmem.cpp',
- ],
- }],
['skia_run_pdfviewer_in_gm', {
'defines': [
'SK_BUILD_NATIVE_PDF_RENDERER',
diff --git a/src/ports/SkDiscardableMemory_ashmem.cpp b/src/ports/SkDiscardableMemory_ashmem.cpp
deleted file mode 100644
index 27d3e23d78..0000000000
--- a/src/ports/SkDiscardableMemory_ashmem.cpp
+++ /dev/null
@@ -1,128 +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 <unistd.h>
-#include <sys/mman.h>
-#include "SkDiscardableMemory.h"
-#include "SkDiscardableMemoryPool.h"
-#include "SkTypes.h"
-#include "android/ashmem.h"
-
-////////////////////////////////////////////////////////////////////////////////
-namespace {
-/**
- * DiscardableMemory implementation that uses the Android kernel's
- * ashmem (Android shared memory).
- */
-class SkAshmemDiscardableMemory : public SkDiscardableMemory {
-public:
- SkAshmemDiscardableMemory(int fd, void* address, size_t size);
- virtual ~SkAshmemDiscardableMemory();
- virtual bool lock() SK_OVERRIDE;
- virtual void* data() SK_OVERRIDE;
- virtual void unlock() SK_OVERRIDE;
- static SkAshmemDiscardableMemory* Create(size_t bytes);
-
-private:
- bool fLocked;
- int fFd;
- void* fMemory;
- const size_t fSize;
-};
-
-SkAshmemDiscardableMemory::SkAshmemDiscardableMemory(int fd,
- void* address,
- size_t size)
- : fLocked(true) // Ashmem pages are pinned by default.
- , fFd(fd)
- , fMemory(address)
- , fSize(size) {
- SkASSERT(fFd >= 0);
- SkASSERT(fMemory != NULL);
- SkASSERT(fSize > 0);
-}
-
-SkAshmemDiscardableMemory::~SkAshmemDiscardableMemory() {
- SkASSERT(!fLocked);
- if (NULL != fMemory) {
- munmap(fMemory, fSize);
- }
- if (fFd != -1) {
- close(fFd);
- }
-}
-
-bool SkAshmemDiscardableMemory::lock() {
- SkASSERT(!fLocked);
- if (-1 == fFd) {
- fLocked = false;
- return false;
- }
- SkASSERT(fMemory != NULL);
- if (fLocked || (ASHMEM_NOT_PURGED == ashmem_pin_region(fFd, 0, 0))) {
- fLocked = true;
- return true;
- } else {
- munmap(fMemory, fSize);
- fMemory = NULL;
-
- close(fFd);
- fFd = -1;
- fLocked = false;
- return false;
- }
-}
-
-void* SkAshmemDiscardableMemory::data() {
- SkASSERT(fLocked);
- return fLocked ? fMemory : NULL;
-}
-
-void SkAshmemDiscardableMemory::unlock() {
- SkASSERT(fLocked);
- if (fLocked && (fFd != -1)) {
- ashmem_unpin_region(fFd, 0, 0);
- }
- fLocked = false;
-}
-
-SkAshmemDiscardableMemory* SkAshmemDiscardableMemory::Create(size_t bytes) {
- // ashmem likes lengths on page boundaries.
- const size_t mask = getpagesize() - 1;
- size_t size = (bytes + mask) & ~mask;
-
- static const char name[] = "Skia_Ashmem_Discardable_Memory";
- int fd = ashmem_create_region(name, size);
- if (fd < 0) {
- return NULL;
- }
- if (0 != ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE)) {
- close(fd);
- return NULL;
- }
- void* addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- if ((MAP_FAILED == addr) || (NULL == addr)) {
- close(fd);
- return NULL;
- }
-
- return SkNEW_ARGS(SkAshmemDiscardableMemory, (fd, addr, size));
-}
-} // namespace
-////////////////////////////////////////////////////////////////////////////////
-
-#ifndef SK_ASHMEM_MINIMUM_MEMORY_SIZE
-// number taken from android/graphics/BitmapFactory.cpp
-#define SK_ASHMEM_MINIMUM_MEMORY_SIZE (32 * 1024)
-#endif // SK_ASHMEM_MINIMUM_MEMORY_SIZE
-SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
- if (bytes < SK_ASHMEM_MINIMUM_MEMORY_SIZE) {
- return SkGetGlobalDiscardableMemoryPool()->create(bytes);
- } else {
- return SkAshmemDiscardableMemory::Create(bytes);
- }
-}
diff --git a/src/utils/android/ashmem.cpp b/src/utils/android/ashmem.cpp
deleted file mode 100644
index 1e512be2b1..0000000000
--- a/src/utils/android/ashmem.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2008 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/*
- * Implementation of the user-space ashmem API for devices, which have our
- * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
- * used by the simulator.
- */
-
-#include <android/ashmem.h>
-
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-
-#include <linux/ashmem.h>
-
-#include <SkTypes.h> // SkASSERT
-
-#define ASHMEM_DEVICE "/dev/ashmem"
-
-/*
- * ashmem_create_region - creates a new ashmem region and returns the file
- * descriptor, or <0 on error
- *
- * `name' is an optional label to give the region (visible in /proc/pid/maps)
- * `size' is the size of the region, in page-aligned bytes
- */
-int ashmem_create_region(const char *name, size_t size)
-{
- int fd, ret;
-
- fd = open(ASHMEM_DEVICE, O_RDWR);
- if (fd < 0)
- return fd;
-
- if (name) {
- char buf[ASHMEM_NAME_LEN];
-
- strlcpy(buf, name, sizeof(buf));
- ret = ioctl(fd, ASHMEM_SET_NAME, buf);
- if (ret < 0)
- goto error;
- }
-
- ret = ioctl(fd, ASHMEM_SET_SIZE, size);
- if (ret < 0)
- goto error;
-
- return fd;
-
-error:
- close(fd);
- return ret;
-}
-
-int ashmem_set_prot_region(int fd, int prot)
-{
- return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
-}
-
-int ashmem_pin_region(int fd, size_t offset, size_t len)
-{
- // Skia only calls this when offset=len=0.
- struct ashmem_pin pin = { static_cast<__u32>(offset),
- static_cast<__u32>(len) };
- SkASSERT(pin.offset == offset && pin.len == len);
- return ioctl(fd, ASHMEM_PIN, &pin);
-}
-
-int ashmem_unpin_region(int fd, size_t offset, size_t len)
-{
- // Skia only calls this when offset=len=0.
- struct ashmem_pin pin = { static_cast<__u32>(offset),
- static_cast<__u32>(len) };
- SkASSERT(pin.offset == offset && pin.len == len);
- return ioctl(fd, ASHMEM_UNPIN, &pin);
-}
-
-int ashmem_get_size_region(int fd)
-{
- return ioctl(fd, ASHMEM_GET_SIZE, NULL);
-}
-
-int ashmem_purge_all_caches(int fd)
-{
- return ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL);
-}
diff --git a/src/utils/android/ashmem.h b/src/utils/android/ashmem.h
deleted file mode 100644
index 94ffe1a33b..0000000000
--- a/src/utils/android/ashmem.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2008 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef _CUTILS_ASHMEM_H
-#define _CUTILS_ASHMEM_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int ashmem_create_region(const char *name, size_t size);
-int ashmem_set_prot_region(int fd, int prot);
-
-/**
- * @return ASHMEM_NOT_PURGED if the memory was not purged.
- * ASHMEM_WAS_PURGED if the memory was purged.
- * -1 on error.
- */
-int ashmem_pin_region(int fd, size_t offset, size_t len);
-int ashmem_unpin_region(int fd, size_t offset, size_t len);
-int ashmem_get_size_region(int fd);
-int ashmem_purge_all_caches(int fd);
-
-#ifdef __cplusplus
-}
-#endif
-
-#ifndef __ASHMEMIOC /* in case someone included <linux/ashmem.h> too */
-
-#define ASHMEM_NAME_LEN 256
-
-#define ASHMEM_NAME_DEF "dev/ashmem"
-
-/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */
-#define ASHMEM_NOT_PURGED 0
-#define ASHMEM_WAS_PURGED 1
-
-/* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */
-#define ASHMEM_IS_UNPINNED 0
-#define ASHMEM_IS_PINNED 1
-
-#endif /* ! __ASHMEMIOC */
-
-#endif /* _CUTILS_ASHMEM_H */