blob: 1135b9b03c2e56db726afe8a836d6ac35013c2f9 [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],
22 SkYUVColorSpace yuvColorSpace);
Robert Phillipsba5c4392018-07-25 12:37:14 -040023 SkString dumpInfo() const override;
Robert Phillips94ade752018-10-09 12:32:31 -040024
Michael Ludwiga4275592018-08-31 10:52:47 -040025 const SkMatrix44& colorSpaceMatrix() const { return fColorSpaceMatrix; }
Robert Phillips94ade752018-10-09 12:32:31 -040026 const SkYUVAIndex& yuvaIndex(int i) const { return fYUVAIndices[i]; }
27
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050028 GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src);
29 std::unique_ptr<GrFragmentProcessor> clone() const override;
30 const char* name() const override { return "YUVtoRGBEffect"; }
31
32private:
Robert Phillips94ade752018-10-09 12:32:31 -040033 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 Nicholas7461a4a2017-12-21 14:18:01 -050036 : INHERITED(kGrYUVtoRGBEffect_ClassID, kNone_OptimizationFlags)
Robert Phillips94ade752018-10-09 12:32:31 -040037 , 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 Nicholas7461a4a2017-12-21 14:18:01 -050051 }
52 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
53 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
54 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -040055 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050056 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Robert Phillips94ade752018-10-09 12:32:31 -040057
58 TextureSampler fSamplers[4];
59 SkMatrix44 fSamplerTransforms[4];
60 GrCoordTransform fSamplerCoordTransforms[4];
61 SkYUVAIndex fYUVAIndices[4];
62 SkMatrix44 fColorSpaceMatrix;
63
Ethan Nicholas7461a4a2017-12-21 14:18:01 -050064 typedef GrFragmentProcessor INHERITED;
65};
66#endif