Chromium Code Reviews| Index: media/renderers/skcanvas_video_renderer.cc |
| diff --git a/media/renderers/skcanvas_video_renderer.cc b/media/renderers/skcanvas_video_renderer.cc |
| index e6ee9d1e12ca16cb01957acd649cdc6034556451..cacee0d44f7b9fbdec9608c74e4ee4c5e170063d 100644 |
| --- a/media/renderers/skcanvas_video_renderer.cc |
| +++ b/media/renderers/skcanvas_video_renderer.cc |
| @@ -4,12 +4,14 @@ |
| #include "media/renderers/skcanvas_video_renderer.h" |
| +#include <GLES3/gl3.h> |
| #include <limits> |
| #include "base/macros.h" |
| #include "gpu/GLES2/gl2extchromium.h" |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| #include "gpu/command_buffer/common/mailbox_holder.h" |
| +#include "media/base/data_buffer.h" |
| #include "media/base/video_frame.h" |
| #include "media/base/yuv_convert.h" |
| #include "skia/ext/texture_handle.h" |
| @@ -522,24 +524,46 @@ scoped_refptr<VideoFrame> DownShiftHighbitVideoFrame( |
| return ret; |
| } |
| -// We take the upper 8 bits of 16-bit data and convert it as luminance to ARGB. |
| -// We loose the precision here, but it is important not to render Y16 as RG_88. |
| -// To get the full precision use float textures with WebGL1 and e.g. R16UI or |
| -// R32F textures with WebGL2. |
| -void ConvertY16ToARGB(const VideoFrame* video_frame, |
| - void* argb_pixels, |
| - size_t argb_row_bytes) { |
| +void FlipAndConvertY16(const VideoFrame* video_frame, |
|
hubbe
2016/11/07 22:16:55
Add comment.
aleksandar.stojiljkovic
2016/11/16 20:01:24
Done.
|
| + uint8_t* out, |
| + unsigned format, |
| + unsigned type, |
| + bool flip_y, |
| + size_t output_row_bytes) { |
| const uint8_t* row_head = video_frame->visible_data(0); |
| - uint8_t* out = static_cast<uint8_t*>(argb_pixels); |
| const size_t stride = video_frame->stride(0); |
| - for (int i = 0; i < video_frame->visible_rect().height(); ++i) { |
| - uint32_t* rgba = reinterpret_cast<uint32_t*>(out); |
| - const uint8_t* row_end = row_head + video_frame->visible_rect().width() * 2; |
| - for (const uint8_t* row = row_head; row < row_end; ++row) { |
| - uint32_t gray_value = *++row; |
| - *rgba++ = SkColorSetRGB(gray_value, gray_value, gray_value); |
| + const int height = video_frame->visible_rect().height(); |
| + for (int i = 0; i < height; ++i) { |
| + uint8_t* out_row_head = flip_y ? out + output_row_bytes * (height - i - 1) |
| + : out + output_row_bytes * i; |
| + const uint16_t* row = reinterpret_cast<const uint16_t*>(row_head); |
| + const uint16_t* row_end = row + video_frame->visible_rect().width(); |
| + if (type == GL_FLOAT && format == GL_RGBA) { |
| + float* out_row = reinterpret_cast<float*>(out_row_head); |
| + while (row < row_end) { |
| + float gray_value = *row++ / 65535.f; |
| + *out_row++ = gray_value; |
| + *out_row++ = gray_value; |
| + *out_row++ = gray_value; |
| + *out_row++ = 1.0f; |
| + } |
| + } else if (type == GL_UNSIGNED_BYTE) { |
| + // We take the upper 8 bits of 16-bit data and convert it as luminance to |
| + // ARGB. We loose the precision here, but it is important not to render |
| + // Y16 as RG_88. To get the full precision use float textures with WebGL1 |
| + // and e.g. R16UI or R32F textures with WebGL2. |
| + DCHECK(format == GL_RGBA) << "Unsupported Y16 conversion for format: 0x" |
| + << std::hex << format << " and type: 0x" |
| + << std::hex << type; |
| + uint32_t* rgba = reinterpret_cast<uint32_t*>(out_row_head); |
| + while (row < row_end) { |
| + uint32_t gray_value = *row++ >> 8; |
| + *rgba++ = SkColorSetRGB(gray_value, gray_value, gray_value); |
| + } |
| + } else { |
| + NOTREACHED() << "Unsupported Y16 conversion for format: 0x" << std::hex |
| + << format << " and type: 0x" << std::hex << type; |
| } |
| - out += argb_row_bytes; |
| row_head += stride; |
| } |
| } |
| @@ -648,7 +672,10 @@ void SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( |
| } |
| case PIXEL_FORMAT_Y16: |
| - ConvertY16ToARGB(video_frame, rgb_pixels, row_bytes); |
| + // Since it is grayscale conversion, we disregard SK_PMCOLOR_BYTE_ORDER |
| + // and always use GL_RGBA. |
| + FlipAndConvertY16(video_frame, static_cast<uint8_t*>(rgb_pixels), GL_RGBA, |
| + GL_UNSIGNED_BYTE, false /*flip_y*/, row_bytes); |
| break; |
| case PIXEL_FORMAT_NV12: |
| @@ -772,6 +799,73 @@ bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture( |
| return true; |
| } |
| +bool SkCanvasVideoRenderer::TexImageImpl(const char* functionID, |
| + unsigned target, |
| + gpu::gles2::GLES2Interface* gl, |
| + VideoFrame* frame, |
| + int level, |
| + int internalformat, |
| + unsigned format, |
| + unsigned type, |
| + int xoffset, |
| + int yoffset, |
| + int zoffset, |
| + bool flip_y, |
| + bool premultiplyAlpha) { |
| + DCHECK(frame); |
| + DCHECK(!frame->HasTextures()); |
| + |
| + bool has_alpha = false; |
| + unsigned output_bytes_per_pixel; |
|
hubbe
2016/11/07 22:16:55
Please initialize to something.
aleksandar.stojiljkovic
2016/11/16 20:01:24
Done.
|
| + switch (frame->format()) { |
| + case PIXEL_FORMAT_Y16: |
| + // Converting single component unsigned short here to FLOAT luminance. |
| + switch (format) { |
| + case GL_RGBA: |
| + if (type == GL_FLOAT) { |
| + output_bytes_per_pixel = 4 * sizeof(GLfloat); |
| + break; |
| + } |
| + // Pass through. |
| + default: |
| + return false; |
| + } |
| + break; |
| + default: |
| + return false; |
| + } |
| + |
| + if (has_alpha && premultiplyAlpha) { |
| + NOTREACHED() << "Premultiply alpha is not supported."; |
| + return false; |
| + } |
| + if (xoffset || yoffset || zoffset) { |
| + NOTREACHED() << "Offsets are not supported."; |
|
hubbe
2016/11/07 22:16:55
If they are not supported, why even have those arg
aleksandar.stojiljkovic
2016/11/16 20:01:24
Done. Split the method and now supported in texSub
|
| + return false; |
| + } |
| + |
| + const size_t width = frame->visible_rect().width(); |
| + const size_t height = frame->visible_rect().height(); |
| + size_t output_row_bytes = width * output_bytes_per_pixel; |
| + scoped_refptr<DataBuffer> temp_buffer = |
| + new DataBuffer(output_row_bytes * height); |
| + uint8_t* data = temp_buffer->writable_data(); |
| + |
| + FlipAndConvertY16(frame, data, format, type, flip_y, output_row_bytes); |
| + |
| + if (!strcmp(functionID, "texImage2D")) { |
| + gl->TexImage2D(target, level, internalformat, width, height, 0, format, |
| + type, data); |
| + } else if (!strcmp(functionID, "texSubImage2D")) { |
| + gl->TexSubImage2D(target, level, xoffset, yoffset, width, height, format, |
| + type, data); |
| + } else { |
| + DCHECK(false) << functionID << " isn't implemented for format: " |
| + << VideoPixelFormatToString(frame->format()); |
| + } |
| + return true; |
| +} |
| + |
| void SkCanvasVideoRenderer::ResetCache() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| // Clear cached values. |