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

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: 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..e89c614535a81b0c0a1e82162c7a8de572325b25 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,44 @@ 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 =
+ // TODO(mcasas): Reuse |surface| (as long as frame->visible_rect() doesn't
Daniele Castagna 2016/07/18 16:51:23 Why? Is it expensive to create one?
mcasas 2016/07/18 17:40:42 It boils down to creating a Raster N32 memory, whi
emircan 2016/07/18 18:24:25 Since the use-case here is for pausing media strea
mcasas 2016/07/18 18:33:14 Oh gotcha, removing the TODO then.
+ // change) by moving it and CopyFrame() to WebMediaPlayerMSCompositor.
+ 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) {
Daniele Castagna 2016/07/18 16:51:23 It seems like surface can be null only if we can't
mcasas 2016/07/18 17:40:43 It could also be null due to incorrect width/heigh
+ 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<uint8*>(pixmap.writable_addr(0, 0)),
Daniele Castagna 2016/07/18 16:51:23 nit: can you use addr instead of writable_addr?
mcasas 2016/07/18 17:40:43 Good catch, done
+ pixmap.getSize64(),
Daniele Castagna 2016/07/18 16:51:23 nit: getSafeSize64 seems to be <= than size64, sho
mcasas 2016/07/18 17:40:43 Done.
+ new_frame->data(media::VideoFrame::kYPlane),
emircan 2016/07/18 18:24:25 Consider the case for coded_size() is different th
mcasas 2016/07/18 18:33:14 Done.
+ new_frame->stride(media::VideoFrame::kYPlane),
+ new_frame->data(media::VideoFrame::kUPlane),
+ new_frame->stride(media::VideoFrame::kUPlane),
+ new_frame->data(media::VideoFrame::kVPlane),
+ new_frame->stride(media::VideoFrame::kVPlane), 0 /* crop_x */,
+ 0 /* crop_y */, pixmap.width(), pixmap.height(),
+ new_frame->coded_size().width(), new_frame->coded_size().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