Bug 1440937 - Change PaintTask to be a UniquePtr. r=mattwoodrow

Now that we have C++14 support we can capture a move only object in a lambda expression.

--HG--
extra : rebase_source : 232639ba334520cf9d38d68190af8fdcd4aa454d
This commit is contained in:
Ryan Hunt 2018-09-12 10:28:59 -05:00
Родитель cddaaa8ed5
Коммит c272b03256
8 изменённых файлов: 39 добавлений и 32 удалений

Просмотреть файл

@ -197,7 +197,7 @@ PaintThread::UpdateRenderMode()
}
void
PaintThread::QueuePaintTask(PaintTask* aTask)
PaintThread::QueuePaintTask(UniquePtr<PaintTask>&& aTask)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aTask);
@ -206,16 +206,16 @@ PaintThread::QueuePaintTask(PaintTask* aTask)
aTask->mCapture->Dump();
}
RefPtr<CompositorBridgeChild> cbc(CompositorBridgeChild::Get());
RefPtr<PaintTask> state(aTask);
MOZ_RELEASE_ASSERT(aTask->mCapture->hasOneRef());
cbc->NotifyBeginAsyncPaint(state);
RefPtr<CompositorBridgeChild> cbc(CompositorBridgeChild::Get());
cbc->NotifyBeginAsyncPaint(aTask.get());
RefPtr<PaintThread> self = this;
RefPtr<Runnable> task = NS_NewRunnableFunction("PaintThread::AsyncPaintTask",
[self, cbc, state]() -> void
[self, cbc, task = std::move(aTask)]() -> void
{
self->AsyncPaintTask(cbc, state);
self->AsyncPaintTask(cbc, task.get());
});
nsIEventTarget* paintThread = mPaintWorkers ?

Просмотреть файл

@ -34,18 +34,15 @@ namespace layers {
// 3. A list of dependent texture clients that must be kept alive for the
// task's duration, and then destroyed on the main thread
class PaintTask {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PaintTask)
public:
PaintTask() {}
~PaintTask() {}
void DropTextureClients();
RefPtr<gfx::DrawTarget> mTarget;
RefPtr<gfx::DrawTargetCapture> mCapture;
AutoTArray<RefPtr<TextureClient>, 4> mClients;
protected:
virtual ~PaintTask() {}
};
class CompositorBridgeChild;
@ -73,7 +70,7 @@ public:
// Must be called on the main thread. Queues an async paint
// task to be completed on the paint thread.
void QueuePaintTask(PaintTask* aTask);
void QueuePaintTask(UniquePtr<PaintTask>&& aTask);
// Must be called on the main thread. Signifies that the current
// layer tree transaction has been finished and any async paints

Просмотреть файл

@ -96,7 +96,7 @@ ClientPaintedLayer::FinishPaintState(PaintState& aState)
{
if (aState.mAsyncTask && !aState.mAsyncTask->mCapture->IsEmpty()) {
ClientManager()->SetQueuedAsyncPaints();
PaintThread::Get()->QueuePaintTask(aState.mAsyncTask);
PaintThread::Get()->QueuePaintTask(std::move(aState.mAsyncTask));
}
}

Просмотреть файл

