| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" | 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 WebKit::WebView* web_view_; | 118 WebKit::WebView* web_view_; |
| 119 ggl::Context* context_; | 119 ggl::Context* context_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 #endif // ENABLE_GPU | 122 #endif // ENABLE_GPU |
| 123 | 123 |
| 124 class PlatformAudioImpl | 124 class PlatformAudioImpl |
| 125 : public pepper::PluginDelegate::PlatformAudio, | 125 : public pepper::PluginDelegate::PlatformAudio, |
| 126 public AudioMessageFilter::Delegate { | 126 public AudioMessageFilter::Delegate, |
| 127 public base::RefCountedThreadSafe<PlatformAudioImpl> { |
| 127 public: | 128 public: |
| 128 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 129 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) |
| 129 : client_(NULL), filter_(filter), stream_id_(0) { | 130 : client_(NULL), filter_(filter), stream_id_(0), |
| 131 main_message_loop_(MessageLoop::current()) { |
| 130 DCHECK(filter_); | 132 DCHECK(filter_); |
| 131 } | 133 } |
| 132 | 134 |
| 133 virtual ~PlatformAudioImpl() { | 135 virtual ~PlatformAudioImpl() { |
| 134 // Make sure we have been shut down. | 136 // Make sure we have been shut down. |
| 135 DCHECK_EQ(0, stream_id_); | 137 DCHECK_EQ(0, stream_id_); |
| 136 DCHECK(!client_); | 138 DCHECK(!client_); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // Initialize this audio context. StreamCreated() will be called when the | 141 // Initialize this audio context. StreamCreated() will be called when the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 170 | 172 |
| 171 virtual void OnVolume(double volume) { } | 173 virtual void OnVolume(double volume) { } |
| 172 | 174 |
| 173 // The client to notify when the stream is created. | 175 // The client to notify when the stream is created. |
| 174 pepper::PluginDelegate::PlatformAudio::Client* client_; | 176 pepper::PluginDelegate::PlatformAudio::Client* client_; |
| 175 // MessageFilter used to send/receive IPC. | 177 // MessageFilter used to send/receive IPC. |
| 176 scoped_refptr<AudioMessageFilter> filter_; | 178 scoped_refptr<AudioMessageFilter> filter_; |
| 177 // Our ID on the MessageFilter. | 179 // Our ID on the MessageFilter. |
| 178 int32 stream_id_; | 180 int32 stream_id_; |
| 179 | 181 |
| 182 MessageLoop* main_message_loop_; |
| 183 |
| 180 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); | 184 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); |
| 181 }; | 185 }; |
| 182 | 186 |
| 183 #ifdef ENABLE_GPU | 187 #ifdef ENABLE_GPU |
| 184 | 188 |
| 185 bool PlatformContext3DImpl::Init() { | 189 bool PlatformContext3DImpl::Init() { |
| 186 // Ignore initializing more than once. | 190 // Ignore initializing more than once. |
| 187 if (context_) | 191 if (context_) |
| 188 return true; | 192 return true; |
| 189 | 193 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 client_ = client; | 278 client_ = client; |
| 275 | 279 |
| 276 ViewHostMsg_Audio_CreateStream_Params params; | 280 ViewHostMsg_Audio_CreateStream_Params params; |
| 277 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; | 281 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; |
| 278 params.params.channels = 2; | 282 params.params.channels = 2; |
| 279 params.params.sample_rate = sample_rate; | 283 params.params.sample_rate = sample_rate; |
| 280 params.params.bits_per_sample = 16; | 284 params.params.bits_per_sample = 16; |
| 281 params.params.samples_per_packet = sample_count; | 285 params.params.samples_per_packet = sample_count; |
| 282 | 286 |
| 283 stream_id_ = filter_->AddDelegate(this); | 287 stream_id_ = filter_->AddDelegate(this); |
| 288 |
| 284 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, | 289 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, |
| 285 true)); | 290 true)); |
| 286 } | 291 } |
| 287 | 292 |
| 288 void PlatformAudioImpl::OnLowLatencyCreated( | 293 void PlatformAudioImpl::OnLowLatencyCreated( |
| 289 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 294 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
| 290 uint32 length) { | 295 uint32 length) { |
| 291 #if defined(OS_WIN) | 296 #if defined(OS_WIN) |
| 292 DCHECK(handle); | 297 DCHECK(handle); |
| 293 DCHECK(socket_handle); | 298 DCHECK(socket_handle); |
| 294 #else | 299 #else |
| 295 DCHECK_NE(-1, handle.fd); | 300 DCHECK_NE(-1, handle.fd); |
| 296 DCHECK_NE(-1, socket_handle); | 301 DCHECK_NE(-1, socket_handle); |
| 297 #endif | 302 #endif |
| 298 DCHECK(length); | 303 DCHECK(length); |
| 299 | 304 |
| 300 client_->StreamCreated(handle, length, socket_handle); | 305 if (MessageLoop::current() == main_message_loop_) { |
| 306 if (client_) { |
| 307 client_->StreamCreated(handle, length, socket_handle); |
| 308 } |
| 309 } else { |
| 310 main_message_loop_->PostTask(FROM_HERE, |
| 311 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, |
| 312 handle, socket_handle, length)); |
| 313 } |
| 301 } | 314 } |
| 302 | 315 |
| 303 void PlatformAudioImpl::ShutDown() { | 316 void PlatformAudioImpl::ShutDown() { |
| 304 // Make sure we don't call shutdown more than once. | 317 // Make sure we don't call shutdown more than once. |
| 305 if (!stream_id_) { | 318 if (!stream_id_) { |
| 306 return; | 319 return; |
| 307 } | 320 } |
| 308 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); | 321 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); |
| 309 filter_->RemoveDelegate(stream_id_); | 322 filter_->RemoveDelegate(stream_id_); |
| 310 stream_id_ = 0; | 323 stream_id_ = 0; |
| 311 client_ = NULL; | 324 client_ = NULL; |
| 325 // Release on the IO thread so that we avoid race problems with |
| 326 // OnLowLatencyCreated. |
| 327 filter_->message_loop()->ReleaseSoon(FROM_HERE, this); |
| 312 } | 328 } |
| 313 | 329 |
| 314 // Implements the VideoDecoder. | 330 // Implements the VideoDecoder. |
| 315 class PlatformVideoDecoderImpl | 331 class PlatformVideoDecoderImpl |
| 316 : public pepper::PluginDelegate::PlatformVideoDecoder { | 332 : public pepper::PluginDelegate::PlatformVideoDecoder { |
| 317 public: | 333 public: |
| 318 PlatformVideoDecoderImpl() | 334 PlatformVideoDecoderImpl() |
| 319 : input_buffer_size_(0), | 335 : input_buffer_size_(0), |
| 320 next_dib_id_(0), | 336 next_dib_id_(0), |
| 321 dib_(NULL) { | 337 dib_(NULL) { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 569 |
| 554 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 570 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
| 555 int index) { | 571 int index) { |
| 556 render_view_->reportFindInPageSelection( | 572 render_view_->reportFindInPageSelection( |
| 557 identifier, index + 1, WebKit::WebRect()); | 573 identifier, index + 1, WebKit::WebRect()); |
| 558 } | 574 } |
| 559 | 575 |
| 560 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( | 576 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( |
| 561 uint32_t sample_rate, uint32_t sample_count, | 577 uint32_t sample_rate, uint32_t sample_count, |
| 562 pepper::PluginDelegate::PlatformAudio::Client* client) { | 578 pepper::PluginDelegate::PlatformAudio::Client* client) { |
| 563 scoped_ptr<PlatformAudioImpl> audio( | 579 scoped_refptr<PlatformAudioImpl> audio( |
| 564 new PlatformAudioImpl(render_view_->audio_message_filter())); | 580 new PlatformAudioImpl(render_view_->audio_message_filter())); |
| 565 if (audio->Initialize(sample_rate, sample_count, client)) { | 581 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 566 return audio.release(); | 582 return audio.release(); |
| 567 } else { | 583 } else { |
| 568 return NULL; | 584 return NULL; |
| 569 } | 585 } |
| 570 } | 586 } |
| 571 | 587 |
| 572 bool PepperPluginDelegateImpl::RunFileChooser( | 588 bool PepperPluginDelegateImpl::RunFileChooser( |
| 573 const WebKit::WebFileChooserParams& params, | 589 const WebKit::WebFileChooserParams& params, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 } | 840 } |
| 825 | 841 |
| 826 void PepperPluginDelegateImpl::DidStopLoading() { | 842 void PepperPluginDelegateImpl::DidStopLoading() { |
| 827 render_view_->DidStopLoadingForPlugin(); | 843 render_view_->DidStopLoadingForPlugin(); |
| 828 } | 844 } |
| 829 | 845 |
| 830 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { | 846 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { |
| 831 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( | 847 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( |
| 832 render_view_->routing_id(), restrictions)); | 848 render_view_->routing_id(), restrictions)); |
| 833 } | 849 } |
| OLD | NEW |