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

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: 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..5398eff8833678bdbdde46e7c50c19d29f2304d3 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,17 @@ SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
return SkNEW_ARGS(SkAshmemDiscardableMemory, (fd, addr, size));
}
+} // namespace
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef SKIA_ASHMEM_MINIMUM_MEMORY_SIZE
scroggo 2014/05/23 19:54:03 I think this should be SK_ASHMEM_MINIMUM_MEMORY_SI
hal.canary 2014/05/23 20:09:22 Done.
+#define SKIA_ASHMEM_MINIMUM_MEMORY_SIZE (3 * 1024)
scroggo 2014/05/23 19:54:03 Android defines this to 32 * 1024, correct? Did yo
hal.canary 2014/05/23 20:09:22 I miscopied that. fixed.
+#endif // SKIA_ASHMEM_MINIMUM_MEMORY_SIZE
+SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
+ if (bytes < SKIA_ASHMEM_MINIMUM_MEMORY_SIZE) {
+ return SkGetGlobalDiscardableMemoryPool()->create(bytes);
+ } else {
+ return SkAshmemDiscardableMemory::Create(size_t bytes);
scroggo 2014/05/23 19:54:03 no need for 'size_t' here.
hal.canary 2014/05/23 20:09:22 I would have caught that when I tried to compile o
+ }
+}
+
« 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