OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 #include "native_client/tests/fake_browser_ppapi/fake_core.h" | |
8 #include <stdio.h> | |
9 #include "native_client/src/include/nacl_macros.h" | |
10 #include "native_client/src/include/portability.h" | |
11 #include "native_client/tests/fake_browser_ppapi/utility.h" | |
12 #include "ppapi/c/ppb_core.h" | |
13 #include "ppapi/c/pp_completion_callback.h" | |
14 #include "ppapi/c/pp_resource.h" | |
15 | |
16 using fake_browser_ppapi::DebugPrintf; | |
17 | |
18 namespace { | |
19 | |
20 // The plugin does reference counting indirectly by using PPAPI C++ layer. | |
21 // The assumption is that PPAPI tests cover reference counting, so we don't | |
22 // need to test it here. Instead every resource will be registered with the | |
23 // host on creation and deallocated in its destructor. | |
24 | |
25 static void AddRefResource(PP_Resource resource) { | |
26 DebugPrintf("Core::AddRefResource: resource=%"NACL_PRIu64"\n", resource); | |
27 } | |
28 | |
29 static void ReleaseResource(PP_Resource resource) { | |
30 DebugPrintf("Core::ReleaseResource: resource=%"NACL_PRIu64"\n", resource); | |
31 } | |
32 | |
33 static void* MemAlloc(uint32_t num_bytes) { | |
34 DebugPrintf("Core::MemAlloc: num_bytes=%"NACL_PRIuS"\n", num_bytes); | |
35 return malloc(num_bytes); | |
36 } | |
37 | |
38 static void MemFree(void* ptr) { | |
39 DebugPrintf("Core::MemFree: ptr=%p\n", ptr); | |
40 free(ptr); | |
41 } | |
42 | |
43 static PP_Time GetTime() { | |
44 DebugPrintf("Core::GetTime\n"); | |
45 static double time = 0.0; | |
46 // TODO(sehr): Do we need a real time here? | |
47 time += 1.0; | |
48 return static_cast<PP_Time>(time); | |
49 } | |
50 | |
51 static PP_TimeTicks GetTimeTicks() { | |
52 DebugPrintf("Core::GetTime\n"); | |
53 static double time = 0.0; | |
54 // TODO(sehr): Do we need a real time here? | |
55 time += 1.0; | |
56 return static_cast<PP_Time>(time); | |
57 } | |
58 | |
59 static void CallOnMainThread(int32_t delay_in_milliseconds, | |
60 PP_CompletionCallback callback, | |
61 int32_t result) { | |
62 UNREFERENCED_PARAMETER(callback); | |
63 DebugPrintf("Core::CallOnMainThread: delay=%" NACL_PRIu32 | |
64 ", result=%" NACL_PRIu32 "\n", | |
65 delay_in_milliseconds, | |
66 result); | |
67 // NACL_UNIMPLEMENTED(); // possibly leak some resources | |
68 } | |
69 | |
70 static PP_Bool IsMainThread() { | |
71 DebugPrintf("Core::IsMainThread: always true\n"); | |
72 return PP_TRUE; | |
73 } | |
74 | |
75 } // namespace | |
76 | |
77 namespace fake_browser_ppapi { | |
78 | |
79 const PPB_Core* Core::GetInterface() { | |
80 static const PPB_Core core_interface = { | |
81 AddRefResource, | |
82 ReleaseResource, | |
83 MemAlloc, | |
84 MemFree, | |
85 GetTime, | |
86 GetTimeTicks, | |
87 CallOnMainThread, | |
88 IsMainThread | |
89 }; | |
90 return &core_interface; | |
91 } | |
92 | |
93 } // namespace fake_browser_ppapi | |
OLD | NEW |