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

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

Issue 430793002: Eliminate MediaPlayer abstraction(paint APIs) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed review comments Created 6 years, 4 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
« 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 "web/WebMediaPlayerClientImpl.h" 6 #include "web/WebMediaPlayerClientImpl.h"
7 7
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/html/HTMLMediaElement.h" 9 #include "core/html/HTMLMediaElement.h"
10 #include "core/html/TimeRanges.h" 10 #include "core/html/TimeRanges.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 #if ENABLE(WEB_AUDIO) 210 #if ENABLE(WEB_AUDIO)
211 // Make sure if we create/re-create the WebMediaPlayer that we update our wr apper. 211 // Make sure if we create/re-create the WebMediaPlayer that we update our wr apper.
212 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); 212 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
213 #endif 213 #endif
214 214
215 m_webMediaPlayer->setVolume(mediaElement().playerVolume()); 215 m_webMediaPlayer->setVolume(mediaElement().playerVolume());
216 216
217 m_webMediaPlayer->setPoster(poster); 217 m_webMediaPlayer->setPoster(poster);
218 218
219 #if OS(ANDROID)
220 m_usePaintOnAndroid = (loadType != WebMediaPlayer::LoadTypeMediaStream);
221 #endif
222
223 // Tell WebMediaPlayer about any connected CDM (may be null). 219 // Tell WebMediaPlayer about any connected CDM (may be null).
224 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMedia: :contentDecryptionModule(mediaElement())); 220 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMedia: :contentDecryptionModule(mediaElement()));
225 m_webMediaPlayer->load(loadType, kurl, corsMode); 221 m_webMediaPlayer->load(loadType, kurl, corsMode);
226 } 222 }
227 223
228
229 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& re ct)
230 {
231 // Normally GraphicsContext operations do nothing when painting is disabled.
232 // Since we're accessing platformContext() directly we have to manually
233 // check.
234 if (m_webMediaPlayer && !context->paintingDisabled()) {
235 // On Android, video frame is emitted as GL_TEXTURE_EXTERNAL_OES texture . We use a different path to
236 // paint the video frame into the context.
237 #if OS(ANDROID)
238 if (m_usePaintOnAndroid) {
239 paintOnAndroid(context, rect, context->getNormalizedAlpha());
240 return;
241 }
242 #endif
243 WebCanvas* canvas = context->canvas();
244 m_webMediaPlayer->paint(canvas, rect, context->getNormalizedAlpha());
245 }
246 }
247
248 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebGraphicsCont ext3D* context, Platform3DObject texture, GLint level, GLenum type, GLenum inter nalFormat, bool premultiplyAlpha, bool flipY)
249 {
250 if (!context || !m_webMediaPlayer)
251 return false;
252 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, type, level ) || !context->makeContextCurrent())
253 return false;
254
255 return m_webMediaPlayer->copyVideoTextureToPlatformTexture(context, texture, level, internalFormat, type, premultiplyAlpha, flipY);
256 }
257
258 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload) 224 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload)
259 { 225 {
260 m_preload = preload; 226 m_preload = preload;
261 227
262 if (m_webMediaPlayer) 228 if (m_webMediaPlayer)
263 m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preloa d)); 229 m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preloa d));
264 } 230 }
265 231
266 #if ENABLE(WEB_AUDIO) 232 #if ENABLE(WEB_AUDIO)
267 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider() 233 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider()
268 { 234 {
269 return &m_audioSourceProvider; 235 return &m_audioSourceProvider;
270 } 236 }
271 #endif 237 #endif
272 238
273 PassOwnPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayerClient* clie nt) 239 PassOwnPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayerClient* clie nt)
274 { 240 {
275 return adoptPtr(new WebMediaPlayerClientImpl(client)); 241 return adoptPtr(new WebMediaPlayerClientImpl(client));
276 } 242 }
277 243
278 #if OS(ANDROID)
279 void WebMediaPlayerClientImpl::paintOnAndroid(blink::GraphicsContext* context, c onst IntRect& rect, uint8_t alpha)
280 {
281 OwnPtr<blink::WebGraphicsContext3DProvider> provider = adoptPtr(blink::Platf orm::current()->createSharedOffscreenGraphicsContext3DProvider());
282 if (!provider)
283 return;
284 WebGraphicsContext3D* context3D = provider->context3d();
285 if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled ())
286 return;
287
288 if (!context3D->makeContextCurrent())
289 return;
290
291 // Copy video texture into a RGBA texture based bitmap first as video textur e on Android is GL_TEXTURE_EXTERNAL_OES
292 // which is not supported by Skia yet. The bitmap's size needs to be the sam e as the video and use naturalSize() here.
293 // Check if we could reuse existing texture based bitmap.
294 // Otherwise, release existing texture based bitmap and allocate a new one b ased on video size.
295 if (!ensureTextureBackedSkBitmap(provider->grContext(), m_bitmap, m_webMedia Player->naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig))
296 return;
297
298 // Copy video texture to bitmap texture.
299 WebCanvas* canvas = context->canvas();
300 unsigned textureId = static_cast<unsigned>((m_bitmap.getTexture())->getTextu reHandle());
301 if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(context3D, textureI d, 0, GL_RGBA, GL_UNSIGNED_BYTE, true, false))
302 return;
303
304 // Draw the texture based bitmap onto the Canvas. If the canvas is hardware based, this will do a GPU-GPU texture copy. If the canvas is software based,
305 // the texture based bitmap will be readbacked to system memory then draw on to the canvas.
306 SkRect dest;
307 dest.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height ());
308 SkPaint paint;
309 paint.setAlpha(alpha);
310 // It is not necessary to pass the dest into the drawBitmap call since all t he context have been set up before calling paintCurrentFrameInContext.
311 canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint);
312 }
313 #endif
314
315 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) 244 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client)
316 : m_client(client) 245 : m_client(client)
317 , m_preload(MediaPlayer::Auto) 246 , m_preload(MediaPlayer::Auto)
318 #if OS(ANDROID)
319 , m_usePaintOnAndroid(false)
320 #endif
321 { 247 {
322 ASSERT(m_client); 248 ASSERT(m_client);
323 } 249 }
324 250
325 blink::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const 251 blink::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const
326 { 252 {
327 return *static_cast<HTMLMediaElement*>(m_client); 253 return *static_cast<HTMLMediaElement*>(m_client);
328 } 254 }
329 255
330 #if ENABLE(WEB_AUDIO) 256 #if ENABLE(WEB_AUDIO)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 302
377 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate) 303 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate)
378 { 304 {
379 if (m_client) 305 if (m_client)
380 m_client->setFormat(numberOfChannels, sampleRate); 306 m_client->setFormat(numberOfChannels, sampleRate);
381 } 307 }
382 308
383 #endif 309 #endif
384 310
385 } // namespace blink 311 } // 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