| OLD | NEW |
| 1 | 1 |
| 2 #include "SkBitmap.h" | 2 #include "SkBitmap.h" |
| 3 #include "SkTableColorFilter.h" | 3 #include "SkTableColorFilter.h" |
| 4 #include "SkColorPriv.h" | 4 #include "SkColorPriv.h" |
| 5 #include "SkReadBuffer.h" | 5 #include "SkReadBuffer.h" |
| 6 #include "SkWriteBuffer.h" | 6 #include "SkWriteBuffer.h" |
| 7 #include "SkUnPreMultiply.h" | 7 #include "SkUnPreMultiply.h" |
| 8 #include "SkString.h" | 8 #include "SkString.h" |
| 9 | 9 |
| 10 class SkTable_ColorFilter : public SkColorFilter { | 10 class SkTable_ColorFilter : public SkColorFilter { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 *table = *fBitmap; | 271 *table = *fBitmap; |
| 272 } | 272 } |
| 273 return true; | 273 return true; |
| 274 } | 274 } |
| 275 | 275 |
| 276 #if SK_SUPPORT_GPU | 276 #if SK_SUPPORT_GPU |
| 277 | 277 |
| 278 #include "GrEffect.h" | 278 #include "GrEffect.h" |
| 279 #include "GrTBackendEffectFactory.h" | 279 #include "GrTBackendEffectFactory.h" |
| 280 #include "gl/GrGLEffect.h" | 280 #include "gl/GrGLEffect.h" |
| 281 #include "gl/GrGLShaderBuilder.h" | 281 #include "gl/builders/GrGLProgramBuilder.h" |
| 282 #include "SkGr.h" | 282 #include "SkGr.h" |
| 283 | 283 |
| 284 class GLColorTableEffect; | 284 class GLColorTableEffect; |
| 285 | 285 |
| 286 class ColorTableEffect : public GrEffect { | 286 class ColorTableEffect : public GrEffect { |
| 287 public: | 287 public: |
| 288 static GrEffect* Create(GrTexture* texture, unsigned flags) { | 288 static GrEffect* Create(GrTexture* texture, unsigned flags) { |
| 289 return SkNEW_ARGS(ColorTableEffect, (texture, flags)); | 289 return SkNEW_ARGS(ColorTableEffect, (texture, flags)); |
| 290 } | 290 } |
| 291 | 291 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 309 unsigned fFlags; // currently not used in shader code, just to assist | 309 unsigned fFlags; // currently not used in shader code, just to assist |
| 310 // getConstantColorComponents(). | 310 // getConstantColorComponents(). |
| 311 | 311 |
| 312 typedef GrEffect INHERITED; | 312 typedef GrEffect INHERITED; |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 class GLColorTableEffect : public GrGLEffect { | 315 class GLColorTableEffect : public GrGLEffect { |
| 316 public: | 316 public: |
| 317 GLColorTableEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 317 GLColorTableEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 318 | 318 |
| 319 virtual void emitCode(GrGLShaderBuilder*, | 319 virtual void emitCode(GrGLProgramBuilder*, |
| 320 const GrDrawEffect&, | 320 const GrDrawEffect&, |
| 321 const GrEffectKey&, | 321 const GrEffectKey&, |
| 322 const char* outputColor, | 322 const char* outputColor, |
| 323 const char* inputColor, | 323 const char* inputColor, |
| 324 const TransformedCoordsArray&, | 324 const TransformedCoordsArray&, |
| 325 const TextureSamplerArray&) SK_OVERRIDE; | 325 const TextureSamplerArray&) SK_OVERRIDE; |
| 326 | 326 |
| 327 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 327 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 328 | 328 |
| 329 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*
b) {} | 329 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*
b) {} |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 | 332 |
| 333 typedef GrGLEffect INHERITED; | 333 typedef GrGLEffect INHERITED; |
| 334 }; | 334 }; |
| 335 | 335 |
| 336 GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, co
nst GrDrawEffect&) | 336 GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, co
nst GrDrawEffect&) |
| 337 : INHERITED(factory) { | 337 : INHERITED(factory) { |
| 338 } | 338 } |
| 339 | 339 |
| 340 void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder, | 340 void GLColorTableEffect::emitCode(GrGLProgramBuilder* builder, |
| 341 const GrDrawEffect&, | 341 const GrDrawEffect&, |
| 342 const GrEffectKey&, | 342 const GrEffectKey&, |
| 343 const char* outputColor, | 343 const char* outputColor, |
| 344 const char* inputColor, | 344 const char* inputColor, |
| 345 const TransformedCoordsArray&, | 345 const TransformedCoordsArray&, |
| 346 const TextureSamplerArray& samplers) { | 346 const TextureSamplerArray& samplers) { |
| 347 | 347 |
| 348 static const float kColorScaleFactor = 255.0f / 256.0f; | 348 static const float kColorScaleFactor = 255.0f / 256.0f; |
| 349 static const float kColorOffsetFactor = 1.0f / 512.0f; | 349 static const float kColorOffsetFactor = 1.0f / 512.0f; |
| 350 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 350 if (NULL == inputColor) { | 351 if (NULL == inputColor) { |
| 351 // the input color is solid white (all ones). | 352 // the input color is solid white (all ones). |
| 352 static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor; | 353 static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor; |
| 353 builder->fsCodeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n", | 354 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n", |
| 354 kMaxValue, kMaxValue, kMaxValue, kMaxValue); | 355 kMaxValue, kMaxValue, kMaxValue, kMaxValue); |
| 355 | 356 |
| 356 } else { | 357 } else { |
| 357 builder->fsCodeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", i
nputColor); | 358 fsBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", i
nputColor); |
| 358 builder->fsCodeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, non
ZeroAlpha);\n", inputColor); | 359 fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, non
ZeroAlpha);\n", inputColor); |
| 359 builder->fsCodeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n
", | 360 fsBuilder->codeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n
", |
| 360 kColorScaleFactor, | 361 kColorScaleFactor, |
| 361 kColorOffsetFactor, kColorOffsetFactor, | 362 kColorOffsetFactor, kColorOffsetFactor, |
| 362 kColorOffsetFactor, kColorOffsetFactor); | 363 kColorOffsetFactor, kColorOffsetFactor); |
| 363 } | 364 } |
| 364 | 365 |
| 365 builder->fsCodeAppendf("\t\t%s.a = ", outputColor); | 366 fsBuilder->codeAppendf("\t\t%s.a = ", outputColor); |
| 366 builder->fsAppendTextureLookup(samplers[0], "vec2(coord.a, 0.125)"); | 367 fsBuilder->appendTextureLookup(samplers[0], "vec2(coord.a, 0.125)"); |
| 367 builder->fsCodeAppend(";\n"); | 368 fsBuilder->codeAppend(";\n"); |
| 368 | 369 |
| 369 builder->fsCodeAppendf("\t\t%s.r = ", outputColor); | 370 fsBuilder->codeAppendf("\t\t%s.r = ", outputColor); |
| 370 builder->fsAppendTextureLookup(samplers[0], "vec2(coord.r, 0.375)"); | 371 fsBuilder->appendTextureLookup(samplers[0], "vec2(coord.r, 0.375)"); |
| 371 builder->fsCodeAppend(";\n"); | 372 fsBuilder->codeAppend(";\n"); |
| 372 | 373 |
| 373 builder->fsCodeAppendf("\t\t%s.g = ", outputColor); | 374 fsBuilder->codeAppendf("\t\t%s.g = ", outputColor); |
| 374 builder->fsAppendTextureLookup(samplers[0], "vec2(coord.g, 0.625)"); | 375 fsBuilder->appendTextureLookup(samplers[0], "vec2(coord.g, 0.625)"); |
| 375 builder->fsCodeAppend(";\n"); | 376 fsBuilder->codeAppend(";\n"); |
| 376 | 377 |
| 377 builder->fsCodeAppendf("\t\t%s.b = ", outputColor); | 378 fsBuilder->codeAppendf("\t\t%s.b = ", outputColor); |
| 378 builder->fsAppendTextureLookup(samplers[0], "vec2(coord.b, 0.875)"); | 379 fsBuilder->appendTextureLookup(samplers[0], "vec2(coord.b, 0.875)"); |
| 379 builder->fsCodeAppend(";\n"); | 380 fsBuilder->codeAppend(";\n"); |
| 380 | 381 |
| 381 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor); | 382 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor); |
| 382 } | 383 } |
| 383 | 384 |
| 384 /////////////////////////////////////////////////////////////////////////////// | 385 /////////////////////////////////////////////////////////////////////////////// |
| 385 | 386 |
| 386 ColorTableEffect::ColorTableEffect(GrTexture* texture, unsigned flags) | 387 ColorTableEffect::ColorTableEffect(GrTexture* texture, unsigned flags) |
| 387 : fTextureAccess(texture, "a") | 388 : fTextureAccess(texture, "a") |
| 388 , fFlags(flags) { | 389 , fFlags(flags) { |
| 389 this->addTextureAccess(&fTextureAccess); | 390 this->addTextureAccess(&fTextureAccess); |
| 390 } | 391 } |
| 391 | 392 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 470 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
| 470 const uint8_t tableR[256], | 471 const uint8_t tableR[256], |
| 471 const uint8_t tableG[256], | 472 const uint8_t tableG[256], |
| 472 const uint8_t tableB[256]) { | 473 const uint8_t tableB[256]) { |
| 473 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); | 474 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); |
| 474 } | 475 } |
| 475 | 476 |
| 476 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 477 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
| 477 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 478 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
| 478 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 479 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |