summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/platform/graphics/texmap/TextureMapper.cpp')
-rw-r--r--Source/WebCore/platform/graphics/texmap/TextureMapper.cpp135
1 files changed, 6 insertions, 129 deletions
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
index b863e79e5..973047f49 100644
--- a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
+++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
@@ -20,151 +20,28 @@
#include "config.h"
#include "TextureMapper.h"
+#include "BitmapTexturePool.h"
#include "FilterOperations.h"
#include "GraphicsLayer.h"
-#include "TextureMapperImageBuffer.h"
#include "Timer.h"
#include <wtf/CurrentTime.h>
-#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
-
namespace WebCore {
-struct BitmapTexturePoolEntry {
- explicit BitmapTexturePoolEntry(PassRefPtr<BitmapTexture> texture)
- : m_texture(texture)
- { }
- inline void markUsed() { m_timeLastUsed = monotonicallyIncreasingTime(); }
- static bool compareTimeLastUsed(const BitmapTexturePoolEntry& a, const BitmapTexturePoolEntry& b)
- {
- return a.m_timeLastUsed - b.m_timeLastUsed > 0;
- }
-
- RefPtr<BitmapTexture> m_texture;
- double m_timeLastUsed;
-};
-
-class BitmapTexturePool {
- WTF_MAKE_NONCOPYABLE(BitmapTexturePool);
- WTF_MAKE_FAST_ALLOCATED;
-public:
- BitmapTexturePool();
-
- PassRefPtr<BitmapTexture> acquireTexture(const IntSize&, TextureMapper*);
-
-private:
- void scheduleReleaseUnusedTextures();
- void releaseUnusedTexturesTimerFired(Timer<BitmapTexturePool>*);
-
- Vector<BitmapTexturePoolEntry> m_textures;
- Timer<BitmapTexturePool> m_releaseUnusedTexturesTimer;
-
- static const double s_releaseUnusedSecondsTolerance;
- static const double s_releaseUnusedTexturesTimerInterval;
-};
-
-const double BitmapTexturePool::s_releaseUnusedSecondsTolerance = 3;
-const double BitmapTexturePool::s_releaseUnusedTexturesTimerInterval = 0.5;
-
-BitmapTexturePool::BitmapTexturePool()
- : m_releaseUnusedTexturesTimer(this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
-{ }
+TextureMapper::TextureMapper() = default;
-void BitmapTexturePool::scheduleReleaseUnusedTextures()
-{
- if (m_releaseUnusedTexturesTimer.isActive())
- m_releaseUnusedTexturesTimer.stop();
-
- m_releaseUnusedTexturesTimer.startOneShot(s_releaseUnusedTexturesTimerInterval);
-}
-
-void BitmapTexturePool::releaseUnusedTexturesTimerFired(Timer<BitmapTexturePool>*)
-{
- if (m_textures.isEmpty())
- return;
-
- // Delete entries, which have been unused in s_releaseUnusedSecondsTolerance.
- std::sort(m_textures.begin(), m_textures.end(), BitmapTexturePoolEntry::compareTimeLastUsed);
-
- double minUsedTime = monotonicallyIncreasingTime() - s_releaseUnusedSecondsTolerance;
- for (size_t i = 0; i < m_textures.size(); ++i) {
- if (m_textures[i].m_timeLastUsed < minUsedTime) {
- m_textures.remove(i, m_textures.size() - i);
- break;
- }
- }
-}
-
-PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, TextureMapper* textureMapper)
-{
- BitmapTexturePoolEntry* selectedEntry = 0;
- for (size_t i = 0; i < m_textures.size(); ++i) {
- BitmapTexturePoolEntry* entry = &m_textures[i];
-
- // If the surface has only one reference (the one in m_textures), we can safely reuse it.
- if (entry->m_texture->refCount() > 1)
- continue;
-
- if (entry->m_texture->canReuseWith(size)) {
- selectedEntry = entry;
- break;
- }
- }
-
- if (!selectedEntry) {
- m_textures.append(BitmapTexturePoolEntry(textureMapper->createTexture()));
- selectedEntry = &m_textures.last();
- }
-
- scheduleReleaseUnusedTextures();
- selectedEntry->markUsed();
- return selectedEntry->m_texture;
-}
+TextureMapper::~TextureMapper() = default;
PassRefPtr<BitmapTexture> TextureMapper::acquireTextureFromPool(const IntSize& size, const BitmapTexture::Flags flags)
{
- RefPtr<BitmapTexture> selectedTexture = m_texturePool->acquireTexture(size, this);
+ RefPtr<BitmapTexture> selectedTexture = m_texturePool->acquireTexture(size, flags);
selectedTexture->reset(size, flags);
- return selectedTexture;
+ return selectedTexture.release();
}
-PassOwnPtr<TextureMapper> TextureMapper::create(AccelerationMode mode)
+std::unique_ptr<TextureMapper> TextureMapper::create()
{
- if (mode == SoftwareMode)
- return TextureMapperImageBuffer::create();
return platformCreateAccelerated();
}
-TextureMapper::TextureMapper(AccelerationMode accelerationMode)
- : m_context(0)
- , m_interpolationQuality(InterpolationDefault)
- , m_textDrawingMode(TextModeFill)
- , m_texturePool(adoptPtr(new BitmapTexturePool()))
- , m_accelerationMode(accelerationMode)
- , m_isMaskMode(false)
- , m_wrapMode(StretchWrap)
-{ }
-
-TextureMapper::~TextureMapper()
-{ }
-
-void BitmapTexture::updateContents(TextureMapper* textureMapper, GraphicsLayer* sourceLayer, const IntRect& targetRect, const IntPoint& offset, UpdateContentsFlag updateContentsFlag)
-{
- std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::create(targetRect.size());
- GraphicsContext* context = imageBuffer->context();
- context->setImageInterpolationQuality(textureMapper->imageInterpolationQuality());
- context->setTextDrawingMode(textureMapper->textDrawingMode());
-
- IntRect sourceRect(targetRect);
- sourceRect.setLocation(offset);
- context->translate(-offset.x(), -offset.y());
- sourceLayer->paintGraphicsLayerContents(*context, sourceRect);
-
- RefPtr<Image> image = imageBuffer->copyImage(DontCopyBackingStore);
-
- updateContents(image.get(), targetRect, IntPoint(), updateContentsFlag);
-}
-
} // namespace
-
-#endif