Home | History | Annotate | Download | only in custom
      1 /*
      2  * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
      3  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
      4  * Copyright (C) 2012 Company 100, Inc. All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  *
     10  * 1. Redistributions of source code must retain the above
     11  *    copyright notice, this list of conditions and the following
     12  *    disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above
     14  *    copyright notice, this list of conditions and the following
     15  *    disclaimer in the documentation and/or other materials
     16  *    provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
     22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     23  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     28  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #ifndef CustomFilterRenderer_h
     33 #define CustomFilterRenderer_h
     34 
     35 #include "core/platform/graphics/GraphicsTypes3D.h"
     36 #include "core/platform/graphics/IntSize.h"
     37 #include "core/platform/graphics/filters/custom/CustomFilterConstants.h"
     38 #include "core/platform/graphics/filters/custom/CustomFilterParameterList.h"
     39 #include "wtf/RefCounted.h"
     40 #include "wtf/RefPtr.h"
     41 
     42 namespace WebCore {
     43 
     44 class CustomFilterArrayParameter;
     45 class CustomFilterCompiledProgram;
     46 class CustomFilterMesh;
     47 class CustomFilterNumberParameter;
     48 class CustomFilterTransformParameter;
     49 class GraphicsContext3D;
     50 
     51 class CustomFilterRenderer : public RefCounted<CustomFilterRenderer> {
     52 public:
     53     static PassRefPtr<CustomFilterRenderer> create(PassRefPtr<GraphicsContext3D>, CustomFilterProgramType, const CustomFilterParameterList&,
     54         unsigned meshRows, unsigned meshColumns, CustomFilterMeshType);
     55     ~CustomFilterRenderer();
     56 
     57     bool premultipliedAlpha() const;
     58     bool programNeedsInputTexture() const;
     59 
     60     bool prepareForDrawing();
     61 
     62     void draw(Platform3DObject, const IntSize&);
     63 
     64     CustomFilterCompiledProgram* compiledProgram() const { return m_compiledProgram.get(); }
     65     void setCompiledProgram(PassRefPtr<CustomFilterCompiledProgram>);
     66 
     67 private:
     68     CustomFilterRenderer(PassRefPtr<GraphicsContext3D>, CustomFilterProgramType, const CustomFilterParameterList&,
     69         unsigned meshRows, unsigned meshColumns, CustomFilterMeshType);
     70 
     71     void initializeCompiledProgramIfNeeded();
     72     void initializeMeshIfNeeded();
     73 
     74     void bindVertexAttribute(int attributeLocation, unsigned size, unsigned offset);
     75     void unbindVertexAttribute(int attributeLocation);
     76     void bindProgramArrayParameters(int uniformLocation, CustomFilterArrayParameter*);
     77     void bindProgramNumberParameters(int uniformLocation, CustomFilterNumberParameter*);
     78     void bindProgramTransformParameter(int uniformLocation, CustomFilterTransformParameter*);
     79     void bindProgramParameters();
     80     void bindProgramAndBuffers(Platform3DObject inputTexture);
     81     void unbindVertexAttributes();
     82 
     83     RefPtr<GraphicsContext3D> m_context;
     84     RefPtr<CustomFilterCompiledProgram> m_compiledProgram;
     85     CustomFilterProgramType m_programType;
     86     RefPtr<CustomFilterMesh> m_mesh;
     87     IntSize m_contextSize;
     88 
     89     CustomFilterParameterList m_parameters;
     90 
     91     unsigned m_meshRows;
     92     unsigned m_meshColumns;
     93     CustomFilterMeshType m_meshType;
     94 };
     95 
     96 } // namespace WebCore
     97 
     98 #endif // CustomFilterRenderer_h
     99