| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_RESOURCES_PLATFORM_COLOR_H_ | 5 #ifndef CC_RESOURCES_PLATFORM_COLOR_H_ |
| 6 #define CC_RESOURCES_PLATFORM_COLOR_H_ | 6 #define CC_RESOURCES_PLATFORM_COLOR_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/resources/resource_provider.h" |
| 10 #include "third_party/khronos/GLES2/gl2.h" | 11 #include "third_party/khronos/GLES2/gl2.h" |
| 11 #include "third_party/khronos/GLES2/gl2ext.h" | 12 #include "third_party/khronos/GLES2/gl2ext.h" |
| 12 #include "third_party/skia/include/core/SkTypes.h" | 13 #include "third_party/skia/include/core/SkTypes.h" |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 | 16 |
| 16 class PlatformColor { | 17 class PlatformColor { |
| 17 public: | 18 public: |
| 18 enum SourceDataFormat { | 19 enum SourceDataFormat { |
| 19 SOURCE_FORMAT_RGBA8, | 20 SOURCE_FORMAT_RGBA8, |
| 20 SOURCE_FORMAT_BGRA8 | 21 SOURCE_FORMAT_BGRA8 |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 static SourceDataFormat Format() { | 24 static SourceDataFormat Format() { |
| 24 return SK_B32_SHIFT ? SOURCE_FORMAT_RGBA8 : SOURCE_FORMAT_BGRA8; | 25 return SK_B32_SHIFT ? SOURCE_FORMAT_RGBA8 : SOURCE_FORMAT_BGRA8; |
| 25 } | 26 } |
| 26 | 27 |
| 27 // Returns the most efficient texture format for this platform. | 28 // Returns the most efficient texture format for this platform. |
| 28 static GLenum BestTextureFormat(bool supports_bgra8888) { | 29 static ResourceProvider::TextureFormat BestTextureFormat( |
| 30 bool supports_bgra8888) { |
| 29 switch (Format()) { | 31 switch (Format()) { |
| 30 case SOURCE_FORMAT_BGRA8: | 32 case SOURCE_FORMAT_BGRA8: |
| 31 if (supports_bgra8888) | 33 return (supports_bgra8888) ? |
| 32 return GL_BGRA_EXT; | 34 ResourceProvider::BGRA_8888 : ResourceProvider::RGBA_8888; |
| 33 return GL_RGBA; | |
| 34 case SOURCE_FORMAT_RGBA8: | 35 case SOURCE_FORMAT_RGBA8: |
| 35 return GL_RGBA; | 36 return ResourceProvider::RGBA_8888; |
| 36 } | 37 } |
| 37 NOTREACHED(); | 38 NOTREACHED(); |
| 38 return GL_RGBA; | 39 return ResourceProvider::RGBA_8888; |
| 39 } | 40 } |
| 40 | 41 |
| 41 // Return true if the given texture format has the same component order | 42 // Return true if the given texture format has the same component order |
| 42 // as the color on this platform. | 43 // as the color on this platform. |
| 43 static bool SameComponentOrder(GLenum texture_format) { | 44 static bool SameComponentOrder(ResourceProvider::TextureFormat format) { |
| 44 switch (Format()) { | 45 switch (Format()) { |
| 45 case SOURCE_FORMAT_RGBA8: | 46 case SOURCE_FORMAT_RGBA8: |
| 46 return texture_format == GL_RGBA; | 47 return format == ResourceProvider::RGBA_8888 || |
| 48 format == ResourceProvider::RGBA_4444; |
| 47 case SOURCE_FORMAT_BGRA8: | 49 case SOURCE_FORMAT_BGRA8: |
| 48 return texture_format == GL_BGRA_EXT; | 50 return format == ResourceProvider::BGRA_8888; |
| 49 } | 51 } |
| 50 NOTREACHED(); | 52 NOTREACHED(); |
| 51 return false; | 53 return false; |
| 52 } | 54 } |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor); | 57 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 } // namespace cc | 60 } // namespace cc |
| 59 | 61 |
| 60 #endif // CC_RESOURCES_PLATFORM_COLOR_H_ | 62 #endif // CC_RESOURCES_PLATFORM_COLOR_H_ |
| OLD | NEW |