[Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.

https://bugs.webkit.org/show_bug.cgi?id=77148

Reviewed by Martin Robinson.

Source/WebCore:

Removed TextureMapperQt, and instead created a TextureMapperImageBuffer class,
which responds to an "Software" mode of TextureMapper, instead of creating subclasses
of TextureMapper directly. This allows using the software fallback of TextureMapper by any
sort.

To make the ImageBuffer backend easier, content updates to BitmapTexture can now use either
an image, or a raw data pointer. The raw data pointer is provided for performance reasons,
as converting data to/from Image references in Qt generates unnecessary deep copies of the
image data.

Also, functions that use TransformationMatrix were added to GraphicsContext, to allow for
3D transforms in cross platform code.
After this patch everything renders the same. An additional bug report was created to allow
ImageBuffer shallow image copies: https://bugs.webkit.org/show_bug.cgi?id=77689

Covered extensively by existing tests, no behavioral changes.

* Target.pri:
* platform/graphics/GraphicsContext.cpp:
* platform/graphics/GraphicsContext.h:
(WebCore):
(GraphicsContext):
* platform/graphics/cairo/TextureMapperCairo.cpp:
* platform/graphics/opengl/TextureMapperGL.cpp:
(TextureMapperGLData):
(BitmapTextureGL):
(WebCore::BitmapTextureGL::BitmapTextureGL):
(WebCore::TextureMapperGL::beginPainting):
(WebCore::BitmapTextureGL::reset):
(WebCore):
(WebCore::swizzleBGRAToRGBA):
(WebCore::BitmapTextureGL::updateContents):
(WebCore::BitmapTextureGL::destroy):
(WebCore::TextureMapperGL::bindSurface):
(WebCore::TextureMapper::platformCreateAccelerated):
* platform/graphics/opengl/TextureMapperGL.h:
(TextureMapperGL):
(WebCore::TextureMapperGL::accelerationMode):
(WebCore):
* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore):
(WebCore::GraphicsContext::get3DTransform):
(WebCore::GraphicsContext::concat3DTransform):
(WebCore::GraphicsContext::set3DTransform):
* platform/graphics/qt/TextureMapperQt.cpp: Removed.
* platform/graphics/qt/TextureMapperQt.h: Removed.
* platform/graphics/texmap/TextureMapper.cpp:
(WebCore):
(BitmapTextureImageBuffer):
(TextureMapperImageBuffer):
* platform/graphics/texmap/TextureMapper.h:
(WebCore::BitmapTexture::BitmapTexture):
(BitmapTexture):
(WebCore::BitmapTexture::bpp):
(WebCore::BitmapTexture::isOpaque):
(WebCore::TextureMapper::setGraphicsContext):
(WebCore::TextureMapper::graphicsContext):
(TextureMapper):
(WebCore::TextureMapper::TextureMapper):
(WebCore::TextureMapper::platformCreateAccelerated):
* platform/graphics/texmap/TextureMapperNode.cpp:
(WebCore::TextureMapperNode::renderContent):
(WebCore::TextureMapperNode::setContentsTileBackBuffer):
* platform/graphics/texmap/TextureMapperNode.h:
(TextureMapperNode):

Source/WebKit/qt:

Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.

* Api/qwebframe.cpp:
(QWebFramePrivate::renderCompositedLayers):
* WebCoreSupport/PageClientQt.cpp:
(WebCore::PageClientQWidget::setRootGraphicsLayer):
(WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer):

Source/WebKit2:

Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.
Remove calls to unused API.

