Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / canvas / WebGLChild.cpp
blobe03056e53da5f71493d4b48413f790cb1de69682
1 /* -*- Mode: C++; tab-width: 20; 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/. */
6 #include "WebGLChild.h"
8 #include "ClientWebGLContext.h"
9 #include "mozilla/StaticPrefs_webgl.h"
10 #include "WebGLMethodDispatcher.h"
12 namespace mozilla::dom {
14 WebGLChild::WebGLChild(ClientWebGLContext& context)
15 : mContext(&context),
16 mDefaultCmdsShmemSize(StaticPrefs::webgl_out_of_process_shmem_size()) {}
18 WebGLChild::~WebGLChild() { (void)Send__delete__(this); }
20 void WebGLChild::ActorDestroy(ActorDestroyReason why) {
21 mPendingCmdsShmem = {};
24 // -
26 Maybe<Range<uint8_t>> WebGLChild::AllocPendingCmdBytes(const size_t size) {
27 if (!mPendingCmdsShmem) {
28 size_t capacity = mDefaultCmdsShmemSize;
29 if (capacity < size) {
30 capacity = size;
33 auto shmem = webgl::RaiiShmem::Alloc(
34 this, capacity,
35 mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC);
36 if (!shmem) {
37 NS_WARNING("Failed to alloc shmem for AllocPendingCmdBytes.");
38 return {};
40 mPendingCmdsShmem = std::move(shmem);
41 mPendingCmdsPos = 0;
43 const auto range = mPendingCmdsShmem.ByteRange();
45 auto itr = range.begin() + mPendingCmdsPos;
46 const auto offset = AlignmentOffset(kUniversalAlignment, itr.get());
47 mPendingCmdsPos += offset;
48 const auto required = mPendingCmdsPos + size;
49 if (required > range.length()) {
50 FlushPendingCmds();
51 return AllocPendingCmdBytes(size);
53 itr = range.begin() + mPendingCmdsPos;
54 const auto remaining = Range<uint8_t>{itr, range.end()};
55 mPendingCmdsPos += size;
56 return Some(Range<uint8_t>{remaining.begin(), remaining.begin() + size});
59 void WebGLChild::FlushPendingCmds() {
60 if (!mPendingCmdsShmem) return;
62 const auto byteSize = mPendingCmdsPos;
63 SendDispatchCommands(mPendingCmdsShmem.Extract(), byteSize);
65 mFlushedCmdInfo.flushes += 1;
66 mFlushedCmdInfo.flushedCmdBytes += byteSize;
68 if (gl::GLContext::ShouldSpew()) {
69 printf_stderr("[WebGLChild] Flushed %zu bytes. (%zu over %zu flushes)\n",
70 byteSize, mFlushedCmdInfo.flushedCmdBytes,
71 mFlushedCmdInfo.flushes);
75 // -
77 mozilla::ipc::IPCResult WebGLChild::RecvJsWarning(
78 const std::string& text) const {
79 if (!mContext) return IPC_OK();
80 mContext->JsWarning(text);
81 return IPC_OK();
84 mozilla::ipc::IPCResult WebGLChild::RecvOnContextLoss(
85 const webgl::ContextLossReason reason) const {
86 if (!mContext) return IPC_OK();
87 mContext->OnContextLoss(reason);
88 return IPC_OK();
91 } // namespace mozilla::dom