summaryrefslogtreecommitdiff
path: root/gfx/2d/DrawingJob.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /gfx/2d/DrawingJob.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/2d/DrawingJob.cpp')
-rw-r--r--gfx/2d/DrawingJob.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/gfx/2d/DrawingJob.cpp b/gfx/2d/DrawingJob.cpp
new file mode 100644
index 0000000000..728e330f42
--- /dev/null
+++ b/gfx/2d/DrawingJob.cpp
@@ -0,0 +1,120 @@
+/* -*- 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 "DrawingJob.h"
+#include "JobScheduler.h"
+#include "mozilla/gfx/2D.h"
+
+namespace mozilla {
+namespace gfx {
+
+DrawingJobBuilder::DrawingJobBuilder()
+{}
+
+DrawingJobBuilder::~DrawingJobBuilder()
+{
+ MOZ_ASSERT(!mDrawTarget);
+}
+
+void
+DrawingJob::Clear()
+{
+ mCommandBuffer = nullptr;
+ mCursor = 0;
+}
+
+void
+DrawingJobBuilder::BeginDrawingJob(DrawTarget* aTarget, IntPoint aOffset,
+ SyncObject* aStart)
+{
+ MOZ_ASSERT(mCommandOffsets.empty());
+ MOZ_ASSERT(aTarget);
+ mDrawTarget = aTarget;
+ mOffset = aOffset;
+ mStart = aStart;
+}
+
+DrawingJob*
+DrawingJobBuilder::EndDrawingJob(CommandBuffer* aCmdBuffer,
+ SyncObject* aCompletion,
+ WorkerThread* aPinToWorker)
+{
+ MOZ_ASSERT(mDrawTarget);
+ DrawingJob* task = new DrawingJob(mDrawTarget, mOffset, mStart, aCompletion, aPinToWorker);
+ task->mCommandBuffer = aCmdBuffer;
+ task->mCommandOffsets = Move(mCommandOffsets);
+
+ mDrawTarget = nullptr;
+ mOffset = IntPoint();
+ mStart = nullptr;
+
+ return task;
+}
+
+DrawingJob::DrawingJob(DrawTarget* aTarget, IntPoint aOffset,
+ SyncObject* aStart, SyncObject* aCompletion,
+ WorkerThread* aPinToWorker)
+: Job(aStart, aCompletion, aPinToWorker)
+, mCommandBuffer(nullptr)
+, mCursor(0)
+, mDrawTarget(aTarget)
+, mOffset(aOffset)
+{
+ mCommandOffsets.reserve(64);
+}
+
+JobStatus
+DrawingJob::Run()
+{
+ while (mCursor < mCommandOffsets.size()) {
+
+ const DrawingCommand* cmd = mCommandBuffer->GetDrawingCommand(mCommandOffsets[mCursor]);
+
+ if (!cmd) {
+ return JobStatus::Error;
+ }
+
+ cmd->ExecuteOnDT(mDrawTarget);
+
+ ++mCursor;
+ }
+
+ return JobStatus::Complete;
+}
+
+DrawingJob::~DrawingJob()
+{
+ Clear();
+}
+
+const DrawingCommand*
+CommandBuffer::GetDrawingCommand(ptrdiff_t aId)
+{
+ return static_cast<DrawingCommand*>(mStorage.GetStorage(aId));
+}
+
+CommandBuffer::~CommandBuffer()
+{
+ mStorage.ForEach([](void* item){
+ static_cast<DrawingCommand*>(item)->~DrawingCommand();
+ });
+ mStorage.Clear();
+}
+
+void
+CommandBufferBuilder::BeginCommandBuffer(size_t aBufferSize)
+{
+ MOZ_ASSERT(!mCommands);
+ mCommands = new CommandBuffer(aBufferSize);
+}
+
+already_AddRefed<CommandBuffer>
+CommandBufferBuilder::EndCommandBuffer()
+{
+ return mCommands.forget();
+}
+
+} // namespace
+} // namespace