Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5044)

Unified Diff: cc/resources/video_resource_updater.cc

Issue 1202843008: cc: Fix BytesPerPixel issue and refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/video_resource_updater.cc
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index e973a3d5240d057877100f4c7a0fb8e366e7b148..1bb68a058d8b6233796fe5c9365d1d37a18c2ae0 100644
--- a/cc/resources/video_resource_updater.cc
+++ b/cc/resources/video_resource_updater.cc
@@ -307,14 +307,16 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
// uploading (including non-frame data to fill in the stride).
size_t video_stride_pixels = video_frame->stride(i);
- size_t bytes_per_pixel = BitsPerPixel(plane_resource.resource_format) / 8;
+ size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes(
+ resource_size_pixels.width(), plane_resource.resource_format);
// Use 4-byte row alignment (OpenGL default) for upload performance.
// Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
- size_t upload_image_stride = MathUtil::RoundUp<size_t>(
- bytes_per_pixel * resource_size_pixels.width(), 4u);
+ size_t upload_image_stride = MathUtil::RoundUp<size_t>(bytes_per_row, 4u);
const uint8_t* pixels;
- if (upload_image_stride == video_stride_pixels * bytes_per_pixel) {
+ size_t video_bytes_per_row = ResourceUtil::UncheckedWidthInBytes(
+ video_stride_pixels, plane_resource.resource_format);
+ if (upload_image_stride == video_bytes_per_row) {
pixels = video_frame->data(i);
} else {
// Avoid malloc for each frame/plane if possible.
@@ -324,9 +326,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
upload_pixels_.resize(needed_size);
for (int row = 0; row < resource_size_pixels.height(); ++row) {
uint8_t* dst = &upload_pixels_[upload_image_stride * row];
- const uint8_t* src = video_frame->data(i) +
- bytes_per_pixel * video_stride_pixels * row;
- memcpy(dst, src, resource_size_pixels.width() * bytes_per_pixel);
+ const uint8_t* src =
+ video_frame->data(i) + (video_bytes_per_row * row);
+ memcpy(dst, src, bytes_per_row);
}
pixels = &upload_pixels_[0];
}

Powered by Google App Engine
This is Rietveld 408576698