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

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

Issue 445013002: media: Optimize HW Video to 2D Canvas copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rollback android code Created 6 years 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
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/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "third_party/WebKit/public/platform/WebString.h" 50 #include "third_party/WebKit/public/platform/WebString.h"
51 #include "third_party/WebKit/public/platform/WebURL.h" 51 #include "third_party/WebKit/public/platform/WebURL.h"
52 #include "third_party/WebKit/public/web/WebDocument.h" 52 #include "third_party/WebKit/public/web/WebDocument.h"
53 #include "third_party/WebKit/public/web/WebFrame.h" 53 #include "third_party/WebKit/public/web/WebFrame.h"
54 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 54 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
55 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 55 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
56 #include "third_party/WebKit/public/web/WebView.h" 56 #include "third_party/WebKit/public/web/WebView.h"
57 #include "third_party/skia/include/core/SkCanvas.h" 57 #include "third_party/skia/include/core/SkCanvas.h"
58 #include "third_party/skia/include/core/SkPaint.h" 58 #include "third_party/skia/include/core/SkPaint.h"
59 #include "third_party/skia/include/core/SkTypeface.h" 59 #include "third_party/skia/include/core/SkTypeface.h"
60 #include "third_party/skia/include/gpu/GrContext.h"
61 #include "third_party/skia/include/gpu/SkGrPixelRef.h"
60 #include "ui/gfx/image/image.h" 62 #include "ui/gfx/image/image.h"
61 63
62 static const uint32 kGLTextureExternalOES = 0x8D65; 64 static const uint32 kGLTextureExternalOES = 0x8D65;
63 static const int kSDKVersionToSupportSecurityOriginCheck = 20; 65 static const int kSDKVersionToSupportSecurityOriginCheck = 20;
64 66
65 using blink::WebMediaPlayer; 67 using blink::WebMediaPlayer;
66 using blink::WebSize; 68 using blink::WebSize;
67 using blink::WebString; 69 using blink::WebString;
68 using blink::WebURL; 70 using blink::WebURL;
69 using gpu::gles2::GLES2Interface; 71 using gpu::gles2::GLES2Interface;
70 using media::MediaPlayerAndroid; 72 using media::MediaPlayerAndroid;
71 using media::VideoFrame; 73 using media::VideoFrame;
72 74
73 namespace { 75 namespace {
74 // Prefix for histograms related to Encrypted Media Extensions. 76 // Prefix for histograms related to Encrypted Media Extensions.
75 const char* kMediaEme = "Media.EME."; 77 const char* kMediaEme = "Media.EME.";
76 78
77 // File-static function is to allow it to run even after WMPA is deleted. 79 // File-static function is to allow it to run even after WMPA is deleted.
78 void OnReleaseTexture( 80 void OnReleaseTexture(
79 const scoped_refptr<content::StreamTextureFactory>& factories, 81 const scoped_refptr<content::StreamTextureFactory>& factories,
80 uint32 texture_id, 82 uint32 texture_id,
81 uint32 release_sync_point) { 83 uint32 release_sync_point) {
82 GLES2Interface* gl = factories->ContextGL(); 84 GLES2Interface* gl = factories->ContextGL();
83 gl->WaitSyncPointCHROMIUM(release_sync_point); 85 gl->WaitSyncPointCHROMIUM(release_sync_point);
84 gl->DeleteTextures(1, &texture_id); 86 gl->DeleteTextures(1, &texture_id);
85 } 87 }
86 88
89 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap,
dshwang 2014/12/12 17:06:59 EnsureTextureBackedSkBitmap was separated into two
90 const gfx::Size& size) {
91 return bitmap->getTexture() && bitmap->width() == size.width() &&
92 bitmap->height() == size.height();
93 }
94
95 bool AllocateSkBitmapTexture(GrContext* gr,
96 SkBitmap* bitmap,
97 const gfx::Size& size) {
98 DCHECK(gr);
99 GrTextureDesc desc;
100 // Use kRGBA_8888_GrPixelConfig, not kSkia8888_GrPixelConfig, to avoid
101 // RGBA to BGRA conversion.
dshwang 2014/12/12 17:06:59 Android can use kSkia8888_GrPixelConfig because RG
no sievers 2014/12/18 23:12:31 You probably know since you are on bug 358198, but
dshwang 2014/12/19 10:15:43 Yes, I tested both video to webgl and video to can
102 desc.fConfig = kRGBA_8888_GrPixelConfig;
103 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
no sievers 2014/12/18 23:12:31 while you are in here: mind putting a comment that
dshwang 2014/12/19 10:15:43 I didn't consider about kRenderTarget because I bl
104 desc.fSampleCnt = 0;
105 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
106 desc.fWidth = size.width();
107 desc.fHeight = size.height();
108 skia::RefPtr<GrTexture> texture = skia::AdoptRef(
109 gr->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch));
110 if (!texture.get())
111 return false;
112
113 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
114 SkGrPixelRef* pixel_ref = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
115 if (!pixel_ref)
116 return false;
117 bitmap->setInfo(info);
118 bitmap->setPixelRef(pixel_ref)->unref();
119 return true;
120 }
121
87 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { 122 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
88 public: 123 public:
89 explicit SyncPointClientImpl( 124 explicit SyncPointClientImpl(
90 blink::WebGraphicsContext3D* web_graphics_context) 125 blink::WebGraphicsContext3D* web_graphics_context)
91 : web_graphics_context_(web_graphics_context) {} 126 : web_graphics_context_(web_graphics_context) {}
92 virtual ~SyncPointClientImpl() {} 127 virtual ~SyncPointClientImpl() {}
93 virtual uint32 InsertSyncPoint() override { 128 virtual uint32 InsertSyncPoint() override {
94 return web_graphics_context_->insertSyncPoint(); 129 return web_graphics_context_->insertSyncPoint();
95 } 130 }
96 virtual void WaitSyncPoint(uint32 sync_point) override { 131 virtual void WaitSyncPoint(uint32 sync_point) override {
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 const blink::WebTimeRange seekable_range(0.0, duration()); 567 const blink::WebTimeRange seekable_range(0.0, duration());
533 return blink::WebTimeRanges(&seekable_range, 1); 568 return blink::WebTimeRanges(&seekable_range, 1);
534 } 569 }
535 570
536 bool WebMediaPlayerAndroid::didLoadingProgress() { 571 bool WebMediaPlayerAndroid::didLoadingProgress() {
537 bool ret = did_loading_progress_; 572 bool ret = did_loading_progress_;
538 did_loading_progress_ = false; 573 did_loading_progress_ = false;
539 return ret; 574 return ret;
540 } 575 }
541 576
542 bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr,
543 SkBitmap& bitmap,
544 const WebSize& size,
545 GrSurfaceOrigin origin,
546 GrPixelConfig config) {
547 DCHECK(main_thread_checker_.CalledOnValidThread());
548 if (!bitmap.getTexture() || bitmap.width() != size.width
549 || bitmap.height() != size.height) {
550 if (!gr)
551 return false;
552 GrTextureDesc desc;
553 desc.fConfig = config;
554 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
555 desc.fSampleCnt = 0;
556 desc.fOrigin = origin;
557 desc.fWidth = size.width;
558 desc.fHeight = size.height;
559 skia::RefPtr<GrTexture> texture;
560 texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0));
561 if (!texture.get())
562 return false;
563
564 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
565 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
566 if (!pixelRef)
567 return false;
568 bitmap.setInfo(info);
569 bitmap.setPixelRef(pixelRef)->unref();
570 }
571
572 return true;
573 }
574
575 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, 577 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
576 const blink::WebRect& rect, 578 const blink::WebRect& rect,
577 unsigned char alpha, 579 unsigned char alpha,
578 SkXfermode::Mode mode) { 580 SkXfermode::Mode mode) {
579 DCHECK(main_thread_checker_.CalledOnValidThread()); 581 DCHECK(main_thread_checker_.CalledOnValidThread());
580 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = 582 scoped_ptr<blink::WebGraphicsContext3DProvider> provider =
581 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current( 583 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current(
582 )->createSharedOffscreenGraphicsContext3DProvider()); 584 )->createSharedOffscreenGraphicsContext3DProvider());
583 if (!provider) 585 if (!provider)
584 return; 586 return;
585 blink::WebGraphicsContext3D* context3D = provider->context3d(); 587 blink::WebGraphicsContext3D* context3D = provider->context3d();
586 if (!context3D) 588 if (!context3D)
587 return; 589 return;
588 590
589 // Copy video texture into a RGBA texture based bitmap first as video texture 591 // Copy video texture into a RGBA texture based bitmap first as video texture
590 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet. 592 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet.
591 // The bitmap's size needs to be the same as the video and use naturalSize() 593 // The bitmap's size needs to be the same as the video and use naturalSize()
592 // here. Check if we could reuse existing texture based bitmap. 594 // here. Check if we could reuse existing texture based bitmap.
593 // Otherwise, release existing texture based bitmap and allocate 595 // Otherwise, release existing texture based bitmap and allocate
594 // a new one based on video size. 596 // a new one based on video size.
595 if (!EnsureTextureBackedSkBitmap(provider->grContext(), bitmap_, 597 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) {
596 naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) { 598 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_,
597 return; 599 naturalSize())) {
600 return;
601 }
598 } 602 }
599 603
600 unsigned textureId = static_cast<unsigned>( 604 unsigned textureId = static_cast<unsigned>(
601 (bitmap_.getTexture())->getTextureHandle()); 605 (bitmap_.getTexture())->getTextureHandle());
602 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, 606 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0,
603 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { 607 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) {
604 return; 608 return;
605 } 609 }
606 610
607 // Draw the texture based bitmap onto the Canvas. If the canvas is 611 // Draw the texture based bitmap onto the Canvas. If the canvas is
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 1797
1794 bool WebMediaPlayerAndroid::IsHLSStream() const { 1798 bool WebMediaPlayerAndroid::IsHLSStream() const {
1795 std::string mime; 1799 std::string mime;
1796 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; 1800 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_;
1797 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) 1801 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime))
1798 return false; 1802 return false;
1799 return !mime.compare("application/x-mpegurl"); 1803 return !mime.compare("application/x-mpegurl");
1800 } 1804 }
1801 1805
1802 } // namespace content 1806 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | content/renderer/media/webmediaplayer_ms.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698