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

Unified Diff: content/renderer/media/webmediaplayer_ms_compositor.cc

Issue 2153093003: WebMediaPlayerMsCompositor: use correct ARGB/ABGR, use SkSurface/SkPixmap ISO SkBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: emircan@s comments Created 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webmediaplayer_ms_compositor.cc
diff --git a/content/renderer/media/webmediaplayer_ms_compositor.cc b/content/renderer/media/webmediaplayer_ms_compositor.cc
index 7f95ba1a5d7a8084e185fc41161d59967a6477a3..42f799e3cf7f60f1c5c2881c182d001fda134330 100644
--- a/content/renderer/media/webmediaplayer_ms_compositor.cc
+++ b/content/renderer/media/webmediaplayer_ms_compositor.cc
@@ -26,6 +26,7 @@
#include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h"
#include "third_party/libyuv/include/libyuv/video_common.h"
+#include "third_party/skia/include/core/SkSurface.h"
namespace content {
@@ -45,31 +46,43 @@ scoped_refptr<media::VideoFrame> CopyFrame(
new_frame = media::VideoFrame::CreateFrame(
media::PIXEL_FORMAT_I420, frame->coded_size(), frame->visible_rect(),
frame->natural_size(), frame->timestamp());
- SkBitmap bitmap;
- bitmap.allocN32Pixels(frame->visible_rect().width(),
- frame->visible_rect().height());
- SkCanvas canvas(bitmap);
- auto* provider =
+ sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
+ frame->visible_rect().width(), frame->visible_rect().height());
+
+ ContextProviderCommandBuffer* const provider =
RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
- if (provider) {
- const media::Context3D context_3d =
- media::Context3D(provider->ContextGL(), provider->GrContext());
- DCHECK(context_3d.gl);
- video_renderer->Copy(frame.get(), &canvas, context_3d);
+ if (surface && provider) {
+ DCHECK(provider->ContextGL());
+ video_renderer->Copy(
+ frame.get(), surface->getCanvas(),
+ media::Context3D(provider->ContextGL(), provider->GrContext()));
} else {
- // GPU Process crashed.
- bitmap.eraseColor(SK_ColorTRANSPARENT);
+ // Return a black frame (yuv = {0, 0x80, 0x80}).
+ return media::VideoFrame::CreateColorFrame(
+ frame->visible_rect().size(), 0u, 0x80, 0x80, frame->timestamp());
}
- libyuv::ARGBToI420(reinterpret_cast<uint8_t*>(bitmap.getPixels()),
- bitmap.rowBytes(),
- new_frame->visible_data(media::VideoFrame::kYPlane),
- new_frame->stride(media::VideoFrame::kYPlane),
- new_frame->visible_data(media::VideoFrame::kUPlane),
- new_frame->stride(media::VideoFrame::kUPlane),
- new_frame->visible_data(media::VideoFrame::kVPlane),
- new_frame->stride(media::VideoFrame::kVPlane),
- bitmap.width(), bitmap.height());
+
+ SkPixmap pixmap;
+ const bool result = surface->getCanvas()->peekPixels(&pixmap);
+ DCHECK(result) << "Error trying to access SkSurface's pixels";
+
+ const uint32 source_pixel_format =
+ (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR
+ : libyuv::FOURCC_ARGB;
+ libyuv::ConvertToI420(
+ static_cast<const uint8*>(pixmap.addr(0, 0)),
+ pixmap.getSafeSize64(),
+ new_frame->visible_data(media::VideoFrame::kYPlane),
+ new_frame->stride(media::VideoFrame::kYPlane),
+ new_frame->visible_data(media::VideoFrame::kUPlane),
+ new_frame->stride(media::VideoFrame::kUPlane),
+ new_frame->visible_data(media::VideoFrame::kVPlane),
+ new_frame->stride(media::VideoFrame::kVPlane),
+ 0 /* crop_x */, 0 /* crop_y */,
+ pixmap.width(), pixmap.height(),
+ new_frame->visible_rect().width(), new_frame->visible_rect().height(),
+ libyuv::kRotate0, source_pixel_format);
} else {
DCHECK(frame->IsMappable());
DCHECK(frame->format() == media::PIXEL_FORMAT_YV12 ||
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698