| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/proxy/ppb_video_decoder_proxy.h" | 5 #include "ppapi/proxy/ppb_video_decoder_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "ppapi/proxy/enter_proxy.h" | 9 #include "ppapi/proxy/enter_proxy.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/ppb_buffer_proxy.h" | 12 #include "ppapi/proxy/ppb_buffer_proxy.h" |
| 13 #include "ppapi/proxy/ppb_context_3d_proxy.h" | 13 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
| 14 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 14 #include "ppapi/thunk/enter.h" | 15 #include "ppapi/thunk/enter.h" |
| 15 #include "ppapi/thunk/resource_creation_api.h" | 16 #include "ppapi/thunk/resource_creation_api.h" |
| 16 #include "ppapi/thunk/thunk.h" | 17 #include "ppapi/thunk/thunk.h" |
| 17 | 18 |
| 18 using ppapi::thunk::EnterResourceNoLock; | 19 using ppapi::thunk::EnterResourceNoLock; |
| 19 using ppapi::thunk::PPB_Buffer_API; | 20 using ppapi::thunk::PPB_Buffer_API; |
| 20 using ppapi::thunk::PPB_Context3D_API; | 21 using ppapi::thunk::PPB_Context3D_API; |
| 22 using ppapi::thunk::PPB_Graphics3D_API; |
| 21 using ppapi::thunk::PPB_VideoDecoder_API; | 23 using ppapi::thunk::PPB_VideoDecoder_API; |
| 22 | 24 |
| 23 namespace ppapi { | 25 namespace ppapi { |
| 24 namespace proxy { | 26 namespace proxy { |
| 25 | 27 |
| 26 class VideoDecoder : public Resource, public VideoDecoderImpl { | 28 class VideoDecoder : public Resource, public VideoDecoderImpl { |
| 27 public: | 29 public: |
| 28 // You must call Init() before using this class. | 30 // You must call Init() before using this class. |
| 29 explicit VideoDecoder(const HostResource& resource); | 31 explicit VideoDecoder(const HostResource& resource); |
| 30 virtual ~VideoDecoder(); | 32 virtual ~VideoDecoder(); |
| 31 | 33 |
| 32 static VideoDecoder* Create(const HostResource& resource, | 34 static VideoDecoder* Create(const HostResource& resource, |
| 33 PP_Resource context3d_id, | 35 PP_Resource graphics_context, |
| 34 const PP_VideoConfigElement* config); | 36 const PP_VideoConfigElement* config); |
| 35 | 37 |
| 36 // Resource overrides. | 38 // Resource overrides. |
| 37 virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; | 39 virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; |
| 38 | 40 |
| 39 // PPB_VideoDecoder_API implementation. | 41 // PPB_VideoDecoder_API implementation. |
| 40 virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 42 virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
| 41 PP_CompletionCallback callback) OVERRIDE; | 43 PP_CompletionCallback callback) OVERRIDE; |
| 42 virtual void AssignPictureBuffers( | 44 virtual void AssignPictureBuffers( |
| 43 uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE; | 45 uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK, | 201 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK, |
| 200 OnMsgEndOfBitstreamACK) | 202 OnMsgEndOfBitstreamACK) |
| 201 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK) | 203 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK) |
| 202 IPC_MESSAGE_UNHANDLED(handled = false) | 204 IPC_MESSAGE_UNHANDLED(handled = false) |
| 203 IPC_END_MESSAGE_MAP() | 205 IPC_END_MESSAGE_MAP() |
| 204 DCHECK(handled); | 206 DCHECK(handled); |
| 205 return handled; | 207 return handled; |
| 206 } | 208 } |
| 207 | 209 |
| 208 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( | 210 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( |
| 209 PP_Instance instance, PP_Resource context3d_id, | 211 PP_Instance instance, |
| 212 PP_Resource graphics_context, |
| 210 const PP_VideoConfigElement* config) { | 213 const PP_VideoConfigElement* config) { |
| 211 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 214 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 212 // Dispatcher is null if it cannot find the instance passed to it (i.e. if the | 215 // Dispatcher is null if it cannot find the instance passed to it (i.e. if the |
| 213 // client passes in an invalid instance). | 216 // client passes in an invalid instance). |
| 214 if (!dispatcher) | 217 if (!dispatcher) |
| 215 return 0; | 218 return 0; |
| 216 | 219 |
| 217 std::vector<PP_VideoConfigElement> copied; | 220 std::vector<PP_VideoConfigElement> copied; |
| 218 if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied)) | 221 if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied)) |
| 219 return 0; | 222 return 0; |
| 220 | 223 |
| 221 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); | 224 HostResource host_context; |
| 222 if (enter_context.failed()) | 225 gpu::gles2::GLES2Implementation* gles2_impl = NULL; |
| 223 return 0; | 226 |
| 224 Context3D* ppb_context = | 227 EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false); |
| 225 static_cast<Context3D*>(enter_context.object()); | 228 if (enter_context.succeeded()) { |
| 226 HostResource host_context = ppb_context->host_resource(); | 229 Context3D* context = static_cast<Context3D*>(enter_context.object()); |
| 230 host_context = context->host_resource(); |
| 231 gles2_impl = context->gles2_impl(); |
| 232 } else { |
| 233 EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context, |
| 234 true); |
| 235 if (enter_context.failed()) |
| 236 return 0; |
| 237 Graphics3D* context = static_cast<Graphics3D*>(enter_context.object()); |
| 238 host_context = context->host_resource(); |
| 239 gles2_impl = context->gles2_impl(); |
| 240 } |
| 227 | 241 |
| 228 HostResource result; | 242 HostResource result; |
| 229 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( | 243 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( |
| 230 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, | 244 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, |
| 231 host_context, copied, &result)); | 245 host_context, copied, &result)); |
| 232 if (result.is_null()) | 246 if (result.is_null()) |
| 233 return 0; | 247 return 0; |
| 234 | 248 |
| 235 // Need a scoped_refptr to keep the object alive during the Init call. | 249 // Need a scoped_refptr to keep the object alive during the Init call. |
| 236 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); | 250 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); |
| 237 if (!decoder->Init(context3d_id, enter_context.object(), config)) | 251 decoder->InitCommon(graphics_context, gles2_impl); |
| 238 return 0; | |
| 239 return decoder->GetReference(); | 252 return decoder->GetReference(); |
| 240 } | 253 } |
| 241 | 254 |
| 242 void PPB_VideoDecoder_Proxy::OnMsgCreate( | 255 void PPB_VideoDecoder_Proxy::OnMsgCreate( |
| 243 PP_Instance instance, const HostResource& context3d_id, | 256 PP_Instance instance, const HostResource& graphics_context, |
| 244 const std::vector<PP_VideoConfigElement>& config, | 257 const std::vector<PP_VideoConfigElement>& config, |
| 245 HostResource* result) { | 258 HostResource* result) { |
| 246 thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance, | 259 thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance, |
| 247 true); | 260 true); |
| 248 if (resource_creation.failed()) | 261 if (resource_creation.failed()) |
| 249 return; | 262 return; |
| 250 | 263 |
| 251 std::vector<PP_VideoConfigElement> copied = config; | 264 std::vector<PP_VideoConfigElement> copied = config; |
| 252 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR); | 265 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR); |
| 253 | 266 |
| 254 // Make the resource and get the API pointer to its interface. | 267 // Make the resource and get the API pointer to its interface. |
| 255 result->SetHostResource( | 268 result->SetHostResource( |
| 256 instance, resource_creation.functions()->CreateVideoDecoder( | 269 instance, resource_creation.functions()->CreateVideoDecoder( |
| 257 instance, context3d_id.host_resource(), &copied.front())); | 270 instance, graphics_context.host_resource(), &copied.front())); |
| 258 } | 271 } |
| 259 | 272 |
| 260 void PPB_VideoDecoder_Proxy::OnMsgDecode( | 273 void PPB_VideoDecoder_Proxy::OnMsgDecode( |
| 261 const HostResource& decoder, | 274 const HostResource& decoder, |
| 262 const HostResource& buffer, int32 id, int32 size) { | 275 const HostResource& buffer, int32 id, int32 size) { |
| 263 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( | 276 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( |
| 264 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); | 277 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); |
| 265 | 278 |
| 266 PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size }; | 279 PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size }; |
| 267 ppb_video_decoder_target()->Decode( | 280 ppb_video_decoder_target()->Decode( |
| 268 decoder.host_resource(), &bitstream, callback.pp_completion_callback()); | 281 decoder.host_resource(), &bitstream, callback.pp_completion_callback()); |
| 269 } | 282 } |
| 270 | 283 |
| 271 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( | 284 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( |
| 272 const HostResource& decoder, | 285 const HostResource& decoder, |
| 273 const std::vector<PP_PictureBuffer_Dev>& buffers) { | 286 const std::vector<PP_PictureBuffer_Dev>& buffers) { |
| 274 DCHECK(!buffers.empty()); | 287 DCHECK(!buffers.empty()); |
| 275 const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); | 288 const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); |
| 276 | 289 |
| 277 ppb_video_decoder_target()->AssignPictureBuffers( | 290 ppb_video_decoder_target()->AssignPictureBuffers( |
| 278 decoder.host_resource(), buffers.size(), buffer_array); | 291 decoder.host_resource(), buffers.size(), buffer_array); |
| 279 } | 292 } |
| 280 | 293 |
| 281 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( | 294 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( |
| 282 const HostResource& decoder, int32 picture_buffer_id) { | 295 const HostResource& decoder, int32 picture_buffer_id) { |
| 283 ppb_video_decoder_target()->ReusePictureBuffer( | 296 ppb_video_decoder_target()->ReusePictureBuffer( |
| 284 decoder.host_resource(), picture_buffer_id); | 297 decoder.host_resource(), picture_buffer_id); |
| 285 } | 298 } |
| 286 | 299 |
| 287 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { | 300 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { |
| 288 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( | 301 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 | 349 |
| 337 void PPB_VideoDecoder_Proxy::OnMsgResetACK( | 350 void PPB_VideoDecoder_Proxy::OnMsgResetACK( |
| 338 const HostResource& decoder, int32_t result) { | 351 const HostResource& decoder, int32_t result) { |
| 339 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | 352 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); |
| 340 if (enter.succeeded()) | 353 if (enter.succeeded()) |
| 341 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); | 354 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); |
| 342 } | 355 } |
| 343 | 356 |
| 344 } // namespace proxy | 357 } // namespace proxy |
| 345 } // namespace ppapi | 358 } // namespace ppapi |
| OLD | NEW |