WebGLChild.h (1992B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WEBGLCHILD_H_ 7 #define WEBGLCHILD_H_ 8 9 #include <string> 10 11 #include "mozilla/Maybe.h" 12 #include "mozilla/WeakPtr.h" 13 #include "mozilla/dom/PWebGLChild.h" 14 #include "mozilla/ipc/BigBuffer.h" 15 16 namespace mozilla { 17 18 class ClientWebGLContext; 19 20 namespace dom { 21 22 struct FlushedCmdInfo final { 23 size_t flushes = 0; 24 // Store a number of flushes since last IPC congestion check. 25 // It is reset to 0, when current IPC congestion check is done. 26 size_t flushesSinceLastCongestionCheck = 0; 27 // Incremented for each IPC congestion check. 28 size_t congestionCheckGeneration = 0; 29 size_t flushedCmdBytes = 0; 30 size_t overhead = 0; 31 }; 32 33 class WebGLChild final : public PWebGLChild, public SupportsWeakPtr { 34 const WeakPtr<ClientWebGLContext> mContext; 35 const size_t mDefaultCmdsShmemSize; 36 mozilla::ipc::BigBuffer mPendingCmdsShmem; 37 size_t mPendingCmdsPos = 0; 38 size_t mPendingCmdsAlignmentOverhead = 0; 39 FlushedCmdInfo mFlushedCmdInfo; 40 41 public: 42 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGLChild, override); 43 44 explicit WebGLChild(ClientWebGLContext&); 45 46 Maybe<Range<uint8_t>> AllocPendingCmdBytes(size_t, 47 size_t fyiAlignmentOverhead); 48 void FlushPendingCmds(); 49 void Destroy(); 50 void ActorDestroy(ActorDestroyReason why) override; 51 52 FlushedCmdInfo& GetFlushedCmdInfo() { return mFlushedCmdInfo; } 53 54 private: 55 friend PWebGLChild; 56 virtual ~WebGLChild(); 57 58 public: 59 mozilla::ipc::IPCResult RecvJsWarning(const std::string&) const; 60 mozilla::ipc::IPCResult RecvOnContextLoss(webgl::ContextLossReason) const; 61 mozilla::ipc::IPCResult RecvOnSyncComplete(webgl::ObjectId) const; 62 }; 63 64 } // namespace dom 65 } // namespace mozilla 66 67 #endif // WEBGLCHILD_H_