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 libyuv::HalfFloatPlane(src, 0, dst, 0, 1.0f / ((1 << bits_per_channel) - 1), |
danakj
2016/10/03 22:48:15
Can you use a temp var to give "1.0f / ((1 << bits
hubbe
2016/10/03 23:30:49
Better?
danakj
2016/10/03 23:47:43
Much, thanks.
hubbe
2016/10/03 23:56:35
Acknowledged.
| |
302 | 303 num, 1); |
303 // This magic constant is 2^-112. Multiplying by this | |
304 // is the same as subtracting 112 from the exponent, which | |
305 // is the difference in exponent bias between 32-bit and | |
306 // 16-bit floats. Once we've done this subtraction, we can | |
307 // simply extract the low bits of the exponent and the high | |
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 } | 304 } |
315 | 305 |
316 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 306 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
317 scoped_refptr<media::VideoFrame> video_frame) { | 307 scoped_refptr<media::VideoFrame> video_frame) { |
318 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 308 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
319 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 309 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
320 | 310 |
321 // TODO(hubbe): Make this a video frame method. | 311 // TODO(hubbe): Make this a video frame method. |
322 int bits_per_channel = 0; | 312 int bits_per_channel = 0; |
323 switch (input_frame_format) { | 313 switch (input_frame_format) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 } | 477 } |
488 return external_resources; | 478 return external_resources; |
489 } | 479 } |
490 | 480 |
491 for (size_t i = 0; i < plane_resources.size(); ++i) { | 481 for (size_t i = 0; i < plane_resources.size(); ++i) { |
492 PlaneResource& plane_resource = *plane_resources[i]; | 482 PlaneResource& plane_resource = *plane_resources[i]; |
493 // Update each plane's resource id with its content. | 483 // Update each plane's resource id with its content. |
494 DCHECK_EQ(plane_resource.resource_format(), | 484 DCHECK_EQ(plane_resource.resource_format(), |
495 resource_provider_->YuvResourceFormat(bits_per_channel)); | 485 resource_provider_->YuvResourceFormat(bits_per_channel)); |
496 | 486 |
497 if (!plane_resource.Matches(video_frame->unique_id(), i)) { | 487 if (!plane_resource.Matches(video_frame->unique_id(), i)) { |
danakj
2016/10/03 22:48:15
I'm starting to wonder if everything inside this i
hubbe
2016/10/03 23:30:49
Agreed, although I'm not sure exactly what that wo
danakj
2016/10/03 23:47:44
Yeh, I don't know that it belongs on VideoFrame. D
hubbe
2016/10/03 23:56:35
All true, but probably better resolved in a separa
danakj
2016/10/03 23:58:56
A TODO is more than I was expecting for this CL, t
| |
498 // We need to transfer data from |video_frame| to the plane resource. | 488 // We need to transfer data from |video_frame| to the plane resource. |
499 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 489 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
500 | 490 |
501 // The |resource_size_pixels| is the size of the resource we want to | 491 // The |resource_size_pixels| is the size of the resource we want to |
502 // upload to. | 492 // upload to. |
503 gfx::Size resource_size_pixels = plane_resource.resource_size(); | 493 gfx::Size resource_size_pixels = plane_resource.resource_size(); |
504 // The |video_stride_bytes| is the width of the video frame we are | 494 // The |video_stride_bytes| is the width of the video frame we are |
505 // uploading (including non-frame data to fill in the stride). | 495 // uploading (including non-frame data to fill in the stride). |
506 int video_stride_bytes = video_frame->stride(i); | 496 int video_stride_bytes = video_frame->stride(i); |
507 | 497 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 if (lost_resource) { | 755 if (lost_resource) { |
766 resource_it->clear_refs(); | 756 resource_it->clear_refs(); |
767 updater->DeleteResource(resource_it); | 757 updater->DeleteResource(resource_it); |
768 return; | 758 return; |
769 } | 759 } |
770 | 760 |
771 resource_it->remove_ref(); | 761 resource_it->remove_ref(); |
772 } | 762 } |
773 | 763 |
774 } // namespace cc | 764 } // namespace cc |
OLD | NEW |