Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 8 | #ifndef GrYUVtoRGBEffect_DEFINED |
| 9 | #define GrYUVtoRGBEffect_DEFINED |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 10 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 11 | #include "SkTypes.h" |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 12 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 13 | #include "GrFragmentProcessor.h" |
| 14 | #include "GrCoordTransform.h" |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 15 | |
| 16 | #include "SkYUVAIndex.h" |
| 17 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 18 | class GrYUVtoRGBEffect : public GrFragmentProcessor { |
| 19 | public: |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 20 | static std::unique_ptr<GrFragmentProcessor> Make(const sk_sp<GrTextureProxy> proxies[], |
| 21 | const SkYUVAIndex indices[4], |
| 22 | SkYUVColorSpace yuvColorSpace); |
Robert Phillips | ba5c439 | 2018-07-25 12:37:14 -0400 | [diff] [blame] | 23 | SkString dumpInfo() const override; |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 24 | |
Michael Ludwig | a427559 | 2018-08-31 10:52:47 -0400 | [diff] [blame] | 25 | const SkMatrix44& colorSpaceMatrix() const { return fColorSpaceMatrix; } |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 26 | const SkYUVAIndex& yuvaIndex(int i) const { return fYUVAIndices[i]; } |
| 27 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 28 | GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src); |
| 29 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 30 | const char* name() const override { return "YUVtoRGBEffect"; } |
| 31 | |
| 32 | private: |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 33 | GrYUVtoRGBEffect(const sk_sp<GrTextureProxy> proxies[], const SkSize scales[], |
| 34 | const GrSamplerState::Filter filterModes[], int numPlanes, |
| 35 | const SkYUVAIndex yuvaIndices[4], const SkMatrix44& colorSpaceMatrix) |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 36 | : INHERITED(kGrYUVtoRGBEffect_ClassID, kNone_OptimizationFlags) |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 37 | , fColorSpaceMatrix(colorSpaceMatrix) { |
| 38 | for (int i = 0; i < numPlanes; ++i) { |
| 39 | fSamplers[i].reset(std::move(proxies[i]), |
| 40 | GrSamplerState(GrSamplerState::WrapMode::kClamp, filterModes[i])); |
| 41 | fSamplerTransforms[i] = SkMatrix::MakeScale(scales[i].width(), scales[i].height()); |
| 42 | fSamplerCoordTransforms[i].reset(fSamplerTransforms[i], fSamplers[i].proxy(), true); |
| 43 | } |
| 44 | |
| 45 | this->setTextureSamplerCnt(numPlanes); |
| 46 | for (int i = 0; i < numPlanes; ++i) { |
| 47 | this->addCoordTransform(&fSamplerCoordTransforms[i]); |
| 48 | } |
| 49 | |
| 50 | memcpy(fYUVAIndices, yuvaIndices, sizeof(fYUVAIndices)); |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 51 | } |
| 52 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 53 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 54 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 55 | const TextureSampler& onTextureSampler(int) const override; |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 56 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame^] | 57 | |
| 58 | TextureSampler fSamplers[4]; |
| 59 | SkMatrix44 fSamplerTransforms[4]; |
| 60 | GrCoordTransform fSamplerCoordTransforms[4]; |
| 61 | SkYUVAIndex fYUVAIndices[4]; |
| 62 | SkMatrix44 fColorSpaceMatrix; |
| 63 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 64 | typedef GrFragmentProcessor INHERITED; |
| 65 | }; |
| 66 | #endif |