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], |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 22 | SkYUVColorSpace yuvColorSpace, |
| 23 | GrSamplerState::Filter filterMode); |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 24 | #ifdef SK_DEBUG |
Robert Phillips | ba5c439 | 2018-07-25 12:37:14 -0400 | [diff] [blame] | 25 | SkString dumpInfo() const override; |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 26 | #endif |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 27 | |
Robert Phillips | b651aac | 2019-03-15 12:18:49 -0400 | [diff] [blame] | 28 | SkYUVColorSpace yuvColorSpace() const { return fYUVColorSpace; } |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 29 | const SkYUVAIndex& yuvaIndex(int i) const { return fYUVAIndices[i]; } |
| 30 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 31 | GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src); |
| 32 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 33 | const char* name() const override { return "YUVtoRGBEffect"; } |
| 34 | |
| 35 | private: |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 36 | GrYUVtoRGBEffect(const sk_sp<GrTextureProxy> proxies[], const SkSize scales[], |
| 37 | const GrSamplerState::Filter filterModes[], int numPlanes, |
Robert Phillips | b651aac | 2019-03-15 12:18:49 -0400 | [diff] [blame] | 38 | const SkYUVAIndex yuvaIndices[4], SkYUVColorSpace yuvColorSpace) |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 39 | : INHERITED(kGrYUVtoRGBEffect_ClassID, kNone_OptimizationFlags) |
Robert Phillips | b651aac | 2019-03-15 12:18:49 -0400 | [diff] [blame] | 40 | , fYUVColorSpace(yuvColorSpace) { |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 41 | for (int i = 0; i < numPlanes; ++i) { |
| 42 | fSamplers[i].reset(std::move(proxies[i]), |
| 43 | GrSamplerState(GrSamplerState::WrapMode::kClamp, filterModes[i])); |
| 44 | fSamplerTransforms[i] = SkMatrix::MakeScale(scales[i].width(), scales[i].height()); |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 45 | fSamplerCoordTransforms[i] = |
| 46 | GrCoordTransform(fSamplerTransforms[i], fSamplers[i].proxy()); |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | this->setTextureSamplerCnt(numPlanes); |
| 50 | for (int i = 0; i < numPlanes; ++i) { |
| 51 | this->addCoordTransform(&fSamplerCoordTransforms[i]); |
| 52 | } |
| 53 | |
| 54 | memcpy(fYUVAIndices, yuvaIndices, sizeof(fYUVAIndices)); |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 55 | } |
| 56 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 57 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 58 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 59 | const TextureSampler& onTextureSampler(int) const override; |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 60 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 61 | |
| 62 | TextureSampler fSamplers[4]; |
| 63 | SkMatrix44 fSamplerTransforms[4]; |
| 64 | GrCoordTransform fSamplerCoordTransforms[4]; |
| 65 | SkYUVAIndex fYUVAIndices[4]; |
Robert Phillips | b651aac | 2019-03-15 12:18:49 -0400 | [diff] [blame] | 66 | SkYUVColorSpace fYUVColorSpace; |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 67 | |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 68 | typedef GrFragmentProcessor INHERITED; |
| 69 | }; |
| 70 | #endif |