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_format.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 ResourceFormat BestTextureFormat(bool supports_bgra8888) { |
29 switch (Format()) { | 30 switch (Format()) { |
30 case SOURCE_FORMAT_BGRA8: | 31 case SOURCE_FORMAT_BGRA8: |
31 if (supports_bgra8888) | 32 return (supports_bgra8888) ? BGRA_8888 : RGBA_8888; |
32 return GL_BGRA_EXT; | |
33 return GL_RGBA; | |
34 case SOURCE_FORMAT_RGBA8: | 33 case SOURCE_FORMAT_RGBA8: |
35 return GL_RGBA; | 34 return RGBA_8888; |
36 } | 35 } |
37 NOTREACHED(); | 36 NOTREACHED(); |
38 return GL_RGBA; | 37 return RGBA_8888; |
39 } | 38 } |
40 | 39 |
41 // Return true if the given texture format has the same component order | 40 // Return true if the given texture format has the same component order |
42 // as the color on this platform. | 41 // as the color on this platform. |
43 static bool SameComponentOrder(GLenum texture_format) { | 42 static bool SameComponentOrder(ResourceFormat format) { |
44 switch (Format()) { | 43 switch (Format()) { |
45 case SOURCE_FORMAT_RGBA8: | 44 case SOURCE_FORMAT_RGBA8: |
46 return texture_format == GL_RGBA; | 45 return format == RGBA_8888 || format == RGBA_4444; |
47 case SOURCE_FORMAT_BGRA8: | 46 case SOURCE_FORMAT_BGRA8: |
48 return texture_format == GL_BGRA_EXT; | 47 return format == BGRA_8888; |
49 } | 48 } |
50 NOTREACHED(); | 49 NOTREACHED(); |
51 return false; | 50 return false; |
52 } | 51 } |
53 | 52 |
54 private: | 53 private: |
55 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor); | 54 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformColor); |
56 }; | 55 }; |
57 | 56 |
58 } // namespace cc | 57 } // namespace cc |
59 | 58 |
60 #endif // CC_RESOURCES_PLATFORM_COLOR_H_ | 59 #endif // CC_RESOURCES_PLATFORM_COLOR_H_ |
OLD | NEW |