180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc.
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef Gr1DKernelEffect_DEFINED
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define Gr1DKernelEffect_DEFINED
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrSingleTextureEffect.h"
12363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger#include "SkMatrix.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Base class for 1D kernel effects. The kernel operates either in X or Y and
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * has a pixel radius. The kernel is specified in the src texture's space
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * and the kernel center is pinned to a texel's center. The radius specifies
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the number of texels on either side of the center texel in X or Y that are
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * read. Since the center pixel is also read, the total width is one larger than
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * two times the radius.
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
22363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass Gr1DKernelEffect : public GrSingleTextureEffect {
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum Direction {
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kX_Direction,
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kY_Direction,
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Gr1DKernelEffect(GrTexture* texture,
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                     Direction direction,
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                     int radius)
34363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        : GrSingleTextureEffect(texture, MakeDivByTextureWHMatrix(texture))
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        , fDirection(direction)
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        , fRadius(radius) {}
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual ~Gr1DKernelEffect() {};
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static int WidthFromRadius(int radius) { return 2 * radius + 1; }
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int radius() const { return fRadius; }
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int width() const { return WidthFromRadius(fRadius); }
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Direction direction() const { return fDirection; }
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Direction       fDirection;
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int             fRadius;
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef GrSingleTextureEffect INHERITED;
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
55