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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // We need to transfer data from |video_frame| to the plane resource. | 300 // We need to transfer data from |video_frame| to the plane resource. |
301 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 301 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
302 | 302 |
303 // The |resource_size_pixels| is the size of the resource we want to | 303 // The |resource_size_pixels| is the size of the resource we want to |
304 // upload to. | 304 // upload to. |
305 gfx::Size resource_size_pixels = plane_resource.resource_size; | 305 gfx::Size resource_size_pixels = plane_resource.resource_size; |
306 // The |video_stride_pixels| is the width of the video frame we are | 306 // The |video_stride_pixels| is the width of the video frame we are |
307 // uploading (including non-frame data to fill in the stride). | 307 // uploading (including non-frame data to fill in the stride). |
308 size_t video_stride_pixels = video_frame->stride(i); | 308 size_t video_stride_pixels = video_frame->stride(i); |
309 | 309 |
310 size_t bytes_per_pixel = BitsPerPixel(plane_resource.resource_format) / 8; | 310 size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes( |
| 311 resource_size_pixels.width(), plane_resource.resource_format); |
311 // Use 4-byte row alignment (OpenGL default) for upload performance. | 312 // Use 4-byte row alignment (OpenGL default) for upload performance. |
312 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 313 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
313 size_t upload_image_stride = MathUtil::RoundUp<size_t>( | 314 size_t upload_image_stride = MathUtil::RoundUp<size_t>(bytes_per_row, 4u); |
314 bytes_per_pixel * resource_size_pixels.width(), 4u); | |
315 | 315 |
316 const uint8_t* pixels; | 316 const uint8_t* pixels; |
317 if (upload_image_stride == video_stride_pixels * bytes_per_pixel) { | 317 size_t video_bytes_per_row = ResourceUtil::UncheckedWidthInBytes( |
| 318 video_stride_pixels, plane_resource.resource_format); |
| 319 if (upload_image_stride == video_bytes_per_row) { |
318 pixels = video_frame->data(i); | 320 pixels = video_frame->data(i); |
319 } else { | 321 } else { |
320 // Avoid malloc for each frame/plane if possible. | 322 // Avoid malloc for each frame/plane if possible. |
321 size_t needed_size = | 323 size_t needed_size = |
322 upload_image_stride * resource_size_pixels.height(); | 324 upload_image_stride * resource_size_pixels.height(); |
323 if (upload_pixels_.size() < needed_size) | 325 if (upload_pixels_.size() < needed_size) |
324 upload_pixels_.resize(needed_size); | 326 upload_pixels_.resize(needed_size); |
325 for (int row = 0; row < resource_size_pixels.height(); ++row) { | 327 for (int row = 0; row < resource_size_pixels.height(); ++row) { |
326 uint8_t* dst = &upload_pixels_[upload_image_stride * row]; | 328 uint8_t* dst = &upload_pixels_[upload_image_stride * row]; |
327 const uint8_t* src = video_frame->data(i) + | 329 const uint8_t* src = |
328 bytes_per_pixel * video_stride_pixels * row; | 330 video_frame->data(i) + (video_bytes_per_row * row); |
329 memcpy(dst, src, resource_size_pixels.width() * bytes_per_pixel); | 331 memcpy(dst, src, bytes_per_row); |
330 } | 332 } |
331 pixels = &upload_pixels_[0]; | 333 pixels = &upload_pixels_[0]; |
332 } | 334 } |
333 | 335 |
334 resource_provider_->CopyToResource(plane_resource.resource_id, pixels, | 336 resource_provider_->CopyToResource(plane_resource.resource_id, pixels, |
335 resource_size_pixels); | 337 resource_size_pixels); |
336 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); | 338 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); |
337 } | 339 } |
338 | 340 |
339 external_resources.mailboxes.push_back( | 341 external_resources.mailboxes.push_back( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 resource_it->ref_count = 0; | 460 resource_it->ref_count = 0; |
459 updater->DeleteResource(resource_it); | 461 updater->DeleteResource(resource_it); |
460 return; | 462 return; |
461 } | 463 } |
462 | 464 |
463 --resource_it->ref_count; | 465 --resource_it->ref_count; |
464 DCHECK_GE(resource_it->ref_count, 0); | 466 DCHECK_GE(resource_it->ref_count, 0); |
465 } | 467 } |
466 | 468 |
467 } // namespace cc | 469 } // namespace cc |
OLD | NEW |