/src/mozilla-central/gfx/2d/DrawingJob.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "DrawingJob.h" |
8 | | #include "JobScheduler.h" |
9 | | #include "mozilla/gfx/2D.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace gfx { |
13 | | |
14 | | DrawingJobBuilder::DrawingJobBuilder() |
15 | 0 | {} |
16 | | |
17 | | DrawingJobBuilder::~DrawingJobBuilder() |
18 | 0 | { |
19 | 0 | MOZ_ASSERT(!mDrawTarget); |
20 | 0 | } |
21 | | |
22 | | void |
23 | | DrawingJob::Clear() |
24 | 0 | { |
25 | 0 | mCommandBuffer = nullptr; |
26 | 0 | mCursor = 0; |
27 | 0 | } |
28 | | |
29 | | void |
30 | | DrawingJobBuilder::BeginDrawingJob(DrawTarget* aTarget, IntPoint aOffset, |
31 | | SyncObject* aStart) |
32 | 0 | { |
33 | 0 | MOZ_ASSERT(mCommandOffsets.empty()); |
34 | 0 | MOZ_ASSERT(aTarget); |
35 | 0 | mDrawTarget = aTarget; |
36 | 0 | mOffset = aOffset; |
37 | 0 | mStart = aStart; |
38 | 0 | } |
39 | | |
40 | | DrawingJob* |
41 | | DrawingJobBuilder::EndDrawingJob(CommandBuffer* aCmdBuffer, |
42 | | SyncObject* aCompletion, |
43 | | WorkerThread* aPinToWorker) |
44 | 0 | { |
45 | 0 | MOZ_ASSERT(mDrawTarget); |
46 | 0 | DrawingJob* task = new DrawingJob(mDrawTarget, mOffset, mStart, aCompletion, aPinToWorker); |
47 | 0 | task->mCommandBuffer = aCmdBuffer; |
48 | 0 | task->mCommandOffsets = std::move(mCommandOffsets); |
49 | 0 |
|
50 | 0 | mDrawTarget = nullptr; |
51 | 0 | mOffset = IntPoint(); |
52 | 0 | mStart = nullptr; |
53 | 0 |
|
54 | 0 | return task; |
55 | 0 | } |
56 | | |
57 | | DrawingJob::DrawingJob(DrawTarget* aTarget, IntPoint aOffset, |
58 | | SyncObject* aStart, SyncObject* aCompletion, |
59 | | WorkerThread* aPinToWorker) |
60 | | : Job(aStart, aCompletion, aPinToWorker) |
61 | | , mCommandBuffer(nullptr) |
62 | | , mCursor(0) |
63 | | , mDrawTarget(aTarget) |
64 | | , mOffset(aOffset) |
65 | 0 | { |
66 | 0 | mCommandOffsets.reserve(64); |
67 | 0 | } |
68 | | |
69 | | JobStatus |
70 | | DrawingJob::Run() |
71 | 0 | { |
72 | 0 | while (mCursor < mCommandOffsets.size()) { |
73 | 0 |
|
74 | 0 | const DrawingCommand* cmd = mCommandBuffer->GetDrawingCommand(mCommandOffsets[mCursor]); |
75 | 0 |
|
76 | 0 | if (!cmd) { |
77 | 0 | return JobStatus::Error; |
78 | 0 | } |
79 | 0 | |
80 | 0 | cmd->ExecuteOnDT(mDrawTarget); |
81 | 0 |
|
82 | 0 | ++mCursor; |
83 | 0 | } |
84 | 0 |
|
85 | 0 | return JobStatus::Complete; |
86 | 0 | } |
87 | | |
88 | | DrawingJob::~DrawingJob() |
89 | 0 | { |
90 | 0 | Clear(); |
91 | 0 | } |
92 | | |
93 | | const DrawingCommand* |
94 | | CommandBuffer::GetDrawingCommand(ptrdiff_t aId) |
95 | 0 | { |
96 | 0 | return static_cast<DrawingCommand*>(mStorage.GetStorage(aId)); |
97 | 0 | } |
98 | | |
99 | | CommandBuffer::~CommandBuffer() |
100 | 0 | { |
101 | 0 | mStorage.ForEach([](void* item){ |
102 | 0 | static_cast<DrawingCommand*>(item)->~DrawingCommand(); |
103 | 0 | }); |
104 | 0 | mStorage.Clear(); |
105 | 0 | } |
106 | | |
107 | | void |
108 | | CommandBufferBuilder::BeginCommandBuffer(size_t aBufferSize) |
109 | 0 | { |
110 | 0 | MOZ_ASSERT(!mCommands); |
111 | 0 | mCommands = new CommandBuffer(aBufferSize); |
112 | 0 | } |
113 | | |
114 | | already_AddRefed<CommandBuffer> |
115 | | CommandBufferBuilder::EndCommandBuffer() |
116 | 0 | { |
117 | 0 | return mCommands.forget(); |
118 | 0 | } |
119 | | |
120 | | } // namespace |
121 | | } // namespace |