| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorMatrixFilterRowMajor255.h" | 8 #include "SkColorMatrixFilterRowMajor255.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkNx.h" | 10 #include "SkNx.h" |
| 11 #include "SkPM4fPriv.h" |
| 11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkRefCnt.h" |
| 14 #include "SkString.h" |
| 15 #include "SkUnPreMultiply.h" |
| 12 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
| 13 #include "SkUnPreMultiply.h" | |
| 14 #include "SkString.h" | |
| 15 #include "SkPM4fPriv.h" | |
| 16 | 17 |
| 17 static void transpose(float dst[20], const float src[20]) { | 18 static void transpose(float dst[20], const float src[20]) { |
| 18 const float* srcR = src + 0; | 19 const float* srcR = src + 0; |
| 19 const float* srcG = src + 5; | 20 const float* srcG = src + 5; |
| 20 const float* srcB = src + 10; | 21 const float* srcB = src + 10; |
| 21 const float* srcA = src + 15; | 22 const float* srcA = src + 15; |
| 22 | 23 |
| 23 for (int i = 0; i < 20; i += 4) { | 24 for (int i = 0; i < 20; i += 4) { |
| 24 dst[i + 0] = *srcR++; | 25 dst[i + 0] = *srcR++; |
| 25 dst[i + 1] = *srcG++; | 26 dst[i + 1] = *srcG++; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 #if SK_SUPPORT_GPU | 241 #if SK_SUPPORT_GPU |
| 241 #include "GrFragmentProcessor.h" | 242 #include "GrFragmentProcessor.h" |
| 242 #include "GrInvariantOutput.h" | 243 #include "GrInvariantOutput.h" |
| 243 #include "glsl/GrGLSLFragmentProcessor.h" | 244 #include "glsl/GrGLSLFragmentProcessor.h" |
| 244 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 245 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 245 #include "glsl/GrGLSLProgramDataManager.h" | 246 #include "glsl/GrGLSLProgramDataManager.h" |
| 246 #include "glsl/GrGLSLUniformHandler.h" | 247 #include "glsl/GrGLSLUniformHandler.h" |
| 247 | 248 |
| 248 class ColorMatrixEffect : public GrFragmentProcessor { | 249 class ColorMatrixEffect : public GrFragmentProcessor { |
| 249 public: | 250 public: |
| 250 static const GrFragmentProcessor* Create(const SkScalar matrix[20]) { | 251 static sk_sp<GrFragmentProcessor> Make(const SkScalar matrix[20]) { |
| 251 return new ColorMatrixEffect(matrix); | 252 return sk_sp<GrFragmentProcessor>(new ColorMatrixEffect(matrix)); |
| 252 } | 253 } |
| 253 | 254 |
| 254 const char* name() const override { return "Color Matrix"; } | 255 const char* name() const override { return "Color Matrix"; } |
| 255 | 256 |
| 256 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 257 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 257 | 258 |
| 258 class GLSLProcessor : public GrGLSLFragmentProcessor { | 259 class GLSLProcessor : public GrGLSLFragmentProcessor { |
| 259 public: | 260 public: |
| 260 // this class always generates the same code. | 261 // this class always generates the same code. |
| 261 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} | 262 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 GrInvariantOutput::kWill_ReadInput); | 381 GrInvariantOutput::kWill_ReadInput); |
| 381 } | 382 } |
| 382 | 383 |
| 383 SkScalar fMatrix[20]; | 384 SkScalar fMatrix[20]; |
| 384 | 385 |
| 385 typedef GrFragmentProcessor INHERITED; | 386 typedef GrFragmentProcessor INHERITED; |
| 386 }; | 387 }; |
| 387 | 388 |
| 388 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorMatrixEffect); | 389 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorMatrixEffect); |
| 389 | 390 |
| 390 const GrFragmentProcessor* ColorMatrixEffect::TestCreate(GrProcessorTestData* d)
{ | 391 sk_sp<GrFragmentProcessor> ColorMatrixEffect::TestCreate(GrProcessorTestData* d)
{ |
| 391 SkScalar colorMatrix[20]; | 392 SkScalar colorMatrix[20]; |
| 392 for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix); ++i) { | 393 for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix); ++i) { |
| 393 colorMatrix[i] = d->fRandom->nextSScalar1(); | 394 colorMatrix[i] = d->fRandom->nextSScalar1(); |
| 394 } | 395 } |
| 395 return ColorMatrixEffect::Create(colorMatrix); | 396 return ColorMatrixEffect::Make(colorMatrix); |
| 396 } | 397 } |
| 397 | 398 |
| 398 const GrFragmentProcessor* SkColorMatrixFilterRowMajor255::asFragmentProcessor(G
rContext*) const { | 399 sk_sp<GrFragmentProcessor> SkColorMatrixFilterRowMajor255::asFragmentProcessor(G
rContext*) const { |
| 399 return ColorMatrixEffect::Create(fMatrix); | 400 return ColorMatrixEffect::Make(fMatrix); |
| 400 } | 401 } |
| 401 | 402 |
| 402 #endif | 403 #endif |
| 403 | 404 |
| 404 #ifndef SK_IGNORE_TO_STRING | 405 #ifndef SK_IGNORE_TO_STRING |
| 405 void SkColorMatrixFilterRowMajor255::toString(SkString* str) const { | 406 void SkColorMatrixFilterRowMajor255::toString(SkString* str) const { |
| 406 str->append("SkColorMatrixFilterRowMajor255: "); | 407 str->append("SkColorMatrixFilterRowMajor255: "); |
| 407 | 408 |
| 408 str->append("matrix: ("); | 409 str->append("matrix: ("); |
| 409 for (int i = 0; i < 20; ++i) { | 410 for (int i = 0; i < 20; ++i) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 428 SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(const SkScalar row[5]) { | 429 SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(const SkScalar row[5]) { |
| 429 SkASSERT(row); | 430 SkASSERT(row); |
| 430 auto cf = sk_make_sp<SkColorMatrixFilterRowMajor255>(); | 431 auto cf = sk_make_sp<SkColorMatrixFilterRowMajor255>(); |
| 431 static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't
match"); | 432 static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't
match"); |
| 432 for (int i = 0; i < 4; ++i) { | 433 for (int i = 0; i < 4; ++i) { |
| 433 memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5); | 434 memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5); |
| 434 } | 435 } |
| 435 cf->initState(); | 436 cf->initState(); |
| 436 return cf; | 437 return cf; |
| 437 } | 438 } |
| OLD | NEW |