Changeset 127063 in webkit
- Timestamp:
- Aug 29, 2012 4:12:45 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r127062 r127063 1 2012-08-29 Roland Takacs <rtakacs@inf.u-szeged.hu>, Helder Correia <helder.correia@nokia.com> 2 3 [Texmap] Move TextureMapperGL to use GraphicsContext3D 4 https://bugs.webkit.org/show_bug.cgi?id=78672 5 6 Reviewed by Noam Rosenthal. 7 8 It is based on a previous patch by Helder Correia. 9 10 TextureMapperGL (TMGL) includes direct GL calls and 11 GraphicsContext3D (GC3D) offers many conveniences over the 12 former approach: using existing CSS shader code, ANGLE for 13 shader compilation, reusing WebCore::Texture, having shaders and 14 textures that can delete themselves. 15 16 A GC3D object is created by TMGL with the newly introduced 17 builder createForCurrentGLContext(), which in turn uses 18 the new RenderToCurrentGLContext flag underneath. 19 20 TMGL's dependency on OpenGLShims.h was completely removed. 21 However, GC3D does not map every single GL constant. Thus, it's 22 important to document the following: 23 - GL_FALSE was mapped to false. 24 - GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS, 25 GL_UNPACK_SKIP_ROWS, GL_TEXTURE_RECTANGLE_ARB, and 26 GL_UNSIGNED_INT_8_8_8_8_REV were locally defined in TMGL. 27 28 The patch was originally developed by Helder Correia and finished 29 by Roland Takacs. 30 31 No new tests, refactoring. 32 33 * platform/graphics/GraphicsContext3D.h: 34 * platform/graphics/texmap/TextureMapperGL.cpp: 35 (SharedGLData): 36 (WebCore::TextureMapperGLData::SharedGLData::currentSharedGLData): 37 (WebCore::TextureMapperGLData::SharedGLData::SharedGLData): 38 (WebCore::TextureMapperGLData::sharedGLData): 39 (WebCore::TextureMapperGLData::TextureMapperGLData): 40 (TextureMapperGLData): 41 (WebCore::scissorClip): 42 (WebCore::TextureMapperGL::ClipStack::apply): 43 (WebCore::TextureMapperGLData::initializeStencil): 44 (WebCore::TextureMapperGL::TextureMapperGL): 45 (WebCore::TextureMapperGL::beginPainting): 46 (WebCore::TextureMapperGL::endPainting): 47 (WebCore::TextureMapperGL::drawQuad): 48 (WebCore::TextureMapperGL::drawBorder): 49 (WebCore): 50 (WebCore::TextureMapperGL::drawTextureRectangleARB): 51 (WebCore::TextureMapperGL::drawTexture): 52 (WebCore::viewportMatrix): 53 (WebCore::TextureMapperGL::drawTextureWithAntialiasing): 54 (WebCore::TextureMapperGL::drawTexturedQuadWithProgram): 55 (WebCore::BitmapTextureGL::didReset): 56 (WebCore::BitmapTextureGL::updateContents): 57 (WebCore::TextureMapperGL::drawFiltered): 58 (WebCore::BitmapTextureGL::initializeStencil): 59 (WebCore::BitmapTextureGL::clearIfNeeded): 60 (WebCore::BitmapTextureGL::createFboIfNeeded): 61 (WebCore::BitmapTextureGL::bind): 62 (WebCore::BitmapTextureGL::~BitmapTextureGL): 63 (WebCore::TextureMapperGL::bindDefaultSurface): 64 (WebCore::TextureMapperGL::beginScissorClip): 65 (WebCore::TextureMapperGL::beginClip): 66 (WebCore::TextureMapperGL::endClip): 67 (WebCore::TextureMapperGL::createTexture): 68 * platform/graphics/texmap/TextureMapperGL.h: 69 (WebCore::TextureMapperGL::graphicsContext3D): 70 (TextureMapperGL): 71 (ClipStack): 72 (WebCore::BitmapTextureGL::textureTarget): 73 (BitmapTextureGL): 74 (WebCore::BitmapTextureGL::BitmapTextureGL): 75 * platform/graphics/texmap/TextureMapperShaderManager.cpp: 76 (WebCore): 77 (WebCore::TextureMapperShaderManager::getShaderProgram): 78 (WebCore::TextureMapperShaderProgram::TextureMapperShaderProgram): 79 (WebCore::TextureMapperShaderProgram::initializeProgram): 80 (WebCore::TextureMapperShaderProgram::getUniformLocation): 81 (WebCore::TextureMapperShaderProgram::~TextureMapperShaderProgram): 82 (WebCore::TextureMapperShaderProgramSimple::TextureMapperShaderProgramSimple): 83 (WebCore::TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor): 84 (WebCore::TextureMapperShaderProgramRectSimple::TextureMapperShaderProgramRectSimple): 85 (WebCore::TextureMapperShaderProgramOpacityAndMask::TextureMapperShaderProgramOpacityAndMask): 86 (WebCore::TextureMapperShaderProgramRectOpacityAndMask::TextureMapperShaderProgramRectOpacityAndMask): 87 (WebCore::TextureMapperShaderProgramAntialiasingNoMask::TextureMapperShaderProgramAntialiasingNoMask): 88 (WebCore::TextureMapperShaderManager::TextureMapperShaderManager): 89 (WebCore::StandardFilterProgram::~StandardFilterProgram): 90 (WebCore::StandardFilterProgram::StandardFilterProgram): 91 (WebCore::StandardFilterProgram::create): 92 (WebCore::StandardFilterProgram::prepare): 93 (WebCore::TextureMapperShaderManager::getShaderForFilter): 94 * platform/graphics/texmap/TextureMapperShaderManager.h: 95 (WebCore::TextureMapperShaderProgram::id): 96 (WebCore::TextureMapperShaderProgram::vertexAttrib): 97 (TextureMapperShaderProgram): 98 (WebCore::TextureMapperShaderProgram::matrixLocation): 99 (WebCore::TextureMapperShaderProgram::flipLocation): 100 (WebCore::TextureMapperShaderProgram::textureSizeLocation): 101 (WebCore::TextureMapperShaderProgram::sourceTextureLocation): 102 (WebCore::TextureMapperShaderProgram::maskTextureLocation): 103 (WebCore::TextureMapperShaderProgram::opacityLocation): 104 (WebCore::TextureMapperShaderProgram::isValidUniformLocation): 105 (StandardFilterProgram): 106 (WebCore::StandardFilterProgram::vertexAttrib): 107 (WebCore::StandardFilterProgram::texCoordAttrib): 108 (WebCore::StandardFilterProgram::textureUniform): 109 (WebCore::TextureMapperShaderProgramSimple::create): 110 (TextureMapperShaderProgramSimple): 111 (WebCore::TextureMapperShaderProgramRectSimple::create): 112 (TextureMapperShaderProgramRectSimple): 113 (WebCore::TextureMapperShaderProgramOpacityAndMask::create): 114 (TextureMapperShaderProgramOpacityAndMask): 115 (WebCore::TextureMapperShaderProgramRectOpacityAndMask::create): 116 (TextureMapperShaderProgramRectOpacityAndMask): 117 (WebCore::TextureMapperShaderProgramSolidColor::create): 118 (WebCore::TextureMapperShaderProgramSolidColor::colorLocation): 119 (TextureMapperShaderProgramSolidColor): 120 (WebCore::TextureMapperShaderProgramAntialiasingNoMask::create): 121 (WebCore::TextureMapperShaderProgramAntialiasingNoMask::expandedQuadVerticesInTextureCoordinatesLocation): 122 (WebCore::TextureMapperShaderProgramAntialiasingNoMask::expandedQuadEdgesInScreenSpaceLocation): 123 (TextureMapperShaderProgramAntialiasingNoMask): 124 (WebCore::TextureMapperShaderManager::TextureMapperShaderManager): 125 (TextureMapperShaderManager): 126 1 127 2012-08-29 Adam Barth <abarth@webkit.org> 2 128 -
trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h
r126743 r127063 251 251 RGB = 0x1907, 252 252 RGBA = 0x1908, 253 BGRA = 0x80E1, 253 254 LUMINANCE = 0x1909, 254 255 LUMINANCE_ALPHA = 0x190A, -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
r126926 r127063 39 39 #if PLATFORM(QT) 40 40 #include "NativeImageQt.h" 41 #include <QOpenGLContext>42 #elif OS(WINDOWS)43 #include <windows.h>44 #elif OS(MAC_OS_X)45 #include <AGL/agl.h>46 #elif defined(XP_UNIX)47 #include <GL/glx.h>48 41 #endif 49 42 … … 54 47 #endif 55 48 56 #define GL_CMD(...) do { __VA_ARGS__; ASSERT_ARG(__VA_ARGS__, !glGetError()); } while (0) 49 #if !USE(TEXMAP_OPENGL_ES_2) 50 // FIXME: Move to Extensions3D.h. 51 #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 52 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 53 #define GL_UNPACK_ROW_LENGTH 0x0CF2 54 #define GL_UNPACK_SKIP_PIXELS 0x0CF4 55 #define GL_UNPACK_SKIP_ROWS 0x0CF3 56 #endif 57 57 58 namespace WebCore { 58 59 struct TextureMapperGLData { 59 60 struct SharedGLData : public RefCounted<SharedGLData> { 60 #if PLATFORM(QT) 61 typedef QOpenGLContext* GLContext; 62 static GLContext getCurrentGLContext() 63 { 64 return QOpenGLContext::currentContext(); 65 } 66 #elif OS(WINDOWS) 67 typedef HGLRC GLContext; 68 static GLContext getCurrentGLContext() 69 { 70 return wglGetCurrentContext(); 71 } 72 #elif OS(MAC_OS_X) 73 typedef AGLContext GLContext; 74 static GLContext getCurrentGLContext() 75 { 76 return aglGetCurrentContext(); 77 } 78 #elif defined(XP_UNIX) 79 typedef GLXContext GLContext; 80 static GLContext getCurrentGLContext() 81 { 82 return glXGetCurrentContext(); 83 } 84 #else 85 // Default implementation for unknown opengl. 86 // Returns always increasing number and disables GL context data sharing. 87 typedef unsigned int GLContext; 88 static GLContext getCurrentGLContext() 89 { 90 static GLContext dummyContextCounter = 0; 91 return ++dummyContextCounter; 92 } 93 94 #endif 95 96 typedef HashMap<GLContext, SharedGLData*> GLContextDataMap; 61 62 typedef HashMap<PlatformGraphicsContext3D, SharedGLData*> GLContextDataMap; 97 63 static GLContextDataMap& glContextDataMap() 98 64 { … … 101 67 } 102 68 103 static PassRefPtr<SharedGLData> currentSharedGLData( )69 static PassRefPtr<SharedGLData> currentSharedGLData(GraphicsContext3D* context) 104 70 { 105 GLContext currentGLConext = getCurrentGLContext(); 106 GLContextDataMap::iterator it = glContextDataMap().find(currentGLConext); 71 GLContextDataMap::iterator it = glContextDataMap().find(context->platformGraphicsContext3D()); 107 72 if (it != glContextDataMap().end()) 108 73 return it->second; 109 74 110 return adoptRef(new SharedGLData( getCurrentGLContext()));75 return adoptRef(new SharedGLData(context)); 111 76 } 112 77 … … 115 80 TextureMapperShaderManager textureMapperShaderManager; 116 81 117 SharedGLData(GLContext glContext) 82 SharedGLData(GraphicsContext3D* context) 83 : textureMapperShaderManager(context) 118 84 { 119 glContextDataMap().add( glContext, this);85 glContextDataMap().add(context->platformGraphicsContext3D(), this); 120 86 } 121 87 … … 136 102 SharedGLData& sharedGLData() const 137 103 { 138 return * (m_sharedGLData.get());104 return *m_sharedGLData; 139 105 } 140 106 141 107 void initializeStencil(); 142 108 143 TextureMapperGLData() 144 : PaintFlags(0) 109 TextureMapperGLData(GraphicsContext3D* context) 110 : context(context) 111 , PaintFlags(0) 145 112 , previousProgram(0) 146 113 , targetFrameBuffer(0) … … 148 115 , previousScissorState(0) 149 116 , previousDepthState(0) 150 , m_sharedGLData(TextureMapperGLData::SharedGLData::currentSharedGLData( ))117 , m_sharedGLData(TextureMapperGLData::SharedGLData::currentSharedGLData(this->context)) 151 118 { } 152 119 120 GraphicsContext3D* context; 153 121 TransformationMatrix projectionMatrix; 154 122 TextureMapper::PaintFlags PaintFlags; 155 G Lint previousProgram;156 G Lint targetFrameBuffer;123 GC3Dint previousProgram; 124 GC3Dint targetFrameBuffer; 157 125 bool didModifyStencil; 158 G Lint previousScissorState;159 G Lint previousDepthState;160 G Lint viewport[4];161 G Lint previousScissor[4];126 GC3Dint previousScissorState; 127 GC3Dint previousDepthState; 128 GC3Dint viewport[4]; 129 GC3Dint previousScissor[4]; 162 130 RefPtr<SharedGLData> m_sharedGLData; 163 131 RefPtr<BitmapTexture> currentSurface; … … 183 151 } 184 152 185 static void scissorClip( const IntRect& rect)153 static void scissorClip(GraphicsContext3D* context, const IntRect& rect) 186 154 { 187 155 if (rect.isEmpty()) 188 156 return; 189 157 190 G Lint viewport[4];191 GL_CMD(glGetIntegerv(GL_VIEWPORT, viewport));192 GL_CMD(glScissor(rect.x(), viewport[3] - rect.maxY(), rect.width(), rect.height()));193 } 194 195 void TextureMapperGL::ClipStack::apply( )196 { 197 scissorClip(c lipState.scissorBox);198 GL_CMD(glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP));199 GL_CMD(glStencilFunc(GL_EQUAL, clipState.stencilIndex - 1, clipState.stencilIndex - 1));158 GC3Dint viewport[4]; 159 context->getIntegerv(GraphicsContext3D::VIEWPORT, viewport); 160 context->scissor(rect.x(), viewport[3] - rect.maxY(), rect.width(), rect.height()); 161 } 162 163 void TextureMapperGL::ClipStack::apply(GraphicsContext3D* context) 164 { 165 scissorClip(context, clipState.scissorBox); 166 context->stencilOp(GraphicsContext3D::KEEP, GraphicsContext3D::KEEP, GraphicsContext3D::KEEP); 167 context->stencilFunc(GraphicsContext3D::EQUAL, clipState.stencilIndex - 1, clipState.stencilIndex - 1); 200 168 if (clipState.stencilIndex == 1) 201 GL_CMD(glDisable(GL_STENCIL_TEST));169 context->disable(GraphicsContext3D::STENCIL_TEST); 202 170 else 203 GL_CMD(glEnable(GL_STENCIL_TEST));171 context->enable(GraphicsContext3D::STENCIL_TEST); 204 172 } 205 173 … … 215 183 return; 216 184 217 GL_CMD(glClearStencil(0));218 GL_CMD(glClear(GL_STENCIL_BUFFER_BIT));185 context->clearStencil(0); 186 context->clear(GraphicsContext3D::STENCIL_BUFFER_BIT); 219 187 didModifyStencil = true; 220 188 } … … 230 198 TextureMapperGL::TextureMapperGL() 231 199 : TextureMapper(OpenGLMode) 232 , m_data(new TextureMapperGLData)233 200 , m_context(0) 234 201 , m_enableEdgeDistanceAntialiasing(false) 235 202 { 203 m_context3D = GraphicsContext3D::createForCurrentGLContext(); 204 m_data = new TextureMapperGLData(m_context3D.get()); 236 205 } 237 206 … … 243 212 void TextureMapperGL::beginPainting(PaintFlags flags) 244 213 { 245 // Make sure that no GL error code stays from previous operations. 246 glGetError(); 247 248 if (!initializeOpenGLShims()) 249 return; 250 251 GL_CMD(glGetIntegerv(GL_CURRENT_PROGRAM, &data().previousProgram)); 252 data().previousScissorState = glIsEnabled(GL_SCISSOR_TEST); 253 data().previousDepthState = glIsEnabled(GL_DEPTH_TEST); 214 m_context3D->getIntegerv(GraphicsContext3D::CURRENT_PROGRAM, &data().previousProgram); 215 data().previousScissorState = m_context3D->isEnabled(GraphicsContext3D::SCISSOR_TEST); 216 data().previousDepthState = m_context3D->isEnabled(GraphicsContext3D::DEPTH_TEST); 254 217 #if PLATFORM(QT) 255 218 if (m_context) { … … 259 222 } 260 223 #endif 261 glDisable(GL_DEPTH_TEST);262 glEnable(GL_SCISSOR_TEST);224 m_context3D->disable(GraphicsContext3D::DEPTH_TEST); 225 m_context3D->enable(GraphicsContext3D::SCISSOR_TEST); 263 226 data().didModifyStencil = false; 264 GL_CMD(glDepthMask(0));265 GL_CMD(glGetIntegerv(GL_VIEWPORT, data().viewport));266 GL_CMD(glGetIntegerv(GL_SCISSOR_BOX, data().previousScissor));227 m_context3D->depthMask(0); 228 m_context3D->getIntegerv(GraphicsContext3D::VIEWPORT, data().viewport); 229 m_context3D->getIntegerv(GraphicsContext3D::SCISSOR_BOX, data().previousScissor); 267 230 m_clipStack.init(IntRect(0, 0, data().viewport[2], data().viewport[3])); 268 GL_CMD(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &data().targetFrameBuffer));231 m_context3D->getIntegerv(GraphicsContext3D::FRAMEBUFFER_BINDING, &data().targetFrameBuffer); 269 232 data().PaintFlags = flags; 270 233 bindSurface(0); … … 274 237 { 275 238 if (data().didModifyStencil) { 276 glClearStencil(1);277 glClear(GL_STENCIL_BUFFER_BIT);278 } 279 280 glUseProgram(data().previousProgram);281 282 glScissor(data().previousScissor[0], data().previousScissor[1], data().previousScissor[2], data().previousScissor[3]);239 m_context3D->clearStencil(1); 240 m_context3D->clear(GraphicsContext3D::STENCIL_BUFFER_BIT); 241 } 242 243 m_context3D->useProgram(data().previousProgram); 244 245 m_context3D->scissor(data().previousScissor[0], data().previousScissor[1], data().previousScissor[2], data().previousScissor[3]); 283 246 if (data().previousScissorState) 284 glEnable(GL_SCISSOR_TEST);247 m_context3D->enable(GraphicsContext3D::SCISSOR_TEST); 285 248 else 286 glDisable(GL_SCISSOR_TEST);249 m_context3D->disable(GraphicsContext3D::SCISSOR_TEST); 287 250 288 251 if (data().previousDepthState) 289 glEnable(GL_DEPTH_TEST);252 m_context3D->enable(GraphicsContext3D::DEPTH_TEST); 290 253 else 291 glDisable(GL_DEPTH_TEST);254 m_context3D->disable(GraphicsContext3D::DEPTH_TEST); 292 255 293 256 #if PLATFORM(QT) … … 300 263 } 301 264 302 void TextureMapperGL::drawQuad(const DrawQuad& quadToDraw, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram* shaderProgram, G Lenum drawingMode, bool needsBlending)303 { 304 GL_CMD(glEnableVertexAttribArray(shaderProgram->vertexAttrib()));305 GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0));306 307 const G Lfloat quad[] = {265 void TextureMapperGL::drawQuad(const DrawQuad& quadToDraw, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram* shaderProgram, GC3Denum drawingMode, bool needsBlending) 266 { 267 m_context3D->enableVertexAttribArray(shaderProgram->vertexAttrib()); 268 m_context3D->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, 0); 269 270 const GC3Dfloat quad[] = { 308 271 quadToDraw.targetRectMappedToUnitSquare.p1().x(), quadToDraw.targetRectMappedToUnitSquare.p1().y(), 309 272 quadToDraw.targetRectMappedToUnitSquare.p2().x(), quadToDraw.targetRectMappedToUnitSquare.p2().y(), … … 311 274 quadToDraw.targetRectMappedToUnitSquare.p4().x(), quadToDraw.targetRectMappedToUnitSquare.p4().y() 312 275 }; 313 GL_CMD(glVertexAttribPointer(shaderProgram->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0,quad));276 m_context3D->vertexAttribPointer(shaderProgram->vertexAttrib(), 2, GraphicsContext3D::FLOAT, false, 0, GC3Dintptr(quad)); 314 277 315 278 TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(modelViewMatrix).multiply(TransformationMatrix( … … 318 281 0, 0, 1, 0, 319 282 quadToDraw.originalTargetRect.x(), quadToDraw.originalTargetRect.y(), 0, 1)); 320 const GLfloat m4[] = {283 GC3Dfloat m4[] = { 321 284 matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(), 322 285 matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(), … … 324 287 matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44() 325 288 }; 326 GL_CMD(glUniformMatrix4fv(shaderProgram->matrixLocation(), 1, GL_FALSE, m4));289 m_context3D->uniformMatrix4fv(shaderProgram->matrixLocation(), 1, false, m4); 327 290 328 291 if (needsBlending) { 329 GL_CMD(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));330 GL_CMD(glEnable(GL_BLEND));292 m_context3D->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA); 293 m_context3D->enable(GraphicsContext3D::BLEND); 331 294 } else 332 GL_CMD(glDisable(GL_BLEND));333 334 GL_CMD(glDrawArrays(drawingMode, 0, 4));335 GL_CMD(glDisableVertexAttribArray(shaderProgram->vertexAttrib()));295 m_context3D->disable(GraphicsContext3D::BLEND); 296 297 m_context3D->drawArrays(drawingMode, 0, 4); 298 m_context3D->disableVertexAttribArray(shaderProgram->vertexAttrib()); 336 299 } 337 300 … … 342 305 343 306 RefPtr<TextureMapperShaderProgramSolidColor> program = data().sharedGLData().textureMapperShaderManager.solidColorProgram(); 344 GL_CMD(glUseProgram(program->id()));307 m_context3D->useProgram(program->id()); 345 308 346 309 float alpha = color.alpha() / 255.0; 347 GL_CMD(glUniform4f(program->colorLocation(),310 m_context3D->uniform4f(program->colorLocation(), 348 311 (color.red() / 255.0) * alpha, 349 312 (color.green() / 255.0) * alpha, 350 313 (color.blue() / 255.0) * alpha, 351 alpha) );352 GL_CMD(glLineWidth(width));353 354 drawQuad(targetRect, modelViewMatrix, program.get(), G L_LINE_LOOP, color.hasAlpha());314 alpha); 315 m_context3D->lineWidth(width); 316 317 drawQuad(targetRect, modelViewMatrix, program.get(), GraphicsContext3D::LINE_LOOP, color.hasAlpha()); 355 318 } 356 319 … … 399 362 } 400 363 401 #if defined(GL_ARB_texture_rectangle)364 #if !USE(TEXMAP_OPENGL_ES_2) 402 365 void TextureMapperGL::drawTextureRectangleARB(uint32_t texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture) 403 366 { … … 407 370 else 408 371 program = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::RectSimple); 409 GL_CMD(glUseProgram(program->id()));410 411 GL_CMD(glEnableVertexAttribArray(program->vertexAttrib()));412 GL_CMD(glActiveTexture(GL_TEXTURE0));413 GL_CMD(glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture));414 GL_CMD(glUniform1i(program->sourceTextureLocation(), 0));415 416 GL_CMD(glUniform1f(program->flipLocation(), !!(flags & ShouldFlipTexture)));417 GL_CMD(glUniform2f(program->textureSizeLocation(), textureSize.width(), textureSize.height()));372 m_context3D->useProgram(program->id()); 373 374 m_context3D->enableVertexAttribArray(program->vertexAttrib()); 375 m_context3D->activeTexture(GraphicsContext3D::TEXTURE0); 376 m_context3D->bindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); 377 m_context3D->uniform1i(program->sourceTextureLocation(), 0); 378 379 m_context3D->uniform1f(program->flipLocation(), !!(flags & ShouldFlipTexture)); 380 m_context3D->uniform2f(program->textureSizeLocation(), textureSize.width(), textureSize.height()); 418 381 419 382 if (TextureMapperShaderProgram::isValidUniformLocation(program->opacityLocation())) 420 GL_CMD(glUniform1f(program->opacityLocation(), opacity));383 m_context3D->uniform1f(program->opacityLocation(), opacity); 421 384 422 385 if (maskTexture && maskTexture->isValid() && TextureMapperShaderProgram::isValidUniformLocation(program->maskTextureLocation())) { 423 386 const BitmapTextureGL* maskTextureGL = static_cast<const BitmapTextureGL*>(maskTexture); 424 GL_CMD(glActiveTexture(GL_TEXTURE1));425 GL_CMD(glBindTexture(GL_TEXTURE_2D, maskTextureGL->id()));426 GL_CMD(glUniform1i(program->maskTextureLocation(), 1));427 GL_CMD(glActiveTexture(GL_TEXTURE0));387 m_context3D->activeTexture(GraphicsContext3D::TEXTURE1); 388 m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, maskTextureGL->id()); 389 m_context3D->uniform1i(program->maskTextureLocation(), 1); 390 m_context3D->activeTexture(GraphicsContext3D::TEXTURE0); 428 391 } 429 392 430 393 bool needsBlending = (flags & SupportsBlending) || opacity < 0.99 || maskTexture; 431 drawQuad(targetRect, modelViewMatrix, program.get(), G L_TRIANGLE_FAN, needsBlending);432 } 433 #endif // defined(GL_ARB_texture_rectangle)394 drawQuad(targetRect, modelViewMatrix, program.get(), GraphicsContext3D::TRIANGLE_FAN, needsBlending); 395 } 396 #endif // !USE(TEXMAP_OPENGL_ES_2) 434 397 435 398 void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize& /* textureSize */, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture, unsigned exposedEdges) 436 399 { 437 bool needsAnti liaing = m_enableEdgeDistanceAntialiasing && !modelViewMatrix.isIntegerTranslation();438 if (needsAnti liaing && drawTextureWithAntialiasing(texture, flags, targetRect, modelViewMatrix, opacity, maskTexture, exposedEdges))400 bool needsAntialiasing = m_enableEdgeDistanceAntialiasing && !modelViewMatrix.isIntegerTranslation(); 401 if (needsAntialiasing && drawTextureWithAntialiasing(texture, flags, targetRect, modelViewMatrix, opacity, maskTexture, exposedEdges)) 439 402 return; 440 403 … … 444 407 else 445 408 program = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple); 446 GL_CMD(glUseProgram(program->id()));409 m_context3D->useProgram(program->id()); 447 410 448 411 drawTexturedQuadWithProgram(program.get(), texture, flags, targetRect, modelViewMatrix, opacity, maskTexture); 449 412 } 450 413 451 static TransformationMatrix viewportMatrix( )452 { 453 G Lint viewport[4];454 GL_CMD(glGetIntegerv(GL_VIEWPORT, viewport));414 static TransformationMatrix viewportMatrix(GraphicsContext3D* context3D) 415 { 416 GC3Dint viewport[4]; 417 context3D->getIntegerv(GraphicsContext3D::VIEWPORT, viewport); 455 418 456 419 TransformationMatrix matrix; … … 549 512 // translates from normalized device coordinates to screen coordinates), because these 550 513 // values are consumed in the fragment shader, which works in screen coordinates. 551 TransformationMatrix screenSpaceTransform = viewportMatrix( ).multiply(TransformationMatrix(data().projectionMatrix)).multiply(modelViewMatrix).to2dTransform();514 TransformationMatrix screenSpaceTransform = viewportMatrix(m_context3D.get()).multiply(TransformationMatrix(data().projectionMatrix)).multiply(modelViewMatrix).to2dTransform(); 552 515 if (!screenSpaceTransform.isInvertible()) 553 516 return false; … … 573 536 574 537 RefPtr<TextureMapperShaderProgramAntialiasingNoMask> program = data().sharedGLData().textureMapperShaderManager.antialiasingNoMaskProgram(); 575 GL_CMD(glUseProgram(program->id()));576 GL_CMD(glUniform3fv(program->expandedQuadEdgesInScreenSpaceLocation(), 8, targetQuadEdges));538 m_context3D->useProgram(program->id()); 539 m_context3D->uniform3fv(program->expandedQuadEdgesInScreenSpaceLocation(), 8, targetQuadEdges); 577 540 578 541 drawTexturedQuadWithProgram(program.get(), texture, flags, DrawQuad(originalTargetRect, expandedQuadInTextureCoordinates), modelViewMatrix, opacity, 0 /* maskTexture */); … … 582 545 void TextureMapperGL::drawTexturedQuadWithProgram(TextureMapperShaderProgram* program, uint32_t texture, Flags flags, const DrawQuad& quadToDraw, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture) 583 546 { 584 GL_CMD(glEnableVertexAttribArray(program->vertexAttrib()));585 GL_CMD(glActiveTexture(GL_TEXTURE0));586 GL_CMD(glBindTexture(GL_TEXTURE_2D, texture));587 GL_CMD(glUniform1i(program->sourceTextureLocation(), 0));588 589 GL_CMD(glUniform1f(program->flipLocation(), !!(flags & ShouldFlipTexture)));547 m_context3D->enableVertexAttribArray(program->vertexAttrib()); 548 m_context3D->activeTexture(GraphicsContext3D::TEXTURE0); 549 m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, texture); 550 m_context3D->uniform1i(program->sourceTextureLocation(), 0); 551 552 m_context3D->uniform1f(program->flipLocation(), !!(flags & ShouldFlipTexture)); 590 553 591 554 if (TextureMapperShaderProgram::isValidUniformLocation(program->opacityLocation())) 592 GL_CMD(glUniform1f(program->opacityLocation(), opacity));555 m_context3D->uniform1f(program->opacityLocation(), opacity); 593 556 594 557 if (maskTexture && maskTexture->isValid() && TextureMapperShaderProgram::isValidUniformLocation(program->maskTextureLocation())) { 595 558 const BitmapTextureGL* maskTextureGL = static_cast<const BitmapTextureGL*>(maskTexture); 596 GL_CMD(glActiveTexture(GL_TEXTURE1));597 GL_CMD(glBindTexture(GL_TEXTURE_2D, maskTextureGL->id()));598 GL_CMD(glUniform1i(program->maskTextureLocation(), 1));599 GL_CMD(glActiveTexture(GL_TEXTURE0));559 m_context3D->activeTexture(GraphicsContext3D::TEXTURE1); 560 m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, maskTextureGL->id()); 561 m_context3D->uniform1i(program->maskTextureLocation(), 1); 562 m_context3D->activeTexture(GraphicsContext3D::TEXTURE0); 600 563 } 601 564 602 565 bool needsBlending = (flags & SupportsBlending) || opacity < 0.99 || maskTexture; 603 drawQuad(quadToDraw, modelViewMatrix, program, G L_TRIANGLE_FAN, needsBlending);566 drawQuad(quadToDraw, modelViewMatrix, program, GraphicsContext3D::TRIANGLE_FAN, needsBlending); 604 567 } 605 568 … … 612 575 #define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE GL_UNSIGNED_INT_8_8_8_8_REV 613 576 #else 614 #define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE G L_UNSIGNED_BYTE577 #define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE GraphicsContext3D::UNSIGNED_BYTE 615 578 #endif 616 579 … … 647 610 void BitmapTextureGL::didReset() 648 611 { 612 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 613 649 614 if (!m_id) 650 GL_CMD(glGenTextures(1, &m_id));615 m_id = context3D->createTexture(); 651 616 652 617 m_shouldClear = true; … … 654 619 return; 655 620 656 GLuint format = driverSupportsBGRASwizzling() ? GL_BGRA : GL_RGBA;621 Platform3DObject format = driverSupportsBGRASwizzling() ? GraphicsContext3D::BGRA : GraphicsContext3D::RGBA; 657 622 658 623 m_textureSize = contentSize(); 659 GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id));660 GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));661 GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));662 GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));663 GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));664 GL_CMD(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureSize.width(), m_textureSize.height(), 0, format, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0));624 context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, m_id); 625 context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); 626 context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); 627 context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); 628 context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); 629 context3D->texImage2DDirect(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, m_textureSize.width(), m_textureSize.height(), 0, format, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0); 665 630 } 666 631 … … 668 633 void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect, const IntPoint& sourceOffset, int bytesPerLine) 669 634 { 670 GLuint glFormat = GL_RGBA; 671 GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)); 635 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 636 637 Platform3DObject glFormat = GraphicsContext3D::RGBA; 638 context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, m_id); 672 639 673 640 const unsigned bytesPerPixel = 4; 674 641 if (driverSupportsBGRASwizzling()) 675 glFormat = G L_BGRA;642 glFormat = GraphicsContext3D::BGRA; 676 643 else 677 644 swizzleBGRAToRGBA(reinterpret_cast<uint32_t*>(const_cast<void*>(data)), IntRect(sourceOffset, targetRect.size()), bytesPerLine / bytesPerPixel); 678 645 679 646 if (bytesPerLine == targetRect.width() / 4 && sourceOffset == IntPoint::zero()) { 680 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));647 context3D->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data); 681 648 return; 682 649 } … … 696 663 } 697 664 698 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, temporaryData.data()));665 context3D->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, temporaryData.data()); 699 666 return; 700 667 } … … 702 669 #if !defined(TEXMAP_OPENGL_ES_2) 703 670 // Use the OpenGL sub-image extension, now that we know it's available. 704 GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel));705 GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, sourceOffset.y()));706 GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, sourceOffset.x()));707 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));708 GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));709 GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, 0));710 GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0));671 context3D->pixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel); 672 context3D->pixelStorei(GL_UNPACK_SKIP_ROWS, sourceOffset.y()); 673 context3D->pixelStorei(GL_UNPACK_SKIP_PIXELS, sourceOffset.x()); 674 context3D->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data); 675 context3D->pixelStorei(GL_UNPACK_ROW_LENGTH, 0); 676 context3D->pixelStorei(GL_UNPACK_SKIP_ROWS, 0); 677 context3D->pixelStorei(GL_UNPACK_SKIP_PIXELS, 0); 711 678 #endif 712 679 } … … 744 711 program->prepare(filter, pass, sourceTexture.contentSize(), static_cast<const BitmapTextureGL&>(contentTexture).id()); 745 712 746 GL_CMD(glEnableVertexAttribArray(program->vertexAttrib()));747 GL_CMD(glEnableVertexAttribArray(program->texCoordAttrib()));748 GL_CMD(glActiveTexture(GL_TEXTURE0));749 GL_CMD(glBindTexture(GL_TEXTURE_2D, static_cast<const BitmapTextureGL&>(sourceTexture).id()));750 glUniform1i(program->textureUniform(), 0);751 const G Lfloat targetVertices[] = {-1, -1, 1, -1, 1, 1, -1, 1};752 const G Lfloat sourceVertices[] = {0, 0, 1, 0, 1, 1, 0, 1};753 GL_CMD(glVertexAttribPointer(program->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0,targetVertices));754 GL_CMD(glVertexAttribPointer(program->texCoordAttrib(), 2, GL_FLOAT, GL_FALSE, 0,sourceVertices));755 GL_CMD(glDisable(GL_BLEND));756 GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));757 GL_CMD(glDisableVertexAttribArray(program->vertexAttrib()));758 GL_CMD(glDisableVertexAttribArray(program->texCoordAttrib()));713 m_context3D->enableVertexAttribArray(program->vertexAttrib()); 714 m_context3D->enableVertexAttribArray(program->texCoordAttrib()); 715 m_context3D->activeTexture(GraphicsContext3D::TEXTURE0); 716 m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, static_cast<const BitmapTextureGL&>(sourceTexture).id()); 717 m_context3D->uniform1i(program->textureUniform(), 0); 718 const GC3Dfloat targetVertices[] = {-1, -1, 1, -1, 1, 1, -1, 1}; 719 const GC3Dfloat sourceVertices[] = {0, 0, 1, 0, 1, 1, 0, 1}; 720 m_context3D->vertexAttribPointer(program->vertexAttrib(), 2, GraphicsContext3D::FLOAT, false, 0, GC3Dintptr(targetVertices)); 721 m_context3D->vertexAttribPointer(program->texCoordAttrib(), 2, GraphicsContext3D::FLOAT, false, 0, GC3Dintptr(sourceVertices)); 722 m_context3D->disable(GraphicsContext3D::BLEND); 723 m_context3D->drawArrays(GraphicsContext3D::TRIANGLE_FAN, 0, 4); 724 m_context3D->disableVertexAttribArray(program->vertexAttrib()); 725 m_context3D->disableVertexAttribArray(program->texCoordAttrib()); 759 726 } 760 727 … … 797 764 if (m_rbo) 798 765 return; 799 GL_CMD(glGenRenderbuffers(1, &m_rbo)); 800 GL_CMD(glBindRenderbuffer(GL_RENDERBUFFER, m_rbo)); 766 767 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 768 m_rbo = context3D->createRenderbuffer(); 769 context3D->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_rbo); 801 770 #ifdef TEXMAP_OPENGL_ES_2 802 GL_CMD(glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, m_textureSize.width(), m_textureSize.height()));771 context3D->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::STENCIL_INDEX8, m_textureSize.width(), m_textureSize.height()); 803 772 #else 804 GL_CMD(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, m_textureSize.width(), m_textureSize.height()));805 #endif 806 GL_CMD(glBindRenderbuffer(GL_RENDERBUFFER, 0));807 GL_CMD(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_rbo));808 GL_CMD(glClearStencil(0));809 GL_CMD(glClear(GL_STENCIL_BUFFER_BIT));773 context3D->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_STENCIL, m_textureSize.width(), m_textureSize.height()); 774 #endif 775 context3D->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, 0); 776 context3D->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::STENCIL_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_rbo); 777 context3D->clearStencil(0); 778 context3D->clear(GraphicsContext3D::STENCIL_BUFFER_BIT); 810 779 } 811 780 … … 815 784 return; 816 785 786 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 787 817 788 m_clipStack.init(IntRect(IntPoint::zero(), m_textureSize)); 818 m_clipStack.apply( );819 GL_CMD(glClearColor(0, 0, 0, 0));820 GL_CMD(glClear(GL_COLOR_BUFFER_BIT));789 m_clipStack.apply(context3D); 790 context3D->clearColor(0, 0, 0, 0); 791 context3D->clear(GraphicsContext3D::COLOR_BUFFER_BIT); 821 792 m_shouldClear = false; 822 793 } … … 827 798 return; 828 799 829 GL_CMD(glGenFramebuffers(1, &m_fbo)); 830 GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo)); 831 GL_CMD(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id(), 0)); 800 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 801 m_fbo = context3D->createFramebuffer(); 802 context3D->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 803 context3D->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, id(), 0); 832 804 m_shouldClear = true; 833 805 } … … 835 807 void BitmapTextureGL::bind() 836 808 { 837 GL_CMD(glBindTexture(GL_TEXTURE_2D, 0)); 809 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 810 context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); 838 811 createFboIfNeeded(); 839 GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo));840 GL_CMD(glViewport(0, 0, m_textureSize.width(), m_textureSize.height()));812 context3D->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 813 context3D->viewport(0, 0, m_textureSize.width(), m_textureSize.height()); 841 814 clearIfNeeded(); 842 815 m_textureMapper->data().projectionMatrix = createProjectionMatrix(m_textureSize, true /* mirrored */); 843 m_clipStack.apply( );816 m_clipStack.apply(context3D); 844 817 } 845 818 846 819 BitmapTextureGL::~BitmapTextureGL() 847 820 { 821 GraphicsContext3D* context3D = m_textureMapper->graphicsContext3D(); 822 848 823 if (m_id) 849 GL_CMD(glDeleteTextures(1, &m_id));824 context3D->deleteTexture(m_id); 850 825 851 826 if (m_fbo) 852 GL_CMD(glDeleteFramebuffers(1, &m_fbo));827 context3D->deleteFramebuffer(m_fbo); 853 828 854 829 if (m_rbo) 855 GL_CMD(glDeleteRenderbuffers(1, &m_rbo));830 context3D->deleteRenderbuffer(m_rbo); 856 831 } 857 832 … … 873 848 void TextureMapperGL::bindDefaultSurface() 874 849 { 875 GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, data().targetFrameBuffer));850 m_context3D->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, data().targetFrameBuffer); 876 851 IntSize viewportSize(data().viewport[2], data().viewport[3]); 877 852 data().projectionMatrix = createProjectionMatrix(viewportSize, data().PaintFlags & PaintingMirrored); 878 GL_CMD(glViewport(data().viewport[0], data().viewport[1], viewportSize.width(), viewportSize.height()));879 m_clipStack.apply( );853 m_context3D->viewport(data().viewport[0], data().viewport[1], viewportSize.width(), viewportSize.height()); 854 m_clipStack.apply(m_context3D.get()); 880 855 data().currentSurface.clear(); 881 856 } … … 907 882 908 883 clipStack().current().scissorBox.intersect(rect); 909 clipStack().apply( );884 clipStack().apply(m_context3D.get()); 910 885 return true; 911 886 } … … 921 896 RefPtr<TextureMapperShaderProgram> program = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple); 922 897 923 GL_CMD(glUseProgram(program->id()));924 GL_CMD(glEnableVertexAttribArray(program->vertexAttrib()));925 const G Lfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};926 GL_CMD(glVertexAttribPointer(program->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0,unitRect));898 m_context3D->useProgram(program->id()); 899 m_context3D->enableVertexAttribArray(program->vertexAttrib()); 900 const GC3Dfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1}; 901 m_context3D->vertexAttribPointer(program->vertexAttrib(), 2, GraphicsContext3D::FLOAT, false, 0, GC3Dintptr(unitRect)); 927 902 928 903 TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix) … … 933 908 targetRect.x(), targetRect.y(), 0, 1)); 934 909 935 const G Lfloat m4[] = {910 const GC3Dfloat m4[] = { 936 911 matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(), 937 912 matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(), … … 940 915 }; 941 916 942 const G Lfloat m4all[] = {917 const GC3Dfloat m4all[] = { 943 918 2, 0, 0, 0, 944 919 0, 2, 0, 0, … … 949 924 int& stencilIndex = clipStack().current().stencilIndex; 950 925 951 GL_CMD(glEnable(GL_STENCIL_TEST));926 m_context3D->enable(GraphicsContext3D::STENCIL_TEST); 952 927 953 928 // Make sure we don't do any actual drawing. 954 GL_CMD(glStencilFunc(GL_NEVER, stencilIndex, stencilIndex));929 m_context3D->stencilFunc(GraphicsContext3D::NEVER, stencilIndex, stencilIndex); 955 930 956 931 // Operate only on the stencilIndex and above. 957 GL_CMD(glStencilMask(0xff & ~(stencilIndex - 1)));932 m_context3D->stencilMask(0xff & ~(stencilIndex - 1)); 958 933 959 934 // First clear the entire buffer at the current index. 960 GL_CMD(glUniformMatrix4fv(program->matrixLocation(), 1, GL_FALSE,m4all));961 GL_CMD(glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO));962 GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));935 m_context3D->uniformMatrix4fv(program->matrixLocation(), 1, false, const_cast<GC3Dfloat*>(m4all)); 936 m_context3D->stencilOp(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO, GraphicsContext3D::ZERO); 937 m_context3D->drawArrays(GraphicsContext3D::TRIANGLE_FAN, 0, 4); 963 938 964 939 // Now apply the current index to the new quad. 965 GL_CMD(glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE));966 GL_CMD(glUniformMatrix4fv(program->matrixLocation(), 1, GL_FALSE,m4));967 GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));940 m_context3D->stencilOp(GraphicsContext3D::REPLACE, GraphicsContext3D::REPLACE, GraphicsContext3D::REPLACE); 941 m_context3D->uniformMatrix4fv(program->matrixLocation(), 1, false, const_cast<GC3Dfloat*>(m4)); 942 m_context3D->drawArrays(GraphicsContext3D::TRIANGLE_FAN, 0, 4); 968 943 969 944 // Clear the state. 970 GL_CMD(glDisableVertexAttribArray(program->vertexAttrib()));971 GL_CMD(glStencilMask(0));945 m_context3D->disableVertexAttribArray(program->vertexAttrib()); 946 m_context3D->stencilMask(0); 972 947 973 948 // Increase stencilIndex and apply stencil testing. 974 949 stencilIndex *= 2; 975 clipStack().apply( );950 clipStack().apply(m_context3D.get()); 976 951 } 977 952 … … 979 954 { 980 955 clipStack().pop(); 981 clipStack().apply( );956 clipStack().apply(m_context3D.get()); 982 957 } 983 958 984 959 PassRefPtr<BitmapTexture> TextureMapperGL::createTexture() 985 960 { 986 BitmapTextureGL* texture = new BitmapTextureGL(); 987 texture->setTextureMapper(this); 961 BitmapTextureGL* texture = new BitmapTextureGL(this); 988 962 return adoptRef(texture); 989 963 } -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
r126743 r127063 24 24 25 25 #include "FloatQuad.h" 26 #include "GraphicsContext3D.h" 26 27 #include "IntSize.h" 27 #include "OpenGLShims.h"28 28 #include "TextureMapper.h" 29 29 #include "TransformationMatrix.h" … … 39 39 public: 40 40 static PassOwnPtr<TextureMapperGL> create() { return adoptPtr(new TextureMapperGL); } 41 TextureMapperGL();42 41 virtual ~TextureMapperGL(); 43 42 … … 55 54 virtual void drawTexture(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture, unsigned exposedEdges = AllEdges); 56 55 57 #if defined(GL_ARB_texture_rectangle)56 #if !USE(TEXMAP_OPENGL_ES_2) 58 57 virtual void drawTextureRectangleARB(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture); 59 58 #endif … … 67 66 virtual PassRefPtr<BitmapTexture> createTexture() OVERRIDE; 68 67 virtual GraphicsContext* graphicsContext() OVERRIDE { return m_context; } 68 inline GraphicsContext3D* graphicsContext3D() const { return m_context3D.get(); } 69 69 virtual void setGraphicsContext(GraphicsContext* context) OVERRIDE { m_context = context; } 70 70 … … 76 76 77 77 private: 78 79 78 struct ClipState { 80 79 IntRect scissorBox; … … 90 89 void push(); 91 90 void pop(); 92 void apply( );91 void apply(GraphicsContext3D*); 93 92 inline ClipState& current() { return clipState; } 94 93 void init(const IntRect&); … … 110 109 }; 111 110 111 TextureMapperGL(); 112 112 113 bool drawTextureWithAntialiasing(uint32_t texture, Flags, const FloatRect& originalTargetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture, unsigned exposedEdges); 113 114 void drawTexturedQuadWithProgram(TextureMapperShaderProgram*, uint32_t texture, Flags, const DrawQuad&, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture); 114 void drawQuad(const DrawQuad&, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram*, G Lenum drawingMode, bool needsBlending);115 void drawQuad(const DrawQuad&, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram*, GC3Denum drawingMode, bool needsBlending); 115 116 116 117 bool beginScissorClip(const TransformationMatrix&, const FloatRect&); … … 118 119 ClipStack& clipStack(); 119 120 inline TextureMapperGLData& data() { return *m_data; } 121 GraphicsContext* m_context; 122 RefPtr<GraphicsContext3D> m_context3D; 120 123 TextureMapperGLData* m_data; 121 GraphicsContext* m_context;122 124 ClipStack m_clipStack; 123 125 bool m_enableEdgeDistanceAntialiasing; … … 136 138 ~BitmapTextureGL(); 137 139 virtual uint32_t id() const { return m_id; } 138 uint32_t textureTarget() const { return G L_TEXTURE_2D; }140 uint32_t textureTarget() const { return GraphicsContext3D::TEXTURE_2D; } 139 141 IntSize textureSize() const { return m_textureSize; } 140 142 void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; } … … 148 150 149 151 private: 150 GLuint m_id;152 Platform3DObject m_id; 151 153 IntSize m_textureSize; 152 154 IntRect m_dirtyRect; 153 GLuint m_fbo;154 GLuint m_rbo;155 Platform3DObject m_fbo; 156 Platform3DObject m_rbo; 155 157 bool m_shouldClear; 158 TextureMapperGL::ClipStack m_clipStack; 156 159 TextureMapperGL* m_textureMapper; 157 TextureMapperGL::ClipStack m_clipStack; 158 BitmapTextureGL() 160 161 BitmapTextureGL(); 162 BitmapTextureGL(TextureMapperGL* textureMapper) 159 163 : m_id(0) 160 164 , m_fbo(0) 161 165 , m_rbo(0) 162 166 , m_shouldClear(true) 163 , m_textureMapper( 0)167 , m_textureMapper(textureMapper) 164 168 { 165 169 } -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp
r126926 r127063 31 31 namespace WebCore { 32 32 33 #ifndef TEXMAP_OPENGL_ES_2 34 #define OES2_PRECISION_DEFINITIONS \ 35 "#define lowp\n#define highp\n" 36 #define OES2_FRAGMENT_SHADER_DEFAULT_PRECISION 37 #else 38 #define OES2_PRECISION_DEFINITIONS 39 #define OES2_FRAGMENT_SHADER_DEFAULT_PRECISION \ 40 "precision mediump float; \n" 41 #endif 42 43 #define STRINGIFY_VAL(src...) #src 44 #define VERTEX_SHADER(src...) OES2_PRECISION_DEFINITIONS\ 45 STRINGIFY_VAL(src) 46 #define FRAGMENT_SHADER(src...) OES2_PRECISION_DEFINITIONS\ 47 OES2_FRAGMENT_SHADER_DEFAULT_PRECISION\ 48 STRINGIFY_VAL(src) 33 #define STRINGIFY(src...) #src 49 34 50 35 static const char* fragmentShaderSourceOpacityAndMask = 51 FRAGMENT_SHADER( 36 STRINGIFY( 37 precision mediump float; 52 38 uniform sampler2D s_source; 53 39 uniform sampler2D s_mask; … … 65 51 66 52 static const char* fragmentShaderSourceRectOpacityAndMask = 67 FRAGMENT_SHADER( 53 STRINGIFY( 54 precision mediump float; 68 55 uniform sampler2DRect s_source; 69 56 uniform sampler2DRect s_mask; … … 81 68 82 69 static const char* vertexShaderSourceOpacityAndMask = 83 VERTEX_SHADER(70 STRINGIFY( 84 71 uniform mat4 u_matrix; 85 72 uniform lowp float u_flip; … … 96 83 97 84 static const char* fragmentShaderSourceSimple = 98 FRAGMENT_SHADER( 85 STRINGIFY( 86 precision mediump float; 99 87 uniform sampler2D s_source; 100 88 uniform lowp float u_opacity; … … 108 96 109 97 static const char* fragmentShaderSourceAntialiasingNoMask = 110 FRAGMENT_SHADER( 98 STRINGIFY( 99 precision mediump float; 111 100 uniform sampler2D s_source; 112 101 varying highp vec2 v_sourceTexCoord; … … 146 135 147 136 static const char* fragmentShaderSourceRectSimple = 148 FRAGMENT_SHADER( 137 STRINGIFY( 138 precision mediump float; 149 139 uniform sampler2DRect s_source; 150 140 uniform lowp vec2 u_textureSize; … … 159 149 160 150 static const char* vertexShaderSourceSimple = 161 VERTEX_SHADER(151 STRINGIFY( 162 152 uniform mat4 u_matrix; 163 153 uniform lowp float u_flip; … … 172 162 173 163 static const char* vertexShaderSourceSolidColor = 174 VERTEX_SHADER(164 STRINGIFY( 175 165 uniform mat4 u_matrix; 176 166 attribute vec4 a_vertex; … … 183 173 184 174 static const char* fragmentShaderSourceSolidColor = 185 VERTEX_SHADER( 175 STRINGIFY( 176 precision mediump float; 186 177 uniform vec4 u_color; 187 178 void main(void) … … 213 204 switch (shaderType) { 214 205 case Simple: 215 program = TextureMapperShaderProgramSimple::create( );206 program = TextureMapperShaderProgramSimple::create(m_context); 216 207 break; 217 208 case RectSimple: 218 program = TextureMapperShaderProgramRectSimple::create( );209 program = TextureMapperShaderProgramRectSimple::create(m_context); 219 210 break; 220 211 case AntialiasingNoMask: 221 program = TextureMapperShaderProgramAntialiasingNoMask::create( );212 program = TextureMapperShaderProgramAntialiasingNoMask::create(m_context); 222 213 break; 223 214 case OpacityAndMask: 224 program = TextureMapperShaderProgramOpacityAndMask::create( );215 program = TextureMapperShaderProgramOpacityAndMask::create(m_context); 225 216 break; 226 217 case RectOpacityAndMask: 227 program = TextureMapperShaderProgramRectOpacityAndMask::create( );218 program = TextureMapperShaderProgramRectOpacityAndMask::create(m_context); 228 219 break; 229 220 case SolidColor: 230 program = TextureMapperShaderProgramSolidColor::create( );221 program = TextureMapperShaderProgramSolidColor::create(m_context); 231 222 break; 232 223 case Invalid: … … 237 228 } 238 229 239 TextureMapperShaderProgram::TextureMapperShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource) 240 : m_id(0) 230 TextureMapperShaderProgram::TextureMapperShaderProgram(GraphicsContext3D* context, const char* vertexShaderSource, const char* fragmentShaderSource) 231 : m_context(context) 232 , m_id(0) 241 233 , m_vertexAttrib(0) 242 234 , m_vertexShader(0) … … 257 249 const char* vertexShaderSourceProgram = vertexShaderSource(); 258 250 const char* fragmentShaderSourceProgram = fragmentShaderSource(); 259 GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);260 GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);261 glShaderSource(vertexShader, 1, &vertexShaderSourceProgram, 0);262 glShaderSource(fragmentShader, 1, &fragmentShaderSourceProgram, 0);263 GLuint programID = glCreateProgram();264 glCompileShader(vertexShader);265 glCompileShader(fragmentShader);266 267 glAttachShader(programID, vertexShader);268 glAttachShader(programID, fragmentShader);269 glLinkProgram(programID);270 271 m_vertexAttrib = glGetAttribLocation(programID, "a_vertex");251 Platform3DObject vertexShader = m_context->createShader(GraphicsContext3D::VERTEX_SHADER); 252 Platform3DObject fragmentShader = m_context->createShader(GraphicsContext3D::FRAGMENT_SHADER); 253 m_context->shaderSource(vertexShader, vertexShaderSourceProgram); 254 m_context->shaderSource(fragmentShader, fragmentShaderSourceProgram); 255 Platform3DObject programID = m_context->createProgram(); 256 m_context->compileShader(vertexShader); 257 m_context->compileShader(fragmentShader); 258 259 m_context->attachShader(programID, vertexShader); 260 m_context->attachShader(programID, fragmentShader); 261 m_context->linkProgram(programID); 262 263 m_vertexAttrib = m_context->getAttribLocation(programID, "a_vertex"); 272 264 273 265 m_id = programID; … … 276 268 } 277 269 278 void TextureMapperShaderProgram::getUniformLocation(G Lint &variable, const char* name)279 { 280 variable = glGetUniformLocation(m_id, name);270 void TextureMapperShaderProgram::getUniformLocation(GC3Dint &variable, const char* name) 271 { 272 variable = m_context->getUniformLocation(m_id, name); 281 273 ASSERT(variable >= 0); 282 274 } … … 284 276 TextureMapperShaderProgram::~TextureMapperShaderProgram() 285 277 { 286 GLuint programID = m_id;278 Platform3DObject programID = m_id; 287 279 if (!programID) 288 280 return; 289 281 290 glDetachShader(programID, m_vertexShader);291 glDeleteShader(m_vertexShader);292 glDetachShader(programID, m_fragmentShader);293 glDeleteShader(m_fragmentShader);294 glDeleteProgram(programID);295 } 296 297 TextureMapperShaderProgramSimple::TextureMapperShaderProgramSimple( )298 : TextureMapperShaderProgram( vertexShaderSourceSimple, fragmentShaderSourceSimple)282 m_context->detachShader(programID, m_vertexShader); 283 m_context->deleteShader(m_vertexShader); 284 m_context->detachShader(programID, m_fragmentShader); 285 m_context->deleteShader(m_fragmentShader); 286 m_context->deleteProgram(programID); 287 } 288 289 TextureMapperShaderProgramSimple::TextureMapperShaderProgramSimple(GraphicsContext3D* context) 290 : TextureMapperShaderProgram(context, vertexShaderSourceSimple, fragmentShaderSourceSimple) 299 291 { 300 292 initializeProgram(); … … 305 297 } 306 298 307 TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor( )308 : TextureMapperShaderProgram( vertexShaderSourceSolidColor, fragmentShaderSourceSolidColor)299 TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor(GraphicsContext3D* context) 300 : TextureMapperShaderProgram(context, vertexShaderSourceSolidColor, fragmentShaderSourceSolidColor) 309 301 { 310 302 initializeProgram(); … … 313 305 } 314 306 315 TextureMapperShaderProgramRectSimple::TextureMapperShaderProgramRectSimple( )316 : TextureMapperShaderProgram( vertexShaderSourceSimple, fragmentShaderSourceRectSimple)307 TextureMapperShaderProgramRectSimple::TextureMapperShaderProgramRectSimple(GraphicsContext3D* context) 308 : TextureMapperShaderProgram(context, vertexShaderSourceSimple, fragmentShaderSourceRectSimple) 317 309 { 318 310 initializeProgram(); … … 324 316 } 325 317 326 TextureMapperShaderProgramOpacityAndMask::TextureMapperShaderProgramOpacityAndMask( )327 : TextureMapperShaderProgram( vertexShaderSourceOpacityAndMask, fragmentShaderSourceOpacityAndMask)318 TextureMapperShaderProgramOpacityAndMask::TextureMapperShaderProgramOpacityAndMask(GraphicsContext3D* context) 319 : TextureMapperShaderProgram(context, vertexShaderSourceOpacityAndMask, fragmentShaderSourceOpacityAndMask) 328 320 { 329 321 initializeProgram(); … … 335 327 } 336 328 337 TextureMapperShaderProgramRectOpacityAndMask::TextureMapperShaderProgramRectOpacityAndMask( )338 : TextureMapperShaderProgram( vertexShaderSourceOpacityAndMask, fragmentShaderSourceRectOpacityAndMask)329 TextureMapperShaderProgramRectOpacityAndMask::TextureMapperShaderProgramRectOpacityAndMask(GraphicsContext3D* context) 330 : TextureMapperShaderProgram(context, vertexShaderSourceOpacityAndMask, fragmentShaderSourceRectOpacityAndMask) 339 331 { 340 332 initializeProgram(); … … 346 338 } 347 339 348 TextureMapperShaderProgramAntialiasingNoMask::TextureMapperShaderProgramAntialiasingNoMask( )349 : TextureMapperShaderProgram( vertexShaderSourceSimple, fragmentShaderSourceAntialiasingNoMask)340 TextureMapperShaderProgramAntialiasingNoMask::TextureMapperShaderProgramAntialiasingNoMask(GraphicsContext3D* context) 341 : TextureMapperShaderProgram(context, vertexShaderSourceSimple, fragmentShaderSourceAntialiasingNoMask) 350 342 { 351 343 initializeProgram(); … … 357 349 } 358 350 359 TextureMapperShaderManager::TextureMapperShaderManager( )360 { 361 ASSERT(initializeOpenGLShims()); 351 TextureMapperShaderManager::TextureMapperShaderManager(GraphicsContext3D* context) 352 : m_context(context) 353 { 362 354 } 363 355 … … 374 366 StandardFilterProgram::~StandardFilterProgram() 375 367 { 376 glDetachShader(m_id, m_vertexShader); 377 glDeleteShader(m_vertexShader); 378 glDetachShader(m_id, m_fragmentShader); 379 glDeleteShader(m_fragmentShader); 380 glDeleteProgram(m_id); 381 } 382 383 StandardFilterProgram::StandardFilterProgram(FilterOperation::OperationType type, unsigned pass) 384 : m_id(0) 368 m_context->detachShader(m_id, m_vertexShader); 369 m_context->deleteShader(m_vertexShader); 370 m_context->detachShader(m_id, m_fragmentShader); 371 m_context->deleteShader(m_fragmentShader); 372 m_context->deleteProgram(m_id); 373 } 374 375 StandardFilterProgram::StandardFilterProgram(GraphicsContext3D* context, FilterOperation::OperationType type, unsigned pass) 376 : m_context(context) 377 , m_id(0) 385 378 { 386 379 const char* vertexShaderSource = 387 VERTEX_SHADER(380 STRINGIFY( 388 381 attribute vec4 a_vertex; 389 382 attribute vec4 a_texCoord; … … 397 390 398 391 #define STANDARD_FILTER(x...) \ 399 OES2_PRECISION_DEFINITIONS\ 400 OES2_FRAGMENT_SHADER_DEFAULT_PRECISION\ 392 "precision mediump float;\n"\ 401 393 "varying highp vec2 v_texCoord;\n"\ 402 394 "uniform highp float u_amount;\n"\ … … 491 483 break; 492 484 case FilterOperation::BLUR: 493 fragmentShaderSource = FRAGMENT_SHADER( 485 fragmentShaderSource = STRINGIFY( 486 precision mediump float; 494 487 varying highp vec2 v_texCoord; 495 488 uniform lowp vec2 u_blurRadius; … … 524 517 case 0: { 525 518 // First pass: horizontal alpha blur. 526 fragmentShaderSource = FRAGMENT_SHADER( 519 fragmentShaderSource = STRINGIFY( 520 precision mediump float; 527 521 varying highp vec2 v_texCoord; 528 522 uniform lowp float u_shadowBlurRadius; … … 557 551 case 1: { 558 552 // Second pass: vertical alpha blur and composite with origin. 559 fragmentShaderSource = FRAGMENT_SHADER( 553 fragmentShaderSource = STRINGIFY( 554 precision mediump float; 560 555 varying highp vec2 v_texCoord; 561 556 uniform lowp float u_shadowBlurRadius; … … 603 598 if (!fragmentShaderSource) 604 599 return; 605 GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);606 GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);607 glShaderSource(vertexShader, 1, &vertexShaderSource, 0);608 glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0);609 GLuint programID = glCreateProgram();610 glCompileShader(vertexShader);611 glCompileShader(fragmentShader);600 Platform3DObject vertexShader = m_context->createShader(GraphicsContext3D::VERTEX_SHADER); 601 Platform3DObject fragmentShader = m_context->createShader(GraphicsContext3D::FRAGMENT_SHADER); 602 m_context->shaderSource(vertexShader, vertexShaderSource); 603 m_context->shaderSource(fragmentShader, fragmentShaderSource); 604 Platform3DObject programID = m_context->createProgram(); 605 m_context->compileShader(vertexShader); 606 m_context->compileShader(fragmentShader); 612 607 #if !LOG_DISABLED 613 GLchar log[100]; 614 GLint len; 615 glGetShaderInfoLog(fragmentShader, 100, &len, log); 608 String log; 609 m_context->getShaderInfoLog(fragmentShader); 616 610 WTFLog(&LogCompositing, "%s\n", log); 617 611 #endif 618 glAttachShader(programID, vertexShader);619 glAttachShader(programID, fragmentShader);620 glLinkProgram(programID);621 622 m_vertexAttrib = glGetAttribLocation(programID, "a_vertex");623 m_texCoordAttrib = glGetAttribLocation(programID, "a_texCoord");624 m_textureUniformLocation = glGetUniformLocation(programID, "u_texture");612 m_context->attachShader(programID, vertexShader); 613 m_context->attachShader(programID, fragmentShader); 614 m_context->linkProgram(programID); 615 616 m_vertexAttrib = m_context->getAttribLocation(programID, "a_vertex"); 617 m_texCoordAttrib = m_context->getAttribLocation(programID, "a_texCoord"); 618 m_textureUniformLocation = m_context->getUniformLocation(programID, "u_texture"); 625 619 switch (type) { 626 620 case FilterOperation::GRAYSCALE: … … 632 626 case FilterOperation::CONTRAST: 633 627 case FilterOperation::OPACITY: 634 m_uniformLocations.amount = glGetUniformLocation(programID, "u_amount");628 m_uniformLocations.amount = m_context->getUniformLocation(programID, "u_amount"); 635 629 break; 636 630 case FilterOperation::BLUR: 637 m_uniformLocations.blur.radius = glGetUniformLocation(programID, "u_blurRadius");638 m_uniformLocations.blur.gaussianKernel = glGetUniformLocation(programID, "u_gaussianKernel");631 m_uniformLocations.blur.radius = m_context->getUniformLocation(programID, "u_blurRadius"); 632 m_uniformLocations.blur.gaussianKernel = m_context->getUniformLocation(programID, "u_gaussianKernel"); 639 633 break; 640 634 case FilterOperation::DROP_SHADOW: 641 m_uniformLocations.shadow.blurRadius = glGetUniformLocation(programID, "u_shadowBlurRadius");642 m_uniformLocations.shadow.gaussianKernel = glGetUniformLocation(programID, "u_gaussianKernel");635 m_uniformLocations.shadow.blurRadius = m_context->getUniformLocation(programID, "u_shadowBlurRadius"); 636 m_uniformLocations.shadow.gaussianKernel = m_context->getUniformLocation(programID, "u_gaussianKernel"); 643 637 if (!pass) 644 m_uniformLocations.shadow.offset = glGetUniformLocation(programID, "u_shadowOffset");638 m_uniformLocations.shadow.offset = m_context->getUniformLocation(programID, "u_shadowOffset"); 645 639 else { 646 640 // We only need the color and the content texture in the second pass, the first pass is only a horizontal alpha blur. 647 m_uniformLocations.shadow.color = glGetUniformLocation(programID, "u_shadowColor");648 m_uniformLocations.shadow.contentTexture = glGetUniformLocation(programID, "u_contentTexture");641 m_uniformLocations.shadow.color = m_context->getUniformLocation(programID, "u_shadowColor"); 642 m_uniformLocations.shadow.contentTexture = m_context->getUniformLocation(programID, "u_contentTexture"); 649 643 } 650 644 break; … … 657 651 } 658 652 659 PassRefPtr<StandardFilterProgram> StandardFilterProgram::create( FilterOperation::OperationType type, unsigned pass)660 { 661 RefPtr<StandardFilterProgram> program = adoptRef(new StandardFilterProgram( type, pass));653 PassRefPtr<StandardFilterProgram> StandardFilterProgram::create(GraphicsContext3D* context, FilterOperation::OperationType type, unsigned pass) 654 { 655 RefPtr<StandardFilterProgram> program = adoptRef(new StandardFilterProgram(context, type, pass)); 662 656 if (!program->m_id) 663 657 return 0; … … 695 689 } 696 690 697 void StandardFilterProgram::prepare(const FilterOperation& operation, unsigned pass, const IntSize& size, G Luint contentTexture)698 { 699 glUseProgram(m_id);691 void StandardFilterProgram::prepare(const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture) 692 { 693 m_context->useProgram(m_id); 700 694 switch (operation.getOperationType()) { 701 695 case FilterOperation::GRAYSCALE: … … 703 697 case FilterOperation::SATURATE: 704 698 case FilterOperation::HUE_ROTATE: 705 glUniform1f(m_uniformLocations.amount, static_cast<const BasicColorMatrixFilterOperation&>(operation).amount());699 m_context->uniform1f(m_uniformLocations.amount, static_cast<const BasicColorMatrixFilterOperation&>(operation).amount()); 706 700 break; 707 701 case FilterOperation::INVERT: … … 709 703 case FilterOperation::CONTRAST: 710 704 case FilterOperation::OPACITY: 711 glUniform1f(m_uniformLocations.amount, static_cast<const BasicComponentTransferFilterOperation&>(operation).amount());705 m_context->uniform1f(m_uniformLocations.amount, static_cast<const BasicComponentTransferFilterOperation&>(operation).amount()); 712 706 break; 713 707 case FilterOperation::BLUR: { … … 721 715 radius.setWidth(floatValueForLength(blur.stdDeviation(), size.width()) / size.width()); 722 716 723 glUniform2f(m_uniformLocations.blur.radius, radius.width(), radius.height());724 glUniform1fv(m_uniformLocations.blur.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel());717 m_context->uniform2f(m_uniformLocations.blur.radius, radius.width(), radius.height()); 718 m_context->uniform1fv(m_uniformLocations.blur.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel()); 725 719 break; 726 720 } … … 730 724 case 0: 731 725 // First pass: vertical alpha blur. 732 glUniform2f(m_uniformLocations.shadow.offset, float(shadow.location().x()) / float(size.width()), float(shadow.location().y()) / float(size.height()));733 glUniform1f(m_uniformLocations.shadow.blurRadius, shadow.stdDeviation() / float(size.width()));734 glUniform1fv(m_uniformLocations.shadow.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel());726 m_context->uniform2f(m_uniformLocations.shadow.offset, float(shadow.location().x()) / float(size.width()), float(shadow.location().y()) / float(size.height())); 727 m_context->uniform1f(m_uniformLocations.shadow.blurRadius, shadow.stdDeviation() / float(size.width())); 728 m_context->uniform1fv(m_uniformLocations.shadow.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel()); 735 729 break; 736 730 case 1: 737 731 // Second pass: we need the shadow color and the content texture for compositing. 738 glUniform1f(m_uniformLocations.shadow.blurRadius, shadow.stdDeviation() / float(size.height()));739 glUniform1fv(m_uniformLocations.shadow.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel());740 glActiveTexture(GL_TEXTURE1);741 glBindTexture(GL_TEXTURE_2D, contentTexture);742 glUniform1i(m_uniformLocations.shadow.contentTexture, 1);732 m_context->uniform1f(m_uniformLocations.shadow.blurRadius, shadow.stdDeviation() / float(size.height())); 733 m_context->uniform1fv(m_uniformLocations.shadow.gaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel()); 734 m_context->activeTexture(GraphicsContext3D::TEXTURE1); 735 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, contentTexture); 736 m_context->uniform1i(m_uniformLocations.shadow.contentTexture, 1); 743 737 float r, g, b, a; 744 738 shadow.color().getRGBA(r, g, b, a); 745 glUniform4f(m_uniformLocations.shadow.color, r, g, b, a);739 m_context->uniform4f(m_uniformLocations.shadow.color, r, g, b, a); 746 740 break; 747 741 } … … 760 754 FilterMap::iterator iterator = m_filterMap.find(key); 761 755 if (iterator == m_filterMap.end()) { 762 program = StandardFilterProgram::create( type, pass);756 program = StandardFilterProgram::create(m_context, type, pass); 763 757 if (!program) 764 758 return 0; -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h
r126743 r127063 25 25 26 26 #include "FloatQuad.h" 27 #include "GraphicsContext3D.h" 27 28 #include "IntSize.h" 28 #include "OpenGLShims.h" 29 #include "TextureMapper.h" 29 #include "TextureMapperGL.h" 30 30 #include "TransformationMatrix.h" 31 31 #include <wtf/HashMap.h> … … 45 45 class TextureMapperShaderProgram : public RefCounted<TextureMapperShaderProgram> { 46 46 public: 47 GLuint id() { return m_id; }48 G Luint vertexAttrib() { return m_vertexAttrib; }49 50 TextureMapperShaderProgram( const char* vertexShaderSource, const char* fragmentShaderSource);47 Platform3DObject id() { return m_id; } 48 GC3Duint vertexAttrib() { return m_vertexAttrib; } 49 50 TextureMapperShaderProgram(GraphicsContext3D*, const char* vertexShaderSource, const char* fragmentShaderSource); 51 51 virtual ~TextureMapperShaderProgram(); 52 52 53 53 virtual void prepare(float opacity, const BitmapTexture*) { } 54 G Lint matrixLocation() const { return m_matrixLocation; }55 G Lint flipLocation() const { return m_flipLocation; }56 G Lint textureSizeLocation() const { return m_textureSizeLocation; }57 G Lint sourceTextureLocation() const { return m_sourceTextureLocation; }58 G Lint maskTextureLocation() const { return m_maskTextureLocation; }59 G Lint opacityLocation() const { return m_opacityLocation; }60 61 static bool isValidUniformLocation(G Lint location) { return location >= 0; }62 63 protected: 64 void getUniformLocation(G Lint& var, const char* name);54 GC3Dint matrixLocation() const { return m_matrixLocation; } 55 GC3Dint flipLocation() const { return m_flipLocation; } 56 GC3Dint textureSizeLocation() const { return m_textureSizeLocation; } 57 GC3Dint sourceTextureLocation() const { return m_sourceTextureLocation; } 58 GC3Dint maskTextureLocation() const { return m_maskTextureLocation; } 59 GC3Dint opacityLocation() const { return m_opacityLocation; } 60 61 static bool isValidUniformLocation(GC3Dint location) { return location >= 0; } 62 63 protected: 64 void getUniformLocation(GC3Dint& var, const char* name); 65 65 void initializeProgram(); 66 66 virtual void initialize() { } … … 68 68 const char* fragmentShaderSource() const { return m_fragmentShaderSource.data(); } 69 69 70 GLuint m_id; 71 GLuint m_vertexAttrib; 72 GLuint m_vertexShader; 73 GLuint m_fragmentShader; 74 GLint m_matrixLocation; 75 GLint m_flipLocation; 76 GLint m_textureSizeLocation; 77 GLint m_sourceTextureLocation; 78 GLint m_opacityLocation; 79 GLint m_maskTextureLocation; 70 GraphicsContext3D* m_context; 71 Platform3DObject m_id; 72 GC3Duint m_vertexAttrib; 73 Platform3DObject m_vertexShader; 74 Platform3DObject m_fragmentShader; 75 GC3Dint m_matrixLocation; 76 GC3Dint m_flipLocation; 77 GC3Dint m_textureSizeLocation; 78 GC3Dint m_sourceTextureLocation; 79 GC3Dint m_opacityLocation; 80 GC3Dint m_maskTextureLocation; 80 81 81 82 private: … … 88 89 public: 89 90 virtual ~StandardFilterProgram(); 90 virtual void prepare(const FilterOperation&, unsigned pass, const IntSize&, GLuint contentTexture); 91 static PassRefPtr<StandardFilterProgram> create(FilterOperation::OperationType, unsigned pass); 92 GLuint vertexAttrib() const { return m_vertexAttrib; } 93 GLuint texCoordAttrib() const { return m_texCoordAttrib; } 94 GLuint textureUniform() const { return m_textureUniformLocation; } 95 private: 96 StandardFilterProgram(FilterOperation::OperationType, unsigned pass); 97 GLuint m_id; 98 GLuint m_vertexShader; 99 GLuint m_fragmentShader; 100 GLuint m_vertexAttrib; 101 GLuint m_texCoordAttrib; 102 GLuint m_textureUniformLocation; 91 virtual void prepare(const FilterOperation&, unsigned pass, const IntSize&, GC3Duint contentTexture); 92 static PassRefPtr<StandardFilterProgram> create(GraphicsContext3D*, FilterOperation::OperationType, unsigned pass); 93 GC3Duint vertexAttrib() const { return m_vertexAttrib; } 94 GC3Duint texCoordAttrib() const { return m_texCoordAttrib; } 95 GC3Duint textureUniform() const { return m_textureUniformLocation; } 96 protected: 97 GraphicsContext3D* m_context; 98 private: 99 StandardFilterProgram(); 100 StandardFilterProgram(GraphicsContext3D*, FilterOperation::OperationType, unsigned pass); 101 Platform3DObject m_id; 102 Platform3DObject m_vertexShader; 103 Platform3DObject m_fragmentShader; 104 GC3Duint m_vertexAttrib; 105 GC3Duint m_texCoordAttrib; 106 GC3Duint m_textureUniformLocation; 103 107 union { 104 G Luint amount;108 GC3Duint amount; 105 109 106 110 struct { 107 G Luint radius;108 G Luint gaussianKernel;111 GC3Duint radius; 112 GC3Duint gaussianKernel; 109 113 } blur; 110 114 111 115 struct { 112 G Luint blurRadius;113 G Luint color;114 G Luint offset;115 G Luint contentTexture;116 G Luint gaussianKernel;116 GC3Duint blurRadius; 117 GC3Duint color; 118 GC3Duint offset; 119 GC3Duint contentTexture; 120 GC3Duint gaussianKernel; 117 121 } shadow; 118 122 } m_uniformLocations; … … 122 126 class TextureMapperShaderProgramSimple : public TextureMapperShaderProgram { 123 127 public: 124 static PassRefPtr<TextureMapperShaderProgramSimple> create() 125 { 126 return adoptRef(new TextureMapperShaderProgramSimple()); 127 } 128 129 protected: 128 static PassRefPtr<TextureMapperShaderProgramSimple> create(GraphicsContext3D* context) 129 { 130 return adoptRef(new TextureMapperShaderProgramSimple(context)); 131 } 132 133 protected: 134 TextureMapperShaderProgramSimple(GraphicsContext3D*); 135 private: 130 136 TextureMapperShaderProgramSimple(); 131 137 }; … … 133 139 class TextureMapperShaderProgramRectSimple : public TextureMapperShaderProgram { 134 140 public: 135 static PassRefPtr<TextureMapperShaderProgramRectSimple> create() 136 { 137 return adoptRef(new TextureMapperShaderProgramRectSimple()); 138 } 139 141 static PassRefPtr<TextureMapperShaderProgramRectSimple> create(GraphicsContext3D* context) 142 { 143 return adoptRef(new TextureMapperShaderProgramRectSimple(context)); 144 } 145 146 protected: 147 TextureMapperShaderProgramRectSimple(GraphicsContext3D*); 140 148 private: 141 149 TextureMapperShaderProgramRectSimple(); … … 144 152 class TextureMapperShaderProgramOpacityAndMask : public TextureMapperShaderProgram { 145 153 public: 146 static PassRefPtr<TextureMapperShaderProgramOpacityAndMask> create() 147 { 148 return adoptRef(new TextureMapperShaderProgramOpacityAndMask()); 149 } 150 154 static PassRefPtr<TextureMapperShaderProgramOpacityAndMask> create(GraphicsContext3D* context) 155 { 156 return adoptRef(new TextureMapperShaderProgramOpacityAndMask(context)); 157 } 158 159 protected: 160 TextureMapperShaderProgramOpacityAndMask(GraphicsContext3D*); 151 161 private: 152 162 TextureMapperShaderProgramOpacityAndMask(); … … 155 165 class TextureMapperShaderProgramRectOpacityAndMask : public TextureMapperShaderProgram { 156 166 public: 157 static PassRefPtr<TextureMapperShaderProgramRectOpacityAndMask> create() 158 { 159 return adoptRef(new TextureMapperShaderProgramRectOpacityAndMask()); 160 } 161 167 static PassRefPtr<TextureMapperShaderProgramRectOpacityAndMask> create(GraphicsContext3D* context) 168 { 169 return adoptRef(new TextureMapperShaderProgramRectOpacityAndMask(context)); 170 } 171 172 protected: 173 TextureMapperShaderProgramRectOpacityAndMask(GraphicsContext3D*); 162 174 private: 163 175 TextureMapperShaderProgramRectOpacityAndMask(); … … 166 178 class TextureMapperShaderProgramSolidColor : public TextureMapperShaderProgram { 167 179 public: 168 static PassRefPtr<TextureMapperShaderProgramSolidColor> create() 169 { 170 return adoptRef(new TextureMapperShaderProgramSolidColor()); 171 } 172 173 GLint colorLocation() const { return m_colorLocation; } 174 180 static PassRefPtr<TextureMapperShaderProgramSolidColor> create(GraphicsContext3D* context) 181 { 182 return adoptRef(new TextureMapperShaderProgramSolidColor(context)); 183 } 184 185 GC3Dint colorLocation() const { return m_colorLocation; } 186 187 protected: 188 TextureMapperShaderProgramSolidColor(GraphicsContext3D*); 175 189 private: 176 190 TextureMapperShaderProgramSolidColor(); 177 G Lint m_colorLocation;191 GC3Dint m_colorLocation; 178 192 }; 179 193 180 194 class TextureMapperShaderProgramAntialiasingNoMask : public TextureMapperShaderProgram { 181 195 public: 182 static PassRefPtr<TextureMapperShaderProgramAntialiasingNoMask> create() 183 { 184 return adoptRef(new TextureMapperShaderProgramAntialiasingNoMask()); 185 } 186 187 GLint expandedQuadVerticesInTextureCoordinatesLocation() { return m_expandedQuadVerticesInTextureCordinatesLocation; } 188 GLint expandedQuadEdgesInScreenSpaceLocation() { return m_expandedQuadEdgesInScreenSpaceLocation; } 189 196 static PassRefPtr<TextureMapperShaderProgramAntialiasingNoMask> create(GraphicsContext3D* context) 197 { 198 return adoptRef(new TextureMapperShaderProgramAntialiasingNoMask(context)); 199 } 200 201 GC3Dint expandedQuadVerticesInTextureCoordinatesLocation() { return m_expandedQuadVerticesInTextureCordinatesLocation; } 202 GC3Dint expandedQuadEdgesInScreenSpaceLocation() { return m_expandedQuadEdgesInScreenSpaceLocation; } 203 204 protected: 205 TextureMapperShaderProgramAntialiasingNoMask(GraphicsContext3D*); 190 206 private: 191 207 TextureMapperShaderProgramAntialiasingNoMask(); 192 208 193 G Lint m_expandedQuadVerticesInTextureCordinatesLocation;194 G Lint m_expandedQuadEdgesInScreenSpaceLocation;209 GC3Dint m_expandedQuadVerticesInTextureCordinatesLocation; 210 GC3Dint m_expandedQuadEdgesInScreenSpaceLocation; 195 211 }; 196 212 … … 207 223 }; 208 224 209 TextureMapperShaderManager(); 225 TextureMapperShaderManager() { } 226 TextureMapperShaderManager(GraphicsContext3D*); 210 227 virtual ~TextureMapperShaderManager(); 211 228 … … 222 239 typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap; 223 240 TextureMapperShaderProgramMap m_textureMapperShaderProgramMap; 241 GraphicsContext3D* m_context; 224 242 225 243 #if ENABLE(CSS_FILTERS) … … 227 245 FilterMap m_filterMap; 228 246 #endif 229 230 247 }; 231 248
Note: See TracChangeset
for help on using the changeset viewer.