| OLD | NEW |
| 1 // Copyright (c) 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 be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.h" | 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include "native_client/src/include/portability.h" | 9 #include "native_client/src/include/portability.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" | 10 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" |
| 11 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" | 11 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 27 const nacl_abi_size_t kPPSizeBytes = | 27 const nacl_abi_size_t kPPSizeBytes = |
| 28 static_cast<nacl_abi_size_t>(sizeof(struct PP_Size)); | 28 static_cast<nacl_abi_size_t>(sizeof(struct PP_Size)); |
| 29 const nacl_abi_size_t kPPPointBytes = | 29 const nacl_abi_size_t kPPPointBytes = |
| 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_Instance instance, | 34 PP_Resource Create(PP_Instance instance, |
| 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 DebugPrintf("PPB_Graphics2D::Create: instance=%"NACL_PRIu32"\n", instance); | 37 DebugPrintf("PPB_Graphics2D::Create: instance=%"NACL_PRId32"\n", instance); |
| 38 char* size_as_char_ptr = | 38 char* size_as_char_ptr = |
| 39 reinterpret_cast<char*>(const_cast<struct PP_Size*>(size)); | 39 reinterpret_cast<char*>(const_cast<struct PP_Size*>(size)); |
| 40 int32_t is_always_opaque_as_int = static_cast<int32_t>(is_always_opaque); | 40 int32_t is_always_opaque_as_int = static_cast<int32_t>(is_always_opaque); |
| 41 PP_Resource resource = kInvalidResourceId; | 41 PP_Resource resource = kInvalidResourceId; |
| 42 NaClSrpcError srpc_result = | 42 NaClSrpcError srpc_result = |
| 43 PpbGraphics2DRpcClient::PPB_Graphics2D_Create( | 43 PpbGraphics2DRpcClient::PPB_Graphics2D_Create( |
| 44 GetMainSrpcChannel(), | 44 GetMainSrpcChannel(), |
| 45 instance, | 45 instance, |
| 46 kPPSizeBytes, | 46 kPPSizeBytes, |
| 47 size_as_char_ptr, | 47 size_as_char_ptr, |
| 48 is_always_opaque_as_int, | 48 is_always_opaque_as_int, |
| 49 &resource); | 49 &resource); |
| 50 DebugPrintf("PPB_Graphics2D::Create: %s\n", NaClSrpcErrorString(srpc_result)); | 50 DebugPrintf("PPB_Graphics2D::Create: %s\n", NaClSrpcErrorString(srpc_result)); |
| 51 if (srpc_result == NACL_SRPC_RESULT_OK) { | 51 if (srpc_result == NACL_SRPC_RESULT_OK) { |
| 52 scoped_refptr<PluginGraphics2D> graphics_2d = | 52 scoped_refptr<PluginGraphics2D> graphics_2d = |
| 53 PluginResource::AdoptAs<PluginGraphics2D>(resource); | 53 PluginResource::AdoptAs<PluginGraphics2D>(resource); |
| 54 if (graphics_2d.get()) { | 54 if (graphics_2d.get()) { |
| 55 return resource; | 55 return resource; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 return kInvalidResourceId; | 58 return kInvalidResourceId; |
| 59 } | 59 } |
| 60 | 60 |
| 61 PP_Bool IsGraphics2D(PP_Resource resource) { | 61 PP_Bool IsGraphics2D(PP_Resource resource) { |
| 62 DebugPrintf("PPB_Graphics2D::IsGraphics2D: resource=%"NACL_PRIu32"\n", | 62 DebugPrintf("PPB_Graphics2D::IsGraphics2D: resource=%"NACL_PRId32"\n", |
| 63 resource); | 63 resource); |
| 64 return PluginResource::GetAs<PluginGraphics2D>(resource).get() | 64 return PP_FromBool(PluginResource::GetAs<PluginGraphics2D>(resource).get()); |
| 65 ? PP_TRUE : PP_FALSE; | |
| 66 } | 65 } |
| 67 | 66 |
| 68 PP_Bool Describe(PP_Resource graphics_2d, | 67 PP_Bool Describe(PP_Resource graphics_2d, |
| 69 struct PP_Size* size, | 68 struct PP_Size* size, |
| 70 PP_Bool* is_always_opaque) { | 69 PP_Bool* is_always_opaque) { |
| 71 DebugPrintf("PPB_Graphics2D::Describe: graphics_2d=%"NACL_PRIu32"\n", | 70 DebugPrintf("PPB_Graphics2D::Describe: graphics_2d=%"NACL_PRId32"\n", |
| 72 graphics_2d); | 71 graphics_2d); |
| 73 if (size == NULL || is_always_opaque == NULL) { | 72 if (size == NULL || is_always_opaque == NULL) { |
| 74 return PP_FALSE; | 73 return PP_FALSE; |
| 75 } | 74 } |
| 76 int32_t is_always_opaque_as_int; | 75 int32_t is_always_opaque_as_int; |
| 77 nacl_abi_size_t size_ret = kPPSizeBytes; | 76 nacl_abi_size_t size_ret = kPPSizeBytes; |
| 78 int32_t result; | 77 int32_t result; |
| 79 NaClSrpcError srpc_result = | 78 NaClSrpcError srpc_result = |
| 80 PpbGraphics2DRpcClient::PPB_Graphics2D_Describe( | 79 PpbGraphics2DRpcClient::PPB_Graphics2D_Describe( |
| 81 GetMainSrpcChannel(), | 80 GetMainSrpcChannel(), |
| 82 graphics_2d, | 81 graphics_2d, |
| 83 &size_ret, | 82 &size_ret, |
| 84 reinterpret_cast<char*>(size), | 83 reinterpret_cast<char*>(size), |
| 85 &is_always_opaque_as_int, | 84 &is_always_opaque_as_int, |
| 86 &result); | 85 &result); |
| 87 DebugPrintf("PPB_Graphics2D::Describe: %s\n", | 86 DebugPrintf("PPB_Graphics2D::Describe: %s\n", |
| 88 NaClSrpcErrorString(srpc_result)); | 87 NaClSrpcErrorString(srpc_result)); |
| 89 if (srpc_result == NACL_SRPC_RESULT_OK || size_ret != kPPSizeBytes) { | 88 if (srpc_result == NACL_SRPC_RESULT_OK || size_ret != kPPSizeBytes) { |
| 90 *is_always_opaque = is_always_opaque_as_int ? PP_TRUE : PP_FALSE; | 89 *is_always_opaque = PP_FromBool(is_always_opaque_as_int); |
| 91 return result ? PP_TRUE : PP_FALSE; | 90 return PP_FromBool(result); |
| 92 } else { | 91 } else { |
| 93 return PP_FALSE; | 92 return PP_FALSE; |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 void PaintImageData(PP_Resource graphics_2d, | 96 void PaintImageData(PP_Resource graphics_2d, |
| 98 PP_Resource image, | 97 PP_Resource image, |
| 99 const struct PP_Point* top_left, | 98 const struct PP_Point* top_left, |
| 100 const struct PP_Rect* src_rect) { | 99 const struct PP_Rect* src_rect) { |
| 101 DebugPrintf("PPB_Graphics2D::PaintImageData: graphics_2d=%"NACL_PRIu32"\n", | 100 DebugPrintf("PPB_Graphics2D::PaintImageData: graphics_2d=%"NACL_PRId32"\n", |
| 102 graphics_2d); | 101 graphics_2d); |
| 103 nacl_abi_size_t rect_size = kPPRectBytes; | 102 nacl_abi_size_t rect_size = kPPRectBytes; |
| 104 if (src_rect == NULL) { // Corresponds to the entire image. | 103 if (src_rect == NULL) { // Corresponds to the entire image. |
| 105 rect_size = 0; | 104 rect_size = 0; |
| 106 } | 105 } |
| 107 NaClSrpcError srpc_result = | 106 NaClSrpcError srpc_result = |
| 108 PpbGraphics2DRpcClient::PPB_Graphics2D_PaintImageData( | 107 PpbGraphics2DRpcClient::PPB_Graphics2D_PaintImageData( |
| 109 GetMainSrpcChannel(), | 108 GetMainSrpcChannel(), |
| 110 graphics_2d, | 109 graphics_2d, |
| 111 image, | 110 image, |
| 112 kPPPointBytes, | 111 kPPPointBytes, |
| 113 reinterpret_cast<char*>(const_cast<struct PP_Point*>(top_left)), | 112 reinterpret_cast<char*>(const_cast<struct PP_Point*>(top_left)), |
| 114 rect_size, | 113 rect_size, |
| 115 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(src_rect))); | 114 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(src_rect))); |
| 116 DebugPrintf("PPB_Graphics2D::PaintImageData: %s\n", | 115 DebugPrintf("PPB_Graphics2D::PaintImageData: %s\n", |
| 117 NaClSrpcErrorString(srpc_result)); | 116 NaClSrpcErrorString(srpc_result)); |
| 118 } | 117 } |
| 119 | 118 |
| 120 void Scroll(PP_Resource graphics_2d, | 119 void Scroll(PP_Resource graphics_2d, |
| 121 const struct PP_Rect* clip_rect, | 120 const struct PP_Rect* clip_rect, |
| 122 const struct PP_Point* amount) { | 121 const struct PP_Point* amount) { |
| 123 DebugPrintf("PPB_Graphics2D::Scroll: graphics_2d=%"NACL_PRIu32"\n", | 122 DebugPrintf("PPB_Graphics2D::Scroll: graphics_2d=%"NACL_PRId32"\n", |
| 124 graphics_2d); | 123 graphics_2d); |
| 125 nacl_abi_size_t rect_size = kPPRectBytes; | 124 nacl_abi_size_t rect_size = kPPRectBytes; |
| 126 if (clip_rect == NULL) { // Corresponds to the entire graphics region. | 125 if (clip_rect == NULL) { // Corresponds to the entire graphics region. |
| 127 rect_size = 0; | 126 rect_size = 0; |
| 128 } | 127 } |
| 129 NaClSrpcError srpc_result = PpbGraphics2DRpcClient::PPB_Graphics2D_Scroll( | 128 NaClSrpcError srpc_result = PpbGraphics2DRpcClient::PPB_Graphics2D_Scroll( |
| 130 GetMainSrpcChannel(), | 129 GetMainSrpcChannel(), |
| 131 graphics_2d, | 130 graphics_2d, |
| 132 rect_size, | 131 rect_size, |
| 133 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(clip_rect)), | 132 reinterpret_cast<char*>(const_cast<struct PP_Rect*>(clip_rect)), |
| 134 kPPPointBytes, | 133 kPPPointBytes, |
| 135 reinterpret_cast<char*>(const_cast<struct PP_Point*>(amount))); | 134 reinterpret_cast<char*>(const_cast<struct PP_Point*>(amount))); |
| 136 DebugPrintf("PPB_Graphics2D::Scroll: %s\n", NaClSrpcErrorString(srpc_result)); | 135 DebugPrintf("PPB_Graphics2D::Scroll: %s\n", NaClSrpcErrorString(srpc_result)); |
| 137 } | 136 } |
| 138 | 137 |
| 139 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image) { | 138 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image) { |
| 140 DebugPrintf("PPB_Graphics2D::ReplaceContents: graphics_2d=%"NACL_PRIu32"\n", | 139 DebugPrintf("PPB_Graphics2D::ReplaceContents: graphics_2d=%"NACL_PRId32"\n", |
| 141 graphics_2d); | 140 graphics_2d); |
| 142 NaClSrpcError srpc_result = | 141 NaClSrpcError srpc_result = |
| 143 PpbGraphics2DRpcClient::PPB_Graphics2D_ReplaceContents( | 142 PpbGraphics2DRpcClient::PPB_Graphics2D_ReplaceContents( |
| 144 GetMainSrpcChannel(), graphics_2d, image); | 143 GetMainSrpcChannel(), graphics_2d, image); |
| 145 DebugPrintf("PPB_Graphics2D::ReplaceContents: %s\n", | 144 DebugPrintf("PPB_Graphics2D::ReplaceContents: %s\n", |
| 146 NaClSrpcErrorString(srpc_result)); | 145 NaClSrpcErrorString(srpc_result)); |
| 147 } | 146 } |
| 148 | 147 |
| 149 int32_t Flush(PP_Resource graphics_2d, | 148 int32_t Flush(PP_Resource graphics_2d, |
| 150 struct PP_CompletionCallback callback) { | 149 struct PP_CompletionCallback callback) { |
| 151 DebugPrintf("PPB_Graphics2D::Flush: graphics_2d=%"NACL_PRIu32"\n", | 150 DebugPrintf("PPB_Graphics2D::Flush: graphics_2d=%"NACL_PRId32"\n", |
| 152 graphics_2d); | 151 graphics_2d); |
| 153 int32_t callback_id = | 152 int32_t callback_id = |
| 154 CompletionCallbackTable::Get()->AddCallback(callback); | 153 CompletionCallbackTable::Get()->AddCallback(callback); |
| 155 if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. | 154 if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. |
| 156 return PP_ERROR_BLOCKS_MAIN_THREAD; | 155 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 157 | 156 |
| 158 int32_t pp_error; | 157 int32_t pp_error; |
| 159 NaClSrpcError srpc_result = | 158 NaClSrpcError srpc_result = |
| 160 PpbGraphics2DRpcClient::PPB_Graphics2D_Flush( | 159 PpbGraphics2DRpcClient::PPB_Graphics2D_Flush( |
| 161 GetMainSrpcChannel(), graphics_2d, callback_id, &pp_error); | 160 GetMainSrpcChannel(), graphics_2d, callback_id, &pp_error); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 Describe, | 173 Describe, |
| 175 PaintImageData, | 174 PaintImageData, |
| 176 Scroll, | 175 Scroll, |
| 177 ReplaceContents, | 176 ReplaceContents, |
| 178 Flush, | 177 Flush, |
| 179 }; | 178 }; |
| 180 return &graphics_2d_interface; | 179 return &graphics_2d_interface; |
| 181 } | 180 } |
| 182 | 181 |
| 183 } // namespace ppapi_proxy | 182 } // namespace ppapi_proxy |
| OLD | NEW |