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" | 6 #include "third_party/khronos/GLES2/gl2ext.h" |
7 | 7 |
8 namespace cc { | 8 namespace cc { |
9 | 9 |
10 size_t Resource::bytes() const { | 10 size_t Resource::bytes() const { |
11 if (size_.IsEmpty()) | 11 if (size_.IsEmpty()) |
12 return 0; | 12 return 0; |
13 | 13 |
14 return MemorySizeBytes(size_, format_); | 14 return MemorySizeBytes(size_, format_, is_16_bit_resource_); |
vangelis
2013/09/10 01:52:19
It would be cleaner if this parameter was a bytes_
kaanb
2013/09/11 04:01:52
I changed it to be the texture type.
| |
15 } | 15 } |
16 | 16 |
17 size_t Resource::BytesPerPixel(GLenum format) { | 17 size_t Resource::BytesPerPixel(GLenum format, bool is_16_bit_resource) { |
18 size_t components_per_pixel = 0; | 18 size_t components_per_pixel = 0; |
19 size_t bytes_per_component = 1; | 19 size_t bytes_per_component = 1; |
20 switch (format) { | 20 switch (format) { |
21 case GL_RGBA: | 21 case GL_RGBA: |
22 components_per_pixel = (is_16_bit_resource) ? 2 : 4; | |
vangelis
2013/09/10 01:52:19
I think what you want to change here is the bytes_
kaanb
2013/09/11 04:01:52
Yes, moved this method to ResourceProvider and I r
| |
23 break; | |
22 case GL_BGRA_EXT: | 24 case GL_BGRA_EXT: |
23 components_per_pixel = 4; | 25 components_per_pixel = 4; |
24 break; | 26 break; |
25 case GL_LUMINANCE: | 27 case GL_LUMINANCE: |
26 components_per_pixel = 1; | 28 components_per_pixel = 1; |
27 break; | 29 break; |
28 default: | 30 default: |
29 NOTREACHED(); | 31 NOTREACHED(); |
30 } | 32 } |
31 return components_per_pixel * bytes_per_component; | 33 return components_per_pixel * bytes_per_component; |
32 } | 34 } |
33 | 35 |
34 size_t Resource::MemorySizeBytes(gfx::Size size, GLenum format) { | 36 size_t Resource::MemorySizeBytes( |
35 return BytesPerPixel(format) * size.width() * size.height(); | 37 gfx::Size size, GLenum format, bool is_16_bit_resource) { |
38 return | |
39 BytesPerPixel(format, is_16_bit_resource) * size.width() * size.height(); | |
36 } | 40 } |
37 | 41 |
38 | 42 |
39 } // namespace cc | 43 } // namespace cc |
OLD | NEW |