| OLD | NEW |
| 1 // Copyright (c) 2012 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 "ppapi/proxy/video_decoder_resource.h" | 5 #include "ppapi/proxy/video_decoder_resource.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { | 55 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 VideoDecoderResource::Picture::~Picture() { | 58 VideoDecoderResource::Picture::~Picture() { |
| 59 } | 59 } |
| 60 | 60 |
| 61 VideoDecoderResource::VideoDecoderResource(Connection connection, | 61 VideoDecoderResource::VideoDecoderResource(Connection connection, |
| 62 PP_Instance instance) | 62 PP_Instance instance) |
| 63 : PluginResource(connection, instance), | 63 : PluginResource(connection, instance), |
| 64 num_decodes_(0), | 64 num_decodes_(0), |
| 65 min_picture_count_(0), |
| 65 get_picture_(NULL), | 66 get_picture_(NULL), |
| 66 get_picture_0_1_(NULL), | 67 get_picture_0_1_(NULL), |
| 67 gles2_impl_(NULL), | 68 gles2_impl_(NULL), |
| 68 initialized_(false), | 69 initialized_(false), |
| 69 testing_(false), | 70 testing_(false), |
| 70 // Set |decoder_last_error_| to PP_OK after successful initialization. | 71 // Set |decoder_last_error_| to PP_OK after successful initialization. |
| 71 // This makes error checking a little more concise, since we can check | 72 // This makes error checking a little more concise, since we can check |
| 72 // that the decoder has been initialized and hasn't returned an error by | 73 // that the decoder has been initialized and hasn't returned an error by |
| 73 // just testing |decoder_last_error_|. | 74 // just testing |decoder_last_error_|. |
| 74 decoder_last_error_(PP_ERROR_FAILED) { | 75 decoder_last_error_(PP_ERROR_FAILED) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 int32_t VideoDecoderResource::Initialize0_1( | 92 int32_t VideoDecoderResource::Initialize0_1( |
| 92 PP_Resource graphics_context, | 93 PP_Resource graphics_context, |
| 93 PP_VideoProfile profile, | 94 PP_VideoProfile profile, |
| 94 PP_Bool allow_software_fallback, | 95 PP_Bool allow_software_fallback, |
| 95 scoped_refptr<TrackedCallback> callback) { | 96 scoped_refptr<TrackedCallback> callback) { |
| 96 return Initialize(graphics_context, | 97 return Initialize(graphics_context, |
| 97 profile, | 98 profile, |
| 98 allow_software_fallback | 99 allow_software_fallback |
| 99 ? PP_HARDWAREACCELERATION_WITHFALLBACK | 100 ? PP_HARDWAREACCELERATION_WITHFALLBACK |
| 100 : PP_HARDWAREACCELERATION_ONLY, | 101 : PP_HARDWAREACCELERATION_ONLY, |
| 102 0, |
| 101 callback); | 103 callback); |
| 102 } | 104 } |
| 103 | 105 |
| 106 int32_t VideoDecoderResource::Initialize0_2( |
| 107 PP_Resource graphics_context, |
| 108 PP_VideoProfile profile, |
| 109 PP_HardwareAcceleration acceleration, |
| 110 scoped_refptr<TrackedCallback> callback) { |
| 111 return Initialize(graphics_context, |
| 112 profile, |
| 113 acceleration, |
| 114 0, |
| 115 callback); |
| 116 } |
| 117 |
| 104 int32_t VideoDecoderResource::Initialize( | 118 int32_t VideoDecoderResource::Initialize( |
| 105 PP_Resource graphics_context, | 119 PP_Resource graphics_context, |
| 106 PP_VideoProfile profile, | 120 PP_VideoProfile profile, |
| 107 PP_HardwareAcceleration acceleration, | 121 PP_HardwareAcceleration acceleration, |
| 122 uint32_t min_picture_count, |
| 108 scoped_refptr<TrackedCallback> callback) { | 123 scoped_refptr<TrackedCallback> callback) { |
| 109 if (initialized_) | 124 if (initialized_) |
| 110 return PP_ERROR_FAILED; | 125 return PP_ERROR_FAILED; |
| 111 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) | 126 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) |
| 112 return PP_ERROR_BADARGUMENT; | 127 return PP_ERROR_BADARGUMENT; |
| 128 if (min_picture_count > kMaximumPictureCount) |
| 129 return PP_ERROR_BADARGUMENT; |
| 113 if (initialize_callback_.get()) | 130 if (initialize_callback_.get()) |
| 114 return PP_ERROR_INPROGRESS; | 131 return PP_ERROR_INPROGRESS; |
| 115 if (!graphics_context) | 132 if (!graphics_context) |
| 116 return PP_ERROR_BADRESOURCE; | 133 return PP_ERROR_BADRESOURCE; |
| 117 | 134 |
| 135 min_picture_count_ = min_picture_count; |
| 136 |
| 118 HostResource host_resource; | 137 HostResource host_resource; |
| 119 if (!testing_) { | 138 if (!testing_) { |
| 120 // Create a new Graphics3D resource that can create texture resources to | 139 // Create a new Graphics3D resource that can create texture resources to |
| 121 // share with the plugin. We can't use the plugin's Graphics3D, since we | 140 // share with the plugin. We can't use the plugin's Graphics3D, since we |
| 122 // create textures on a proxy thread, and would interfere with the plugin. | 141 // create textures on a proxy thread, and would interfere with the plugin. |
| 123 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); | 142 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); |
| 124 if (enter_create.failed()) | 143 if (enter_create.failed()) |
| 125 return PP_ERROR_FAILED; | 144 return PP_ERROR_FAILED; |
| 126 int32_t attrib_list[] = {PP_GRAPHICS3DATTRIB_NONE}; | 145 int32_t attrib_list[] = {PP_GRAPHICS3DATTRIB_NONE}; |
| 127 graphics3d_ = | 146 graphics3d_ = |
| 128 ScopedPPResource(ScopedPPResource::PassRef(), | 147 ScopedPPResource(ScopedPPResource::PassRef(), |
| 129 enter_create.functions()->CreateGraphics3D( | 148 enter_create.functions()->CreateGraphics3D( |
| 130 pp_instance(), graphics_context, attrib_list)); | 149 pp_instance(), graphics_context, attrib_list)); |
| 131 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(graphics3d_.get(), | 150 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(graphics3d_.get(), |
| 132 false); | 151 false); |
| 133 if (enter_graphics.failed()) | 152 if (enter_graphics.failed()) |
| 134 return PP_ERROR_BADRESOURCE; | 153 return PP_ERROR_BADRESOURCE; |
| 135 | 154 |
| 136 PPB_Graphics3D_Shared* ppb_graphics3d_shared = | 155 PPB_Graphics3D_Shared* ppb_graphics3d_shared = |
| 137 static_cast<PPB_Graphics3D_Shared*>(enter_graphics.object()); | 156 static_cast<PPB_Graphics3D_Shared*>(enter_graphics.object()); |
| 138 gles2_impl_ = ppb_graphics3d_shared->gles2_impl(); | 157 gles2_impl_ = ppb_graphics3d_shared->gles2_impl(); |
| 139 host_resource = ppb_graphics3d_shared->host_resource(); | 158 host_resource = ppb_graphics3d_shared->host_resource(); |
| 140 } | 159 } |
| 141 | 160 |
| 142 initialize_callback_ = callback; | 161 initialize_callback_ = callback; |
| 143 | 162 |
| 144 Call<PpapiPluginMsg_VideoDecoder_InitializeReply>( | 163 Call<PpapiPluginMsg_VideoDecoder_InitializeReply>( |
| 145 RENDERER, | 164 RENDERER, |
| 146 PpapiHostMsg_VideoDecoder_Initialize( | 165 PpapiHostMsg_VideoDecoder_Initialize( |
| 147 host_resource, profile, acceleration), | 166 host_resource, profile, acceleration, min_picture_count), |
| 148 base::Bind(&VideoDecoderResource::OnPluginMsgInitializeComplete, this)); | 167 base::Bind(&VideoDecoderResource::OnPluginMsgInitializeComplete, this)); |
| 149 | 168 |
| 150 return PP_OK_COMPLETIONPENDING; | 169 return PP_OK_COMPLETIONPENDING; |
| 151 } | 170 } |
| 152 | 171 |
| 153 int32_t VideoDecoderResource::Decode(uint32_t decode_id, | 172 int32_t VideoDecoderResource::Decode(uint32_t decode_id, |
| 154 uint32_t size, | 173 uint32_t size, |
| 155 const void* buffer, | 174 const void* buffer, |
| 156 scoped_refptr<TrackedCallback> callback) { | 175 scoped_refptr<TrackedCallback> callback) { |
| 157 if (decoder_last_error_) | 176 if (decoder_last_error_) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 testing_ = true; | 371 testing_ = true; |
| 353 } | 372 } |
| 354 | 373 |
| 355 void VideoDecoderResource::OnPluginMsgRequestTextures( | 374 void VideoDecoderResource::OnPluginMsgRequestTextures( |
| 356 const ResourceMessageReplyParams& params, | 375 const ResourceMessageReplyParams& params, |
| 357 uint32_t num_textures, | 376 uint32_t num_textures, |
| 358 const PP_Size& size, | 377 const PP_Size& size, |
| 359 uint32_t texture_target, | 378 uint32_t texture_target, |
| 360 const std::vector<gpu::Mailbox>& mailboxes) { | 379 const std::vector<gpu::Mailbox>& mailboxes) { |
| 361 DCHECK(num_textures); | 380 DCHECK(num_textures); |
| 381 DCHECK(num_textures >= min_picture_count_); |
| 362 DCHECK(mailboxes.empty() || mailboxes.size() == num_textures); | 382 DCHECK(mailboxes.empty() || mailboxes.size() == num_textures); |
| 363 std::vector<uint32_t> texture_ids(num_textures); | 383 std::vector<uint32_t> texture_ids(num_textures); |
| 364 if (gles2_impl_) { | 384 if (gles2_impl_) { |
| 365 gles2_impl_->GenTextures(num_textures, &texture_ids.front()); | 385 gles2_impl_->GenTextures(num_textures, &texture_ids.front()); |
| 366 for (uint32_t i = 0; i < num_textures; ++i) { | 386 for (uint32_t i = 0; i < num_textures; ++i) { |
| 367 gles2_impl_->ActiveTexture(GL_TEXTURE0); | 387 gles2_impl_->ActiveTexture(GL_TEXTURE0); |
| 368 gles2_impl_->BindTexture(texture_target, texture_ids[i]); | 388 gles2_impl_->BindTexture(texture_target, texture_ids[i]); |
| 369 gles2_impl_->TexParameteri( | 389 gles2_impl_->TexParameteri( |
| 370 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 390 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 371 gles2_impl_->TexParameteri( | 391 gles2_impl_->TexParameteri( |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 get_picture_0_1_->texture_target = texture_target; | 574 get_picture_0_1_->texture_target = texture_target; |
| 555 get_picture_0_1_->texture_size = texture_size; | 575 get_picture_0_1_->texture_size = texture_size; |
| 556 get_picture_0_1_ = NULL; | 576 get_picture_0_1_ = NULL; |
| 557 } | 577 } |
| 558 | 578 |
| 559 received_pictures_.pop(); | 579 received_pictures_.pop(); |
| 560 } | 580 } |
| 561 | 581 |
| 562 } // namespace proxy | 582 } // namespace proxy |
| 563 } // namespace ppapi | 583 } // namespace ppapi |
| OLD | NEW |