| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/video_layer_impl.h" | 7 #include "cc/video_layer_impl.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/io_surface_draw_quad.h" | 10 #include "cc/io_surface_draw_quad.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 if (format == media::VideoFrame::YV12 && plane != media::VideoFrame::kYPlane
) | 280 if (format == media::VideoFrame::YV12 && plane != media::VideoFrame::kYPlane
) |
| 281 return originalDimension / 2; | 281 return originalDimension / 2; |
| 282 return originalDimension; | 282 return originalDimension; |
| 283 } | 283 } |
| 284 | 284 |
| 285 static bool hasPaddingBytes(const media::VideoFrame& frame, size_t plane) | 285 static bool hasPaddingBytes(const media::VideoFrame& frame, size_t plane) |
| 286 { | 286 { |
| 287 return frame.stride(plane) > videoFrameDimension(frame.data_size().width(),
plane, frame.format()); | 287 return frame.stride(plane) > videoFrameDimension(frame.data_size().width(),
plane, frame.format()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 IntSize computeVisibleSize(const media::VideoFrame& frame, size_t plane) | 290 gfx::Size computeVisibleSize(const media::VideoFrame& frame, size_t plane) |
| 291 { | 291 { |
| 292 int visibleWidth = videoFrameDimension(frame.data_size().width(), plane, fra
me.format()); | 292 int visibleWidth = videoFrameDimension(frame.data_size().width(), plane, fra
me.format()); |
| 293 int originalWidth = visibleWidth; | 293 int originalWidth = visibleWidth; |
| 294 int visibleHeight = videoFrameDimension(frame.data_size().height(), plane, f
rame.format()); | 294 int visibleHeight = videoFrameDimension(frame.data_size().height(), plane, f
rame.format()); |
| 295 | 295 |
| 296 // When there are dead pixels at the edge of the texture, decrease | 296 // When there are dead pixels at the edge of the texture, decrease |
| 297 // the frame width by 1 to prevent the rightmost pixels from | 297 // the frame width by 1 to prevent the rightmost pixels from |
| 298 // interpolating with the dead pixels. | 298 // interpolating with the dead pixels. |
| 299 if (hasPaddingBytes(frame, plane)) | 299 if (hasPaddingBytes(frame, plane)) |
| 300 --visibleWidth; | 300 --visibleWidth; |
| 301 | 301 |
| 302 // In YV12, every 2x2 square of Y values corresponds to one U and | 302 // In YV12, every 2x2 square of Y values corresponds to one U and |
| 303 // one V value. If we decrease the width of the UV plane, we must decrease t
he | 303 // one V value. If we decrease the width of the UV plane, we must decrease t
he |
| 304 // width of the Y texture by 2 for proper alignment. This must happen | 304 // width of the Y texture by 2 for proper alignment. This must happen |
| 305 // always, even if Y's texture does not have padding bytes. | 305 // always, even if Y's texture does not have padding bytes. |
| 306 if (plane == media::VideoFrame::kYPlane && frame.format() == media::VideoFra
me::YV12) { | 306 if (plane == media::VideoFrame::kYPlane && frame.format() == media::VideoFra
me::YV12) { |
| 307 if (hasPaddingBytes(frame, media::VideoFrame::kUPlane)) | 307 if (hasPaddingBytes(frame, media::VideoFrame::kUPlane)) |
| 308 visibleWidth = originalWidth - 2; | 308 visibleWidth = originalWidth - 2; |
| 309 } | 309 } |
| 310 | 310 |
| 311 return IntSize(visibleWidth, visibleHeight); | 311 return gfx::Size(visibleWidth, visibleHeight); |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool VideoLayerImpl::FramePlane::allocateData(ResourceProvider* resourceProvider
) | 314 bool VideoLayerImpl::FramePlane::allocateData(ResourceProvider* resourceProvider
) |
| 315 { | 315 { |
| 316 if (resourceId) | 316 if (resourceId) |
| 317 return true; | 317 return true; |
| 318 | 318 |
| 319 resourceId = resourceProvider->createResource(Renderer::ImplPool, size, form
at, ResourceProvider::TextureUsageAny); | 319 resourceId = resourceProvider->createResource(Renderer::ImplPool, size, form
at, ResourceProvider::TextureUsageAny); |
| 320 return resourceId; | 320 return resourceId; |
| 321 } | 321 } |
| 322 | 322 |
| 323 void VideoLayerImpl::FramePlane::freeData(ResourceProvider* resourceProvider) | 323 void VideoLayerImpl::FramePlane::freeData(ResourceProvider* resourceProvider) |
| 324 { | 324 { |
| 325 if (!resourceId) | 325 if (!resourceId) |
| 326 return; | 326 return; |
| 327 | 327 |
| 328 resourceProvider->deleteResource(resourceId); | 328 resourceProvider->deleteResource(resourceId); |
| 329 resourceId = 0; | 329 resourceId = 0; |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool VideoLayerImpl::allocatePlaneData(ResourceProvider* resourceProvider) | 332 bool VideoLayerImpl::allocatePlaneData(ResourceProvider* resourceProvider) |
| 333 { | 333 { |
| 334 const int maxTextureSize = resourceProvider->maxTextureSize(); | 334 const int maxTextureSize = resourceProvider->maxTextureSize(); |
| 335 const size_t planeCount = numPlanes(); | 335 const size_t planeCount = numPlanes(); |
| 336 for (size_t planeIndex = 0; planeIndex < planeCount; ++planeIndex) { | 336 for (size_t planeIndex = 0; planeIndex < planeCount; ++planeIndex) { |
| 337 VideoLayerImpl::FramePlane& plane = m_framePlanes[planeIndex]; | 337 VideoLayerImpl::FramePlane& plane = m_framePlanes[planeIndex]; |
| 338 | 338 |
| 339 IntSize requiredTextureSize(m_frame->stride(planeIndex), videoFrameDimen
sion(m_frame->data_size().height(), planeIndex, m_frame->format())); | 339 gfx::Size requiredTextureSize(m_frame->stride(planeIndex), videoFrameDim
ension(m_frame->data_size().height(), planeIndex, m_frame->format())); |
| 340 // FIXME: Remove the test against maxTextureSize when tiled layers are i
mplemented. | 340 // FIXME: Remove the test against maxTextureSize when tiled layers are i
mplemented. |
| 341 if (requiredTextureSize.isZero() || requiredTextureSize.width() > maxTex
tureSize || requiredTextureSize.height() > maxTextureSize) | 341 if (requiredTextureSize.IsEmpty() || requiredTextureSize.width() > maxTe
xtureSize || requiredTextureSize.height() > maxTextureSize) |
| 342 return false; | 342 return false; |
| 343 | 343 |
| 344 if (plane.size != requiredTextureSize || plane.format != m_format) { | 344 if (plane.size != requiredTextureSize || plane.format != m_format) { |
| 345 plane.freeData(resourceProvider); | 345 plane.freeData(resourceProvider); |
| 346 plane.size = requiredTextureSize; | 346 plane.size = requiredTextureSize; |
| 347 plane.format = m_format; | 347 plane.format = m_format; |
| 348 } | 348 } |
| 349 | 349 |
| 350 if (!plane.resourceId) { | 350 if (!plane.resourceId) { |
| 351 if (!plane.allocateData(resourceProvider)) | 351 if (!plane.allocateData(resourceProvider)) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 str->append("video layer\n"); | 424 str->append("video layer\n"); |
| 425 LayerImpl::dumpLayerProperties(str, indent); | 425 LayerImpl::dumpLayerProperties(str, indent); |
| 426 } | 426 } |
| 427 | 427 |
| 428 const char* VideoLayerImpl::layerTypeAsString() const | 428 const char* VideoLayerImpl::layerTypeAsString() const |
| 429 { | 429 { |
| 430 return "VideoLayer"; | 430 return "VideoLayer"; |
| 431 } | 431 } |
| 432 | 432 |
| 433 } | 433 } |
| OLD | NEW |