/src/mozilla-central/gfx/layers/mlgpu/LayerMLGPU.cpp
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 | | #include "LayerManagerMLGPU.h" |
8 | | #include "RenderPassMLGPU.h" |
9 | | #include "RenderViewMLGPU.h" |
10 | | #include "FrameBuilder.h" |
11 | | #include "mozilla/layers/ImageHost.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace layers { |
15 | | |
16 | | using namespace gfx; |
17 | | |
18 | | uint64_t LayerMLGPU::sFrameKey = 0; |
19 | | |
20 | | LayerMLGPU::LayerMLGPU(LayerManagerMLGPU* aManager) |
21 | | : HostLayer(aManager), |
22 | | mFrameKey(0), |
23 | | mComputedOpacity(0.0), |
24 | | mPrepared(false) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | /* static */ void |
29 | | LayerMLGPU::BeginFrame() |
30 | 0 | { |
31 | 0 | sFrameKey++; |
32 | 0 | } |
33 | | |
34 | | LayerManagerMLGPU* |
35 | | LayerMLGPU::GetManager() |
36 | 0 | { |
37 | 0 | return static_cast<LayerManagerMLGPU*>(mCompositorManager); |
38 | 0 | } |
39 | | |
40 | | bool |
41 | | LayerMLGPU::PrepareToRender(FrameBuilder* aBuilder, const RenderTargetIntRect& aClipRect) |
42 | 0 | { |
43 | 0 | if (mFrameKey == sFrameKey) { |
44 | 0 | return mPrepared; |
45 | 0 | } |
46 | 0 | mFrameKey = sFrameKey; |
47 | 0 | mPrepared = false; |
48 | 0 |
|
49 | 0 | Layer* layer = GetLayer(); |
50 | 0 |
|
51 | 0 | // Only container layers may have mixed blend modes. |
52 | 0 | MOZ_ASSERT_IF(layer->GetMixBlendMode() != CompositionOp::OP_OVER, |
53 | 0 | layer->GetType() == Layer::TYPE_CONTAINER); |
54 | 0 |
|
55 | 0 | mComputedClipRect = aClipRect; |
56 | 0 | mComputedOpacity = layer->GetEffectiveOpacity(); |
57 | 0 |
|
58 | 0 | if (layer->HasMaskLayers()) { |
59 | 0 | mMask = aBuilder->AddMaskOperation(this); |
60 | 0 | // If the mask has no texture, the pixel shader can't read any non-zero |
61 | 0 | // values for the mask, so we can consider the whole thing invisible. |
62 | 0 | if (mMask && mMask->IsEmpty()) { |
63 | 0 | mComputedOpacity = 0.0f; |
64 | 0 | } |
65 | 0 | } else { |
66 | 0 | mMask = nullptr; |
67 | 0 | } |
68 | 0 |
|
69 | 0 | if (!OnPrepareToRender(aBuilder)) { |
70 | 0 | return false; |
71 | 0 | } |
72 | 0 | |
73 | 0 | mPrepared = true; |
74 | 0 | return true; |
75 | 0 | } |
76 | | |
77 | | void |
78 | | LayerMLGPU::AssignToView(FrameBuilder* aBuilder, |
79 | | RenderViewMLGPU* aView, |
80 | | Maybe<gfx::Polygon>&& aGeometry) |
81 | 0 | { |
82 | 0 | AddBoundsToView(aBuilder, aView, std::move(aGeometry)); |
83 | 0 | } |
84 | | |
85 | | void |
86 | | LayerMLGPU::AddBoundsToView(FrameBuilder* aBuilder, |
87 | | RenderViewMLGPU* aView, |
88 | | Maybe<gfx::Polygon>&& aGeometry) |
89 | 0 | { |
90 | 0 | IntRect bounds = GetClippedBoundingBox(aView, aGeometry); |
91 | 0 | aView->AddItem(this, bounds, std::move(aGeometry)); |
92 | 0 | } |
93 | | |
94 | | IntRect |
95 | | LayerMLGPU::GetClippedBoundingBox(RenderViewMLGPU* aView, |
96 | | const Maybe<gfx::Polygon>& aGeometry) |
97 | 0 | { |
98 | 0 | MOZ_ASSERT(IsPrepared()); |
99 | 0 |
|
100 | 0 | Layer* layer = GetLayer(); |
101 | 0 | const Matrix4x4& transform = layer->GetEffectiveTransform(); |
102 | 0 |
|
103 | 0 | Rect rect = aGeometry |
104 | 0 | ? aGeometry->BoundingBox() |
105 | 0 | : Rect(layer->GetLocalVisibleRegion().GetBounds().ToUnknownRect()); |
106 | 0 | rect = transform.TransformBounds(rect); |
107 | 0 | rect.MoveBy(-aView->GetTargetOffset()); |
108 | 0 | rect = rect.Intersect(Rect(mComputedClipRect.ToUnknownRect())); |
109 | 0 |
|
110 | 0 | IntRect bounds; |
111 | 0 | rect.RoundOut(); |
112 | 0 | rect.ToIntRect(&bounds); |
113 | 0 | return bounds; |
114 | 0 | } |
115 | | |
116 | | void |
117 | | LayerMLGPU::MarkPrepared() |
118 | 0 | { |
119 | 0 | mFrameKey = sFrameKey; |
120 | 0 | mPrepared = true; |
121 | 0 | } |
122 | | |
123 | | bool |
124 | | LayerMLGPU::IsContentOpaque() |
125 | 0 | { |
126 | 0 | return GetLayer()->IsOpaque(); |
127 | 0 | } |
128 | | |
129 | | void |
130 | | LayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion) |
131 | 0 | { |
132 | 0 | mRenderRegion = std::move(aRegion); |
133 | 0 | } |
134 | | |
135 | | void |
136 | | LayerMLGPU::SetLayerManager(HostLayerManager* aManager) |
137 | 0 | { |
138 | 0 | LayerManagerMLGPU* manager = aManager->AsLayerManagerMLGPU(); |
139 | 0 | MOZ_RELEASE_ASSERT(manager); |
140 | 0 |
|
141 | 0 | HostLayer::SetLayerManager(aManager); |
142 | 0 | GetLayer()->SetManager(manager, this); |
143 | 0 |
|
144 | 0 | if (CompositableHost* host = GetCompositableHost()) { |
145 | 0 | host->SetTextureSourceProvider(manager->GetTextureSourceProvider()); |
146 | 0 | } |
147 | 0 |
|
148 | 0 | OnLayerManagerChange(manager); |
149 | 0 | } |
150 | | |
151 | | RefLayerMLGPU::RefLayerMLGPU(LayerManagerMLGPU* aManager) |
152 | | : RefLayer(aManager, static_cast<HostLayer*>(this)) |
153 | | , LayerMLGPU(aManager) |
154 | 0 | { |
155 | 0 | } |
156 | | |
157 | | RefLayerMLGPU::~RefLayerMLGPU() |
158 | 0 | { |
159 | 0 | } |
160 | | |
161 | | ColorLayerMLGPU::ColorLayerMLGPU(LayerManagerMLGPU* aManager) |
162 | | : ColorLayer(aManager, static_cast<HostLayer*>(this)) |
163 | | , LayerMLGPU(aManager) |
164 | 0 | { |
165 | 0 | } |
166 | | |
167 | | ColorLayerMLGPU::~ColorLayerMLGPU() |
168 | 0 | { |
169 | 0 | } |
170 | | |
171 | | } // namespace layers |
172 | | } // namespace mozilla |