| 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 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual ~SkTable_ColorFilter() { | 39 virtual ~SkTable_ColorFilter() { |
| 40 SkDELETE(fBitmap); | 40 SkDELETE(fBitmap); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual bool asComponentTable(SkBitmap* table) const SK_OVERRIDE; | 43 virtual bool asComponentTable(SkBitmap* table) const SK_OVERRIDE; |
| 44 | 44 |
| 45 #if SK_SUPPORT_GPU | 45 #if SK_SUPPORT_GPU |
| 46 virtual GrEffect* asNewEffect(GrContext* context) const SK_OVERRIDE; | 46 virtual GrFragmentProcessor* asFragmentProcessor(GrContext* context) const S
K_OVERRIDE; |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 virtual void filterSpan(const SkPMColor src[], int count, | 49 virtual void filterSpan(const SkPMColor src[], int count, |
| 50 SkPMColor dst[]) const SK_OVERRIDE; | 50 SkPMColor dst[]) const SK_OVERRIDE; |
| 51 | 51 |
| 52 SK_TO_STRING_OVERRIDE() | 52 SK_TO_STRING_OVERRIDE() |
| 53 | 53 |
| 54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) | 54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) |
| 55 | 55 |
| 56 enum { | 56 enum { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 fBitmap = bmp; | 269 fBitmap = bmp; |
| 270 } | 270 } |
| 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 "GrProcessor.h" |
| 279 #include "GrTBackendEffectFactory.h" | 279 #include "GrTBackendProcessorFactory.h" |
| 280 #include "gl/GrGLEffect.h" | 280 #include "gl/GrGLProcessor.h" |
| 281 #include "gl/builders/GrGLProgramBuilder.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 GrFragmentProcessor { |
| 287 public: | 287 public: |
| 288 static GrEffect* Create(GrTexture* texture, unsigned flags) { | 288 static GrFragmentProcessor* Create(GrTexture* texture, unsigned flags) { |
| 289 return SkNEW_ARGS(ColorTableEffect, (texture, flags)); | 289 return SkNEW_ARGS(ColorTableEffect, (texture, flags)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 virtual ~ColorTableEffect(); | 292 virtual ~ColorTableEffect(); |
| 293 | 293 |
| 294 static const char* Name() { return "ColorTable"; } | 294 static const char* Name() { return "ColorTable"; } |
| 295 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 295 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 296 | 296 |
| 297 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 297 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 298 | 298 |
| 299 typedef GLColorTableEffect GLEffect; | 299 typedef GLColorTableEffect GLProcessor; |
| 300 | 300 |
| 301 private: | 301 private: |
| 302 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 302 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
| 303 | 303 |
| 304 explicit ColorTableEffect(GrTexture* texture, unsigned flags); | 304 explicit ColorTableEffect(GrTexture* texture, unsigned flags); |
| 305 | 305 |
| 306 GR_DECLARE_EFFECT_TEST; | 306 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 307 | 307 |
| 308 GrTextureAccess fTextureAccess; | 308 GrTextureAccess fTextureAccess; |
| 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 GrFragmentProcessor INHERITED; |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 class GLColorTableEffect : public GrGLEffect { | 315 class GLColorTableEffect : public GrGLFragmentProcessor { |
| 316 public: | 316 public: |
| 317 GLColorTableEffect(const GrBackendEffectFactory&, const GrEffect&); | 317 GLColorTableEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 318 | 318 |
| 319 virtual void emitCode(GrGLProgramBuilder*, | 319 virtual void emitCode(GrGLProgramBuilder*, |
| 320 const GrEffect&, | 320 const GrFragmentProcessor&, |
| 321 const GrEffectKey&, | 321 const GrProcessorKey&, |
| 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 GrEffect&) SK_OVER
RIDE {} | 327 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE {} |
| 328 | 328 |
| 329 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder* b)
{} | 329 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde
r* b) {} |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 | 332 |
| 333 typedef GrGLEffect INHERITED; | 333 typedef GrGLFragmentProcessor INHERITED; |
| 334 }; | 334 }; |
| 335 | 335 |
| 336 GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, co
nst GrEffect&) | 336 GLColorTableEffect::GLColorTableEffect(const GrBackendProcessorFactory& factory,
const GrProcessor&) |
| 337 : INHERITED(factory) { | 337 : INHERITED(factory) { |
| 338 } | 338 } |
| 339 | 339 |
| 340 void GLColorTableEffect::emitCode(GrGLProgramBuilder* builder, | 340 void GLColorTableEffect::emitCode(GrGLProgramBuilder* builder, |
| 341 const GrEffect&, | 341 const GrFragmentProcessor&, |
| 342 const GrEffectKey&, | 342 const GrProcessorKey&, |
| 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 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 351 if (NULL == inputColor) { | 351 if (NULL == inputColor) { |
| 352 // the input color is solid white (all ones). | 352 // the input color is solid white (all ones). |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 386 |
| 387 ColorTableEffect::ColorTableEffect(GrTexture* texture, unsigned flags) | 387 ColorTableEffect::ColorTableEffect(GrTexture* texture, unsigned flags) |
| 388 : fTextureAccess(texture, "a") | 388 : fTextureAccess(texture, "a") |
| 389 , fFlags(flags) { | 389 , fFlags(flags) { |
| 390 this->addTextureAccess(&fTextureAccess); | 390 this->addTextureAccess(&fTextureAccess); |
| 391 } | 391 } |
| 392 | 392 |
| 393 ColorTableEffect::~ColorTableEffect() { | 393 ColorTableEffect::~ColorTableEffect() { |
| 394 } | 394 } |
| 395 | 395 |
| 396 const GrBackendEffectFactory& ColorTableEffect::getFactory() const { | 396 const GrBackendFragmentProcessorFactory& ColorTableEffect::getFactory() const { |
| 397 return GrTBackendEffectFactory<ColorTableEffect>::getInstance(); | 397 return GrTBackendFragmentProcessorFactory<ColorTableEffect>::getInstance(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool ColorTableEffect::onIsEqual(const GrEffect& sBase) const { | 400 bool ColorTableEffect::onIsEqual(const GrProcessor& sBase) const { |
| 401 return this->texture(0) == sBase.texture(0); | 401 return this->texture(0) == sBase.texture(0); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void ColorTableEffect::getConstantColorComponents(GrColor* color, uint32_t* vali
dFlags) const { | 404 void ColorTableEffect::getConstantColorComponents(GrColor* color, uint32_t* vali
dFlags) const { |
| 405 // If we kept the table in the effect then we could actually run known input
s through the | 405 // If we kept the table in the effect then we could actually run known input
s through the |
| 406 // table. | 406 // table. |
| 407 if (fFlags & SkTable_ColorFilter::kR_Flag) { | 407 if (fFlags & SkTable_ColorFilter::kR_Flag) { |
| 408 *validFlags &= ~kR_GrColorComponentFlag; | 408 *validFlags &= ~kR_GrColorComponentFlag; |
| 409 } | 409 } |
| 410 if (fFlags & SkTable_ColorFilter::kG_Flag) { | 410 if (fFlags & SkTable_ColorFilter::kG_Flag) { |
| 411 *validFlags &= ~kG_GrColorComponentFlag; | 411 *validFlags &= ~kG_GrColorComponentFlag; |
| 412 } | 412 } |
| 413 if (fFlags & SkTable_ColorFilter::kB_Flag) { | 413 if (fFlags & SkTable_ColorFilter::kB_Flag) { |
| 414 *validFlags &= ~kB_GrColorComponentFlag; | 414 *validFlags &= ~kB_GrColorComponentFlag; |
| 415 } | 415 } |
| 416 if (fFlags & SkTable_ColorFilter::kA_Flag) { | 416 if (fFlags & SkTable_ColorFilter::kA_Flag) { |
| 417 *validFlags &= ~kA_GrColorComponentFlag; | 417 *validFlags &= ~kA_GrColorComponentFlag; |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 | 421 |
| 422 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
| 423 | 423 |
| 424 GR_DEFINE_EFFECT_TEST(ColorTableEffect); | 424 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect); |
| 425 | 425 |
| 426 GrEffect* ColorTableEffect::TestCreate(SkRandom* random, | 426 GrFragmentProcessor* ColorTableEffect::TestCreate(SkRandom* random, |
| 427 GrContext* context, | 427 GrContext* context, |
| 428 const GrDrawTargetCaps&, | 428 const GrDrawTargetCaps&, |
| 429 GrTexture* textures[]) { | 429 GrTexture* textures[]) { |
| 430 static unsigned kAllFlags = SkTable_ColorFilter::kR_Flag | SkTable_ColorFilt
er::kG_Flag | | 430 static unsigned kAllFlags = SkTable_ColorFilter::kR_Flag | SkTable_ColorFilt
er::kG_Flag | |
| 431 SkTable_ColorFilter::kB_Flag | SkTable_ColorFilt
er::kA_Flag; | 431 SkTable_ColorFilter::kB_Flag | SkTable_ColorFilt
er::kA_Flag; |
| 432 return ColorTableEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx]
, kAllFlags); | 432 return ColorTableEffect::Create(textures[GrProcessorUnitTest::kAlphaTextureI
dx], kAllFlags); |
| 433 } | 433 } |
| 434 | 434 |
| 435 GrEffect* SkTable_ColorFilter::asNewEffect(GrContext* context) const { | 435 GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* context
) const { |
| 436 SkBitmap bitmap; | 436 SkBitmap bitmap; |
| 437 GrEffect* effect = NULL; | 437 GrFragmentProcessor* fp = NULL; |
| 438 this->asComponentTable(&bitmap); | 438 this->asComponentTable(&bitmap); |
| 439 // passing NULL because this effect does no tiling or filtering. | 439 // passing NULL because this effect does no tiling or filtering. |
| 440 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, bitmap, NULL); | 440 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, bitmap, NULL); |
| 441 if (texture) { | 441 if (texture) { |
| 442 effect = ColorTableEffect::Create(texture, fFlags); | 442 fp = ColorTableEffect::Create(texture, fFlags); |
| 443 | 443 |
| 444 // Unlock immediately, this is not great, but we don't have a way of | 444 // Unlock immediately, this is not great, but we don't have a way of |
| 445 // knowing when else to unlock it currently. TODO: Remove this when | 445 // knowing when else to unlock it currently. TODO: Remove this when |
| 446 // unref becomes the unlock replacement for all types of textures. | 446 // unref becomes the unlock replacement for all types of textures. |
| 447 GrUnlockAndUnrefCachedBitmapTexture(texture); | 447 GrUnlockAndUnrefCachedBitmapTexture(texture); |
| 448 } | 448 } |
| 449 return effect; | 449 return fp; |
| 450 } | 450 } |
| 451 | 451 |
| 452 #endif // SK_SUPPORT_GPU | 452 #endif // SK_SUPPORT_GPU |
| 453 | 453 |
| 454 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
| 455 | 455 |
| 456 #ifdef SK_CPU_BENDIAN | 456 #ifdef SK_CPU_BENDIAN |
| 457 #else | 457 #else |
| 458 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) | 458 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) |
| 459 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) | 459 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 470 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 470 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
| 471 const uint8_t tableR[256], | 471 const uint8_t tableR[256], |
| 472 const uint8_t tableG[256], | 472 const uint8_t tableG[256], |
| 473 const uint8_t tableB[256]) { | 473 const uint8_t tableB[256]) { |
| 474 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); | 474 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); |
| 475 } | 475 } |
| 476 | 476 |
| 477 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 477 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
| 478 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 478 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
| 479 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 479 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |