Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: include/gpu/GrColor.h

Issue 211683002: Add discard API to SkCanvas, plumb it to glDiscardFramebuffer() (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: move to ToT Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkCanvas.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
11 #ifndef GrColor_DEFINED 11 #ifndef GrColor_DEFINED
12 #define GrColor_DEFINED 12 #define GrColor_DEFINED
13 13
14 #include "GrTypes.h" 14 #include "GrTypes.h"
15 15
16 /** 16 /**
17 * GrColor is 4 bytes for R, G, B, A, in a compile-time specific order. The 17 * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. The com ponents are stored
18 * components are stored premultiplied. 18 * premultiplied.
19 */ 19 */
20 typedef uint32_t GrColor; 20 typedef uint32_t GrColor;
21 21
22
23 // shift amount to assign a component to a GrColor int 22 // shift amount to assign a component to a GrColor int
24 // These shift values are chosen for compatibility with GL attrib arrays 23 // These shift values are chosen for compatibility with GL attrib arrays
25 // ES doesn't allow BGRA vertex attrib order so if they were not in this order 24 // ES doesn't allow BGRA vertex attrib order so if they were not in this order
26 // we'd have to swizzle in shaders. Note the assumption that the cpu is little 25 // we'd have to swizzle in shaders.
27 // endian. 26 #ifdef SK_CPU_BENDIAN
28 #define GrColor_SHIFT_R 0 27 #define GrColor_SHIFT_R 24
29 #define GrColor_SHIFT_G 8 28 #define GrColor_SHIFT_G 16
30 #define GrColor_SHIFT_B 16 29 #define GrColor_SHIFT_B 8
31 #define GrColor_SHIFT_A 24 30 #define GrColor_SHIFT_A 0
31 #else
32 #define GrColor_SHIFT_R 0
33 #define GrColor_SHIFT_G 8
34 #define GrColor_SHIFT_B 16
35 #define GrColor_SHIFT_A 24
36 #endif
32 37
33 /** 38 /**
34 * Pack 4 components (RGBA) into a GrColor int 39 * Pack 4 components (RGBA) into a GrColor int
35 */ 40 */
36 static inline GrColor GrColorPackRGBA(unsigned r, unsigned g, 41 static inline GrColor GrColorPackRGBA(unsigned r, unsigned g,
37 unsigned b, unsigned a) { 42 unsigned b, unsigned a) {
38 SkASSERT((uint8_t)r == r); 43 SkASSERT((uint8_t)r == r);
39 SkASSERT((uint8_t)g == g); 44 SkASSERT((uint8_t)g == g);
40 SkASSERT((uint8_t)b == b); 45 SkASSERT((uint8_t)b == b);
41 SkASSERT((uint8_t)a == a); 46 SkASSERT((uint8_t)a == a);
42 return (r << GrColor_SHIFT_R) | 47 return (r << GrColor_SHIFT_R) |
43 (g << GrColor_SHIFT_G) | 48 (g << GrColor_SHIFT_G) |
44 (b << GrColor_SHIFT_B) | 49 (b << GrColor_SHIFT_B) |
45 (a << GrColor_SHIFT_A); 50 (a << GrColor_SHIFT_A);
46 } 51 }
47 52
48 // extract a component (byte) from a GrColor int 53 // extract a component (byte) from a GrColor int
49 54
50 #define GrColorUnpackR(color) (((color) >> GrColor_SHIFT_R) & 0xFF) 55 #define GrColorUnpackR(color) (((color) >> GrColor_SHIFT_R) & 0xFF)
51 #define GrColorUnpackG(color) (((color) >> GrColor_SHIFT_G) & 0xFF) 56 #define GrColorUnpackG(color) (((color) >> GrColor_SHIFT_G) & 0xFF)
52 #define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF) 57 #define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF)
53 #define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF) 58 #define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF)
54 59
55 /** 60 /**
56 * Since premultiplied means that alpha >= color, we construct a color with 61 * Since premultiplied means that alpha >= color, we construct a color with
57 * each component==255 and alpha == 0 to be "illegal" 62 * each component==255 and alpha == 0 to be "illegal"
58 */ 63 */
59 #define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A)) 64 #define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A))
60 65
66 /**
67 * Assert in debug builds that a GrColor is premultiplied.
68 */
69 static inline void GrColorIsPMAssert(GrColor c) {
70 #ifdef SK_DEBUG
71 unsigned a = GrColorUnpackA(c);
72 unsigned r = GrColorUnpackR(c);
73 unsigned g = GrColorUnpackG(c);
74 unsigned b = GrColorUnpackB(c);
75
76 SkASSERT(r <= a);
77 SkASSERT(g <= a);
78 SkASSERT(b <= a);
79 #endif
80 }
81
61 /** Converts a GrColor to an rgba array of GrGLfloat */ 82 /** Converts a GrColor to an rgba array of GrGLfloat */
62 static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) { 83 static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) {
63 static const float ONE_OVER_255 = 1.f / 255.f; 84 static const float ONE_OVER_255 = 1.f / 255.f;
64 rgba[0] = GrColorUnpackR(color) * ONE_OVER_255; 85 rgba[0] = GrColorUnpackR(color) * ONE_OVER_255;
65 rgba[1] = GrColorUnpackG(color) * ONE_OVER_255; 86 rgba[1] = GrColorUnpackG(color) * ONE_OVER_255;
66 rgba[2] = GrColorUnpackB(color) * ONE_OVER_255; 87 rgba[2] = GrColorUnpackB(color) * ONE_OVER_255;
67 rgba[3] = GrColorUnpackA(color) * ONE_OVER_255; 88 rgba[3] = GrColorUnpackA(color) * ONE_OVER_255;
68 } 89 }
69 90
70 /** 91 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); 139 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
119 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); 140 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
120 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); 141 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
121 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); 142 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
122 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); 143 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
123 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); 144 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
124 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); 145 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
125 } 146 }
126 147
127 #endif 148 #endif
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698