[Texmap] Move surface management from TextureMapperNode to TextureMapper
https://bugs.webkit.org/show_bug.cgi?id=75779
Instead of a TextureMapperSurfaceManager class inside of TextureMapperNode.cpp, we now
maintain that surface pool inside of the TextureMapper class. This will later allow us to
allocate intermediate surface from within TextureMapperGL, a functionality we need for
filters.
Also, surfaces are not automatically created with the viewport size, but rather with the
size passed as a parameter. The surface from the pool is the smallest texture that is
larger than the required size, or any texture if such texture is not yet allocated.
Reviewed by Kenneth Rohde Christiansen.
Tests in LayoutTests/compositing already cover this.
* GNUmakefile.list.am: Added TextureMapper.cpp to the build.
* Target.pri: Added TextureMapper.cpp to the build.
* WebCore.gypi: Added TextureMapper.cpp to the build.
* platform/graphics/texmap/TextureMapper.cpp: Added.
* platform/graphics/texmap/TextureMapper.h:
* platform/graphics/texmap/TextureMapperNode.cpp:
(WebCore::TextureMapperNode::paint):
(WebCore::TextureMapperNode::paintReflection):
(WebCore::TextureMapperNode::paintRecursive):
* platform/graphics/texmap/TextureMapperNode.h:
(WebCore::TextureMapperNode::TextureMapperNode):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104447 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 657af66..38a9e67 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,33 @@
+2012-01-09 No'am Rosenthal <noam.rosenthal@nokia.com>
+
+ [Texmap] Move surface management from TextureMapperNode to TextureMapper
+ https://bugs.webkit.org/show_bug.cgi?id=75779
+
+ Instead of a TextureMapperSurfaceManager class inside of TextureMapperNode.cpp, we now
+ maintain that surface pool inside of the TextureMapper class. This will later allow us to
+ allocate intermediate surface from within TextureMapperGL, a functionality we need for
+ filters.
+
+ Also, surfaces are not automatically created with the viewport size, but rather with the
+ size passed as a parameter. The surface from the pool is the smallest texture that is
+ larger than the required size, or any texture if such texture is not yet allocated.
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Tests in LayoutTests/compositing already cover this.
+
+ * GNUmakefile.list.am: Added TextureMapper.cpp to the build.
+ * Target.pri: Added TextureMapper.cpp to the build.
+ * WebCore.gypi: Added TextureMapper.cpp to the build.
+ * platform/graphics/texmap/TextureMapper.cpp: Added.
+ * platform/graphics/texmap/TextureMapper.h:
+ * platform/graphics/texmap/TextureMapperNode.cpp:
+ (WebCore::TextureMapperNode::paint):
+ (WebCore::TextureMapperNode::paintReflection):
+ (WebCore::TextureMapperNode::paintRecursive):
+ * platform/graphics/texmap/TextureMapperNode.h:
+ (WebCore::TextureMapperNode::TextureMapperNode):
+
2012-01-09 Mario Sanchez Prada <msanchez@igalia.com>
[Gtk] Regression: text-inserted events lack text inserted and current line
diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am
index 4cb8a4e..6d7ea21 100644
--- a/Source/WebCore/GNUmakefile.list.am
+++ b/Source/WebCore/GNUmakefile.list.am
@@ -5656,6 +5656,7 @@
webcore_sources += \
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp \
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h \
+ Source/WebCore/platform/graphics/texmap/TextureMapper.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapper.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
@@ -5671,6 +5672,7 @@
Source/WebCore/platform/graphics/opengl/TextureMapperGL.h \
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp \
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h \
+ Source/WebCore/platform/graphics/texmap/TextureMapper.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapper.h \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
diff --git a/Source/WebCore/Target.pri b/Source/WebCore/Target.pri
index f82e055..4d169d0 100644
--- a/Source/WebCore/Target.pri
+++ b/Source/WebCore/Target.pri
@@ -1170,6 +1170,7 @@
rendering/BidiRun.cpp \
rendering/CounterNode.cpp \
rendering/EllipsisBox.cpp \
+ rendering/FilterEffectRenderer.cpp \
rendering/FixedTableLayout.cpp \
rendering/HitTestingTransformState.cpp \
rendering/HitTestResult.cpp \
@@ -2284,6 +2285,7 @@
rendering/break_lines.h \
rendering/CounterNode.h \
rendering/EllipsisBox.h \
+ rendering/FilterEffectRenderer.h \
rendering/FixedTableLayout.h \
rendering/HitTestingTransformState.h \
rendering/HitTestResult.h \
@@ -3905,6 +3907,7 @@
SOURCES += \
platform/graphics/qt/TextureMapperQt.cpp \
+ platform/graphics/texmap/TextureMapper.cpp \
platform/graphics/texmap/TextureMapperNode.cpp \
platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi
index 3ac99ac..3ba4b91 100644
--- a/Source/WebCore/WebCore.gypi
+++ b/Source/WebCore/WebCore.gypi
@@ -3922,6 +3922,7 @@
'platform/graphics/skia/TransformationMatrixSkia.cpp',
'platform/graphics/texmap/GraphicsLayerTextureMapper.cpp',
'platform/graphics/texmap/GraphicsLayerTextureMapper.h',
+ 'platform/graphics/texmap/TextureMapper.cpp',
'platform/graphics/texmap/TextureMapper.h',
'platform/graphics/texmap/TextureMapperNode.cpp',
'platform/graphics/texmap/TextureMapperNode.h',
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
new file mode 100644
index 0000000..2622d21
--- /dev/null
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
@@ -0,0 +1,79 @@
+/*
+ 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 "TextureMapper.h"
+
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+
+namespace WebCore {
+
+PassRefPtr<BitmapTexture> TextureMapper::acquireTextureFromPool(const IntSize& size)
+{
+ if (m_texturePool.isEmpty()) {
+ RefPtr<BitmapTexture> selectedTexture = createTexture();
+ selectedTexture->reset(size, false);
+ selectedTexture->lock();
+ return selectedTexture;
+ }
+
+ size_t index = 0;
+ RefPtr<BitmapTexture> selectedTexture = m_texturePool[0];
+
+ for (size_t i = 1; i < m_texturePool.size(); ++i) {
+ RefPtr<BitmapTexture> texture = m_texturePool[i];
+
+ IntSize textureSize = texture->size();
+ IntSize selectedTextureSize = selectedTexture->size();
+
+ // We prefer to pick a texture that's equal or larger than the requested size.
+ if (textureSize.width() < size.width() || textureSize.height() < size.height())
+ continue;
+
+ // We select the new texture if the currently selected texture is smaller than the
+ // required size, and the new texture has a smaller area.
+ int textureArea = textureSize.width() * textureSize.height();
+ int selectedTextureArea = selectedTextureSize.width() * selectedTextureSize.height();
+ bool selectedTextureFitsSize =
+ selectedTextureSize.width() >= size.width()
+ && selectedTextureSize.height() >= size.height();
+
+ if (selectedTextureFitsSize && selectedTextureArea <= textureArea)
+ continue;
+
+ selectedTexture = texture;
+ index = i;
+ }
+
+ m_texturePool.remove(index);
+ selectedTexture->reset(size, false);
+ selectedTexture->lock();
+ return selectedTexture;
+}
+
+void TextureMapper::releaseTextureToPool(BitmapTexture* texture)
+{
+ if (!texture)
+ return;
+ m_texturePool.append(texture);
+ texture->unlock();
+}
+
+}
+#endif
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.h b/Source/WebCore/platform/graphics/texmap/TextureMapper.h
index 27058aa..d81333d 100644
--- a/Source/WebCore/platform/graphics/texmap/TextureMapper.h
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.h
@@ -126,6 +126,9 @@
virtual void beginPainting() { }
virtual void endPainting() { }
+ virtual void releaseTextureToPool(BitmapTexture* surface);
+ virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&);
+
protected:
TextureMapper()
@@ -138,6 +141,7 @@
TextDrawingModeFlags m_textDrawingMode;
TransformationMatrix m_transform;
IntSize m_viewportSize;
+ Vector<RefPtr<BitmapTexture> > m_texturePool;
};
};
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp
index 9157e23..15dff5a 100644
--- a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp
@@ -31,40 +31,6 @@
namespace WebCore {
-class TextureMapperSurfaceManager {
-public:
- TextureMapper* textureMapper;
- Vector<RefPtr<BitmapTexture> > surfaces;
- IntSize viewportSize;
-
- PassRefPtr<BitmapTexture> getIntermediateSurface()
- {
- IntSize newViewportSize = textureMapper->viewportSize();
- if (newViewportSize != viewportSize) {
- viewportSize = newViewportSize;
- surfaces.clear();
- }
- if (surfaces.isEmpty()) {
- RefPtr<BitmapTexture> newSurface = textureMapper->createTexture();
- newSurface->reset(viewportSize, false);
- return newSurface.get();
- }
- RefPtr<BitmapTexture> surface = surfaces.last();
- surface->reset(viewportSize, false);
- surfaces.removeLast();
- surface->lock();
- return surface.get();
- }
-
- void releaseIntermediateSurface(BitmapTexture* surface)
- {
- if (!surface)
- return;
- surfaces.append(surface);
- surface->unlock();
- }
-};
-
TextureMapperNode* toTextureMapperNode(GraphicsLayer* layer)
{
return layer ? toGraphicsLayerTextureMapper(layer)->node() : 0;
@@ -346,11 +312,7 @@
if (m_size.isEmpty())
return;
- if (!m_surfaceManager)
- m_surfaceManager = new TextureMapperSurfaceManager;
- m_surfaceManager->textureMapper = m_textureMapper;
TextureMapperPaintOptions opt;
- opt.surfaceManager = m_surfaceManager;
opt.textureMapper = m_textureMapper;
opt.textureMapper->bindSurface(0);
paintRecursive(opt);
@@ -496,7 +458,7 @@
// The mask has to be adjusted to target coordinates.
if (maskTexture) {
- maskSurface = options.surfaceManager->getIntermediateSurface();
+ maskSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
options.textureMapper->bindSurface(maskSurface.get());
options.textureMapper->drawTexture(*maskTexture.get(), entireRect(), m_transforms.target, 1, 0);
maskTexture = maskSurface;
@@ -504,7 +466,7 @@
// The replica's mask has to be adjusted to target coordinates.
if (replicaMaskTexture) {
- replicaMaskSurface = options.surfaceManager->getIntermediateSurface();
+ replicaMaskSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
options.textureMapper->bindSurface(replicaMaskSurface.get());
options.textureMapper->drawTexture(*replicaMaskTexture.get(), entireRect(), m_transforms.target, 1, 0);
replicaMaskTexture = replicaMaskSurface;
@@ -512,21 +474,21 @@
// We might need to apply the mask of the content layer before we draw the reflection, as there might be yet another mask for the reflection itself.
if (useIntermediateBufferForMask) {
- RefPtr<BitmapTexture> maskSurface = options.surfaceManager->getIntermediateSurface();
+ RefPtr<BitmapTexture> maskSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
options.textureMapper->bindSurface(maskSurface.get());
options.textureMapper->drawTexture(*surface.get(), viewportRect, TransformationMatrix(), 1, maskTexture.get());
- options.surfaceManager->releaseIntermediateSurface(surface.get());
+ options.textureMapper->releaseTextureToPool(surface.get());
surface = maskSurface;
maskTexture.clear();
}
// We blend the layer and its replica in an intermediate buffer before blending into the target surface.
if (useIntermediateBufferForReplica) {
- RefPtr<BitmapTexture> replicaSurface = options.surfaceManager->getIntermediateSurface();
+ RefPtr<BitmapTexture> replicaSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
options.textureMapper->bindSurface(replicaSurface.get());
options.textureMapper->drawTexture(*surface.get(), viewportRect, m_transforms.replica, m_state.replicaLayer->m_opacity, replicaMaskTexture.get());
options.textureMapper->drawTexture(*surface.get(), viewportRect, TransformationMatrix(), 1, maskTexture.get());
- options.surfaceManager->releaseIntermediateSurface(surface.get());
+ options.textureMapper->releaseTextureToPool(surface.get());
surface = replicaSurface;
}
@@ -539,8 +501,8 @@
// Draw the original.
options.textureMapper->drawTexture(*surface.get(), viewportRect, TransformationMatrix(), options.opacity, maskTexture.get());
- options.surfaceManager->releaseIntermediateSurface(maskSurface.get());
- options.surfaceManager->releaseIntermediateSurface(replicaMaskSurface.get());
+ options.textureMapper->releaseTextureToPool(maskSurface.get());
+ options.textureMapper->releaseTextureToPool(replicaMaskSurface.get());
return true;
}
@@ -570,12 +532,12 @@
// The mask has to be adjusted to target coordinates.
if (m_state.maskLayer) {
- maskSurface = options.surfaceManager->getIntermediateSurface();
+ maskSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
options.textureMapper->bindSurface(maskSurface.get());
options.textureMapper->drawTexture(*m_state.maskLayer->texture(), entireRect(), m_transforms.target, 1.0, 0);
}
- surface = options.surfaceManager->getIntermediateSurface();
+ surface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
optionsForDescendants.surface = surface.get();
options.isSurface = true;
optionsForDescendants.opacity = 1;
@@ -588,8 +550,8 @@
options.textureMapper->drawTexture(*surface.get(), viewportRect, TransformationMatrix(), options.opacity, 0);
}
- options.surfaceManager->releaseIntermediateSurface(surface.get());
- options.surfaceManager->releaseIntermediateSurface(maskSurface.get());
+ options.textureMapper->releaseTextureToPool(surface.get());
+ options.textureMapper->releaseTextureToPool(maskSurface.get());
}
TextureMapperNode::~TextureMapperNode()
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h
index fc479ba..b40cd5d 100644
--- a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h
@@ -39,17 +39,20 @@
class TextureMapperPlatformLayer;
class TextureMapperNode;
class GraphicsLayerTextureMapper;
-class TextureMapperSurfaceManager;
class TextureMapperPaintOptions {
public:
BitmapTexture* surface;
TextureMapper* textureMapper;
- TextureMapperSurfaceManager* surfaceManager;
float opacity;
bool isSurface;
- TextureMapperPaintOptions() : surface(0), textureMapper(0), opacity(1.0), isSurface(false) { }
+ TextureMapperPaintOptions()
+ : surface(0)
+ , textureMapper(0)
+ , opacity(1)
+ , isSurface(false)
+ { }
};
class TextureMapperAnimation : public RefCounted<TextureMapperAnimation> {
@@ -135,7 +138,11 @@
};
TextureMapperNode()
- : m_parent(0), m_effectTarget(0), m_opacity(1.0), m_surfaceManager(0), m_textureMapper(0) { }
+ : m_parent(0)
+ , m_effectTarget(0)
+ , m_opacity(1)
+ , m_textureMapper(0)
+ { }
virtual ~TextureMapperNode();
@@ -317,7 +324,6 @@
};
State m_state;
- TextureMapperSurfaceManager* m_surfaceManager;
TextureMapper* m_textureMapper;
Vector<RefPtr<TextureMapperAnimation> > m_animations;