OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkBlitRow.h" | 8 #include "SkBlitRow.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { | 117 SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { |
118 SkColor color = buffer.readColor(); | 118 SkColor color = buffer.readColor(); |
119 SkXfermode::Mode mode = (SkXfermode::Mode)buffer.readUInt(); | 119 SkXfermode::Mode mode = (SkXfermode::Mode)buffer.readUInt(); |
120 return SkColorFilter::CreateModeFilter(color, mode); | 120 return SkColorFilter::CreateModeFilter(color, mode); |
121 } | 121 } |
122 | 122 |
123 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
124 #if SK_SUPPORT_GPU | 124 #if SK_SUPPORT_GPU |
125 #include "GrBlend.h" | 125 #include "GrBlend.h" |
126 #include "GrFragmentProcessor.h" | 126 #include "GrFragmentProcessor.h" |
| 127 #include "GrInvariantOutput.h" |
127 #include "GrProcessorUnitTest.h" | 128 #include "GrProcessorUnitTest.h" |
128 #include "GrTBackendProcessorFactory.h" | 129 #include "GrTBackendProcessorFactory.h" |
129 #include "gl/GrGLProcessor.h" | 130 #include "gl/GrGLProcessor.h" |
130 #include "gl/builders/GrGLProgramBuilder.h" | 131 #include "gl/builders/GrGLProgramBuilder.h" |
131 #include "SkGr.h" | 132 #include "SkGr.h" |
132 | 133 |
133 namespace { | 134 namespace { |
134 /** | 135 /** |
135 * A definition of blend equation for one coefficient. Generates a | 136 * A definition of blend equation for one coefficient. Generates a |
136 * blend_coeff * value "expression". | 137 * blend_coeff * value "expression". |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 private: | 275 private: |
275 ModeColorFilterEffect(GrColor color, SkXfermode::Mode mode) | 276 ModeColorFilterEffect(GrColor color, SkXfermode::Mode mode) |
276 : fMode(mode), | 277 : fMode(mode), |
277 fColor(color) {} | 278 fColor(color) {} |
278 | 279 |
279 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { | 280 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { |
280 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); | 281 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); |
281 return fMode == s.fMode && fColor == s.fColor; | 282 return fMode == s.fMode && fColor == s.fColor; |
282 } | 283 } |
283 | 284 |
284 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE; | 285 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
285 | 286 |
286 SkXfermode::Mode fMode; | 287 SkXfermode::Mode fMode; |
287 GrColor fColor; | 288 GrColor fColor; |
288 | 289 |
289 typedef GrFragmentProcessor INHERITED; | 290 typedef GrFragmentProcessor INHERITED; |
290 }; | 291 }; |
291 | 292 |
292 namespace { | 293 namespace { |
293 | 294 |
294 /** Function color_component_to_int tries to reproduce the GLSL rounding. The sp
ec doesn't specify | 295 /** Function color_component_to_int tries to reproduce the GLSL rounding. The sp
ec doesn't specify |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 uint32_t getValidComponents() const { return fFlags; } | 366 uint32_t getValidComponents() const { return fFlags; } |
366 | 367 |
367 typedef MaskedColorExpr AExpr; | 368 typedef MaskedColorExpr AExpr; |
368 private: | 369 private: |
369 float fColor[4]; | 370 float fColor[4]; |
370 uint32_t fFlags; | 371 uint32_t fFlags; |
371 }; | 372 }; |
372 | 373 |
373 } | 374 } |
374 | 375 |
375 void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) con
st { | 376 void ModeColorFilterEffect::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { |
376 float inputColor[4]; | 377 float inputColor[4]; |
377 GrColorToRGBAFloat(inout->color(), inputColor); | 378 GrColorToRGBAFloat(inout->color(), inputColor); |
378 float filterColor[4]; | 379 float filterColor[4]; |
379 GrColorToRGBAFloat(fColor, filterColor); | 380 GrColorToRGBAFloat(fColor, filterColor); |
380 MaskedColorExpr result = | 381 MaskedColorExpr result = |
381 color_filter_expression(fMode, | 382 color_filter_expression(fMode, |
382 MaskedColorExpr(filterColor, kRGBA_GrColorCompon
entFlags), | 383 MaskedColorExpr(filterColor, kRGBA_GrColorCompon
entFlags), |
383 MaskedColorExpr(inputColor, inout->validFlags())
); | 384 MaskedColorExpr(inputColor, inout->validFlags())
); |
384 | 385 |
385 // Check if we will use the input color | 386 // Check if we will use the input color |
386 SkXfermode::Coeff dstCoeff; | 387 SkXfermode::Coeff dstCoeff; |
387 SkXfermode::Coeff srcCoeff; | 388 SkXfermode::Coeff srcCoeff; |
388 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); | 389 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); |
389 InvariantOutput::ReadInput readInput = InvariantOutput::kWill_ReadInput; | 390 GrInvariantOutput::ReadInput readInput = GrInvariantOutput::kWill_ReadInput; |
390 // These could be calculated from the blend equation with template trickery.
. | 391 // These could be calculated from the blend equation with template trickery.
. |
391 if (SkXfermode::kZero_Coeff == dstCoeff && | 392 if (SkXfermode::kZero_Coeff == dstCoeff && |
392 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { | 393 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { |
393 readInput = InvariantOutput::kWillNot_ReadInput; | 394 readInput = GrInvariantOutput::kWillNot_ReadInput; |
394 } | 395 } |
395 inout->setToOther(result.getValidComponents(), result.getColor(), readInput)
; | 396 inout->setToOther(result.getValidComponents(), result.getColor(), readInput)
; |
396 } | 397 } |
397 | 398 |
398 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); | 399 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); |
399 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, | 400 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, |
400 GrContext*, | 401 GrContext*, |
401 const GrDrawTargetCaps&, | 402 const GrDrawTargetCaps&, |
402 GrTexture*[]) { | 403 GrTexture*[]) { |
403 SkXfermode::Mode mode = SkXfermode::kDst_Mode; | 404 SkXfermode::Mode mode = SkXfermode::kDst_Mode; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), | 551 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), |
551 SkIntToScalar(SkColorGetG(add)), | 552 SkIntToScalar(SkColorGetG(add)), |
552 SkIntToScalar(SkColorGetB(add)), | 553 SkIntToScalar(SkColorGetB(add)), |
553 0); | 554 0); |
554 return SkColorMatrixFilter::Create(matrix); | 555 return SkColorMatrixFilter::Create(matrix); |
555 } | 556 } |
556 | 557 |
557 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) | 558 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) |
558 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) | 559 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) |
559 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 560 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |