summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/chromium/ContentLayerChromium.cpp')
-rw-r--r--WebCore/platform/graphics/chromium/ContentLayerChromium.cpp57
1 files changed, 25 insertions, 32 deletions
diff --git a/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp b/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
index 48119bb..86be8da 100644
--- a/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
@@ -34,6 +34,7 @@
#include "ContentLayerChromium.h"
+#include "GraphicsContext3D.h"
#include "LayerRendererChromium.h"
#include "RenderLayerBacking.h"
@@ -47,12 +48,11 @@
#include <CoreGraphics/CGBitmapContext.h>
#endif
-#include <GLES2/gl2.h>
-
namespace WebCore {
-ContentLayerChromium::SharedValues::SharedValues()
- : m_contentShaderProgram(0)
+ContentLayerChromium::SharedValues::SharedValues(GraphicsContext3D* context)
+ : m_context(context)
+ , m_contentShaderProgram(0)
, m_shaderSamplerLocation(-1)
, m_shaderMatrixLocation(-1)
, m_shaderAlphaLocation(-1)
@@ -71,8 +71,8 @@ ContentLayerChromium::SharedValues::SharedValues()
"} \n";
// Note differences between Skia and Core Graphics versions:
- // - Skia uses BGRA and origin is upper left
- // - Core Graphics uses RGBA and origin is lower left
+ // - Skia uses BGRA
+ // - Core Graphics uses RGBA
char fragmentShaderString[] =
"precision mediump float; \n"
"varying vec2 v_texCoord; \n"
@@ -80,26 +80,25 @@ ContentLayerChromium::SharedValues::SharedValues()
"uniform float alpha; \n"
"void main() \n"
"{ \n"
-#if PLATFORM(SKIA)
" vec4 texColor = texture2D(s_texture, v_texCoord); \n"
+#if PLATFORM(SKIA)
" gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; \n"
#elif PLATFORM(CG)
- " vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
#else
#error "Need to implement for your platform."
#endif
"} \n";
- m_contentShaderProgram = createShaderProgram(vertexShaderString, fragmentShaderString);
+ m_contentShaderProgram = createShaderProgram(m_context, vertexShaderString, fragmentShaderString);
if (!m_contentShaderProgram) {
LOG_ERROR("ContentLayerChromium: Failed to create shader program");
return;
}
- m_shaderSamplerLocation = glGetUniformLocation(m_contentShaderProgram, "s_texture");
- m_shaderMatrixLocation = glGetUniformLocation(m_contentShaderProgram, "matrix");
- m_shaderAlphaLocation = glGetUniformLocation(m_contentShaderProgram, "alpha");
+ m_shaderSamplerLocation = m_context->getUniformLocation(m_contentShaderProgram, "s_texture");
+ m_shaderMatrixLocation = m_context->getUniformLocation(m_contentShaderProgram, "matrix");
+ m_shaderAlphaLocation = m_context->getUniformLocation(m_contentShaderProgram, "alpha");
ASSERT(m_shaderSamplerLocation != -1);
ASSERT(m_shaderMatrixLocation != -1);
ASSERT(m_shaderAlphaLocation != -1);
@@ -110,7 +109,7 @@ ContentLayerChromium::SharedValues::SharedValues()
ContentLayerChromium::SharedValues::~SharedValues()
{
if (m_contentShaderProgram)
- GLC(glDeleteProgram(m_contentShaderProgram));
+ GLC(m_context, m_context->deleteProgram(m_contentShaderProgram));
}
@@ -128,7 +127,7 @@ ContentLayerChromium::ContentLayerChromium(GraphicsLayerChromium* owner)
ContentLayerChromium::~ContentLayerChromium()
{
if (m_contentsTexture)
- GLC(glDeleteTextures(1, &m_contentsTexture));
+ GLC(layerRendererContext(), layerRendererContext()->deleteTexture(m_contentsTexture));
}
@@ -207,11 +206,13 @@ void ContentLayerChromium::updateContents()
dirtyRect.width(), dirtyRect.height(), 8, rowBytes,
colorSpace.get(),
kCGImageAlphaPremultipliedLast));
+ CGContextTranslateCTM(contextCG.get(), 0, dirtyRect.height());
+ CGContextScaleCTM(contextCG.get(), 1, -1);
GraphicsContext graphicsContext(contextCG.get());
LocalCurrentGraphicsContext scopedNSGraphicsContext(&graphicsContext);
- // Translate the graphics contxt into the coordinate system of the dirty rect.
+ // Translate the graphics context into the coordinate system of the dirty rect.
graphicsContext.translate(-dirtyRect.x(), -dirtyRect.y());
m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect);
@@ -235,30 +236,21 @@ void ContentLayerChromium::updateTextureRect(void* pixels, const IntSize& bitmap
if (!pixels)
return;
- glBindTexture(GL_TEXTURE_2D, textureId);
+ GraphicsContext3D* context = layerRendererContext();
+ context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
// If the texture id or size changed since last time then we need to tell GL
// to re-allocate a texture.
if (m_contentsTexture != textureId || requiredTextureSize != m_allocatedTextureSize) {
ASSERT(bitmapSize == requiredTextureSize);
- GLC(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
+ GLC(context, context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
m_contentsTexture = textureId;
m_allocatedTextureSize = requiredTextureSize;
} else {
ASSERT(updateRect.width() <= m_allocatedTextureSize.width() && updateRect.height() <= m_allocatedTextureSize.height());
ASSERT(updateRect.width() == bitmapSize.width() && updateRect.height() == bitmapSize.height());
-#if PLATFORM(CG)
- // The origin is at the lower left in Core Graphics' coordinate system. We need to correct for this here.
- GLC(glTexSubImage2D(GL_TEXTURE_2D, 0,
- updateRect.x(), m_allocatedTextureSize.height() - updateRect.height() - updateRect.y(),
- updateRect.width(), updateRect.height(),
- GL_RGBA, GL_UNSIGNED_BYTE, pixels));
-#elif PLATFORM(SKIA)
- GLC(glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels));
-#else
-#error "Need to implement for your platform."
-#endif
+ GLC(context, context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
}
m_dirtyRect.setSize(FloatSize());
@@ -273,11 +265,12 @@ void ContentLayerChromium::draw()
ASSERT(layerRenderer());
const ContentLayerChromium::SharedValues* sv = layerRenderer()->contentLayerSharedValues();
ASSERT(sv && sv->initialized());
- GLC(glActiveTexture(GL_TEXTURE0));
- GLC(glBindTexture(GL_TEXTURE_2D, m_contentsTexture));
+ GraphicsContext3D* context = layerRendererContext();
+ GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
+ GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_contentsTexture));
layerRenderer()->useShader(sv->contentShaderProgram());
- GLC(glUniform1i(sv->shaderSamplerLocation(), 0));
- drawTexturedQuad(layerRenderer()->projectionMatrix(), drawTransform(),
+ GLC(context, context->uniform1i(sv->shaderSamplerLocation(), 0));
+ drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
bounds().width(), bounds().height(), drawOpacity(),
sv->shaderMatrixLocation(), sv->shaderAlphaLocation());
}