blob: 3d94402ad318991a1288b62212d943165ca99c63 [file] [log] [blame]
Ethan Nicholas7461a4a2017-12-21 14:18:01 -05001/*
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05002 * Copyright 2018 Google Inc.
Ethan Nicholas7461a4a2017-12-21 14:18:01 -05003 *
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 Nicholas7461a4a2017-12-21 14:18:01 -05008#ifndef GrYUVtoRGBEffect_DEFINED
9#define GrYUVtoRGBEffect_DEFINED
Robert Phillips94ade752018-10-09 12:32:31 -040010
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050011#include "SkTypes.h"
Robert Phillips94ade752018-10-09 12:32:31 -040012
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050013#include "GrFragmentProcessor.h"
14#include "GrCoordTransform.h"
Robert Phillips94ade752018-10-09 12:32:31 -040015
16#include "SkYUVAIndex.h"
17
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050018class GrYUVtoRGBEffect : public GrFragmentProcessor {
19public:
Robert Phillips94ade752018-10-09 12:32:31 -040020 static std::unique_ptr<GrFragmentProcessor> Make(const sk_sp<GrTextureProxy> proxies[],
21 const SkYUVAIndex indices[4],
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040022 SkYUVColorSpace yuvColorSpace,
23 GrSamplerState::Filter filterMode);
Brian Osman9a390ac2018-11-12 09:47:48 -050024#ifdef SK_DEBUG
Robert Phillipsba5c4392018-07-25 12:37:14 -040025 SkString dumpInfo() const override;
Brian Osman9a390ac2018-11-12 09:47:48 -050026#endif
Robert Phillips94ade752018-10-09 12:32:31 -040027
Michael Ludwiga4275592018-08-31 10:52:47 -040028 const SkMatrix44& colorSpaceMatrix() const { return fColorSpaceMatrix; }
Robert Phillips94ade752018-10-09 12:32:31 -040029 const SkYUVAIndex& yuvaIndex(int i) const { return fYUVAIndices[i]; }
30
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050031 GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src);
32 std::unique_ptr<GrFragmentProcessor> clone() const override;
33 const char* name() const override { return "YUVtoRGBEffect"; }
34
35private:
Robert Phillips94ade752018-10-09 12:32:31 -040036 GrYUVtoRGBEffect(const sk_sp<GrTextureProxy> proxies[], const SkSize scales[],
37 const GrSamplerState::Filter filterModes[], int numPlanes,
38 const SkYUVAIndex yuvaIndices[4], const SkMatrix44& colorSpaceMatrix)
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050039 : INHERITED(kGrYUVtoRGBEffect_ClassID, kNone_OptimizationFlags)
Robert Phillips94ade752018-10-09 12:32:31 -040040 , fColorSpaceMatrix(colorSpaceMatrix) {
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 Salomon246bc3d2018-12-06 15:33:02 -050045 fSamplerCoordTransforms[i] =
46 GrCoordTransform(fSamplerTransforms[i], fSamplers[i].proxy());
Robert Phillips94ade752018-10-09 12:32:31 -040047 }
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 Nicholas7461a4a2017-12-21 14:18:01 -050055 }
56 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
57 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
58 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -040059 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050060 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Robert Phillips94ade752018-10-09 12:32:31 -040061
62 TextureSampler fSamplers[4];
63 SkMatrix44 fSamplerTransforms[4];
64 GrCoordTransform fSamplerCoordTransforms[4];
65 SkYUVAIndex fYUVAIndices[4];
66 SkMatrix44 fColorSpaceMatrix;
67
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050068 typedef GrFragmentProcessor INHERITED;
69};
70#endif