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 "SkTableColorFilter.h" | 8 #include "SkTableColorFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB); | 329 return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB); |
330 } | 330 } |
331 | 331 |
332 #if SK_SUPPORT_GPU | 332 #if SK_SUPPORT_GPU |
333 | 333 |
334 #include "GrFragmentProcessor.h" | 334 #include "GrFragmentProcessor.h" |
335 #include "GrInvariantOutput.h" | 335 #include "GrInvariantOutput.h" |
336 #include "SkGr.h" | 336 #include "SkGr.h" |
337 #include "effects/GrTextureStripAtlas.h" | 337 #include "effects/GrTextureStripAtlas.h" |
338 #include "gl/GrGLFragmentProcessor.h" | 338 #include "gl/GrGLFragmentProcessor.h" |
339 #include "gl/builders/GrGLProgramBuilder.h" | 339 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 340 #include "glsl/GrGLSLProgramBuilder.h" |
340 #include "glsl/GrGLSLProgramDataManager.h" | 341 #include "glsl/GrGLSLProgramDataManager.h" |
341 | 342 |
342 class ColorTableEffect : public GrFragmentProcessor { | 343 class ColorTableEffect : public GrFragmentProcessor { |
343 public: | 344 public: |
344 static const GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap
, unsigned flags); | 345 static const GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap
, unsigned flags); |
345 | 346 |
346 virtual ~ColorTableEffect(); | 347 virtual ~ColorTableEffect(); |
347 | 348 |
348 const char* name() const override { return "ColorTable"; } | 349 const char* name() const override { return "ColorTable"; } |
349 | 350 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 pdm.set4fv(fRGBAYValuesUni, 1, rgbaYValues); | 413 pdm.set4fv(fRGBAYValuesUni, 1, rgbaYValues); |
413 } | 414 } |
414 | 415 |
415 void GLColorTableEffect::emitCode(EmitArgs& args) { | 416 void GLColorTableEffect::emitCode(EmitArgs& args) { |
416 const char* yoffsets; | 417 const char* yoffsets; |
417 fRGBAYValuesUni = args.fBuilder->addUniform(GrGLSLFPBuilder::kFragment_Visib
ility, | 418 fRGBAYValuesUni = args.fBuilder->addUniform(GrGLSLFPBuilder::kFragment_Visib
ility, |
418 kVec4f_GrSLType, kDefault_GrSLPr
ecision, | 419 kVec4f_GrSLType, kDefault_GrSLPr
ecision, |
419 "yoffsets", &yoffsets); | 420 "yoffsets", &yoffsets); |
420 static const float kColorScaleFactor = 255.0f / 256.0f; | 421 static const float kColorScaleFactor = 255.0f / 256.0f; |
421 static const float kColorOffsetFactor = 1.0f / 512.0f; | 422 static const float kColorOffsetFactor = 1.0f / 512.0f; |
422 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 423 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
423 if (nullptr == args.fInputColor) { | 424 if (nullptr == args.fInputColor) { |
424 // the input color is solid white (all ones). | 425 // the input color is solid white (all ones). |
425 static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor; | 426 static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor; |
426 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n", | 427 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n", |
427 kMaxValue, kMaxValue, kMaxValue, kMaxValue); | 428 kMaxValue, kMaxValue, kMaxValue, kMaxValue); |
428 | 429 |
429 } else { | 430 } else { |
430 fsBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", a
rgs.fInputColor); | 431 fsBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", a
rgs.fInputColor); |
431 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, non
ZeroAlpha);\n", | 432 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, non
ZeroAlpha);\n", |
432 args.fInputColor); | 433 args.fInputColor); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 this->addTextureAccess(&fTextureAccess); | 495 this->addTextureAccess(&fTextureAccess); |
495 } | 496 } |
496 | 497 |
497 ColorTableEffect::~ColorTableEffect() { | 498 ColorTableEffect::~ColorTableEffect() { |
498 if (fAtlas) { | 499 if (fAtlas) { |
499 fAtlas->unlockRow(fRow); | 500 fAtlas->unlockRow(fRow); |
500 } | 501 } |
501 } | 502 } |
502 | 503 |
503 void ColorTableEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 504 void ColorTableEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
504 GrProcessorKeyBuilder* b) const { | 505 GrProcessorKeyBuilder* b) const { |
505 GLColorTableEffect::GenKey(*this, caps, b); | 506 GLColorTableEffect::GenKey(*this, caps, b); |
506 } | 507 } |
507 | 508 |
508 GrGLFragmentProcessor* ColorTableEffect::onCreateGLInstance() const { | 509 GrGLFragmentProcessor* ColorTableEffect::onCreateGLInstance() const { |
509 return new GLColorTableEffect(*this); | 510 return new GLColorTableEffect(*this); |
510 } | 511 } |
511 | 512 |
512 bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { | 513 bool ColorTableEffect::onIsEqual(const GrFragmentProcessor& other) const { |
513 // For non-atlased instances, the texture (compared by base class) is suffic
ient to | 514 // For non-atlased instances, the texture (compared by base class) is suffic
ient to |
514 // differentiate different tables. For atlased instances we ensure they are
using the | 515 // differentiate different tables. For atlased instances we ensure they are
using the |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 598 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
598 const uint8_t tableR[256], | 599 const uint8_t tableR[256], |
599 const uint8_t tableG[256], | 600 const uint8_t tableG[256], |
600 const uint8_t tableB[256]) { | 601 const uint8_t tableB[256]) { |
601 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); | 602 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); |
602 } | 603 } |
603 | 604 |
604 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 605 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
605 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 606 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
606 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 607 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |