2 Copyright (C) 2011 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
23 #if USE(ACCELERATED_COMPOSITING)
25 #include "LayerShaderManager.h"
27 #include "GraphicsContext3D.h"
28 #include "LayerBorderShader.h"
29 #include "LayerCanvasShader.h"
30 #include "LayerTexShader.h"
31 #include "LayerMaskShader.h"
32 #include "LayerVideoShader.h"
36 PassOwnPtr<LayerShaderManager> LayerShaderManager::create(GraphicsContext3D* context)
38 return adoptPtr(new LayerShaderManager(context));
41 LayerShaderManager::LayerShaderManager(GraphicsContext3D* context)
42 : LayerManager(context)
46 m_bInitialized = initialize();
49 LayerShaderManager::~LayerShaderManager()
54 bool LayerShaderManager::initialize()
56 m_texShader = LayerTexShader::create(m_context.get());
57 m_maskShader = LayerMaskShader::create(m_context.get());
58 m_videoShader = LayerVideoShader::create(m_context.get());
59 m_canvasShader = LayerCanvasShader::create(m_context.get());
60 m_borderShader = LayerBorderShader::create(m_context.get());
62 if (!m_texShader || !m_maskShader || !m_videoShader || !m_canvasShader || !m_borderShader)
68 void LayerShaderManager::release()
72 m_videoShader.clear();
73 m_canvasShader.clear();
74 m_borderShader.clear();
77 void LayerShaderManager::use(int type)
79 m_currentLayerType = type;
82 LayerShader* requiredShader = m_usedShader;
84 case EflLayer::HTMLContentsType:
85 case EflLayer::ImageContentsType:
86 case EflLayer::PluginContentsType:
87 requiredShader = m_texShader.get();
89 case EflLayer::VideoContentsType:
90 requiredShader = m_videoShader.get();
92 case EflLayer::WebGLContentsType:
93 requiredShader = m_canvasShader.get();
95 case EflLayer::CanvasContentsType:
96 #if ENABLE(CANVAS_CAIRO_GLES_RENDERING)
97 requiredShader = m_canvasShader.get();
99 requiredShader = m_texShader.get();
102 case DebugBordersType:
103 requiredShader = m_borderShader.get();
109 if (requiredShader == m_usedShader)
112 requiredShader->use();
113 m_usedShader = requiredShader;
116 void LayerShaderManager::useMaskShader()
125 void LayerShaderManager::setMatrix(float* matrix)
127 if (m_maskShader && m_useMaskLayer) {
128 m_maskShader->setMatrix(matrix);
133 m_usedShader->setMatrix(matrix);
136 void LayerShaderManager::setSampler(int sampler)
138 if (m_maskShader && m_useMaskLayer) {
139 m_maskShader->setSampler(sampler);
144 m_usedShader->setSampler(sampler);
147 void LayerShaderManager::setAlpha(float alpha)
149 if (m_maskShader && m_useMaskLayer) {
150 m_maskShader->setAlpha(alpha);
155 m_usedShader->setAlpha(alpha);
158 void LayerShaderManager::setMaskMatrix(float* matrix)
161 // Reverse image vertically.
162 // We get WebGL reverse texture image. The reason is not found yet.
163 if (m_currentLayerType == EflLayer::WebGLContentsType)
166 m_maskShader->setMaskMatrix(matrix);
170 void LayerShaderManager::setMaskSampler(int sampler)
173 m_maskShader->setMaskSampler(sampler);
176 void LayerShaderManager::setMaskAlpha(float alpha)
179 m_maskShader->setAlpha(alpha);
182 void LayerShaderManager::setColor(const Color& color)
184 if (m_maskShader && m_useMaskLayer) {
185 m_maskShader->setColor(color);
190 m_usedShader->setColor(color);
193 } // namespace WebCore