| 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_graphics_2d.h" | 7 #include "native_client/src/shared/ppapi_proxy/plugin_graphics_2d.h" |
| 8 | 8 |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 static_cast<nacl_abi_size_t>(sizeof(struct PP_Point)); | 30 static_cast<nacl_abi_size_t>(sizeof(struct PP_Point)); |
| 31 const nacl_abi_size_t kPpRectBytes = | 31 const nacl_abi_size_t kPpRectBytes = |
| 32 static_cast<nacl_abi_size_t>(sizeof(struct PP_Rect)); | 32 static_cast<nacl_abi_size_t>(sizeof(struct PP_Rect)); |
| 33 | 33 |
| 34 PP_Resource Create(PP_Module module, | 34 PP_Resource Create(PP_Module module, |
| 35 const struct PP_Size* size, | 35 const struct PP_Size* size, |
| 36 PP_Bool is_always_opaque) { | 36 PP_Bool is_always_opaque) { |
| 37 int32_t* size_as_int_ptr = | 37 int32_t* size_as_int_ptr = |
| 38 reinterpret_cast<int32_t*>(const_cast<struct PP_Size*>(size)); | 38 reinterpret_cast<int32_t*>(const_cast<struct PP_Size*>(size)); |
| 39 int32_t is_always_opaque_as_int = static_cast<int32_t>(is_always_opaque); | 39 int32_t is_always_opaque_as_int = static_cast<int32_t>(is_always_opaque); |
| 40 int64_t resource; | 40 PP_Resource resource; |
| 41 NaClSrpcError retval = | 41 NaClSrpcError retval = |
| 42 PpbGraphics2DRpcClient::PPB_Graphics2D_Create( | 42 PpbGraphics2DRpcClient::PPB_Graphics2D_Create( |
| 43 GetMainSrpcChannel(), | 43 GetMainSrpcChannel(), |
| 44 static_cast<int64_t>(module), | 44 module, |
| 45 kPpSizeBytes, | 45 kPpSizeBytes, |
| 46 size_as_int_ptr, | 46 size_as_int_ptr, |
| 47 is_always_opaque_as_int, | 47 is_always_opaque_as_int, |
| 48 &resource); | 48 &resource); |
| 49 if (retval == NACL_SRPC_RESULT_OK) { | 49 if (retval == NACL_SRPC_RESULT_OK) { |
| 50 return static_cast<PP_Resource>(resource); | 50 return resource; |
| 51 } else { | 51 } else { |
| 52 return kInvalidResourceId; | 52 return kInvalidResourceId; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 PP_Bool IsGraphics2D(PP_Resource resource) { | 56 PP_Bool IsGraphics2D(PP_Resource resource) { |
| 57 return PluginResource::GetAs<PluginGraphics2D>(resource).get() | 57 return PluginResource::GetAs<PluginGraphics2D>(resource).get() |
| 58 ? PP_TRUE : PP_FALSE; | 58 ? PP_TRUE : PP_FALSE; |
| 59 } | 59 } |
| 60 | 60 |
| 61 PP_Bool Describe(PP_Resource graphics_2d, | 61 PP_Bool Describe(PP_Resource graphics_2d, |
| 62 struct PP_Size* size, | 62 struct PP_Size* size, |
| 63 PP_Bool* is_always_opaque) { | 63 PP_Bool* is_always_opaque) { |
| 64 int32_t is_always_opaque_as_int; | 64 int32_t is_always_opaque_as_int; |
| 65 nacl_abi_size_t size_ret = kPpSizeBytes; | 65 nacl_abi_size_t size_ret = kPpSizeBytes; |
| 66 int32_t result; | 66 int32_t result; |
| 67 NaClSrpcError retval = | 67 NaClSrpcError retval = |
| 68 PpbGraphics2DRpcClient::PPB_Graphics2D_Describe( | 68 PpbGraphics2DRpcClient::PPB_Graphics2D_Describe( |
| 69 GetMainSrpcChannel(), | 69 GetMainSrpcChannel(), |
| 70 static_cast<int64_t>(graphics_2d), | 70 graphics_2d, |
| 71 &size_ret, | 71 &size_ret, |
| 72 reinterpret_cast<int32_t*>(size), | 72 reinterpret_cast<int32_t*>(size), |
| 73 &is_always_opaque_as_int, | 73 &is_always_opaque_as_int, |
| 74 &result); | 74 &result); |
| 75 if (retval == NACL_SRPC_RESULT_OK || size_ret != kPpSizeBytes) { | 75 if (retval == NACL_SRPC_RESULT_OK || size_ret != kPpSizeBytes) { |
| 76 *is_always_opaque = is_always_opaque_as_int ? PP_TRUE : PP_FALSE; | 76 *is_always_opaque = is_always_opaque_as_int ? PP_TRUE : PP_FALSE; |
| 77 return result ? PP_TRUE : PP_FALSE; | 77 return result ? PP_TRUE : PP_FALSE; |
| 78 } else { | 78 } else { |
| 79 return PP_FALSE; | 79 return PP_FALSE; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PaintImageData(PP_Resource graphics_2d, | 83 void PaintImageData(PP_Resource graphics_2d, |
| 84 PP_Resource image, | 84 PP_Resource image, |
| 85 const struct PP_Point* top_left, | 85 const struct PP_Point* top_left, |
| 86 const struct PP_Rect* src_rect) { | 86 const struct PP_Rect* src_rect) { |
| 87 // TODO(sehr,polina): there is no way to report a failure through this | 87 // TODO(sehr,polina): there is no way to report a failure through this |
| 88 // interface design other than crash. Let's find one. | 88 // interface design other than crash. Let's find one. |
| 89 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_PaintImageData( | 89 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_PaintImageData( |
| 90 GetMainSrpcChannel(), | 90 GetMainSrpcChannel(), |
| 91 static_cast<int64_t>(graphics_2d), | 91 graphics_2d, |
| 92 static_cast<int64_t>(image), | 92 image, |
| 93 kPpPointBytes, | 93 kPpPointBytes, |
| 94 reinterpret_cast<int32_t*>(const_cast<struct PP_Point*>(top_left)), | 94 reinterpret_cast<int32_t*>(const_cast<struct PP_Point*>(top_left)), |
| 95 kPpRectBytes, | 95 kPpRectBytes, |
| 96 reinterpret_cast<int32_t*>(const_cast<struct PP_Rect*>(src_rect))); | 96 reinterpret_cast<int32_t*>(const_cast<struct PP_Rect*>(src_rect))); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void Scroll(PP_Resource graphics_2d, | 99 void Scroll(PP_Resource graphics_2d, |
| 100 const struct PP_Rect* clip_rect, | 100 const struct PP_Rect* clip_rect, |
| 101 const struct PP_Point* amount) { | 101 const struct PP_Point* amount) { |
| 102 // TODO(sehr,polina): there is no way to report a failure through this | 102 // TODO(sehr,polina): there is no way to report a failure through this |
| 103 // interface design other than crash. Let's find one. | 103 // interface design other than crash. Let's find one. |
| 104 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_Scroll( | 104 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_Scroll( |
| 105 GetMainSrpcChannel(), | 105 GetMainSrpcChannel(), |
| 106 static_cast<int64_t>(graphics_2d), | 106 graphics_2d, |
| 107 kPpRectBytes, | 107 kPpRectBytes, |
| 108 reinterpret_cast<int32_t*>(const_cast<struct PP_Rect*>(clip_rect)), | 108 reinterpret_cast<int32_t*>(const_cast<struct PP_Rect*>(clip_rect)), |
| 109 kPpPointBytes, | 109 kPpPointBytes, |
| 110 reinterpret_cast<int32_t*>(const_cast<struct PP_Point*>(amount))); | 110 reinterpret_cast<int32_t*>(const_cast<struct PP_Point*>(amount))); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image) { | 113 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image) { |
| 114 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_ReplaceContents( | 114 (void) PpbGraphics2DRpcClient::PPB_Graphics2D_ReplaceContents( |
| 115 GetMainSrpcChannel(), | 115 GetMainSrpcChannel(), graphics_2d, image); |
| 116 static_cast<int64_t>(graphics_2d), | |
| 117 static_cast<int64_t>(image)); | |
| 118 } | 116 } |
| 119 | 117 |
| 120 int32_t Flush(PP_Resource graphics_2d, | 118 int32_t Flush(PP_Resource graphics_2d, |
| 121 struct PP_CompletionCallback callback) { | 119 struct PP_CompletionCallback callback) { |
| 122 UNREFERENCED_PARAMETER(graphics_2d); | 120 UNREFERENCED_PARAMETER(graphics_2d); |
| 123 UNREFERENCED_PARAMETER(callback); | 121 UNREFERENCED_PARAMETER(callback); |
| 124 // TODO(sehr): implement the call on the upcall channel once the completion | 122 // TODO(sehr): implement the call on the upcall channel once the completion |
| 125 // callback implementation is in place. | 123 // callback implementation is in place. |
| 126 NACL_UNIMPLEMENTED(); | 124 NACL_UNIMPLEMENTED(); |
| 127 return PP_ERROR_BADRESOURCE; | 125 return PP_ERROR_BADRESOURCE; |
| 128 } | 126 } |
| 129 | 127 |
| 130 } // namespace | 128 } // namespace |
| 131 | 129 |
| 132 const PPB_Graphics2D* PluginGraphics2D::GetInterface() { | 130 const PPB_Graphics2D* PluginGraphics2D::GetInterface() { |
| 133 static const PPB_Graphics2D intf = { | 131 static const PPB_Graphics2D intf = { |
| 134 Create, | 132 Create, |
| 135 IsGraphics2D, | 133 IsGraphics2D, |
| 136 Describe, | 134 Describe, |
| 137 PaintImageData, | 135 PaintImageData, |
| 138 Scroll, | 136 Scroll, |
| 139 ReplaceContents, | 137 ReplaceContents, |
| 140 Flush, | 138 Flush, |
| 141 }; | 139 }; |
| 142 return &intf; | 140 return &intf; |
| 143 } | 141 } |
| 144 | 142 |
| 145 } // namespace ppapi_proxy | 143 } // namespace ppapi_proxy |
| OLD | NEW |