mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
1c5959ee6e
- Bug 1125750 - Check the overflow region direction to avoid unnecesary reflow for scrollable frame. (6b5067631) - Bug 1125750 - Add auto test to detect error when using mOuter to check overflow area of a scrollable frame. (4e9c43e31) - override -> MOZ_OVERRIDE (ed1ecc151) - Bug 990907 - Don't add text-overflow markers while being actively scrolled by APZ. (523bc5a3e) - Bug 945584: Part 6 - Implementation of scroll snapping (v10 Patch) (bf64eb0f3) - Bug 945584: Part 7 - Implement Scroll Snapping for Autoscroll, - Triggering scroll snapping at the end of an autoscroll. - This enables text selection to be unencumbered by scroll snapping, while restoring the scroll position to a valid snapping position when the drag operation is completed. (db9ce9811) - Bug 945584: Part 8 - Implement Scroll Snapping for Middle Mouse Button Scrolls (v2 Patch) (06d1b733d) - some MacOS 10.5 Leopard support (6a37f6745) - Bug 945584: Part 9 - Tests for scroll snapping (v4 Patch) (f67175387) - Bug 1102427 - Ensure scroll parents of an active scrollframe are layerized. (910d43ec5) - Bug 1142731 followup. Check isInterpreted() before we call environment(), because of the asmjs lambdas. (29b2acdc7) - Bug 1161627 - part 1 - add move constructor and assignment operator for already_AddRefed&& to RefPtr; This change is prep work for future mass rewriting. (98416d45c) - Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; (336e96af7) - Bug 1161627 - part 3 - remove TemporaryRef<T> from RefPtr.h (6c3acdaed) - Bug 940273 - Part 3 - Service Worker Cache webidl. (4b6803d0a) - Bug 940273 - Part 4 - Initial implementation of Service Worker Cache. (74498c108) - Bug 1133861 - Bustage fix. (4a81437c2)
271 lines
8.5 KiB
C++
271 lines
8.5 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include <map>
|
|
#include <stack>
|
|
|
|
#include "gfxPlatform.h"
|
|
#include "mozilla/layers/GrallocTextureClient.h"
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "TextureClientRecycleAllocator.h"
|
|
|
|
namespace mozilla {
|
|
namespace layers {
|
|
|
|
class TextureClientRecycleAllocatorImp : public ISurfaceAllocator
|
|
{
|
|
~TextureClientRecycleAllocatorImp();
|
|
|
|
public:
|
|
explicit TextureClientRecycleAllocatorImp(ISurfaceAllocator* aAllocator);
|
|
|
|
void SetMaxPoolSize(uint32_t aMax)
|
|
{
|
|
if (aMax > 0) {
|
|
mMaxPooledSize = aMax;
|
|
}
|
|
}
|
|
|
|
// Creates and allocates a TextureClient.
|
|
already_AddRefed<TextureClient>
|
|
CreateOrRecycleForDrawing(gfx::SurfaceFormat aFormat,
|
|
gfx::IntSize aSize,
|
|
gfx::BackendType aMoz2dBackend,
|
|
TextureFlags aTextureFlags,
|
|
TextureAllocationFlags flags);
|
|
|
|
void Destroy();
|
|
|
|
void RecycleCallbackImp(TextureClient* aClient);
|
|
|
|
static void RecycleCallback(TextureClient* aClient, void* aClosure);
|
|
|
|
// ISurfaceAllocator
|
|
virtual LayersBackend GetCompositorBackendType() const override
|
|
{
|
|
return mSurfaceAllocator->GetCompositorBackendType();
|
|
}
|
|
|
|
virtual bool AllocShmem(size_t aSize,
|
|
mozilla::ipc::SharedMemory::SharedMemoryType aType,
|
|
mozilla::ipc::Shmem* aShmem) override
|
|
{
|
|
return mSurfaceAllocator->AllocShmem(aSize, aType, aShmem);
|
|
}
|
|
|
|
virtual bool AllocUnsafeShmem(size_t aSize,
|
|
mozilla::ipc::SharedMemory::SharedMemoryType aType,
|
|
mozilla::ipc::Shmem* aShmem) override
|
|
{
|
|
return mSurfaceAllocator->AllocUnsafeShmem(aSize, aType, aShmem);
|
|
}
|
|
|
|
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) override
|
|
{
|
|
mSurfaceAllocator->DeallocShmem(aShmem);
|
|
}
|
|
|
|
virtual bool IsSameProcess() const override
|
|
{
|
|
return mSurfaceAllocator->IsSameProcess();
|
|
}
|
|
|
|
protected:
|
|
// ISurfaceAllocator
|
|
virtual bool IsOnCompositorSide() const override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
static const uint32_t kMaxPooledSized = 2;
|
|
|
|
// Used to keep TextureClient's reference count stable as not to disrupt recycling.
|
|
class TextureClientHolder
|
|
{
|
|
~TextureClientHolder() {}
|
|
public:
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureClientHolder)
|
|
|
|
explicit TextureClientHolder(TextureClient* aClient)
|
|
: mTextureClient(aClient)
|
|
{}
|
|
|
|
TextureClient* GetTextureClient()
|
|
{
|
|
return mTextureClient;
|
|
}
|
|
void ClearTextureClient() { mTextureClient = nullptr; }
|
|
protected:
|
|
RefPtr<TextureClient> mTextureClient;
|
|
};
|
|
|
|
bool mDestroyed;
|
|
uint32_t mMaxPooledSize;
|
|
RefPtr<ISurfaceAllocator> mSurfaceAllocator;
|
|
std::map<TextureClient*, RefPtr<TextureClientHolder> > mInUseClients;
|
|
|
|
// On b2g gonk, std::queue might be a better choice.
|
|
// On ICS, fence wait happens implicitly before drawing.
|
|
// Since JB, fence wait happens explicitly when fetching a client from the pool.
|
|
// stack is good from Graphics cache usage point of view.
|
|
std::stack<RefPtr<TextureClientHolder> > mPooledClients;
|
|
Mutex mLock;
|
|
};
|
|
|
|
TextureClientRecycleAllocatorImp::TextureClientRecycleAllocatorImp(ISurfaceAllocator *aAllocator)
|
|
: mDestroyed(false)
|
|
, mMaxPooledSize(kMaxPooledSized)
|
|
, mSurfaceAllocator(aAllocator)
|
|
, mLock("TextureClientRecycleAllocatorImp.mLock")
|
|
{
|
|
}
|
|
|
|
TextureClientRecycleAllocatorImp::~TextureClientRecycleAllocatorImp()
|
|
{
|
|
MOZ_ASSERT(mDestroyed);
|
|
MOZ_ASSERT(mPooledClients.empty());
|
|
MOZ_ASSERT(mInUseClients.empty());
|
|
}
|
|
|
|
already_AddRefed<TextureClient>
|
|
TextureClientRecycleAllocatorImp::CreateOrRecycleForDrawing(
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::IntSize aSize,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aTextureFlags,
|
|
TextureAllocationFlags aAllocFlags)
|
|
{
|
|
// TextureAllocationFlags is actually used only by ContentClient.
|
|
// This class does not handle ConteClient's TextureClient allocation.
|
|
MOZ_ASSERT(aAllocFlags == TextureAllocationFlags::ALLOC_DEFAULT ||
|
|
aAllocFlags == TextureAllocationFlags::ALLOC_DISALLOW_BUFFERTEXTURECLIENT);
|
|
MOZ_ASSERT(!(aTextureFlags & TextureFlags::RECYCLE));
|
|
aTextureFlags = aTextureFlags | TextureFlags::RECYCLE; // Set recycle flag
|
|
|
|
RefPtr<TextureClientHolder> textureHolder;
|
|
|
|
if (aMoz2DBackend == gfx::BackendType::NONE) {
|
|
aMoz2DBackend = gfxPlatform::GetPlatform()->GetContentBackend();
|
|
}
|
|
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
if (mDestroyed) {
|
|
return nullptr;
|
|
} else if (!mPooledClients.empty()) {
|
|
textureHolder = mPooledClients.top();
|
|
mPooledClients.pop();
|
|
// If a pooled TextureClient is not compatible, release it.
|
|
if (textureHolder->GetTextureClient()->GetFormat() != aFormat ||
|
|
textureHolder->GetTextureClient()->GetSize() != aSize)
|
|
{
|
|
TextureClientReleaseTask* task = new TextureClientReleaseTask(textureHolder->GetTextureClient());
|
|
textureHolder->ClearTextureClient();
|
|
textureHolder = nullptr;
|
|
// Release TextureClient.
|
|
mSurfaceAllocator->GetMessageLoop()->PostTask(FROM_HERE, task);
|
|
} else {
|
|
textureHolder->GetTextureClient()->RecycleTexture(aTextureFlags);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!textureHolder) {
|
|
// Allocate new TextureClient
|
|
RefPtr<TextureClient> texture;
|
|
texture = TextureClient::CreateForDrawing(this, aFormat, aSize, aMoz2DBackend,
|
|
aTextureFlags, aAllocFlags);
|
|
if (!texture) {
|
|
return nullptr;
|
|
}
|
|
textureHolder = new TextureClientHolder(texture);
|
|
}
|
|
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
MOZ_ASSERT(mInUseClients.find(textureHolder->GetTextureClient()) == mInUseClients.end());
|
|
// Register TextureClient
|
|
mInUseClients[textureHolder->GetTextureClient()] = textureHolder;
|
|
}
|
|
textureHolder->GetTextureClient()->SetRecycleCallback(TextureClientRecycleAllocatorImp::RecycleCallback, this);
|
|
RefPtr<TextureClient> client(textureHolder->GetTextureClient());
|
|
return client.forget();
|
|
}
|
|
|
|
void
|
|
TextureClientRecycleAllocatorImp::Destroy()
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
if (mDestroyed) {
|
|
return;
|
|
}
|
|
mDestroyed = true;
|
|
while (!mPooledClients.empty()) {
|
|
mPooledClients.pop();
|
|
}
|
|
}
|
|
|
|
void
|
|
TextureClientRecycleAllocatorImp::RecycleCallbackImp(TextureClient* aClient)
|
|
{
|
|
RefPtr<TextureClientHolder> textureHolder;
|
|
aClient->ClearRecycleCallback();
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
if (mInUseClients.find(aClient) != mInUseClients.end()) {
|
|
textureHolder = mInUseClients[aClient]; // Keep reference count of TextureClientHolder within lock.
|
|
if (!mDestroyed && mPooledClients.size() < mMaxPooledSize) {
|
|
mPooledClients.push(textureHolder);
|
|
}
|
|
mInUseClients.erase(aClient);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* static */ void
|
|
TextureClientRecycleAllocatorImp::RecycleCallback(TextureClient* aClient, void* aClosure)
|
|
{
|
|
TextureClientRecycleAllocatorImp* recycleAllocator = static_cast<TextureClientRecycleAllocatorImp*>(aClosure);
|
|
recycleAllocator->RecycleCallbackImp(aClient);
|
|
}
|
|
|
|
TextureClientRecycleAllocator::TextureClientRecycleAllocator(ISurfaceAllocator *aAllocator)
|
|
{
|
|
mAllocator = new TextureClientRecycleAllocatorImp(aAllocator);
|
|
}
|
|
|
|
TextureClientRecycleAllocator::~TextureClientRecycleAllocator()
|
|
{
|
|
mAllocator->Destroy();
|
|
mAllocator = nullptr;
|
|
}
|
|
|
|
void
|
|
TextureClientRecycleAllocator::SetMaxPoolSize(uint32_t aMax)
|
|
{
|
|
mAllocator->SetMaxPoolSize(aMax);
|
|
}
|
|
|
|
already_AddRefed<TextureClient>
|
|
TextureClientRecycleAllocator::CreateOrRecycleForDrawing(
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::IntSize aSize,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aTextureFlags,
|
|
TextureAllocationFlags aAllocFlags)
|
|
{
|
|
return mAllocator->CreateOrRecycleForDrawing(aFormat,
|
|
aSize,
|
|
aMoz2DBackend,
|
|
aTextureFlags,
|
|
aAllocFlags);
|
|
}
|
|
|
|
}
|
|
}
|