summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp')
-rw-r--r--Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp b/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
index ea8bc71..662d6a8 100644
--- a/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
+++ b/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp
@@ -35,7 +35,10 @@
#include "SharedGraphicsContext3D.h"
#include "AffineTransform.h"
+#include "BicubicShader.h"
#include "Color.h"
+#include "ConvolutionShader.h"
+#include "DrawingBuffer.h"
#include "Extensions3D.h"
#include "FloatRect.h"
#include "IntSize.h"
@@ -43,6 +46,15 @@
#include "SolidFillShader.h"
#include "TexShader.h"
+#if ENABLE(SKIA_GPU)
+#include "GrContext.h"
+// Limit the number of textures we hold in the bitmap->texture cache.
+static const int maxTextureCacheCount = 512;
+// Limit the bytes allocated toward textures in the bitmap->texture cache.
+static const size_t maxTextureCacheBytes = 50 * 1024 * 1024;
+#endif
+
+#include <wtf/OwnArrayPtr.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
@@ -65,16 +77,30 @@ PassRefPtr<SharedGraphicsContext3D> SharedGraphicsContext3D::create(HostWindow*
OwnPtr<TexShader> texShader = TexShader::create(context.get());
if (!texShader)
return 0;
- return adoptRef(new SharedGraphicsContext3D(context.release(), solidFillShader.release(), texShader.release()));
+ OwnPtr<BicubicShader> bicubicShader = BicubicShader::create(context.get());
+ if (!bicubicShader)
+ return 0;
+ OwnArrayPtr<OwnPtr<ConvolutionShader> > convolutionShaders = adoptArrayPtr(new OwnPtr<ConvolutionShader>[cMaxKernelWidth]);
+ for (int i = 0; i < cMaxKernelWidth; ++i) {
+ convolutionShaders[i] = ConvolutionShader::create(context.get(), i + 1);
+ if (!convolutionShaders[i])
+ return 0;
+ }
+ return adoptRef(new SharedGraphicsContext3D(context.release(), solidFillShader.release(), texShader.release(), bicubicShader.release(), convolutionShaders.release()));
}
-SharedGraphicsContext3D::SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<SolidFillShader> solidFillShader, PassOwnPtr<TexShader> texShader)
+SharedGraphicsContext3D::SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<SolidFillShader> solidFillShader, PassOwnPtr<TexShader> texShader, PassOwnPtr<BicubicShader> bicubicShader, PassOwnArrayPtr<OwnPtr<ConvolutionShader> > convolutionShaders)
: m_context(context)
, m_bgraSupported(false)
, m_quadVertices(0)
, m_solidFillShader(solidFillShader)
, m_texShader(texShader)
+ , m_bicubicShader(bicubicShader)
+ , m_convolutionShaders(convolutionShaders)
, m_oesStandardDerivativesSupported(false)
+#if ENABLE(SKIA_GPU)
+ , m_grContext(0)
+#endif
{
allContexts()->add(this);
Extensions3D* extensions = m_context->getExtensions();
@@ -92,6 +118,9 @@ SharedGraphicsContext3D::~SharedGraphicsContext3D()
{
m_context->deleteBuffer(m_quadVertices);
allContexts()->remove(this);
+#if ENABLE(SKIA_GPU)
+ GrSafeUnref(m_grContext);
+#endif
}
void SharedGraphicsContext3D::makeContextCurrent()
@@ -369,6 +398,17 @@ void SharedGraphicsContext3D::useTextureProgram(const AffineTransform& transform
m_texShader->use(transform, texTransform, 0, alpha);
}
+void SharedGraphicsContext3D::useBicubicProgram(const AffineTransform& transform, const AffineTransform& texTransform, const float coefficients[16], const float imageIncrement[2], float alpha)
+{
+ m_bicubicShader->use(transform, texTransform, coefficients, imageIncrement, alpha);
+}
+
+void SharedGraphicsContext3D::useConvolutionProgram(const AffineTransform& transform, const AffineTransform& texTransform, const float* kernel, int kernelWidth, float imageIncrement[2])
+{
+ ASSERT(kernelWidth >= 1 && kernelWidth <= cMaxKernelWidth);
+ m_convolutionShaders[kernelWidth - 1]->use(transform, texTransform, kernel, kernelWidth, imageIncrement);
+}
+
void SharedGraphicsContext3D::bindFramebuffer(Platform3DObject framebuffer)
{
m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, framebuffer);
@@ -411,6 +451,31 @@ void SharedGraphicsContext3D::useLoopBlinnExteriorProgram(unsigned vertexOffset,
m_loopBlinnExteriorShader->use(vertexOffset, klmOffset, transform, color);
}
+DrawingBuffer* SharedGraphicsContext3D::getOffscreenBuffer(unsigned index, const IntSize& size)
+{
+ if (index >= m_offscreenBuffers.size())
+ m_offscreenBuffers.resize(index + 1);
+
+ if (!m_offscreenBuffers[index])
+ m_offscreenBuffers[index] = m_context->createDrawingBuffer(size);
+
+ if (size.width() != m_offscreenBuffers[index]->size().width()
+ || size.height() != m_offscreenBuffers[index]->size().height())
+ m_offscreenBuffers[index]->reset(size);
+ return m_offscreenBuffers[index].get();
+}
+
+#if ENABLE(SKIA_GPU)
+GrContext* SharedGraphicsContext3D::grContext()
+{
+ if (!m_grContext) {
+ m_grContext = GrContext::CreateGLShaderContext();
+ m_grContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes);
+ }
+ return m_grContext;
+}
+#endif
+
} // namespace WebCore
#endif