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

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 1266103005: cc: Handle overflow/underflow in MathUtil::RoundUp/RoundDown functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small nit. Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « cc/resources/resource_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 int video_stride_pixels = video_frame->stride(i); 308 int video_stride_pixels = video_frame->stride(i);
309 309
310 size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>( 310 size_t bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>(
311 resource_size_pixels.width(), plane_resource.resource_format); 311 resource_size_pixels.width(), plane_resource.resource_format);
312 // Use 4-byte row alignment (OpenGL default) for upload performance. 312 // Use 4-byte row alignment (OpenGL default) for upload performance.
313 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. 313 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
314 size_t upload_image_stride = MathUtil::RoundUp<size_t>(bytes_per_row, 4u); 314 size_t upload_image_stride =
315 MathUtil::UncheckedRoundUp<size_t>(bytes_per_row, 4u);
315 316
316 const uint8_t* pixels; 317 const uint8_t* pixels;
317 size_t video_bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>( 318 size_t video_bytes_per_row = ResourceUtil::UncheckedWidthInBytes<size_t>(
318 video_stride_pixels, plane_resource.resource_format); 319 video_stride_pixels, plane_resource.resource_format);
319 if (upload_image_stride == video_bytes_per_row) { 320 if (upload_image_stride == video_bytes_per_row) {
320 pixels = video_frame->data(i); 321 pixels = video_frame->data(i);
321 } else { 322 } else {
322 // Avoid malloc for each frame/plane if possible. 323 // Avoid malloc for each frame/plane if possible.
323 size_t needed_size = 324 size_t needed_size =
324 upload_image_stride * resource_size_pixels.height(); 325 upload_image_stride * resource_size_pixels.height();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 resource_it->ref_count = 0; 461 resource_it->ref_count = 0;
461 updater->DeleteResource(resource_it); 462 updater->DeleteResource(resource_it);
462 return; 463 return;
463 } 464 }
464 465
465 --resource_it->ref_count; 466 --resource_it->ref_count;
466 DCHECK_GE(resource_it->ref_count, 0); 467 DCHECK_GE(resource_it->ref_count, 0);
467 } 468 }
468 469
469 } // namespace cc 470 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698