@ -163,7 +163,7 @@ ContentClient::BeginPaint(PaintedLayer* aLayer,
IntRect drawBounds = result.mRegionToDraw.GetBounds();
if (result.mAsyncPaint) {
result.mAsyncTask = new PaintTask();
result.mAsyncTask.reset(new PaintTask());
}
// Try to acquire the back buffer, copy over contents if we are using a new buffer,

Просмотреть файл

@ -25,6 +25,7 @@
#include "mozilla/layers/PaintThread.h" // for PaintTask
#include "mozilla/Maybe.h" // for Maybe
#include "mozilla/mozalloc.h" // for operator delete
#include "mozilla/UniquePtr.h" // for UniquePtr
#include "ReadbackProcessor.h" // For ReadbackProcessor::Update
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsPoint.h" // for nsIntPoint
@ -117,7 +118,7 @@ public:
DrawRegionClip mClip;
gfxContentType mContentType;
bool mAsyncPaint;
RefPtr<PaintTask> mAsyncTask;
UniquePtr<PaintTask> mAsyncTask;
};
enum {

Просмотреть файл

@ -152,7 +152,7 @@ void ClientMultiTiledLayerBuffer::MaybeSyncTextures(const nsIntRegion& aPaintReg
// texture IDs that we need to ensure are unused by the GPU before we
// continue.
if (!aPaintRegion.IsEmpty()) {
MOZ_ASSERT(mPaintTasks.size() == 0);
MOZ_ASSERT(mPaintTasks.IsEmpty());
for (size_t i = 0; i < mRetainedTiles.Length(); ++i) {
const TileCoordIntPoint tileCoord = aNewTiles.TileCoord(i);
@ -220,7 +220,7 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
MaybeSyncTextures(paintRegion, newTiles, scaledTileSize);
if (!paintRegion.IsEmpty()) {
MOZ_ASSERT(mPaintTasks.size() == 0);
MOZ_ASSERT(mPaintTasks.IsEmpty());
for (size_t i = 0; i < newTileCount; ++i) {
const TileCoordIntPoint tileCoord = newTiles.TileCoord(i);
@ -243,14 +243,14 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
dirtyRegion.OrWith(tileDrawRegion);
}
if (!mPaintTiles.empty()) {
if (!mPaintTiles.IsEmpty()) {
// Create a tiled draw target
gfx::TileSet tileset;
for (size_t i = 0; i < mPaintTiles.size(); ++i) {
for (size_t i = 0; i < mPaintTiles.Length(); ++i) {
mPaintTiles[i].mTileOrigin -= mTilingOrigin;
}
tileset.mTiles = &mPaintTiles[0];
tileset.mTileCount = mPaintTiles.size();
tileset.mTiles = mPaintTiles.Elements();
tileset.mTileCount = mPaintTiles.Length();
RefPtr<DrawTarget> drawTarget = gfx::Factory::CreateTiledDrawTarget(tileset);
if (!drawTarget || !drawTarget->IsValid()) {
gfxDevCrash(LogReason::InvalidContext) << "Invalid tiled draw target";
@ -274,7 +274,7 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
}
// Reset
mPaintTiles.clear();
mPaintTiles.Clear();
mTilingOrigin = IntPoint(std::numeric_limits<int32_t>::max(),
std::numeric_limits<int32_t>::max());
}
@ -283,9 +283,10 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
if (aFlags & TilePaintFlags::Async) {
bool queuedTask = false;
for (const auto& state : mPaintTasks) {
if (!state->mCapture->IsEmpty()) {
PaintThread::Get()->QueuePaintTask(state);
while (!mPaintTasks.IsEmpty()) {
UniquePtr<PaintTask> task = mPaintTasks.PopLastElement();
if (!task->mCapture->IsEmpty()) {
PaintThread::Get()->QueuePaintTask(std::move(task));
queuedTask = true;
}
}
@ -294,7 +295,7 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion,
mManager->SetQueuedAsyncPaints();
}
mPaintTasks.clear();
mPaintTasks.Clear();
}
for (uint32_t i = 0; i < mRetainedTiles.Length(); ++i) {
@ -386,14 +387,14 @@ ClientMultiTiledLayerBuffer::ValidateTile(TileClient& aTile,
gfx::Tile paintTile;
paintTile.mTileOrigin = gfx::IntPoint(aTileOrigin.x, aTileOrigin.y);
paintTile.mDrawTarget = backBuffer->mTarget;
mPaintTiles.push_back(paintTile);
mPaintTiles.AppendElement(paintTile);
if (aFlags & TilePaintFlags::Async) {
RefPtr<PaintTask> task = new PaintTask();
UniquePtr<PaintTask> task(new PaintTask());
task->mCapture = backBuffer->mCapture;
task->mTarget = backBuffer->mBackBuffer;
task->mClients = std::move(backBuffer->mTextureClients);
mPaintTasks.push_back(task);
mPaintTasks.AppendElement(std::move(task));
} else {
MOZ_RELEASE_ASSERT(backBuffer->mTarget == backBuffer->mBackBuffer);
MOZ_RELEASE_ASSERT(backBuffer->mCapture == nullptr);

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/layers/CompositableClient.h" // for CompositableClient
#include "mozilla/layers/LayersMessages.h" // for TileDescriptor
#include "mozilla/layers/TiledContentClient.h" // for ClientTiledPaintedLayer
#include "mozilla/UniquePtr.h" // for UniquePtr
#include "TiledLayerBuffer.h" // for TiledLayerBuffer
namespace mozilla {
@ -121,8 +122,8 @@ private:
// Parameters that are collected during Update for a paint before they
// are either executed or replayed on the paint thread.
std::vector<gfx::Tile> mPaintTiles;
std::vector<RefPtr<PaintTask>> mPaintTasks;
AutoTArray<gfx::Tile, 4> mPaintTiles;
AutoTArray<UniquePtr<PaintTask>, 4> mPaintTasks;
/**
* While we're adding tiles, this is used to keep track of the position of

Просмотреть файл

@ -8,6 +8,7 @@
#include "ClientTiledPaintedLayer.h"
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
namespace mozilla {
namespace layers {
@ -236,11 +237,17 @@ ClientSingleTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion,
if (asyncPaint) {
if (!backBuffer->mCapture->IsEmpty()) {
RefPtr<PaintTask> task = new PaintTask();
UniquePtr<PaintTask> task(new PaintTask());
task->mCapture = backBuffer->mCapture;
task->mTarget = backBuffer->mBackBuffer;
task->mClients = std::move(backBuffer->mTextureClients);
PaintThread::Get()->QueuePaintTask(task);
// The target is an alias for the capture, and the paint thread expects
// to be the only one with a reference to the capture
backBuffer->mTarget = nullptr;
backBuffer->mCapture = nullptr;
PaintThread::Get()->QueuePaintTask(std::move(task));
mManager->SetQueuedAsyncPaints();
}
} else {