summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/gpu')
-rw-r--r--WebCore/platform/graphics/gpu/DrawingBuffer.cpp107
-rw-r--r--WebCore/platform/graphics/gpu/Shader.cpp4
-rw-r--r--WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp14
-rw-r--r--WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h1
-rw-r--r--WebCore/platform/graphics/gpu/Texture.cpp31
-rw-r--r--WebCore/platform/graphics/gpu/Texture.h2
6 files changed, 84 insertions, 75 deletions
diff --git a/WebCore/platform/graphics/gpu/DrawingBuffer.cpp b/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
index 8cb6d0c..d2415ca 100644
--- a/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
+++ b/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
@@ -41,7 +41,13 @@ namespace WebCore {
PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size)
{
RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size));
- drawingBuffer->m_multisampleExtensionSupported = context->getExtensions()->supports("GL_ANGLE_framebuffer_blit") && context->getExtensions()->supports("GL_ANGLE_framebuffer_multisample");
+ Extensions3D* extensions = context->getExtensions();
+ bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit") && extensions->supports("GL_ANGLE_framebuffer_multisample");
+ if (multisampleSupported) {
+ extensions->ensureEnabled("GL_ANGLE_framebuffer_blit");
+ extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample");
+ }
+ drawingBuffer->m_multisampleExtensionSupported = multisampleSupported;
return (drawingBuffer->m_context) ? drawingBuffer.release() : 0;
}
@@ -113,13 +119,11 @@ void DrawingBuffer::reset(const IntSize& newSize)
// resize multisample FBO
if (multisample()) {
- int maxSampleCount;
+ int maxSampleCount = 0;
m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
int sampleCount = std::min(8, maxSampleCount);
- if (sampleCount > maxSampleCount)
- sampleCount = maxSampleCount;
-
+
m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
@@ -145,7 +149,7 @@ void DrawingBuffer::reset(const IntSize& newSize)
m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
- m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
+ m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE);
m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE, m_colorBuffer, 0);
m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
if (!multisample() && (attributes.stencil || attributes.depth)) {
@@ -166,57 +170,48 @@ void DrawingBuffer::reset(const IntSize& newSize)
if (multisample())
m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
- // Initialize renderbuffers to 0.
- float clearColor[] = {0, 0, 0, 0}, clearDepth = 0;
- int clearStencil = 0;
- unsigned char colorMask[] = {true, true, true, true}, depthMask = true;
- unsigned int stencilMask = 0xffffffff;
- unsigned char isScissorEnabled = false;
- unsigned char isDitherEnabled = false;
- unsigned long clearMask = GraphicsContext3D::COLOR_BUFFER_BIT;
- m_context->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, clearColor);
- m_context->clearColor(0, 0, 0, 0);
- m_context->getBooleanv(GraphicsContext3D::COLOR_WRITEMASK, colorMask);
- m_context->colorMask(true, true, true, true);
- if (attributes.depth) {
- m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth);
- m_context->clearDepth(1);
- m_context->getBooleanv(GraphicsContext3D::DEPTH_WRITEMASK, &depthMask);
- m_context->depthMask(true);
- clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT;
- }
- if (attributes.stencil) {
- m_context->getIntegerv(GraphicsContext3D::STENCIL_CLEAR_VALUE, &clearStencil);
- m_context->clearStencil(0);
- m_context->getIntegerv(GraphicsContext3D::STENCIL_WRITEMASK, reinterpret_cast<int*>(&stencilMask));
- m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xffffffff);
- clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT;
- }
- isScissorEnabled = m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST);
- m_context->disable(GraphicsContext3D::SCISSOR_TEST);
- isDitherEnabled = m_context->isEnabled(GraphicsContext3D::DITHER);
- m_context->disable(GraphicsContext3D::DITHER);
-
- m_context->clear(clearMask);
-
- m_context->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
- m_context->colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
- if (attributes.depth) {
- m_context->clearDepth(clearDepth);
- m_context->depthMask(depthMask);
- }
- if (attributes.stencil) {
- m_context->clearStencil(clearStencil);
- m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, stencilMask);
+ if (!m_context->getExtensions()->supports("GL_CHROMIUM_resource_safe")) {
+ // Initialize renderbuffers (depth/stencil).
+ float clearDepth = 0;
+ int clearStencil = 0;
+ unsigned char depthMask = true;
+ unsigned int stencilMask = 0xffffffff;
+ unsigned char isScissorEnabled = false;
+ unsigned long clearMask = 0;
+ if (attributes.depth) {
+ m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth);
+ m_context->clearDepth(1);
+ m_context->getBooleanv(GraphicsContext3D::DEPTH_WRITEMASK, &depthMask);
+ m_context->depthMask(true);
+ clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT;
+ }
+ if (attributes.stencil) {
+ m_context->getIntegerv(GraphicsContext3D::STENCIL_CLEAR_VALUE, &clearStencil);
+ m_context->clearStencil(0);
+ m_context->getIntegerv(GraphicsContext3D::STENCIL_WRITEMASK, reinterpret_cast<int*>(&stencilMask));
+ m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xffffffff);
+ clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT;
+ }
+ if (clearMask) {
+ isScissorEnabled = m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST);
+ m_context->disable(GraphicsContext3D::SCISSOR_TEST);
+
+ m_context->clear(clearMask);
+
+ if (attributes.depth) {
+ m_context->clearDepth(clearDepth);
+ m_context->depthMask(depthMask);
+ }
+ if (attributes.stencil) {
+ m_context->clearStencil(clearStencil);
+ m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, stencilMask);
+ }
+ if (isScissorEnabled)
+ m_context->enable(GraphicsContext3D::SCISSOR_TEST);
+ else
+ m_context->disable(GraphicsContext3D::SCISSOR_TEST);
+ }
}
- if (isScissorEnabled)
- m_context->enable(GraphicsContext3D::SCISSOR_TEST);
- else
- m_context->disable(GraphicsContext3D::SCISSOR_TEST);
- if (isDitherEnabled)
- m_context->enable(GraphicsContext3D::DITHER);
- else
- m_context->disable(GraphicsContext3D::DITHER);
m_context->flush();
diff --git a/WebCore/platform/graphics/gpu/Shader.cpp b/WebCore/platform/graphics/gpu/Shader.cpp
index 8983adc..6978322 100644
--- a/WebCore/platform/graphics/gpu/Shader.cpp
+++ b/WebCore/platform/graphics/gpu/Shader.cpp
@@ -65,7 +65,7 @@ unsigned Shader::loadShader(GraphicsContext3D* context, unsigned type, const cha
String shaderSourceStr(shaderSource);
context->shaderSource(shader, shaderSourceStr);
context->compileShader(shader);
- int compileStatus;
+ int compileStatus = 0;
context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compileStatus);
if (!compileStatus) {
String infoLog = context->getShaderInfoLog(shader);
@@ -91,7 +91,7 @@ unsigned Shader::loadProgram(GraphicsContext3D* context, const char* vertexShade
context->attachShader(program, vertexShader);
context->attachShader(program, fragmentShader);
context->linkProgram(program);
- int linkStatus;
+ int linkStatus = 0;
context->getProgramiv(program, GraphicsContext3D::LINK_STATUS, &linkStatus);
if (!linkStatus)
context->deleteProgram(program);
diff --git a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
index a230384..a166d9c 100644
--- a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
+++ b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
@@ -68,11 +68,18 @@ PassRefPtr<SharedGraphicsContext3D> SharedGraphicsContext3D::create(HostWindow*
SharedGraphicsContext3D::SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<SolidFillShader> solidFillShader, PassOwnPtr<TexShader> texShader)
: m_context(context)
+ , m_bgraSupported(false)
, m_quadVertices(0)
, m_solidFillShader(solidFillShader)
, m_texShader(texShader)
{
allContexts()->add(this);
+ Extensions3D* extensions = m_context->getExtensions();
+ m_bgraSupported = extensions->supports("GL_EXT_texture_format_BGRA8888") && extensions->supports("GL_EXT_read_format_bgra");
+ if (m_bgraSupported) {
+ extensions->ensureEnabled("GL_EXT_texture_format_BGRA8888");
+ extensions->ensureEnabled("GL_EXT_read_format_bgra");
+ }
}
SharedGraphicsContext3D::~SharedGraphicsContext3D()
@@ -165,6 +172,10 @@ void SharedGraphicsContext3D::texParameteri(unsigned target, unsigned pname, int
int SharedGraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
{
+ if (!pixels) {
+ m_context->texImage2DResourceSafe(target, level, internalformat, width, height, border, format, type);
+ return 0;
+ }
return m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
@@ -180,8 +191,7 @@ void SharedGraphicsContext3D::readPixels(long x, long y, unsigned long width, un
bool SharedGraphicsContext3D::supportsBGRA()
{
- return m_context->getExtensions()->supports("GL_EXT_texture_format_BGRA8888")
- && m_context->getExtensions()->supports("GL_EXT_read_format_bgra");
+ return m_bgraSupported;
}
Texture* SharedGraphicsContext3D::createTexture(NativeImagePtr ptr, Texture::Format format, int width, int height)
diff --git a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h
index 86c64b4..a1ae8f2 100644
--- a/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h
+++ b/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.h
@@ -124,6 +124,7 @@ private:
void removeTextureFor(NativeImagePtr);
RefPtr<GraphicsContext3D> m_context;
+ bool m_bgraSupported;
unsigned m_quadVertices;
diff --git a/WebCore/platform/graphics/gpu/Texture.cpp b/WebCore/platform/graphics/gpu/Texture.cpp
index 18c9ead..e1f8114 100644
--- a/WebCore/platform/graphics/gpu/Texture.cpp
+++ b/WebCore/platform/graphics/gpu/Texture.cpp
@@ -106,15 +106,15 @@ PassRefPtr<Texture> Texture::create(GraphicsContext3D* context, Format format, i
IntRect tileBoundsWithBorder = tiling.tileBoundsWithBorder(i);
- unsigned int glFormat = 0;
- unsigned int glType = 0;
- bool swizzle;
- convertFormat(context, format, &glFormat, &glType, &swizzle);
- context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
- context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, glFormat,
- tileBoundsWithBorder.width(),
- tileBoundsWithBorder.height(),
- 0, glFormat, glType, 0);
+ unsigned int glFormat = 0;
+ unsigned int glType = 0;
+ bool swizzle;
+ convertFormat(context, format, &glFormat, &glType, &swizzle);
+ context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
+ context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, glFormat,
+ tileBoundsWithBorder.width(),
+ tileBoundsWithBorder.height(),
+ 0, glFormat, glType);
}
return adoptRef(new Texture(context, textureIds.leakPtr(), format, width, height, maxTextureSize));
}
@@ -149,8 +149,11 @@ void Texture::load(void* pixels)
updateSubRect(pixels, IntRect(0, 0, m_tiles.totalSizeX(), m_tiles.totalSizeY()));
}
-void Texture::updateSubRect(void* pixels, const IntRect updateRect)
+void Texture::updateSubRect(void* pixels, const IntRect& updateRect)
{
+ IntRect updateRectSanitized(updateRect);
+ updateRectSanitized.intersect(IntRect(0, 0, m_tiles.totalSizeX(), m_tiles.totalSizeY()));
+
uint32_t* pixels32 = static_cast<uint32_t*>(pixels);
unsigned int glFormat = 0;
unsigned int glType = 0;
@@ -160,16 +163,16 @@ void Texture::updateSubRect(void* pixels, const IntRect updateRect)
ASSERT(glFormat == GraphicsContext3D::RGBA && glType == GraphicsContext3D::UNSIGNED_BYTE);
// FIXME: This could use PBO's to save doing an extra copy here.
}
- int tempBuffSize = // Temporary buffer size is the smaller of the max texture size or the updateRect
- min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRect.width()) *
- min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRect.height());
+ int tempBuffSize = // Temporary buffer size is the smaller of the max texture size or the updateRectSanitized
+ min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRectSanitized.width()) *
+ min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRectSanitized.height());
OwnArrayPtr<uint32_t> tempBuff(new uint32_t[tempBuffSize]);
for (int tile = 0; tile < m_tiles.numTiles(); tile++) {
// Intersect with tile
IntRect tileBoundsWithBorder = m_tiles.tileBoundsWithBorder(tile);
- IntRect updateRectIntersected = updateRect;
+ IntRect updateRectIntersected = updateRectSanitized;
updateRectIntersected.intersect(tileBoundsWithBorder);
IntRect dstRect = updateRectIntersected;
diff --git a/WebCore/platform/graphics/gpu/Texture.h b/WebCore/platform/graphics/gpu/Texture.h
index 92b6d0a..1f35006 100644
--- a/WebCore/platform/graphics/gpu/Texture.h
+++ b/WebCore/platform/graphics/gpu/Texture.h
@@ -50,7 +50,7 @@ public:
static PassRefPtr<Texture> create(GraphicsContext3D*, Format, int width, int height);
void bindTile(int tile);
void load(void* pixels);
- void updateSubRect(void* pixels, const IntRect);
+ void updateSubRect(void* pixels, const IntRect&);
Format format() const { return m_format; }
const TilingData& tiles() const { return m_tiles; }
private: