Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2011 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1.  Redistributions of source code must retain the above copyright
      9  *     notice, this list of conditions and the following disclaimer.
     10  * 2.  Redistributions in binary form must reproduce the above copyright
     11  *     notice, this list of conditions and the following disclaimer in the
     12  *     documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef ShaderChromium_h
     27 #define ShaderChromium_h
     28 
     29 #if USE(ACCELERATED_COMPOSITING)
     30 
     31 #include "PlatformString.h"
     32 
     33 #if USE(SKIA)
     34 #include "SkColorPriv.h"
     35 #endif
     36 
     37 namespace WebCore {
     38 
     39 class GraphicsContext3D;
     40 
     41 class VertexShaderPosTex {
     42 public:
     43     VertexShaderPosTex();
     44 
     45     bool init(GraphicsContext3D*, unsigned program);
     46     String getShaderString() const;
     47 
     48     int matrixLocation() const { return m_matrixLocation; }
     49 
     50 private:
     51     int m_matrixLocation;
     52 };
     53 
     54 class VertexShaderPosTexYUVStretch {
     55 public:
     56     VertexShaderPosTexYUVStretch();
     57 
     58     bool init(GraphicsContext3D*, unsigned program);
     59     String getShaderString() const;
     60 
     61     int matrixLocation() const { return m_matrixLocation; }
     62     int yWidthScaleFactorLocation() const { return m_yWidthScaleFactorLocation; }
     63     int uvWidthScaleFactorLocation() const { return m_uvWidthScaleFactorLocation; }
     64 
     65 private:
     66     int m_matrixLocation;
     67     int m_yWidthScaleFactorLocation;
     68     int m_uvWidthScaleFactorLocation;
     69 };
     70 
     71 class VertexShaderPos {
     72 public:
     73     VertexShaderPos();
     74 
     75     bool init(GraphicsContext3D*, unsigned program);
     76     String getShaderString() const;
     77 
     78     int matrixLocation() const { return m_matrixLocation; }
     79 
     80 private:
     81     int m_matrixLocation;
     82 };
     83 
     84 class VertexShaderPosTexTransform {
     85 public:
     86     VertexShaderPosTexTransform();
     87 
     88     bool init(GraphicsContext3D*, unsigned program);
     89     String getShaderString() const;
     90 
     91     int matrixLocation() const { return m_matrixLocation; }
     92     int texTransformLocation() const { return m_texTransformLocation; }
     93 
     94 private:
     95     int m_matrixLocation;
     96     int m_texTransformLocation;
     97 };
     98 
     99 class FragmentTexAlphaBinding {
    100 public:
    101     FragmentTexAlphaBinding();
    102 
    103     bool init(GraphicsContext3D*, unsigned program);
    104     int alphaLocation() const { return m_alphaLocation; }
    105     int samplerLocation() const { return m_samplerLocation; }
    106 
    107 private:
    108     int m_samplerLocation;
    109     int m_alphaLocation;
    110 };
    111 
    112 class FragmentShaderRGBATexFlipAlpha : public FragmentTexAlphaBinding {
    113 public:
    114     String getShaderString() const;
    115 };
    116 
    117 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
    118 public:
    119     String getShaderString() const;
    120 };
    121 
    122 class FragmentShaderBGRATexAlpha : public FragmentTexAlphaBinding {
    123 public:
    124     String getShaderString() const;
    125 };
    126 
    127 class FragmentShaderRGBATexAlphaMask {
    128 public:
    129     FragmentShaderRGBATexAlphaMask();
    130     String getShaderString() const;
    131 
    132     bool init(GraphicsContext3D*, unsigned program);
    133     int alphaLocation() const { return m_alphaLocation; }
    134     int samplerLocation() const { return m_samplerLocation; }
    135     int maskSamplerLocation() const { return m_maskSamplerLocation; }
    136 
    137 private:
    138     int m_samplerLocation;
    139     int m_maskSamplerLocation;
    140     int m_alphaLocation;
    141 };
    142 
    143 #if USE(SKIA) && SK_B32_SHIFT
    144 typedef FragmentShaderRGBATexAlpha FragmentShaderTexAlpha;
    145 #else
    146 typedef FragmentShaderBGRATexAlpha FragmentShaderTexAlpha;
    147 #endif
    148 
    149 class FragmentShaderYUVVideo {
    150 public:
    151     FragmentShaderYUVVideo();
    152     String getShaderString() const;
    153 
    154     bool init(GraphicsContext3D*, unsigned program);
    155 
    156     int yTextureLocation() const { return m_yTextureLocation; }
    157     int uTextureLocation() const { return m_uTextureLocation; }
    158     int vTextureLocation() const { return m_vTextureLocation; }
    159     int alphaLocation() const { return m_alphaLocation; }
    160     int ccMatrixLocation() const { return m_ccMatrixLocation; }
    161     int yuvAdjLocation() const { return m_yuvAdjLocation; }
    162 
    163 private:
    164     int m_yTextureLocation;
    165     int m_uTextureLocation;
    166     int m_vTextureLocation;
    167     int m_alphaLocation;
    168     int m_ccMatrixLocation;
    169     int m_yuvAdjLocation;
    170 };
    171 
    172 class FragmentShaderColor {
    173 public:
    174     FragmentShaderColor();
    175     String getShaderString() const;
    176 
    177     bool init(GraphicsContext3D*, unsigned program);
    178     int colorLocation() const { return m_colorLocation; }
    179 
    180 private:
    181     int m_colorLocation;
    182 };
    183 
    184 } // namespace WebCore
    185 
    186 #endif // USE(ACCELERATED_COMPOSITING)
    187 
    188 #endif
    189