/work/obj-fuzz/dist/include/mozilla/layers/IpcResourceUpdateQueue.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 GFX_WR_IPCRESOURCEUPDATEQUEUE_H |
8 | | #define GFX_WR_IPCRESOURCEUPDATEQUEUE_H |
9 | | |
10 | | #include "mozilla/layers/WebRenderMessages.h" |
11 | | #include "mozilla/layers/RefCountedShmem.h" |
12 | | #include "mozilla/webrender/WebRenderTypes.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace ipc { |
16 | | class IShmemAllocator; |
17 | | } |
18 | | namespace wr { |
19 | | |
20 | | /// ShmSegmentsWriter pushes bytes in a sequence of fixed size shmems for small |
21 | | /// allocations and creates dedicated shmems for large allocations. |
22 | | class ShmSegmentsWriter { |
23 | | public: |
24 | | ShmSegmentsWriter(layers::WebRenderBridgeChild* aAllocator, size_t aChunkSize); |
25 | | ~ShmSegmentsWriter(); |
26 | | |
27 | | layers::OffsetRange Write(Range<uint8_t> aBytes); |
28 | | |
29 | | template<typename T> |
30 | | layers::OffsetRange WriteAsBytes(Range<T> aValues) |
31 | 0 | { |
32 | 0 | return Write(Range<uint8_t>((uint8_t*)aValues.begin().get(), aValues.length() * sizeof(T))); |
33 | 0 | } |
34 | | |
35 | | void Flush(nsTArray<layers::RefCountedShmem>& aSmallAllocs, nsTArray<ipc::Shmem>& aLargeAllocs); |
36 | | |
37 | | void Clear(); |
38 | | bool IsEmpty() const; |
39 | | |
40 | 0 | layers::WebRenderBridgeChild* WrBridge() const { return mShmAllocator; } |
41 | | |
42 | | protected: |
43 | | bool AllocChunk(); |
44 | | layers::OffsetRange AllocLargeChunk(size_t aSize); |
45 | | |
46 | | nsTArray<layers::RefCountedShmem> mSmallAllocs; |
47 | | nsTArray<ipc::Shmem> mLargeAllocs; |
48 | | layers::WebRenderBridgeChild* mShmAllocator; |
49 | | size_t mCursor; |
50 | | size_t mChunkSize; |
51 | | }; |
52 | | |
53 | | class ShmSegmentsReader { |
54 | | public: |
55 | | ShmSegmentsReader(const nsTArray<layers::RefCountedShmem>& aSmallShmems, |
56 | | const nsTArray<ipc::Shmem>& aLargeShmems); |
57 | | |
58 | | bool Read(const layers::OffsetRange& aRange, wr::Vec<uint8_t>& aInto); |
59 | | |
60 | | protected: |
61 | | bool ReadLarge(const layers::OffsetRange& aRange, wr::Vec<uint8_t>& aInto); |
62 | | |
63 | | const nsTArray<layers::RefCountedShmem>& mSmallAllocs; |
64 | | const nsTArray<ipc::Shmem>& mLargeAllocs; |
65 | | size_t mChunkSize; |
66 | | }; |
67 | | |
68 | | class IpcResourceUpdateQueue { |
69 | | public: |
70 | | // Because we are using shmems, the size should be a multiple of the page size. |
71 | | // Each shmem has two guard pages, and the minimum shmem size (at least one Windows) |
72 | | // is 64k which is already quite large for a lot of the resources we use here. |
73 | | // The RefCountedShmem type used to allocate the chunks keeps a 16 bytes header |
74 | | // in the buffer which we account for here as well. |
75 | | // So we pick 64k - 2 * 4k - 16 = 57328 bytes as the default alloc size. |
76 | | explicit IpcResourceUpdateQueue(layers::WebRenderBridgeChild* aAllocator, size_t aChunkSize = 57328); |
77 | | |
78 | | bool AddImage(wr::ImageKey aKey, |
79 | | const ImageDescriptor& aDescriptor, |
80 | | Range<uint8_t> aBytes); |
81 | | |
82 | | bool AddBlobImage(wr::ImageKey aKey, |
83 | | const ImageDescriptor& aDescriptor, |
84 | | Range<uint8_t> aBytes); |
85 | | |
86 | | void AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey); |
87 | | |
88 | | void PushExternalImageForTexture(wr::ExternalImageId aExtId, |
89 | | wr::ImageKey aKey, |
90 | | layers::TextureClient* aTexture, |
91 | | bool aIsUpdate); |
92 | | |
93 | | bool UpdateImageBuffer(wr::ImageKey aKey, |
94 | | const ImageDescriptor& aDescriptor, |
95 | | Range<uint8_t> aBytes); |
96 | | |
97 | | bool UpdateBlobImage(wr::ImageKey aKey, |
98 | | const ImageDescriptor& aDescriptor, |
99 | | Range<uint8_t> aBytes, |
100 | | ImageIntRect aDirtyRect); |
101 | | |
102 | | void UpdateExternalImage(ExternalImageId aExtID, |
103 | | ImageKey aKey, |
104 | | ImageIntRect aDirtyRect); |
105 | | |
106 | | void SetImageVisibleArea(ImageKey aKey, const gfx::Rect& aArea); |
107 | | |
108 | | void DeleteImage(wr::ImageKey aKey); |
109 | | |
110 | | bool AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex); |
111 | | |
112 | | bool AddFontDescriptor(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex); |
113 | | |
114 | | void DeleteFont(wr::FontKey aKey); |
115 | | |
116 | | void AddFontInstance(wr::FontInstanceKey aKey, |
117 | | wr::FontKey aFontKey, |
118 | | float aGlyphSize, |
119 | | const wr::FontInstanceOptions* aOptions, |
120 | | const wr::FontInstancePlatformOptions* aPlatformOptions, |
121 | | Range<const gfx::FontVariation> aVariations); |
122 | | |
123 | | void DeleteFontInstance(wr::FontInstanceKey aKey); |
124 | | |
125 | | void Clear(); |
126 | | |
127 | | void Flush(nsTArray<layers::OpUpdateResource>& aUpdates, |
128 | | nsTArray<layers::RefCountedShmem>& aSmallAllocs, |
129 | | nsTArray<ipc::Shmem>& aLargeAllocs); |
130 | | |
131 | | bool IsEmpty() const; |
132 | | |
133 | | static void ReleaseShmems(ipc::IProtocol*, nsTArray<layers::RefCountedShmem>& aShmems); |
134 | | static void ReleaseShmems(ipc::IProtocol*, nsTArray<ipc::Shmem>& aShmems); |
135 | | protected: |
136 | | ShmSegmentsWriter mWriter; |
137 | | nsTArray<layers::OpUpdateResource> mUpdates; |
138 | | }; |
139 | | |
140 | | } // namespace |
141 | | } // namespace |
142 | | |
143 | | #endif |