Home | History | Annotate | Download | only in custom
      1 /*
      2  * Copyright (C) 2012 Adobe Systems Incorporated. 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
      9  *    copyright notice, this list of conditions and the following
     10  *    disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above
     12  *    copyright notice, this list of conditions and the following
     13  *    disclaimer in the documentation and/or other materials
     14  *    provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
     17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
     20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #ifndef CustomFilterProgramInfo_h
     31 #define CustomFilterProgramInfo_h
     32 
     33 #include "core/platform/graphics/GraphicsTypes.h"
     34 #include "core/platform/graphics/filters/custom/CustomFilterConstants.h"
     35 
     36 #include "wtf/HashTableDeletedValueType.h"
     37 #include "wtf/HashTraits.h"
     38 #include "wtf/text/WTFString.h"
     39 
     40 namespace WebCore {
     41 
     42 
     43 struct CustomFilterProgramMixSettings {
     44     CustomFilterProgramMixSettings()
     45         : blendMode(BlendModeNormal)
     46         , compositeOperator(CompositeSourceAtop)
     47     {
     48     }
     49 
     50     bool operator==(const CustomFilterProgramMixSettings& o) const
     51     {
     52         return blendMode == o.blendMode && compositeOperator == o.compositeOperator;
     53     }
     54 
     55     BlendMode blendMode;
     56     CompositeOperator compositeOperator;
     57 };
     58 
     59 // CustomFilterProgramInfo is the key used to link CustomFilterProgram with CustomFilterCompiledProgram.
     60 // It can be used as a key in a HashMap, with the note that at least one of Strings needs to be non-null.
     61 // Null strings are placeholders for the default shader.
     62 class CustomFilterProgramInfo {
     63 public:
     64     CustomFilterProgramInfo(const String&, const String&, CustomFilterProgramType, const CustomFilterProgramMixSettings&, CustomFilterMeshType);
     65 
     66     CustomFilterProgramInfo();
     67     bool isEmptyValue() const;
     68 
     69     CustomFilterProgramInfo(WTF::HashTableDeletedValueType);
     70     bool isHashTableDeletedValue() const;
     71 
     72     unsigned hash() const;
     73     bool operator==(const CustomFilterProgramInfo&) const;
     74 
     75     const String& vertexShaderString() const { return m_vertexShaderString; }
     76     const String& fragmentShaderString() const { return m_fragmentShaderString; }
     77     CustomFilterProgramType programType() const { return m_programType; }
     78     const CustomFilterProgramMixSettings& mixSettings() const { return m_mixSettings; }
     79     CustomFilterMeshType meshType() const { return m_meshType; }
     80 private:
     81     String m_vertexShaderString;
     82     String m_fragmentShaderString;
     83     CustomFilterProgramType m_programType;
     84     CustomFilterProgramMixSettings m_mixSettings;
     85     CustomFilterMeshType m_meshType;
     86 };
     87 
     88 struct CustomFilterProgramInfoHash {
     89     static unsigned hash(const CustomFilterProgramInfo& programInfo) { return programInfo.hash(); }
     90     static bool equal(const CustomFilterProgramInfo& a, const CustomFilterProgramInfo& b) { return a == b; }
     91     static const bool safeToCompareToEmptyOrDeleted = false;
     92 };
     93 
     94 struct CustomFilterProgramInfoHashTraits : WTF::SimpleClassHashTraits<CustomFilterProgramInfo> {
     95     static const bool hasIsEmptyValueFunction = true;
     96     static bool isEmptyValue(const CustomFilterProgramInfo& info) { return info.isEmptyValue(); }
     97 };
     98 
     99 } // namespace WebCore
    100 
    101 namespace WTF {
    102 
    103 template<> struct HashTraits<WebCore::CustomFilterProgramInfo> : WebCore::CustomFilterProgramInfoHashTraits { };
    104 template<> struct DefaultHash<WebCore::CustomFilterProgramInfo> {
    105     typedef WebCore::CustomFilterProgramInfoHash Hash;
    106 };
    107 
    108 }
    109 
    110 #endif // CustomFilterProgramInfo_h
    111