| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/texture.h" | 7 #include "cc/texture.h" |
| 8 #include "third_party/khronos/GLES2/gl2ext.h" |
| 8 | 9 |
| 9 namespace cc { | 10 namespace cc { |
| 10 | 11 |
| 11 void CCTexture::setDimensions(const IntSize& size, GLenum format) | 12 void CCTexture::setDimensions(const IntSize& size, GLenum format) |
| 12 { | 13 { |
| 13 m_size = size; | 14 m_size = size; |
| 14 m_format = format; | 15 m_format = format; |
| 15 } | 16 } |
| 16 | 17 |
| 17 size_t CCTexture::bytes() const | 18 size_t CCTexture::bytes() const |
| 18 { | 19 { |
| 19 if (m_size.isEmpty()) | 20 if (m_size.isEmpty()) |
| 20 return 0u; | 21 return 0u; |
| 21 | 22 |
| 22 return memorySizeBytes(m_size, m_format); | 23 return memorySizeBytes(m_size, m_format); |
| 23 } | 24 } |
| 24 | 25 |
| 26 size_t CCTexture::bytesPerPixel(GLenum format) |
| 27 { |
| 28 unsigned int componentsPerPixel = 0; |
| 29 unsigned int bytesPerComponent = 1; |
| 30 switch (format) { |
| 31 case GL_RGBA: |
| 32 case GL_BGRA_EXT: |
| 33 componentsPerPixel = 4; |
| 34 break; |
| 35 case GL_LUMINANCE: |
| 36 componentsPerPixel = 1; |
| 37 break; |
| 38 default: |
| 39 NOTREACHED(); |
| 40 } |
| 41 return componentsPerPixel * bytesPerComponent; |
| 42 } |
| 43 |
| 25 size_t CCTexture::memorySizeBytes(const IntSize& size, GLenum format) | 44 size_t CCTexture::memorySizeBytes(const IntSize& size, GLenum format) |
| 26 { | 45 { |
| 27 unsigned int componentsPerPixel = 4; | 46 return bytesPerPixel(format) * size.width() * size.height(); |
| 28 unsigned int bytesPerComponent = 1; | |
| 29 return componentsPerPixel * bytesPerComponent * size.width() * size.height()
; | |
| 30 } | 47 } |
| 31 | 48 |
| 32 } | 49 } |
| OLD | NEW |