Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: src/ports/SkDiscardableMemory_ashmem.cpp

Issue 293283002: move ashmem switching logic to SkDiscardableMemory::Create (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/ImageDecodingTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkDiscardableMemory_ashmem.cpp
diff --git a/src/ports/SkDiscardableMemory_ashmem.cpp b/src/ports/SkDiscardableMemory_ashmem.cpp
index e5e5f5396933d96aeb7d86f05997399de3efd90f..88261543fd7651bc681924e26c1f0ee8da6ea182 100644
--- a/src/ports/SkDiscardableMemory_ashmem.cpp
+++ b/src/ports/SkDiscardableMemory_ashmem.cpp
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include "SkDiscardableMemory.h"
+#include "SkDiscardableMemoryPool.h"
#include "SkTypes.h"
#include "android/ashmem.h"
@@ -24,6 +25,8 @@ public:
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;
@@ -86,10 +89,8 @@ void SkAshmemDiscardableMemory::unlock() {
}
fLocked = false;
}
-} // namespace
-////////////////////////////////////////////////////////////////////////////////
-SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
+SkAshmemDiscardableMemory* SkAshmemDiscardableMemory::Create(size_t bytes) {
// ashmem likes lengths on page boundaries.
const size_t mask = getpagesize() - 1;
size_t size = (bytes + mask) & ~mask;
@@ -111,3 +112,18 @@ SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
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);
+ }
+}
+
« no previous file with comments | « no previous file | tests/ImageDecodingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698