Home | History | Annotate | Download | only in resources
      1 // Copyright 2011 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 #ifndef CC_RESOURCES_PLATFORM_COLOR_H_
      6 #define CC_RESOURCES_PLATFORM_COLOR_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/logging.h"
     10 #include "third_party/khronos/GLES2/gl2.h"
     11 #include "third_party/khronos/GLES2/gl2ext.h"
     12 #include "third_party/skia/include/core/SkTypes.h"
     13 
     14 namespace cc {
     15 
     16 class PlatformColor {
     17  public:
     18   enum SourceDataFormat {
     19     SOURCE_FORMAT_RGBA8,
     20     SOURCE_FORMAT_BGRA8
     21   };
     22 
     23   static SourceDataFormat Format() {
     24     return SK_B32_SHIFT ? SOURCE_FORMAT_RGBA8 : SOURCE_FORMAT_BGRA8;
     25   }
     26 
     27   // Returns the most efficient texture format for this platform.
     28   static GLenum BestTextureFormat(bool supports_bgra8888) {
     29     GLenum texture_format = GL_RGBA;
     30     switch (Format()) {
     31       case SOURCE_FORMAT_RGBA8:
     32         break;
     33       case SOURCE_FORMAT_BGRA8:
     34         if (supports_bgra8888)
     35           texture_format = GL_BGRA_EXT;
     36         break;
     37       default:
     38         NOTREACHED();
     39         break;
     40     }
     41     return texture_format;
     42   }
     43 
     44   // Return true if the given texture format has the same component order
     45   // as the color on this platform.
     46   static bool SameComponentOrder(GLenum texture_format) {
     47     switch (Format()) {
     48       case SOURCE_FORMAT_RGBA8:
     49         return texture_format == GL_RGBA;
     50       case SOURCE_FORMAT_BGRA8:
     51         return texture_format == GL_BGRA_EXT;
     52       default:
     53         NOTREACHED();
     54         return false;
     55     }
     56   }
     57 
     58  private:
     59   DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor);
     60 };
     61 
     62 }  // namespace cc
     63 
     64 #endif  // CC_RESOURCES_PLATFORM_COLOR_H_
     65