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

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

Issue 1202843008: cc: Fix BytesPerPixel issue and refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving few functions to their own files. Created 5 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/resource_util.h"
6
7 #include "base/numerics/safe_math.h"
8 #include "cc/base/math_util.h"
9
10 namespace cc {
11
12 // static
13 bool ResourceUtil::VerifySizeInBytes(const gfx::Size& size,
14 ResourceFormat format) {
15 base::CheckedNumeric<size_t> checked_value = BitsPerPixel(format);
16 checked_value *= size.width();
17 checked_value *= size.height();
18 if (!checked_value.IsValid())
19 return false;
20 size_t value = checked_value.ValueOrDie();
21 if ((value % 8) != 0)
22 return false;
23 return true;
24 }
25
26 // static
27 size_t ResourceUtil::CheckedMemorySizeBytes(const gfx::Size& size,
28 ResourceFormat format) {
29 DCHECK(VerifySizeInBytes(size, format));
30 base::CheckedNumeric<size_t> checked_value = BitsPerPixel(format);
31 checked_value *= size.width();
32 checked_value *= size.height();
33 checked_value /= 8;
34 return checked_value.ValueOrDie();
35 }
36
37 // static
38 size_t ResourceUtil::UncheckedMemorySizeBytes(const gfx::Size& size,
39 ResourceFormat format) {
40 DCHECK(VerifySizeInBytes(size, format));
41 size_t bytes_per_row =
42 size.width() * static_cast<size_t>(BitsPerPixel(format)) / 8;
43 return size.height() * bytes_per_row;
44 }
45
46 // static
47 size_t ResourceUtil::UncheckedMemorySizeBytesAligned(const gfx::Size& size,
48 ResourceFormat format) {
49 DCHECK(VerifySizeInBytes(size, format));
50 size_t bytes_per_row =
51 size.width() * static_cast<size_t>(BitsPerPixel(format)) / 8;
52 // Use 4-byte row alignment (OpenGL default) for upload performance.
53 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
54 bytes_per_row = MathUtil::RoundUp<size_t>(bytes_per_row, 4u);
55 return size.height() * bytes_per_row;
56 }
57
58 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698