| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkTableColorFilter.h" | 9 #include "SkTableColorFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 #include "gl/builders/GrGLProgramBuilder.h" | 341 #include "gl/builders/GrGLProgramBuilder.h" |
| 342 | 342 |
| 343 class ColorTableEffect : public GrFragmentProcessor { | 343 class ColorTableEffect : public GrFragmentProcessor { |
| 344 public: | 344 public: |
| 345 static GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap, unsi
gned flags); | 345 static GrFragmentProcessor* Create(GrContext* context, SkBitmap bitmap, unsi
gned flags); |
| 346 | 346 |
| 347 virtual ~ColorTableEffect(); | 347 virtual ~ColorTableEffect(); |
| 348 | 348 |
| 349 const char* name() const override { return "ColorTable"; } | 349 const char* name() const override { return "ColorTable"; } |
| 350 | 350 |
| 351 GrGLFragmentProcessor* createGLInstance() const override; | |
| 352 | |
| 353 const GrTextureStripAtlas* atlas() const { return fAtlas; } | 351 const GrTextureStripAtlas* atlas() const { return fAtlas; } |
| 354 int atlasRow() const { return fRow; } | 352 int atlasRow() const { return fRow; } |
| 355 | 353 |
| 356 private: | 354 private: |
| 355 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 356 |
| 357 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 357 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 358 | 358 |
| 359 bool onIsEqual(const GrFragmentProcessor&) const override; | 359 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 360 | 360 |
| 361 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 361 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 362 | 362 |
| 363 ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atlas, int row, un
signed flags); | 363 ColorTableEffect(GrTexture* texture, GrTextureStripAtlas* atlas, int row, un
signed flags); |
| 364 | 364 |
| 365 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 365 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 366 | 366 |
| 367 GrTextureAccess fTextureAccess; | 367 GrTextureAccess fTextureAccess; |
| 368 | 368 |
| 369 // currently not used in shader code, just to assist onComputeInvariantOutpu
t(). | 369 // currently not used in shader code, just to assist onComputeInvariantOutpu
t(). |
| 370 unsigned fFlags; | 370 unsigned fFlags; |
| 371 | 371 |
| 372 GrTextureStripAtlas* fAtlas; | 372 GrTextureStripAtlas* fAtlas; |
| 373 int fRow; | 373 int fRow; |
| 374 | 374 |
| 375 typedef GrFragmentProcessor INHERITED; | 375 typedef GrFragmentProcessor INHERITED; |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 class GLColorTableEffect : public GrGLFragmentProcessor { | 378 class GLColorTableEffect : public GrGLFragmentProcessor { |
| 379 public: | 379 public: |
| 380 GLColorTableEffect(const GrProcessor&); | 380 GLColorTableEffect(const GrProcessor&); |
| 381 | 381 |
| 382 virtual void emitCode(EmitArgs&) override; | 382 virtual void emitCode(EmitArgs&) override; |
| 383 | 383 |
| 384 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 384 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der* b) {} |
| 385 | 385 |
| 386 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der* b) {} | 386 protected: |
| 387 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 387 | 388 |
| 388 private: | 389 private: |
| 389 UniformHandle fRGBAYValuesUni; | 390 UniformHandle fRGBAYValuesUni; |
| 390 typedef GrGLFragmentProcessor INHERITED; | 391 typedef GrGLFragmentProcessor INHERITED; |
| 391 }; | 392 }; |
| 392 | 393 |
| 393 GLColorTableEffect::GLColorTableEffect(const GrProcessor&) { | 394 GLColorTableEffect::GLColorTableEffect(const GrProcessor&) { |
| 394 } | 395 } |
| 395 | 396 |
| 396 void GLColorTableEffect::setData(const GrGLProgramDataManager& pdm, const GrProc
essor& proc) { | 397 void GLColorTableEffect::onSetData(const GrGLProgramDataManager& pdm, const GrPr
ocessor& proc) { |
| 397 // The textures are organized in a strip where the rows are ordered a, r, g,
b. | 398 // The textures are organized in a strip where the rows are ordered a, r, g,
b. |
| 398 float rgbaYValues[4]; | 399 float rgbaYValues[4]; |
| 399 const ColorTableEffect& cte = proc.cast<ColorTableEffect>(); | 400 const ColorTableEffect& cte = proc.cast<ColorTableEffect>(); |
| 400 if (cte.atlas()) { | 401 if (cte.atlas()) { |
| 401 SkScalar yDelta = cte.atlas()->getNormalizedTexelHeight(); | 402 SkScalar yDelta = cte.atlas()->getNormalizedTexelHeight(); |
| 402 rgbaYValues[3] = cte.atlas()->getYOffset(cte.atlasRow()) + SK_ScalarHalf
* yDelta; | 403 rgbaYValues[3] = cte.atlas()->getYOffset(cte.atlasRow()) + SK_ScalarHalf
* yDelta; |
| 403 rgbaYValues[0] = rgbaYValues[3] + yDelta; | 404 rgbaYValues[0] = rgbaYValues[3] + yDelta; |
| 404 rgbaYValues[1] = rgbaYValues[0] + yDelta; | 405 rgbaYValues[1] = rgbaYValues[0] + yDelta; |
| 405 rgbaYValues[2] = rgbaYValues[1] + yDelta; | 406 rgbaYValues[2] = rgbaYValues[1] + yDelta; |
| 406 } else { | 407 } else { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::createGLInstance() const { | 509 GrGLFragmentProcessor* ColorTableEffect::onCreateGLInstance() const { |
| 509 return SkNEW_ARGS(GLColorTableEffect, (*this)); | 510 return SkNEW_ARGS(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 |
| 515 // same row. | 516 // same row. |
| 516 const ColorTableEffect& that = other.cast<ColorTableEffect>(); | 517 const ColorTableEffect& that = other.cast<ColorTableEffect>(); |
| 517 SkASSERT(SkToBool(fAtlas) == SkToBool(that.fAtlas)); | 518 SkASSERT(SkToBool(fAtlas) == SkToBool(that.fAtlas)); |
| 518 // Ok to always do this comparison since both would be -1 if non-atlased. | 519 // Ok to always do this comparison since both would be -1 if non-atlased. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 613 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], |
| 613 const uint8_t tableR[256], | 614 const uint8_t tableR[256], |
| 614 const uint8_t tableG[256], | 615 const uint8_t tableG[256], |
| 615 const uint8_t tableB[256]) { | 616 const uint8_t tableB[256]) { |
| 616 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); | 617 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); |
| 617 } | 618 } |
| 618 | 619 |
| 619 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 620 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
| 620 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 621 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
| 621 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 622 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |