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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/gl_renderer.h" | 8 #include "cc/output/gl_renderer.h" |
9 #include "cc/resources/resource_provider.h" | 9 #include "cc/resources/resource_provider.h" |
10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 case media::VideoFrame::UNKNOWN: | 80 case media::VideoFrame::UNKNOWN: |
81 case media::VideoFrame::I420: | 81 case media::VideoFrame::I420: |
82 break; | 82 break; |
83 } | 83 } |
84 return false; | 84 return false; |
85 } | 85 } |
86 | 86 |
87 // For frames that we receive in software format, determine the dimensions of | 87 // For frames that we receive in software format, determine the dimensions of |
88 // each plane in the frame. | 88 // each plane in the frame. |
89 static gfx::Size SoftwarePlaneDimension( | 89 static gfx::Size SoftwarePlaneDimension( |
90 media::VideoFrame::Format input_frame_format, | 90 const scoped_refptr<media::VideoFrame>& input_frame, |
91 const gfx::Size& coded_size, | |
92 ResourceFormat output_resource_format, | 91 ResourceFormat output_resource_format, |
93 int plane_index) { | 92 size_t plane_index) { |
94 if (output_resource_format == kYUVResourceFormat) { | 93 if (output_resource_format == kYUVResourceFormat) { |
95 if (plane_index == media::VideoFrame::kYPlane || | 94 return media::VideoFrame::PlaneSize( |
96 plane_index == media::VideoFrame::kAPlane) | 95 input_frame->format(), plane_index, input_frame->coded_size()); |
97 return coded_size; | |
98 | |
99 switch (input_frame_format) { | |
100 case media::VideoFrame::YV12: | |
101 case media::VideoFrame::YV12A: | |
102 case media::VideoFrame::YV12J: | |
103 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 0.5f)); | |
104 case media::VideoFrame::YV16: | |
105 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 1.f)); | |
106 | |
107 case media::VideoFrame::UNKNOWN: | |
108 case media::VideoFrame::I420: | |
109 case media::VideoFrame::NATIVE_TEXTURE: | |
110 #if defined(VIDEO_HOLE) | |
111 case media::VideoFrame::HOLE: | |
112 #endif // defined(VIDEO_HOLE) | |
113 NOTREACHED(); | |
114 } | |
115 } | 96 } |
116 | 97 |
117 DCHECK_EQ(output_resource_format, kRGBResourceFormat); | 98 DCHECK_EQ(output_resource_format, kRGBResourceFormat); |
118 return coded_size; | 99 return input_frame->coded_size(); |
119 } | 100 } |
120 | 101 |
121 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 102 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
122 const scoped_refptr<media::VideoFrame>& video_frame) { | 103 const scoped_refptr<media::VideoFrame>& video_frame) { |
123 media::VideoFrame::Format input_frame_format = video_frame->format(); | 104 media::VideoFrame::Format input_frame_format = video_frame->format(); |
124 | 105 |
125 #if defined(VIDEO_HOLE) | 106 #if defined(VIDEO_HOLE) |
126 if (input_frame_format == media::VideoFrame::HOLE) { | 107 if (input_frame_format == media::VideoFrame::HOLE) { |
127 VideoFrameExternalResources external_resources; | 108 VideoFrameExternalResources external_resources; |
128 external_resources.type = VideoFrameExternalResources::HOLE; | 109 external_resources.type = VideoFrameExternalResources::HOLE; |
129 return external_resources; | 110 return external_resources; |
130 } | 111 } |
131 #endif // defined(VIDEO_HOLE) | 112 #endif // defined(VIDEO_HOLE) |
132 | 113 |
133 // Only YUV software video frames are supported. | 114 // Only YUV software video frames are supported. |
134 DCHECK(input_frame_format == media::VideoFrame::YV12 || | 115 DCHECK(input_frame_format == media::VideoFrame::YV12 || |
135 input_frame_format == media::VideoFrame::YV12A || | 116 input_frame_format == media::VideoFrame::YV12A || |
136 input_frame_format == media::VideoFrame::YV12J || | 117 input_frame_format == media::VideoFrame::YV12J || |
137 input_frame_format == media::VideoFrame::YV16); | 118 input_frame_format == media::VideoFrame::YV16); |
138 if (input_frame_format != media::VideoFrame::YV12 && | 119 if (input_frame_format != media::VideoFrame::YV12 && |
139 input_frame_format != media::VideoFrame::YV12A && | 120 input_frame_format != media::VideoFrame::YV12A && |
140 input_frame_format != media::VideoFrame::YV12J && | 121 input_frame_format != media::VideoFrame::YV12J && |
141 input_frame_format != media::VideoFrame::YV16) | 122 input_frame_format != media::VideoFrame::YV16) |
142 return VideoFrameExternalResources(); | 123 return VideoFrameExternalResources(); |
143 | 124 |
144 bool software_compositor = context_provider_ == NULL; | 125 bool software_compositor = context_provider_ == NULL; |
145 | 126 |
146 ResourceFormat output_resource_format = kYUVResourceFormat; | 127 ResourceFormat output_resource_format = kYUVResourceFormat; |
147 size_t output_plane_count = | 128 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); |
148 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3; | |
149 | 129 |
150 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 130 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
151 // conversion here. That involves an extra copy of each frame to a bitmap. | 131 // conversion here. That involves an extra copy of each frame to a bitmap. |
152 // Obviously, this is suboptimal and should be addressed once ubercompositor | 132 // Obviously, this is suboptimal and should be addressed once ubercompositor |
153 // starts shaping up. | 133 // starts shaping up. |
154 if (software_compositor) { | 134 if (software_compositor) { |
155 output_resource_format = kRGBResourceFormat; | 135 output_resource_format = kRGBResourceFormat; |
156 output_plane_count = 1; | 136 output_plane_count = 1; |
157 } | 137 } |
158 | 138 |
159 int max_resource_size = resource_provider_->max_texture_size(); | 139 int max_resource_size = resource_provider_->max_texture_size(); |
160 gfx::Size coded_frame_size = video_frame->coded_size(); | |
161 | |
162 std::vector<PlaneResource> plane_resources; | 140 std::vector<PlaneResource> plane_resources; |
163 bool allocation_success = true; | 141 bool allocation_success = true; |
164 | 142 |
165 for (size_t i = 0; i < output_plane_count; ++i) { | 143 for (size_t i = 0; i < output_plane_count; ++i) { |
166 gfx::Size output_plane_resource_size = | 144 gfx::Size output_plane_resource_size = |
167 SoftwarePlaneDimension(input_frame_format, | 145 SoftwarePlaneDimension(video_frame, output_resource_format, i); |
168 coded_frame_size, | |
169 output_resource_format, | |
170 i); | |
171 if (output_plane_resource_size.IsEmpty() || | 146 if (output_plane_resource_size.IsEmpty() || |
172 output_plane_resource_size.width() > max_resource_size || | 147 output_plane_resource_size.width() > max_resource_size || |
173 output_plane_resource_size.height() > max_resource_size) { | 148 output_plane_resource_size.height() > max_resource_size) { |
174 allocation_success = false; | 149 allocation_success = false; |
175 break; | 150 break; |
176 } | 151 } |
177 | 152 |
178 ResourceProvider::ResourceId resource_id = 0; | 153 ResourceProvider::ResourceId resource_id = 0; |
179 gpu::Mailbox mailbox; | 154 gpu::Mailbox mailbox; |
180 | 155 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 358 } |
384 | 359 |
385 PlaneResource recycled_resource(data.resource_id, | 360 PlaneResource recycled_resource(data.resource_id, |
386 data.resource_size, | 361 data.resource_size, |
387 data.resource_format, | 362 data.resource_format, |
388 data.mailbox); | 363 data.mailbox); |
389 updater->recycled_resources_.push_back(recycled_resource); | 364 updater->recycled_resources_.push_back(recycled_resource); |
390 } | 365 } |
391 | 366 |
392 } // namespace cc | 367 } // namespace cc |
OLD | NEW |