OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bit_cast.h" | 13 #include "base/bit_cast.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
16 #include "cc/output/gl_renderer.h" | 16 #include "cc/output/gl_renderer.h" |
17 #include "cc/resources/resource_provider.h" | 17 #include "cc/resources/resource_provider.h" |
18 #include "cc/resources/resource_util.h" | 18 #include "cc/resources/resource_util.h" |
19 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
20 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
22 #include "media/renderers/skcanvas_video_renderer.h" | 22 #include "media/renderers/skcanvas_video_renderer.h" |
23 #include "third_party/khronos/GLES2/gl2.h" | 23 #include "third_party/khronos/GLES2/gl2.h" |
24 #include "third_party/khronos/GLES2/gl2ext.h" | 24 #include "third_party/khronos/GLES2/gl2ext.h" |
| 25 #include "third_party/libyuv/include/libyuv.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "ui/gfx/geometry/size_conversions.h" | 27 #include "ui/gfx/geometry/size_conversions.h" |
27 | 28 |
28 namespace cc { | 29 namespace cc { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 const ResourceFormat kRGBResourceFormat = RGBA_8888; | 33 const ResourceFormat kRGBResourceFormat = RGBA_8888; |
33 | 34 |
34 VideoFrameExternalResources::ResourceType ResourceTypeForVideoFrame( | 35 VideoFrameExternalResources::ResourceType ResourceTypeForVideoFrame( |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 plane_index, input_frame->format(), coded_size.width()); | 292 plane_index, input_frame->format(), coded_size.width()); |
292 int plane_height = media::VideoFrame::Rows(plane_index, input_frame->format(), | 293 int plane_height = media::VideoFrame::Rows(plane_index, input_frame->format(), |
293 coded_size.height()); | 294 coded_size.height()); |
294 return gfx::Size(plane_width, plane_height); | 295 return gfx::Size(plane_width, plane_height); |
295 } | 296 } |
296 | 297 |
297 void VideoResourceUpdater::MakeHalfFloats(const uint16_t* src, | 298 void VideoResourceUpdater::MakeHalfFloats(const uint16_t* src, |
298 int bits_per_channel, | 299 int bits_per_channel, |
299 size_t num, | 300 size_t num, |
300 uint16_t* dst) { | 301 uint16_t* dst) { |
301 // TODO(hubbe): Make AVX and neon versions of this code. | 302 // Source and dest stride can be zero since we're only copying |
302 | 303 // one row at a time. |
303 // This magic constant is 2^-112. Multiplying by this | 304 int stride = 0; |
304 // is the same as subtracting 112 from the exponent, which | 305 // Maximum value used in |src|. |
305 // is the difference in exponent bias between 32-bit and | 306 int max_value = (1 << bits_per_channel) - 1; |
306 // 16-bit floats. Once we've done this subtraction, we can | 307 int rows = 1; |
307 // simply extract the low bits of the exponent and the high | 308 libyuv::HalfFloatPlane(src, stride, dst, stride, 1.0f / max_value, num, rows); |
308 // bits of the mantissa from our float and we're done. | |
309 float mult = 1.9259299444e-34f / ((1 << bits_per_channel) - 1); | |
310 for (size_t i = 0; i < num; i++) { | |
311 float value = src[i] * mult; | |
312 dst[i] = (*(uint32_t*)&value) >> 13; | |
313 } | |
314 } | 309 } |
315 | 310 |
316 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 311 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
317 scoped_refptr<media::VideoFrame> video_frame) { | 312 scoped_refptr<media::VideoFrame> video_frame) { |
318 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 313 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
319 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 314 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
320 | 315 |
321 // TODO(hubbe): Make this a video frame method. | 316 // TODO(hubbe): Make this a video frame method. |
322 int bits_per_channel = 0; | 317 int bits_per_channel = 0; |
323 switch (input_frame_format) { | 318 switch (input_frame_format) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 return external_resources; | 483 return external_resources; |
489 } | 484 } |
490 | 485 |
491 for (size_t i = 0; i < plane_resources.size(); ++i) { | 486 for (size_t i = 0; i < plane_resources.size(); ++i) { |
492 PlaneResource& plane_resource = *plane_resources[i]; | 487 PlaneResource& plane_resource = *plane_resources[i]; |
493 // Update each plane's resource id with its content. | 488 // Update each plane's resource id with its content. |
494 DCHECK_EQ(plane_resource.resource_format(), | 489 DCHECK_EQ(plane_resource.resource_format(), |
495 resource_provider_->YuvResourceFormat(bits_per_channel)); | 490 resource_provider_->YuvResourceFormat(bits_per_channel)); |
496 | 491 |
497 if (!plane_resource.Matches(video_frame->unique_id(), i)) { | 492 if (!plane_resource.Matches(video_frame->unique_id(), i)) { |
| 493 // TODO(hubbe): Move all conversion (and upload?) code to media/. |
498 // We need to transfer data from |video_frame| to the plane resource. | 494 // We need to transfer data from |video_frame| to the plane resource. |
499 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 495 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
500 | 496 |
501 // The |resource_size_pixels| is the size of the resource we want to | 497 // The |resource_size_pixels| is the size of the resource we want to |
502 // upload to. | 498 // upload to. |
503 gfx::Size resource_size_pixels = plane_resource.resource_size(); | 499 gfx::Size resource_size_pixels = plane_resource.resource_size(); |
504 // The |video_stride_bytes| is the width of the video frame we are | 500 // The |video_stride_bytes| is the width of the video frame we are |
505 // uploading (including non-frame data to fill in the stride). | 501 // uploading (including non-frame data to fill in the stride). |
506 int video_stride_bytes = video_frame->stride(i); | 502 int video_stride_bytes = video_frame->stride(i); |
507 | 503 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (lost_resource) { | 761 if (lost_resource) { |
766 resource_it->clear_refs(); | 762 resource_it->clear_refs(); |
767 updater->DeleteResource(resource_it); | 763 updater->DeleteResource(resource_it); |
768 return; | 764 return; |
769 } | 765 } |
770 | 766 |
771 resource_it->remove_ref(); | 767 resource_it->remove_ref(); |
772 } | 768 } |
773 | 769 |
774 } // namespace cc | 770 } // namespace cc |
OLD | NEW |