/src/mozilla-central/gfx/2d/CaptureCommandList.h
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 | | #ifndef mozilla_gfx_2d_CaptureCommandList_h |
8 | | #define mozilla_gfx_2d_CaptureCommandList_h |
9 | | |
10 | | #include "mozilla/Move.h" |
11 | | #include "mozilla/PodOperations.h" |
12 | | #include <vector> |
13 | | |
14 | | #include "DrawCommand.h" |
15 | | #include "Logging.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace gfx { |
19 | | |
20 | | class CaptureCommandList |
21 | | { |
22 | | public: |
23 | | CaptureCommandList() |
24 | | : mLastCommand(nullptr) |
25 | 0 | {} |
26 | | CaptureCommandList(CaptureCommandList&& aOther) |
27 | | : mStorage(std::move(aOther.mStorage)) |
28 | | , mLastCommand(aOther.mLastCommand) |
29 | 0 | { |
30 | 0 | aOther.mLastCommand = nullptr; |
31 | 0 | } |
32 | | ~CaptureCommandList(); |
33 | | |
34 | 0 | CaptureCommandList& operator=(CaptureCommandList&& aOther) { |
35 | 0 | mStorage = std::move(aOther.mStorage); |
36 | 0 | mLastCommand = aOther.mLastCommand; |
37 | 0 | aOther.mLastCommand = nullptr; |
38 | 0 | return *this; |
39 | 0 | } |
40 | | |
41 | | template <typename T> |
42 | 0 | T* Append() { |
43 | 0 | size_t oldSize = mStorage.size(); |
44 | 0 | mStorage.resize(mStorage.size() + sizeof(T) + sizeof(uint32_t)); |
45 | 0 | uint8_t* nextDrawLocation = &mStorage.front() + oldSize; |
46 | 0 | *(uint32_t*)(nextDrawLocation) = sizeof(T) + sizeof(uint32_t); |
47 | 0 | T* newCommand = reinterpret_cast<T*>(nextDrawLocation + sizeof(uint32_t)); |
48 | 0 | mLastCommand = newCommand; |
49 | 0 | return newCommand; |
50 | 0 | } Unexecuted instantiation: mozilla::gfx::SetPermitSubpixelAACommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::SetPermitSubpixelAACommand>() Unexecuted instantiation: mozilla::gfx::DrawSurfaceCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::DrawSurfaceCommand>() Unexecuted instantiation: mozilla::gfx::DrawSurfaceWithShadowCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::DrawSurfaceWithShadowCommand>() Unexecuted instantiation: mozilla::gfx::DrawFilterCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::DrawFilterCommand>() Unexecuted instantiation: mozilla::gfx::ClearRectCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::ClearRectCommand>() Unexecuted instantiation: mozilla::gfx::MaskSurfaceCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::MaskSurfaceCommand>() Unexecuted instantiation: mozilla::gfx::CopySurfaceCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::CopySurfaceCommand>() Unexecuted instantiation: mozilla::gfx::CopyRectCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::CopyRectCommand>() Unexecuted instantiation: mozilla::gfx::FillRectCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::FillRectCommand>() Unexecuted instantiation: mozilla::gfx::StrokeRectCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::StrokeRectCommand>() Unexecuted instantiation: mozilla::gfx::StrokeLineCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::StrokeLineCommand>() Unexecuted instantiation: mozilla::gfx::StrokeCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::StrokeCommand>() Unexecuted instantiation: mozilla::gfx::FillCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::FillCommand>() Unexecuted instantiation: mozilla::gfx::FillGlyphsCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::FillGlyphsCommand>() Unexecuted instantiation: mozilla::gfx::StrokeGlyphsCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::StrokeGlyphsCommand>() Unexecuted instantiation: mozilla::gfx::MaskCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::MaskCommand>() Unexecuted instantiation: mozilla::gfx::PushClipCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PushClipCommand>() Unexecuted instantiation: mozilla::gfx::PushClipRectCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PushClipRectCommand>() Unexecuted instantiation: mozilla::gfx::PushLayerCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PushLayerCommand>() Unexecuted instantiation: mozilla::gfx::PopLayerCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PopLayerCommand>() Unexecuted instantiation: mozilla::gfx::PopClipCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PopClipCommand>() Unexecuted instantiation: mozilla::gfx::SetTransformCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::SetTransformCommand>() Unexecuted instantiation: mozilla::gfx::BlurCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::BlurCommand>() Unexecuted instantiation: mozilla::gfx::PadEdgesCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::PadEdgesCommand>() Unexecuted instantiation: mozilla::gfx::FlushCommand* mozilla::gfx::CaptureCommandList::Append<mozilla::gfx::FlushCommand>() |
51 | | |
52 | | template <typename T> |
53 | 0 | T* ReuseOrAppend() { |
54 | 0 | { // Scope lock |
55 | 0 | if (mLastCommand != nullptr && |
56 | 0 | mLastCommand->GetType() == T::Type) { |
57 | 0 | return reinterpret_cast<T*>(mLastCommand); |
58 | 0 | } |
59 | 0 | } |
60 | 0 | return Append<T>(); |
61 | 0 | } Unexecuted instantiation: mozilla::gfx::SetPermitSubpixelAACommand* mozilla::gfx::CaptureCommandList::ReuseOrAppend<mozilla::gfx::SetPermitSubpixelAACommand>() Unexecuted instantiation: mozilla::gfx::SetTransformCommand* mozilla::gfx::CaptureCommandList::ReuseOrAppend<mozilla::gfx::SetTransformCommand>() |
62 | | |
63 | 0 | bool IsEmpty() const { |
64 | 0 | return mStorage.empty(); |
65 | 0 | } |
66 | | |
67 | | template <typename T> |
68 | 0 | bool BufferWillAlloc() const { |
69 | 0 | return mStorage.size() + sizeof(uint32_t) + sizeof(T) > mStorage.capacity(); |
70 | 0 | } Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::SetPermitSubpixelAACommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::DrawSurfaceCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::DrawSurfaceWithShadowCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::DrawFilterCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::ClearRectCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::MaskSurfaceCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::CopySurfaceCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::CopyRectCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::FillRectCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::StrokeRectCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::StrokeLineCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::StrokeCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::FillCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::FillGlyphsCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::StrokeGlyphsCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::MaskCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PushClipCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PushClipRectCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PushLayerCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PopLayerCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PopClipCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::SetTransformCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::BlurCommand>() const Unexecuted instantiation: bool mozilla::gfx::CaptureCommandList::BufferWillAlloc<mozilla::gfx::PadEdgesCommand>() const |
71 | | |
72 | 0 | size_t BufferCapacity() const { |
73 | 0 | return mStorage.capacity(); |
74 | 0 | } |
75 | | |
76 | | void Clear(); |
77 | | |
78 | | class iterator |
79 | | { |
80 | | public: |
81 | | explicit iterator(CaptureCommandList& aParent) |
82 | | : mParent(aParent), |
83 | | mCurrent(nullptr), |
84 | | mEnd(nullptr) |
85 | 0 | { |
86 | 0 | if (!mParent.mStorage.empty()) { |
87 | 0 | mCurrent = &mParent.mStorage.front(); |
88 | 0 | mEnd = mCurrent + mParent.mStorage.size(); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | 0 | bool Done() const { |
93 | 0 | return mCurrent >= mEnd; |
94 | 0 | } |
95 | 0 | void Next() { |
96 | 0 | MOZ_ASSERT(!Done()); |
97 | 0 | mCurrent += *reinterpret_cast<uint32_t*>(mCurrent); |
98 | 0 | } |
99 | 0 | DrawingCommand* Get() { |
100 | 0 | MOZ_ASSERT(!Done()); |
101 | 0 | return reinterpret_cast<DrawingCommand*>(mCurrent + sizeof(uint32_t)); |
102 | 0 | } |
103 | | |
104 | | private: |
105 | | CaptureCommandList& mParent; |
106 | | uint8_t* mCurrent; |
107 | | uint8_t* mEnd; |
108 | | }; |
109 | | |
110 | | void Log(TreeLog& aStream) |
111 | 0 | { |
112 | 0 | for (iterator iter(*this); !iter.Done(); iter.Next()) { |
113 | 0 | DrawingCommand* cmd = iter.Get(); |
114 | 0 | cmd->Log(aStream); |
115 | 0 | aStream << "\n"; |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | private: |
120 | | CaptureCommandList(const CaptureCommandList& aOther) = delete; |
121 | | void operator =(const CaptureCommandList& aOther) = delete; |
122 | | |
123 | | private: |
124 | | std::vector<uint8_t> mStorage; |
125 | | DrawingCommand* mLastCommand; |
126 | | }; |
127 | | |
128 | | } // namespace gfx |
129 | | } // namespace mozilla |
130 | | |
131 | | #endif // mozilla_gfx_2d_CaptureCommandList_h |