| Index: cc/resources/video_resource_updater.cc
|
| diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
|
| index 2584e0b3a83308af23ac83893c244a9badc04111..efe48c03fc94a67c5659a9b34083f8d9e17047f7 100644
|
| --- a/cc/resources/video_resource_updater.cc
|
| +++ b/cc/resources/video_resource_updater.cc
|
| @@ -84,6 +84,8 @@ VideoFrameExternalResources::ResourceType ResourceTypeForVideoFrame(
|
| case media::PIXEL_FORMAT_YUV420P10:
|
| case media::PIXEL_FORMAT_YUV422P10:
|
| case media::PIXEL_FORMAT_YUV444P10:
|
| + case media::PIXEL_FORMAT_Y8:
|
| + case media::PIXEL_FORMAT_Y16:
|
| case media::PIXEL_FORMAT_UNKNOWN:
|
| break;
|
| }
|
| @@ -295,6 +297,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| const media::VideoPixelFormat input_frame_format = video_frame->format();
|
|
|
| // TODO(hubbe): Make this a video frame method.
|
| + // TODO(dshwang): handle YUV4XXPX by GMBs pool code. crbug.com/445071
|
| int bits_per_channel = 0;
|
| switch (input_frame_format) {
|
| case media::PIXEL_FORMAT_UNKNOWN:
|
| @@ -315,6 +318,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| case media::PIXEL_FORMAT_RGB32:
|
| case media::PIXEL_FORMAT_MJPEG:
|
| case media::PIXEL_FORMAT_MT21:
|
| + case media::PIXEL_FORMAT_Y8:
|
| bits_per_channel = 8;
|
| break;
|
| case media::PIXEL_FORMAT_YUV420P9:
|
| @@ -327,6 +331,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| case media::PIXEL_FORMAT_YUV444P10:
|
| bits_per_channel = 10;
|
| break;
|
| + case media::PIXEL_FORMAT_Y16:
|
| + bits_per_channel = 16;
|
| + break;
|
| }
|
|
|
| // Only YUV software video frames are supported.
|
| @@ -393,7 +400,6 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| }
|
|
|
| VideoFrameExternalResources external_resources;
|
| -
|
| external_resources.bits_per_channel = bits_per_channel;
|
|
|
| if (software_compositor || texture_needs_rgb_conversion) {
|
| @@ -452,13 +458,31 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| return external_resources;
|
| }
|
|
|
| - for (size_t i = 0; i < plane_resources.size(); ++i) {
|
| - PlaneResource& plane_resource = *plane_resources[i];
|
| + bool needs_conversion = false;
|
| + int shift = 0;
|
| + if (output_resource_format == LUMINANCE_F16) {
|
| + // LUMINANCE_F16 uses half-floats, so we always need a conversion step.
|
| + needs_conversion = true;
|
| + // Note that the current method of converting integers to half-floats
|
| + // stops working if you have more than 10 bits of data.
|
| + DCHECK_LE(bits_per_channel, 10);
|
| + } else if (output_resource_format == RG_88) {
|
| + // RG_88 can represent 16bit int, so we don't need a conversion step.
|
| + needs_conversion = false;
|
| + } else if (bits_per_channel > 8) {
|
| + // If bits_per_channel > 8 and we can't use RG_88, we need to
|
| + // shift the data down and create an 8-bit texture.
|
| + needs_conversion = true;
|
| + shift = bits_per_channel - 8;
|
| + external_resources.bits_per_channel = 8;
|
| + }
|
| +
|
| + for (size_t plane = 0; plane < plane_resources.size(); ++plane) {
|
| + PlaneResource& plane_resource = *plane_resources[plane];
|
| // Update each plane's resource id with its content.
|
| - DCHECK_EQ(plane_resource.resource_format(),
|
| - resource_provider_->YuvResourceFormat(bits_per_channel));
|
| + DCHECK_EQ(plane_resource.resource_format(), output_resource_format);
|
|
|
| - if (!plane_resource.Matches(video_frame->unique_id(), i)) {
|
| + if (!plane_resource.Matches(video_frame->unique_id(), plane)) {
|
| // We need to transfer data from |video_frame| to the plane resource.
|
| // TODO(reveman): Can use GpuMemoryBuffers here to improve performance.
|
|
|
| @@ -467,7 +491,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| gfx::Size resource_size_pixels = plane_resource.resource_size();
|
| // The |video_stride_bytes| is the width of the video frame we are
|
| // uploading (including non-frame data to fill in the stride).
|
| - int video_stride_bytes = video_frame->stride(i);
|
| + int video_stride_bytes = video_frame->stride(plane);
|
|
|
| size_t bytes_per_row = ResourceUtil::CheckedWidthInBytes<size_t>(
|
| resource_size_pixels.width(), plane_resource.resource_format());
|
| @@ -476,25 +500,10 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| size_t upload_image_stride =
|
| MathUtil::CheckedRoundUp<size_t>(bytes_per_row, 4u);
|
|
|
| - bool needs_conversion = false;
|
| - int shift = 0;
|
| -
|
| - // LUMINANCE_F16 uses half-floats, so we always need a conversion step.
|
| - if (plane_resource.resource_format() == LUMINANCE_F16) {
|
| - needs_conversion = true;
|
| - // Note that the current method of converting integers to half-floats
|
| - // stops working if you have more than 10 bits of data.
|
| - DCHECK_LE(bits_per_channel, 10);
|
| - } else if (bits_per_channel > 8) {
|
| - // If bits_per_channel > 8 and we can't use LUMINANCE_F16, we need to
|
| - // shift the data down and create an 8-bit texture.
|
| - needs_conversion = true;
|
| - shift = bits_per_channel - 8;
|
| - }
|
| const uint8_t* pixels;
|
| if (static_cast<int>(upload_image_stride) == video_stride_bytes &&
|
| !needs_conversion) {
|
| - pixels = video_frame->data(i);
|
| + pixels = video_frame->data(plane);
|
| } else {
|
| // Avoid malloc for each frame/plane if possible.
|
| size_t needed_size =
|
| @@ -507,7 +516,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| uint16_t* dst = reinterpret_cast<uint16_t*>(
|
| &upload_pixels_[upload_image_stride * row]);
|
| const uint16_t* src = reinterpret_cast<uint16_t*>(
|
| - video_frame->data(i) + (video_stride_bytes * row));
|
| + video_frame->data(plane) + (video_stride_bytes * row));
|
| // Micro-benchmarking indicates that the compiler does
|
| // a good enough job of optimizing this loop that trying
|
| // to manually operate on one uint64 at a time is not
|
| @@ -520,15 +529,16 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
| // down to fit it into an 8-bit texture.
|
| uint8_t* dst = &upload_pixels_[upload_image_stride * row];
|
| const uint16_t* src = reinterpret_cast<uint16_t*>(
|
| - video_frame->data(i) + (video_stride_bytes * row));
|
| + video_frame->data(plane) + (video_stride_bytes * row));
|
| for (size_t i = 0; i < bytes_per_row; i++)
|
| dst[i] = src[i] >> shift;
|
| +
|
| } else {
|
| // Input and output are the same size and format, but
|
| // differ in stride, copy one row at a time.
|
| uint8_t* dst = &upload_pixels_[upload_image_stride * row];
|
| const uint8_t* src =
|
| - video_frame->data(i) + (video_stride_bytes * row);
|
| + video_frame->data(plane) + (video_stride_bytes * row);
|
| memcpy(dst, src, bytes_per_row);
|
| }
|
| }
|
| @@ -537,7 +547,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
|
|
|
| resource_provider_->CopyToResource(plane_resource.resource_id(), pixels,
|
| resource_size_pixels);
|
| - plane_resource.SetUniqueId(video_frame->unique_id(), i);
|
| + plane_resource.SetUniqueId(video_frame->unique_id(), plane);
|
| }
|
|
|
| if (plane_resource.resource_format() == LUMINANCE_F16) {
|
|
|