Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: Source/web/WebMediaPlayerClientImpl.cpp

Issue 203213008: Move deferred loading logic from WebMediaPlayerClientImpl to HTMLMediaElement. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing semicolon Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/WebMediaPlayerClientImpl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "config.h" 5 #include "config.h"
6 #include "WebMediaPlayerClientImpl.h" 6 #include "WebMediaPlayerClientImpl.h"
7 7
8 #include "WebDocument.h" 8 #include "WebDocument.h"
9 #include "WebFrameClient.h" 9 #include "WebFrameClient.h"
10 #include "WebFrameImpl.h" 10 #include "WebFrameImpl.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 { 171 {
172 m_client->mediaPlayerRequestFullscreen(); 172 m_client->mediaPlayerRequestFullscreen();
173 } 173 }
174 174
175 void WebMediaPlayerClientImpl::requestSeek(double time) 175 void WebMediaPlayerClientImpl::requestSeek(double time)
176 { 176 {
177 m_client->mediaPlayerRequestSeek(time); 177 m_client->mediaPlayerRequestSeek(time);
178 } 178 }
179 179
180 // MediaPlayer ------------------------------------------------- 180 // MediaPlayer -------------------------------------------------
181 181 void WebMediaPlayerClientImpl::load(WebMediaPlayer::LoadType loadType, const WTF ::String& url, WebMediaPlayer::CORSMode corsMode)
182 void WebMediaPlayerClientImpl::load(WebMediaPlayer::LoadType loadType, const WTF ::String& url)
183 { 182 {
184 m_url = KURL(ParsedURLString, url); 183 ASSERT(!m_webMediaPlayer);
185 m_loadType = loadType;
186
187 if (m_preload == MediaPlayer::None) {
188 #if ENABLE(WEB_AUDIO)
189 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlay er's WebAudioSourceProvider.
190 #endif
191 m_webMediaPlayer.clear();
192 m_delayingLoad = true;
193 } else
194 loadInternal();
195 }
196
197 void WebMediaPlayerClientImpl::loadInternal()
198 {
199 #if ENABLE(WEB_AUDIO)
200 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider.
201 #endif
202 184
203 // FIXME: Remove this cast 185 // FIXME: Remove this cast
204 LocalFrame* frame = mediaElement().document().frame(); 186 LocalFrame* frame = mediaElement().document().frame();
205 187
206 WebURL poster = m_client->mediaPlayerPosterURL(); 188 WebURL poster = m_client->mediaPlayerPosterURL();
207 189
208 // This does not actually check whether the hardware can support accelerated 190 // This does not actually check whether the hardware can support accelerated
209 // compositing, but only if the flag is set. However, this is checked lazily 191 // compositing, but only if the flag is set. However, this is checked lazily
210 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there 192 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there
211 // if necessary. 193 // if necessary.
212 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler atedCompositing(); 194 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler atedCompositing();
213 195
214 m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame); 196 KURL kurl(ParsedURLString, url);
215 if (m_webMediaPlayer) { 197 m_webMediaPlayer = createWebMediaPlayer(this, kurl, frame);
198 if (!m_webMediaPlayer)
199 return;
200
216 #if ENABLE(WEB_AUDIO) 201 #if ENABLE(WEB_AUDIO)
217 // Make sure if we create/re-create the WebMediaPlayer that we update ou r wrapper. 202 // Make sure if we create/re-create the WebMediaPlayer that we update our wr apper.
218 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); 203 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
219 #endif 204 #endif
220 205
221 m_webMediaPlayer->setVolume(mediaElement().playerVolume()); 206 m_webMediaPlayer->setVolume(mediaElement().playerVolume());
222 207
223 // Tell WebMediaPlayer about the poster image URL. 208 m_webMediaPlayer->setPoster(poster);
224 m_webMediaPlayer->setPoster(poster);
225 209
226 // Tell WebMediaPlayer about any connected CDM (may be null). 210 #if OS(ANDROID)
227 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMe dia::contentDecryptionModule(mediaElement())); 211 m_usePaintOnAndroid = (loadType != WebMediaPlayer::LoadTypeMediaStream);
212 #endif
228 213
229 WebMediaPlayer::CORSMode corsMode = static_cast<WebMediaPlayer::CORSMode >(m_client->mediaPlayerCORSMode()); 214 // Tell WebMediaPlayer about any connected CDM (may be null).
230 m_webMediaPlayer->load(m_loadType, m_url, corsMode); 215 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMedia: :contentDecryptionModule(mediaElement()));
231 } 216 m_webMediaPlayer->load(loadType, kurl, corsMode);
232 } 217 }
233 218
234 void WebMediaPlayerClientImpl::play() 219 void WebMediaPlayerClientImpl::play()
235 { 220 {
236 if (m_webMediaPlayer) 221 if (m_webMediaPlayer)
237 m_webMediaPlayer->play(); 222 m_webMediaPlayer->play();
238 } 223 }
239 224
240 void WebMediaPlayerClientImpl::pause() 225 void WebMediaPlayerClientImpl::pause()
241 { 226 {
(...skipping 11 matching lines...) Expand all
253 { 238 {
254 if (m_webMediaPlayer) 239 if (m_webMediaPlayer)
255 m_webMediaPlayer->exitFullscreen(); 240 m_webMediaPlayer->exitFullscreen();
256 } 241 }
257 242
258 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const 243 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const
259 { 244 {
260 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen(); 245 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen();
261 } 246 }
262 247
263 void WebMediaPlayerClientImpl::prepareToPlay()
264 {
265 if (m_delayingLoad)
266 startDelayedLoad();
267 }
268
269 IntSize WebMediaPlayerClientImpl::naturalSize() const 248 IntSize WebMediaPlayerClientImpl::naturalSize() const
270 { 249 {
271 if (m_webMediaPlayer) 250 if (m_webMediaPlayer)
272 return m_webMediaPlayer->naturalSize(); 251 return m_webMediaPlayer->naturalSize();
273 return IntSize(); 252 return IntSize();
274 } 253 }
275 254
276 bool WebMediaPlayerClientImpl::hasVideo() const 255 bool WebMediaPlayerClientImpl::hasVideo() const
277 { 256 {
278 if (m_webMediaPlayer) 257 if (m_webMediaPlayer)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 360
382 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& re ct) 361 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& re ct)
383 { 362 {
384 // Normally GraphicsContext operations do nothing when painting is disabled. 363 // Normally GraphicsContext operations do nothing when painting is disabled.
385 // Since we're accessing platformContext() directly we have to manually 364 // Since we're accessing platformContext() directly we have to manually
386 // check. 365 // check.
387 if (m_webMediaPlayer && !context->paintingDisabled()) { 366 if (m_webMediaPlayer && !context->paintingDisabled()) {
388 // On Android, video frame is emitted as GL_TEXTURE_EXTERNAL_OES texture . We use a different path to 367 // On Android, video frame is emitted as GL_TEXTURE_EXTERNAL_OES texture . We use a different path to
389 // paint the video frame into the context. 368 // paint the video frame into the context.
390 #if OS(ANDROID) 369 #if OS(ANDROID)
391 if (m_loadType != WebMediaPlayer::LoadTypeMediaStream) { 370 if (m_usePaintOnAndroid) {
392 paintOnAndroid(context, rect, context->getNormalizedAlpha()); 371 paintOnAndroid(context, rect, context->getNormalizedAlpha());
393 return; 372 return;
394 } 373 }
395 #endif 374 #endif
396 WebCanvas* canvas = context->canvas(); 375 WebCanvas* canvas = context->canvas();
397 m_webMediaPlayer->paint(canvas, rect, context->getNormalizedAlpha()); 376 m_webMediaPlayer->paint(canvas, rect, context->getNormalizedAlpha());
398 } 377 }
399 } 378 }
400 379
401 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebGraphicsCont ext3D* context, Platform3DObject texture, GLint level, GLenum type, GLenum inter nalFormat, bool premultiplyAlpha, bool flipY) 380 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebGraphicsCont ext3D* context, Platform3DObject texture, GLint level, GLenum type, GLenum inter nalFormat, bool premultiplyAlpha, bool flipY)
402 { 381 {
403 if (!context || !m_webMediaPlayer) 382 if (!context || !m_webMediaPlayer)
404 return false; 383 return false;
405 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, type, level ) || !context->makeContextCurrent()) 384 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, type, level ) || !context->makeContextCurrent())
406 return false; 385 return false;
407 386
408 return m_webMediaPlayer->copyVideoTextureToPlatformTexture(context, texture, level, internalFormat, type, premultiplyAlpha, flipY); 387 return m_webMediaPlayer->copyVideoTextureToPlatformTexture(context, texture, level, internalFormat, type, premultiplyAlpha, flipY);
409 } 388 }
410 389
411 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload) 390 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload)
412 { 391 {
413 m_preload = preload; 392 m_preload = preload;
414 393
415 if (m_webMediaPlayer) 394 if (m_webMediaPlayer)
416 m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preloa d)); 395 m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preloa d));
417
418 if (m_delayingLoad && m_preload != MediaPlayer::None)
419 startDelayedLoad();
420 } 396 }
421 397
422 bool WebMediaPlayerClientImpl::hasSingleSecurityOrigin() const 398 bool WebMediaPlayerClientImpl::hasSingleSecurityOrigin() const
423 { 399 {
424 if (m_webMediaPlayer) 400 if (m_webMediaPlayer)
425 return m_webMediaPlayer->hasSingleSecurityOrigin(); 401 return m_webMediaPlayer->hasSingleSecurityOrigin();
426 return false; 402 return false;
427 } 403 }
428 404
429 bool WebMediaPlayerClientImpl::didPassCORSAccessCheck() const 405 bool WebMediaPlayerClientImpl::didPassCORSAccessCheck() const
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // the texture based bitmap will be readbacked to system memory then draw on to the canvas. 498 // the texture based bitmap will be readbacked to system memory then draw on to the canvas.
523 SkRect dest; 499 SkRect dest;
524 dest.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height ()); 500 dest.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height ());
525 SkPaint paint; 501 SkPaint paint;
526 paint.setAlpha(alpha); 502 paint.setAlpha(alpha);
527 // It is not necessary to pass the dest into the drawBitmap call since all t he context have been set up before calling paintCurrentFrameInContext. 503 // It is not necessary to pass the dest into the drawBitmap call since all t he context have been set up before calling paintCurrentFrameInContext.
528 canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint); 504 canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint);
529 } 505 }
530 #endif 506 #endif
531 507
532 void WebMediaPlayerClientImpl::startDelayedLoad()
533 {
534 ASSERT(m_delayingLoad);
535 ASSERT(!m_webMediaPlayer);
536
537 m_delayingLoad = false;
538
539 loadInternal();
540 }
541
542 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) 508 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client)
543 : m_client(client) 509 : m_client(client)
544 , m_delayingLoad(false)
545 , m_preload(MediaPlayer::Auto) 510 , m_preload(MediaPlayer::Auto)
546 , m_needsWebLayerForVideo(false) 511 , m_needsWebLayerForVideo(false)
547 , m_rate(1.0) 512 , m_rate(1.0)
548 , m_loadType(WebMediaPlayer::LoadTypeURL) 513 #if OS(ANDROID)
514 , m_usePaintOnAndroid(false)
515 #endif
549 { 516 {
550 ASSERT(m_client); 517 ASSERT(m_client);
551 } 518 }
552 519
553 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const 520 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const
554 { 521 {
555 return *static_cast<HTMLMediaElement*>(m_client); 522 return *static_cast<HTMLMediaElement*>(m_client);
556 } 523 }
557 524
558 #if ENABLE(WEB_AUDIO) 525 #if ENABLE(WEB_AUDIO)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 571
605 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate) 572 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate)
606 { 573 {
607 if (m_client) 574 if (m_client)
608 m_client->setFormat(numberOfChannels, sampleRate); 575 m_client->setFormat(numberOfChannels, sampleRate);
609 } 576 }
610 577
611 #endif 578 #endif
612 579
613 } // namespace blink 580 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebMediaPlayerClientImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698