Chromium Code Reviews| 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/resource.h" | 5 #include "cc/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 void Resource::setDimensions(const gfx::Size& size, GLenum format) | 10 void Resource::set_dimensions(const gfx::Size& size, GLenum format) { |
| 11 { | 11 size_ = size; |
| 12 m_size = size; | 12 format_ = format; |
| 13 m_format = format; | |
| 14 } | 13 } |
| 15 | 14 |
| 16 size_t Resource::bytes() const | 15 size_t Resource::bytes() const { |
| 17 { | 16 if (size_.IsEmpty()) |
| 18 if (m_size.IsEmpty()) | 17 return 0; |
| 19 return 0u; | |
| 20 | 18 |
| 21 return memorySizeBytes(m_size, m_format); | 19 return MemorySizeBytes(size_, format_); |
| 22 } | 20 } |
| 23 | 21 |
| 24 size_t Resource::bytesPerPixel(GLenum format) | 22 size_t Resource::BytesPerPixel(GLenum format) { |
| 25 { | 23 size_t components_per_pixel = 0; |
| 26 unsigned int componentsPerPixel = 0; | 24 size_t bytes_per_component = 1; |
| 27 unsigned int bytesPerComponent = 1; | 25 switch (format) { |
| 28 switch (format) { | |
| 29 case GL_RGBA: | 26 case GL_RGBA: |
| 30 case GL_BGRA_EXT: | 27 case GL_BGRA_EXT: |
| 31 componentsPerPixel = 4; | 28 components_per_pixel = 4; |
| 32 break; | 29 break; |
| 33 case GL_LUMINANCE: | 30 case GL_LUMINANCE: |
| 34 componentsPerPixel = 1; | 31 components_per_pixel = 1; |
| 35 break; | 32 break; |
| 36 default: | 33 default: |
| 37 NOTREACHED(); | 34 NOTREACHED(); |
| 38 } | 35 } |
| 39 return componentsPerPixel * bytesPerComponent; | 36 return components_per_pixel * bytes_per_component; |
| 40 } | 37 } |
| 41 | 38 |
| 42 size_t Resource::memorySizeBytes(const gfx::Size& size, GLenum format) | 39 size_t Resource::MemorySizeBytes(const gfx::Size& size, GLenum format) { |
| 43 { | 40 return BytesPerPixel(format) * size.width() * size.height(); |
| 44 return bytesPerPixel(format) * size.width() * size.height(); | |
| 45 } | 41 } |
| 46 | 42 |
| 43 | |
|
jamesr
2012/11/15 23:40:09
do you need two blank lines before the "} // name
tfarina
2012/11/15 23:42:13
No. Please, just one.
| |
| 47 } // namespace cc | 44 } // namespace cc |
| OLD | NEW |