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 3 // found in the LICENSE file. 4 5 #include "cc/resources/resource.h" 6 #include "third_party/khronos/GLES2/gl2ext.h" 7 8 namespace cc { 9 10 size_t Resource::bytes() const { 11 if (size_.IsEmpty()) 12 return 0; 13 14 return MemorySizeBytes(size_, format_); 15 } 16 17 size_t Resource::BytesPerPixel(GLenum format) { 18 size_t components_per_pixel = 0; 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 } 33 34 size_t Resource::MemorySizeBytes(gfx::Size size, GLenum format) { 35 return BytesPerPixel(format) * size.width() * size.height(); 36 } 37 38 39 } // namespace cc 40