1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
10ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrTypes_DEFINED
12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrTypes_DEFINED
13ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
149b24d25c6b7ddde5788444f17fa3bfad19096f37reed@google.com#include "SkTypes.h"
15ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrConfig.h"
16b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com#include "SkMath.h"
17ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
18972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org//#define SK_SUPPORT_LEGACY_GRTYPES
19972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
20fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com////////////////////////////////////////////////////////////////////////////////
21fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
22fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/**
23fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Defines overloaded bitwise operators to make it easier to use an enum as a
24fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * bitfield.
25fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */
26fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com#define GR_MAKE_BITFIELD_OPS(X) \
2786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    inline X operator | (X a, X b) { \
28fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com        return (X) (+a | +b); \
29fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    } \
30fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    \
3186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    inline X operator & (X a, X b) { \
32fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com        return (X) (+a & +b); \
33fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    } \
34fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    template <typename T> \
3586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    inline X operator & (T a, X b) { \
36fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com        return (X) (+a & +b); \
37fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    } \
38fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    template <typename T> \
3986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    inline X operator & (X a, T b) { \
40fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com        return (X) (+a & +b); \
41fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    } \
42fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
4386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com#define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
4486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    friend X operator | (X a, X b); \
4586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    \
4686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    friend X operator & (X a, X b); \
4786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    \
4886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    template <typename T> \
4986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    friend X operator & (T a, X b); \
5086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    \
5186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    template <typename T> \
5286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com    friend X operator & (X a, T b); \
53fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com////////////////////////////////////////////////////////////////////////////////
54fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
55972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GRTYPES
56fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
57ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
58ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  Macro to round n up to the next multiple of 4, or return it unchanged if
59ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  n is already a multiple of 4
60ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
619b24d25c6b7ddde5788444f17fa3bfad19096f37reed@google.com#define GrALIGN4(n)     SkAlign4(n)
6201224d5d0a3228fe47e63d8346e0e433a87563a8tomhudson@google.com#define GrIsALIGN4(n)   SkIsAlign4(n)
63ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
64ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comtemplate <typename T> const T& GrMin(const T& a, const T& b) {
6507ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com    return (a < b) ? a : b;
66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
67ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
68ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comtemplate <typename T> const T& GrMax(const T& a, const T& b) {
6907ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com    return (b < a) ? a : b;
70ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
71ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
72972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org/**
73972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org *  Count elements in an array
74972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org */
75972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#define GR_ARRAY_COUNT(array)  SK_ARRAY_COUNT(array)
76972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
77972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org/**
78972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org *  16.16 fixed point type
79972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org */
80972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.orgtypedef int32_t GrFixed;
81972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
82972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#ifdef SK_DEBUG
83972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
84972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.orgstatic inline int16_t GrToS16(intptr_t x) {
85972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org    SkASSERT((int16_t)x == x);
86972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org    return (int16_t)x;
87972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org}
88972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
89972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#else
90972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
91972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#define GrToS16(x)  x
92972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
93972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#endif
94972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
95972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org#endif
96972f9cd7a063d0544f8c919fd12b9a3adbd12b24commit-bot@chromium.org
97ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com// compile time versions of min/max
98ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b))
99ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a))
100ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
101ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
102ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  divide, rounding up
103ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
104919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.comstatic inline int32_t GrIDivRoundUp(int x, int y) {
105f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org    SkASSERT(y > 0);
106919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com    return (x + (y-1)) / y;
107919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com}
1081c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) {
1091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    return (x + (y-1)) / y;
1101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com}
1114da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.comstatic inline size_t GrSizeDivRoundUp(size_t x, size_t y) {
112ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    return (x + (y-1)) / y;
113ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
114ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
1154da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com// compile time, evaluates Y multiple times
1164da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com#define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y))
1174da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com
118ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
119ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  align up
120ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
1211c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) {
122ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    return GrUIDivRoundUp(x, alignment) * alignment;
123ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
1244da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.comstatic inline size_t GrSizeAlignUp(size_t x, size_t alignment) {
1251c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    return GrSizeDivRoundUp(x, alignment) * alignment;
1261c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com}
127ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
1284da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com// compile time, evaluates A multiple times
1294da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com#define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A))
1304da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com
131ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
132ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * amount of pad needed to align up
133ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
1341c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) {
1351c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    return (alignment - x % alignment) % alignment;
1361c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com}
1374da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.comstatic inline size_t GrSizeAlignUpPad(size_t x, size_t alignment) {
138ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    return (alignment - x % alignment) % alignment;
139ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
140ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
141ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
142ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  align down
143ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
1441c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) {
1451c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com    return (x / alignment) * alignment;
1461c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com}
1475e497329bb40704c468627a4d37148ea4fae4da3bsalomon@google.comstatic inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) {
148ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com    return (x / alignment) * alignment;
149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
150ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
151ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com///////////////////////////////////////////////////////////////////////////////
152ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
153ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
154ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com *  Return the next power of 2 >= n.
155ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */
156ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comstatic inline uint32_t GrNextPow2(uint32_t n) {
157b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com    return n ? (1 << (32 - SkCLZ(n - 1))) : 1;
158ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com}
159ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
160b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.comstatic inline int GrNextPow2(int n) {
161f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org    SkASSERT(n >= 0); // this impl only works for non-neg.
162b9086a026844e4cfd08b219e49ce3f12294cba98bsalomon@google.com    return n ? (1 << (32 - SkCLZ(n - 1))) : 1;
163b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com}
164b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com
165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com///////////////////////////////////////////////////////////////////////////////
166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
167ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
16805ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com * Possible 3D APIs that may be used by Ganesh.
16905ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com */
17016e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comenum GrBackend {
17116e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    kOpenGL_GrBackend,
17205ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com};
17305ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com
17405ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com/**
17516e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * Backend-specific 3D context handle
1760b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com *      GrGLInterface* for OpenGL. If NULL will use the default GL interface.
17705ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com */
17816e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comtypedef intptr_t GrBackendContext;
17905ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com
18005ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com///////////////////////////////////////////////////////////////////////////////
1815877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com
182ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/**
183ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com* Geometric primitives used for drawing.
184ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com*/
185ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.comenum GrPrimitiveType {
18647059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kTriangles_GrPrimitiveType,
18747059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kTriangleStrip_GrPrimitiveType,
18847059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kTriangleFan_GrPrimitiveType,
18947059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kPoints_GrPrimitiveType,
19047059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kLines_GrPrimitiveType,     // 1 pix wide only
19147059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kLineStrip_GrPrimitiveType  // 1 pix wide only
192ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com};
193ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com
1940650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.comstatic inline bool GrIsPrimTypeLines(GrPrimitiveType type) {
19547059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    return kLines_GrPrimitiveType == type || kLineStrip_GrPrimitiveType == type;
1960650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com}
1970650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com
1980650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.comstatic inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
19947059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    return kTriangles_GrPrimitiveType == type     ||
20047059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com           kTriangleStrip_GrPrimitiveType == type ||
20147059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com           kTriangleFan_GrPrimitiveType == type;
2020650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com}
2030650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com
204ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com/**
205ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com * Coeffecients for alpha-blending.
206ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com */
207ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.comenum GrBlendCoeff {
20847059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kInvalid_GrBlendCoeff = -1,
20947059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com
21047059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kZero_GrBlendCoeff,    //<! 0
21147059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kOne_GrBlendCoeff,     //<! 1
21247059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kSC_GrBlendCoeff,      //<! src color
21347059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kISC_GrBlendCoeff,     //<! one minus src color
21447059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kDC_GrBlendCoeff,      //<! dst color
21547059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kIDC_GrBlendCoeff,     //<! one minus dst color
21647059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kSA_GrBlendCoeff,      //<! src alpha
21747059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kISA_GrBlendCoeff,     //<! one minus src alpha
21847059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kDA_GrBlendCoeff,      //<! dst alpha
21947059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kIDA_GrBlendCoeff,     //<! one minus dst alpha
22047059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kConstC_GrBlendCoeff,  //<! constant color
22147059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kIConstC_GrBlendCoeff, //<! one minus constant color
22247059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kConstA_GrBlendCoeff,  //<! constant color alpha
22347059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kIConstA_GrBlendCoeff, //<! one minus constant color alpha
22447059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com
22547059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com    kPublicGrBlendCoeffCount
226ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com};
227ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com
228d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com/**
229759c16e20dc42577226c8805bfea92d8bacb14d8reed@google.com *  Formats for masks, used by the font cache.
230759c16e20dc42577226c8805bfea92d8bacb14d8reed@google.com *  Important that these are 0-based.
23198539c607b05f7e25406ae873bf1b24154a36a6freed@google.com */
23298539c607b05f7e25406ae873bf1b24154a36a6freed@google.comenum GrMaskFormat {
2331eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com    kA8_GrMaskFormat,    //!< 1-byte per pixel
2341eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com    kA565_GrMaskFormat,  //!< 2-bytes per pixel
2351eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com    kA888_GrMaskFormat,  //!< 4-bytes per pixel
236f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    kARGB_GrMaskFormat,  //!< 4-bytes per pixel, color format
23765caeaf32d09f5886f3c740cfef2f1c26ef9cb50skia.committer@gmail.com
238f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    kLast_GrMaskFormat = kARGB_GrMaskFormat
23998539c607b05f7e25406ae873bf1b24154a36a6freed@google.com};
2403fddf0eed6dc2873bcc8e584f435c6cd34964518commit-bot@chromium.orgstatic const int kMaskFormatCount = kLast_GrMaskFormat + 1;
24198539c607b05f7e25406ae873bf1b24154a36a6freed@google.com
24298539c607b05f7e25406ae873bf1b24154a36a6freed@google.com/**
24398539c607b05f7e25406ae873bf1b24154a36a6freed@google.com *  Return the number of bytes-per-pixel for the specified mask format.
24498539c607b05f7e25406ae873bf1b24154a36a6freed@google.com */
24598539c607b05f7e25406ae873bf1b24154a36a6freed@google.comstatic inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
246f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    SkASSERT((unsigned)format <= 3);
247bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com    // kA8   (0) -> 1
248bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com    // kA565 (1) -> 2
249bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com    // kA888 (2) -> 4
2506e515d67d2365ecd05fb80762eeb76c55e81368cskia.committer@gmail.com    // kARGB (3) -> 4
251f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    static const int sBytesPerPixel[] = { 1, 2, 4, 4 };
252f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount, array_size_mismatch);
253f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org
254f8cb184095946ebf8f183d253e27bd544a19f23ccommit-bot@chromium.org    return sBytesPerPixel[(int) format];
25598539c607b05f7e25406ae873bf1b24154a36a6freed@google.com}
25698539c607b05f7e25406ae873bf1b24154a36a6freed@google.com
25798539c607b05f7e25406ae873bf1b24154a36a6freed@google.com/**
258669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * Pixel configurations.
259669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com */
260669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comenum GrPixelConfig {
261669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    kUnknown_GrPixelConfig,
262669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    kAlpha_8_GrPixelConfig,
263669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    kIndex_8_GrPixelConfig,
264669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    kRGB_565_GrPixelConfig,
265c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    /**
266c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com     * Premultiplied
267c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com     */
268c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    kRGBA_4444_GrPixelConfig,
269c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    /**
2700342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * Premultiplied. Byte order is r,g,b,a.
271c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com     */
2720342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com    kRGBA_8888_GrPixelConfig,
273c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    /**
2740342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com     * Premultiplied. Byte order is b,g,r,a.
275c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com     */
2760342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com    kBGRA_8888_GrPixelConfig,
2776e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    /**
2786e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     * ETC1 Compressed Data
2796e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     */
2806e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    kETC1_GrPixelConfig,
2816e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    /**
2826e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     * LATC/RGTC/3Dc/BC4 Compressed Data
2836e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     */
2846e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    kLATC_GrPixelConfig,
2854bcb0c6e0377557d326344f4bd2bbab4e8b1bc3absalomon@google.com
2866e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    kLast_GrPixelConfig = kLATC_GrPixelConfig
287669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com};
288b8eb2e89edf914caf5479baeffcb670d3e93f496bsalomon@google.comstatic const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
289669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com
290fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com// Aliases for pixel configs that match skia's byte order.
291c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#ifndef SK_CPU_LENDIAN
292c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    #error "Skia gpu currently assumes little endian"
293c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#endif
294e4657ed7e1f4ae5b1834b398724c718f21589ca3commit-bot@chromium.org#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
2950342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com    static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
296e4657ed7e1f4ae5b1834b398724c718f21589ca3commit-bot@chromium.org#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
2970342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com    static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
298c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#else
299c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
300c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#endif
301c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com
3026e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org// Returns true if the pixel config is a GPU-specific compressed format
3036e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org// representation.
3046e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.orgstatic inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
3056e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    switch (config) {
3066e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        case kETC1_GrPixelConfig:
3076e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        case kLATC_GrPixelConfig:
3086e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org            return true;
3096e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        default:
3106e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org            return false;
3116e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    }
3126e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org}
3136e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org
3140a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com// Returns true if the pixel config is 32 bits per pixel
3159c68058b679aee81e6e0158e7fcbfb5d8479c91absalomon@google.comstatic inline bool GrPixelConfigIs8888(GrPixelConfig config) {
3160a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com    switch (config) {
3170342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kRGBA_8888_GrPixelConfig:
3180342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kBGRA_8888_GrPixelConfig:
3190a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com            return true;
3200a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com        default:
3210a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com            return false;
3220a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com    }
3230a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com}
3240a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com
3250a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com// Takes a config and returns the equivalent config with the R and B order
3260a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com// swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig
3270a97be216df494291fe929b79d438809af7e9c83bsalomon@google.comstatic inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
3280a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com    switch (config) {
3290342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kBGRA_8888_GrPixelConfig:
3300342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com            return kRGBA_8888_GrPixelConfig;
3310342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kRGBA_8888_GrPixelConfig:
3320342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com            return kBGRA_8888_GrPixelConfig;
3330a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com        default:
3340a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com            return kUnknown_GrPixelConfig;
3350a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com    }
3360a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com}
3370a97be216df494291fe929b79d438809af7e9c83bsalomon@google.com
338669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline size_t GrBytesPerPixel(GrPixelConfig config) {
339669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    switch (config) {
340669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kAlpha_8_GrPixelConfig:
341669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kIndex_8_GrPixelConfig:
342669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return 1;
343669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kRGB_565_GrPixelConfig:
344669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kRGBA_4444_GrPixelConfig:
345669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return 2;
3460342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kRGBA_8888_GrPixelConfig:
3470342a85091fd430c90a142d155dc9642aa729d9ebsalomon@google.com        case kBGRA_8888_GrPixelConfig:
348669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return 4;
349669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        default:
350669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return 0;
351669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    }
352669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com}
353669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com
354669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
355669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    switch (config) {
3566e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        case kETC1_GrPixelConfig:
357669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kRGB_565_GrPixelConfig:
358c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com            return true;
359c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com        default:
360c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com            return false;
361c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com    }
362c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com}
363c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com
364669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
365669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    switch (config) {
366748e9d37dcc7c58ef9010ea0ab78efea6af2a84bkrajcevski        case kLATC_GrPixelConfig:
367669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        case kAlpha_8_GrPixelConfig:
368669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return true;
369669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com        default:
370669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com            return false;
371669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com    }
372669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com}
373669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com
374669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com/**
375fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Optional bitfield flags that can be passed to createTexture.
376fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */
377fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comenum GrTextureFlags {
378fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    kNone_GrTextureFlags            = 0x0,
379fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    /**
380fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * Creates a texture that can be rendered to as a GrRenderTarget. Use
381fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * GrTexture::asRenderTarget() to access.
382fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     */
383fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    kRenderTarget_GrTextureFlagBit  = 0x1,
384fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    /**
385fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * By default all render targets have an associated stencil buffer that
386fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * may be required for path filling. This flag overrides stencil buffer
387fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * creation.
388fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * MAKE THIS PRIVATE?
389fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     */
390fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    kNoStencil_GrTextureFlagBit     = 0x2,
391fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    /**
392fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * Hint that the CPU may modify this texture after creation.
393fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     */
394fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    kDynamicUpdate_GrTextureFlagBit = 0x4,
395d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org    /**
396d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org     * Indicates that all allocations (color buffer, FBO completeness, etc)
397d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org     * should be verified.
398d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org     */
399d0925240efb3732475e62966896716c28e9902b2senorblanco@chromium.org    kCheckAllocation_GrTextureFlagBit  = 0x8,
40015c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com
40115c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com    kDummy_GrTextureFlagBit,
40215c0fea699b25343fe6f49668a5632866e1a0306robertphillips@google.com    kLastPublic_GrTextureFlagBit = kDummy_GrTextureFlagBit-1,
403fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com};
404fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
405fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comGR_MAKE_BITFIELD_OPS(GrTextureFlags)
406fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
407fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comenum {
408fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com   /**
409fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    *  For Index8 pixel config, the colortable must be 256 entries
410fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    */
411fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    kGrColorTableSize = 256 * 4 //sizeof(GrColor)
412fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com};
413fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
414ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org/**
415ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org * Some textures will be stored such that the upper and left edges of the content meet at the
416ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org * the origin (in texture coord space) and for other textures the lower and left edges meet at
4173cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org * the origin. kDefault_GrSurfaceOrigin sets textures to TopLeft, and render targets
4183cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org * to BottomLeft.
419ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org */
420ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org
421ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.orgenum GrSurfaceOrigin {
4223cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org    kDefault_GrSurfaceOrigin,         // DEPRECATED; to be removed
423cf9faf6ce9e3351b4d4030753eb43c8cd2010e0crobertphillips@google.com    kTopLeft_GrSurfaceOrigin,
4243cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org    kBottomLeft_GrSurfaceOrigin,
425ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org};
4265091b7094ba4708451ea73b4fdd8020d8aaa7d23robertphillips@google.com
4275091b7094ba4708451ea73b4fdd8020d8aaa7d23robertphillips@google.com/**
428fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Describes a texture to be created.
429fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */
430fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comstruct GrTextureDesc {
431fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    GrTextureDesc()
43275b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    : fFlags(kNone_GrTextureFlags)
4333cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org    , fOrigin(kDefault_GrSurfaceOrigin)
43475b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    , fWidth(0)
43575b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    , fHeight(0)
43675b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    , fConfig(kUnknown_GrPixelConfig)
4379c2ea846351a29208cb4a36301ee611e7fb384earobertphillips@google.com    , fSampleCnt(0) {
43875b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    }
43975b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com
440fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    GrTextureFlags         fFlags;  //!< bitfield of TextureFlags
4413cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org    GrSurfaceOrigin        fOrigin; //!< origin of the texture
44279d2dbed5a08e0d3f65646d52b4bb884cd0af9b5bsalomon@google.com    int                    fWidth;  //!< Width of the texture
44379d2dbed5a08e0d3f65646d52b4bb884cd0af9b5bsalomon@google.com    int                    fHeight; //!< Height of the texture
44478d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com
445fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com    /**
44607ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com     * Format of source data of the texture. Not guaranteed to be the same as
447fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     * internal format used by 3D API.
448fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com     */
4495bc34f04fe70cdde702ac3bff1fea0ccb275d4a5bsalomon@google.com    GrPixelConfig          fConfig;
450b9014f4f2e6e2bb13f63006cecf34b848d95b0f3bsalomon@google.com
45178d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com    /**
45278d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com     * The number of samples per pixel or 0 to disable full scene AA. This only
45378d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com     * applies if the kRenderTarget_GrTextureFlagBit is set. The actual number
45478d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com     * of samples may not exactly match the request. The request will be rounded
45578d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com     * up to the next supported sample count, or down if it is larger than the
4562d0baded0f45dfde9dc8c25313ff14ea18c0c915bsalomon@google.com     * max supported count.
45778d6cf9f434d3351b19de14f1eab424c23f0ab6dbsalomon@google.com     */
45875b3c9633cb9a594dab0ccf51dab1e694c149a18robertphillips@google.com    int                    fSampleCnt;
4599c2ea846351a29208cb4a36301ee611e7fb384earobertphillips@google.com};
4609c2ea846351a29208cb4a36301ee611e7fb384earobertphillips@google.com
4619c2ea846351a29208cb4a36301ee611e7fb384earobertphillips@google.com/**
4620797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * GrCacheID is used create and find cached GrResources (e.g. GrTextures). The ID has two parts:
4630797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * the domain and the key. Domains simply allow multiple clients to use 0-based indices as their
4640797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * cache key without colliding. The key uniquely identifies a GrResource within the domain.
4650797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com * Users of the cache must obtain a domain via GenerateDomain().
4669c2ea846351a29208cb4a36301ee611e7fb384earobertphillips@google.com */
4670797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.comstruct GrCacheID {
4680797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.compublic:
4690797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    typedef uint8_t  Domain;
4700797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
4710797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    struct Key {
4720797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com        union {
4730797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com            uint8_t  fData8[16];
4740797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com            uint32_t fData32[4];
4750797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com            uint64_t fData64[2];
4760797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com        };
4770797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    };
4784b86e3428b115202e82d49a0914ea8ab6dc25940bsalomon@google.com
4790b6ad2297fbf43466950690102c1c9c150f2a972bsalomon@google.com    /**
4800797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com     * A default cache ID is invalid; a set method must be called before the object is used.
4810b6ad2297fbf43466950690102c1c9c150f2a972bsalomon@google.com     */
4820797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    GrCacheID() { fDomain = kInvalid_Domain; }
4834b86e3428b115202e82d49a0914ea8ab6dc25940bsalomon@google.com
4840b6ad2297fbf43466950690102c1c9c150f2a972bsalomon@google.com    /**
4850797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com     * Initialize the cache ID to a domain and key.
4860b6ad2297fbf43466950690102c1c9c150f2a972bsalomon@google.com     */
4870797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    GrCacheID(Domain domain, const Key& key) {
488f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org        SkASSERT(kInvalid_Domain != domain);
4890797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com        this->reset(domain, key);
4900797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    }
4910797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
4920797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    void reset(Domain domain, const Key& key) {
4930797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com        fDomain = domain;
4940797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com        memcpy(&fKey, &key, sizeof(Key));
4950797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    }
4960797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
4970797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    /** Has this been initialized to a valid domain */
4980797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    bool isValid() const { return kInvalid_Domain != fDomain; }
4990797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
500f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org    const Key& getKey() const { SkASSERT(this->isValid()); return fKey; }
501f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org    Domain getDomain() const { SkASSERT(this->isValid()); return fDomain; }
5022859eb74f9c87471b2429cd12b84144b97157efbskia.committer@gmail.com
5030797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    /** Creates a new unique ID domain. */
5040797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    static Domain GenerateDomain();
5050797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
5060797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.comprivate:
5070797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    Key             fKey;
5080797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    Domain          fDomain;
5090797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com
5100797c2cceadd7dfc2e7f9efa30b611d18efcdcddbsalomon@google.com    static const Domain kInvalid_Domain = 0;
511fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com};
512fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com
513fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/**
514d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Clips are composed from these objects.
515d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com */
516d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.comenum GrClipType {
517d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    kRect_ClipType,
518d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    kPath_ClipType
519d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com};
520d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com
521ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com///////////////////////////////////////////////////////////////////////////////
522ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com
523e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com// opaque type for 3D API object handles
52416e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comtypedef intptr_t GrBackendObject;
525e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
526e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/**
527e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr can wrap an existing texture created by the client with a GrTexture
528e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * object. The client is responsible for ensuring that the texture lives at
529fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * least as long as the GrTexture object wrapping it. We require the client to
530fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * explicitly provide information about the texture, such as width, height,
531e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * and pixel config, rather than querying the 3D APIfor these values. We expect
532e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * these to be immutable even if the 3D API doesn't require this (OpenGL).
533e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com *
534e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Textures that are also render targets are supported as well. Gr will manage
535e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for
536e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr to draw into the render target. To access the render target object
537e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * call GrTexture::asRenderTarget().
538e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com *
539e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * If in addition to the render target flag, the caller also specifies a sample
540e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * count Gr will create an MSAA buffer that resolves into the texture. Gr auto-
541e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * resolves when it reads from the texture. The client can explictly resolve
542e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * using the GrRenderTarget interface.
54332716283420df90644c8b8114308f7967aa91d9frobertphillips@google.com *
54432716283420df90644c8b8114308f7967aa91d9frobertphillips@google.com * Note: These flags currently form a subset of GrTexture's flags.
545e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */
546e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
54716e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comenum GrBackendTextureFlags {
548e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
549e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * No flags enabled
550e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
55116e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    kNone_GrBackendTextureFlag             = kNone_GrTextureFlags,
552e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
553e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * Indicates that the texture is also a render target, and thus should have
554e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * a GrRenderTarget object.
555e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     *
556e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * D3D (future): client must have created the texture with flags that allow
557e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * it to be used as a render target.
558e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
55916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    kRenderTarget_GrBackendTextureFlag     = kRenderTarget_GrTextureFlagBit,
560e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com};
56116e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comGR_MAKE_BITFIELD_OPS(GrBackendTextureFlags)
562e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
56316e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comstruct GrBackendTextureDesc {
56416e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); }
56516e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    GrBackendTextureFlags           fFlags;
566ef5dbe1cd90fe586f165e54cb6f7608942610793senorblanco@chromium.org    GrSurfaceOrigin                 fOrigin;
567e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fWidth;         //<! width in pixels
568e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fHeight;        //<! height in pixels
569e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    GrPixelConfig                   fConfig;        //<! color format
570e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
571e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * If the render target flag is set and sample count is greater than 0
572e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * then Gr will create an MSAA buffer that resolves to the texture.
573e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
574e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fSampleCnt;
575e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
576e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * Handle to the 3D API object.
577e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * OpenGL: Texture ID.
578e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
57916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    GrBackendObject                 fTextureHandle;
580e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com};
581e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
582e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com///////////////////////////////////////////////////////////////////////////////
583e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
584e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/**
585e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr can wrap an existing render target created by the client in the 3D API
586e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * with a GrRenderTarget object. The client is responsible for ensuring that the
587e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * underlying 3D API object lives at least as long as the GrRenderTarget object
588fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * wrapping it. We require the client to explicitly provide information about
589e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * the target, such as width, height, and pixel config rather than querying the
590e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 3D API for these values. We expect these properties to be immutable even if
591e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * the 3D API doesn't require this (OpenGL).
592e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */
593e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
59416e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.comstruct GrBackendRenderTargetDesc {
59516e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); }
596e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fWidth;         //<! width in pixels
597e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fHeight;        //<! height in pixels
598e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    GrPixelConfig                   fConfig;        //<! color format
5993cb406bb88f5aa09cf9f5a9554b4b1314cf1a2eesenorblanco@chromium.org    GrSurfaceOrigin                 fOrigin;        //<! pixel origin
600e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
601e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * The number of samples per pixel. Gr uses this to influence decisions
60216e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com     * about applying other forms of anti-aliasing.
603e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
604e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fSampleCnt;
605e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
606e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * Number of bits of stencil per-pixel.
607e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
608e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    int                             fStencilBits;
609e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com    /**
610e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * Handle to the 3D API object.
611e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     * OpenGL: FBO ID
612e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com     */
61316e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com    GrBackendObject                 fRenderTargetHandle;
614e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com};
615e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com
6160a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com/**
6170a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com * The GrContext's cache of backend context state can be partially invalidated.
6180a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com * These enums are specific to the GL backend and we'd add a new set for an alternative backend.
6190a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com */
6200a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.comenum GrGLBackendState {
6210a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kRenderTarget_GrGLBackendState     = 1 << 0,
6220a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kTextureBinding_GrGLBackendState   = 1 << 1,
6230a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    // View state stands for scissor and viewport
6240a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kView_GrGLBackendState             = 1 << 2,
6250a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kBlend_GrGLBackendState            = 1 << 3,
6260a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kAA_GrGLBackendState               = 1 << 4,
6270a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kVertex_GrGLBackendState           = 1 << 5,
6280a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kStencil_GrGLBackendState          = 1 << 6,
6290a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kPixelStore_GrGLBackendState       = 1 << 7,
6300a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kProgram_GrGLBackendState          = 1 << 8,
63146fbfe0cd1bbe60fd15ce52e784f5d51450ff5fdcommit-bot@chromium.org    kFixedFunction_GrGLBackendState    = 1 << 9,
6320a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kMisc_GrGLBackendState             = 1 << 10,
633c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org    kPathRendering_GrGLBackendState    = 1 << 11,
6340a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com    kALL_GrGLBackendState              = 0xffff
6350a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com};
6360a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com
6370a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com/**
6389c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski * Returns the data size for the given compressed pixel config
6399c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski */
6409c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevskistatic inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
6419c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski                                                int width, int height) {
6429c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski    SkASSERT(GrPixelConfigIsCompressed(config));
6439c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski
6449c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski    switch (config) {
6459c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski        case kLATC_GrPixelConfig:
6469c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski        case kETC1_GrPixelConfig:
6479c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski            SkASSERT((width & 3) == 0);
6489c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski            SkASSERT((height & 3) == 0);
6499c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski            return (width >> 2) * (height >> 2) * 8;
6509c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski
6519c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski        default:
6529c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski            SkFAIL("Unknown compressed pixel config");
6539c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski            return 4 * width * height;
6549c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski    }
6559c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski}
6569c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski
6579c0e629c64c0fa93ac9bf5c2eaa1821370a6fbe5krajcevski/**
6580a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com * This value translates to reseting all the context state for any backend.
6590a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com */
6600a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.comstatic const uint32_t kAll_GrBackendState = 0xffffffff;
6610a208a117b2d7f2c2231aa357f1db4864dbdcba3bsalomon@google.com
66216e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com///////////////////////////////////////////////////////////////////////////////
6635877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com
664ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif
665