| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkComposeShader.h" | 10 #include "SkComposeShader.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 result += n; | 190 result += n; |
| 191 x += n; | 191 x += n; |
| 192 count -= n; | 192 count -= n; |
| 193 } while (count > 0); | 193 } while (count > 0); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 #if SK_SUPPORT_GPU | 197 #if SK_SUPPORT_GPU |
| 198 | 198 |
| 199 #include "SkGr.h" | |
| 200 #include "GrProcessor.h" | |
| 201 #include "gl/GrGLBlend.h" | 199 #include "gl/GrGLBlend.h" |
| 202 #include "gl/builders/GrGLProgramBuilder.h" | 200 #include "gl/builders/GrGLProgramBuilder.h" |
| 203 | 201 |
| 204 ///////////////////////////////////////////////////////////////////// | 202 ///////////////////////////////////////////////////////////////////// |
| 205 | 203 |
| 206 class GrComposeEffect : public GrFragmentProcessor { | |
| 207 public: | |
| 208 | |
| 209 static GrFragmentProcessor* Create(const GrFragmentProcessor* fpA, | |
| 210 const GrFragmentProcessor* fpB, | |
| 211 SkXfermode::Mode mode) { | |
| 212 return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); | |
| 213 } | |
| 214 const char* name() const override {return fName.c_str(); } | |
| 215 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | |
| 216 | |
| 217 SkXfermode::Mode getMode() const { return fMode; } | |
| 218 int getShaderAChildIndex() const { return fShaderAChildIndex; } | |
| 219 int getShaderBChildIndex() const { return fShaderBChildIndex; } | |
| 220 | |
| 221 protected: | |
| 222 bool onIsEqual(const GrFragmentProcessor&) const override; | |
| 223 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | |
| 224 | |
| 225 private: | |
| 226 GrComposeEffect(const GrFragmentProcessor* fpA, const GrFragmentProcessor* f
pB, | |
| 227 SkXfermode::Mode mode) | |
| 228 : fMode(mode) { | |
| 229 this->initClassID<GrComposeEffect>(); | |
| 230 fShaderAChildIndex = this->registerChildProcessor(fpA); | |
| 231 fShaderBChildIndex = this->registerChildProcessor(fpB); | |
| 232 fName.printf("Compose Shader <%s, %s> (Mode: %s)", fpA->name(), fpB->nam
e(), | |
| 233 SkXfermode::ModeName(fMode)); | |
| 234 } | |
| 235 | |
| 236 GrGLFragmentProcessor* onCreateGLInstance() const override; | |
| 237 | |
| 238 SkString fName; | |
| 239 int fShaderAChildIndex; | |
| 240 int fShaderBChildIndex; | |
| 241 SkXfermode::Mode fMode; | |
| 242 | |
| 243 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | |
| 244 | |
| 245 typedef GrFragmentProcessor INHERITED; | |
| 246 }; | |
| 247 | |
| 248 ///////////////////////////////////////////////////////////////////// | |
| 249 | |
| 250 class GrGLComposeEffect : public GrGLFragmentProcessor { | 204 class GrGLComposeEffect : public GrGLFragmentProcessor { |
| 251 public: | 205 public: |
| 252 GrGLComposeEffect(const GrProcessor& processor) { | 206 GrGLComposeEffect(const GrProcessor& processor) { |
| 253 const GrComposeEffect& cs = processor.cast<GrComposeEffect>(); | 207 const GrComposeEffect& cs = processor.cast<GrComposeEffect>(); |
| 254 fShaderAChildIndex = cs.getShaderAChildIndex(); | 208 fShaderAChildIndex = cs.getShaderAChildIndex(); |
| 255 fShaderBChildIndex = cs.getShaderBChildIndex(); | 209 fShaderBChildIndex = cs.getShaderBChildIndex(); |
| 256 fMode = cs.getMode(); | 210 fMode = cs.getMode(); |
| 257 } | 211 } |
| 258 | 212 |
| 259 void emitCode(EmitArgs&) override; | 213 void emitCode(EmitArgs&) override; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 283 do { | 237 do { |
| 284 fpB.reset(GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); | 238 fpB.reset(GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); |
| 285 SkASSERT(fpB); | 239 SkASSERT(fpB); |
| 286 } while (fpB.get()->numChildProcessors() != 0); | 240 } while (fpB.get()->numChildProcessors() != 0); |
| 287 | 241 |
| 288 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 242 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 289 d->fRandom->nextRangeU(0, SkXfermode::Mode::kLastCoeffMode)); | 243 d->fRandom->nextRangeU(0, SkXfermode::Mode::kLastCoeffMode)); |
| 290 return SkNEW_ARGS(GrComposeEffect, (fpA.get(), fpB.get(), mode)); | 244 return SkNEW_ARGS(GrComposeEffect, (fpA.get(), fpB.get(), mode)); |
| 291 } | 245 } |
| 292 | 246 |
| 247 GrFragmentProcessor* GrComposeEffect::Create(const GrFragmentProcessor* fpA, |
| 248 const GrFragmentProcessor* fpB, |
| 249 SkXfermode::Mode mode) { |
| 250 return SkNEW_ARGS(GrComposeEffect, (fpA, fpB, mode)); |
| 251 } |
| 252 |
| 253 GrComposeEffect::GrComposeEffect(const GrFragmentProcessor* fpA, const GrFragmen
tProcessor* fpB, |
| 254 SkXfermode::Mode mode) |
| 255 : fMode(mode) { |
| 256 this->initClassID<GrComposeEffect>(); |
| 257 fShaderAChildIndex = this->registerChildProcessor(fpA); |
| 258 fShaderBChildIndex = this->registerChildProcessor(fpB); |
| 259 fName.printf("Compose Shader (Mode: %s)", SkXfermode::ModeName(fMode)); |
| 260 } |
| 261 |
| 293 bool GrComposeEffect::onIsEqual(const GrFragmentProcessor& other) const { | 262 bool GrComposeEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 294 const GrComposeEffect& cs = other.cast<GrComposeEffect>(); | 263 const GrComposeEffect& cs = other.cast<GrComposeEffect>(); |
| 295 return fMode == cs.fMode; | 264 return fMode == cs.fMode; |
| 296 } | 265 } |
| 297 | 266 |
| 298 void GrComposeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 267 void GrComposeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
| 299 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 268 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 300 } | 269 } |
| 301 | 270 |
| 302 void GrComposeEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { | 271 void GrComposeEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (fMode) { | 364 if (fMode) { |
| 396 str->append(" Xfermode: "); | 365 str->append(" Xfermode: "); |
| 397 fMode->toString(str); | 366 fMode->toString(str); |
| 398 } | 367 } |
| 399 | 368 |
| 400 this->INHERITED::toString(str); | 369 this->INHERITED::toString(str); |
| 401 | 370 |
| 402 str->append(")"); | 371 str->append(")"); |
| 403 } | 372 } |
| 404 #endif | 373 #endif |
| OLD | NEW |