Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / wr / IpcResourceUpdateQueue.h
blobe16917c10ed8a2d1458abe435184d2099d8049cc
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/. */
7 #ifndef GFX_WR_IPCRESOURCEUPDATEQUEUE_H
8 #define GFX_WR_IPCRESOURCEUPDATEQUEUE_H
10 #include "mozilla/layers/WebRenderMessages.h"
11 #include "mozilla/layers/RefCountedShmem.h"
12 #include "mozilla/layers/TextureClient.h"
13 #include "mozilla/webrender/WebRenderTypes.h"
15 namespace mozilla {
16 namespace ipc {
17 class IShmemAllocator;
19 namespace layers {
20 class TextureClient;
23 namespace wr {
25 /// ShmSegmentsWriter pushes bytes in a sequence of fixed size shmems for small
26 /// allocations and creates dedicated shmems for large allocations.
27 class ShmSegmentsWriter {
28 public:
29 ShmSegmentsWriter(layers::WebRenderBridgeChild* aAllocator,
30 size_t aChunkSize);
31 ~ShmSegmentsWriter();
33 ShmSegmentsWriter(ShmSegmentsWriter&& aOther) noexcept;
34 ShmSegmentsWriter& operator=(ShmSegmentsWriter&& aOther) noexcept;
36 ShmSegmentsWriter(const ShmSegmentsWriter& aOther) = delete;
37 ShmSegmentsWriter& operator=(const ShmSegmentsWriter& aOther) = delete;
39 layers::OffsetRange Write(Range<uint8_t> aBytes);
41 template <typename T>
42 layers::OffsetRange WriteAsBytes(Range<T> aValues) {
43 return Write(Range<uint8_t>((uint8_t*)aValues.begin().get(),
44 aValues.length() * sizeof(T)));
47 void Flush(nsTArray<layers::RefCountedShmem>& aSmallAllocs,
48 nsTArray<mozilla::ipc::Shmem>& aLargeAllocs);
50 void Clear();
51 bool IsEmpty() const;
53 layers::WebRenderBridgeChild* WrBridge() const { return mShmAllocator; }
54 size_t ChunkSize() const { return mChunkSize; }
56 protected:
57 bool AllocChunk();
58 layers::OffsetRange AllocLargeChunk(size_t aSize);
60 nsTArray<layers::RefCountedShmem> mSmallAllocs;
61 nsTArray<mozilla::ipc::Shmem> mLargeAllocs;
62 layers::WebRenderBridgeChild* mShmAllocator;
63 size_t mCursor;
64 size_t mChunkSize;
67 class ShmSegmentsReader {
68 public:
69 ShmSegmentsReader(const nsTArray<layers::RefCountedShmem>& aSmallShmems,
70 const nsTArray<mozilla::ipc::Shmem>& aLargeShmems);
72 bool Read(const layers::OffsetRange& aRange, wr::Vec<uint8_t>& aInto);
74 protected:
75 bool ReadLarge(const layers::OffsetRange& aRange, wr::Vec<uint8_t>& aInto);
77 const nsTArray<layers::RefCountedShmem>& mSmallAllocs;
78 const nsTArray<mozilla::ipc::Shmem>& mLargeAllocs;
79 size_t mChunkSize;
82 class IpcResourceUpdateQueue {
83 public:
84 // Because we are using shmems, the size should be a multiple of the page
85 // size. Each shmem has two guard pages, and the minimum shmem size (at least
86 // one Windows) is 64k which is already quite large for a lot of the resources
87 // we use here. The RefCountedShmem type used to allocate the chunks keeps a
88 // 16 bytes header in the buffer which we account for here as well. So we pick
89 // 64k - 2 * 4k - 16 = 57328 bytes as the default alloc size.
90 explicit IpcResourceUpdateQueue(
91 layers::WebRenderBridgeChild* aAllocator,
92 wr::RenderRoot aRenderRoot = wr::RenderRoot::Default,
93 size_t aChunkSize = 57328);
95 // Although resource updates don't belong to a particular document/render root
96 // in any concrete way, they still end up being tied to a render root because
97 // we need to know which WR document to generate a frame for when they change.
98 IpcResourceUpdateQueue& SubQueue(wr::RenderRoot aRenderRoot) {
99 MOZ_ASSERT(mRenderRoot == wr::RenderRoot::Default);
100 MOZ_ASSERT(aRenderRoot == wr::RenderRoot::Default);
101 return *this;
104 bool HasAnySubQueue() { return false; }
106 bool HasSubQueue(wr::RenderRoot aRenderRoot) {
107 return aRenderRoot == wr::RenderRoot::Default;
110 wr::RenderRoot GetRenderRoot() { return mRenderRoot; }
112 IpcResourceUpdateQueue(IpcResourceUpdateQueue&& aOther) noexcept;
113 IpcResourceUpdateQueue& operator=(IpcResourceUpdateQueue&& aOther) noexcept;
115 IpcResourceUpdateQueue(const IpcResourceUpdateQueue& aOther) = delete;
116 IpcResourceUpdateQueue& operator=(const IpcResourceUpdateQueue& aOther) =
117 delete;
119 // Moves over everything but the subqueues
120 void ReplaceResources(IpcResourceUpdateQueue&& aOther);
122 bool AddImage(wr::ImageKey aKey, const ImageDescriptor& aDescriptor,
123 Range<uint8_t> aBytes);
125 bool AddBlobImage(wr::BlobImageKey aKey, const ImageDescriptor& aDescriptor,
126 Range<uint8_t> aBytes, ImageIntRect aVisibleRect);
128 void AddPrivateExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey,
129 wr::ImageDescriptor aDesc);
131 void AddSharedExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey);
133 void PushExternalImageForTexture(wr::ExternalImageId aExtId,
134 wr::ImageKey aKey,
135 layers::TextureClient* aTexture,
136 bool aIsUpdate);
138 bool UpdateImageBuffer(wr::ImageKey aKey, const ImageDescriptor& aDescriptor,
139 Range<uint8_t> aBytes);
141 bool UpdateBlobImage(wr::BlobImageKey aKey,
142 const ImageDescriptor& aDescriptor,
143 Range<uint8_t> aBytes, ImageIntRect aVisibleRect,
144 ImageIntRect aDirtyRect);
146 void UpdatePrivateExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey,
147 const wr::ImageDescriptor& aDesc,
148 ImageIntRect aDirtyRect);
149 void UpdateSharedExternalImage(ExternalImageId aExtID, ImageKey aKey,
150 ImageIntRect aDirtyRect);
152 void SetBlobImageVisibleArea(BlobImageKey aKey, const ImageIntRect& aArea);
154 void DeleteImage(wr::ImageKey aKey);
156 void DeleteBlobImage(wr::BlobImageKey aKey);
158 bool AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex);
160 bool AddFontDescriptor(wr::FontKey aKey, Range<uint8_t> aBytes,
161 uint32_t aIndex);
163 void DeleteFont(wr::FontKey aKey);
165 void AddFontInstance(wr::FontInstanceKey aKey, wr::FontKey aFontKey,
166 float aGlyphSize,
167 const wr::FontInstanceOptions* aOptions,
168 const wr::FontInstancePlatformOptions* aPlatformOptions,
169 Range<const gfx::FontVariation> aVariations);
171 void DeleteFontInstance(wr::FontInstanceKey aKey);
173 void Clear();
175 void Flush(nsTArray<layers::OpUpdateResource>& aUpdates,
176 nsTArray<layers::RefCountedShmem>& aSmallAllocs,
177 nsTArray<mozilla::ipc::Shmem>& aLargeAllocs);
179 bool IsEmpty() const;
181 static void ReleaseShmems(mozilla::ipc::IProtocol*,
182 nsTArray<layers::RefCountedShmem>& aShms);
183 static void ReleaseShmems(mozilla::ipc::IProtocol*,
184 nsTArray<mozilla::ipc::Shmem>& aShms);
186 protected:
187 ShmSegmentsWriter mWriter;
188 nsTArray<layers::OpUpdateResource> mUpdates;
189 wr::RenderRoot mRenderRoot;
192 } // namespace wr
193 } // namespace mozilla
195 #endif