OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layers/video_layer_impl.h" | 5 #include "cc/layers/video_layer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/layers/video_frame_provider_client_impl.h" | 9 #include "cc/layers/video_frame_provider_client_impl.h" |
10 #include "cc/quads/io_surface_draw_quad.h" | 10 #include "cc/quads/io_surface_draw_quad.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // Pixels for macroblocked formats. | 181 // Pixels for macroblocked formats. |
182 const float tex_width_scale = | 182 const float tex_width_scale = |
183 static_cast<float>(visible_rect.width()) / coded_size.width(); | 183 static_cast<float>(visible_rect.width()) / coded_size.width(); |
184 const float tex_height_scale = | 184 const float tex_height_scale = |
185 static_cast<float>(visible_rect.height()) / coded_size.height(); | 185 static_cast<float>(visible_rect.height()) / coded_size.height(); |
186 const float tex_x_offset = | 186 const float tex_x_offset = |
187 static_cast<float>(visible_rect.x()) / coded_size.width(); | 187 static_cast<float>(visible_rect.x()) / coded_size.width(); |
188 const float tex_y_offset = | 188 const float tex_y_offset = |
189 static_cast<float>(visible_rect.y()) / coded_size.height(); | 189 static_cast<float>(visible_rect.y()) / coded_size.height(); |
190 | 190 |
| 191 // Vertex shader should clamp to the visible rect, and then minus |
| 192 // half a pixel (of the coded size) to account for bilinear filtering. |
| 193 // This prevents sampling outside of the visible rect. |
| 194 gfx::SizeF half_pixel(0.5f / coded_size.width(), 0.5f / coded_size.height()); |
| 195 gfx::SizeF clamp_size(tex_width_scale + tex_x_offset - half_pixel.width(), |
| 196 tex_height_scale + tex_y_offset - half_pixel.height()); |
| 197 |
191 switch (frame_resource_type_) { | 198 switch (frame_resource_type_) { |
192 // TODO(danakj): Remove this, hide it in the hardware path. | 199 // TODO(danakj): Remove this, hide it in the hardware path. |
193 case VideoFrameExternalResources::SOFTWARE_RESOURCE: { | 200 case VideoFrameExternalResources::SOFTWARE_RESOURCE: { |
194 DCHECK_EQ(frame_resources_.size(), 0u); | 201 DCHECK_EQ(frame_resources_.size(), 0u); |
195 DCHECK_EQ(software_resources_.size(), 1u); | 202 DCHECK_EQ(software_resources_.size(), 1u); |
196 if (software_resources_.size() < 1u) | 203 if (software_resources_.size() < 1u) |
197 break; | 204 break; |
198 bool premultiplied_alpha = true; | 205 bool premultiplied_alpha = true; |
199 gfx::PointF uv_top_left(0.f, 0.f); | 206 gfx::PointF uv_top_left(0.f, 0.f); |
200 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); | 207 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); |
(...skipping 22 matching lines...) Expand all Loading... |
223 break; | 230 break; |
224 YUVVideoDrawQuad::ColorSpace color_space = | 231 YUVVideoDrawQuad::ColorSpace color_space = |
225 frame_->format() == media::VideoFrame::YV12J | 232 frame_->format() == media::VideoFrame::YV12J |
226 ? YUVVideoDrawQuad::REC_601_JPEG | 233 ? YUVVideoDrawQuad::REC_601_JPEG |
227 : YUVVideoDrawQuad::REC_601; | 234 : YUVVideoDrawQuad::REC_601; |
228 gfx::RectF tex_coord_rect( | 235 gfx::RectF tex_coord_rect( |
229 tex_x_offset, tex_y_offset, tex_width_scale, tex_height_scale); | 236 tex_x_offset, tex_y_offset, tex_width_scale, tex_height_scale); |
230 YUVVideoDrawQuad* yuv_video_quad = | 237 YUVVideoDrawQuad* yuv_video_quad = |
231 render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); | 238 render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); |
232 yuv_video_quad->SetNew( | 239 yuv_video_quad->SetNew( |
233 shared_quad_state, | 240 shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, |
234 quad_rect, | 241 tex_coord_rect, clamp_size, frame_resources_[0], frame_resources_[1], |
235 opaque_rect, | |
236 visible_quad_rect, | |
237 tex_coord_rect, | |
238 frame_resources_[0], | |
239 frame_resources_[1], | |
240 frame_resources_[2], | 242 frame_resources_[2], |
241 frame_resources_.size() > 3 ? frame_resources_[3] : 0, | 243 frame_resources_.size() > 3 ? frame_resources_[3] : 0, color_space); |
242 color_space); | |
243 break; | 244 break; |
244 } | 245 } |
245 case VideoFrameExternalResources::RGB_RESOURCE: { | 246 case VideoFrameExternalResources::RGB_RESOURCE: { |
246 DCHECK_EQ(frame_resources_.size(), 1u); | 247 DCHECK_EQ(frame_resources_.size(), 1u); |
247 if (frame_resources_.size() < 1u) | 248 if (frame_resources_.size() < 1u) |
248 break; | 249 break; |
249 bool premultiplied_alpha = true; | 250 bool premultiplied_alpha = true; |
250 gfx::PointF uv_top_left(0.f, 0.f); | 251 gfx::PointF uv_top_left(0.f, 0.f); |
251 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); | 252 gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale); |
252 float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 253 float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 void VideoLayerImpl::SetProviderClientImpl( | 370 void VideoLayerImpl::SetProviderClientImpl( |
370 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl) { | 371 scoped_refptr<VideoFrameProviderClientImpl> provider_client_impl) { |
371 provider_client_impl_ = provider_client_impl; | 372 provider_client_impl_ = provider_client_impl; |
372 } | 373 } |
373 | 374 |
374 const char* VideoLayerImpl::LayerTypeAsString() const { | 375 const char* VideoLayerImpl::LayerTypeAsString() const { |
375 return "cc::VideoLayerImpl"; | 376 return "cc::VideoLayerImpl"; |
376 } | 377 } |
377 | 378 |
378 } // namespace cc | 379 } // namespace cc |
OLD | NEW |