summaryrefslogtreecommitdiff
path: root/chromium/components/viz/common/resources/platform_color.h
blob: 5a6caba510d309662ee0916bafdad919906e8b4a (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2011 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.

#ifndef COMPONENTS_VIZ_COMMON_RESOURCES_PLATFORM_COLOR_H_
#define COMPONENTS_VIZ_COMMON_RESOURCES_PLATFORM_COLOR_H_

#include "base/logging.h"
#include "base/macros.h"
#include "components/viz/common/resources/resource_format.h"
#include "third_party/skia/include/core/SkTypes.h"

namespace viz {

class PlatformColor {
 public:
  enum SourceDataFormat { SOURCE_FORMAT_RGBA8, SOURCE_FORMAT_BGRA8 };

  static SourceDataFormat Format() {
    return SK_B32_SHIFT ? SOURCE_FORMAT_RGBA8 : SOURCE_FORMAT_BGRA8;
  }

  // Returns the most efficient texture format for this platform.
  static ResourceFormat BestTextureFormat() {
    switch (Format()) {
      case SOURCE_FORMAT_BGRA8:
        return BGRA_8888;
      case SOURCE_FORMAT_RGBA8:
        return RGBA_8888;
    }
    NOTREACHED();
    return RGBA_8888;
  }

  // Returns the most efficient supported texture format for this platform.
  static ResourceFormat BestSupportedTextureFormat(bool supports_bgra8888) {
    switch (Format()) {
      case SOURCE_FORMAT_BGRA8:
        return (supports_bgra8888) ? BGRA_8888 : RGBA_8888;
      case SOURCE_FORMAT_RGBA8:
        return RGBA_8888;
    }
    NOTREACHED();
    return RGBA_8888;
  }

  // Return true if the given 32bpp resource format has the same component order
  // as the platform color data format.
  static bool SameComponentOrder(ResourceFormat format) {
    switch (format) {
      case RGBA_8888:
        return Format() == SOURCE_FORMAT_RGBA8;
      case BGRA_8888:
        return Format() == SOURCE_FORMAT_BGRA8;
      case ALPHA_8:
      case LUMINANCE_8:
      case RGB_565:
      case RGBA_4444:
      case ETC1:
      case RED_8:
      case LUMINANCE_F16:
      case RGBA_F16:
      case R16_EXT:
        NOTREACHED();
        return false;
    }

    NOTREACHED();
    return false;
  }

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor);
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_COMMON_RESOURCES_PLATFORM_COLOR_H_