OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // be found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h" | 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include "srpcgen/ppb_rpc.h" | 10 #include "srpcgen/ppb_rpc.h" |
11 #include "native_client/src/include/portability.h" | 11 #include "native_client/src/include/portability.h" |
12 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" | 12 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
13 #include "native_client/src/shared/ppapi_proxy/utility.h" | 13 #include "native_client/src/shared/ppapi_proxy/utility.h" |
(...skipping 30 matching lines...) Expand all Loading... |
44 NACL_PRId32"\n", static_cast<int32_t>(format)); | 44 NACL_PRId32"\n", static_cast<int32_t>(format)); |
45 int32_t result; | 45 int32_t result; |
46 NaClSrpcError srpc_result = | 46 NaClSrpcError srpc_result = |
47 PpbImageDataRpcClient::PPB_ImageData_IsImageDataFormatSupported( | 47 PpbImageDataRpcClient::PPB_ImageData_IsImageDataFormatSupported( |
48 GetMainSrpcChannel(), | 48 GetMainSrpcChannel(), |
49 static_cast<int32_t>(format), | 49 static_cast<int32_t>(format), |
50 &result); | 50 &result); |
51 DebugPrintf("PPB_ImageData::IsImageDataFormatSupported: %s\n", | 51 DebugPrintf("PPB_ImageData::IsImageDataFormatSupported: %s\n", |
52 NaClSrpcErrorString(srpc_result)); | 52 NaClSrpcErrorString(srpc_result)); |
53 if (srpc_result == NACL_SRPC_RESULT_OK) { | 53 if (srpc_result == NACL_SRPC_RESULT_OK) { |
54 return (result ? PP_TRUE : PP_FALSE); | 54 return PP_FromBool(result); |
55 } else { | 55 } else { |
56 return PP_FALSE; | 56 return PP_FALSE; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 PP_Resource Create(PP_Instance instance, | 60 PP_Resource Create(PP_Instance instance, |
61 PP_ImageDataFormat format, | 61 PP_ImageDataFormat format, |
62 const struct PP_Size* size, | 62 const struct PP_Size* size, |
63 PP_Bool init_to_zero) { | 63 PP_Bool init_to_zero) { |
64 DebugPrintf("PPB_ImageData::Create: instance=%"NACL_PRIu32"\n", instance); | 64 DebugPrintf("PPB_ImageData::Create: instance=%"NACL_PRId32"\n", instance); |
65 PP_Resource resource; | 65 PP_Resource resource; |
66 NaClSrpcError srpc_result = | 66 NaClSrpcError srpc_result = |
67 PpbImageDataRpcClient::PPB_ImageData_Create( | 67 PpbImageDataRpcClient::PPB_ImageData_Create( |
68 GetMainSrpcChannel(), | 68 GetMainSrpcChannel(), |
69 instance, | 69 instance, |
70 static_cast<int32_t>(format), | 70 static_cast<int32_t>(format), |
71 static_cast<nacl_abi_size_t>(sizeof(struct PP_Size)), | 71 static_cast<nacl_abi_size_t>(sizeof(struct PP_Size)), |
72 reinterpret_cast<char*>(const_cast<struct PP_Size*>(size)), | 72 reinterpret_cast<char*>(const_cast<struct PP_Size*>(size)), |
73 (init_to_zero == PP_TRUE), | 73 PP_ToBool(init_to_zero), |
74 &resource); | 74 &resource); |
75 DebugPrintf("PPB_ImageData::Create: %s\n", NaClSrpcErrorString(srpc_result)); | 75 DebugPrintf("PPB_ImageData::Create: %s\n", NaClSrpcErrorString(srpc_result)); |
76 if (srpc_result == NACL_SRPC_RESULT_OK) { | 76 if (srpc_result == NACL_SRPC_RESULT_OK) { |
77 scoped_refptr<PluginImageData> image_data = | 77 scoped_refptr<PluginImageData> image_data = |
78 PluginResource::AdoptAs<PluginImageData>(resource); | 78 PluginResource::AdoptAs<PluginImageData>(resource); |
79 if (image_data.get()) { | 79 if (image_data.get()) { |
80 return resource; | 80 return resource; |
81 } | 81 } |
82 } | 82 } |
83 return kInvalidResourceId; | 83 return kInvalidResourceId; |
84 } | 84 } |
85 | 85 |
86 PP_Bool IsImageData(PP_Resource resource) { | 86 PP_Bool IsImageData(PP_Resource resource) { |
87 DebugPrintf("PPB_ImageData::IsImageData: resource=%"NACL_PRIu32"\n", | 87 DebugPrintf("PPB_ImageData::IsImageData: resource=%"NACL_PRId32"\n", |
88 resource); | 88 resource); |
89 return PluginResource::GetAs<PluginImageData>(resource).get() | 89 return PP_FromBool(PluginResource::GetAs<PluginImageData>(resource).get()); |
90 ? PP_TRUE : PP_FALSE; | |
91 } | 90 } |
92 | 91 |
93 PP_Bool Describe(PP_Resource resource, | 92 PP_Bool Describe(PP_Resource resource, |
94 struct PP_ImageDataDesc* desc) { | 93 struct PP_ImageDataDesc* desc) { |
95 DebugPrintf("PPB_ImageData::Describe: resource=%"NACL_PRIu32"\n", | 94 DebugPrintf("PPB_ImageData::Describe: resource=%"NACL_PRId32"\n", |
96 resource); | 95 resource); |
97 scoped_refptr<PluginImageData> imagedata = | 96 scoped_refptr<PluginImageData> imagedata = |
98 PluginResource::GetAs<PluginImageData>(resource); | 97 PluginResource::GetAs<PluginImageData>(resource); |
99 if (!imagedata.get()) { | 98 if (!imagedata.get()) { |
100 return PP_FALSE; | 99 return PP_FALSE; |
101 } | 100 } |
102 | 101 |
103 *desc = imagedata->desc(); | 102 *desc = imagedata->desc(); |
104 return PP_TRUE; | 103 return PP_TRUE; |
105 } | 104 } |
106 | 105 |
107 void* DoMap(PP_Resource resource) { | 106 void* DoMap(PP_Resource resource) { |
108 DebugPrintf("PPB_ImageData::DoMap: resource=%"NACL_PRIu32"\n", resource); | 107 DebugPrintf("PPB_ImageData::DoMap: resource=%"NACL_PRId32"\n", resource); |
109 scoped_refptr<PluginImageData> imagedata = | 108 scoped_refptr<PluginImageData> imagedata = |
110 PluginResource::GetAs<PluginImageData>(resource); | 109 PluginResource::GetAs<PluginImageData>(resource); |
111 | 110 |
112 return imagedata.get() ? imagedata->Map() : NULL; | 111 return imagedata.get() ? imagedata->Map() : NULL; |
113 } | 112 } |
114 | 113 |
115 void DoUnmap(PP_Resource resource) { | 114 void DoUnmap(PP_Resource resource) { |
116 DebugPrintf("PPB_ImageData::DoUnmap: resource=%"NACL_PRIu32"\n", resource); | 115 DebugPrintf("PPB_ImageData::DoUnmap: resource=%"NACL_PRId32"\n", resource); |
117 scoped_refptr<PluginImageData> imagedata = | 116 scoped_refptr<PluginImageData> imagedata = |
118 PluginResource::GetAs<PluginImageData>(resource); | 117 PluginResource::GetAs<PluginImageData>(resource); |
119 if (imagedata.get()) | 118 if (imagedata.get()) |
120 imagedata->Unmap(); | 119 imagedata->Unmap(); |
121 } | 120 } |
122 | 121 |
123 } // namespace | 122 } // namespace |
124 | 123 |
125 const PPB_ImageData* PluginImageData::GetInterface() { | 124 const PPB_ImageData* PluginImageData::GetInterface() { |
126 static const PPB_ImageData image_data_interface = { | 125 static const PPB_ImageData image_data_interface = { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 175 } |
177 | 176 |
178 void PluginImageData::Unmap() { | 177 void PluginImageData::Unmap() { |
179 if (addr_) { | 178 if (addr_) { |
180 munmap(addr_, ceil64k(shm_size_)); | 179 munmap(addr_, ceil64k(shm_size_)); |
181 addr_ = NULL; | 180 addr_ = NULL; |
182 } | 181 } |
183 } | 182 } |
184 | 183 |
185 } // namespace ppapi_proxy | 184 } // namespace ppapi_proxy |
OLD | NEW |