* UIProcess/qt/LayerTreeHostProxyQt.cpp:
(WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
(WebKit::LayerTreeHostProxy::paintToGraphicsContext):
(WebKit::LayerTreeHostProxy::createImage):
(WebKit::LayerTreeHostProxy::ensureRootLayer):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106659 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3a75735d
2012-02-03 No'am Rosenthal <noam.rosenthal@nokia.com>
[Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.
https://bugs.webkit.org/show_bug.cgi?id=77148
Reviewed by Martin Robinson.
Removed TextureMapperQt, and instead created a TextureMapperImageBuffer class,
which responds to an "Software" mode of TextureMapper, instead of creating subclasses
of TextureMapper directly. This allows using the software fallback of TextureMapper by any
sort.
To make the ImageBuffer backend easier, content updates to BitmapTexture can now use either
an image, or a raw data pointer. The raw data pointer is provided for performance reasons,
as converting data to/from Image references in Qt generates unnecessary deep copies of the
image data.
Also, functions that use TransformationMatrix were added to GraphicsContext, to allow for
3D transforms in cross platform code.
After this patch everything renders the same. An additional bug report was created to allow
ImageBuffer shallow image copies: https://bugs.webkit.org/show_bug.cgi?id=77689
Covered extensively by existing tests, no behavioral changes.
* Target.pri:
* platform/graphics/GraphicsContext.cpp:
* platform/graphics/GraphicsContext.h:
(WebCore):
(GraphicsContext):
* platform/graphics/cairo/TextureMapperCairo.cpp:
* platform/graphics/opengl/TextureMapperGL.cpp:
(TextureMapperGLData):
(BitmapTextureGL):
(WebCore::BitmapTextureGL::BitmapTextureGL):
(WebCore::TextureMapperGL::beginPainting):
(WebCore::BitmapTextureGL::reset):
(WebCore):
(WebCore::swizzleBGRAToRGBA):
(WebCore::BitmapTextureGL::updateContents):
(WebCore::BitmapTextureGL::destroy):
(WebCore::TextureMapperGL::bindSurface):
(WebCore::TextureMapper::platformCreateAccelerated):
* platform/graphics/opengl/TextureMapperGL.h:
(TextureMapperGL):
(WebCore::TextureMapperGL::accelerationMode):
(WebCore):
* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore):
(WebCore::GraphicsContext::get3DTransform):
(WebCore::GraphicsContext::concat3DTransform):
(WebCore::GraphicsContext::set3DTransform):
* platform/graphics/qt/TextureMapperQt.cpp: Removed.
* platform/graphics/qt/TextureMapperQt.h: Removed.
* platform/graphics/texmap/TextureMapper.cpp:
(WebCore):
(BitmapTextureImageBuffer):
(TextureMapperImageBuffer):
* platform/graphics/texmap/TextureMapper.h:
(WebCore::BitmapTexture::BitmapTexture):
(BitmapTexture):
(WebCore::BitmapTexture::bpp):
(WebCore::BitmapTexture::isOpaque):
(WebCore::TextureMapper::setGraphicsContext):
(WebCore::TextureMapper::graphicsContext):
(TextureMapper):
(WebCore::TextureMapper::TextureMapper):
(WebCore::TextureMapper::platformCreateAccelerated):
* platform/graphics/texmap/TextureMapperNode.cpp:
(WebCore::TextureMapperNode::renderContent):
(WebCore::TextureMapperNode::setContentsTileBackBuffer):
* platform/graphics/texmap/TextureMapperNode.h:
(TextureMapperNode):
2012-01-27 Yury Semikhatsky <yurys@chromium.org>
Web Inspector: console evaluation doesn't work on breakpoint in pages with CSP
......@@ -5733,9 +5733,11 @@ webcore_sources += \
Source/WebCore/platform/graphics/texmap/TextureMapper.h \
Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
webcoregtk_sources += \
Source/WebCore/platform/graphics/cairo/TextureMapperCairo.cpp \
Source/WebCore/platform/graphics/cairo/TextureMapperCairo.h
......@@ -5753,8 +5755,10 @@ webcore_sources += \
Source/WebCore/platform/graphics/texmap/TextureMapper.h \
Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
webcoregtk_sources += \
Source/WebCore/platform/graphics/cairo/TextureMapperGLCairo.cpp \
......
......@@ -3939,19 +3939,19 @@ win32:!win32-g++*:contains(QMAKE_HOST.arch, x86_64):{
contains(CONFIG, texmap) {
HEADERS += \
platform/graphics/qt/TextureMapperQt.h \
platform/graphics/texmap/GraphicsLayerTextureMapper.h \
platform/graphics/texmap/LayerTransform.h \
platform/graphics/texmap/TextureMapper.h \
platform/graphics/texmap/TextureMapperAnimation.h \
platform/graphics/texmap/TextureMapperImageBuffer.h \
platform/graphics/texmap/TextureMapperNode.h \
platform/graphics/texmap/TextureMapperPlatformLayer.h
SOURCES += \
platform/graphics/qt/TextureMapperQt.cpp \
platform/graphics/texmap/LayerTransform.cpp \
platform/graphics/texmap/TextureMapper.cpp \
platform/graphics/texmap/TextureMapperAnimation.cpp \
platform/graphics/texmap/TextureMapperImageBuffer.cpp \
platform/graphics/texmap/TextureMapperNode.cpp \
platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
......@@ -3959,6 +3959,7 @@ contains(CONFIG, texmap) {
HEADERS += platform/graphics/opengl/TextureMapperGL.h
SOURCES += platform/graphics/opengl/TextureMapperGL.cpp
CONFIG += opengl-shims
DEFINES += WTF_USE_TEXTURE_MAPPER_GL
}
} else {
HEADERS += platform/graphics/qt/GraphicsLayerQt.h
......
......@@ -3580,6 +3580,8 @@
'platform/graphics/texmap/TextureMapper.h',
'platform/graphics/texmap/TextureMapperAnimation.cpp',
'platform/graphics/texmap/TextureMapperAnimation.h',
'platform/graphics/texmap/TextureMapperImageBuffer.cpp',
'platform/graphics/texmap/TextureMapperImageBuffer.h',
'platform/graphics/texmap/TextureMapperNode.cpp',
'platform/graphics/texmap/TextureMapperNode.h',
'platform/graphics/texmap/TextureMapperPlatformLayer.h',
......
......@@ -124,6 +124,7 @@ namespace WebCore {
class KURL;
class GraphicsContext3D;
class TextRun;
class TransformationMatrix;
enum TextDrawingMode {
TextModeInvisible = 0,
......@@ -409,6 +410,12 @@ namespace WebCore {
void setCTM(const AffineTransform&);
AffineTransform getCTM() const;
#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
// This is needed when using accelerated-compositing in software mode, like in TextureMapper.
void concat3DTransform(const TransformationMatrix&);
void set3DTransform(const TransformationMatrix&);
TransformationMatrix get3DTransform() const;
#endif
// Create an image buffer compatible with this context, with suitable resolution
// for drawing into the buffer and then into this context.
PassOwnPtr<ImageBuffer> createCompatibleBuffer(const IntSize&) const;
......
......@@ -115,11 +115,6 @@ void TextureMapperCairo::drawTexture(const BitmapTexture& texture, const FloatRe
notImplemented();
}
PassOwnPtr<TextureMapper> TextureMapper::create(GraphicsContext* context)
{
return adoptPtr(new TextureMapperCairo);
}
PassRefPtr<BitmapTexture> TextureMapperCairo::createTexture()
{
return adoptRef(new BitmapTextureCairo());
......
......@@ -265,57 +265,6 @@ struct TextureMapperGLData {
};
struct DirectlyCompositedImageRepository {
struct Entry {
GLuint texture;
int refCount;
};
typedef HashMap<ImageUID, Entry> ImageTextureMap;
ImageTextureMap imageToTexture;
GLuint findOrCreate(ImageUID image, bool& found)
{
ImageTextureMap::iterator it = imageToTexture.find(image);
found = false;
if (it != imageToTexture.end()) {
it->second.refCount++;
found = true;
return it->second.texture;
}
Entry entry;
GL_CMD(glGenTextures(1, &entry.texture));
entry.refCount = 1;
imageToTexture.add(image, entry);
return entry.texture;
}
bool deref(ImageUID image)
{
HashMap<ImageUID, Entry>::iterator it = imageToTexture.find(image);
if (it != imageToTexture.end()) {
if (it->second.refCount < 2) {
imageToTexture.remove(it);
return false;
}
}
return true;
}
DirectlyCompositedImageRepository()
{
}
~DirectlyCompositedImageRepository()
{
for (ImageTextureMap::iterator it = imageToTexture.begin(); it != imageToTexture.end(); ++it) {
GLuint texture = it->second.texture;
if (texture)
GL_CMD(glDeleteTextures(1, &texture));
}
}
} directlyCompositedImages;
SharedGLData& sharedGLData() const
{
return *(m_sharedGLData.get());
......@@ -332,6 +281,7 @@ struct TextureMapperGLData {
int currentProgram;
GLint previousProgram;
GLint previousScissorState;
GLint viewport[4];
RefPtr<SharedGLData> m_sharedGLData;
};
......@@ -342,56 +292,25 @@ public:
virtual bool isValid() const;
virtual void reset(const IntSize&, bool opaque);
void bind();
virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect);
virtual void endPaint();
virtual void setContentsToImage(Image*);
~BitmapTextureGL() { destroy(); }
virtual uint32_t id() const { return m_id; }
inline bool isOpaque() const { return m_opaque; }
inline FloatSize relativeSize() const { return m_relativeSize; }
void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; }
void updateContents(PixelFormat, const IntRect&, void*);
void updateRawContents(const IntRect&, const void*);
void pack()
{
// This is currently a stub.
if (isPacked())
return;
m_isPacked = true;
}
void unpack()
{
// This is currently a stub.
if (!isPacked())
return;
m_isPacked = false;
}
bool isPacked() const
{
return m_isPacked;
}
void updateContents(Image*, const IntRect&, const IntRect&, PixelFormat);
void updateContents(const void*, const IntRect&);
private:
GLuint m_id;
ImageUID m_imageUID;
FloatSize m_relativeSize;
bool m_opaque;
IntSize m_textureSize;
OwnPtr<BGRA32PremultimpliedBuffer> m_buffer;
IntRect m_dirtyRect;
GLuint m_fbo;
GLuint m_rbo;
IntSize m_actualSize;
bool m_surfaceNeedsReset;
bool m_isPacked;
TextureMapperGL* m_textureMapper;
BitmapTextureGL()
: m_id(0)
, m_imageUID(0)
, m_opaque(false)
, m_fbo(0)
, m_rbo(0)
, m_surfaceNeedsReset(true)
......@@ -544,6 +463,7 @@ void TextureMapperGL::beginPainting()
#endif
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glGetIntegerv(GL_VIEWPORT, data().viewport);
bindSurface(0);
}
......@@ -663,7 +583,6 @@ static void texImage2DResourceSafe(size_t width, size_t height)
void BitmapTextureGL::reset(const IntSize& newSize, bool opaque)
{
BitmapTexture::reset(newSize, opaque);
m_imageUID = 0;
IntSize newTextureSize = nextPowerOfTwo(newSize);
bool justCreated = false;
if (!m_id) {
......@@ -682,28 +601,10 @@ void BitmapTextureGL::reset(const IntSize& newSize, bool opaque)
}
m_actualSize = newSize;
m_relativeSize = FloatSize(float(newSize.width()) / m_textureSize.width(), float(newSize.height()) / m_textureSize.height());
m_opaque = opaque;
m_surfaceNeedsReset = true;
}
PlatformGraphicsContext* BitmapTextureGL::beginPaint(const IntRect& dirtyRect)
{
m_buffer = BGRA32PremultimpliedBuffer::create();
m_dirtyRect = dirtyRect;
return m_buffer->beginPaint(dirtyRect, m_opaque);
}
void BitmapTextureGL::endPaint()
{
if (!m_buffer)
return;
m_buffer->endPaint();
updateContents(BGRAFormat, m_dirtyRect, m_buffer->data());
GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
m_buffer.clear();
}
#ifdef TEXMAP_OPENGL_ES_2
static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size)
{
int width = size.width();
......@@ -714,79 +615,31 @@ static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size)
p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
}
}
#endif
void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits)
void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect)
{
GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
#ifdef TEXMAP_OPENGL_ES_2
bool shouldSwizzle = false;
#endif
GLint glFormat = GL_RGBA;
switch (pixelFormat) {
case RGBAFormat:
glFormat = GL_RGBA;
break;
case RGBFormat:
glFormat = GL_RGB;
break;
case BGRAFormat:
#ifdef TEXMAP_OPENGL_ES_2
shouldSwizzle = true;
glFormat = GL_RGBA;
#else
glFormat = GL_BGRA;
#endif
break;
case BGRFormat:
#ifdef TEXMAP_OPENGL_ES_2
shouldSwizzle = true;
glFormat = GL_RGB;
#else
glFormat = GL_BGR;
#endif
break;
}
#ifdef TEXMAP_OPENGL_ES_2
if (shouldSwizzle)
swizzleBGRAToRGBA(static_cast<uint32_t*>(bits), rect.size());
#endif
GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits))
GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, data))
}
void BitmapTextureGL::updateRawContents(const IntRect& rect, const void* bits)
void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, const IntRect& sourceRect, BitmapTexture::PixelFormat format)
{
if (!image)
return;
GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
GLuint glFormat = isOpaque() ? GL_RGB : GL_RGBA;
GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits))
}
void BitmapTextureGL::setContentsToImage(Image* image)
{
ImageUID uid = image ? uidForImage(image) : 0;
if (!image || !uid) {
if (m_imageUID)
destroy();
NativeImagePtr frameImage = image->nativeImageForCurrentFrame();
if (!frameImage)
return;
}
if (uid == m_imageUID)
return;
bool found = false;
GLuint newTextureID = m_textureMapper->data().directlyCompositedImages.findOrCreate(uid, found);
if (newTextureID != m_id) {
m_imageUID = uid;
destroy();
m_id = newTextureID;
reset(image->size(), false);
if (!found) {
GraphicsContext context(beginPaint(IntRect(0, 0, m_textureSize.width(), m_textureSize.height())));
context.drawImage(image, ColorSpaceDeviceRGB, IntPoint(0, 0), CompositeCopy);
endPaint();
}
}
#if PLATFORM(QT)
QImage qtImage = frameImage->toImage();
if (IntSize(qtImage.size()) != sourceRect.size())
qtImage = qtImage.copy(sourceRect);
if (format == BGRAFormat || format == BGRFormat)
swizzleBGRAToRGBA(reinterpret_cast<uint32_t*>(qtImage.bits()), qtImage.size());
GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, GL_UNSIGNED_BYTE, qtImage.constBits()))
#endif
}
static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool flip)
......@@ -837,7 +690,7 @@ void BitmapTextureGL::bind()
void BitmapTextureGL::destroy()
{
if (m_id && (!m_imageUID || !m_textureMapper->data().directlyCompositedImages.deref(m_imageUID)))
if (m_id)
GL_CMD(glDeleteTextures(1, &m_id))
if (m_fbo)
......@@ -872,12 +725,13 @@ void TextureMapperGL::bindSurface(BitmapTexture *surfacePointer)
BitmapTextureGL* surface = static_cast<BitmapTextureGL*>(surfacePointer);
if (!surface) {
IntSize viewportSize(data().viewport[2], data().viewport[3]);
GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, 0))
data().projectionMatrix = createProjectionMatrix(viewportSize(), true).multiply(transform());
data().projectionMatrix = createProjectionMatrix(viewportSize, true);
GL_CMD(glStencilFunc(data().sharedGLData().stencilIndex > 1 ? GL_EQUAL : GL_ALWAYS, data().sharedGLData().stencilIndex - 1, data().sharedGLData().stencilIndex - 1))
GL_CMD(glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP))
GL_CMD(glViewport(0, 0, viewportSize().width(), viewportSize().height()))
data().sharedGLData().clipStack.append(IntRect(IntPoint::zero(), viewportSize()));
GL_CMD(glViewport(0, 0, viewportSize.width(), viewportSize.height()))
data().sharedGLData().clipStack.append(IntRect(data().viewport[0], data().viewport[1], data().viewport[2], data().viewport[3]));
return;
}
......@@ -985,4 +839,9 @@ PassRefPtr<BitmapTexture> TextureMapperGL::createTexture()
return adoptRef(texture);
}
PassOwnPtr<TextureMapper> TextureMapper::platformCreateAccelerated()
{
return TextureMapperGL::create();
}
};
......@@ -43,16 +43,17 @@ public:
virtual void drawTexture(uint32_t texture, bool opaque, const FloatSize&, const FloatRect&, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture, bool flip);
virtual void bindSurface(BitmapTexture* surface);
virtual void beginClip(const TransformationMatrix&, const FloatRect&);
virtual void beginPainting();
virtual void endPainting();
virtual void endClip();
virtual bool allowSurfaceForRoot() const { return false; }
virtual PassRefPtr<BitmapTexture> createTexture();
virtual const char* type() const;
static PassOwnPtr<TextureMapperGL> create() { return adoptPtr(new TextureMapperGL); }
void beginPainting();
void endPainting();
void setGraphicsContext(GraphicsContext* context) { m_context = context; }
GraphicsContext* graphicsContext() { return m_context; }
virtual bool isOpenGLBacked() const { return true; }
void platformUpdateContents(NativeImagePtr, const IntRect&, const IntRect&, BitmapTexture::PixelFormat);
virtual AccelerationMode accelerationMode() const { return OpenGLMode; }
private:
bool beginScissorClip(const TransformationMatrix&, const FloatRect&);
......@@ -64,16 +65,6 @@ private:
};
// An offscreen buffer to be rendered by software.
class BGRA32PremultimpliedBuffer {
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~BGRA32PremultimpliedBuffer() { }
virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect, bool opaque) = 0;
virtual void endPaint() = 0;
virtual void* data() = 0;
static PassOwnPtr<BGRA32PremultimpliedBuffer> create();
};
static inline int nextPowerOfTwo(int num)
{
for (int i = 0x10000000; i > 0; i >>= 1) {
......
......@@ -146,7 +146,7 @@ void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper
{
blitMultisampleFramebufferAndRestoreContext();
if (textureMapper->isOpenGLBacked()) {
if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
texmapGL->drawTexture(m_context->m_texture, !m_context->m_attrs.alpha, FloatSize(1, 1), targetRect, matrix, opacity, mask, true /* flip */);
return;
......
......@@ -1335,6 +1335,32 @@ void GraphicsContext::setCTM(const AffineTransform& transform)
m_data->p()->setWorldTransform(transform);
}
#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
TransformationMatrix GraphicsContext::get3DTransform() const
{
if (paintingDisabled())
return TransformationMatrix();
return platformContext()->combinedTransform();
}
void GraphicsContext::concat3DTransform(const TransformationMatrix& transform)
{
if (paintingDisabled())
return;
m_data->p()->setWorldTransform(transform, true);
}
void GraphicsContext::set3DTransform(const TransformationMatrix& transform)
{
if (paintingDisabled())
return;
m_data->p()->setWorldTransform(transform, false);
}
#endif
void GraphicsContext::setURLForRect(const KURL&, const IntRect&)
{
notImplemented();
......
/*
Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "TextureMapperQt.h"
#include <QtCore/qdebug.h>
#include <QtGui/qpaintengine.h>
#include <QtGui/qpixmap.h>
#if USE(TEXTURE_MAPPER_GL)
# include "opengl/TextureMapperGL.h"
#endif
namespace WebCore {
void BitmapTextureQt::destroy()
{
if (m_pixmap.paintingActive())
qFatal("Destroying an active pixmap");
m_pixmap = QPixmap();
}
void BitmapTextureQt::reset(const IntSize& size, bool isOpaque)
{
BitmapTexture::reset(size, isOpaque);
if (size.width() > m_pixmap.size().width() || size.height() > m_pixmap.size().height() || m_pixmap.isNull())
m_pixmap = QPixmap(size.width(), size.height());
if (!isOpaque)
m_pixmap.fill(Qt::transparent);
}
PlatformGraphicsContext* BitmapTextureQt::beginPaint(const IntRect& dirtyRect)
{