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

Unified Diff: Source/platform/exported/Platform.cpp

Issue 87983002: Add WTF::DiscardableMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update comment Created 7 years, 1 month 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 | Source/wtf/DiscardableMemory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/exported/Platform.cpp
diff --git a/Source/platform/exported/Platform.cpp b/Source/platform/exported/Platform.cpp
index 7973183f8a251770df58646058a044e8f9364f86..3a42186b6b0717fdd7ab9ae252b7d45570dda3e7 100644
--- a/Source/platform/exported/Platform.cpp
+++ b/Source/platform/exported/Platform.cpp
@@ -30,14 +30,67 @@
#include "config.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebDiscardableMemory.h"
+#include "wtf/Assertions.h"
+#include "wtf/Compiler.h"
+#include "wtf/DiscardableMemory.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/WTFPlatform.h"
+
+using namespace WTF;
namespace blink {
-static Platform* s_platform = 0;
+namespace {
+
+Platform* s_platform = 0;
+
+class WTFDiscardableMemoryImpl : public DiscardableMemory {
+public:
+ explicit WTFDiscardableMemoryImpl(PassOwnPtr<WebDiscardableMemory> discardableMemory)
+ : m_discardableMemory(discardableMemory)
+ { }
+
+ virtual bool lock() OVERRIDE
+ {
+ return m_discardableMemory->lock();
+ }
+
+ virtual void* data() OVERRIDE
+ {
+ return m_discardableMemory->data();
+ }
+
+ virtual void unlock() OVERRIDE
+ {
+ return m_discardableMemory->unlock();
+ }
+
+private:
+ OwnPtr<WebDiscardableMemory> m_discardableMemory;
+};
+
+// WTFPlatformImpl is nothing more than a wrapper around blink::Platform.
+class WTFPlatformImpl : public WTFPlatform {
+public:
+ virtual PassOwnPtr<DiscardableMemory> allocateAndLockDiscardableMemory(size_t bytes) OVERRIDE
+ {
+ ASSERT(s_platform);
+ OwnPtr<WebDiscardableMemory> memory(adoptPtr(s_platform->allocateAndLockDiscardableMemory(bytes)));
+ if (!memory)
+ return PassOwnPtr<DiscardableMemory>();
+
+ return adoptPtr(new WTFDiscardableMemoryImpl(memory.release()));
+ }
+};
+
+} // namespace
void Platform::initialize(Platform* platform)
{
s_platform = platform;
+ WTFPlatform::setInstance(new WTFPlatformImpl());
}
void Platform::shutdown()
« no previous file with comments | « no previous file | Source/wtf/DiscardableMemory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698