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

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 409793006: Eliminate MediaPlayer abstraction(paint APIs- chromium changes) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 6 years, 5 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 | « content/renderer/media/android/webmediaplayer_android.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/android/webmediaplayer_android.h" 5 #include "content/renderer/media/android/webmediaplayer_android.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 21 matching lines...) Expand all
32 #include "gpu/GLES2/gl2extchromium.h" 32 #include "gpu/GLES2/gl2extchromium.h"
33 #include "gpu/command_buffer/client/gles2_interface.h" 33 #include "gpu/command_buffer/client/gles2_interface.h"
34 #include "gpu/command_buffer/common/mailbox_holder.h" 34 #include "gpu/command_buffer/common/mailbox_holder.h"
35 #include "media/base/android/media_player_android.h" 35 #include "media/base/android/media_player_android.h"
36 #include "media/base/bind_to_current_loop.h" 36 #include "media/base/bind_to_current_loop.h"
37 // TODO(xhwang): Remove when we remove prefixed EME implementation. 37 // TODO(xhwang): Remove when we remove prefixed EME implementation.
38 #include "media/base/media_keys.h" 38 #include "media/base/media_keys.h"
39 #include "media/base/media_switches.h" 39 #include "media/base/media_switches.h"
40 #include "media/base/video_frame.h" 40 #include "media/base/video_frame.h"
41 #include "net/base/mime_util.h" 41 #include "net/base/mime_util.h"
42 #include "third_party/WebKit/public/platform/Platform.h"
43 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
42 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" 44 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
43 #include "third_party/WebKit/public/platform/WebString.h" 45 #include "third_party/WebKit/public/platform/WebString.h"
44 #include "third_party/WebKit/public/platform/WebURL.h" 46 #include "third_party/WebKit/public/platform/WebURL.h"
45 #include "third_party/WebKit/public/web/WebDocument.h" 47 #include "third_party/WebKit/public/web/WebDocument.h"
46 #include "third_party/WebKit/public/web/WebFrame.h" 48 #include "third_party/WebKit/public/web/WebFrame.h"
47 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
48 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 50 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
49 #include "third_party/WebKit/public/web/WebView.h" 51 #include "third_party/WebKit/public/web/WebView.h"
50 #include "third_party/skia/include/core/SkBitmap.h"
51 #include "third_party/skia/include/core/SkCanvas.h" 52 #include "third_party/skia/include/core/SkCanvas.h"
52 #include "third_party/skia/include/core/SkPaint.h" 53 #include "third_party/skia/include/core/SkPaint.h"
53 #include "third_party/skia/include/core/SkTypeface.h" 54 #include "third_party/skia/include/core/SkTypeface.h"
54 #include "ui/gfx/image/image.h" 55 #include "ui/gfx/image/image.h"
55 56
56 static const uint32 kGLTextureExternalOES = 0x8D65; 57 static const uint32 kGLTextureExternalOES = 0x8D65;
57 58
58 using blink::WebMediaPlayer; 59 using blink::WebMediaPlayer;
59 using blink::WebSize; 60 using blink::WebSize;
60 using blink::WebString; 61 using blink::WebString;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 454
454 return duration(); 455 return duration();
455 } 456 }
456 457
457 bool WebMediaPlayerAndroid::didLoadingProgress() { 458 bool WebMediaPlayerAndroid::didLoadingProgress() {
458 bool ret = did_loading_progress_; 459 bool ret = did_loading_progress_;
459 did_loading_progress_ = false; 460 did_loading_progress_ = false;
460 return ret; 461 return ret;
461 } 462 }
462 463
464 bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr,
465 SkBitmap& bitmap,
466 const WebSize& size,
467 GrSurfaceOrigin origin,
468 GrPixelConfig config) {
469 if (!bitmap.getTexture() || bitmap.width() != size.width || bitmap.height() != size.height) {
470 if (!gr)
471 return false;
472 GrTextureDesc desc;
473 desc.fConfig = config;
474 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
475 desc.fSampleCnt = 0;
476 desc.fOrigin = origin;
477 desc.fWidth = size.width;
478 desc.fHeight = size.height;
479 skia::RefPtr<GrTexture> texture;
480 texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0));
481 if (!texture.get())
482 return false;
483
484 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
485 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
486 if (!pixelRef)
487 return false;
488 bitmap.setInfo(info);
489 bitmap.setPixelRef(pixelRef)->unref();
490 }
491
492 return true;
493 }
494
463 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, 495 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
464 const blink::WebRect& rect, 496 const blink::WebRect& rect,
465 unsigned char alpha) { 497 unsigned char alpha) {
466 NOTIMPLEMENTED(); 498 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = scoped_ptr<blink::W ebGraphicsContext3DProvider>(blink::Platform::current()->createSharedOffscreenGr aphicsContext3DProvider());
qinmin 2014/07/25 21:55:21 chromium has character limit of 80, break offendin
499 if (!provider)
500 return;
501 blink::WebGraphicsContext3D* context3D = provider->context3d();
502 if (!context3D || !context3D->makeContextCurrent())
503 return;
504
505 // Copy video texture into a RGBA texture based bitmap first as video texture on Android is GL_TEXTURE_EXTERNAL_OES
506 // which is not supported by Skia yet. The bitmap's size needs to be the same as the video and use naturalSize() here.
507 // Check if we could reuse existing texture based bitmap.
508 // Otherwise, release existing texture based bitmap and allocate a new one bas ed on video size.
509 if (!EnsureTextureBackedSkBitmap(provider->grContext(), bitmap_, naturalSize() , kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig))
510 return;
511
512 unsigned textureId = static_cast<unsigned>((bitmap_.getTexture())->getTextureH andle());
513 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, GL_RGBA, GL_UN SIGNED_BYTE, true, false))
514 return;
515
516 // Draw the texture based bitmap onto the Canvas. If the canvas is hardware ba sed, this will do a GPU-GPU texture copy. If the canvas is software based,
517 // the texture based bitmap will be readbacked to system memory then draw onto the canvas.
518 SkRect dest;
519 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
520 SkPaint paint;
521 paint.setAlpha(alpha);
522 // It is not necessary to pass the dest into the drawBitmap call since all the context have been set up before calling paintCurrentFrameInContext.
523 canvas->drawBitmapRect(bitmap_, 0, dest, &paint);
467 } 524 }
468 525
469 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( 526 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
470 blink::WebGraphicsContext3D* web_graphics_context, 527 blink::WebGraphicsContext3D* web_graphics_context,
471 unsigned int texture, 528 unsigned int texture,
472 unsigned int level, 529 unsigned int level,
473 unsigned int internal_format, 530 unsigned int internal_format,
474 unsigned int type, 531 unsigned int type,
475 bool premultiply_alpha, 532 bool premultiply_alpha,
476 bool flip_y) { 533 bool flip_y) {
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 player_manager_->EnterFullscreen(player_id_, frame_); 1589 player_manager_->EnterFullscreen(player_id_, frame_);
1533 SetNeedsEstablishPeer(false); 1590 SetNeedsEstablishPeer(false);
1534 } 1591 }
1535 } 1592 }
1536 1593
1537 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 1594 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
1538 return player_manager_->CanEnterFullscreen(frame_); 1595 return player_manager_->CanEnterFullscreen(frame_);
1539 } 1596 }
1540 1597
1541 } // namespace content 1598 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698