gfx/skia/trunk/src/core/SkBitmapProcState.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkBitmapProcState.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,238 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2007 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkBitmapProcState_DEFINED
    1.14 +#define SkBitmapProcState_DEFINED
    1.15 +
    1.16 +#include "SkBitmap.h"
    1.17 +#include "SkBitmapFilter.h"
    1.18 +#include "SkMatrix.h"
    1.19 +#include "SkPaint.h"
    1.20 +#include "SkScaledImageCache.h"
    1.21 +
    1.22 +#define FractionalInt_IS_64BIT
    1.23 +
    1.24 +#ifdef FractionalInt_IS_64BIT
    1.25 +    typedef SkFixed48    SkFractionalInt;
    1.26 +    #define SkScalarToFractionalInt(x)  SkScalarToFixed48(x)
    1.27 +    #define SkFractionalIntToFixed(x)   SkFixed48ToFixed(x)
    1.28 +    #define SkFixedToFractionalInt(x)   SkFixedToFixed48(x)
    1.29 +    #define SkFractionalIntToInt(x)     SkFixed48ToInt(x)
    1.30 +#else
    1.31 +    typedef SkFixed    SkFractionalInt;
    1.32 +    #define SkScalarToFractionalInt(x)  SkScalarToFixed(x)
    1.33 +    #define SkFractionalIntToFixed(x)   (x)
    1.34 +    #define SkFixedToFractionalInt(x)   (x)
    1.35 +    #define SkFractionalIntToInt(x)     ((x) >> 16)
    1.36 +#endif
    1.37 +
    1.38 +class SkPaint;
    1.39 +struct SkConvolutionProcs;
    1.40 +
    1.41 +struct SkBitmapProcState {
    1.42 +
    1.43 +    SkBitmapProcState(): fScaledCacheID(NULL), fBitmapFilter(NULL) {}
    1.44 +    ~SkBitmapProcState();
    1.45 +
    1.46 +    typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y,
    1.47 +                                 SkPMColor[], int count);
    1.48 +
    1.49 +    typedef void (*ShaderProc16)(const SkBitmapProcState&, int x, int y,
    1.50 +                                 uint16_t[], int count);
    1.51 +
    1.52 +    typedef void (*MatrixProc)(const SkBitmapProcState&,
    1.53 +                               uint32_t bitmapXY[],
    1.54 +                               int count,
    1.55 +                               int x, int y);
    1.56 +
    1.57 +    typedef void (*SampleProc32)(const SkBitmapProcState&,
    1.58 +                                 const uint32_t[],
    1.59 +                                 int count,
    1.60 +                                 SkPMColor colors[]);
    1.61 +
    1.62 +    typedef void (*SampleProc16)(const SkBitmapProcState&,
    1.63 +                                 const uint32_t[],
    1.64 +                                 int count,
    1.65 +                                 uint16_t colors[]);
    1.66 +
    1.67 +    typedef U16CPU (*FixedTileProc)(SkFixed);   // returns 0..0xFFFF
    1.68 +    typedef U16CPU (*FixedTileLowBitsProc)(SkFixed, int);   // returns 0..0xF
    1.69 +    typedef U16CPU (*IntTileProc)(int value, int count);   // returns 0..count-1
    1.70 +
    1.71 +    const SkBitmap*     fBitmap;            // chooseProcs - orig or scaled
    1.72 +    SkMatrix            fInvMatrix;         // chooseProcs
    1.73 +    SkMatrix::MapXYProc fInvProc;           // chooseProcs
    1.74 +
    1.75 +    SkFractionalInt     fInvSxFractionalInt;
    1.76 +    SkFractionalInt     fInvKyFractionalInt;
    1.77 +
    1.78 +    FixedTileProc       fTileProcX;         // chooseProcs
    1.79 +    FixedTileProc       fTileProcY;         // chooseProcs
    1.80 +    FixedTileLowBitsProc fTileLowBitsProcX; // chooseProcs
    1.81 +    FixedTileLowBitsProc fTileLowBitsProcY; // chooseProcs
    1.82 +    IntTileProc         fIntTileProcY;      // chooseProcs
    1.83 +    SkFixed             fFilterOneX;
    1.84 +    SkFixed             fFilterOneY;
    1.85 +
    1.86 +    SkPMColor           fPaintPMColor;      // chooseProcs - A8 config
    1.87 +    SkFixed             fInvSx;             // chooseProcs
    1.88 +    SkFixed             fInvKy;             // chooseProcs
    1.89 +    uint16_t            fAlphaScale;        // chooseProcs
    1.90 +    uint8_t             fInvType;           // chooseProcs
    1.91 +    uint8_t             fTileModeX;         // CONSTRUCTOR
    1.92 +    uint8_t             fTileModeY;         // CONSTRUCTOR
    1.93 +    uint8_t             fFilterLevel;       // chooseProcs
    1.94 +
    1.95 +    /** The shader will let us know when we can release some of our resources
    1.96 +      * like scaled bitmaps.
    1.97 +      */
    1.98 +
    1.99 +    void endContext();
   1.100 +
   1.101 +    /** Platforms implement this, and can optionally overwrite only the
   1.102 +        following fields:
   1.103 +
   1.104 +        fShaderProc32
   1.105 +        fShaderProc16
   1.106 +        fMatrixProc
   1.107 +        fSampleProc32
   1.108 +        fSampleProc32
   1.109 +
   1.110 +        They will already have valid function pointers, so a platform that does
   1.111 +        not have an accelerated version can just leave that field as is. A valid
   1.112 +        implementation can do nothing (see SkBitmapProcState_opts_none.cpp)
   1.113 +     */
   1.114 +    void platformProcs();
   1.115 +
   1.116 +    /** Platforms can also optionally overwrite the convolution functions
   1.117 +        if we have SIMD versions of them.
   1.118 +      */
   1.119 +
   1.120 +    void platformConvolutionProcs(SkConvolutionProcs*);
   1.121 +
   1.122 +    /** Given the byte size of the index buffer to be passed to the matrix proc,
   1.123 +        return the maximum number of resulting pixels that can be computed
   1.124 +        (i.e. the number of SkPMColor values to be written by the sample proc).
   1.125 +        This routine takes into account that filtering and scale-vs-affine
   1.126 +        affect the amount of buffer space needed.
   1.127 +
   1.128 +        Only valid to call after chooseProcs (setContext) has been called. It is
   1.129 +        safe to call this inside the shader's shadeSpan() method.
   1.130 +     */
   1.131 +    int maxCountForBufferSize(size_t bufferSize) const;
   1.132 +
   1.133 +    // If a shader proc is present, then the corresponding matrix/sample procs
   1.134 +    // are ignored
   1.135 +    ShaderProc32 getShaderProc32() const { return fShaderProc32; }
   1.136 +    ShaderProc16 getShaderProc16() const { return fShaderProc16; }
   1.137 +
   1.138 +    SkBitmapFilter* getBitmapFilter() const { return fBitmapFilter; }
   1.139 +
   1.140 +#ifdef SK_DEBUG
   1.141 +    MatrixProc getMatrixProc() const;
   1.142 +#else
   1.143 +    MatrixProc getMatrixProc() const { return fMatrixProc; }
   1.144 +#endif
   1.145 +    SampleProc32 getSampleProc32() const { return fSampleProc32; }
   1.146 +    SampleProc16 getSampleProc16() const { return fSampleProc16; }
   1.147 +
   1.148 +private:
   1.149 +    friend class SkBitmapProcShader;
   1.150 +
   1.151 +    ShaderProc32        fShaderProc32;      // chooseProcs
   1.152 +    ShaderProc16        fShaderProc16;      // chooseProcs
   1.153 +    // These are used if the shaderproc is NULL
   1.154 +    MatrixProc          fMatrixProc;        // chooseProcs
   1.155 +    SampleProc32        fSampleProc32;      // chooseProcs
   1.156 +    SampleProc16        fSampleProc16;      // chooseProcs
   1.157 +
   1.158 +    SkBitmap            fOrigBitmap;        // CONSTRUCTOR
   1.159 +    SkBitmap            fScaledBitmap;      // chooseProcs
   1.160 +
   1.161 +    SkScaledImageCache::ID* fScaledCacheID;
   1.162 +
   1.163 +    MatrixProc chooseMatrixProc(bool trivial_matrix);
   1.164 +    bool chooseProcs(const SkMatrix& inv, const SkPaint&);
   1.165 +    ShaderProc32 chooseShaderProc32();
   1.166 +
   1.167 +    // returns false if we did not try to scale the image. In that case, we
   1.168 +    // will need to "lock" its pixels some other way.
   1.169 +    bool possiblyScaleImage();
   1.170 +
   1.171 +    // returns false if we failed to "lock" the pixels at all. Typically this
   1.172 +    // means we have to abort the shader.
   1.173 +    bool lockBaseBitmap();
   1.174 +
   1.175 +    SkBitmapFilter* fBitmapFilter;
   1.176 +
   1.177 +    // If supported, sets fShaderProc32 and fShaderProc16 and returns true,
   1.178 +    // otherwise returns false.
   1.179 +    bool setBitmapFilterProcs();
   1.180 +
   1.181 +    // Return false if we failed to setup for fast translate (e.g. overflow)
   1.182 +    bool setupForTranslate();
   1.183 +
   1.184 +#ifdef SK_DEBUG
   1.185 +    static void DebugMatrixProc(const SkBitmapProcState&,
   1.186 +                                uint32_t[], int count, int x, int y);
   1.187 +#endif
   1.188 +};
   1.189 +
   1.190 +/*  Macros for packing and unpacking pairs of 16bit values in a 32bit uint.
   1.191 +    Used to allow access to a stream of uint16_t either one at a time, or
   1.192 +    2 at a time by unpacking a uint32_t
   1.193 + */
   1.194 +#ifdef SK_CPU_BENDIAN
   1.195 +    #define PACK_TWO_SHORTS(pri, sec) ((pri) << 16 | (sec))
   1.196 +    #define UNPACK_PRIMARY_SHORT(packed)    ((uint32_t)(packed) >> 16)
   1.197 +    #define UNPACK_SECONDARY_SHORT(packed)  ((packed) & 0xFFFF)
   1.198 +#else
   1.199 +    #define PACK_TWO_SHORTS(pri, sec) ((pri) | ((sec) << 16))
   1.200 +    #define UNPACK_PRIMARY_SHORT(packed)    ((packed) & 0xFFFF)
   1.201 +    #define UNPACK_SECONDARY_SHORT(packed)  ((uint32_t)(packed) >> 16)
   1.202 +#endif
   1.203 +
   1.204 +#ifdef SK_DEBUG
   1.205 +    static inline uint32_t pack_two_shorts(U16CPU pri, U16CPU sec) {
   1.206 +        SkASSERT((uint16_t)pri == pri);
   1.207 +        SkASSERT((uint16_t)sec == sec);
   1.208 +        return PACK_TWO_SHORTS(pri, sec);
   1.209 +    }
   1.210 +#else
   1.211 +    #define pack_two_shorts(pri, sec)   PACK_TWO_SHORTS(pri, sec)
   1.212 +#endif
   1.213 +
   1.214 +// These functions are generated via macros, but are exposed here so that
   1.215 +// platformProcs may test for them by name.
   1.216 +void S32_opaque_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[],
   1.217 +                              int count, SkPMColor colors[]);
   1.218 +void S32_alpha_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[],
   1.219 +                             int count, SkPMColor colors[]);
   1.220 +void S32_opaque_D32_filter_DXDY(const SkBitmapProcState& s,
   1.221 +                                const uint32_t xy[], int count, SkPMColor colors[]);
   1.222 +void S32_alpha_D32_filter_DXDY(const SkBitmapProcState& s,
   1.223 +                               const uint32_t xy[], int count, SkPMColor colors[]);
   1.224 +void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[],
   1.225 +                                int count, int x, int y);
   1.226 +void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[],
   1.227 +                                  int count, int x, int y);
   1.228 +void ClampX_ClampY_filter_affine(const SkBitmapProcState& s,
   1.229 +                                 uint32_t xy[], int count, int x, int y);
   1.230 +void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s,
   1.231 +                                   uint32_t xy[], int count, int x, int y);
   1.232 +void S32_D16_filter_DX(const SkBitmapProcState& s,
   1.233 +                       const uint32_t* xy, int count, uint16_t* colors);
   1.234 +
   1.235 +void highQualityFilter32(const SkBitmapProcState &s, int x, int y,
   1.236 +                         SkPMColor *SK_RESTRICT colors, int count);
   1.237 +void highQualityFilter16(const SkBitmapProcState &s, int x, int y,
   1.238 +                         uint16_t *SK_RESTRICT colors, int count);
   1.239 +
   1.240 +
   1.241 +#endif

mercurial