Chromium Code Reviews| Index: cc/resources/resource_util.h |
| diff --git a/cc/resources/resource_util.h b/cc/resources/resource_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33f916bd592fa566f679e6377b0b370af823c10f |
| --- /dev/null |
| +++ b/cc/resources/resource_util.h |
| @@ -0,0 +1,40 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_RESOURCES_RESOURCE_UTIL_H_ |
| +#define CC_RESOURCES_RESOURCE_UTIL_H_ |
| + |
| +#include "cc/base/cc_export.h" |
| +#include "cc/resources/resource_format.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace cc { |
| + |
| +class CC_EXPORT ResourceUtil { |
| + public: |
| + // Dies with a CRASH() if the size can not be represented as a positive number |
| + // of bytes. |
| + static int CheckedSizeInBytes(const gfx::Size& size, ResourceFormat format); |
|
vmpstr
2015/07/22 18:05:55
It's a bit awkward that the Checked version return
prashant.n
2015/07/23 05:27:10
I thought of adding following code; but it has a d
vmpstr
2015/07/23 17:56:27
What about the following?
template <typename T>
T
|
| + // Returns the width in bytes but may overflow or return 0. Only do this for |
| + // computing widths for sizes that have already been checked. |
| + static size_t UncheckedWidthInBytes(size_t width, ResourceFormat format); |
| + static size_t UncheckedWidthInBytesAligned(size_t width, |
| + ResourceFormat format); |
| + // Returns the size in bytes but may overflow or return 0. Only do this for |
| + // sizes that have already been checked. |
| + static size_t UncheckedSizeInBytes(const gfx::Size& size, |
| + ResourceFormat format); |
| + static size_t UncheckedSizeInBytesAligned(const gfx::Size& size, |
| + ResourceFormat format); |
| + // Return true if the call to size in bytes would return a value that fits in |
| + // a size_t. |
| + static bool VerifySizeInBytes(const gfx::Size& size, ResourceFormat format); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ResourceUtil); |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_RESOURCES_RESOURCE_UTIL_H_ |