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() |