summaryrefslogtreecommitdiffstats
path: root/gfx/layers/mlgpu/LayerMLGPU.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/layers/mlgpu/LayerMLGPU.cpp
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/mlgpu/LayerMLGPU.cpp')
-rw-r--r--gfx/layers/mlgpu/LayerMLGPU.cpp141
1 files changed, 141 insertions, 0 deletions
diff --git a/gfx/layers/mlgpu/LayerMLGPU.cpp b/gfx/layers/mlgpu/LayerMLGPU.cpp
new file mode 100644
index 0000000000..714214e83b
--- /dev/null
+++ b/gfx/layers/mlgpu/LayerMLGPU.cpp
@@ -0,0 +1,141 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "LayerManagerMLGPU.h"
+#include "RenderPassMLGPU.h"
+#include "RenderViewMLGPU.h"
+#include "FrameBuilder.h"
+#include "mozilla/layers/ImageHost.h"
+#include "mozilla/layers/LayerManagerComposite.h"
+
+namespace mozilla {
+namespace layers {
+
+using namespace gfx;
+
+uint64_t LayerMLGPU::sFrameKey = 0;
+
+LayerMLGPU::~LayerMLGPU() = default;
+
+LayerMLGPU::LayerMLGPU(LayerManagerMLGPU* aManager)
+ : HostLayer(aManager),
+ mFrameKey(0),
+ mComputedOpacity(0.0),
+ mPrepared(false) {}
+
+/* static */
+void LayerMLGPU::BeginFrame() { sFrameKey++; }
+
+LayerManagerMLGPU* LayerMLGPU::GetManager() {
+ return static_cast<LayerManagerMLGPU*>(mCompositorManager);
+}
+
+bool LayerMLGPU::PrepareToRender(FrameBuilder* aBuilder,
+ const RenderTargetIntRect& aClipRect) {
+ if (mFrameKey == sFrameKey) {
+ return mPrepared;
+ }
+ mFrameKey = sFrameKey;
+ mPrepared = false;
+
+ Layer* layer = GetLayer();
+
+ // Only container layers may have mixed blend modes.
+ MOZ_ASSERT_IF(layer->GetMixBlendMode() != CompositionOp::OP_OVER,
+ layer->GetType() == Layer::TYPE_CONTAINER);
+
+ mComputedClipRect = aClipRect;
+ mComputedOpacity = layer->GetEffectiveOpacity();
+
+ if (layer->HasMaskLayers()) {
+ mMask = aBuilder->AddMaskOperation(this);
+ // If the mask has no texture, the pixel shader can't read any non-zero
+ // values for the mask, so we can consider the whole thing invisible.
+ if (mMask && mMask->IsEmpty()) {
+ mComputedOpacity = 0.0f;
+ }
+ } else {
+ mMask = nullptr;
+ }
+
+ if (!OnPrepareToRender(aBuilder)) {
+ return false;
+ }
+
+ mPrepared = true;
+ return true;
+}
+
+void LayerMLGPU::AssignToView(FrameBuilder* aBuilder, RenderViewMLGPU* aView,
+ Maybe<gfx::Polygon>&& aGeometry) {
+ AddBoundsToView(aBuilder, aView, std::move(aGeometry));
+}
+
+void LayerMLGPU::AddBoundsToView(FrameBuilder* aBuilder, RenderViewMLGPU* aView,
+ Maybe<gfx::Polygon>&& aGeometry) {
+ IntRect bounds = GetClippedBoundingBox(aView, aGeometry);
+ aView->AddItem(this, bounds, std::move(aGeometry));
+}
+
+IntRect LayerMLGPU::GetClippedBoundingBox(
+ RenderViewMLGPU* aView, const Maybe<gfx::Polygon>& aGeometry) {
+ MOZ_ASSERT(IsPrepared());
+
+ Layer* layer = GetLayer();
+ const Matrix4x4& transform = layer->GetEffectiveTransform();
+
+ Rect rect =
+ aGeometry
+ ? aGeometry->BoundingBox()
+ : Rect(layer->GetLocalVisibleRegion().GetBounds().ToUnknownRect());
+ rect = transform.TransformBounds(rect);
+ rect.MoveBy(-aView->GetTargetOffset());
+ rect = rect.Intersect(Rect(mComputedClipRect.ToUnknownRect()));
+
+ IntRect bounds;
+ rect.RoundOut();
+ rect.ToIntRect(&bounds);
+ return bounds;
+}
+
+void LayerMLGPU::MarkPrepared() {
+ mFrameKey = sFrameKey;
+ mPrepared = true;
+}
+
+bool LayerMLGPU::IsContentOpaque() { return GetLayer()->IsOpaque(); }
+
+void LayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion) {
+ mRenderRegion = std::move(aRegion);
+}
+
+void LayerMLGPU::SetLayerManager(HostLayerManager* aManager) {
+ LayerManagerMLGPU* manager = aManager->AsLayerManagerMLGPU();
+ MOZ_RELEASE_ASSERT(manager);
+
+ HostLayer::SetLayerManager(aManager);
+ GetLayer()->SetManager(manager, this);
+
+ if (CompositableHost* host = GetCompositableHost()) {
+ host->SetTextureSourceProvider(manager->GetTextureSourceProvider());
+ }
+
+ OnLayerManagerChange(manager);
+}
+
+RefLayerMLGPU::RefLayerMLGPU(LayerManagerMLGPU* aManager)
+ : RefLayer(aManager, static_cast<HostLayer*>(this)), LayerMLGPU(aManager) {}
+
+RefLayerMLGPU::~RefLayerMLGPU() = default;
+
+ColorLayerMLGPU::ColorLayerMLGPU(LayerManagerMLGPU* aManager)
+ : ColorLayer(aManager, static_cast<HostLayer*>(this)),
+ LayerMLGPU(aManager) {}
+
+ColorLayerMLGPU::~ColorLayerMLGPU() = default;
+
+} // namespace layers
+} // namespace mozilla