mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 09:05:45 +00:00
01583602a9
The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
159 lines
4.2 KiB
C++
159 lines
4.2 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/. */
|
|
|
|
#ifndef MOZILLA_GFX_COMMANDBUFFER_H_
|
|
#define MOZILLA_GFX_COMMANDBUFFER_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
#include "mozilla/Assertions.h"
|
|
#include "mozilla/gfx/Matrix.h"
|
|
#include "mozilla/gfx/JobScheduler.h"
|
|
#include "mozilla/gfx/IterableArena.h"
|
|
#include "mozilla/RefCounted.h"
|
|
#include "DrawCommand.h"
|
|
|
|
namespace mozilla {
|
|
namespace gfx {
|
|
|
|
class DrawingCommand;
|
|
class PrintCommand;
|
|
class SignalCommand;
|
|
class DrawingJob;
|
|
class WaitCommand;
|
|
|
|
class SyncObject;
|
|
class MultiThreadedJobQueue;
|
|
|
|
class DrawTarget;
|
|
|
|
class DrawingJobBuilder;
|
|
class CommandBufferBuilder;
|
|
|
|
/// Contains a sequence of immutable drawing commands that are typically used by
|
|
/// several DrawingJobs.
|
|
///
|
|
/// CommandBuffer objects are built using CommandBufferBuilder.
|
|
class CommandBuffer : public external::AtomicRefCounted<CommandBuffer>
|
|
{
|
|
public:
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(CommandBuffer)
|
|
|
|
~CommandBuffer();
|
|
|
|
const DrawingCommand* GetDrawingCommand(ptrdiff_t aId);
|
|
|
|
protected:
|
|
explicit CommandBuffer(size_t aSize = 256)
|
|
: mStorage(IterableArena::GROWABLE, aSize)
|
|
{}
|
|
|
|
IterableArena mStorage;
|
|
friend class CommandBufferBuilder;
|
|
};
|
|
|
|
/// Generates CommandBuffer objects.
|
|
///
|
|
/// The builder is a separate object to ensure that commands are not added to a
|
|
/// submitted CommandBuffer.
|
|
class CommandBufferBuilder
|
|
{
|
|
public:
|
|
void BeginCommandBuffer(size_t aBufferSize = 256);
|
|
|
|
already_AddRefed<CommandBuffer> EndCommandBuffer();
|
|
|
|
/// Build the CommandBuffer, command after command.
|
|
/// This must be used between BeginCommandBuffer and EndCommandBuffer.
|
|
template<typename T, typename... Args>
|
|
ptrdiff_t AddCommand(Args&&... aArgs)
|
|
{
|
|
static_assert(IsBaseOf<DrawingCommand, T>::value,
|
|
"T must derive from DrawingCommand");
|
|
return mCommands->mStorage.Alloc<T>(Forward<Args>(aArgs)...);
|
|
}
|
|
|
|
bool HasCommands() const { return !!mCommands; }
|
|
|
|
protected:
|
|
RefPtr<CommandBuffer> mCommands;
|
|
};
|
|
|
|
/// Stores multiple commands to be executed sequencially.
|
|
class DrawingJob : public Job {
|
|
public:
|
|
~DrawingJob();
|
|
|
|
virtual JobStatus Run() override;
|
|
|
|
protected:
|
|
DrawingJob(DrawTarget* aTarget,
|
|
IntPoint aOffset,
|
|
SyncObject* aStart,
|
|
SyncObject* aCompletion,
|
|
WorkerThread* aPinToWorker = nullptr);
|
|
|
|
/// Runs the tasks's destructors and resets the buffer.
|
|
void Clear();
|
|
|
|
std::vector<ptrdiff_t> mCommandOffsets;
|
|
RefPtr<CommandBuffer> mCommandBuffer;
|
|
uint32_t mCursor;
|
|
|
|
RefPtr<DrawTarget> mDrawTarget;
|
|
IntPoint mOffset;
|
|
|
|
friend class DrawingJobBuilder;
|
|
};
|
|
|
|
/// Generates DrawingJob objects.
|
|
///
|
|
/// The builder is a separate object to ensure that commands are not added to a
|
|
/// submitted DrawingJob.
|
|
class DrawingJobBuilder {
|
|
public:
|
|
DrawingJobBuilder();
|
|
|
|
~DrawingJobBuilder();
|
|
|
|
/// Allocates a DrawingJob.
|
|
///
|
|
/// call this method before starting to add commands.
|
|
void BeginDrawingJob(DrawTarget* aTarget, IntPoint aOffset,
|
|
SyncObject* aStart = nullptr);
|
|
|
|
/// Build the DrawingJob, command after command.
|
|
/// This must be used between BeginDrawingJob and EndDrawingJob.
|
|
void AddCommand(ptrdiff_t offset)
|
|
{
|
|
mCommandOffsets.push_back(offset);
|
|
}
|
|
|
|
/// Finalizes and returns the drawing task.
|
|
///
|
|
/// If aCompletion is not null, the sync object will be signaled after the
|
|
/// task buffer is destroyed (and after the destructor of the tasks have run).
|
|
/// In most cases this means after the completion of all tasks in the task buffer,
|
|
/// but also when the task buffer is destroyed due to an error.
|
|
DrawingJob* EndDrawingJob(CommandBuffer* aCmdBuffer,
|
|
SyncObject* aCompletion = nullptr,
|
|
WorkerThread* aPinToWorker = nullptr);
|
|
|
|
/// Returns true between BeginDrawingJob and EndDrawingJob, false otherwise.
|
|
bool HasDrawingJob() const { return !!mDrawTarget; }
|
|
|
|
protected:
|
|
std::vector<ptrdiff_t> mCommandOffsets;
|
|
RefPtr<DrawTarget> mDrawTarget;
|
|
IntPoint mOffset;
|
|
RefPtr<SyncObject> mStart;
|
|
};
|
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
#endif
|