• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
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 
8 #ifndef GrYUVtoRGBEffect_DEFINED
9 #define GrYUVtoRGBEffect_DEFINED
10 
11 #include "SkTypes.h"
12 
13 #include "GrFragmentProcessor.h"
14 #include "GrCoordTransform.h"
15 
16 #include "SkYUVAIndex.h"
17 
18 class GrYUVtoRGBEffect : public GrFragmentProcessor {
19 public:
20     static std::unique_ptr<GrFragmentProcessor> Make(const sk_sp<GrTextureProxy> proxies[],
21                                                      const SkYUVAIndex indices[4],
22                                                      SkYUVColorSpace yuvColorSpace,
23                                                      GrSamplerState::Filter filterMode);
24 #ifdef SK_DEBUG
25     SkString dumpInfo() const override;
26 #endif
27 
colorSpaceMatrix()28     const SkMatrix44& colorSpaceMatrix() const { return fColorSpaceMatrix; }
yuvaIndex(int i)29     const SkYUVAIndex& yuvaIndex(int i) const { return fYUVAIndices[i]; }
30 
31     GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src);
32     std::unique_ptr<GrFragmentProcessor> clone() const override;
name()33     const char* name() const override { return "YUVtoRGBEffect"; }
34 
35 private:
GrYUVtoRGBEffect(const sk_sp<GrTextureProxy> proxies[],const SkSize scales[],const GrSamplerState::Filter filterModes[],int numPlanes,const SkYUVAIndex yuvaIndices[4],const SkMatrix44 & colorSpaceMatrix)36     GrYUVtoRGBEffect(const sk_sp<GrTextureProxy> proxies[], const SkSize scales[],
37                      const GrSamplerState::Filter filterModes[], int numPlanes,
38                      const SkYUVAIndex yuvaIndices[4], const SkMatrix44& colorSpaceMatrix)
39             : INHERITED(kGrYUVtoRGBEffect_ClassID, kNone_OptimizationFlags)
40             , 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());
45             fSamplerCoordTransforms[i] =
46                     GrCoordTransform(fSamplerTransforms[i], fSamplers[i].proxy());
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));
55     }
56     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
57     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
58     bool onIsEqual(const GrFragmentProcessor&) const override;
59     const TextureSampler& onTextureSampler(int) const override;
60     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
61 
62     TextureSampler   fSamplers[4];
63     SkMatrix44       fSamplerTransforms[4];
64     GrCoordTransform fSamplerCoordTransforms[4];
65     SkYUVAIndex      fYUVAIndices[4];
66     SkMatrix44       fColorSpaceMatrix;
67 
68     typedef GrFragmentProcessor INHERITED;
69 };
70 #endif
71