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

Side by Side 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 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/DiscardableMemory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "public/platform/Platform.h" 32 #include "public/platform/Platform.h"
33 #include "public/platform/WebDiscardableMemory.h"
34 #include "wtf/Assertions.h"
35 #include "wtf/Compiler.h"
36 #include "wtf/DiscardableMemory.h"
37 #include "wtf/OwnPtr.h"
38 #include "wtf/PassOwnPtr.h"
39 #include "wtf/WTFPlatform.h"
40
41 using namespace WTF;
33 42
34 namespace blink { 43 namespace blink {
35 44
36 static Platform* s_platform = 0; 45 namespace {
46
47 Platform* s_platform = 0;
48
49 class WTFDiscardableMemoryImpl : public DiscardableMemory {
50 public:
51 explicit WTFDiscardableMemoryImpl(PassOwnPtr<WebDiscardableMemory> discardab leMemory)
52 : m_discardableMemory(discardableMemory)
53 { }
54
55 virtual bool lock() OVERRIDE
56 {
57 return m_discardableMemory->lock();
58 }
59
60 virtual void* data() OVERRIDE
61 {
62 return m_discardableMemory->data();
63 }
64
65 virtual void unlock() OVERRIDE
66 {
67 return m_discardableMemory->unlock();
68 }
69
70 private:
71 OwnPtr<WebDiscardableMemory> m_discardableMemory;
72 };
73
74 // WTFPlatformImpl is nothing more than a wrapper around blink::Platform.
75 class WTFPlatformImpl : public WTFPlatform {
76 public:
77 virtual PassOwnPtr<DiscardableMemory> allocateAndLockDiscardableMemory(size_ t bytes) OVERRIDE
78 {
79 ASSERT(s_platform);
80 OwnPtr<WebDiscardableMemory> memory(adoptPtr(s_platform->allocateAndLock DiscardableMemory(bytes)));
81 if (!memory)
82 return PassOwnPtr<DiscardableMemory>();
83
84 return adoptPtr(new WTFDiscardableMemoryImpl(memory.release()));
85 }
86 };
87
88 } // namespace
37 89
38 void Platform::initialize(Platform* platform) 90 void Platform::initialize(Platform* platform)
39 { 91 {
40 s_platform = platform; 92 s_platform = platform;
93 WTFPlatform::setInstance(new WTFPlatformImpl());
41 } 94 }
42 95
43 void Platform::shutdown() 96 void Platform::shutdown()
44 { 97 {
45 s_platform = 0; 98 s_platform = 0;
46 } 99 }
47 100
48 Platform* Platform::current() 101 Platform* Platform::current()
49 { 102 {
50 return s_platform; 103 return s_platform;
51 } 104 }
52 105
53 } // namespace blink 106 } // namespace blink
OLDNEW
« 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