OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resource.h" | 5 #include "cc/resources/resource.h" |
6 #include "third_party/khronos/GLES2/gl2ext.h" | |
7 | 6 |
8 namespace cc { | 7 namespace cc { |
9 | 8 |
10 size_t Resource::bytes() const { | 9 size_t Resource::bytes() const { |
11 if (size_.IsEmpty()) | 10 if (size_.IsEmpty()) |
12 return 0; | 11 return 0; |
13 | 12 |
14 return MemorySizeBytes(size_, format_); | 13 return MemorySizeBytes(size_, format_); |
15 } | 14 } |
16 | 15 |
17 size_t Resource::BytesPerPixel(GLenum format) { | 16 size_t Resource::MemorySizeBytes(gfx::Size size, ResourceFormat format) { |
18 size_t components_per_pixel = 0; | 17 return ResourceProvider::BytesPerPixel(format) * size.width() * size.height(); |
19 size_t bytes_per_component = 1; | |
20 switch (format) { | |
21 case GL_RGBA: | |
22 case GL_BGRA_EXT: | |
23 components_per_pixel = 4; | |
24 break; | |
25 case GL_LUMINANCE: | |
26 components_per_pixel = 1; | |
27 break; | |
28 default: | |
29 NOTREACHED(); | |
30 } | |
31 return components_per_pixel * bytes_per_component; | |
32 } | 18 } |
33 | 19 |
34 size_t Resource::MemorySizeBytes(gfx::Size size, GLenum format) { | |
35 return BytesPerPixel(format) * size.width() * size.height(); | |
36 } | |
37 | |
38 | |
39 } // namespace cc | 20 } // namespace cc |
OLD | NEW |