summaryrefslogtreecommitdiffstats
path: root/cc/resources/resource.cc
blob: 192eaebddc6d0c09fbf35619c8605f3144dff4ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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 "cc/resources/resource.h"
#include "third_party/khronos/GLES2/gl2ext.h"

namespace cc {

size_t Resource::bytes() const {
  if (size_.IsEmpty())
    return 0;

  return MemorySizeBytes(size_, format_);
}

size_t Resource::BytesPerPixel(GLenum format) {
  size_t components_per_pixel = 0;
  size_t bytes_per_component = 1;
  switch (format) {
    case GL_RGBA:
    case GL_BGRA_EXT:
      components_per_pixel = 4;
      break;
    case GL_LUMINANCE:
      components_per_pixel = 1;
      break;
    default:
      NOTREACHED();
  }
  return components_per_pixel * bytes_per_component;
}

size_t Resource::MemorySizeBytes(gfx::Size size, GLenum format) {
  return BytesPerPixel(format) * size.width() * size.height();
}


}  // namespace cc