Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2017 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 in uniform sampler2D image;
      9 in half4x4 matrix;
     10 
     11 @constructorParams {
     12     GrSamplerState samplerParams
     13 }
     14 
     15 @coordTransform(image) {
     16     matrix
     17 }
     18 
     19 @samplerParams(image) {
     20     samplerParams
     21 }
     22 
     23 @make {
     24     static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
     25                                                      const SkMatrix& matrix) {
     26         return std::unique_ptr<GrFragmentProcessor>(
     27             new GrSimpleTextureEffect(std::move(proxy), matrix,
     28                     GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kNearest)));
     29     }
     30 
     31     /* clamp mode */
     32     static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
     33                                                      const SkMatrix& matrix,
     34                                                      GrSamplerState::Filter filter) {
     35         return std::unique_ptr<GrFragmentProcessor>(
     36             new GrSimpleTextureEffect(std::move(proxy), matrix,
     37                                       GrSamplerState(GrSamplerState::WrapMode::kClamp, filter)));
     38      }
     39 
     40     static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
     41                                                      const SkMatrix& matrix,
     42                                                      const GrSamplerState& p) {
     43         return std::unique_ptr<GrFragmentProcessor>(
     44             new GrSimpleTextureEffect(std::move(proxy), matrix, p));
     45     }
     46 }
     47 
     48 @optimizationFlags {
     49     ModulateForSamplerOptFlags(image->config(),
     50             samplerParams.wrapModeX() == GrSamplerState::WrapMode::kClampToBorder ||
     51             samplerParams.wrapModeY() == GrSamplerState::WrapMode::kClampToBorder)
     52 }
     53 
     54 void main() {
     55     sk_OutColor = sk_InColor * texture(image, sk_TransformedCoords2D[0]);
     56 }
     57 
     58 @test(testData) {
     59     int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
     60                                                : GrProcessorUnitTest::kAlphaTextureIdx;
     61     GrSamplerState::WrapMode wrapModes[2];
     62     GrTest::TestWrapModes(testData->fRandom, wrapModes);
     63     if (!testData->caps()->npotTextureTileSupport()) {
     64         // Performing repeat sampling on npot textures will cause asserts on HW
     65         // that lacks support.
     66         wrapModes[0] = GrSamplerState::WrapMode::kClamp;
     67         wrapModes[1] = GrSamplerState::WrapMode::kClamp;
     68     }
     69 
     70     GrSamplerState params(wrapModes, testData->fRandom->nextBool()
     71                                                                ? GrSamplerState::Filter::kBilerp
     72                                                                : GrSamplerState::Filter::kNearest);
     73 
     74     const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
     75     return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
     76 }
     77