diff options
author | reveman@google.com <reveman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 17:32:33 +0000 |
---|---|---|
committer | reveman@google.com <reveman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 17:32:33 +0000 |
commit | f7685bc23afff59c963f9967b162b75b0c3f2580 (patch) | |
tree | cf7f76b7d3d4d7e5998327ca231a9353ce6dc351 /cc/resource.cc | |
parent | 1c2433bde9f8b41c9eeaec06232d3905ecc95e40 (diff) | |
download | chromium_src-f7685bc23afff59c963f9967b162b75b0c3f2580.zip chromium_src-f7685bc23afff59c963f9967b162b75b0c3f2580.tar.gz chromium_src-f7685bc23afff59c963f9967b162b75b0c3f2580.tar.bz2 |
cc: Rename Texture class to Resource.
Renames Texture to Resource and ScopedTexture to ScopedResource.
BUG=
TEST=cc_unittests
Review URL: https://codereview.chromium.org/11377055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resource.cc')
-rw-r--r-- | cc/resource.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cc/resource.cc b/cc/resource.cc new file mode 100644 index 0000000..0995793 --- /dev/null +++ b/cc/resource.cc @@ -0,0 +1,49 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#include "cc/resource.h" +#include "third_party/khronos/GLES2/gl2ext.h" + +namespace cc { + +void Resource::setDimensions(const gfx::Size& size, GLenum format) +{ + m_size = size; + m_format = format; +} + +size_t Resource::bytes() const +{ + if (m_size.IsEmpty()) + return 0u; + + return memorySizeBytes(m_size, m_format); +} + +size_t Resource::bytesPerPixel(GLenum format) +{ + unsigned int componentsPerPixel = 0; + unsigned int bytesPerComponent = 1; + switch (format) { + case GL_RGBA: + case GL_BGRA_EXT: + componentsPerPixel = 4; + break; + case GL_LUMINANCE: + componentsPerPixel = 1; + break; + default: + NOTREACHED(); + } + return componentsPerPixel * bytesPerComponent; +} + +size_t Resource::memorySizeBytes(const gfx::Size& size, GLenum format) +{ + return bytesPerPixel(format) * size.width() * size.height(); +} + +} // namespace cc |