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