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 // Copy one row. |
danakj
2016/10/03 23:47:44
this comment's redundant i think, the var says the
hubbe
2016/10/03 23:56:35
Done.
| |
307 // simply extract the low bits of the exponent and the high | 308 int rows = 1; |
308 // bits of the mantissa from our float and we're done. | 309 libyuv::HalfFloatPlane(src, stride, dst, stride, 1.0f / max_value, num, rows); |
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 } | 310 } |
315 | 311 |
316 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 312 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
317 scoped_refptr<media::VideoFrame> video_frame) { | 313 scoped_refptr<media::VideoFrame> video_frame) { |
318 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 314 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
319 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 315 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
320 | 316 |
321 // TODO(hubbe): Make this a video frame method. | 317 // TODO(hubbe): Make this a video frame method. |
322 int bits_per_channel = 0; | 318 int bits_per_channel = 0; |
323 switch (input_frame_format) { | 319 switch (input_frame_format) { |
(...skipping 441 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 |