| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkArithmeticMode_gpu.h" | 8 #include "SkArithmeticMode_gpu.h" |
| 9 | 9 |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); | 155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); |
| 156 | 156 |
| 157 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
| 158 // Xfer Processor | 158 // Xfer Processor |
| 159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
| 160 | 160 |
| 161 class ArithmeticXP : public GrXferProcessor { | 161 class ArithmeticXP : public GrXferProcessor { |
| 162 public: | 162 public: |
| 163 static GrXferProcessor* Create(float k1, float k2, float k3, float k4, bool
enforcePMColor, | 163 ArithmeticXP(const GrPipelineBuilder&, const DstTexture*, |
| 164 const DstTexture* dstTexture, bool willReadDs
tColor) { | 164 float k1, float k2, float k3, float k4, bool enforcePMColor); |
| 165 return SkNEW_ARGS(ArithmeticXP, (k1, k2, k3, k4, enforcePMColor, dstText
ure, | |
| 166 willReadDstColor)); | |
| 167 } | |
| 168 | |
| 169 ~ArithmeticXP() override {}; | |
| 170 | 165 |
| 171 const char* name() const override { return "Arithmetic"; } | 166 const char* name() const override { return "Arithmetic"; } |
| 172 | 167 |
| 173 GrGLXferProcessor* createGLInstance() const override; | 168 GrGLXferProcessor* createGLInstance() const override; |
| 174 | 169 |
| 175 bool hasSecondaryOutput() const override { return false; } | |
| 176 | |
| 177 float k1() const { return fK1; } | 170 float k1() const { return fK1; } |
| 178 float k2() const { return fK2; } | 171 float k2() const { return fK2; } |
| 179 float k3() const { return fK3; } | 172 float k3() const { return fK3; } |
| 180 float k4() const { return fK4; } | 173 float k4() const { return fK4; } |
| 181 bool enforcePMColor() const { return fEnforcePMColor; } | 174 bool enforcePMColor() const { return fEnforcePMColor; } |
| 182 | 175 |
| 183 private: | 176 private: |
| 184 ArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor, | |
| 185 const DstTexture*, bool willReadDstColor); | |
| 186 | |
| 187 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 177 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 188 const GrProcOptInfo& coveragePO
I, | 178 const GrProcOptInfo& coveragePO
I, |
| 189 bool doesStencilWrite, | 179 bool doesStencilWrite, |
| 190 GrColor* overrideColor, | 180 GrColor* overrideColor, |
| 191 const GrCaps& caps) override; | 181 const GrCaps& caps) override; |
| 192 | 182 |
| 193 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 183 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
| 194 | 184 |
| 195 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 185 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 196 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); | 186 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 }; | 244 }; |
| 255 | 245 |
| 256 GrGLProgramDataManager::UniformHandle fKUni; | 246 GrGLProgramDataManager::UniformHandle fKUni; |
| 257 bool fEnforcePMColor; | 247 bool fEnforcePMColor; |
| 258 | 248 |
| 259 typedef GrGLXferProcessor INHERITED; | 249 typedef GrGLXferProcessor INHERITED; |
| 260 }; | 250 }; |
| 261 | 251 |
| 262 /////////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////////// |
| 263 | 253 |
| 264 ArithmeticXP::ArithmeticXP(float k1, float k2, float k3, float k4, bool enforceP
MColor, | 254 ArithmeticXP::ArithmeticXP(const GrPipelineBuilder& builder, const DstTexture* d
stTexture, |
| 265 const DstTexture* dstTexture, bool willReadDstColor) | 255 float k1, float k2, float k3, float k4, bool enforceP
MColor) |
| 266 : INHERITED(dstTexture, willReadDstColor) | 256 : INHERITED(builder, dstTexture, true) |
| 267 , fK1(k1) | 257 , fK1(k1) |
| 268 , fK2(k2) | 258 , fK2(k2) |
| 269 , fK3(k3) | 259 , fK3(k3) |
| 270 , fK4(k4) | 260 , fK4(k4) |
| 271 , fEnforcePMColor(enforcePMColor) { | 261 , fEnforcePMColor(enforcePMColor) { |
| 272 this->initClassID<ArithmeticXP>(); | 262 this->initClassID<ArithmeticXP>(); |
| 273 } | 263 } |
| 274 | 264 |
| 275 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 265 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
| 276 GLArithmeticXP::GenKey(*this, caps, b); | 266 GLArithmeticXP::GenKey(*this, caps, b); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 291 /////////////////////////////////////////////////////////////////////////////// | 281 /////////////////////////////////////////////////////////////////////////////// |
| 292 | 282 |
| 293 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, | 283 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, |
| 294 bool enforcePMColor) | 284 bool enforcePMColor) |
| 295 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 285 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
| 296 this->initClassID<GrArithmeticXPFactory>(); | 286 this->initClassID<GrArithmeticXPFactory>(); |
| 297 } | 287 } |
| 298 | 288 |
| 299 GrXferProcessor* | 289 GrXferProcessor* |
| 300 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, | 290 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, |
| 291 const GrPipelineBuilder& builder, |
| 301 const GrProcOptInfo& colorPOI, | 292 const GrProcOptInfo& colorPOI, |
| 302 const GrProcOptInfo& coveragePOI, | 293 const GrProcOptInfo& coveragePOI, |
| 303 const DstTexture* dstTexture) const
{ | 294 const DstTexture* dstTexture) const
{ |
| 304 return ArithmeticXP::Create(fK1, fK2, fK3, fK4, fEnforcePMColor, dstTexture, | 295 return SkNEW_ARGS(ArithmeticXP, (builder, dstTexture, fK1, fK2, fK3, fK4, fE
nforcePMColor)); |
| 305 this->willReadDstColor(caps, colorPOI, coverageP
OI)); | |
| 306 } | 296 } |
| 307 | 297 |
| 308 | 298 |
| 309 void GrArithmeticXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP
OI, | 299 void GrArithmeticXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP
OI, |
| 310 InvariantBlendedColor* blen
dedColor) const { | 300 InvariantBlendedColor* blen
dedColor) const { |
| 311 blendedColor->fWillBlendWithDst = true; | 301 blendedColor->fWillBlendWithDst = true; |
| 312 | 302 |
| 313 // TODO: We could try to optimize this more. For example if fK1 and fK3 are
zero, then we won't | 303 // TODO: We could try to optimize this more. For example if fK1 and fK3 are
zero, then we won't |
| 314 // be blending the color with dst at all so we can know what the output colo
r is (up to the | 304 // be blending the color with dst at all so we can know what the output colo
r is (up to the |
| 315 // valid color components passed in). | 305 // valid color components passed in). |
| 316 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; | 306 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
| 317 } | 307 } |
| 318 | 308 |
| 319 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); | 309 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); |
| 320 | 310 |
| 321 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random, | 311 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random, |
| 322 GrContext*, | 312 GrContext*, |
| 323 const GrCaps&, | 313 const GrCaps&, |
| 324 GrTexture*[]) { | 314 GrTexture*[]) { |
| 325 float k1 = random->nextF(); | 315 float k1 = random->nextF(); |
| 326 float k2 = random->nextF(); | 316 float k2 = random->nextF(); |
| 327 float k3 = random->nextF(); | 317 float k3 = random->nextF(); |
| 328 float k4 = random->nextF(); | 318 float k4 = random->nextF(); |
| 329 bool enforcePMColor = random->nextBool(); | 319 bool enforcePMColor = random->nextBool(); |
| 330 | 320 |
| 331 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 321 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
| 332 } | 322 } |
| 333 | 323 |
| 334 #endif | 324 #endif |
| OLD | NEW |