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

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

Issue 818853004: Revert of media: Optimize HW Video to 2D Canvas copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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"
62 #include "ui/gfx/image/image.h" 60 #include "ui/gfx/image/image.h"
63 61
64 static const uint32 kGLTextureExternalOES = 0x8D65; 62 static const uint32 kGLTextureExternalOES = 0x8D65;
65 static const int kSDKVersionToSupportSecurityOriginCheck = 20; 63 static const int kSDKVersionToSupportSecurityOriginCheck = 20;
66 64
67 using blink::WebMediaPlayer; 65 using blink::WebMediaPlayer;
68 using blink::WebSize; 66 using blink::WebSize;
69 using blink::WebString; 67 using blink::WebString;
70 using blink::WebURL; 68 using blink::WebURL;
71 using gpu::gles2::GLES2Interface; 69 using gpu::gles2::GLES2Interface;
72 using media::MediaPlayerAndroid; 70 using media::MediaPlayerAndroid;
73 using media::VideoFrame; 71 using media::VideoFrame;
74 72
75 namespace { 73 namespace {
76 // Prefix for histograms related to Encrypted Media Extensions. 74 // Prefix for histograms related to Encrypted Media Extensions.
77 const char* kMediaEme = "Media.EME."; 75 const char* kMediaEme = "Media.EME.";
78 76
79 // File-static function is to allow it to run even after WMPA is deleted. 77 // File-static function is to allow it to run even after WMPA is deleted.
80 void OnReleaseTexture( 78 void OnReleaseTexture(
81 const scoped_refptr<content::StreamTextureFactory>& factories, 79 const scoped_refptr<content::StreamTextureFactory>& factories,
82 uint32 texture_id, 80 uint32 texture_id,
83 uint32 release_sync_point) { 81 uint32 release_sync_point) {
84 GLES2Interface* gl = factories->ContextGL(); 82 GLES2Interface* gl = factories->ContextGL();
85 gl->WaitSyncPointCHROMIUM(release_sync_point); 83 gl->WaitSyncPointCHROMIUM(release_sync_point);
86 gl->DeleteTextures(1, &texture_id); 84 gl->DeleteTextures(1, &texture_id);
87 } 85 }
88 86
89 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap,
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.
102 desc.fConfig = kRGBA_8888_GrPixelConfig;
103 // kRenderTarget_GrTextureFlagBit avoids a copy before readback in skia.
104 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
105 desc.fSampleCnt = 0;
106 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
107 desc.fWidth = size.width();
108 desc.fHeight = size.height();
109 skia::RefPtr<GrTexture> texture = skia::AdoptRef(
110 gr->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch));
111 if (!texture.get())
112 return false;
113
114 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
115 SkGrPixelRef* pixel_ref = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
116 if (!pixel_ref)
117 return false;
118 bitmap->setInfo(info);
119 bitmap->setPixelRef(pixel_ref)->unref();
120 return true;
121 }
122
123 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { 87 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
124 public: 88 public:
125 explicit SyncPointClientImpl( 89 explicit SyncPointClientImpl(
126 blink::WebGraphicsContext3D* web_graphics_context) 90 blink::WebGraphicsContext3D* web_graphics_context)
127 : web_graphics_context_(web_graphics_context) {} 91 : web_graphics_context_(web_graphics_context) {}
128 virtual ~SyncPointClientImpl() {} 92 virtual ~SyncPointClientImpl() {}
129 virtual uint32 InsertSyncPoint() override { 93 virtual uint32 InsertSyncPoint() override {
130 return web_graphics_context_->insertSyncPoint(); 94 return web_graphics_context_->insertSyncPoint();
131 } 95 }
132 virtual void WaitSyncPoint(uint32 sync_point) override { 96 virtual void WaitSyncPoint(uint32 sync_point) override {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 const blink::WebTimeRange seekable_range(0.0, duration()); 533 const blink::WebTimeRange seekable_range(0.0, duration());
570 return blink::WebTimeRanges(&seekable_range, 1); 534 return blink::WebTimeRanges(&seekable_range, 1);
571 } 535 }
572 536
573 bool WebMediaPlayerAndroid::didLoadingProgress() { 537 bool WebMediaPlayerAndroid::didLoadingProgress() {
574 bool ret = did_loading_progress_; 538 bool ret = did_loading_progress_;
575 did_loading_progress_ = false; 539 did_loading_progress_ = false;
576 return ret; 540 return ret;
577 } 541 }
578 542
543 bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr,
544 SkBitmap& bitmap,
545 const WebSize& size,
546 GrSurfaceOrigin origin,
547 GrPixelConfig config) {
548 DCHECK(main_thread_checker_.CalledOnValidThread());
549 if (!bitmap.getTexture() || bitmap.width() != size.width
550 || bitmap.height() != size.height) {
551 if (!gr)
552 return false;
553 GrTextureDesc desc;
554 desc.fConfig = config;
555 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
556 desc.fSampleCnt = 0;
557 desc.fOrigin = origin;
558 desc.fWidth = size.width;
559 desc.fHeight = size.height;
560 skia::RefPtr<GrTexture> texture;
561 texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0));
562 if (!texture.get())
563 return false;
564
565 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
566 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
567 if (!pixelRef)
568 return false;
569 bitmap.setInfo(info);
570 bitmap.setPixelRef(pixelRef)->unref();
571 }
572
573 return true;
574 }
575
579 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, 576 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
580 const blink::WebRect& rect, 577 const blink::WebRect& rect,
581 unsigned char alpha, 578 unsigned char alpha,
582 SkXfermode::Mode mode) { 579 SkXfermode::Mode mode) {
583 DCHECK(main_thread_checker_.CalledOnValidThread()); 580 DCHECK(main_thread_checker_.CalledOnValidThread());
584 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = 581 scoped_ptr<blink::WebGraphicsContext3DProvider> provider =
585 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current( 582 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current(
586 )->createSharedOffscreenGraphicsContext3DProvider()); 583 )->createSharedOffscreenGraphicsContext3DProvider());
587 if (!provider) 584 if (!provider)
588 return; 585 return;
589 blink::WebGraphicsContext3D* context3D = provider->context3d(); 586 blink::WebGraphicsContext3D* context3D = provider->context3d();
590 if (!context3D) 587 if (!context3D)
591 return; 588 return;
592 589
593 // Copy video texture into a RGBA texture based bitmap first as video texture 590 // Copy video texture into a RGBA texture based bitmap first as video texture
594 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet. 591 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet.
595 // The bitmap's size needs to be the same as the video and use naturalSize() 592 // The bitmap's size needs to be the same as the video and use naturalSize()
596 // here. Check if we could reuse existing texture based bitmap. 593 // here. Check if we could reuse existing texture based bitmap.
597 // Otherwise, release existing texture based bitmap and allocate 594 // Otherwise, release existing texture based bitmap and allocate
598 // a new one based on video size. 595 // a new one based on video size.
599 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { 596 if (!EnsureTextureBackedSkBitmap(provider->grContext(), bitmap_,
600 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, 597 naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) {
601 naturalSize())) { 598 return;
602 return;
603 }
604 } 599 }
605 600
606 unsigned textureId = static_cast<unsigned>( 601 unsigned textureId = static_cast<unsigned>(
607 (bitmap_.getTexture())->getTextureHandle()); 602 (bitmap_.getTexture())->getTextureHandle());
608 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, 603 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0,
609 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { 604 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) {
610 return; 605 return;
611 } 606 }
612 607
613 // Draw the texture based bitmap onto the Canvas. If the canvas is 608 // Draw the texture based bitmap onto the Canvas. If the canvas is
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 1794
1800 bool WebMediaPlayerAndroid::IsHLSStream() const { 1795 bool WebMediaPlayerAndroid::IsHLSStream() const {
1801 std::string mime; 1796 std::string mime;
1802 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; 1797 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_;
1803 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) 1798 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime))
1804 return false; 1799 return false;
1805 return !mime.compare("application/x-mpegurl"); 1800 return !mime.compare("application/x-mpegurl");
1806 } 1801 }
1807 1802
1808 } // namespace content 1803 } // 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