• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrTypes_DEFINED
9 #define GrTypes_DEFINED
10 
11 #include "SkMath.h"
12 #include "SkTypes.h"
13 #include "GrConfig.h"
14 
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 /**
18  * Defines overloaded bitwise operators to make it easier to use an enum as a
19  * bitfield.
20  */
21 #define GR_MAKE_BITFIELD_OPS(X) \
22     inline X operator |(X a, X b) { \
23         return (X) (+a | +b); \
24     } \
25     inline X& operator |=(X& a, X b) { \
26         return (a = a | b); \
27     } \
28     inline X operator &(X a, X b) { \
29         return (X) (+a & +b); \
30     } \
31     inline X& operator &=(X& a, X b) { \
32         return (a = a & b); \
33     } \
34     template <typename T> \
35     inline X operator &(T a, X b) { \
36         return (X) (+a & +b); \
37     } \
38     template <typename T> \
39     inline X operator &(X a, T b) { \
40         return (X) (+a & +b); \
41     } \
42 
43 #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
44     friend X operator |(X a, X b); \
45     friend X& operator |=(X& a, X b); \
46     \
47     friend X operator &(X a, X b); \
48     friend X& operator &=(X& a, X b); \
49     \
50     template <typename T> \
51     friend X operator &(T a, X b); \
52     \
53     template <typename T> \
54     friend X operator &(X a, T b); \
55 
56 /**
57  * Wraps a C++11 enum that we use as a bitfield, and enables a limited amount of
58  * masking with type safety. Instantiated with the ~ operator.
59  */
60 template<typename TFlags> class GrTFlagsMask {
61 public:
GrTFlagsMask(TFlags value)62     constexpr explicit GrTFlagsMask(TFlags value) : GrTFlagsMask(static_cast<int>(value)) {}
GrTFlagsMask(int value)63     constexpr explicit GrTFlagsMask(int value) : fValue(value) {}
value()64     constexpr int value() const { return fValue; }
65 private:
66     const int fValue;
67 };
68 
69 // Or-ing a mask always returns another mask.
70 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(GrTFlagsMask<TFlags> a,
71                                                                    GrTFlagsMask<TFlags> b) {
72     return GrTFlagsMask<TFlags>(a.value() | b.value());
73 }
74 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(GrTFlagsMask<TFlags> a,
75                                                                    TFlags b) {
76     return GrTFlagsMask<TFlags>(a.value() | static_cast<int>(b));
77 }
78 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator|(TFlags a,
79                                                                    GrTFlagsMask<TFlags> b) {
80     return GrTFlagsMask<TFlags>(static_cast<int>(a) | b.value());
81 }
82 template<typename TFlags> inline GrTFlagsMask<TFlags>& operator|=(GrTFlagsMask<TFlags>& a,
83                                                                   GrTFlagsMask<TFlags> b) {
84     return (a = a | b);
85 }
86 
87 // And-ing two masks returns another mask; and-ing one with regular flags returns flags.
88 template<typename TFlags> constexpr GrTFlagsMask<TFlags> operator&(GrTFlagsMask<TFlags> a,
89                                                                    GrTFlagsMask<TFlags> b) {
90     return GrTFlagsMask<TFlags>(a.value() & b.value());
91 }
92 template<typename TFlags> constexpr TFlags operator&(GrTFlagsMask<TFlags> a, TFlags b) {
93     return static_cast<TFlags>(a.value() & static_cast<int>(b));
94 }
95 template<typename TFlags> constexpr TFlags operator&(TFlags a, GrTFlagsMask<TFlags> b) {
96     return static_cast<TFlags>(static_cast<int>(a) & b.value());
97 }
98 template<typename TFlags> inline TFlags& operator&=(TFlags& a, GrTFlagsMask<TFlags> b) {
99     return (a = a & b);
100 }
101 
102 /**
103  * Defines bitwise operators that make it possible to use an enum class as a
104  * basic bitfield.
105  */
106 #define GR_MAKE_BITFIELD_CLASS_OPS(X) \
107     constexpr GrTFlagsMask<X> operator~(X a) { \
108         return GrTFlagsMask<X>(~static_cast<int>(a)); \
109     } \
110     constexpr X operator|(X a, X b) { \
111         return static_cast<X>(static_cast<int>(a) | static_cast<int>(b)); \
112     } \
113     inline X& operator|=(X& a, X b) { \
114         return (a = a | b); \
115     } \
116     constexpr bool operator&(X a, X b) { \
117         return SkToBool(static_cast<int>(a) & static_cast<int>(b)); \
118     } \
119 
120 #define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \
121     friend constexpr GrTFlagsMask<X> operator ~(X); \
122     friend constexpr X operator |(X, X); \
123     friend X& operator |=(X&, X); \
124     friend constexpr bool operator &(X, X);
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 
128 // compile time versions of min/max
129 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b))
130 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a))
131 
132 /**
133  *  divide, rounding up
134  */
GrIDivRoundUp(int x,int y)135 static inline int32_t GrIDivRoundUp(int x, int y) {
136     SkASSERT(y > 0);
137     return (x + (y-1)) / y;
138 }
GrUIDivRoundUp(uint32_t x,uint32_t y)139 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) {
140     return (x + (y-1)) / y;
141 }
GrSizeDivRoundUp(size_t x,size_t y)142 static inline size_t GrSizeDivRoundUp(size_t x, size_t y) {
143     return (x + (y-1)) / y;
144 }
145 
146 // compile time, evaluates Y multiple times
147 #define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y))
148 
149 /**
150  *  align up
151  */
GrUIAlignUp(uint32_t x,uint32_t alignment)152 static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) {
153     return GrUIDivRoundUp(x, alignment) * alignment;
154 }
GrSizeAlignUp(size_t x,size_t alignment)155 static inline size_t GrSizeAlignUp(size_t x, size_t alignment) {
156     return GrSizeDivRoundUp(x, alignment) * alignment;
157 }
158 
159 // compile time, evaluates A multiple times
160 #define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A))
161 
162 /**
163  * amount of pad needed to align up
164  */
GrUIAlignUpPad(uint32_t x,uint32_t alignment)165 static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) {
166     return (alignment - x % alignment) % alignment;
167 }
GrSizeAlignUpPad(size_t x,size_t alignment)168 static inline size_t GrSizeAlignUpPad(size_t x, size_t alignment) {
169     return (alignment - x % alignment) % alignment;
170 }
171 
172 /**
173  *  align down
174  */
GrUIAlignDown(uint32_t x,uint32_t alignment)175 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) {
176     return (x / alignment) * alignment;
177 }
GrSizeAlignDown(size_t x,uint32_t alignment)178 static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) {
179     return (x / alignment) * alignment;
180 }
181 
182 ///////////////////////////////////////////////////////////////////////////////
183 
184 /**
185  * Possible 3D APIs that may be used by Ganesh.
186  */
187 enum GrBackend {
188     kMetal_GrBackend,
189     kOpenGL_GrBackend,
190     kVulkan_GrBackend,
191     /**
192      * Mock is a backend that does not draw anything. It is used for unit tests
193      * and to measure CPU overhead.
194      */
195     kMock_GrBackend,
196 };
197 
198 /**
199  * Backend-specific 3D context handle
200  *      OpenGL: const GrGLInterface*. If null will use the result of GrGLCreateNativeInterface().
201  *      Vulkan: GrVkBackendContext*.
202  *      Mock: const GrMockOptions* or null for default constructed GrMockContextOptions.
203  */
204 typedef intptr_t GrBackendContext;
205 
206 ///////////////////////////////////////////////////////////////////////////////
207 
208 /**
209  * Used to control antialiasing in draw calls.
210  */
211 enum class GrAA {
212     kYes,
213     kNo
214 };
215 
GrBoolToAA(bool aa)216 static inline GrAA GrBoolToAA(bool aa) { return aa ? GrAA::kYes : GrAA::kNo; }
217 
218 ///////////////////////////////////////////////////////////////////////////////
219 
220 /**
221 * Geometric primitives used for drawing.
222 */
223 enum class GrPrimitiveType {
224     kTriangles,
225     kTriangleStrip,
226     kTriangleFan,
227     kPoints,
228     kLines,     // 1 pix wide only
229     kLineStrip, // 1 pix wide only
230     kLinesAdjacency // requires geometry shader support.
231 };
232 static constexpr int kNumGrPrimitiveTypes = (int) GrPrimitiveType::kLinesAdjacency + 1;
233 
GrIsPrimTypeLines(GrPrimitiveType type)234 static constexpr bool GrIsPrimTypeLines(GrPrimitiveType type) {
235     return GrPrimitiveType::kLines == type ||
236            GrPrimitiveType::kLineStrip == type ||
237            GrPrimitiveType::kLinesAdjacency == type;
238 }
239 
GrIsPrimTypeTris(GrPrimitiveType type)240 static constexpr bool GrIsPrimTypeTris(GrPrimitiveType type) {
241     return GrPrimitiveType::kTriangles == type     ||
242            GrPrimitiveType::kTriangleStrip == type ||
243            GrPrimitiveType::kTriangleFan == type;
244 }
245 
GrPrimTypeRequiresGeometryShaderSupport(GrPrimitiveType type)246 static constexpr bool GrPrimTypeRequiresGeometryShaderSupport(GrPrimitiveType type) {
247     return GrPrimitiveType::kLinesAdjacency == type;
248 }
249 
250 /**
251  *  Formats for masks, used by the font cache.
252  *  Important that these are 0-based.
253  */
254 enum GrMaskFormat {
255     kA8_GrMaskFormat,    //!< 1-byte per pixel
256     kA565_GrMaskFormat,  //!< 2-bytes per pixel, RGB represent 3-channel LCD coverage
257     kARGB_GrMaskFormat,  //!< 4-bytes per pixel, color format
258 
259     kLast_GrMaskFormat = kARGB_GrMaskFormat
260 };
261 static const int kMaskFormatCount = kLast_GrMaskFormat + 1;
262 
263 /**
264  *  Return the number of bytes-per-pixel for the specified mask format.
265  */
GrMaskFormatBytesPerPixel(GrMaskFormat format)266 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
267     SkASSERT(format < kMaskFormatCount);
268     // kA8   (0) -> 1
269     // kA565 (1) -> 2
270     // kARGB (2) -> 4
271     static const int sBytesPerPixel[] = { 1, 2, 4 };
272     static_assert(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount, "array_size_mismatch");
273     static_assert(kA8_GrMaskFormat == 0, "enum_order_dependency");
274     static_assert(kA565_GrMaskFormat == 1, "enum_order_dependency");
275     static_assert(kARGB_GrMaskFormat == 2, "enum_order_dependency");
276 
277     return sBytesPerPixel[(int) format];
278 }
279 
280 /**
281  * Pixel configurations.
282  */
283 enum GrPixelConfig {
284     kUnknown_GrPixelConfig,
285     kAlpha_8_GrPixelConfig,
286     kGray_8_GrPixelConfig,
287     kRGB_565_GrPixelConfig,
288     /**
289      * Premultiplied
290      */
291     kRGBA_4444_GrPixelConfig,
292     /**
293      * Premultiplied. Byte order is r,g,b,a.
294      */
295     kRGBA_8888_GrPixelConfig,
296     /**
297      * Premultiplied. Byte order is b,g,r,a.
298      */
299     kBGRA_8888_GrPixelConfig,
300     /**
301      * Premultiplied and sRGB. Byte order is r,g,b,a.
302      */
303     kSRGBA_8888_GrPixelConfig,
304     /**
305      * Premultiplied and sRGB. Byte order is b,g,r,a.
306      */
307     kSBGRA_8888_GrPixelConfig,
308     /**
309      * 8 bit signed integers per-channel. Byte order is b,g,r,a.
310      */
311     kRGBA_8888_sint_GrPixelConfig,
312 
313     /**
314      * Byte order is r, g, b, a.  This color format is 32 bits per channel
315      */
316     kRGBA_float_GrPixelConfig,
317     /**
318      * Byte order is r, g.  This color format is 32 bits per channel
319      */
320     kRG_float_GrPixelConfig,
321 
322     /**
323      * This color format is a single 16 bit float channel
324      */
325     kAlpha_half_GrPixelConfig,
326 
327     /**
328     * Byte order is r, g, b, a.  This color format is 16 bits per channel
329     */
330     kRGBA_half_GrPixelConfig,
331 
332     kLast_GrPixelConfig = kRGBA_half_GrPixelConfig
333 };
334 static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
335 
336 // Aliases for pixel configs that match skia's byte order.
337 #ifndef SK_CPU_LENDIAN
338     #error "Skia gpu currently assumes little endian"
339 #endif
340 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
341     static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
342 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
343     static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
344 #else
345     #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
346 #endif
347 
348 // Returns true if the pixel config is 32 bits per pixel
GrPixelConfigIs8888Unorm(GrPixelConfig config)349 static inline bool GrPixelConfigIs8888Unorm(GrPixelConfig config) {
350     switch (config) {
351         case kRGBA_8888_GrPixelConfig:
352         case kBGRA_8888_GrPixelConfig:
353         case kSRGBA_8888_GrPixelConfig:
354         case kSBGRA_8888_GrPixelConfig:
355             return true;
356         case kUnknown_GrPixelConfig:
357         case kAlpha_8_GrPixelConfig:
358         case kGray_8_GrPixelConfig:
359         case kRGB_565_GrPixelConfig:
360         case kRGBA_4444_GrPixelConfig:
361         case kRGBA_8888_sint_GrPixelConfig:
362         case kRGBA_float_GrPixelConfig:
363         case kRG_float_GrPixelConfig:
364         case kAlpha_half_GrPixelConfig:
365         case kRGBA_half_GrPixelConfig:
366             return false;
367     }
368     SkFAIL("Invalid pixel config");
369     return false;
370 }
371 
372 // Returns true if the color (non-alpha) components represent sRGB values. It does NOT indicate that
373 // all three color components are present in the config or anything about their order.
GrPixelConfigIsSRGB(GrPixelConfig config)374 static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) {
375     switch (config) {
376         case kSRGBA_8888_GrPixelConfig:
377         case kSBGRA_8888_GrPixelConfig:
378             return true;
379         case kUnknown_GrPixelConfig:
380         case kAlpha_8_GrPixelConfig:
381         case kGray_8_GrPixelConfig:
382         case kRGB_565_GrPixelConfig:
383         case kRGBA_4444_GrPixelConfig:
384         case kRGBA_8888_GrPixelConfig:
385         case kBGRA_8888_GrPixelConfig:
386         case kRGBA_8888_sint_GrPixelConfig:
387         case kRGBA_float_GrPixelConfig:
388         case kRG_float_GrPixelConfig:
389         case kAlpha_half_GrPixelConfig:
390         case kRGBA_half_GrPixelConfig:
391             return false;
392     }
393     SkFAIL("Invalid pixel config");
394     return false;
395 }
396 
397 // Takes a config and returns the equivalent config with the R and B order
398 // swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig
GrPixelConfigSwapRAndB(GrPixelConfig config)399 static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
400     switch (config) {
401         case kBGRA_8888_GrPixelConfig:
402             return kRGBA_8888_GrPixelConfig;
403         case kRGBA_8888_GrPixelConfig:
404             return kBGRA_8888_GrPixelConfig;
405         case kSBGRA_8888_GrPixelConfig:
406             return kSRGBA_8888_GrPixelConfig;
407         case kSRGBA_8888_GrPixelConfig:
408             return kSBGRA_8888_GrPixelConfig;
409         case kUnknown_GrPixelConfig:
410         case kAlpha_8_GrPixelConfig:
411         case kGray_8_GrPixelConfig:
412         case kRGB_565_GrPixelConfig:
413         case kRGBA_4444_GrPixelConfig:
414         case kRGBA_8888_sint_GrPixelConfig:
415         case kRGBA_float_GrPixelConfig:
416         case kRG_float_GrPixelConfig:
417         case kAlpha_half_GrPixelConfig:
418         case kRGBA_half_GrPixelConfig:
419             return kUnknown_GrPixelConfig;
420     }
421     SkFAIL("Invalid pixel config");
422     return kUnknown_GrPixelConfig;
423 }
424 
GrBytesPerPixel(GrPixelConfig config)425 static inline size_t GrBytesPerPixel(GrPixelConfig config) {
426     switch (config) {
427         case kAlpha_8_GrPixelConfig:
428         case kGray_8_GrPixelConfig:
429             return 1;
430         case kRGB_565_GrPixelConfig:
431         case kRGBA_4444_GrPixelConfig:
432         case kAlpha_half_GrPixelConfig:
433             return 2;
434         case kRGBA_8888_GrPixelConfig:
435         case kBGRA_8888_GrPixelConfig:
436         case kSRGBA_8888_GrPixelConfig:
437         case kSBGRA_8888_GrPixelConfig:
438         case kRGBA_8888_sint_GrPixelConfig:
439             return 4;
440         case kRGBA_half_GrPixelConfig:
441             return 8;
442         case kRGBA_float_GrPixelConfig:
443             return 16;
444         case kRG_float_GrPixelConfig:
445             return 8;
446         case kUnknown_GrPixelConfig:
447             return 0;
448     }
449     SkFAIL("Invalid pixel config");
450     return 0;
451 }
452 
GrPixelConfigIsOpaque(GrPixelConfig config)453 static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
454     switch (config) {
455         case kRGB_565_GrPixelConfig:
456         case kGray_8_GrPixelConfig:
457         case kRG_float_GrPixelConfig:
458             return true;
459         case kAlpha_8_GrPixelConfig:
460         case kRGBA_4444_GrPixelConfig:
461         case kAlpha_half_GrPixelConfig:
462         case kRGBA_8888_GrPixelConfig:
463         case kBGRA_8888_GrPixelConfig:
464         case kSRGBA_8888_GrPixelConfig:
465         case kSBGRA_8888_GrPixelConfig:
466         case kRGBA_8888_sint_GrPixelConfig:
467         case kRGBA_half_GrPixelConfig:
468         case kRGBA_float_GrPixelConfig:
469         case kUnknown_GrPixelConfig:
470             return false;
471     }
472     SkFAIL("Invalid pixel config");
473     return false;
474 }
475 
GrPixelConfigIsAlphaOnly(GrPixelConfig config)476 static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
477     switch (config) {
478         case kAlpha_8_GrPixelConfig:
479         case kAlpha_half_GrPixelConfig:
480             return true;
481         case kUnknown_GrPixelConfig:
482         case kGray_8_GrPixelConfig:
483         case kRGB_565_GrPixelConfig:
484         case kRGBA_4444_GrPixelConfig:
485         case kRGBA_8888_GrPixelConfig:
486         case kBGRA_8888_GrPixelConfig:
487         case kSRGBA_8888_GrPixelConfig:
488         case kSBGRA_8888_GrPixelConfig:
489         case kRGBA_8888_sint_GrPixelConfig:
490         case kRGBA_float_GrPixelConfig:
491         case kRG_float_GrPixelConfig:
492         case kRGBA_half_GrPixelConfig:
493             return false;
494     }
495     SkFAIL("Invalid pixel config.");
496     return false;
497 }
498 
GrPixelConfigIsFloatingPoint(GrPixelConfig config)499 static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
500     switch (config) {
501         case kRGBA_float_GrPixelConfig:
502         case kRG_float_GrPixelConfig:
503         case kAlpha_half_GrPixelConfig:
504         case kRGBA_half_GrPixelConfig:
505             return true;
506         case kUnknown_GrPixelConfig:
507         case kAlpha_8_GrPixelConfig:
508         case kGray_8_GrPixelConfig:
509         case kRGB_565_GrPixelConfig:
510         case kRGBA_4444_GrPixelConfig:
511         case kRGBA_8888_GrPixelConfig:
512         case kBGRA_8888_GrPixelConfig:
513         case kSRGBA_8888_GrPixelConfig:
514         case kSBGRA_8888_GrPixelConfig:
515         case kRGBA_8888_sint_GrPixelConfig:
516             return false;
517     }
518     SkFAIL("Invalid pixel config");
519     return false;
520 }
521 
GrPixelConfigIsSint(GrPixelConfig config)522 static inline bool GrPixelConfigIsSint(GrPixelConfig config) {
523     return config == kRGBA_8888_sint_GrPixelConfig;
524 }
525 
GrPixelConfigIsUnorm(GrPixelConfig config)526 static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
527     switch (config) {
528         case kAlpha_8_GrPixelConfig:
529         case kGray_8_GrPixelConfig:
530         case kRGB_565_GrPixelConfig:
531         case kRGBA_4444_GrPixelConfig:
532         case kRGBA_8888_GrPixelConfig:
533         case kBGRA_8888_GrPixelConfig:
534         case kSRGBA_8888_GrPixelConfig:
535         case kSBGRA_8888_GrPixelConfig:
536             return true;
537         case kUnknown_GrPixelConfig:
538         case kAlpha_half_GrPixelConfig:
539         case kRGBA_8888_sint_GrPixelConfig:
540         case kRGBA_float_GrPixelConfig:
541         case kRG_float_GrPixelConfig:
542         case kRGBA_half_GrPixelConfig:
543             return false;
544     }
545     SkFAIL("Invalid pixel config.");
546     return false;
547 }
548 
549 /**
550  * Optional bitfield flags that can be set on GrSurfaceDesc (below).
551  */
552 enum GrSurfaceFlags {
553     kNone_GrSurfaceFlags = 0x0,
554     /**
555      * Creates a texture that can be rendered to as a GrRenderTarget. Use
556      * GrTexture::asRenderTarget() to access.
557      */
558     kRenderTarget_GrSurfaceFlag = 0x1,
559     /**
560      * Clears to zero on creation. It will cause creation failure if initial data is supplied to the
561      * texture. This only affects the base level if the texture is created with MIP levels.
562      */
563     kPerformInitialClear_GrSurfaceFlag = 0x2
564 };
565 
566 GR_MAKE_BITFIELD_OPS(GrSurfaceFlags)
567 
568 // opaque type for 3D API object handles
569 typedef intptr_t GrBackendObject;
570 
571 /**
572  * Some textures will be stored such that the upper and left edges of the content meet at the
573  * the origin (in texture coord space) and for other textures the lower and left edges meet at
574  * the origin. kDefault_GrSurfaceOrigin sets textures to TopLeft, and render targets
575  * to BottomLeft.
576  */
577 
578 enum GrSurfaceOrigin {
579     kDefault_GrSurfaceOrigin,         // DEPRECATED; to be removed
580     kTopLeft_GrSurfaceOrigin,
581     kBottomLeft_GrSurfaceOrigin,
582 };
583 
584 struct GrMipLevel {
585     const void* fPixels;
586     size_t fRowBytes;
587 };
588 
589 /**
590  * Describes a surface to be created.
591  */
592 struct GrSurfaceDesc {
GrSurfaceDescGrSurfaceDesc593     GrSurfaceDesc()
594     : fFlags(kNone_GrSurfaceFlags)
595     , fOrigin(kDefault_GrSurfaceOrigin)
596     , fWidth(0)
597     , fHeight(0)
598     , fConfig(kUnknown_GrPixelConfig)
599     , fSampleCnt(0)
600     , fIsMipMapped(false) {
601     }
602 
603     GrSurfaceFlags         fFlags;  //!< bitfield of TextureFlags
604     GrSurfaceOrigin        fOrigin; //!< origin of the texture
605     int                    fWidth;  //!< Width of the texture
606     int                    fHeight; //!< Height of the texture
607 
608     /**
609      * Format of source data of the texture. Not guaranteed to be the same as
610      * internal format used by 3D API.
611      */
612     GrPixelConfig          fConfig;
613 
614     /**
615      * The number of samples per pixel or 0 to disable full scene AA. This only
616      * applies if the kRenderTarget_GrSurfaceFlag is set. The actual number
617      * of samples may not exactly match the request. The request will be rounded
618      * up to the next supported sample count, or down if it is larger than the
619      * max supported count.
620      */
621     int                    fSampleCnt;
622     bool                   fIsMipMapped; //!< Indicates if the texture has mipmaps
623 };
624 
625 // Legacy alias
626 typedef GrSurfaceDesc GrTextureDesc;
627 
628 /**
629  * Clips are composed from these objects.
630  */
631 enum GrClipType {
632     kRect_ClipType,
633     kPath_ClipType
634 };
635 
636 ///////////////////////////////////////////////////////////////////////////////
637 
638 
639 /** Ownership rules for external GPU resources imported into Skia. */
640 enum GrWrapOwnership {
641     /** Skia will assume the client will keep the resource alive and Skia will not free it. */
642     kBorrow_GrWrapOwnership,
643 
644     /** Skia will assume ownership of the resource and free it. */
645     kAdopt_GrWrapOwnership,
646 };
647 
648 /**
649  * Gr can wrap an existing texture created by the client with a GrTexture
650  * object. The client is responsible for ensuring that the texture lives at
651  * least as long as the GrTexture object wrapping it. We require the client to
652  * explicitly provide information about the texture, such as width, height,
653  * and pixel config, rather than querying the 3D APIfor these values. We expect
654  * these to be immutable even if the 3D API doesn't require this (OpenGL).
655  *
656  * Textures that are also render targets are supported as well. Gr will manage
657  * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for
658  * Gr to draw into the render target. To access the render target object
659  * call GrTexture::asRenderTarget().
660  *
661  * If in addition to the render target flag, the caller also specifies a sample
662  * count Gr will create an MSAA buffer that resolves into the texture. Gr auto-
663  * resolves when it reads from the texture. The client can explictly resolve
664  * using the GrRenderTarget interface.
665  *
666  * Note: These flags currently form a subset of GrTexture's flags.
667  */
668 
669 enum GrBackendTextureFlags {
670     /**
671      * No flags enabled
672      */
673     kNone_GrBackendTextureFlag             = 0,
674     /**
675      * Indicates that the texture is also a render target, and thus should have
676      * a GrRenderTarget object.
677      */
678     kRenderTarget_GrBackendTextureFlag     = kRenderTarget_GrSurfaceFlag,
679 };
680 GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags)
681 
682 struct GrBackendTextureDesc {
GrBackendTextureDescGrBackendTextureDesc683     GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); }
684     GrBackendTextureFlags           fFlags;
685     GrSurfaceOrigin                 fOrigin;
686     int                             fWidth;         //<! width in pixels
687     int                             fHeight;        //<! height in pixels
688     GrPixelConfig                   fConfig;        //<! color format
689     /**
690      * If the render target flag is set and sample count is greater than 0
691      * then Gr will create an MSAA buffer that resolves to the texture.
692      */
693     int                             fSampleCnt;
694     /**
695      * Handle to the 3D API object.
696      * OpenGL: Texture ID.
697      * Vulkan: GrVkImageInfo*
698      */
699     GrBackendObject                 fTextureHandle;
700 };
701 
702 ///////////////////////////////////////////////////////////////////////////////
703 
704 /**
705  * Gr can wrap an existing render target created by the client in the 3D API
706  * with a GrRenderTarget object. The client is responsible for ensuring that the
707  * underlying 3D API object lives at least as long as the GrRenderTarget object
708  * wrapping it. We require the client to explicitly provide information about
709  * the target, such as width, height, and pixel config rather than querying the
710  * 3D API for these values. We expect these properties to be immutable even if
711  * the 3D API doesn't require this (OpenGL).
712  */
713 
714 struct GrBackendRenderTargetDesc {
GrBackendRenderTargetDescGrBackendRenderTargetDesc715     GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); }
716     int                             fWidth;         //<! width in pixels
717     int                             fHeight;        //<! height in pixels
718     GrPixelConfig                   fConfig;        //<! color format
719     GrSurfaceOrigin                 fOrigin;        //<! pixel origin
720     /**
721      * The number of samples per pixel. Gr uses this to influence decisions
722      * about applying other forms of anti-aliasing.
723      */
724     int                             fSampleCnt;
725     /**
726      * Number of bits of stencil per-pixel.
727      */
728     int                             fStencilBits;
729     /**
730      * Handle to the 3D API object.
731      * OpenGL: FBO ID
732      * Vulkan: GrVkImageInfo*
733      */
734     GrBackendObject                 fRenderTargetHandle;
735 };
736 
737 /**
738  * The GrContext's cache of backend context state can be partially invalidated.
739  * These enums are specific to the GL backend and we'd add a new set for an alternative backend.
740  */
741 enum GrGLBackendState {
742     kRenderTarget_GrGLBackendState     = 1 << 0,
743     kTextureBinding_GrGLBackendState   = 1 << 1,
744     // View state stands for scissor and viewport
745     kView_GrGLBackendState             = 1 << 2,
746     kBlend_GrGLBackendState            = 1 << 3,
747     kMSAAEnable_GrGLBackendState       = 1 << 4,
748     kVertex_GrGLBackendState           = 1 << 5,
749     kStencil_GrGLBackendState          = 1 << 6,
750     kPixelStore_GrGLBackendState       = 1 << 7,
751     kProgram_GrGLBackendState          = 1 << 8,
752     kFixedFunction_GrGLBackendState    = 1 << 9,
753     kMisc_GrGLBackendState             = 1 << 10,
754     kPathRendering_GrGLBackendState    = 1 << 11,
755     kALL_GrGLBackendState              = 0xffff
756 };
757 
758 /**
759  * This value translates to reseting all the context state for any backend.
760  */
761 static const uint32_t kAll_GrBackendState = 0xffffffff;
762 
763 #endif
764