epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 10 | #include "../GrBinHashKey.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 11 | #include "GrCustomStage.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 12 | #include "GrGLProgram.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 13 | #include "GrGLProgramStage.h" |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 14 | #include "GrGLSL.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 15 | #include "GrGpuGLShaders.h" |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 16 | #include "../GrGpuVertex.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 17 | #include "GrNoncopyable.h" |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 18 | #include "../GrStringBuilder.h" |
| 19 | #include "../GrRandom.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 20 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 21 | #define SKIP_CACHE_CHECK true |
| 22 | #define GR_UINT32_MAX static_cast<uint32_t>(-1) |
| 23 | |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 24 | #include "../GrTHashCache.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 25 | |
| 26 | class GrGpuGLShaders::ProgramCache : public ::GrNoncopyable { |
| 27 | private: |
| 28 | class Entry; |
| 29 | |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 30 | typedef GrBinHashKey<Entry, GrGLProgram::kProgramKeySize> ProgramHashKey; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 31 | |
| 32 | class Entry : public ::GrNoncopyable { |
| 33 | public: |
| 34 | Entry() {} |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 35 | void copyAndTakeOwnership(Entry& entry) { |
| 36 | fProgramData.copyAndTakeOwnership(entry.fProgramData); |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 37 | fKey = entry.fKey; // ownership transfer |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 38 | fLRUStamp = entry.fLRUStamp; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | public: |
| 42 | int compare(const ProgramHashKey& key) const { return fKey.compare(key); } |
| 43 | |
| 44 | public: |
| 45 | GrGLProgram::CachedData fProgramData; |
| 46 | ProgramHashKey fKey; |
| 47 | unsigned int fLRUStamp; |
| 48 | }; |
| 49 | |
| 50 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 51 | |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 52 | // We may have kMaxEntries+1 shaders in the GL context because |
| 53 | // we create a new shader before evicting from the cache. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 54 | enum { |
| 55 | kMaxEntries = 32 |
| 56 | }; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 57 | Entry fEntries[kMaxEntries]; |
| 58 | int fCount; |
| 59 | unsigned int fCurrLRUStamp; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 60 | const GrGLContextInfo& fGL; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 61 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 62 | public: |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 63 | ProgramCache(const GrGLContextInfo& gl) |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 64 | : fCount(0) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 65 | , fCurrLRUStamp(0) |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 66 | , fGL(gl) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | ~ProgramCache() { |
| 70 | for (int i = 0; i < fCount; ++i) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 71 | GrGpuGLShaders::DeleteProgram(fGL.interface(), |
| 72 | &fEntries[i].fProgramData); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | void abandon() { |
| 77 | fCount = 0; |
| 78 | } |
| 79 | |
| 80 | void invalidateViewMatrices() { |
| 81 | for (int i = 0; i < fCount; ++i) { |
| 82 | // set to illegal matrix |
| 83 | fEntries[i].fProgramData.fViewMatrix = GrMatrix::InvalidMatrix(); |
| 84 | } |
| 85 | } |
| 86 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 87 | GrGLProgram::CachedData* getProgramData(const GrGLProgram& desc, |
| 88 | GrCustomStage** stages) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 89 | Entry newEntry; |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 90 | newEntry.fKey.setKeyData(desc.keyData()); |
| 91 | |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 92 | Entry* entry = fHashCache.find(newEntry.fKey); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 93 | if (NULL == entry) { |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 94 | if (!desc.genProgram(fGL, stages, &newEntry.fProgramData)) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 97 | if (fCount < kMaxEntries) { |
| 98 | entry = fEntries + fCount; |
| 99 | ++fCount; |
| 100 | } else { |
| 101 | GrAssert(kMaxEntries == fCount); |
| 102 | entry = fEntries; |
| 103 | for (int i = 1; i < kMaxEntries; ++i) { |
| 104 | if (fEntries[i].fLRUStamp < entry->fLRUStamp) { |
| 105 | entry = fEntries + i; |
| 106 | } |
| 107 | } |
| 108 | fHashCache.remove(entry->fKey, entry); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 109 | GrGpuGLShaders::DeleteProgram(fGL.interface(), |
| 110 | &entry->fProgramData); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 111 | } |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 112 | entry->copyAndTakeOwnership(newEntry); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 113 | fHashCache.insert(entry->fKey, entry); |
| 114 | } |
| 115 | |
| 116 | entry->fLRUStamp = fCurrLRUStamp; |
| 117 | if (GR_UINT32_MAX == fCurrLRUStamp) { |
| 118 | // wrap around! just trash our LRU, one time hit. |
| 119 | for (int i = 0; i < fCount; ++i) { |
| 120 | fEntries[i].fLRUStamp = 0; |
| 121 | } |
| 122 | } |
| 123 | ++fCurrLRUStamp; |
| 124 | return &entry->fProgramData; |
| 125 | } |
| 126 | }; |
| 127 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 128 | void GrGpuGLShaders::abandonResources(){ |
| 129 | INHERITED::abandonResources(); |
| 130 | fProgramCache->abandon(); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 131 | fHWProgramID = 0; |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 132 | } |
| 133 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 134 | void GrGpuGLShaders::DeleteProgram(const GrGLInterface* gl, |
| 135 | CachedData* programData) { |
| 136 | GR_GL_CALL(gl, DeleteShader(programData->fVShaderID)); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 137 | if (programData->fGShaderID) { |
| 138 | GR_GL_CALL(gl, DeleteShader(programData->fGShaderID)); |
| 139 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 140 | GR_GL_CALL(gl, DeleteShader(programData->fFShaderID)); |
| 141 | GR_GL_CALL(gl, DeleteProgram(programData->fProgramID)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 142 | GR_DEBUGCODE(memset(programData, 0, sizeof(*programData));) |
| 143 | } |
| 144 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 145 | //////////////////////////////////////////////////////////////////////////////// |
| 146 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 147 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 148 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 149 | namespace { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 150 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 151 | // GrRandoms nextU() values have patterns in the low bits |
| 152 | // So using nextU() % array_count might never take some values. |
| 153 | int random_int(GrRandom* r, int count) { |
| 154 | return (int)(r->nextF() * count); |
| 155 | } |
| 156 | |
| 157 | // min is inclusive, max is exclusive |
| 158 | int random_int(GrRandom* r, int min, int max) { |
| 159 | return (int)(r->nextF() * (max-min)) + min; |
| 160 | } |
| 161 | |
| 162 | bool random_bool(GrRandom* r) { |
| 163 | return r->nextF() > .5f; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 167 | |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 168 | bool GrGpuGLShaders::programUnitTest() { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 169 | |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 170 | GrGLSLGeneration glslGeneration = |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 171 | GrGetGLSLGeneration(this->glBinding(), this->glInterface()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 172 | static const int STAGE_OPTS[] = { |
| 173 | 0, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 174 | StageDesc::kNoPerspective_OptFlagBit, |
| 175 | StageDesc::kIdentity_CoordMapping |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 176 | }; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 177 | static const int IN_CONFIG_FLAGS[] = { |
| 178 | StageDesc::kNone_InConfigFlag, |
| 179 | StageDesc::kSwapRAndB_InConfigFlag, |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 180 | StageDesc::kSwapRAndB_InConfigFlag | |
| 181 | StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag, |
| 182 | StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag, |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 183 | StageDesc::kSmearAlpha_InConfigFlag, |
| 184 | }; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 185 | GrGLProgram program; |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 186 | ProgramDesc& pdesc = program.fProgramDesc; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 187 | |
| 188 | static const int NUM_TESTS = 512; |
| 189 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 190 | GrRandom random; |
| 191 | for (int t = 0; t < NUM_TESTS; ++t) { |
| 192 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 193 | #if 0 |
| 194 | GrPrintf("\nTest Program %d\n-------------\n", t); |
| 195 | static const int stop = -1; |
| 196 | if (t == stop) { |
| 197 | int breakpointhere = 9; |
| 198 | } |
| 199 | #endif |
| 200 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 201 | pdesc.fVertexLayout = 0; |
| 202 | pdesc.fEmitsPointSize = random.nextF() > .5f; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 203 | pdesc.fColorInput = random_int(&random, ProgramDesc::kColorInputCnt); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 204 | pdesc.fCoverageInput = random_int(&random, ProgramDesc::kColorInputCnt); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 205 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 206 | pdesc.fColorFilterXfermode = random_int(&random, SkXfermode::kCoeffModesCnt); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 207 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 208 | pdesc.fFirstCoverageStage = random_int(&random, GrDrawState::kNumStages); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 209 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 210 | pdesc.fVertexLayout |= random_bool(&random) ? |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 211 | GrDrawTarget::kCoverage_VertexLayoutBit : |
| 212 | 0; |
| 213 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 214 | #if GR_GL_EXPERIMENTAL_GS |
bsalomon@google.com | 6f92f18 | 2011-09-29 15:05:48 +0000 | [diff] [blame] | 215 | pdesc.fExperimentalGS = this->getCaps().fGeometryShaderSupport && |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 216 | random_bool(&random); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 217 | #endif |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 218 | pdesc.fOutputConfig = random_int(&random, ProgramDesc::kOutputConfigCnt); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 219 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 220 | bool edgeAA = random_bool(&random); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 221 | if (edgeAA) { |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 222 | bool vertexEdgeAA = random_bool(&random); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 223 | if (vertexEdgeAA) { |
| 224 | pdesc.fVertexLayout |= GrDrawTarget::kEdge_VertexLayoutBit; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 225 | if (this->getCaps().fShaderDerivativeSupport) { |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 226 | pdesc.fVertexEdgeType = (GrDrawState::VertexEdgeType) random_int(&random, GrDrawState::kVertexEdgeTypeCnt); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 227 | } else { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 228 | pdesc.fVertexEdgeType = GrDrawState::kHairLine_EdgeType; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 229 | } |
| 230 | pdesc.fEdgeAANumEdges = 0; |
| 231 | } else { |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 232 | pdesc.fEdgeAANumEdges = random_int(&random, 1, this->getMaxEdges()); |
| 233 | pdesc.fEdgeAAConcave = random_bool(&random); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 234 | } |
| 235 | } else { |
| 236 | pdesc.fEdgeAANumEdges = 0; |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 237 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 238 | |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 239 | pdesc.fColorMatrixEnabled = random_bool(&random); |
| 240 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 241 | if (this->getCaps().fDualSourceBlendingSupport) { |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 242 | pdesc.fDualSrcOutput = random_int(&random, ProgramDesc::kDualSrcOutputCnt); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 243 | } else { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 244 | pdesc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 245 | } |
| 246 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 247 | GrCustomStage* customStages[GrDrawState::kNumStages]; |
| 248 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 249 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 250 | // enable the stage? |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 251 | if (random_bool(&random)) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 252 | // use separate tex coords? |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 253 | if (random_bool(&random)) { |
| 254 | int t = random_int(&random, GrDrawState::kMaxTexCoords); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 255 | pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t); |
| 256 | } else { |
| 257 | pdesc.fVertexLayout |= StagePosAsTexCoordVertexLayoutBit(s); |
| 258 | } |
| 259 | } |
| 260 | // use text-formatted verts? |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 261 | if (random_bool(&random)) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 262 | pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit; |
| 263 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 264 | StageDesc& stage = pdesc.fStages[s]; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 265 | stage.fOptFlags = STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))]; |
| 266 | stage.fInConfigFlags = IN_CONFIG_FLAGS[random_int(&random, GR_ARRAY_COUNT(IN_CONFIG_FLAGS))]; |
| 267 | stage.fCoordMapping = random_int(&random, StageDesc::kCoordMappingCnt); |
| 268 | stage.fFetchMode = random_int(&random, StageDesc::kFetchModeCnt); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 269 | // convolution shaders don't work with persp tex matrix |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 270 | if (stage.fFetchMode == StageDesc::kConvolution_FetchMode || |
| 271 | stage.fFetchMode == StageDesc::kDilate_FetchMode || |
| 272 | stage.fFetchMode == StageDesc::kErode_FetchMode) { |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 273 | stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; |
| 274 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 275 | stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout)); |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 276 | static const uint32_t kMulByAlphaMask = |
| 277 | StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag | |
| 278 | StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 279 | switch (stage.fFetchMode) { |
| 280 | case StageDesc::kSingle_FetchMode: |
| 281 | stage.fKernelWidth = 0; |
| 282 | break; |
| 283 | case StageDesc::kConvolution_FetchMode: |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 284 | case StageDesc::kDilate_FetchMode: |
| 285 | case StageDesc::kErode_FetchMode: |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 286 | stage.fKernelWidth = random_int(&random, 2, 8); |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 287 | stage.fInConfigFlags &= ~kMulByAlphaMask; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 288 | break; |
| 289 | case StageDesc::k2x2_FetchMode: |
| 290 | stage.fKernelWidth = 0; |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 291 | stage.fInConfigFlags &= ~kMulByAlphaMask; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 292 | break; |
| 293 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 294 | |
| 295 | stage.fCustomStageKey = 0; |
| 296 | customStages[s] = NULL; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 297 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 298 | CachedData cachedData; |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 299 | if (!program.genProgram(this->glContextInfo(), customStages, |
| 300 | &cachedData)) { |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 301 | return false; |
| 302 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 303 | DeleteProgram(this->glInterface(), &cachedData); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 304 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 305 | return true; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 306 | } |
| 307 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 308 | GrGpuGLShaders::GrGpuGLShaders(const GrGLContextInfo& ctxInfo) |
| 309 | : GrGpuGL(ctxInfo) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 310 | |
bsalomon@google.com | dafde9e | 2012-01-11 18:45:39 +0000 | [diff] [blame] | 311 | // Enable supported shader-related caps |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 312 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 313 | fCaps.fDualSourceBlendingSupport = |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 314 | this->glVersion() >= GR_GL_VER(3,3) || |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 315 | this->hasExtension("GL_ARB_blend_func_extended"); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 316 | fCaps.fShaderDerivativeSupport = true; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 317 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 318 | fCaps.fGeometryShaderSupport = |
| 319 | this->glVersion() >= GR_GL_VER(3,2) && |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 320 | this->glslGeneration() >= k150_GrGLSLGeneration; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 321 | } else { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 322 | fCaps.fShaderDerivativeSupport = |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 323 | this->hasExtension("GL_OES_standard_derivatives"); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 324 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 325 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 326 | GR_GL_GetIntegerv(this->glInterface(), |
| 327 | GR_GL_MAX_VERTEX_ATTRIBS, |
| 328 | &fMaxVertexAttribs); |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame] | 329 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 330 | fProgramData = NULL; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 331 | fProgramCache = new ProgramCache(this->glContextInfo()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 332 | |
| 333 | #if 0 |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 334 | this->programUnitTest(); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 335 | #endif |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | GrGpuGLShaders::~GrGpuGLShaders() { |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 339 | |
| 340 | if (fProgramData && 0 != fHWProgramID) { |
| 341 | // detach the current program so there is no confusion on OpenGL's part |
| 342 | // that we want it to be deleted |
| 343 | SkASSERT(fHWProgramID == fProgramData->fProgramID); |
| 344 | GL_CALL(UseProgram(0)); |
| 345 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 346 | delete fProgramCache; |
| 347 | } |
| 348 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 349 | const GrMatrix& GrGpuGLShaders::getHWViewMatrix() { |
| 350 | GrAssert(fProgramData); |
| 351 | |
| 352 | if (GrGLProgram::kSetAsAttribute == |
| 353 | fProgramData->fUniLocations.fViewMatrixUni) { |
| 354 | return fHWDrawState.getViewMatrix(); |
| 355 | } else { |
| 356 | return fProgramData->fViewMatrix; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | void GrGpuGLShaders::recordHWViewMatrix(const GrMatrix& matrix) { |
| 361 | GrAssert(fProgramData); |
| 362 | if (GrGLProgram::kSetAsAttribute == |
| 363 | fProgramData->fUniLocations.fViewMatrixUni) { |
| 364 | fHWDrawState.setViewMatrix(matrix); |
| 365 | } else { |
| 366 | fProgramData->fViewMatrix = matrix; |
| 367 | } |
| 368 | } |
| 369 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 370 | const GrMatrix& GrGpuGLShaders::getHWSamplerMatrix(int stage) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 371 | GrAssert(fProgramData); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 372 | |
| 373 | if (GrGLProgram::kSetAsAttribute == |
| 374 | fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 375 | return fHWDrawState.getSampler(stage).getMatrix(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 376 | } else { |
| 377 | return fProgramData->fTextureMatrices[stage]; |
| 378 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 382 | GrAssert(fProgramData); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 383 | if (GrGLProgram::kSetAsAttribute == |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 384 | fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) { |
bsalomon@google.com | aa814fe | 2011-12-12 18:45:07 +0000 | [diff] [blame] | 385 | *fHWDrawState.sampler(stage)->matrix() = matrix; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 386 | } else { |
| 387 | fProgramData->fTextureMatrices[stage] = matrix; |
| 388 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 389 | } |
| 390 | |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 391 | void GrGpuGLShaders::onResetContext() { |
| 392 | INHERITED::onResetContext(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 393 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 394 | fHWGeometryState.fVertexOffset = ~0; |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame] | 395 | |
| 396 | // Third party GL code may have left vertex attributes enabled. Some GL |
| 397 | // implementations (osmesa) may read vetex attributes that are not required |
| 398 | // by the current shader. Therefore, we have to ensure that only the |
| 399 | // attributes we require for the current draw are enabled or we may cause an |
| 400 | // invalid read. |
| 401 | |
| 402 | // Disable all vertex layout bits so that next flush will assume all |
| 403 | // optional vertex attributes are disabled. |
| 404 | fHWGeometryState.fVertexLayout = 0; |
| 405 | |
| 406 | // We always use the this attribute and assume it is always enabled. |
| 407 | int posAttrIdx = GrGLProgram::PositionAttributeIdx(); |
| 408 | GL_CALL(EnableVertexAttribArray(posAttrIdx)); |
| 409 | // Disable all other vertex attributes. |
| 410 | for (int va = 0; va < fMaxVertexAttribs; ++va) { |
| 411 | if (va != posAttrIdx) { |
| 412 | GL_CALL(DisableVertexAttribArray(va)); |
| 413 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 414 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 415 | |
| 416 | fHWProgramID = 0; |
| 417 | } |
| 418 | |
| 419 | void GrGpuGLShaders::flushViewMatrix() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 420 | const GrMatrix& vm = this->getDrawState().getViewMatrix(); |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 421 | if (!GrGpuGLShaders::getHWViewMatrix().cheapEqualTo(vm)) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 422 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 423 | const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
| 424 | GrAssert(NULL != rt); |
| 425 | GrMatrix m; |
| 426 | m.setAll( |
| 427 | GrIntToScalar(2) / rt->width(), 0, -GR_Scalar1, |
| 428 | 0,-GrIntToScalar(2) / rt->height(), GR_Scalar1, |
| 429 | 0, 0, GrMatrix::I()[8]); |
| 430 | m.setConcat(m, vm); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 431 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 432 | // ES doesn't allow you to pass true to the transpose param, |
| 433 | // so do our own transpose |
| 434 | GrGLfloat mt[] = { |
| 435 | GrScalarToFloat(m[GrMatrix::kMScaleX]), |
| 436 | GrScalarToFloat(m[GrMatrix::kMSkewY]), |
| 437 | GrScalarToFloat(m[GrMatrix::kMPersp0]), |
| 438 | GrScalarToFloat(m[GrMatrix::kMSkewX]), |
| 439 | GrScalarToFloat(m[GrMatrix::kMScaleY]), |
| 440 | GrScalarToFloat(m[GrMatrix::kMPersp1]), |
| 441 | GrScalarToFloat(m[GrMatrix::kMTransX]), |
| 442 | GrScalarToFloat(m[GrMatrix::kMTransY]), |
| 443 | GrScalarToFloat(m[GrMatrix::kMPersp2]) |
| 444 | }; |
| 445 | |
| 446 | if (GrGLProgram::kSetAsAttribute == |
| 447 | fProgramData->fUniLocations.fViewMatrixUni) { |
| 448 | int baseIdx = GrGLProgram::ViewMatrixAttributeIdx(); |
| 449 | GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); |
| 450 | GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); |
| 451 | GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); |
| 452 | } else { |
| 453 | GrAssert(GrGLProgram::kUnusedUniform != |
| 454 | fProgramData->fUniLocations.fViewMatrixUni); |
| 455 | GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni, |
| 456 | 1, false, mt)); |
| 457 | } |
| 458 | this->recordHWViewMatrix(vm); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 459 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 460 | } |
| 461 | |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 462 | void GrGpuGLShaders::flushTextureDomain(int s) { |
| 463 | const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTexDomUni; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 464 | const GrDrawState& drawState = this->getDrawState(); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 465 | if (GrGLProgram::kUnusedUniform != uni) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 466 | const GrRect &texDom = drawState.getSampler(s).getTextureDomain(); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 467 | |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 468 | if (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
| 469 | fProgramData->fTextureDomain[s] != texDom) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 470 | |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 471 | fProgramData->fTextureDomain[s] = texDom; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 472 | |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 473 | float values[4] = { |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 474 | GrScalarToFloat(texDom.left()), |
| 475 | GrScalarToFloat(texDom.top()), |
| 476 | GrScalarToFloat(texDom.right()), |
| 477 | GrScalarToFloat(texDom.bottom()) |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 478 | }; |
| 479 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 480 | const GrGLTexture* texture = |
| 481 | static_cast<const GrGLTexture*>(drawState.getTexture(s)); |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 482 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 483 | |
| 484 | // vertical flip if necessary |
| 485 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 486 | values[1] = 1.0f - values[1]; |
| 487 | values[3] = 1.0f - values[3]; |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 488 | // The top and bottom were just flipped, so correct the ordering |
| 489 | // of elements so that values = (l, t, r, b). |
| 490 | SkTSwap(values[1], values[3]); |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 491 | } |
| 492 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 493 | GL_CALL(Uniform4fv(uni, 1, values)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 494 | } |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 498 | void GrGpuGLShaders::flushTextureMatrix(int s) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 499 | const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 500 | const GrDrawState& drawState = this->getDrawState(); |
| 501 | const GrGLTexture* texture = |
| 502 | static_cast<const GrGLTexture*>(drawState.getTexture(s)); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 503 | if (NULL != texture) { |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 504 | const GrMatrix& hwMatrix = this->getHWSamplerMatrix(s); |
| 505 | const GrMatrix& samplerMatrix = drawState.getSampler(s).getMatrix(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 506 | if (GrGLProgram::kUnusedUniform != uni && |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 507 | (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 508 | !hwMatrix.cheapEqualTo(samplerMatrix))) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 510 | GrMatrix m = samplerMatrix; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 511 | GrSamplerState::SampleMode mode = |
| 512 | drawState.getSampler(s).getSampleMode(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 513 | AdjustTextureMatrix(texture, mode, &m); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 514 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 515 | // ES doesn't allow you to pass true to the transpose param, |
| 516 | // so do our own transpose |
bsalomon@google.com | 27a4dc4 | 2011-05-16 13:14:03 +0000 | [diff] [blame] | 517 | GrGLfloat mt[] = { |
| 518 | GrScalarToFloat(m[GrMatrix::kMScaleX]), |
| 519 | GrScalarToFloat(m[GrMatrix::kMSkewY]), |
| 520 | GrScalarToFloat(m[GrMatrix::kMPersp0]), |
| 521 | GrScalarToFloat(m[GrMatrix::kMSkewX]), |
| 522 | GrScalarToFloat(m[GrMatrix::kMScaleY]), |
| 523 | GrScalarToFloat(m[GrMatrix::kMPersp1]), |
| 524 | GrScalarToFloat(m[GrMatrix::kMTransX]), |
| 525 | GrScalarToFloat(m[GrMatrix::kMTransY]), |
| 526 | GrScalarToFloat(m[GrMatrix::kMPersp2]) |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 527 | }; |
bsalomon@google.com | 27a4dc4 | 2011-05-16 13:14:03 +0000 | [diff] [blame] | 528 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 529 | if (GrGLProgram::kSetAsAttribute == |
| 530 | fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) { |
| 531 | int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 532 | GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); |
| 533 | GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); |
| 534 | GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 535 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 536 | GL_CALL(UniformMatrix3fv(uni, 1, false, mt)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 537 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 538 | this->recordHWSamplerMatrix(s, drawState.getSampler(s).getMatrix()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 539 | } |
| 540 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 541 | } |
| 542 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 543 | void GrGpuGLShaders::flushRadial2(int s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 544 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 545 | const int &uni = fProgramData->fUniLocations.fStages[s].fRadial2Uni; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 546 | const GrSamplerState& sampler = this->getDrawState().getSampler(s); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 547 | if (GrGLProgram::kUnusedUniform != uni && |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 548 | (fProgramData->fRadial2CenterX1[s] != sampler.getRadial2CenterX1() || |
| 549 | fProgramData->fRadial2Radius0[s] != sampler.getRadial2Radius0() || |
| 550 | fProgramData->fRadial2PosRoot[s] != sampler.isRadial2PosRoot())) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 551 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 552 | GrScalar centerX1 = sampler.getRadial2CenterX1(); |
| 553 | GrScalar radius0 = sampler.getRadial2Radius0(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 554 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 555 | GrScalar a = GrMul(centerX1, centerX1) - GR_Scalar1; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 556 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 557 | // when were in the degenerate (linear) case the second |
| 558 | // value will be INF but the program doesn't read it. (We |
| 559 | // use the same 6 uniforms even though we don't need them |
| 560 | // all in the linear case just to keep the code complexity |
| 561 | // down). |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 562 | float values[6] = { |
| 563 | GrScalarToFloat(a), |
bsalomon@google.com | 2cdfade | 2011-11-23 16:53:42 +0000 | [diff] [blame] | 564 | 1 / (2.f * GrScalarToFloat(a)), |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 565 | GrScalarToFloat(centerX1), |
| 566 | GrScalarToFloat(radius0), |
| 567 | GrScalarToFloat(GrMul(radius0, radius0)), |
| 568 | sampler.isRadial2PosRoot() ? 1.f : -1.f |
| 569 | }; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 570 | GL_CALL(Uniform1fv(uni, 6, values)); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 571 | fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1(); |
| 572 | fProgramData->fRadial2Radius0[s] = sampler.getRadial2Radius0(); |
| 573 | fProgramData->fRadial2PosRoot[s] = sampler.isRadial2PosRoot(); |
| 574 | } |
| 575 | } |
| 576 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 577 | void GrGpuGLShaders::flushConvolution(int s) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 578 | const GrSamplerState& sampler = this->getDrawState().getSampler(s); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 579 | int kernelUni = fProgramData->fUniLocations.fStages[s].fKernelUni; |
| 580 | if (GrGLProgram::kUnusedUniform != kernelUni) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 581 | GL_CALL(Uniform1fv(kernelUni, sampler.getKernelWidth(), |
| 582 | sampler.getKernel())); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 583 | } |
| 584 | int imageIncrementUni = fProgramData->fUniLocations.fStages[s].fImageIncrementUni; |
| 585 | if (GrGLProgram::kUnusedUniform != imageIncrementUni) { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 586 | const GrGLTexture* texture = |
| 587 | static_cast<const GrGLTexture*>(this->getDrawState().getTexture(s)); |
| 588 | float imageIncrement[2] = { 0 }; |
| 589 | switch (sampler.getFilterDirection()) { |
| 590 | case GrSamplerState::kX_FilterDirection: |
| 591 | imageIncrement[0] = 1.0f / texture->width(); |
| 592 | break; |
| 593 | case GrSamplerState::kY_FilterDirection: |
| 594 | imageIncrement[1] = 1.0f / texture->height(); |
| 595 | break; |
| 596 | default: |
| 597 | GrCrash("Unknown filter direction."); |
| 598 | } |
| 599 | GL_CALL(Uniform2fv(imageIncrementUni, 1, imageIncrement)); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 603 | void GrGpuGLShaders::flushTexelSize(int s) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 604 | const int& uni = fProgramData->fUniLocations.fStages[s].fNormalizedTexelSizeUni; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 605 | if (GrGLProgram::kUnusedUniform != uni) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 606 | const GrGLTexture* texture = |
| 607 | static_cast<const GrGLTexture*>(this->getDrawState().getTexture(s)); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 608 | if (texture->width() != fProgramData->fTextureWidth[s] || |
| 609 | texture->height() != fProgramData->fTextureHeight[s]) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 610 | |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 611 | float texelSize[] = {1.f / texture->width(), |
| 612 | 1.f / texture->height()}; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 613 | GL_CALL(Uniform2fv(uni, 1, texelSize)); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 614 | fProgramData->fTextureWidth[s] = texture->width(); |
| 615 | fProgramData->fTextureHeight[s] = texture->height(); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 618 | } |
| 619 | |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 620 | void GrGpuGLShaders::flushEdgeAAData() { |
| 621 | const int& uni = fProgramData->fUniLocations.fEdgesUni; |
| 622 | if (GrGLProgram::kUnusedUniform != uni) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 623 | int count = this->getDrawState().getNumAAEdges(); |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 624 | GrDrawState::Edge edges[GrDrawState::kMaxEdges]; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 625 | // Flip the edges in Y |
bsalomon@google.com | 9d12f5c | 2011-09-29 18:08:18 +0000 | [diff] [blame] | 626 | float height = |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 627 | static_cast<float>(this->getDrawState().getRenderTarget()->height()); |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 628 | for (int i = 0; i < count; ++i) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 629 | edges[i] = this->getDrawState().getAAEdges()[i]; |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 630 | float b = edges[i].fY; |
| 631 | edges[i].fY = -b; |
| 632 | edges[i].fZ += b * height; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 633 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 634 | GL_CALL(Uniform3fv(uni, count, &edges[0].fX)); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 638 | void GrGpuGLShaders::flushColorMatrix() { |
| 639 | const ProgramDesc& desc = fCurrentProgram.getDesc(); |
| 640 | int matrixUni = fProgramData->fUniLocations.fColorMatrixUni; |
| 641 | int vecUni = fProgramData->fUniLocations.fColorMatrixVecUni; |
| 642 | if (GrGLProgram::kUnusedUniform != matrixUni |
| 643 | && GrGLProgram::kUnusedUniform != vecUni) { |
| 644 | const float* m = this->getDrawState().getColorMatrix(); |
| 645 | GrGLfloat mt[] = { |
| 646 | m[0], m[5], m[10], m[15], |
| 647 | m[1], m[6], m[11], m[16], |
| 648 | m[2], m[7], m[12], m[17], |
| 649 | m[3], m[8], m[13], m[18], |
| 650 | }; |
| 651 | static float scale = 1.0f / 255.0f; |
| 652 | GrGLfloat vec[] = { |
| 653 | m[4] * scale, m[9] * scale, m[14] * scale, m[19] * scale, |
| 654 | }; |
| 655 | GL_CALL(UniformMatrix4fv(matrixUni, 1, false, mt)); |
| 656 | GL_CALL(Uniform4fv(vecUni, 1, vec)); |
| 657 | } |
| 658 | } |
| 659 | |
Scroggo | 01b87ec | 2011-05-11 18:05:38 +0000 | [diff] [blame] | 660 | static const float ONE_OVER_255 = 1.f / 255.f; |
| 661 | |
| 662 | #define GR_COLOR_TO_VEC4(color) {\ |
| 663 | GrColorUnpackR(color) * ONE_OVER_255,\ |
| 664 | GrColorUnpackG(color) * ONE_OVER_255,\ |
| 665 | GrColorUnpackB(color) * ONE_OVER_255,\ |
| 666 | GrColorUnpackA(color) * ONE_OVER_255 \ |
| 667 | } |
| 668 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 669 | void GrGpuGLShaders::flushColor(GrColor color) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 670 | const ProgramDesc& desc = fCurrentProgram.getDesc(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 671 | const GrDrawState& drawState = this->getDrawState(); |
| 672 | |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 673 | if (this->getVertexLayout() & kColor_VertexLayoutBit) { |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 674 | // color will be specified per-vertex as an attribute |
| 675 | // invalidate the const vertex attrib color |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 676 | fHWDrawState.setColor(GrColor_ILLEGAL); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 677 | } else { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 678 | switch (desc.fColorInput) { |
| 679 | case ProgramDesc::kAttribute_ColorInput: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 680 | if (fHWDrawState.getColor() != color) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 681 | // OpenGL ES only supports the float varieties of |
| 682 | // glVertexAttrib |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 683 | float c[] = GR_COLOR_TO_VEC4(color); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 684 | GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), |
| 685 | c)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 686 | fHWDrawState.setColor(color); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 687 | } |
| 688 | break; |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 689 | case ProgramDesc::kUniform_ColorInput: |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 690 | if (fProgramData->fColor != color) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 691 | // OpenGL ES doesn't support unsigned byte varieties of |
| 692 | // glUniform |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 693 | float c[] = GR_COLOR_TO_VEC4(color); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 694 | GrAssert(GrGLProgram::kUnusedUniform != |
| 695 | fProgramData->fUniLocations.fColorUni); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 696 | GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorUni, |
| 697 | 1, c)); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 698 | fProgramData->fColor = color; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 699 | } |
| 700 | break; |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 701 | case ProgramDesc::kSolidWhite_ColorInput: |
| 702 | case ProgramDesc::kTransBlack_ColorInput: |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 703 | break; |
| 704 | default: |
| 705 | GrCrash("Unknown color type."); |
| 706 | } |
| 707 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 708 | if (fProgramData->fUniLocations.fColorFilterUni |
| 709 | != GrGLProgram::kUnusedUniform |
| 710 | && fProgramData->fColorFilterColor |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 711 | != drawState.getColorFilterColor()) { |
| 712 | float c[] = GR_COLOR_TO_VEC4(drawState.getColorFilterColor()); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 713 | GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 714 | fProgramData->fColorFilterColor = drawState.getColorFilterColor(); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 715 | } |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 716 | } |
| 717 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 718 | void GrGpuGLShaders::flushCoverage(GrColor coverage) { |
| 719 | const ProgramDesc& desc = fCurrentProgram.getDesc(); |
| 720 | const GrDrawState& drawState = this->getDrawState(); |
| 721 | |
| 722 | |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 723 | if (this->getVertexLayout() & kCoverage_VertexLayoutBit) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 724 | // coverage will be specified per-vertex as an attribute |
| 725 | // invalidate the const vertex attrib coverage |
| 726 | fHWDrawState.setCoverage4(GrColor_ILLEGAL); |
| 727 | } else { |
| 728 | switch (desc.fCoverageInput) { |
| 729 | case ProgramDesc::kAttribute_ColorInput: |
| 730 | if (fHWDrawState.getCoverage() != coverage) { |
| 731 | // OpenGL ES only supports the float varieties of |
| 732 | // glVertexAttrib |
| 733 | float c[] = GR_COLOR_TO_VEC4(coverage); |
| 734 | GL_CALL(VertexAttrib4fv(GrGLProgram::CoverageAttributeIdx(), |
| 735 | c)); |
| 736 | fHWDrawState.setCoverage(coverage); |
| 737 | } |
| 738 | break; |
| 739 | case ProgramDesc::kUniform_ColorInput: |
| 740 | if (fProgramData->fCoverage != coverage) { |
| 741 | // OpenGL ES doesn't support unsigned byte varieties of |
| 742 | // glUniform |
| 743 | float c[] = GR_COLOR_TO_VEC4(coverage); |
| 744 | GrAssert(GrGLProgram::kUnusedUniform != |
| 745 | fProgramData->fUniLocations.fCoverageUni); |
| 746 | GL_CALL(Uniform4fv(fProgramData->fUniLocations.fCoverageUni, |
| 747 | 1, c)); |
| 748 | fProgramData->fCoverage = coverage; |
| 749 | } |
| 750 | break; |
| 751 | case ProgramDesc::kSolidWhite_ColorInput: |
| 752 | case ProgramDesc::kTransBlack_ColorInput: |
| 753 | break; |
| 754 | default: |
| 755 | GrCrash("Unknown coverage type."); |
| 756 | } |
| 757 | } |
| 758 | } |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 759 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 760 | bool GrGpuGLShaders::flushGraphicsState(GrPrimitiveType type) { |
| 761 | if (!flushGLStateCommon(type)) { |
| 762 | return false; |
| 763 | } |
| 764 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 765 | const GrDrawState& drawState = this->getDrawState(); |
| 766 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 767 | if (fDirtyFlags.fRenderTargetChanged) { |
| 768 | // our coords are in pixel space and the GL matrices map to NDC |
| 769 | // so if the viewport changed, our matrix is now wrong. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 770 | fHWDrawState.setViewMatrix(GrMatrix::InvalidMatrix()); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 771 | // we assume all shader matrices may be wrong after viewport changes |
| 772 | fProgramCache->invalidateViewMatrices(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 773 | } |
| 774 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 775 | GrBlendCoeff srcCoeff; |
| 776 | GrBlendCoeff dstCoeff; |
| 777 | BlendOptFlags blendOpts = this->getBlendOpts(false, &srcCoeff, &dstCoeff); |
| 778 | if (kSkipDraw_BlendOptFlag & blendOpts) { |
| 779 | return false; |
| 780 | } |
| 781 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 782 | GrCustomStage* customStages [GrDrawState::kNumStages]; |
| 783 | this->buildProgram(type, blendOpts, dstCoeff, customStages); |
| 784 | fProgramData = fProgramCache->getProgramData(fCurrentProgram, |
| 785 | customStages); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 786 | if (NULL == fProgramData) { |
| 787 | GrAssert(!"Failed to create program!"); |
| 788 | return false; |
| 789 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 790 | |
| 791 | if (fHWProgramID != fProgramData->fProgramID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 792 | GL_CALL(UseProgram(fProgramData->fProgramID)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 793 | fHWProgramID = fProgramData->fProgramID; |
| 794 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 795 | fCurrentProgram.overrideBlend(&srcCoeff, &dstCoeff); |
| 796 | this->flushBlend(type, srcCoeff, dstCoeff); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 797 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 798 | GrColor color; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 799 | GrColor coverage; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 800 | if (blendOpts & kEmitTransBlack_BlendOptFlag) { |
| 801 | color = 0; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 802 | coverage = 0; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 803 | } else if (blendOpts & kEmitCoverage_BlendOptFlag) { |
| 804 | color = 0xffffffff; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 805 | coverage = drawState.getCoverage(); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 806 | } else { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 807 | color = drawState.getColor(); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 808 | coverage = drawState.getCoverage(); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 809 | } |
| 810 | this->flushColor(color); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 811 | this->flushCoverage(coverage); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 812 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 813 | this->flushViewMatrix(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 814 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 815 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 816 | if (this->isStageEnabled(s)) { |
| 817 | this->flushTextureMatrix(s); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 818 | |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 819 | this->flushRadial2(s); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 820 | |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 821 | this->flushConvolution(s); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 822 | |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 823 | this->flushTexelSize(s); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 824 | |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 825 | this->flushTextureDomain(s); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 826 | |
| 827 | if (NULL != fProgramData->fCustomStage[s]) { |
| 828 | const GrSamplerState& sampler = |
| 829 | this->getDrawState().getSampler(s); |
| 830 | fProgramData->fCustomStage[s]->setData( |
| 831 | this->glInterface(), sampler.getCustomStage()); |
| 832 | } |
bsalomon@google.com | 40d9293 | 2011-12-13 18:40:47 +0000 | [diff] [blame] | 833 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 834 | } |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 835 | this->flushEdgeAAData(); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 836 | this->flushColorMatrix(); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 837 | resetDirtyFlags(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 838 | return true; |
| 839 | } |
| 840 | |
| 841 | void GrGpuGLShaders::postDraw() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | void GrGpuGLShaders::setupGeometry(int* startVertex, |
| 845 | int* startIndex, |
| 846 | int vertexCount, |
| 847 | int indexCount) { |
| 848 | |
| 849 | int newColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 850 | int newCoverageOffset; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 851 | int newTexCoordOffsets[GrDrawState::kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 852 | int newEdgeOffset; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 853 | |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 854 | GrVertexLayout currLayout = this->getVertexLayout(); |
| 855 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 856 | GrGLsizei newStride = VertexSizeAndOffsetsByIdx( |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 857 | currLayout, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 858 | newTexCoordOffsets, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 859 | &newColorOffset, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 860 | &newCoverageOffset, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 861 | &newEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 862 | int oldColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 863 | int oldCoverageOffset; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 864 | int oldTexCoordOffsets[GrDrawState::kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 865 | int oldEdgeOffset; |
| 866 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 867 | GrGLsizei oldStride = VertexSizeAndOffsetsByIdx( |
| 868 | fHWGeometryState.fVertexLayout, |
| 869 | oldTexCoordOffsets, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 870 | &oldColorOffset, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 871 | &oldCoverageOffset, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 872 | &oldEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 873 | bool indexed = NULL != startIndex; |
| 874 | |
| 875 | int extraVertexOffset; |
| 876 | int extraIndexOffset; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 877 | this->setBuffers(indexed, &extraVertexOffset, &extraIndexOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 878 | |
| 879 | GrGLenum scalarType; |
| 880 | bool texCoordNorm; |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 881 | if (currLayout & kTextFormat_VertexLayoutBit) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 882 | scalarType = GrGLTextType; |
| 883 | texCoordNorm = GR_GL_TEXT_TEXTURE_NORMALIZED; |
| 884 | } else { |
| 885 | scalarType = GrGLType; |
| 886 | texCoordNorm = false; |
| 887 | } |
| 888 | |
| 889 | size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride; |
| 890 | *startVertex = 0; |
| 891 | if (indexed) { |
| 892 | *startIndex += extraIndexOffset; |
| 893 | } |
| 894 | |
| 895 | // all the Pointers must be set if any of these are true |
| 896 | bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || |
| 897 | vertexOffset != fHWGeometryState.fVertexOffset || |
| 898 | newStride != oldStride; |
| 899 | |
| 900 | // position and tex coord offsets change if above conditions are true |
| 901 | // or the type/normalization changed based on text vs nontext type coords. |
| 902 | bool posAndTexChange = allOffsetsChange || |
| 903 | (((GrGLTextType != GrGLType) || GR_GL_TEXT_TEXTURE_NORMALIZED) && |
| 904 | (kTextFormat_VertexLayoutBit & |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 905 | (fHWGeometryState.fVertexLayout ^ currLayout))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 906 | |
| 907 | if (posAndTexChange) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 908 | int idx = GrGLProgram::PositionAttributeIdx(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 909 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, false, newStride, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 910 | (GrGLvoid*)vertexOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 911 | fHWGeometryState.fVertexOffset = vertexOffset; |
| 912 | } |
| 913 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 914 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 915 | if (newTexCoordOffsets[t] > 0) { |
| 916 | GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 917 | int idx = GrGLProgram::TexCoordAttributeIdx(t); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 918 | if (oldTexCoordOffsets[t] <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 919 | GL_CALL(EnableVertexAttribArray(idx)); |
| 920 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 921 | newStride, texCoordOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 922 | } else if (posAndTexChange || |
| 923 | newTexCoordOffsets[t] != oldTexCoordOffsets[t]) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 924 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 925 | newStride, texCoordOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 926 | } |
| 927 | } else if (oldTexCoordOffsets[t] > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 928 | GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
| 932 | if (newColorOffset > 0) { |
| 933 | GrGLvoid* colorOffset = (int8_t*)(vertexOffset + newColorOffset); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 934 | int idx = GrGLProgram::ColorAttributeIdx(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 935 | if (oldColorOffset <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 936 | GL_CALL(EnableVertexAttribArray(idx)); |
| 937 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 938 | true, newStride, colorOffset)); |
| 939 | } else if (allOffsetsChange || newColorOffset != oldColorOffset) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 940 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 941 | true, newStride, colorOffset)); |
| 942 | } |
| 943 | } else if (oldColorOffset > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 944 | GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx())); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 945 | } |
| 946 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 947 | if (newCoverageOffset > 0) { |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 948 | GrGLvoid* coverageOffset = (int8_t*)(vertexOffset + newCoverageOffset); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 949 | int idx = GrGLProgram::CoverageAttributeIdx(); |
| 950 | if (oldCoverageOffset <= 0) { |
| 951 | GL_CALL(EnableVertexAttribArray(idx)); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 952 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 953 | true, newStride, coverageOffset)); |
| 954 | } else if (allOffsetsChange || newCoverageOffset != oldCoverageOffset) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 955 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 956 | true, newStride, coverageOffset)); |
| 957 | } |
| 958 | } else if (oldCoverageOffset > 0) { |
| 959 | GL_CALL(DisableVertexAttribArray(GrGLProgram::CoverageAttributeIdx())); |
| 960 | } |
| 961 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 962 | if (newEdgeOffset > 0) { |
| 963 | GrGLvoid* edgeOffset = (int8_t*)(vertexOffset + newEdgeOffset); |
| 964 | int idx = GrGLProgram::EdgeAttributeIdx(); |
| 965 | if (oldEdgeOffset <= 0) { |
| 966 | GL_CALL(EnableVertexAttribArray(idx)); |
| 967 | GL_CALL(VertexAttribPointer(idx, 4, scalarType, |
| 968 | false, newStride, edgeOffset)); |
| 969 | } else if (allOffsetsChange || newEdgeOffset != oldEdgeOffset) { |
| 970 | GL_CALL(VertexAttribPointer(idx, 4, scalarType, |
| 971 | false, newStride, edgeOffset)); |
| 972 | } |
| 973 | } else if (oldEdgeOffset > 0) { |
| 974 | GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx())); |
| 975 | } |
| 976 | |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 977 | fHWGeometryState.fVertexLayout = currLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 978 | fHWGeometryState.fArrayPtrsDirty = false; |
| 979 | } |
| 980 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 981 | namespace { |
| 982 | |
| 983 | void setup_custom_stage(GrGLProgram::ProgramDesc::StageDesc* stage, |
| 984 | const GrSamplerState& sampler, |
| 985 | GrCustomStage** customStages, |
| 986 | GrGLProgram* program, int index) { |
| 987 | GrCustomStage* customStage = sampler.getCustomStage(); |
| 988 | if (customStage) { |
| 989 | GrGLProgramStageFactory* factory = customStage->getGLFactory(); |
| 990 | stage->fCustomStageKey = factory->stageKey(customStage); |
| 991 | customStages[index] = customStage; |
| 992 | } else { |
| 993 | stage->fCustomStageKey = 0; |
| 994 | customStages[index] = NULL; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | } |
| 999 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1000 | void GrGpuGLShaders::buildProgram(GrPrimitiveType type, |
| 1001 | BlendOptFlags blendOpts, |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1002 | GrBlendCoeff dstCoeff, |
| 1003 | GrCustomStage** customStages) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1004 | ProgramDesc& desc = fCurrentProgram.fProgramDesc; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1005 | const GrDrawState& drawState = this->getDrawState(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1006 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1007 | // This should already have been caught |
| 1008 | GrAssert(!(kSkipDraw_BlendOptFlag & blendOpts)); |
| 1009 | |
| 1010 | bool skipCoverage = SkToBool(blendOpts & kEmitTransBlack_BlendOptFlag); |
| 1011 | |
| 1012 | bool skipColor = SkToBool(blendOpts & (kEmitTransBlack_BlendOptFlag | |
| 1013 | kEmitCoverage_BlendOptFlag)); |
| 1014 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1015 | // The descriptor is used as a cache key. Thus when a field of the |
| 1016 | // descriptor will not affect program generation (because of the vertex |
| 1017 | // layout in use or other descriptor field settings) it should be set |
| 1018 | // to a canonical value to avoid duplicate programs with different keys. |
| 1019 | |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 1020 | // Must initialize all fields or cache will have false negatives! |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 1021 | desc.fVertexLayout = this->getVertexLayout(); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 1022 | |
| 1023 | desc.fEmitsPointSize = kPoints_PrimitiveType == type; |
| 1024 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1025 | bool requiresAttributeColors = |
| 1026 | !skipColor && SkToBool(desc.fVertexLayout & kColor_VertexLayoutBit); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1027 | bool requiresAttributeCoverage = |
| 1028 | !skipCoverage && SkToBool(desc.fVertexLayout & |
| 1029 | kCoverage_VertexLayoutBit); |
| 1030 | |
| 1031 | // fColorInput/fCoverageInput records how colors are specified for the. |
| 1032 | // program. So we strip the bits from the layout to avoid false negatives |
| 1033 | // when searching for an existing program in the cache. |
| 1034 | desc.fVertexLayout &= ~(kColor_VertexLayoutBit | kCoverage_VertexLayoutBit); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 1035 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1036 | desc.fColorFilterXfermode = skipColor ? |
| 1037 | SkXfermode::kDst_Mode : |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1038 | drawState.getColorFilterMode(); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 1039 | |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1040 | desc.fColorMatrixEnabled = drawState.isStateFlagEnabled(GrDrawState::kColorMatrix_StateBit); |
| 1041 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1042 | // no reason to do edge aa or look at per-vertex coverage if coverage is |
| 1043 | // ignored |
| 1044 | if (skipCoverage) { |
| 1045 | desc.fVertexLayout &= ~(kEdge_VertexLayoutBit | |
| 1046 | kCoverage_VertexLayoutBit); |
| 1047 | } |
| 1048 | |
| 1049 | bool colorIsTransBlack = SkToBool(blendOpts & kEmitTransBlack_BlendOptFlag); |
| 1050 | bool colorIsSolidWhite = (blendOpts & kEmitCoverage_BlendOptFlag) || |
| 1051 | (!requiresAttributeColors && |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1052 | 0xffffffff == drawState.getColor()); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1053 | if (GR_AGGRESSIVE_SHADER_OPTS && colorIsTransBlack) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 1054 | desc.fColorInput = ProgramDesc::kTransBlack_ColorInput; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1055 | } else if (GR_AGGRESSIVE_SHADER_OPTS && colorIsSolidWhite) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 1056 | desc.fColorInput = ProgramDesc::kSolidWhite_ColorInput; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1057 | } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeColors) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 1058 | desc.fColorInput = ProgramDesc::kUniform_ColorInput; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1059 | } else { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 1060 | desc.fColorInput = ProgramDesc::kAttribute_ColorInput; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 1061 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1062 | |
| 1063 | bool covIsSolidWhite = !requiresAttributeCoverage && |
| 1064 | 0xffffffff == drawState.getCoverage(); |
| 1065 | |
| 1066 | if (skipCoverage) { |
| 1067 | desc.fCoverageInput = ProgramDesc::kTransBlack_ColorInput; |
| 1068 | } else if (covIsSolidWhite) { |
| 1069 | desc.fCoverageInput = ProgramDesc::kSolidWhite_ColorInput; |
| 1070 | } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeCoverage) { |
| 1071 | desc.fCoverageInput = ProgramDesc::kUniform_ColorInput; |
| 1072 | } else { |
| 1073 | desc.fCoverageInput = ProgramDesc::kAttribute_ColorInput; |
| 1074 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1075 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1076 | desc.fEdgeAANumEdges = skipCoverage ? 0 : drawState.getNumAAEdges(); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1077 | desc.fEdgeAAConcave = desc.fEdgeAANumEdges > 0 && |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1078 | drawState.isConcaveEdgeAAState(); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 1079 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1080 | int lastEnabledStage = -1; |
| 1081 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1082 | if (!skipCoverage && (desc.fVertexLayout & |
| 1083 | GrDrawTarget::kEdge_VertexLayoutBit)) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1084 | desc.fVertexEdgeType = drawState.getVertexEdgeType(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1085 | } else { |
| 1086 | // use canonical value when not set to avoid cache misses |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1087 | desc.fVertexEdgeType = GrDrawState::kHairLine_EdgeType; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1090 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1091 | StageDesc& stage = desc.fStages[s]; |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1092 | |
| 1093 | stage.fOptFlags = 0; |
| 1094 | stage.setEnabled(this->isStageEnabled(s)); |
| 1095 | |
| 1096 | bool skip = s < drawState.getFirstCoverageStage() ? skipColor : |
| 1097 | skipCoverage; |
| 1098 | |
| 1099 | if (!skip && stage.isEnabled()) { |
| 1100 | lastEnabledStage = s; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1101 | const GrGLTexture* texture = |
| 1102 | static_cast<const GrGLTexture*>(drawState.getTexture(s)); |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1103 | GrAssert(NULL != texture); |
| 1104 | const GrSamplerState& sampler = drawState.getSampler(s); |
| 1105 | // we matrix to invert when orientation is TopDown, so make sure |
| 1106 | // we aren't in that case before flagging as identity. |
| 1107 | if (TextureMatrixIsIdentity(texture, sampler)) { |
| 1108 | stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit; |
| 1109 | } else if (!sampler.getMatrix().hasPerspective()) { |
| 1110 | stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; |
| 1111 | } |
| 1112 | switch (sampler.getSampleMode()) { |
| 1113 | case GrSamplerState::kNormal_SampleMode: |
| 1114 | stage.fCoordMapping = StageDesc::kIdentity_CoordMapping; |
| 1115 | break; |
| 1116 | case GrSamplerState::kRadial_SampleMode: |
| 1117 | stage.fCoordMapping = StageDesc::kRadialGradient_CoordMapping; |
| 1118 | break; |
| 1119 | case GrSamplerState::kRadial2_SampleMode: |
| 1120 | if (sampler.radial2IsDegenerate()) { |
| 1121 | stage.fCoordMapping = |
| 1122 | StageDesc::kRadial2GradientDegenerate_CoordMapping; |
| 1123 | } else { |
| 1124 | stage.fCoordMapping = |
| 1125 | StageDesc::kRadial2Gradient_CoordMapping; |
| 1126 | } |
| 1127 | break; |
| 1128 | case GrSamplerState::kSweep_SampleMode: |
| 1129 | stage.fCoordMapping = StageDesc::kSweepGradient_CoordMapping; |
| 1130 | break; |
| 1131 | default: |
| 1132 | GrCrash("Unexpected sample mode!"); |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | switch (sampler.getFilter()) { |
| 1137 | // these both can use a regular texture2D() |
| 1138 | case GrSamplerState::kNearest_Filter: |
| 1139 | case GrSamplerState::kBilinear_Filter: |
| 1140 | stage.fFetchMode = StageDesc::kSingle_FetchMode; |
| 1141 | break; |
| 1142 | // performs 4 texture2D()s |
| 1143 | case GrSamplerState::k4x4Downsample_Filter: |
| 1144 | stage.fFetchMode = StageDesc::k2x2_FetchMode; |
| 1145 | break; |
| 1146 | // performs fKernelWidth texture2D()s |
| 1147 | case GrSamplerState::kConvolution_Filter: |
| 1148 | stage.fFetchMode = StageDesc::kConvolution_FetchMode; |
| 1149 | break; |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1150 | case GrSamplerState::kDilate_Filter: |
| 1151 | stage.fFetchMode = StageDesc::kDilate_FetchMode; |
| 1152 | break; |
| 1153 | case GrSamplerState::kErode_Filter: |
| 1154 | stage.fFetchMode = StageDesc::kErode_FetchMode; |
| 1155 | break; |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1156 | default: |
| 1157 | GrCrash("Unexpected filter!"); |
| 1158 | break; |
| 1159 | } |
| 1160 | |
| 1161 | if (sampler.hasTextureDomain()) { |
| 1162 | GrAssert(GrSamplerState::kClamp_WrapMode == |
| 1163 | sampler.getWrapX() && |
| 1164 | GrSamplerState::kClamp_WrapMode == |
| 1165 | sampler.getWrapY()); |
| 1166 | stage.fOptFlags |= StageDesc::kCustomTextureDomain_OptFlagBit; |
| 1167 | } |
| 1168 | |
| 1169 | stage.fInConfigFlags = 0; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1170 | if (!this->glCaps().textureSwizzleSupport()) { |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1171 | if (GrPixelConfigIsAlphaOnly(texture->config())) { |
| 1172 | // if we don't have texture swizzle support then |
epoger@google.com | 0048469 | 2012-04-30 19:02:08 +0000 | [diff] [blame] | 1173 | // the shader must do an alpha smear after reading |
| 1174 | // the texture |
| 1175 | stage.fInConfigFlags |= StageDesc::kSmearAlpha_InConfigFlag; |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1176 | } else if (sampler.swapsRAndB()) { |
| 1177 | stage.fInConfigFlags |= StageDesc::kSwapRAndB_InConfigFlag; |
| 1178 | } |
| 1179 | } |
| 1180 | if (GrPixelConfigIsUnpremultiplied(texture->config())) { |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1181 | // The shader generator assumes that color channels are bytes |
| 1182 | // when rounding. |
| 1183 | GrAssert(4 == GrBytesPerPixel(texture->config())); |
| 1184 | if (kUpOnWrite_DownOnRead_UnpremulConversion == |
| 1185 | fUnpremulConversion) { |
| 1186 | stage.fInConfigFlags |= |
| 1187 | StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag; |
| 1188 | } else { |
| 1189 | stage.fInConfigFlags |= |
| 1190 | StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag; |
| 1191 | } |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1194 | if (sampler.getFilter() == GrSamplerState::kConvolution_Filter || |
| 1195 | sampler.getFilter() == GrSamplerState::kDilate_Filter || |
| 1196 | sampler.getFilter() == GrSamplerState::kErode_Filter) { |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1197 | stage.fKernelWidth = sampler.getKernelWidth(); |
| 1198 | } else { |
| 1199 | stage.fKernelWidth = 0; |
| 1200 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1201 | |
| 1202 | setup_custom_stage(&stage, sampler, customStages, |
| 1203 | &fCurrentProgram, s); |
| 1204 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1205 | } else { |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1206 | stage.fOptFlags = 0; |
| 1207 | stage.fCoordMapping = (StageDesc::CoordMapping) 0; |
| 1208 | stage.fInConfigFlags = 0; |
| 1209 | stage.fFetchMode = (StageDesc::FetchMode) 0; |
| 1210 | stage.fKernelWidth = 0; |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1211 | stage.fCustomStageKey = 0; |
| 1212 | customStages[s] = NULL; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1213 | } |
| 1214 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1215 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1216 | if (GrPixelConfigIsUnpremultiplied(drawState.getRenderTarget()->config())) { |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1217 | // The shader generator assumes that color channels are bytes |
| 1218 | // when rounding. |
| 1219 | GrAssert(4 == GrBytesPerPixel(drawState.getRenderTarget()->config())); |
| 1220 | if (kUpOnWrite_DownOnRead_UnpremulConversion == fUnpremulConversion) { |
| 1221 | desc.fOutputConfig = |
| 1222 | ProgramDesc::kUnpremultiplied_RoundUp_OutputConfig; |
| 1223 | } else { |
| 1224 | desc.fOutputConfig = |
| 1225 | ProgramDesc::kUnpremultiplied_RoundDown_OutputConfig; |
| 1226 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1227 | } else { |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1228 | desc.fOutputConfig = ProgramDesc::kPremultiplied_OutputConfig; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1231 | desc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1232 | |
| 1233 | // currently the experimental GS will only work with triangle prims |
| 1234 | // (and it doesn't do anything other than pass through values from |
| 1235 | // the VS to the FS anyway). |
| 1236 | #if 0 && GR_GL_EXPERIMENTAL_GS |
| 1237 | desc.fExperimentalGS = this->getCaps().fGeometryShaderSupport; |
| 1238 | #endif |
| 1239 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1240 | // we want to avoid generating programs with different "first cov stage" |
| 1241 | // values when they would compute the same result. |
| 1242 | // We set field in the desc to kNumStages when either there are no |
| 1243 | // coverage stages or the distinction between coverage and color is |
| 1244 | // immaterial. |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 1245 | int firstCoverageStage = GrDrawState::kNumStages; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1246 | desc.fFirstCoverageStage = GrDrawState::kNumStages; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1247 | bool hasCoverage = drawState.getFirstCoverageStage() <= lastEnabledStage; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1248 | if (hasCoverage) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1249 | firstCoverageStage = drawState.getFirstCoverageStage(); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | // other coverage inputs |
| 1253 | if (!hasCoverage) { |
| 1254 | hasCoverage = |
| 1255 | desc.fEdgeAANumEdges || |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1256 | requiresAttributeCoverage || |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1257 | (desc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit); |
| 1258 | } |
| 1259 | |
| 1260 | if (hasCoverage) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1261 | // color filter is applied between color/coverage computation |
| 1262 | if (SkXfermode::kDst_Mode != desc.fColorFilterXfermode) { |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1263 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1266 | if (this->getCaps().fDualSourceBlendingSupport && |
| 1267 | !(blendOpts & (kEmitCoverage_BlendOptFlag | |
| 1268 | kCoverageAsAlpha_BlendOptFlag))) { |
| 1269 | if (kZero_BlendCoeff == dstCoeff) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1270 | // write the coverage value to second color |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1271 | desc.fDualSrcOutput = ProgramDesc::kCoverage_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1272 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1273 | } else if (kSA_BlendCoeff == dstCoeff) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1274 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially |
| 1275 | // cover |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1276 | desc.fDualSrcOutput = ProgramDesc::kCoverageISA_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1277 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1278 | } else if (kSC_BlendCoeff == dstCoeff) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1279 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially |
| 1280 | // cover |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1281 | desc.fDualSrcOutput = ProgramDesc::kCoverageISC_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1282 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1286 | } |