Line data Source code
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/. */
5 :
6 : #ifndef mozilla_gfx_layers_mlgpu_LayerMLGPU_h
7 : #define mozilla_gfx_layers_mlgpu_LayerMLGPU_h
8 :
9 : #include "Layers.h"
10 : #include "mozilla/layers/LayerManagerComposite.h"
11 :
12 : namespace mozilla {
13 : namespace layers {
14 :
15 : class CanvasLayerMLGPU;
16 : class ColorLayerMLGPU;
17 : class ContainerLayerMLGPU;
18 : class FrameBuilder;
19 : class ImageHost;
20 : class ImageLayerMLGPU;
21 : class LayerManagerMLGPU;
22 : class MaskOperation;
23 : class MLGRenderTarget;
24 : class PaintedLayerMLGPU;
25 : class RefLayerMLGPU;
26 : class RenderViewMLGPU;
27 : class TexturedLayerMLGPU;
28 : class TextureSource;
29 :
30 0 : class LayerMLGPU : public HostLayer
31 : {
32 : public:
33 0 : LayerMLGPU* AsLayerMLGPU() override { return this; }
34 0 : virtual PaintedLayerMLGPU* AsPaintedLayerMLGPU() { return nullptr; }
35 0 : virtual ImageLayerMLGPU* AsImageLayerMLGPU() { return nullptr; }
36 0 : virtual CanvasLayerMLGPU* AsCanvasLayerMLGPU() { return nullptr; }
37 0 : virtual ContainerLayerMLGPU* AsContainerLayerMLGPU() { return nullptr; }
38 0 : virtual RefLayerMLGPU* AsRefLayerMLGPU() { return nullptr; }
39 0 : virtual ColorLayerMLGPU* AsColorLayerMLGPU() { return nullptr; }
40 0 : virtual TexturedLayerMLGPU* AsTexturedLayerMLGPU() { return nullptr; }
41 :
42 : static void BeginFrame();
43 :
44 : // Ask the layer to acquire any resources or per-frame information needed
45 : // to render. If this returns false, the layer will be skipped entirely.
46 : bool PrepareToRender(FrameBuilder* aBuilder, const RenderTargetIntRect& aClipRect);
47 :
48 0 : Layer::LayerType GetType() {
49 0 : return GetLayer()->GetType();
50 : }
51 0 : const RenderTargetIntRect& GetComputedClipRect() const {
52 0 : return mComputedClipRect;
53 : }
54 0 : MaskOperation* GetMask() const {
55 0 : return mMask;
56 : }
57 0 : float GetComputedOpacity() const {
58 0 : return mComputedOpacity;
59 : }
60 :
61 : // Return the bounding box of this layer in render target space, clipped to
62 : // the computed clip rect, and rounded out to an integer rect.
63 : gfx::IntRect GetClippedBoundingBox(RenderViewMLGPU* aView,
64 : const Maybe<gfx::Polygon>& aGeometry);
65 :
66 : // If this layer has already been prepared for the current frame, return
67 : // true. This should only be used to guard against double-processing
68 : // container layers after 3d-sorting.
69 0 : bool IsPrepared() const {
70 0 : return mFrameKey == sFrameKey && mPrepared;
71 : }
72 :
73 : // Return true if the content in this layer is opaque (not factoring in
74 : // blend modes or opacity), false otherwise.
75 : virtual bool IsContentOpaque();
76 :
77 : // This is a wrapper around SetShadowVisibleRegion. Some layers have visible
78 : // regions that extend beyond what is actually drawn. When performing CPU-
79 : // based occlusion culling we must clamp the visible region to the actual
80 : // area.
81 : virtual void SetRegionToRender(LayerIntRegion&& aRegion);
82 :
83 : virtual void AssignToView(FrameBuilder* aBuilder,
84 : RenderViewMLGPU* aView,
85 : Maybe<gfx::Polygon>&& aGeometry);
86 :
87 : // Callback for when PrepareToRender has finished successfully. If this
88 : // returns false, PrepareToRender will return false.
89 0 : virtual bool OnPrepareToRender(FrameBuilder* aBuilder) {
90 0 : return true;
91 : }
92 :
93 0 : virtual void ClearCachedResources() {}
94 0 : virtual CompositableHost* GetCompositableHost() override {
95 0 : return nullptr;
96 : }
97 :
98 : protected:
99 : LayerMLGPU(LayerManagerMLGPU* aManager);
100 : LayerManagerMLGPU* GetManager();
101 :
102 : void AddBoundsToView(FrameBuilder* aBuilder,
103 : RenderViewMLGPU* aView,
104 : Maybe<gfx::Polygon>&& aGeometry);
105 :
106 : void MarkPrepared();
107 :
108 : // We don't want derivative layers overriding this directly - we provide a
109 : // callback instead.
110 : void SetLayerManager(HostLayerManager* aManager) override;
111 0 : virtual void OnLayerManagerChange(LayerManagerMLGPU* aManager) {}
112 :
113 : private:
114 : // This is a monotonic counter used to check whether a layer appears twice
115 : // when 3d sorting.
116 : static uint64_t sFrameKey;
117 :
118 : protected:
119 : // These are set during PrepareToRender.
120 : RenderTargetIntRect mComputedClipRect;
121 : RefPtr<MaskOperation> mMask;
122 : uint64_t mFrameKey;
123 : float mComputedOpacity;
124 : bool mPrepared;
125 : };
126 :
127 : class RefLayerMLGPU final : public RefLayer
128 : , public LayerMLGPU
129 : {
130 : public:
131 : explicit RefLayerMLGPU(LayerManagerMLGPU* aManager);
132 : ~RefLayerMLGPU() override;
133 :
134 : // Layer
135 0 : HostLayer* AsHostLayer() override { return this; }
136 0 : RefLayerMLGPU* AsRefLayerMLGPU() override { return this; }
137 0 : Layer* GetLayer() override { return this; }
138 :
139 : // ContainerLayer
140 0 : void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
141 : {
142 0 : DefaultComputeEffectiveTransforms(aTransformToSurface);
143 0 : }
144 :
145 0 : MOZ_LAYER_DECL_NAME("RefLayerMLGPU", TYPE_REF)
146 : };
147 :
148 : class ColorLayerMLGPU final : public ColorLayer
149 : , public LayerMLGPU
150 : {
151 : public:
152 : explicit ColorLayerMLGPU(LayerManagerMLGPU* aManager);
153 : ~ColorLayerMLGPU() override;
154 :
155 : // LayerMLGPU
156 0 : bool IsContentOpaque() override {
157 0 : return mColor.a >= 1.0f;
158 : }
159 :
160 : // Layer
161 0 : HostLayer* AsHostLayer() override { return this; }
162 0 : ColorLayerMLGPU* AsColorLayerMLGPU() override { return this; }
163 0 : Layer* GetLayer() override { return this; }
164 :
165 0 : MOZ_LAYER_DECL_NAME("ColorLayerMLGPU", TYPE_COLOR)
166 : };
167 :
168 : } // namespace layers
169 : } // namespace mozilla
170 :
171 : #endif // mozilla_gfx_layers_mlgpu_LayerMLGPU_h
|