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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/android/webmediaplayer_android.cc
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc
index 804ab3aa497ad68cb43e94294d9d7a30ba8c4811..e95ab1f50aa3d28807833aa6e79e5cd39841bb82 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -39,6 +39,8 @@
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
#include "net/base/mime_util.h"
+#include "third_party/WebKit/public/platform/Platform.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
#include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
@@ -47,7 +49,6 @@
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebView.h"
-#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkTypeface.h"
@@ -460,10 +461,66 @@ bool WebMediaPlayerAndroid::didLoadingProgress() {
return ret;
}
+bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr,
+ SkBitmap& bitmap,
+ const WebSize& size,
+ GrSurfaceOrigin origin,
+ GrPixelConfig config) {
+ if (!bitmap.getTexture() || bitmap.width() != size.width || bitmap.height() != size.height) {
+ if (!gr)
+ return false;
+ GrTextureDesc desc;
+ desc.fConfig = config;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+ desc.fSampleCnt = 0;
+ desc.fOrigin = origin;
+ desc.fWidth = size.width;
+ desc.fHeight = size.height;
+ skia::RefPtr<GrTexture> texture;
+ texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0));
+ if (!texture.get())
+ return false;
+
+ SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
+ SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
+ if (!pixelRef)
+ return false;
+ bitmap.setInfo(info);
+ bitmap.setPixelRef(pixelRef)->unref();
+ }
+
+ return true;
+}
+
void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
const blink::WebRect& rect,
unsigned char alpha) {
- NOTIMPLEMENTED();
+ scoped_ptr<blink::WebGraphicsContext3DProvider> provider = scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
qinmin 2014/07/25 21:55:21 chromium has character limit of 80, break offendin
+ if (!provider)
+ return;
+ blink::WebGraphicsContext3D* context3D = provider->context3d();
+ if (!context3D || !context3D->makeContextCurrent())
+ return;
+
+ // Copy video texture into a RGBA texture based bitmap first as video texture on Android is GL_TEXTURE_EXTERNAL_OES
+ // which is not supported by Skia yet. The bitmap's size needs to be the same as the video and use naturalSize() here.
+ // Check if we could reuse existing texture based bitmap.
+ // Otherwise, release existing texture based bitmap and allocate a new one based on video size.
+ if (!EnsureTextureBackedSkBitmap(provider->grContext(), bitmap_, naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig))
+ return;
+
+ unsigned textureId = static_cast<unsigned>((bitmap_.getTexture())->getTextureHandle());
+ if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE, true, false))
+ return;
+
+ // 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,
+ // the texture based bitmap will be readbacked to system memory then draw onto the canvas.
+ SkRect dest;
+ dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
+ SkPaint paint;
+ paint.setAlpha(alpha);
+ // It is not necessary to pass the dest into the drawBitmap call since all the context have been set up before calling paintCurrentFrameInContext.
+ canvas->drawBitmapRect(bitmap_, 0, dest, &paint);
}
bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
« 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