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 CustomFilterCompiledProgram_h 31 #define CustomFilterCompiledProgram_h 32 33 #include "core/platform/graphics/GraphicsContext3D.h" 34 #include "core/platform/graphics/filters/custom/CustomFilterProgramInfo.h" 35 #include "wtf/RefCounted.h" 36 #include "wtf/text/WTFString.h" 37 38 namespace WebCore { 39 40 class CustomFilterGlobalContext; 41 42 class CustomFilterCompiledProgram: public RefCounted<CustomFilterCompiledProgram> { 43 public: 44 static PassRefPtr<CustomFilterCompiledProgram> create(PassRefPtr<GraphicsContext3D> context, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType programType) 45 { 46 return adoptRef(new CustomFilterCompiledProgram(context, validatedVertexShader, validatedFragmentShader, programType)); 47 } 48 49 ~CustomFilterCompiledProgram(); 50 51 int positionAttribLocation() const { return m_positionAttribLocation; } 52 int texAttribLocation() const { return m_texAttribLocation; } 53 int meshAttribLocation() const { return m_meshAttribLocation; } 54 int triangleAttribLocation() const { return m_triangleAttribLocation; } 55 int meshBoxLocation() const { return m_meshBoxLocation; } 56 int projectionMatrixLocation() const { return m_projectionMatrixLocation; } 57 int tileSizeLocation() const { return m_tileSizeLocation; } 58 int meshSizeLocation() const { return m_meshSizeLocation; } 59 int samplerLocation() const { return m_samplerLocation; } 60 int contentSamplerLocation() const { return m_contentSamplerLocation; } 61 int samplerSizeLocation() const { return m_samplerSizeLocation; } 62 63 int uniformLocationByName(const String&); 64 65 bool isInitialized() const { return m_isInitialized; } 66 67 Platform3DObject program() const { return m_program; } 68 private: 69 CustomFilterCompiledProgram(PassRefPtr<GraphicsContext3D>, const String& validatedVertexShader, const String& validatedFragmentShader, CustomFilterProgramType); 70 71 Platform3DObject compileShader(GC3Denum shaderType, const String& shaderString); 72 Platform3DObject linkProgram(Platform3DObject vertexShader, Platform3DObject fragmentShader); 73 void initializeParameterLocations(CustomFilterProgramType); 74 75 RefPtr<GraphicsContext3D> m_context; 76 Platform3DObject m_program; 77 78 int m_positionAttribLocation; 79 int m_texAttribLocation; 80 int m_meshAttribLocation; 81 int m_triangleAttribLocation; 82 int m_meshBoxLocation; 83 int m_projectionMatrixLocation; 84 int m_tileSizeLocation; 85 int m_meshSizeLocation; 86 int m_samplerLocation; 87 int m_samplerSizeLocation; 88 int m_contentSamplerLocation; 89 90 bool m_isInitialized; 91 }; 92 93 } 94 95 #endif 96