bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 GrGLProgramDesc_DEFINED |
| 9 | #define GrGLProgramDesc_DEFINED |
| 10 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
| 12 | #include "GrProgramDesc.h" |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 13 | #include "GrGpu.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 14 | #include "GrTypesPriv.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 15 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 16 | class GrGLGpu; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 17 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 18 | /** |
| 19 | * This class can be used to build a GrProgramDesc. It also provides helpers for accessing |
| 20 | * GL specific info in the header. |
| 21 | */ |
| 22 | class GrGLProgramDescBuilder { |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 23 | public: |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 24 | struct GLKeyHeader : public GrProgramDesc::KeyHeader { |
| 25 | SkBool8 fUseNvpr; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 26 | }; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 27 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 28 | // The key, stored in fKey, is composed of five parts(first 2 are defined in the key itself): |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 29 | // 1. uint32_t for total key length. |
| 30 | // 2. uint32_t for a checksum. |
| 31 | // 3. Header struct defined above. |
egdaniel | c67870c | 2014-11-26 08:50:50 -0800 | [diff] [blame] | 32 | // 4. Backend-specific information including per-processor keys and their key lengths. |
| 33 | // Each processor's key is a variable length array of uint32_t. |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 34 | enum { |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 35 | // Part 3. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 36 | kHeaderOffset = GrProgramDesc::kHeaderOffset, |
| 37 | kHeaderSize = SkAlign4(sizeof(GLKeyHeader)), |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 38 | // Part 4. |
egdaniel | c67870c | 2014-11-26 08:50:50 -0800 | [diff] [blame] | 39 | // This is the offset into the backenend specific part of the key, which includes |
| 40 | // per-processor keys. |
| 41 | kProcessorKeysOffset = kHeaderOffset + kHeaderSize, |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Builds a GL specific program descriptor |
| 46 | * |
| 47 | * @param GrOptDrawState The optimized drawstate. The descriptor will represent a program |
| 48 | * which this optstate can use to draw with. The optstate contains |
| 49 | * general draw information, as well as the specific color, geometry, |
| 50 | * and coverage stages which will be used to generate the GL Program for |
| 51 | * this optstate. |
| 52 | * @param DescInfo A descriptor info struct, generated by the optstate, which contains a number |
| 53 | * of important facts about the program the built descriptor will represent |
| 54 | * @param DrawType |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 55 | * @param GrGLGpu A GL Gpu, the caps and Gpu object are used to output processor specific |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 56 | * parts of the descriptor. |
| 57 | * @param GrDeviceCoordTexture A dstCopy texture, which may be null if frame buffer fetch is |
| 58 | * supported |
| 59 | * @param GrProgramDesc The built and finalized descriptor |
| 60 | **/ |
| 61 | static bool Build(const GrOptDrawState&, |
| 62 | const GrProgramDesc::DescInfo&, |
| 63 | GrGpu::DrawType, |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 64 | GrGLGpu*, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 65 | GrProgramDesc*); |
| 66 | |
| 67 | static const GLKeyHeader& GetHeader(const GrProgramDesc& desc) { |
| 68 | return *desc.atOffset<GLKeyHeader, kHeaderOffset>(); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 69 | } |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #endif |