| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/shared/ppapi_proxy/plugin_core.h" | 7 #include "native_client/src/shared/ppapi_proxy/plugin_core.h" |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 __thread bool is_main_thread = false; | 28 __thread bool is_main_thread = false; |
| 29 bool main_thread_marked = false; | 29 bool main_thread_marked = false; |
| 30 #endif // __native_client__ | 30 #endif // __native_client__ |
| 31 | 31 |
| 32 // Increment the reference count for a specified resource. This only takes | 32 // Increment the reference count for a specified resource. This only takes |
| 33 // care of the plugin's reference count - the Resource should obtain the | 33 // care of the plugin's reference count - the Resource should obtain the |
| 34 // browser reference when it stores the browser's Resource id. When the | 34 // browser reference when it stores the browser's Resource id. When the |
| 35 // Resource's reference count goes to zero, the destructor should make sure | 35 // Resource's reference count goes to zero, the destructor should make sure |
| 36 // the browser reference is returned. | 36 // the browser reference is returned. |
| 37 void AddRefResource(PP_Resource resource) { | 37 void AddRefResource(PP_Resource resource) { |
| 38 DebugPrintf("PluginCore::AddRefResource: resource=%"NACL_PRIu64"\n", | 38 DebugPrintf("Plugin::PPB_Core::AddRefResource: resource=%"NACL_PRIu64"\n", |
| 39 resource); | 39 resource); |
| 40 if (ppapi_proxy::PluginResourceTracker::Get()->AddRefResource(resource)) | 40 if (ppapi_proxy::PluginResourceTracker::Get()->AddRefResource(resource)) |
| 41 DebugPrintf("Warning: AddRefResource()ing a nonexistent resource"); | 41 DebugPrintf("Plugin::PPB_Core::AddRefResource: nonexistent resource"); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void ReleaseResource(PP_Resource resource) { | 44 void ReleaseResource(PP_Resource resource) { |
| 45 DebugPrintf("PluginCore::ReleaseResource: resource=%"NACL_PRIu64"\n", | 45 DebugPrintf("Plugin::PPB_Core::ReleaseResource: resource=%"NACL_PRIu64"\n", |
| 46 resource); | 46 resource); |
| 47 if (ppapi_proxy::PluginResourceTracker::Get()->UnrefResource(resource)) | 47 if (ppapi_proxy::PluginResourceTracker::Get()->UnrefResource(resource)) |
| 48 DebugPrintf("Warning: ReleaseRefResource()ing a nonexistent resource"); | 48 DebugPrintf("Plugin::PPB_Core::ReleaseRefResource: nonexistent resource"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void* MemAlloc(size_t num_bytes) { | 51 void* MemAlloc(size_t num_bytes) { |
| 52 DebugPrintf("PluginCore::MemAlloc: num_bytes=%"NACL_PRIuS"\n", num_bytes); | 52 DebugPrintf("Plugin::PPB_Core::MemAlloc: num_bytes=%"NACL_PRIuS"\n", |
| 53 num_bytes); |
| 53 return malloc(num_bytes); | 54 return malloc(num_bytes); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void MemFree(void* ptr) { | 57 void MemFree(void* ptr) { |
| 57 DebugPrintf("PluginCore::MemFree: ptr=%p\n", ptr); | 58 DebugPrintf("Plugin::PPB_Core::MemFree: ptr=%p\n", ptr); |
| 58 free(ptr); | 59 free(ptr); |
| 59 } | 60 } |
| 60 | 61 |
| 61 PP_TimeTicks GetTime() { | 62 PP_TimeTicks GetTime() { |
| 62 DebugPrintf("PluginCore::GetTime\n"); | 63 DebugPrintf("Plugin::PPB_Core::GetTime\n"); |
| 63 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); | 64 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); |
| 64 double time; | 65 double time; |
| 65 NaClSrpcError retval = PpbCoreRpcClient::PPB_Core_GetTime(channel, &time); | 66 NaClSrpcError retval = PpbCoreRpcClient::PPB_Core_GetTime(channel, &time); |
| 66 if (retval != NACL_SRPC_RESULT_OK) { | 67 if (retval != NACL_SRPC_RESULT_OK) { |
| 67 return static_cast<PP_Time>(-1.0); | 68 return static_cast<PP_Time>(-1.0); |
| 68 } else { | 69 } else { |
| 69 return static_cast<PP_Time>(time); | 70 return static_cast<PP_Time>(time); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 PP_TimeTicks GetTimeTicks() { | 74 PP_TimeTicks GetTimeTicks() { |
| 74 DebugPrintf("PluginCore::GetTime\n"); | 75 DebugPrintf("Plugin::PPB_Core::GetTime\n"); |
| 75 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); | 76 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); |
| 76 double time; | 77 double time; |
| 77 // TODO(sehr): implement time ticks. | 78 // TODO(sehr): implement time ticks. |
| 78 NaClSrpcError retval = PpbCoreRpcClient::PPB_Core_GetTime(channel, &time); | 79 NaClSrpcError retval = PpbCoreRpcClient::PPB_Core_GetTime(channel, &time); |
| 79 if (retval != NACL_SRPC_RESULT_OK) { | 80 if (retval != NACL_SRPC_RESULT_OK) { |
| 80 return static_cast<PP_TimeTicks>(-1.0); | 81 return static_cast<PP_TimeTicks>(-1.0); |
| 81 } else { | 82 } else { |
| 82 return static_cast<PP_TimeTicks>(time); | 83 return static_cast<PP_TimeTicks>(time); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 static void CallOnMainThread(int32_t delay_in_milliseconds, | 87 static void CallOnMainThread(int32_t delay_in_milliseconds, |
| 87 PP_CompletionCallback callback, | 88 PP_CompletionCallback callback, |
| 88 int32_t result) { | 89 int32_t result) { |
| 89 UNREFERENCED_PARAMETER(callback); | 90 UNREFERENCED_PARAMETER(callback); |
| 90 DebugPrintf("PluginCore::CallOnMainThread: delay=%" NACL_PRIu32 | 91 DebugPrintf("Plugin::PPB_Core::CallOnMainThread: delay=%" NACL_PRIu32 |
| 91 ", result=%" NACL_PRIu32 "\n", | 92 ", result=%" NACL_PRIu32 "\n", |
| 92 delay_in_milliseconds, | 93 delay_in_milliseconds, |
| 93 result); | 94 result); |
| 94 NACL_UNIMPLEMENTED(); | 95 NACL_UNIMPLEMENTED(); |
| 95 // See how NPN_PluginThreadAsyncCall is implemented in npruntime. | 96 // See how NPN_PluginThreadAsyncCall is implemented in npruntime. |
| 96 } | 97 } |
| 97 | 98 |
| 98 static PP_Bool IsMainThread() { | 99 static PP_Bool IsMainThread() { |
| 99 DebugPrintf("PluginCore::IsMainThread\n"); | 100 DebugPrintf("Plugin::PPB_Core::IsMainThread\n"); |
| 100 #ifdef __native_client__ | 101 #ifdef __native_client__ |
| 101 return pp::BoolToPPBool(is_main_thread); | 102 return pp::BoolToPPBool(is_main_thread); |
| 102 #else | 103 #else |
| 103 // TODO(polina): implement this for trusted clients if needed. | 104 // TODO(polina): implement this for trusted clients if needed. |
| 104 NACL_UNIMPLEMENTED(); | 105 NACL_UNIMPLEMENTED(); |
| 105 return PP_TRUE; | 106 return PP_TRUE; |
| 106 #endif // __native_client__ | 107 #endif // __native_client__ |
| 107 } | 108 } |
| 108 | 109 |
| 109 } // namespace | 110 } // namespace |
| (...skipping 24 matching lines...) Expand all Loading... |
| 134 // Setting this once works because the main thread will call this function | 135 // Setting this once works because the main thread will call this function |
| 135 // before calling any pthread_creates. Hence the result is already | 136 // before calling any pthread_creates. Hence the result is already |
| 136 // published before other threads might attempt to call it. | 137 // published before other threads might attempt to call it. |
| 137 main_thread_marked = true; | 138 main_thread_marked = true; |
| 138 } | 139 } |
| 139 #endif // __native_client__ | 140 #endif // __native_client__ |
| 140 } | 141 } |
| 141 | 142 |
| 142 | 143 |
| 143 } // namespace ppapi_proxy | 144 } // namespace ppapi_proxy |
| OLD | NEW |